InvoiceController.php 315 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585
  1. <?php
  2. /**
  3. * 开票功能控制器
  4. * @author CP
  5. * @version 1.0
  6. * @namespace invoice
  7. * @package invoiceController
  8. */
  9. class InvoiceController extends DooController {
  10. public $staff;
  11. public $NEW;
  12. public $data;
  13. private $INVOICEKEY = "APPROVAL";
  14. private $INVOICECOLLECTPATH = "protected/cache/invoiceCollect/";
  15. private $ACTION = '';
  16. private $appId = 'wx3ee46531947a1384';
  17. private $appSecret = 'awGWzy3J5q_96VXKBLA2BQ9RpiT0LiPXnkMF-xV6h5o'; // awGWzy3J5q_96VXKBLA2BXU6mVCGynPGD-sxUCsdNDE //'PeiQVH8tbQE7pM9pVO4AIPlX9FFNpwu7O6Iy6VFcAVtpjTA3Qn42dbNmktBFkUHo';
  18. public function beforeRun($resource, $action) {
  19. Doo::loadModel ( "invoiceManage" );
  20. $invoiceManage = new invoiceManage ();
  21. Doo::loadClass ( 'XDeode' );
  22. $XDeode = new XDeode ( 5 );
  23. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  24. header ( 'Content-Type:text/html;charset=utf-8' );
  25. $moldList = $invoiceManage->getInvoiceByStaff ( $sid );
  26. if (empty ( $moldList )) {
  27. $flag = false;
  28. $uGroups = 'ordinary';
  29. if (Doo::acl ()->isAllowed ( $uGroups, $resource, $action )) {
  30. $flag = true;
  31. }
  32. } else {
  33. $flag = false;
  34. array_push ( $moldList, array (
  35. 'mold' => 'ordinary'
  36. ) );
  37. // 删除审批人后-加入权限问题-暂时关闭
  38. $fileInvoice = file_get_contents ( "protected/config/invoice/invoice.ini" );
  39. $fiML = json_decode ( $fileInvoice, true );
  40. if (empty ( $fiML ))
  41. $fiML = array ();
  42. foreach ( $fiML as $key => $value ) {
  43. $sidList = explode ( ',', $value );
  44. foreach ( $sidList as $k => $v ) {
  45. if ($v == $sid) {
  46. array_push ( $moldList, array (
  47. 'mold' => $key
  48. ) );
  49. break;
  50. }
  51. }
  52. }
  53. foreach ( $moldList as $value ) {
  54. if (Doo::acl ()->isAllowed ( $value ['mold'], $resource, $action )) {
  55. $flag = true;
  56. break;
  57. }
  58. }
  59. }
  60. /*
  61. * Doo::acl()->isAllowed($uGroups['groups'], $resource, $action);
  62. */
  63. // 单独判断办事处汇总的访问权限 invoiceAggregateCategoryDetail,invoiceAggregateStaffDetail
  64. if ($action == 'invoiceAggregateCategoryDetail' || $action == 'invoiceAggregateStaffDetail') {
  65. Doo::loadModel ( "invoiceCategoryManage" );
  66. $invoiceCategoryManage = new invoiceCategoryManage ();
  67. $icm = $invoiceCategoryManage->getInvoiceCMByStaff ( $sid );
  68. if (empty ( $icm ))
  69. die ( 'illegal request-iacd' );
  70. }
  71. // 单独判断应收款访问权限
  72. if ($action == 'invoiceAggregateCompanyDetail') {
  73. Doo::loadModel ( "invoiceCompanyManage" );
  74. $invoiceCompanyManage = new invoiceCompanyManage ();
  75. $icm = $invoiceCompanyManage->getInvoiceCMByStaff ( $sid );
  76. if (empty ( $icm ))
  77. die ( 'illegal request' );
  78. }
  79. // 主权限获得与判断
  80. Doo::loadModel ( 'staff' );
  81. $staff = new staff ();
  82. $detail = $staff->getStaffBySid ( $_COOKIE ["staff"] );
  83. $accessModular = 'INVOICE';
  84. if (empty ( $detail ['cldAccessArray'] ))
  85. die ( 'illegal request' );
  86. else {
  87. if (in_array ( $accessModular, $detail ['cldAccessArray'] )) {
  88. if (Doo::acl ()->isAllowed ( $accessModular, $resource, $action )) {
  89. $flag = true;
  90. } else {
  91. $flag = false;
  92. }
  93. } else {
  94. die ( 'illegal request' );
  95. }
  96. }
  97. if (! $flag)
  98. die ( 'illegal request' );
  99. }
  100. function __construct() {
  101. if (isset ( $_COOKIE ["staff"] )) {
  102. if (! empty ( $_COOKIE ["staff"] )) {
  103. Doo::loadModel ( 'staff' );
  104. $staff = new staff ();
  105. $uriPartsOrig = explode ( '/', $_SERVER ['REQUEST_URI'] );
  106. $this->ACTION = $uriPartsOrig [1];
  107. $this->data ['new'] = $this->isInvoiceNew ();
  108. $this->staff = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  109. $this->data ['isStaffCompleteMsg'] = false;
  110. $detail = $staff->checkStaffInfoIsComplete ( $_COOKIE ["staff"] );
  111. if (! empty ( $detail ))
  112. $this->data ['isStaffCompleteMsg'] = true;
  113. return "/";
  114. }
  115. }
  116. Doo::loadCore ( 'uri/DooUriRouter' );
  117. $router = new DooUriRouter ();
  118. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  119. if ($routeRs ['1'] != "login") {
  120. header ( 'Content-Type:text/html;charset=utf-8' );
  121. @header ( "Location: /login" );
  122. }
  123. }
  124. function testSend() {
  125. // 测试根据规则发送信息 普通发送
  126. // $pendingApprovalsSid = 41;
  127. // Doo::loadModel ( 'staff' );
  128. // $staff = new staff ();
  129. // $username2 = $staff->getOne ( array ( 'select' => 'wxid', 'where' => 'sid=' . $pendingApprovalsSid, 'asArray' => TRUE ) );
  130. // // 发送微信审批通知
  131. // $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  132. // $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  133. // Doo::loadModel ( 'staff' );
  134. // $staff = new staff ();
  135. // $toparty = $this->getToparty ( '广东办' );
  136. // $wxList = array ();
  137. // if (! empty ( $toparty )) {
  138. // $userList = $this->getUserByToparty ( $toparty );
  139. // $userCon = implode ( ',', $userList );
  140. // // echo $userCon;
  141. // $sidList = $staff->getStaffByWxid ( $userCon );
  142. // foreach ( $sidList as $key => $value ) {
  143. // $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  144. // if ($falg) {
  145. // array_push ( $wxList, $value ['wxid'] );
  146. // }
  147. // }
  148. // $wxString = implode ( '|', $wxList );
  149. // print_r ( $wxList );
  150. // echo $wxString;
  151. // }
  152. // 测试发送
  153. /*
  154. * //$toparty = $this->getWxidByCategory( $receivablesCategory [1] ); $toparty = $this->getToparty ( $receivablesCategory [1] ); $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。'; if ($toparty != 0) $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  155. */
  156. // print_r ( $userList );
  157. // $msTouser='caipin|outaozhen';
  158. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  159. // $title2 = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  160. // $hfreult = $this->msgSend ( '', $title2, '', 'outaozhen' );
  161. // $toparty= $this->getToparty('广东办');
  162. // $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  163. // $toparty = 26;
  164. // $msg = '';
  165. // $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/1.html';
  166. // $hfreult = $this->msgSendToparty ( $msg, '', '', $toparty,'text' );
  167. }
  168. function invoice() {
  169. Doo::loadModel ( 'invoice' );
  170. $invoice = new invoice ();
  171. Doo::loadModel ( 'express' );
  172. $express = new express ();
  173. $expressList = $express->getExpressByAll ();
  174. $this->data ['expressList'] = $expressList;
  175. // Doo::loadModel ( 'invoiceReceivables' );
  176. // $invoiceReceivables = new invoiceReceivables ();
  177. // $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  178. Doo::loadClass ( 'XDeode' );
  179. $XDeode = new XDeode ( 5 );
  180. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  181. Doo::loadModel ( 'invoiceStatistics' );
  182. $invoiceStatistics = new invoiceStatistics ();
  183. $isMonth = $invoiceStatistics->getStatisticsByMonth ( $sid );
  184. // 缓存统计结果
  185. $year = date ( "Y" );
  186. $tmp_date = date ( "Ym" );
  187. $tmp_year = substr ( $tmp_date, 0, 4 );
  188. $tmp_mon = substr ( $tmp_date, 4, 2 );
  189. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  190. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  191. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . "_" . $sid . ".htm";
  192. if (is_file ( $path ))
  193. $htm = file_get_contents ( $path );
  194. else
  195. $htm = $this->showCache ( $path, $sid );
  196. $invoiceList = $invoice->getMyInvoice ( $sid );
  197. $sql = 'status=2 and printStatus=1 and irid!="" and sid=' . $sid;
  198. $list = $invoice->getInvoiceByUntreadStatusPage ( 4, $sql );
  199. // 我的待入账发票 and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  200. $sql = "status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid=" . $sid;
  201. $myInvoiceUnAccount = $invoice->getInvoiceByUntreadStatusPage ( 4, $sql );
  202. // 获得已退票功能
  203. $untreadStatusList = $invoice->getMyInvoiceByUntreadStatus ( 2, 0, 5, $sid );
  204. $this->data ['untreadStatusList'] = $untreadStatusList;
  205. // print_r($untreadStatusList);
  206. $this->data ['isMonth'] = $isMonth;
  207. $this->data ['htm'] = $htm;
  208. $this->data ['invoiceList'] = $invoiceList;
  209. $this->data ['receivablesList'] = $list;
  210. $this->data ['myInvoiceUnAccount'] = $myInvoiceUnAccount;
  211. $this->data ['memu'] = "invoice";
  212. $this->data ['staff'] = $this->staff;
  213. $this->data ['receiptMemu'] = 'invoice';
  214. $this->render ( "/admin/invoice", $this->data );
  215. }
  216. function invoiceExpress() {
  217. $expressCom = isset ( $this->params ['expressCom'] ) ? $this->params ['expressCom'] : "";
  218. $expressNumber = isset ( $this->params ['expressNumber'] ) ? $this->params ['expressNumber'] : "";
  219. $this->data ['expressCom'] = $expressCom;
  220. $this->data ['expressNumber'] = $expressNumber;
  221. $this->render ( "/admin/invoiceExpress", $this->data );
  222. }
  223. function invoiceAdd() {
  224. session_start ();
  225. /*Doo::loadModel ( 'invoice' );
  226. $invoice = new invoice ();
  227. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );*/
  228. Doo::loadModel ( 'L_category' );
  229. $lCategory = new L_category ();
  230. $category = $lCategory->find ( array (
  231. 'asArray' => true
  232. ) );
  233. $this->data ['category'] = $category;
  234. Doo::loadModel ( 'invoiceTraining' );
  235. $invoiceTraining = new invoiceTraining ();
  236. $itList = $invoiceTraining->getInvoiceTrainingByCid ( $this->staff [0] ['cid'] );
  237. Doo::loadModel ( 'receipt' );
  238. $receipt = new receipt ();
  239. foreach ( $itList as $key => $value ) { // 不展示已结算完结的培训班
  240. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $value ['itid'] );
  241. if (! empty ( $receiptDetail )) {
  242. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9) {
  243. unset ( $itList [$key] );
  244. }
  245. }
  246. }
  247. $this->data ['itList'] = $itList;
  248. $token = $this->set_token ();
  249. $tokenTime=time().rand(5, 15);
  250. $_SESSION ['token_' . $this->staff [0] ['sidKey'].'_'.$tokenTime] = $token;
  251. $this->data ['token'] = $token;
  252. $this->data['tokenTime']=$tokenTime;
  253. $this->data ['memu'] = "invoice";
  254. $this->data ['staff'] = $this->staff;
  255. $this->data ['receiptMemu'] = 'invoice';
  256. $this->render ( "/admin/invoiceAdd", $this->data );
  257. }
  258. /**
  259. * 自更新发票信息库
  260. * @param unknown $invoicePrintDetail
  261. */
  262. function autoUpdateInvoiceInfoBase($invoicePrintDetail) {
  263. // 发票信息库
  264. Doo::loadModel ( 'invoiceInfoBase' );
  265. $invoiceInfoBase = new invoiceInfoBase ();
  266. $updateDate = strtotime ( $invoicePrintDetail ['date'] );
  267. $TIN = $invoicePrintDetail ['TIN'];
  268. $invoiceTitle = $invoicePrintDetail ['invoiceTitle'];
  269. if (empty ( $invoiceTitle ))
  270. $invoiceTitle = $invoicePrintDetail ['invoiceCompany'];
  271. $IIBList = $invoiceInfoBase->getInvoiceInfoByTT ( $TIN, $invoiceTitle );
  272. // 确认有该条发票信息
  273. $invoiceInfoBase = new invoiceInfoBase ();
  274. if (! empty ( $IIBList )) {
  275. // 发票库里的信息数量
  276. $IIBListCount = count ( $IIBList );
  277. if ($IIBListCount == 1) { // 更新发票--提交是最新的时间
  278. $item = array (
  279. 'iibID' => $IIBList [0] ['iibID'],
  280. 'invoiceTitle' => $invoiceTitle,
  281. 'TIN' => $TIN
  282. );
  283. if (! empty ( $invoicePrintDetail ['address'] )) {
  284. $item += array (
  285. 'address' => $invoicePrintDetail ['address']
  286. );
  287. }
  288. if (! empty ( $invoicePrintDetail ['phone'] )) {
  289. $item += array (
  290. 'phone' => $invoicePrintDetail ['phone']
  291. );
  292. }
  293. if (! empty ( $invoicePrintDetail ['bank'] )) {
  294. $item += array (
  295. 'bank' => $invoicePrintDetail ['bank']
  296. );
  297. }
  298. if (! empty ( $invoicePrintDetail ['bankAccount'] )) {
  299. $item += array (
  300. 'bankAccount' => $invoicePrintDetail ['bankAccount']
  301. );
  302. }
  303. if ($updateDate >= strtotime ($IIBList [0] ['updateDate'])) {
  304. $item += array (
  305. 'updateDate' => $invoicePrintDetail ['date']
  306. );
  307. $invoiceInfoBase->setInvoiceInfoBaseByCondition ( $item );
  308. }
  309. } else { // 删除多张发票,重新添加发票
  310. $iibIDStr = '';
  311. $iibID = array ();
  312. foreach ( $IIBList as $key => $value ) {
  313. array_push ( $iibID, $value ['iibID'] );
  314. }
  315. $iibIDStr = implode ( ",", $iibID ); // 删除
  316. $invoiceInfoBase->delInvoiceInfoBaseByIibStr ( $iibIDStr );
  317. $item = array (
  318. 'invoiceTitle' => $invoiceTitle,
  319. 'TIN' => $TIN,
  320. 'address' => $invoicePrintDetail ['address'],
  321. 'phone' => $invoicePrintDetail ['phone'],
  322. 'bank' => $invoicePrintDetail ['bank'],
  323. 'bankAccount' => $invoicePrintDetail ['bankAccount'],
  324. 'updateDate' => $invoicePrintDetail ['date']
  325. );
  326. $invoiceInfoBase->addInvoiceInfoBase ( $item );
  327. }
  328. } else { // 没有新增发票信息
  329. $item = array (
  330. 'invoiceTitle' => $invoiceTitle,
  331. 'TIN' => $TIN,
  332. 'address' => $invoicePrintDetail ['address'],
  333. 'phone' => $invoicePrintDetail ['phone'],
  334. 'bank' => $invoicePrintDetail ['bank'],
  335. 'bankAccount' => $invoicePrintDetail ['bankAccount'],
  336. 'updateDate' => $invoicePrintDetail ['date']
  337. );
  338. $invoiceInfoBase->addInvoiceInfoBase ( $item );
  339. }
  340. }
  341. function invoiceAddFill() {
  342. session_start ();
  343. Doo::loadModel ( 'L_category' );
  344. $lCategory = new L_category ();
  345. $category = $lCategory->find ( array (
  346. 'asArray' => true
  347. ) );
  348. $this->data ['category'] = $category;
  349. Doo::loadModel ( 'invoiceTraining' );
  350. $invoiceTraining = new invoiceTraining ();
  351. $itList = $invoiceTraining->getInvoiceTrainingByCid ( $this->staff [0] ['cid'] );
  352. $this->data ['itList'] = $itList;
  353. Doo::loadModel ( 'invoice' );
  354. $invoice = new invoice ();
  355. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );
  356. $detail ['mailItemsArray'] = json_decode ( $detail ['mailItemsJson'], true );
  357. $token = $this->set_token ();
  358. $tokenTime=time().rand(5, 15);
  359. $_SESSION ['token_' . $this->staff [0] ['sidKey'].'_'.$tokenTime] = $token;
  360. $this->data ['token'] = $token;
  361. $this->data['tokenTime']=$tokenTime;
  362. $this->data ['invoiceDetail'] = $detail;
  363. $this->data ['memu'] = "invoice";
  364. $this->data ['staff'] = $this->staff;
  365. $this->data ['receiptMemu'] = 'invoice';
  366. $this->render ( "/admin/invoiceAddFill", $this->data );
  367. }
  368. /**
  369. * 提交一份开票申请,并记录下操作日志
  370. *
  371. * @since 1.0.0
  372. * @var integer cid 办事处ID
  373. * @var integer invoiceType 发票类型
  374. * @var integer doPost 是否邮寄
  375. * @var integer invoicePrice 开票金额
  376. * @var string invoiceElement 开票内容
  377. * @var string invoiceTitle 发票抬头
  378. * @var string invoiceCompany 单位名称
  379. * @var string TIN 纳税人识别码
  380. * @var string address 注册地址
  381. * @var string phone 注册电话
  382. * @var string bank 开户银行
  383. * @var string bankAccount 银行账户
  384. * @var string recipients 收件人
  385. * @var string recipientsPhone 收件人手机/电话
  386. * @var string recipientsAddress 收件地址
  387. * @var string mailItems 邮寄物品
  388. * @var string remark 备注
  389. * @return string 返回跳转开票主页路径
  390. */
  391. function invoiceAddDo() {
  392. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  393. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  394. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  395. // $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  396. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  397. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  398. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  399. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  400. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  401. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  402. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  403. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  404. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  405. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  406. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  407. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  408. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  409. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  410. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  411. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  412. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  413. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  414. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  415. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  416. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  417. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  418. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  419. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  420. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  421. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  422. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  423. $trainId = $this->get_args ( 'trainId' ) ? $this->get_args ( 'trainId' ) : 0;
  424. $settlementType = $this->get_args ( 'settlementType' ) ? $this->get_args ( 'settlementType' ) : "";
  425. /*
  426. * $mailList=array(); array_push($mailList, array('invoice'=>1)); array_push($mailList, array('mailItems'=>$mailItems)); if (!empty($softLock)) array_push($mailList, array('softLock'=>$softLockNum)); if (!empty($contract)) array_push($mailList, array('contract'=>$contractNum)); if (!empty($instructions)) array_push($mailList, array('instructions'=>$instructionsNum)); if (!empty($remittance)) array_push($mailList, array('remittance'=>$remittance)); echo json_encode($mailList) ; print_r($mailList); die;
  427. */
  428. $token = $this->get_args ( 'token' ) ? $this->get_args ( 'token' ) : "";
  429. $tokenTime = $this->get_args ( 'tokenTime' ) ? $this->get_args ( 'tokenTime' ) : "";
  430. if (empty ( $token )) {
  431. die ( 'illegal request-token' );
  432. } else {
  433. session_start ();
  434. $sessionKey='token_' . $this->staff [0] ['sidKey'].'_'.$tokenTime;
  435. header ( 'Content-Type:text/html;charset=utf-8' );
  436. if (!isset($_SESSION [$sessionKey])||empty($_SESSION [$sessionKey])) {
  437. die ( '请重新刷新发票申请页面' );
  438. }elseif($_SESSION [$sessionKey]=='repeat'){
  439. die ( '请勿重复申请发票' );
  440. } else {
  441. if ($_SESSION [$sessionKey] != $token){
  442. die ( '请勿重复申请发票' );
  443. }else{
  444. $_SESSION [$sessionKey] = 'repeat';
  445. }
  446. }
  447. }
  448. if ($invoiceType == 1) {
  449. $temporary = $invoiceQuantity * $invoiceUnitPrice;
  450. if ($temporary > 100001) {
  451. header ( 'Content-Type:text/html;charset=utf-8' );
  452. die ( '专用发票总金额暂时不能超过100000.00(一万)元。' );
  453. // die ( 'illegal request-Please priceError' );
  454. }
  455. }
  456. if (empty ( $this->staff [0] ))
  457. die ( 'illegal request-Please login' );
  458. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $settlementType )) {
  459. Doo::loadModel ( 'invoice' );
  460. $invoice = new invoice ();
  461. Doo::loadModel ( 'L_category' );
  462. $lCategory = new L_category ();
  463. Doo::loadModel ( 'invoiceManage' );
  464. $invoiceManage = new invoiceManage ();
  465. Doo::loadModel ( 'invoiceOperationLog' );
  466. $invoiceOperationLog = new invoiceOperationLog ();
  467. Doo::loadClass ( 'XDeode' );
  468. $XDeode = new XDeode ( 5 );
  469. $trainId = $XDeode->decode ( $trainId );
  470. $categoryDetil = $lCategory->getOne ( array (
  471. 'SELECT' => 'title',
  472. 'where' => 'cid=' . $cid,
  473. 'asArray' => true
  474. ) );
  475. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  476. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  477. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  478. // print_r(current($invoiceManageDetail ['staffList']));
  479. // die;
  480. $moldManage = array ();
  481. foreach ( $invoiceManageList as $key => $value ) {
  482. if ($value ['mold'] == '发票打印')
  483. $moldManage [$value ['mold']] = $value ['staffList'];
  484. elseif ($value ['mold'] == '发票邮寄')
  485. $moldManage [$value ['mold']] = $value ['staffList'];
  486. elseif ($value ['mold'] == '发票退票')
  487. $moldManage [$value ['mold']] = $value ['staffList'];
  488. }
  489. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  490. $st = '';
  491. if ($settlementType == 'SOFTWARE') {
  492. $st = 0;
  493. $trainId = 0;
  494. } elseif ($settlementType == 'TRAINING') {
  495. $st = 1;
  496. if (empty ( $trainId ) && ! is_numeric ( $trainId )) {
  497. die ( 'illegal request-trainingIdError' );
  498. }
  499. } else {
  500. die ( 'illegal request-settlementError' );
  501. }
  502. $item = array (
  503. 'cid' => $cid,
  504. 'categoryName' => $categoryDetil ['title'],
  505. 'invoiceElement' => $invoiceElement,
  506. 'invoiceQuantity' => $invoiceQuantity,
  507. 'invoiceUnitPrice' => $invoiceUnitPrice,
  508. 'invoicePrice' => $invoicePrice,
  509. 'invoiceType' => $invoiceType,
  510. 'settlementType' => $st,
  511. 'doPost' => $doPost,
  512. 'status' => 1,
  513. 'invoiceSerial' => "#F" . date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT),
  514. 'date' => date ( "Y-m-d H:i:s" ),
  515. 'updateTime' => date ( "Y-m-d H:i:s" ),
  516. 'sid' => $this->staff [0] ['sid'],
  517. 'userName' => $this->staff [0] ['username'],
  518. 'invoiceManage' => $invoiceManageDetail ['staff'],
  519. 'pendingApprovals' => $pendingApprovalsSid,
  520. 'moldManage' => json_encode ( $moldManage ),
  521. 'remark' => $remark,
  522. 'trainId' => $trainId
  523. );
  524. if ($invoiceType == 0)
  525. $item += array (
  526. 'invoiceTitle' => $invoiceTitle,
  527. 'TIN' => $TINT,
  528. 'address' => $addressT,
  529. 'phone' => $phoneT,
  530. 'bank' => $bankT,
  531. 'bankAccount' => $bankAccountT
  532. );
  533. else {
  534. $item += array (
  535. 'invoiceCompany' => $invoiceCompany,
  536. 'TIN' => $TIN,
  537. 'address' => $address,
  538. 'phone' => $phone,
  539. 'bank' => $bank,
  540. 'bankAccount' => $bankAccount
  541. );
  542. }
  543. if ($doPost == 1) {
  544. $mailList = array (
  545. 'invoice' => 1,
  546. 'mailItems' => $mailItems
  547. );
  548. if (! empty ( $softLock ))
  549. $mailList += array (
  550. 'softLock' => $softLockNum
  551. );
  552. else
  553. $mailList += array (
  554. 'softLock' => 0
  555. );
  556. if (! empty ( $contract ))
  557. $mailList += array (
  558. 'contract' => $contractNum
  559. );
  560. else
  561. $mailList += array (
  562. 'contract' => 0
  563. );
  564. if (! empty ( $instructions ))
  565. $mailList += array (
  566. 'instructions' => $instructionsNum
  567. );
  568. else
  569. $mailList += array (
  570. 'instructions' => 0
  571. );
  572. if (! empty ( $remittance ))
  573. $mailList += array (
  574. 'remittance' => $remittance
  575. );
  576. else
  577. $mailList += array (
  578. 'remittance' => ''
  579. );
  580. $mailString = '发票x1张,备注:' . $mailItems;
  581. if (! empty ( $softLock ))
  582. $mailString .= ',软件锁x' . $softLockNum . '个';
  583. if (! empty ( $contract ))
  584. $mailString .= ',合同x' . $contractNum . '份';
  585. if (! empty ( $instructions ))
  586. $mailString .= ',说明书x' . $instructionsNum . '本';
  587. if (! empty ( $remittance ))
  588. $mailString .= ',汇款账号单(张)';
  589. $item += array (
  590. 'recipients' => $recipients,
  591. 'recipientsPhone' => $recipientsPhone,
  592. 'recipientsAddress' => $recipientsAddress,
  593. 'mailItems' => $mailString,
  594. 'mailItemsJson' => json_encode ( $mailList )
  595. );
  596. }
  597. $iid = $invoice->addInvoice ( $item );
  598. // 如果是培训班结算 创建培训班发票到培训班备份中
  599. if (! empty ( $st ) && $st == 1) {
  600. Doo::loadModel ( 'invoiceStore' );
  601. $invoiceStore = new invoiceStore ();
  602. Doo::loadModel ( 'invoiceTraining' );
  603. $invoiceTraining = new invoiceTraining ();
  604. $isid = $invoiceStore->setInvoiceToInvoiceStore ( $iid );
  605. $itemIS = array (
  606. 'isid' => $isid,
  607. 'ipSource' => 1,
  608. 'apStatus' => 1,
  609. 'iid' => $iid
  610. );
  611. $invoiceStore->setInvoiceStoreByCondition ( $itemIS );
  612. // 更新培训班总数量
  613. $detailIT = $invoiceTraining->getInvoiceTrainingByItid ( $trainId );
  614. $item = array (
  615. 'itid' => $trainId,
  616. 'invoiceTotal' => $detailIT ['invoiceTotal'] + 1,
  617. 'submitStatus' => 1
  618. );
  619. $itid = $invoiceTraining->setInvoiceTrainByCondition ( $item );
  620. }
  621. // 操作日志
  622. $item = array (
  623. 'date' => date ( "Y-m-d H:i:s" ),
  624. 'operation' => "创建",
  625. 'status' => 1,
  626. 'img' => $this->staff [0] ['avatar'],
  627. 'username' => $this->staff [0] ['username'],
  628. 'uid' => $this->staff [0] ['sid'],
  629. 'category' => $this->staff [0] ['category'],
  630. 'iid' => $iid
  631. );
  632. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  633. $item = array (
  634. 'date' => date ( "Y-m-d H:i:s" ),
  635. 'operation' => "提交审批",
  636. 'status' => 1,
  637. 'img' => $this->staff [0] ['avatar'],
  638. 'username' => $this->staff [0] ['username'],
  639. 'uid' => $this->staff [0] ['sid'],
  640. 'category' => $this->staff [0] ['category'],
  641. 'iid' => $iid
  642. );
  643. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  644. Doo::loadModel ( 'staff' );
  645. $staff = new staff ();
  646. $username2 = $staff->getOne ( array (
  647. 'select' => 'wxid',
  648. 'where' => 'sid=' . $pendingApprovalsSid,
  649. 'asArray' => TRUE
  650. ) );
  651. // 发送微信审批通知
  652. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  653. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  654. }
  655. return "/invoice";
  656. }
  657. function invoiceEdit() {
  658. Doo::loadClass ( 'XDeode' );
  659. $XDeode = new XDeode ( 5 );
  660. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  661. $iid = $XDeode->decode ( $iid );
  662. if (! is_numeric ( $iid ))
  663. die ( 'illegal request' );
  664. Doo::loadModel ( 'invoice' );
  665. $invoice = new invoice ();
  666. Doo::loadModel ( 'invoiceOperationLog' );
  667. $invoiceOperationLog = new invoiceOperationLog ();
  668. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  669. $operation = $invoiceOperationLog->getInvoiceOperationByDropped ( $iid );
  670. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  671. $this->data ['operation'] = $operation;
  672. $this->data ['invoiceDetail'] = $invoiceDetail;
  673. $this->data ['memu'] = "invoice";
  674. $this->data ['staff'] = $this->staff;
  675. $this->data ['receiptMemu'] = 'invoice';
  676. $this->render ( "/admin/invoiceEdit", $this->data );
  677. }
  678. /**
  679. * 重新编辑退回的发票
  680. * @return string
  681. */
  682. function invoiceEditDo() {
  683. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  684. Doo::loadModel ( 'invoice' );
  685. $invoice = new invoice ();
  686. $iid = $invoice->authcode ( $iidKey );
  687. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  688. die ( 'illegal request' );
  689. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  690. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  691. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  692. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  693. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  694. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  695. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  696. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  697. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  698. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  699. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  700. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  701. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  702. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  703. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  704. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  705. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  706. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  707. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  708. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  709. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  710. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  711. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  712. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  713. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  714. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  715. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  716. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  717. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  718. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  719. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  720. if ($invoiceType == 1) {
  721. $temporary = $invoiceQuantity * $invoiceUnitPrice;
  722. if ($temporary > 100001)
  723. die ( 'illegal request-Please priceError' );
  724. }
  725. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  726. Doo::loadModel ( 'invoiceManage' );
  727. $invoiceManage = new invoiceManage ();
  728. Doo::loadModel ( 'invoiceOperationLog' );
  729. $invoiceOperationLog = new invoiceOperationLog ();
  730. Doo::loadModel ( 'invoiceStore' );
  731. $invoiceStore = new invoiceStore ();
  732. $cid = explode ( ':', $cid );
  733. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  734. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  735. $moldManage = array ();
  736. foreach ( $invoiceManageList as $key => $value ) {
  737. if ($value ['mold'] == '发票打印')
  738. $moldManage [$value ['mold']] = $value ['staffList'];
  739. elseif ($value ['mold'] == '发票邮寄')
  740. $moldManage [$value ['mold']] = $value ['staffList'];
  741. elseif ($value ['mold'] == '发票打印')
  742. $moldManage [$value ['mold']] = $value ['staffList'];
  743. }
  744. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  745. $item = array (
  746. 'iid' => $iid,
  747. 'cid' => $cid [0],
  748. 'categoryName' => $cid [1],
  749. 'invoiceElement' => $invoiceElement,
  750. 'invoiceQuantity' => $invoiceQuantity,
  751. 'invoiceUnitPrice' => $invoiceUnitPrice,
  752. 'invoicePrice' => $invoicePrice,
  753. 'invoiceType' => $invoiceType,
  754. 'doPost' => $doPost,
  755. 'status' => 1,
  756. 'updateTime' => date ( "Y-m-d H:i:s" ),
  757. 'remark' => $remark
  758. );
  759. if ($invoiceType == 0)
  760. $item += array (
  761. 'invoiceTitle' => $invoiceTitle,
  762. 'TIN' => $TINT,
  763. 'address' => $addressT,
  764. 'phone' => $phoneT,
  765. 'bank' => $bankT,
  766. 'bankAccount' => $bankAccountT
  767. );
  768. else {
  769. $item += array (
  770. 'invoiceCompany' => $invoiceCompany,
  771. 'TIN' => $TIN,
  772. 'address' => $address,
  773. 'phone' => $phone,
  774. 'bank' => $bank,
  775. 'bankAccount' => $bankAccount
  776. );
  777. }
  778. if ($doPost == 1) {
  779. $mailList = array (
  780. 'invoice' => 1,
  781. 'mailItems' => $mailItems
  782. );
  783. if (! empty ( $softLock ))
  784. $mailList += array (
  785. 'softLock' => $softLockNum
  786. );
  787. else
  788. $mailList += array (
  789. 'softLock' => '0'
  790. );
  791. if (! empty ( $contract ))
  792. $mailList += array (
  793. 'contract' => $contractNum
  794. );
  795. else
  796. $mailList += array (
  797. 'contract' => '0'
  798. );
  799. if (! empty ( $instructions ))
  800. $mailList += array (
  801. 'instructions' => $instructionsNum
  802. );
  803. else
  804. $mailList += array (
  805. 'instructions' => '0'
  806. );
  807. if (! empty ( $remittance ))
  808. $mailList += array (
  809. 'remittance' => $remittance
  810. );
  811. else
  812. $mailList += array (
  813. 'remittance' => ''
  814. );
  815. $mailString = '发票x1,备注:' . $mailItems;
  816. if (! empty ( $softLock ))
  817. $mailString .= ',软件锁x' . $softLockNum;
  818. if (! empty ( $contract ))
  819. $mailString .= ',合同x' . $contractNum;
  820. if (! empty ( $instructions ))
  821. $mailString .= ',说明书x' . $instructionsNum;
  822. if (! empty ( $remittance ))
  823. $mailString .= ',汇款账号单';
  824. $item += array (
  825. 'recipients' => $recipients,
  826. 'recipientsPhone' => $recipientsPhone,
  827. 'recipientsAddress' => $recipientsAddress,
  828. 'mailItems' => $mailString,
  829. 'mailItemsJson' => json_encode ( $mailList )
  830. );
  831. }
  832. $invoice->setInvoiceByCondition ( $item );
  833. // 更新培训班仓库里的发票
  834. $detail = $invoice->getInvoiceByIid ( $iid );
  835. if (! empty ( $detail ['isid'] )) {
  836. $invoiceStore->isid = $detail ['isid'];
  837. $invoiceStore->invoiceQuantity = $invoiceQuantity;
  838. $invoiceStore->invoiceUnitPrice = $invoiceUnitPrice;
  839. $invoiceStore->invoicePrice = $invoicePrice;
  840. $invoiceStore->update ();
  841. }
  842. $item = array (
  843. 'date' => date ( "Y-m-d H:i:s" ),
  844. 'operation' => "重新提交审批",
  845. 'status' => 1,
  846. 'img' => $this->staff [0] ['avatar'],
  847. 'username' => $this->staff [0] ['username'],
  848. 'uid' => $this->staff [0] ['sid'],
  849. 'category' => $this->staff [0] ['category'],
  850. 'iid' => $iid
  851. );
  852. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  853. }
  854. return "/invoice";
  855. }
  856. /**
  857. * 培训班
  858. */
  859. function invoiceTraining() {
  860. Doo::loadModel ( 'L_category' );
  861. $lCategory = new L_category ();
  862. Doo::loadModel ( 'invoiceTraining' );
  863. $invoiceTraining = new invoiceTraining ();
  864. Doo::loadModel ( 'invoiceTrainManage' );
  865. $invoiceTrainManage = new invoiceTrainManage ();
  866. $imcStaff = $invoiceTrainManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  867. $cidList = array ();
  868. foreach ( $imcStaff as $key => $value ) {
  869. array_push ( $cidList, $value ['cid'] );
  870. }
  871. if (empty ( $cidList )) {
  872. $cidString = $this->staff [0] ['cid'];
  873. } else {
  874. $cidString = implode ( ',', $cidList );
  875. $cidString .= $cidString . ',' . $this->staff [0] ['cid'];
  876. }
  877. $itTodoList = $invoiceTraining->getInvoiceTrainingByTodo ( '', $cidString, $this->staff [0] ['sid'] );
  878. $itedList = $invoiceTraining->getInvoiceTrainingByStatus ( 2, '', $cidString, $this->staff [0] ['sid'] );
  879. $category = $lCategory->getCategory ();
  880. $itid = array ();
  881. foreach ( $itTodoList as $key => $value ) {
  882. array_push ( $itid, $value ['itid'] );
  883. // 如果入账100%更新为已完成
  884. if ($itTodoList [$key] ['arriveSchedule'] >= 100) {
  885. $invoiceTraining = new invoiceTraining ();
  886. $invoiceTraining->itid = $value ['itid'];
  887. $invoiceTraining->status = 2;
  888. $invoiceTraining->update ();
  889. }
  890. }
  891. foreach ( $itedList as $value ) {
  892. array_push ( $itid, $value ['itid'] );
  893. }
  894. $itid = implode ( ',', $itid );
  895. $this->data ['itStatist'] = $invoiceTraining->getInvoiceTrainStatistics ( $itid );
  896. // print_r($itTodoList);
  897. $this->data ['trainCount'] = count ( $itTodoList ) + count ( $itedList );
  898. $this->data ['itTodoList'] = $itTodoList;
  899. $this->data ['itedList'] = $itedList;
  900. $this->data ['category'] = $category;
  901. $this->data ['memu'] = "invoice";
  902. $this->data ['staff'] = $this->staff;
  903. $this->data ['receiptMemu'] = 'invoiceTraining';
  904. $this->render ( "/admin/invoiceTraining", $this->data );
  905. }
  906. /**
  907. * 创建培训班
  908. */
  909. function invoiceTrainingAdd() {
  910. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  911. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  912. $trainDate = $this->get_args ( 'trainDate' ) ? $this->get_args ( 'trainDate' ) : "";
  913. if (empty ( $this->staff [0] ))
  914. die ( 'illegal request' );
  915. if (! empty ( $cid ) && ! empty ( $trainName ) && ! empty ( $trainDate )) {
  916. Doo::loadModel ( 'invoiceTraining' );
  917. $invoiceTraining = new invoiceTraining ();
  918. Doo::loadModel ( 'invoice' );
  919. $invoice = new invoice ();
  920. Doo::loadModel ( 'L_category' );
  921. $lCategory = new L_category ();
  922. Doo::loadModel ( 'invoiceManage' );
  923. $invoiceManage = new invoiceManage ();
  924. Doo::loadModel ( 'invoiceOperationLog' );
  925. $invoiceOperationLog = new invoiceOperationLog ();
  926. $item = array (
  927. 'cid' => $cid,
  928. 'trainName' => $trainName,
  929. 'trainDate' => $trainDate,
  930. 'creator' => $this->staff [0] ['sid'],
  931. 'creatorDate' => date ( "Y-m-d H:i:s" )
  932. );
  933. $itid = $invoiceTraining->addInvoiceTraining ( $item );
  934. }
  935. return "/invoiceTraining";
  936. }
  937. /**
  938. * 删除培训班
  939. */
  940. function invoiceTrainingDelDo() {
  941. $itid = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  942. if (! empty ( $itid )) {
  943. Doo::loadModel ( 'invoiceTraining' );
  944. $invoiceTraining = new invoiceTraining ();
  945. $invoiceTraining->delInvoiceTrainingByItid ( $itid );
  946. }
  947. return "/invoiceTraining";
  948. }
  949. /**
  950. * 培训班详情
  951. */
  952. function invoiceTrainingDetail() {
  953. $trainStatus = $this->get_args ( 'trainStatus' ) ? $this->get_args ( 'trainStatus' ) : "ALL";
  954. $itid = isset ( $this->params ['trainingKey'] ) ? $this->params ['trainingKey'] : "";
  955. Doo::loadModel ( 'invoiceTraining' );
  956. $invoiceTraining = new invoiceTraining ();
  957. Doo::loadModel ( 'invoiceStore' );
  958. $invoiceStore = new invoiceStore ();
  959. if (empty ( $itid ))
  960. die ( 'illegal request' );
  961. $con = ' (b.untreadStatus is null or b.untreadStatus!=2) and ';
  962. if ($trainStatus == "SUBED")
  963. $con = ' (b.untreadStatus is null ) and ';
  964. elseif ($trainStatus == "APPROVAL")
  965. $con = ' ( b.status=1 and b.untreadStatus!=2 ) and ';
  966. elseif ($trainStatus == "TICKET")
  967. $con = ' (b.printStatus=1 and b.status=2 and b.untreadStatus!=2) and ';
  968. elseif ($trainStatus == "TICKETING") {
  969. $con = ' (b.status=2 and b.untreadStatus=1) and ';
  970. }
  971. $detail = $invoiceTraining->getInvoiceTrainingByItid ( $itid );
  972. $isList = $invoiceStore->getinvoiceStoreByItid ( $itid, $con );
  973. //print_r($isList);
  974. $trainlist = array ();
  975. foreach ( $isList as $key => $value ) {
  976. $irDetail = array ();
  977. if ($value ['apStatus'] == 1) {
  978. // array_push ( $irDetail, '' );
  979. array_push ( $irDetail, '<input disabled type="checkbox" style="display:none" >' );
  980. } else {
  981. array_push ( $irDetail, '<input type="checkbox" class="hide" id="' . $value ['storeKey'] . '" name="isBox" value="' . $value ['storeKey'] . '" > <a href="/invoiceStoreEdit/' . $value ['storeKey'] . '.html">编辑</a>
  982. <a href="#confirm" onclick="invoiceStoreApproval(\'' . $value ['storeKey'] . '\')" data-toggle="modal">提交审批</a>
  983. <a href="#del" node-iStore="del" data-key="' . $value ['storeKey'] . '" onclick="invoiceStoreDel(\'' . $value ['storeKey'] . '\')" data-toggle="modal" class="colRed">移除</a>' );
  984. }
  985. array_push ( $irDetail, $value ['invoiceSerial'] );
  986. if ($value ['invoiceType'] == 1)
  987. array_push ( $irDetail, $value ['invoiceCompany'] );
  988. else
  989. array_push ( $irDetail, $value ['invoiceTitle'] );
  990. array_push ( $irDetail, $value ['TIN'] );
  991. array_push ( $irDetail, $value ['userName'] );
  992. if (empty ( $value ['mailItems'] ) && $value ['apStatus'] != 1) {
  993. array_push ( $irDetail, '<a href="#confirm-erro" onclick="invoiceStoreMail(\'' . $value ['storeKey'] . '\')" data-toggle="modal">设置邮寄物品</a>' );
  994. } else
  995. array_push ( $irDetail, $value ['mailItems'] );
  996. array_push ( $irDetail, $value ['recipientsAddress'] . $value ['recipients'] . $value ['recipientsPhone'] );
  997. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  998. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  999. array_push ( $irDetail, $value ['invoiceElement'] );
  1000. array_push ( $irDetail, $value ['invoiceQuantity'] );
  1001. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  1002. if ($value ['invoiceType'] == 1)
  1003. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  1004. else
  1005. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  1006. array_push ( $irDetail, $value ['remark'] );
  1007. if ($value ['status'] == 1)
  1008. array_push ( $irDetail, '审批中' );
  1009. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1)
  1010. array_push ( $irDetail, '已出票' );
  1011. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1 && $value ['printStatus'] != 'irid' && ($value ['untreadStatus'] == 3 || $value ['untreadStatus'] == 0))
  1012. array_push ( $irDetail, '已入账' );
  1013. else
  1014. array_push ( $irDetail, '' );
  1015. array_push ( $irDetail, $value ['invoiceNo'] );
  1016. array_push ( $irDetail, $value ['printTime'] );
  1017. $html = '';
  1018. foreach ( $value ['invoiceReceivables'] as $value ) {
  1019. $html .= '&nbsp;<a href="#billing" node-invoice="INFO" data-type="receivables" data-iskey="' . $value [2] . '" data-toggle="modal">' . $value [1] . '</a>';
  1020. }
  1021. array_push ( $irDetail, $html );
  1022. array_push ( $trainlist, $irDetail );
  1023. }
  1024. $trainlistJson = json_encode ( $trainlist );
  1025. if (empty ( $detail ))
  1026. die ( 'illegal request' );
  1027. // 培训班结算是否有和是否已经结算完成
  1028. Doo::loadModel ( 'receipt' );
  1029. $receipt = new receipt ();
  1030. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $itid );
  1031. $this->data ['receiptDetail'] = $receiptDetail;
  1032. $this->data ['trainStatus'] = $trainStatus;
  1033. $this->data ['itid'] = $itid;
  1034. $this->data ['trainlistJson'] = $trainlistJson;
  1035. $this->data ['iTrainDetail'] = $detail;
  1036. $this->data ['memu'] = "invoice";
  1037. $this->data ['staff'] = $this->staff;
  1038. $this->data ['receiptMemu'] = 'invoiceTraining';
  1039. $this->render ( "/admin/invoiceTrainingDetail", $this->data );
  1040. }
  1041. /**
  1042. * 上传培训班发票
  1043. * @return string
  1044. */
  1045. function invoiceTrainingUpload() {
  1046. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  1047. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  1048. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  1049. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  1050. header ( "HTTP/1.1 500 Internal Server Error" );
  1051. echo "POST exceeded maximum allowed size.";
  1052. exit ( 0 );
  1053. }
  1054. // Settings
  1055. $save_path = DOO::conf ()->SITE_PATH . "upload/invoiceTraining/"; // The path were we will save the file (getcwd() may not be reliable and should be tested in your environment)
  1056. $upload_name = "Filedata";
  1057. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  1058. $extension_whitelist = array (
  1059. "doc",
  1060. "txt",
  1061. "jpg",
  1062. "gif",
  1063. "png"
  1064. ); // Allowed file extensions
  1065. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  1066. // Other variables
  1067. $MAX_FILENAME_LENGTH = 260;
  1068. $file_name = "";
  1069. $file_extension = "";
  1070. $uploadErrors = array (
  1071. 0 => "文件上传成功",
  1072. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  1073. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  1074. 3 => "上传的文件仅为部分文件",
  1075. 4 => "没有文件上传",
  1076. 6 => "缺少临时文件夹"
  1077. );
  1078. $nk = time ();
  1079. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  1080. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  1081. echo "文件无法保存.";
  1082. exit ( 0 );
  1083. }
  1084. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  1085. echo json_encode ( array (
  1086. 'filename' => $file_name,
  1087. 'id' => $nk
  1088. ) );
  1089. exit ( 0 );
  1090. }
  1091. /**
  1092. * 导入发票临时仓库
  1093. */
  1094. function invoiceStoreImport() {
  1095. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  1096. $trainingKey = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  1097. $path = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  1098. if ($path != "" && ! empty ( $trainingKey )) {
  1099. Doo::loadModel ( 'invoiceStore' );
  1100. Doo::loadModel ( 'staff' );
  1101. $staff = new staff ();
  1102. Doo::loadModel ( 'invoiceTraining' );
  1103. $invoiceTraining = new invoiceTraining ();
  1104. Doo::loadClass ( 'XDeode' );
  1105. $XDeode = new XDeode ( 5 );
  1106. $itid = $XDeode->decode ( $trainingKey );
  1107. // 培训班结算是否有和是否已经结算完成
  1108. Doo::loadModel ( 'receipt' );
  1109. $receipt = new receipt ();
  1110. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $itid );
  1111. if (! empty ( $receiptDetail )) {
  1112. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9)
  1113. die ( 'illegal request--status' );
  1114. }
  1115. $exlArray = $this->formatExcelToArrayTrain ( DOO::conf ()->SITE_PATH . "upload/invoiceTraining/" . $path );
  1116. $userName = $this->staff [0] ['username'];
  1117. $sDetail = $staff->getStaffByName ( $userName );
  1118. // die('sdd');
  1119. // 可以优化
  1120. foreach ( $exlArray as $key => $value ) {
  1121. // 开票
  1122. $invoice = new invoiceStore ();
  1123. $invoice->trainId = $itid;
  1124. $invoice->invoiceType = 0;
  1125. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  1126. $invoice->invoiceType = 1;
  1127. $invoice->invoiceQuantity = $value ['invoiceQuantity'];
  1128. $invoice->invoiceUnitPrice = $value ['invoiceUnitPrice'];
  1129. $invoice->invoicePrice = $value ['invoiceQuantity'] * $value ['invoiceUnitPrice'];
  1130. $invoice->invoiceTitle = $value ['invoiceTitle'];
  1131. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  1132. $invoice->invoiceCompany = $value ['invoiceTitle'];
  1133. $invoice->userName = $userName;
  1134. $invoice->sid = $sDetail ['sid'];
  1135. $invoice->cid = $sDetail ['cid'];
  1136. $invoice->categoryName = $sDetail ['category'];
  1137. $invoice->invoiceElement = $value ['invoiceElement'];
  1138. $invoice->remark = $value ['remark'];
  1139. // $invoice->date = $value ['date'];
  1140. // $invoice->printTime = $value ['date'];
  1141. $invoice->ipSource = 1;
  1142. $invoice->printStatus = 0;
  1143. $invoice->status = 0;
  1144. $invoice->postStatus = 1;
  1145. $invoice->untreadStatus = 0;
  1146. // $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1147. $invoice->TIN = $value ['TIN'];
  1148. $invoice->address = $value ['address'];
  1149. $invoice->phone = $value ['phone'];
  1150. $invoice->bank = $value ['bank'];
  1151. $invoice->bankAccount = $value ['bankAccount'];
  1152. $invoice->recipientsAddress = $value ['recipientsAddress'];
  1153. $invoice->recipients = $value ['recipients'];
  1154. $invoice->recipientsPhone = $value ['recipientsPhone'];
  1155. $iid = $invoice->insert ();
  1156. }
  1157. // 加入发票总数量
  1158. $item = array (
  1159. 'itid' => $itid,
  1160. 'invoiceTotal' => count ( $exlArray )
  1161. );
  1162. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1163. return '/invoiceTrainingDetail/' . $trainingKey . ".html";
  1164. }
  1165. echo 'no file';
  1166. }
  1167. /**
  1168. * 编辑仓库里的发票
  1169. */
  1170. function invoiceStoreEdit() {
  1171. Doo::loadClass ( 'XDeode' );
  1172. $XDeode = new XDeode ( 5 );
  1173. $iid = isset ( $this->params ['storeKey'] ) ? $this->params ['storeKey'] : "";
  1174. $iid = $XDeode->decode ( $iid );
  1175. if (! is_numeric ( $iid ))
  1176. die ( 'illegal request' );
  1177. Doo::loadModel ( 'invoiceStore' );
  1178. $invoiceStore = new invoiceStore ();
  1179. $invoiceDetail = $invoiceStore->getInvoiceStoreByIsid ( $iid );
  1180. // print_r($invoiceDetail);
  1181. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  1182. $this->data ['invoiceDetail'] = $invoiceDetail;
  1183. $this->data ['memu'] = "invoice";
  1184. $this->data ['staff'] = $this->staff;
  1185. $this->data ['receiptMemu'] = 'invoiceTraining';
  1186. $this->render ( "/admin/invoiceStoreEdit", $this->data );
  1187. }
  1188. function invoiceStoreEditDo() {
  1189. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1190. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1191. Doo::loadModel ( 'invoiceStore' );
  1192. $invoice = new invoiceStore ();
  1193. Doo::loadClass ( 'XDeode' );
  1194. $XDeode = new XDeode ( 5 );
  1195. $iid = $XDeode->decode ( $storeKey );
  1196. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1197. die ( 'illegal request' );
  1198. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  1199. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  1200. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  1201. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  1202. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  1203. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  1204. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  1205. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  1206. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  1207. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  1208. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  1209. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  1210. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  1211. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  1212. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1213. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1214. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1215. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1216. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  1217. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  1218. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  1219. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  1220. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  1221. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  1222. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1223. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1224. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1225. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1226. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1227. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1228. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1229. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  1230. $cid = explode ( ':', $cid );
  1231. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  1232. $item = array (
  1233. 'isid' => $iid,
  1234. 'cid' => $cid [0],
  1235. 'categoryName' => $cid [1],
  1236. 'invoiceElement' => $invoiceElement,
  1237. 'invoiceQuantity' => $invoiceQuantity,
  1238. 'invoiceUnitPrice' => $invoiceUnitPrice,
  1239. 'invoicePrice' => $invoicePrice,
  1240. 'invoiceType' => $invoiceType,
  1241. 'doPost' => $doPost,
  1242. 'status' => 1,
  1243. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1244. 'remark' => $remark
  1245. );
  1246. if ($invoiceType == 0)
  1247. $item += array (
  1248. 'invoiceTitle' => $invoiceTitle,
  1249. 'TIN' => $TINT,
  1250. 'address' => $addressT,
  1251. 'phone' => $phoneT,
  1252. 'bank' => $bankT,
  1253. 'bankAccount' => $bankAccountT
  1254. );
  1255. else {
  1256. $item += array (
  1257. 'invoiceCompany' => $invoiceCompany,
  1258. 'TIN' => $TIN,
  1259. 'address' => $address,
  1260. 'phone' => $phone,
  1261. 'bank' => $bank,
  1262. 'bankAccount' => $bankAccount
  1263. );
  1264. }
  1265. if ($doPost == 1) {
  1266. $mailList = array (
  1267. 'invoice' => 1,
  1268. 'mailItems' => $mailItems
  1269. );
  1270. if (! empty ( $softLock ))
  1271. $mailList += array (
  1272. 'softLock' => $softLockNum
  1273. );
  1274. else
  1275. $mailList += array (
  1276. 'softLock' => '0'
  1277. );
  1278. if (! empty ( $contract ))
  1279. $mailList += array (
  1280. 'contract' => $contractNum
  1281. );
  1282. else
  1283. $mailList += array (
  1284. 'contract' => '0'
  1285. );
  1286. if (! empty ( $instructions ))
  1287. $mailList += array (
  1288. 'instructions' => $instructionsNum
  1289. );
  1290. else
  1291. $mailList += array (
  1292. 'instructions' => '0'
  1293. );
  1294. if (! empty ( $remittance ))
  1295. $mailList += array (
  1296. 'remittance' => $remittance
  1297. );
  1298. else
  1299. $mailList += array (
  1300. 'remittance' => ''
  1301. );
  1302. $mailString = '发票x1,备注:' . $mailItems;
  1303. if (! empty ( $softLock ))
  1304. $mailString .= ',软件锁x' . $softLockNum;
  1305. if (! empty ( $contract ))
  1306. $mailString .= ',合同x' . $contractNum;
  1307. if (! empty ( $instructions ))
  1308. $mailString .= ',说明书x' . $instructionsNum;
  1309. if (! empty ( $remittance ))
  1310. $mailString .= ',汇款账号单';
  1311. $item += array (
  1312. 'recipients' => $recipients,
  1313. 'recipientsPhone' => $recipientsPhone,
  1314. 'recipientsAddress' => $recipientsAddress,
  1315. 'mailItems' => $mailString,
  1316. 'mailItemsJson' => json_encode ( $mailList )
  1317. );
  1318. }
  1319. $invoice->setInvoiceStoreByCondition ( $item );
  1320. }
  1321. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1322. }
  1323. /**
  1324. *
  1325. * @return string
  1326. */
  1327. function invoiceStoreDelete() {
  1328. Doo::loadClass ( 'XDeode' );
  1329. $XDeode = new XDeode ( 5 );
  1330. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1331. $iStoreKey = $this->get_args ( 'iStoreKey' ) ? $this->get_args ( 'iStoreKey' ) : 0;
  1332. $isid = $XDeode->decode ( $iStoreKey );
  1333. $itid = $XDeode->decode ( $trainKey );
  1334. if (! is_numeric ( $isid ))
  1335. die ( 'illegal request' );
  1336. Doo::loadModel ( 'invoiceStore' );
  1337. $invoiceStore = new invoiceStore ();
  1338. $invoiceStore->delete ( array (
  1339. 'where' => 'isid=' . $isid,
  1340. 'limit' => 1
  1341. ) );
  1342. Doo::loadModel ( 'invoiceTraining' );
  1343. $invoiceTraining = new invoiceTraining ();
  1344. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1345. $item = array (
  1346. 'itid' => $itid,
  1347. 'invoiceTotal' => $itDetail ['invoiceTotal'] - 1
  1348. );
  1349. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1350. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1351. }
  1352. /**
  1353. * 批量删除库里发票
  1354. */
  1355. function invoiceStoreBatchDelete() {
  1356. Doo::loadClass ( 'XDeode' );
  1357. $XDeode = new XDeode ( 5 );
  1358. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1359. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1360. if (empty ( $trainKey ) || empty ( $storeKey ))
  1361. die ( 'illegal request-IdKey' );
  1362. $tid = $XDeode->decode ( $trainKey );
  1363. if (! is_numeric ( $tid ) && ! empty ( $storeKey ))
  1364. die ( 'illegal request' );
  1365. Doo::loadModel ( 'invoiceStore' );
  1366. $isidKeyList = explode ( ',', $storeKey );
  1367. $isidList = array ();
  1368. foreach ( $isidKeyList as $value ) {
  1369. $isid = $XDeode->decode ( $value );
  1370. if (! empty ( $isid ) && is_numeric ( $isid ))
  1371. array_push ( $isidList, $isid );
  1372. }
  1373. $isidString = implode ( ',', $isidList );
  1374. $invoiceStore = new invoiceStore ();
  1375. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,apStatus' );
  1376. $isidList = array ();
  1377. foreach ( $isList as $key => $value ) {
  1378. if ($value ['apStatus'] == 0)
  1379. array_push ( $isidList, $value ['isid'] );
  1380. }
  1381. $isidString = implode ( ',', $isidList );
  1382. // print_r($isList);
  1383. // echo $isidString;
  1384. $invoiceStore = new invoiceStore ();
  1385. $invoiceStore->delete ( array (
  1386. 'where' => "isid in ( " . $isidString . ")",
  1387. 'asArray' => TRUE
  1388. ) );
  1389. Doo::loadModel ( 'invoiceTraining' );
  1390. $invoiceTraining = new invoiceTraining ();
  1391. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1392. $item = array (
  1393. 'itid' => $tid,
  1394. 'invoiceTotal' => $itDetail ['invoiceTotal'] - count ( $isidList )
  1395. );
  1396. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1397. // echo $tid;
  1398. // echo $storeKey;
  1399. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1400. }
  1401. /**
  1402. * 仓库发票提交审批
  1403. * @return string
  1404. */
  1405. function invoiceStoreApproval() {
  1406. Doo::loadClass ( 'XDeode' );
  1407. $XDeode = new XDeode ( 5 );
  1408. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1409. $iStoreKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1410. $isid = $XDeode->decode ( $iStoreKey );
  1411. $trainId = $XDeode->decode ( $trainKey );
  1412. if (! is_numeric ( $isid ))
  1413. die ( 'illegal request' );
  1414. Doo::loadModel ( 'invoiceStore' );
  1415. Doo::loadModel ( 'invoice' );
  1416. $invoice = new invoice ();
  1417. // 加入限制必须填写入开票内容和邮寄物品
  1418. $invoiceStore = new invoiceStore ();
  1419. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid, 'isid,trainId ,invoiceElement,mailItemsJson' );
  1420. if (empty ( $isDetail ['invoiceElement'] ) || empty ( $isDetail ['mailItemsJson'] )) {
  1421. header ( 'Content-Type:text/html;charset=utf-8' );
  1422. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1423. }
  1424. // 拷贝插入一条发票数据
  1425. $invoiceStore = new invoiceStore ();
  1426. $iid = $invoiceStore->setInvoiceStoreToApproval ( $isid );
  1427. $invoiceStore = new invoiceStore ();
  1428. $item = array (
  1429. 'isid' => $isid,
  1430. 'iid' => $iid,
  1431. 'apStatus' => 1
  1432. );
  1433. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1434. Doo::loadModel ( 'invoiceManage' );
  1435. $invoiceManage = new invoiceManage ();
  1436. Doo::loadModel ( 'invoiceOperationLog' );
  1437. $invoiceOperationLog = new invoiceOperationLog ();
  1438. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1439. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1440. $moldManage = array ();
  1441. foreach ( $invoiceManageList as $key => $value ) {
  1442. if ($value ['mold'] == '发票打印')
  1443. $moldManage [$value ['mold']] = $value ['staffList'];
  1444. elseif ($value ['mold'] == '发票邮寄')
  1445. $moldManage [$value ['mold']] = $value ['staffList'];
  1446. elseif ($value ['mold'] == '发票退票')
  1447. $moldManage [$value ['mold']] = $value ['staffList'];
  1448. }
  1449. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1450. $item = array (
  1451. 'iid' => $iid,
  1452. 'isid' => $isid,
  1453. 'invoiceSerial' => "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  1454. 'date' => date ( "Y-m-d H:i:s" ),
  1455. 'status' => 1,
  1456. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1457. 'trainId' => $trainId,
  1458. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1459. 'moldManage' => json_encode ( $moldManage ),
  1460. 'settlementType' => 1,
  1461. 'pendingApprovals' => $pendingApprovalsSid
  1462. );
  1463. $invoice->setInvoiceByCondition ( $item );
  1464. Doo::loadModel ( 'invoiceTraining' );
  1465. $invoiceTraining = new invoiceTraining ();
  1466. $item = array (
  1467. 'itid' => $trainId,
  1468. 'submitStatus' => 1
  1469. );
  1470. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1471. $item = array (
  1472. 'date' => date ( "Y-m-d H:i:s" ),
  1473. 'operation' => "创建",
  1474. 'status' => 1,
  1475. 'img' => $this->staff [0] ['avatar'],
  1476. 'username' => $this->staff [0] ['username'],
  1477. 'uid' => $this->staff [0] ['sid'],
  1478. 'category' => $this->staff [0] ['category'],
  1479. 'iid' => $iid
  1480. );
  1481. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1482. $item = array (
  1483. 'date' => date ( "Y-m-d H:i:s" ),
  1484. 'operation' => "提交审批",
  1485. 'status' => 1,
  1486. 'img' => $this->staff [0] ['avatar'],
  1487. 'username' => $this->staff [0] ['username'],
  1488. 'uid' => $this->staff [0] ['sid'],
  1489. 'category' => $this->staff [0] ['category'],
  1490. 'iid' => $iid
  1491. );
  1492. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1493. Doo::loadModel ( 'staff' );
  1494. $staff = new staff ();
  1495. $username2 = $staff->getOne ( array (
  1496. 'select' => 'wxid',
  1497. 'where' => 'sid=' . $pendingApprovalsSid,
  1498. 'asArray' => TRUE
  1499. ) );
  1500. // 发送微信审批通知
  1501. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1502. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1503. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1504. }
  1505. /**
  1506. * 批量提交发票
  1507. * @return string
  1508. */
  1509. function invoiceStoreBatchApproval() {
  1510. Doo::loadClass ( 'XDeode' );
  1511. $XDeode = new XDeode ( 5 );
  1512. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1513. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1514. if (empty ( $trainKey ) || empty ( $storeKey ))
  1515. die ( 'illegal request-IdKey' );
  1516. $trainId = $XDeode->decode ( $trainKey );
  1517. $isidKeyList = explode ( ',', $storeKey );
  1518. $isidList = array ();
  1519. foreach ( $isidKeyList as $value ) {
  1520. $isid = $XDeode->decode ( $value );
  1521. if (! empty ( $isid ) && is_numeric ( $isid ))
  1522. array_push ( $isidList, $isid );
  1523. }
  1524. $isidString = implode ( ',', $isidList );
  1525. if (! is_numeric ( $trainId ))
  1526. die ( 'illegal request' );
  1527. Doo::loadModel ( 'invoiceStore' );
  1528. Doo::loadModel ( 'invoice' );
  1529. // 判断哪些已经加入审批过
  1530. // 加入限制必须填写入开票内容和邮寄物品
  1531. $invoiceStore = new invoiceStore ();
  1532. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,trainId ,invoiceElement,mailItemsJson' );
  1533. foreach ( $isList as $key => $value ) {
  1534. if (empty ( $value ['invoiceElement'] ) || empty ( $value ['mailItemsJson'] )) {
  1535. header ( 'Content-Type:text/html;charset=utf-8' );
  1536. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1537. }
  1538. }
  1539. // 拷贝插入一条发票数据
  1540. $invoiceStore = new invoiceStore ();
  1541. $invoiceStore->setInvoiceStoreBatchToApproval ( $isidString );
  1542. $invoiceStore = new invoiceStore ();
  1543. $item = array (
  1544. 'apStatus' => 1
  1545. );
  1546. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1547. // 获得正式发票ID
  1548. $invoice = new invoice ();
  1549. $iidList = $invoice->getInvoiceByIstoreid ( $isidString, 'iid,isid' );
  1550. $sqlList = array ();
  1551. $iidString = '';
  1552. $iida = array ();
  1553. foreach ( $iidList as $key => $value ) {
  1554. $sqlList [$value ['isid']] = $value ['iid'];
  1555. array_push ( $iida, $value ['iid'] );
  1556. }
  1557. $iidString = implode ( ',', $iida );
  1558. $ids = implode ( ',', array_keys ( $sqlList ) );
  1559. $sql = "UPDATE CLD_invoiceStore SET iid = CASE isid ";
  1560. foreach ( $sqlList as $id => $ordinal ) {
  1561. $sql .= sprintf ( "WHEN %d THEN %d ", $id, $ordinal );
  1562. }
  1563. $sql .= "END WHERE isid IN ($ids)";
  1564. $invoiceStore = new invoiceStore ();
  1565. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1566. Doo::loadModel ( 'invoiceManage' );
  1567. $invoiceManage = new invoiceManage ();
  1568. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1569. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1570. $moldManage = array ();
  1571. foreach ( $invoiceManageList as $key => $value ) {
  1572. if ($value ['mold'] == '发票打印')
  1573. $moldManage [$value ['mold']] = $value ['staffList'];
  1574. elseif ($value ['mold'] == '发票邮寄')
  1575. $moldManage [$value ['mold']] = $value ['staffList'];
  1576. elseif ($value ['mold'] == '发票退票')
  1577. $moldManage [$value ['mold']] = $value ['staffList'];
  1578. }
  1579. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1580. // 批量更新发票信息
  1581. $item = array (
  1582. 'date' => date ( "Y-m-d H:i:s" ),
  1583. 'status' => 1,
  1584. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1585. 'trainId' => $trainId,
  1586. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1587. 'moldManage' => json_encode ( $moldManage ),
  1588. 'settlementType' => 1,
  1589. 'pendingApprovals' => $pendingApprovalsSid
  1590. );
  1591. $invoice = new invoice ();
  1592. $invoice->BatchInvoiceByCondition ( $item, $iidString );
  1593. // 批量更新发票中仓库isid
  1594. $sql = "UPDATE CLD_invoiceStore SET isid = CASE iid ";
  1595. foreach ( $sqlList as $isid => $iid ) {
  1596. $sql .= sprintf ( "WHEN %d THEN %d ", $iid, $isid );
  1597. }
  1598. $sql .= "END WHERE iid IN ($iidString)";
  1599. $invoice = new invoice ();
  1600. $invoice->UpdateBatchInvoice ( $sql );
  1601. // 批量更新发票序列号
  1602. $sqlList = array ();
  1603. foreach ( $iida as $value ) {
  1604. $sqlList [$value] = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1605. }
  1606. $ids = implode ( ',', array_keys ( $sqlList ) );
  1607. $sql = "UPDATE CLD_invoice SET invoiceSerial = CASE iid ";
  1608. foreach ( $sqlList as $id => $ordinal ) {
  1609. $sql .= sprintf ( "WHEN %d THEN '%s' ", $id, $ordinal );
  1610. }
  1611. $sql .= "END WHERE iid IN ($ids)";
  1612. $invoiceStore = new invoiceStore ();
  1613. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1614. // 批量生产操作日志
  1615. Doo::loadModel ( 'invoiceOperationLog' );
  1616. $sqlList = array ();
  1617. foreach ( $iida as $key => $value ) {
  1618. $sql = '("' . date ( "Y-m-d H:i:s" ) . '","创建","1","' . $this->staff [0] ['avatar'] . '","' . $this->staff [0] ['username'] . '","' . $this->staff [0] ['sid'] . '","' . $this->staff [0] ['category'] . '","' . $value . '"),
  1619. ("' . date ( "Y-m-d H:i:s" ) . '","提交审批","1","' . $this->staff [0] ['avatar'] . '","' . $this->staff [0] ['username'] . '","' . $this->staff [0] ['sid'] . '","' . $this->staff [0] ['category'] . '","' . $value . '") ';
  1620. array_push ( $sqlList, $sql );
  1621. }
  1622. $iolSql = implode ( ',', $sqlList );
  1623. $sql = "INSERT INTO `CLD_invoiceOperationLog` (`date`, `operation`, `status`, `img`, `username`, `uid`, `category`, `iid`) VALUES " . $iolSql;
  1624. $invoiceOperationLog = new invoiceOperationLog ();
  1625. $invoiceOperationLog->setInvoiceOperationLogBySql ( $sql );
  1626. Doo::loadModel ( 'invoiceTraining' );
  1627. $invoiceTraining = new invoiceTraining ();
  1628. $item = array (
  1629. 'itid' => $trainId,
  1630. 'submitStatus' => 1
  1631. );
  1632. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1633. Doo::loadModel ( 'staff' );
  1634. $staff = new staff ();
  1635. $username2 = $staff->getOne ( array (
  1636. 'select' => 'wxid',
  1637. 'where' => 'sid=' . $pendingApprovalsSid,
  1638. 'asArray' => TRUE
  1639. ) );
  1640. // 发送微信审批通知
  1641. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1642. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1643. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1644. }
  1645. /**
  1646. */
  1647. function invoiceStoreMailItemSet() {
  1648. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1649. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1650. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1651. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1652. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1653. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1654. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1655. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1656. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1657. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1658. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1659. Doo::loadClass ( 'XDeode' );
  1660. $XDeode = new XDeode ( 5 );
  1661. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1662. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1663. $isid = $XDeode->decode ( $storeKey );
  1664. $trainId = $XDeode->decode ( $trainKey );
  1665. if (! is_numeric ( $isid ))
  1666. die ( 'illegal request' );
  1667. Doo::loadModel ( 'invoiceStore' );
  1668. $invoiceStore = new invoiceStore ();
  1669. $mailList = array (
  1670. 'invoice' => 1,
  1671. 'mailItems' => $mailItems
  1672. );
  1673. if (! empty ( $softLock ))
  1674. $mailList += array (
  1675. 'softLock' => $softLockNum
  1676. );
  1677. else
  1678. $mailList += array (
  1679. 'softLock' => 0
  1680. );
  1681. if (! empty ( $contract ))
  1682. $mailList += array (
  1683. 'contract' => $contractNum
  1684. );
  1685. else
  1686. $mailList += array (
  1687. 'contract' => 0
  1688. );
  1689. if (! empty ( $instructions ))
  1690. $mailList += array (
  1691. 'instructions' => $instructionsNum
  1692. );
  1693. else
  1694. $mailList += array (
  1695. 'instructions' => 0
  1696. );
  1697. if (! empty ( $remittance ))
  1698. $mailList += array (
  1699. 'remittance' => $remittance
  1700. );
  1701. else
  1702. $mailList += array (
  1703. 'remittance' => ''
  1704. );
  1705. $mailString = '发票x1,备注:' . $mailItems;
  1706. if (! empty ( $softLock ))
  1707. $mailString .= ',软件锁x' . $softLockNum;
  1708. if (! empty ( $contract ))
  1709. $mailString .= ',合同x' . $contractNum;
  1710. if (! empty ( $instructions ))
  1711. $mailString .= ',说明书x' . $instructionsNum;
  1712. if (! empty ( $remittance ))
  1713. $mailString .= ',汇款账号单';
  1714. $item = array (
  1715. 'isid' => $isid,
  1716. 'doPost' => 1,
  1717. 'mailItems' => $mailString,
  1718. 'mailItemsJson' => json_encode ( $mailList )
  1719. );
  1720. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1721. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1722. }
  1723. /**
  1724. * 批量设置邮寄物品
  1725. */
  1726. function invoiceStoreBatchMailItemSet() {
  1727. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1728. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1729. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1730. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1731. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1732. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1733. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1734. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1735. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1736. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1737. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1738. Doo::loadClass ( 'XDeode' );
  1739. $XDeode = new XDeode ( 5 );
  1740. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1741. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1742. if (empty ( $trainKey ) || empty ( $storeKey ))
  1743. die ( 'illegal request-IdKey' );
  1744. $isidKeyList = explode ( ',', $storeKey );
  1745. $isidList = array ();
  1746. foreach ( $isidKeyList as $value ) {
  1747. $isid = $XDeode->decode ( $value );
  1748. if (! empty ( $isid ) && is_numeric ( $isid ))
  1749. array_push ( $isidList, $isid );
  1750. }
  1751. $isidString = implode ( ',', $isidList );
  1752. $trainId = $XDeode->decode ( $trainKey );
  1753. if (! is_numeric ( $isid ))
  1754. die ( 'illegal request' );
  1755. Doo::loadModel ( 'invoiceStore' );
  1756. $invoiceStore = new invoiceStore ();
  1757. $mailList = array (
  1758. 'invoice' => 1,
  1759. 'mailItems' => $mailItems
  1760. );
  1761. if (! empty ( $softLock ))
  1762. $mailList += array (
  1763. 'softLock' => $softLockNum
  1764. );
  1765. else
  1766. $mailList += array (
  1767. 'softLock' => 0
  1768. );
  1769. if (! empty ( $contract ))
  1770. $mailList += array (
  1771. 'contract' => $contractNum
  1772. );
  1773. else
  1774. $mailList += array (
  1775. 'contract' => 0
  1776. );
  1777. if (! empty ( $instructions ))
  1778. $mailList += array (
  1779. 'instructions' => $instructionsNum
  1780. );
  1781. else
  1782. $mailList += array (
  1783. 'instructions' => 0
  1784. );
  1785. if (! empty ( $remittance ))
  1786. $mailList += array (
  1787. 'remittance' => $remittance
  1788. );
  1789. else
  1790. $mailList += array (
  1791. 'remittance' => ''
  1792. );
  1793. $mailString = '发票x1,备注:' . $mailItems;
  1794. if (! empty ( $softLock ))
  1795. $mailString .= ',软件锁x' . $softLockNum;
  1796. if (! empty ( $contract ))
  1797. $mailString .= ',合同x' . $contractNum;
  1798. if (! empty ( $instructions ))
  1799. $mailString .= ',说明书x' . $instructionsNum;
  1800. if (! empty ( $remittance ))
  1801. $mailString .= ',汇款账号单';
  1802. $item = array (
  1803. 'doPost' => 1,
  1804. 'mailItems' => $mailString,
  1805. 'mailItemsJson' => json_encode ( $mailList )
  1806. );
  1807. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1808. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1809. }
  1810. /**
  1811. * 废弃
  1812. */
  1813. function ajaxGetMailItemByIstore() {
  1814. Doo::loadClass ( 'XDeode' );
  1815. $XDeode = new XDeode ( 5 );
  1816. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1817. $isid = $XDeode->decode ( $storeKey );
  1818. if (! is_numeric ( $isid ))
  1819. die ( 'illegal request' );
  1820. Doo::loadModel ( 'invoiceStore' );
  1821. $invoiceStore = new invoiceStore ();
  1822. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid );
  1823. $isDetail ['mailItemsJson'] = json_decode ( $isDetail ['mailItemsJson'], true );
  1824. echo json_encode ( $isDetail ['mailItemsJson'] );
  1825. exit ();
  1826. }
  1827. /**
  1828. * 终止开票
  1829. */
  1830. function invoiceDroppedDo() {
  1831. $droppedIidKey = $this->get_args ( 'droppedIidKey' ) ? $this->get_args ( 'droppedIidKey' ) : '';
  1832. Doo::loadModel ( 'invoice' );
  1833. $invoice = new invoice ();
  1834. Doo::loadModel ( 'invoiceOperationLog' );
  1835. $invoiceOperationLog = new invoiceOperationLog ();
  1836. $iid = $invoice->authcode ( $droppedIidKey );
  1837. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1838. die ( 'illegal request' );
  1839. $item = array (
  1840. 'iid' => $iid,
  1841. 'status' => 4,
  1842. 'updateTime' => date ( "Y-m-d H:i:s" )
  1843. );
  1844. $invoice->setInvoiceByCondition ( $item );
  1845. $item = array (
  1846. 'date' => date ( "Y-m-d H:i:s" ),
  1847. 'operation' => '终止了开票',
  1848. 'status' => 4,
  1849. 'img' => $this->staff [0] ['avatar'],
  1850. 'username' => $this->staff [0] ['username'],
  1851. 'uid' => $this->staff [0] ['sid'],
  1852. 'category' => $this->staff [0] ['category'],
  1853. 'iid' => $iid
  1854. );
  1855. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1856. return "/invoice";
  1857. }
  1858. /**
  1859. * 更新退票的邮寄信息
  1860. */
  1861. function invoiceUntreadMailDo() {
  1862. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  1863. $untreadCompany = $this->get_args ( 'untreadCompany' ) ? $this->get_args ( 'untreadCompany' ) : "";
  1864. $untreadNumber = $this->get_args ( 'untreadNumber' ) ? $this->get_args ( 'untreadNumber' ) : "";
  1865. $untreadItems = $this->get_args ( 'untreadItems' ) ? $this->get_args ( 'untreadItems' ) : "";
  1866. Doo::loadModel ( 'invoice' );
  1867. $invoice = new invoice ();
  1868. $iid = $invoice->authcode ( $untreadIidKey );
  1869. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1870. die ( 'illegal request' );
  1871. $item = array (
  1872. 'iid' => $iid,
  1873. 'untreadCompany' => $untreadCompany,
  1874. 'untreadNumber' => $untreadNumber,
  1875. 'untreadItems' => $untreadItems
  1876. );
  1877. $invoice->setInvoiceByCondition ( $item );
  1878. return "/invoice";
  1879. }
  1880. /**
  1881. * 申请退票 --
  1882. */
  1883. function invoiceUntreadDo() {
  1884. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  1885. $untreadReason = $this->get_args ( 'untreadReason' ) ? $this->get_args ( 'untreadReason' ) : "";
  1886. $untreadPost = $this->get_args ( 'untreadPost' ) ? $this->get_args ( 'untreadPost' ) : "";
  1887. Doo::loadModel ( 'invoice' );
  1888. $invoice = new invoice ();
  1889. Doo::loadModel ( 'invoiceOperationLog' );
  1890. $invoiceOperationLog = new invoiceOperationLog ();
  1891. Doo::loadModel ( 'invoiceReceivables' );
  1892. $invoiceReceivables = new invoiceReceivables ();
  1893. $iid = $invoice->authcode ( $untreadIidKey );
  1894. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1895. die ( 'illegal request' );
  1896. /*
  1897. * 需求变革 有绑定收款也可以退票 $lt = $invoiceReceivables->getInvoiceReceivablesByIid ( $untreadIidKey ); if (! empty ( $lt )) { header ( 'Content-Type:text/html;charset=utf-8' ); die ( '该发票有收款绑定,请先移除!' ); }
  1898. */
  1899. $item = array (
  1900. 'iid' => $iid,
  1901. 'untreadStatus' => 1,
  1902. 'untreadReason' => $untreadReason,
  1903. 'untreadPost' => $untreadPost,
  1904. 'updateTime' => date ( "Y-m-d H:i:s" )
  1905. );
  1906. $invoice->setInvoiceByCondition ( $item );
  1907. $item = array (
  1908. 'date' => date ( "Y-m-d H:i:s" ),
  1909. 'operation' => '申请退票',
  1910. 'status' => 7,
  1911. 'img' => $this->staff [0] ['avatar'],
  1912. 'username' => $this->staff [0] ['username'],
  1913. 'uid' => $this->staff [0] ['sid'],
  1914. 'category' => $this->staff [0] ['category'],
  1915. 'iid' => $iid
  1916. );
  1917. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1918. return "/invoice";
  1919. }
  1920. /**
  1921. * 删除已终止的开票
  1922. */
  1923. function invoiceDelDo() {
  1924. Doo::loadModel ( 'invoice' );
  1925. $invoice = new invoice ();
  1926. Doo::loadModel ( 'invoiceOperationLog' );
  1927. $invoiceOperationLog = new invoiceOperationLog ();
  1928. Doo::loadClass ( 'XDeode' );
  1929. $XDeode = new XDeode ( 5 );
  1930. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  1931. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  1932. $iid = $XDeode->decode ( $iid );
  1933. Doo::loadModel ( 'invoiceStore' );
  1934. $invoiceStore = new invoiceStore ();
  1935. if (! is_numeric ( $iid ))
  1936. die ( 'illegal request' );
  1937. $invoiceDetail = $invoice->getMyInvoice ( $sid, $iid );
  1938. if (empty ( $invoiceDetail ))
  1939. die ( 'illegal request' );
  1940. $item = array (
  1941. 'iid' => $iid,
  1942. 'isDelete' => 1,
  1943. 'updateTime' => date ( "Y-m-d H:i:s" )
  1944. );
  1945. $invoice->setInvoiceByCondition ( $item );
  1946. $item = array (
  1947. 'date' => date ( "Y-m-d H:i:s" ),
  1948. 'operation' => '删除了已终止的发票',
  1949. 'status' => 4,
  1950. 'img' => $this->staff [0] ['avatar'],
  1951. 'username' => $this->staff [0] ['username'],
  1952. 'uid' => $this->staff [0] ['sid'],
  1953. 'category' => $this->staff [0] ['category'],
  1954. 'iid' => $iid
  1955. );
  1956. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1957. // 删除培训班发票仓库里的发票
  1958. $invoiceStore->delInvoiceStoreByIsid ( $invoiceDetail ['isid'] );
  1959. return "/invoice";
  1960. }
  1961. /**
  1962. */
  1963. function invoiceApproval() {
  1964. Doo::loadModel ( 'invoice' );
  1965. $invoice = new invoice ();
  1966. Doo::loadClass ( 'XDeode' );
  1967. $XDeode = new XDeode ( 5 );
  1968. Doo::loadModel ( 'staff' );
  1969. $staff = new staff ();
  1970. $invoiceList = $invoice->find ( array (
  1971. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  1972. 'desc' => 'iid',
  1973. 'limit' => 10,
  1974. 'asArray' => true
  1975. ) );
  1976. foreach ( $invoiceList as $key => $value ) {
  1977. $invoiceList [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1978. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1979. if (! empty ( $lastApprover )) {
  1980. $lastApproverKey = array_keys ( $lastApprover );
  1981. $lastApprover = end ( $lastApprover );
  1982. $staffDetail = $staff->getOne ( array (
  1983. 'where' => 'sid=' . end ( $lastApproverKey ),
  1984. 'asArray' => true
  1985. ) );
  1986. $lastApprover ['username'] = $staffDetail ['username'];
  1987. }
  1988. $invoiceList [$key] ['lastApprover'] = $lastApprover;
  1989. }
  1990. $ilist = $invoice->getInvoiceByProcessStatus ();
  1991. foreach ( $ilist as $key => $value ) {
  1992. $ilist [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1993. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1994. if (! empty ( $lastApprover )) {
  1995. $lastApproverKey = array_keys ( $lastApprover );
  1996. $lastApprover = end ( $lastApprover );
  1997. $staffDetail = $staff->getOne ( array (
  1998. 'where' => 'sid=' . end ( $lastApproverKey ),
  1999. 'asArray' => true
  2000. ) );
  2001. $lastApprover ['username'] = $staffDetail ['username'];
  2002. }
  2003. $ilist [$key] ['lastApprover'] = $lastApprover;
  2004. }
  2005. // print_r($ilist);
  2006. $this->data ['invoiceList'] = $invoiceList;
  2007. $this->data ['ilist'] = $ilist;
  2008. $this->data ['memu'] = "invoice";
  2009. $this->data ['staff'] = $this->staff;
  2010. $this->data ['receiptMemu'] = 'invoiceApproval';
  2011. $this->render ( "/admin/invoiceApproval", $this->data );
  2012. }
  2013. function invoiceDetail() {
  2014. Doo::loadClass ( 'XDeode' );
  2015. $XDeode = new XDeode ( 5 );
  2016. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  2017. $iid = $XDeode->decode ( $iid );
  2018. if (! is_numeric ( $iid ))
  2019. die ( 'illegal request' );
  2020. Doo::loadModel ( 'invoice' );
  2021. $invoice = new invoice ();
  2022. Doo::loadModel ( 'invoiceOperationLog' );
  2023. $invoiceOperationLog = new invoiceOperationLog ();
  2024. $invoiceDetail = $invoice->getOne ( array (
  2025. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'] . ' and iid=' . $iid,
  2026. 'asArray' => true
  2027. ) );
  2028. if (empty ( $invoiceDetail ))
  2029. die ( 'illegal request' );
  2030. if ($invoiceDetail ['settlementType'] == 1) {
  2031. Doo::loadModel ( 'invoiceTraining' );
  2032. $invoiceTraining = new invoiceTraining ();
  2033. $invoiceDetail ['invoiceTraining'] = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceDetail ['trainId'] );
  2034. }
  2035. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  2036. $this->data ['invoiceDetail'] = $invoiceDetail;
  2037. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  2038. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  2039. $this->data ['memu'] = "invoice";
  2040. $this->data ['staff'] = $this->staff;
  2041. $this->data ['receiptMemu'] = 'invoiceApproval';
  2042. $this->render ( "/admin/invoiceApprovalDetail", $this->data );
  2043. }
  2044. /**
  2045. * 对发票进行审批,其中操作有终止,退回,同意动作。操作成功并记录下操作日志
  2046. *
  2047. * @since 1.0.0
  2048. * @var integer iid 开票ID 已加密
  2049. * @var integer status 发票审批状态
  2050. * @var integer opintion 审批发票的意见
  2051. * @return string 如操作成功返回审批首页
  2052. */
  2053. function invoiceApprovalDo() {
  2054. Doo::loadModel ( 'invoice' );
  2055. $invoice = new invoice ();
  2056. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2057. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  2058. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  2059. $divApproval = $this->get_args ( 'divApproval' ) ? $this->get_args ( 'divApproval' ) : "";
  2060. $iid = $invoice->authcode ( $iid );
  2061. if (! is_numeric ( $iid ))
  2062. die ( 'illegal request' );
  2063. // && ! empty ( $opinion )
  2064. if (! empty ( $iid ) && ! empty ( $status )) {
  2065. if (! ($status == 2 || $status == 3 || $status == 4))
  2066. die ( 'illegal request' );
  2067. Doo::loadModel ( 'invoiceOperationLog' );
  2068. $invoiceOperationLog = new invoiceOperationLog ();
  2069. $invoiceDetail = $invoice->getOne ( array (
  2070. 'where' => 'status=1 and iid=' . $iid . ' and pendingApprovals=' . $this->staff [0] ['sid'],
  2071. 'asArray' => true
  2072. ) );
  2073. if (empty ( $invoiceDetail ))
  2074. die ( 'illegal request' );
  2075. $processApprovals = json_decode ( $invoiceDetail ['processApprovals'], true );
  2076. $invoiceManage = json_decode ( $invoiceDetail ['invoiceManage'], true );
  2077. if ($status == 3) {
  2078. $invoice->status = $status;
  2079. $item = array (
  2080. 'operation' => $opinion
  2081. );
  2082. } else {
  2083. if (empty ( $processApprovals )) {
  2084. $processApprovals = array (
  2085. $this->staff [0] ['sid'] => array (
  2086. 'date' => date ( "Y-m-d H:i:s" ),
  2087. 'opinion' => $opinion,
  2088. 'status' => $status
  2089. )
  2090. );
  2091. // var_dump(next($invoiceManage));
  2092. $nextInvoiceManage = next ( $invoiceManage );
  2093. // print_r($nextInvoiceManage);
  2094. if ($status != 4 && $nextInvoiceManage !== false)
  2095. $invoice->pendingApprovals = $nextInvoiceManage [0];
  2096. $invoice->processApprovals = json_encode ( $processApprovals );
  2097. // var_dump($invoice);
  2098. // print_r($invoiceManage);
  2099. } else {
  2100. $processApprovals [$this->staff [0] ['sid']] = array (
  2101. 'date' => date ( "Y-m-d H:i:s" ),
  2102. 'opinion' => $opinion,
  2103. 'status' => $status
  2104. );
  2105. $pendingApprovals = 0;
  2106. foreach ( $invoiceManage as $key => $value ) {
  2107. if ($value [0] == $this->staff [0] ['sid']) {
  2108. if (isset ( $invoiceManage [$key + 1] ))
  2109. $pendingApprovals = $invoiceManage [$key + 1] [0];
  2110. break;
  2111. }
  2112. }
  2113. if ($status != 4 && ! empty ( $pendingApprovals ))
  2114. $invoice->pendingApprovals = $pendingApprovals;
  2115. $invoice->processApprovals = json_encode ( $processApprovals );
  2116. }
  2117. $item = array (
  2118. 'operation' => $opinion
  2119. );
  2120. if (count ( $processApprovals ) == count ( $invoiceManage ) && $status != 4) {
  2121. $invoice->status = $status;
  2122. $invoice->pendingApprovals = 0;
  2123. $invoice->approvalTime = date ( "Y-m-d H:i:s" );
  2124. } elseif ($status == 4) {
  2125. $invoice->status = $status;
  2126. $item = array (
  2127. 'operation' => $opinion
  2128. );
  2129. }
  2130. }
  2131. $invoice->updateTime = date ( "Y-m-d H:i:s" );
  2132. $invoice->update ( array (
  2133. 'where' => 'iid=' . $iid
  2134. ) );
  2135. $item += array (
  2136. 'date' => date ( "Y-m-d H:i:s" ),
  2137. 'img' => $this->staff [0] ['avatar'],
  2138. 'username' => $this->staff [0] ['username'],
  2139. 'uid' => $this->staff [0] ['sid'],
  2140. 'category' => $this->staff [0] ['category'],
  2141. 'status' => $status,
  2142. 'iid' => $iid
  2143. );
  2144. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2145. if (empty ( $divApproval ))
  2146. return '/invoiceApproval';
  2147. else
  2148. return '/invoiceApprovalAchieve/PEND';
  2149. }
  2150. die ( 'illegal request' );
  2151. }
  2152. /**
  2153. * 展示需要打印的发票数据
  2154. *
  2155. * @since 1.0.0
  2156. */
  2157. function invoicePrint() {
  2158. Doo::loadModel ( 'invoice' );
  2159. $invoice = new invoice ();
  2160. Doo::loadClass ( 'XDeode' );
  2161. $XDeode = new XDeode ( 5 );
  2162. Doo::loadModel ( 'staff' );
  2163. $staff = new staff ();
  2164. $toPrint = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0 );
  2165. $printed = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 1 );
  2166. foreach ( $toPrint as $key => $value ) {
  2167. $toPrint [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2168. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2169. if (! empty ( $lastApprover )) {
  2170. $lastApproverKey = array_keys ( $lastApprover );
  2171. $lastApprover = end ( $lastApprover );
  2172. $staffDetail = $staff->getOne ( array (
  2173. 'where' => 'sid=' . end ( $lastApproverKey ),
  2174. 'asArray' => true
  2175. ) );
  2176. $lastApprover ['username'] = $staffDetail ['username'];
  2177. }
  2178. $toPrint [$key] ['lastApprover'] = $lastApprover;
  2179. }
  2180. foreach ( $printed as $key => $value ) {
  2181. $printed [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2182. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2183. if (! empty ( $lastApprover )) {
  2184. $lastApproverKey = array_keys ( $lastApprover );
  2185. $lastApprover = end ( $lastApprover );
  2186. $staffDetail = $staff->getOne ( array (
  2187. 'where' => 'sid=' . end ( $lastApproverKey ),
  2188. 'asArray' => true
  2189. ) );
  2190. $lastApprover ['username'] = $staffDetail ['username'];
  2191. }
  2192. $printed [$key] ['lastApprover'] = $lastApprover;
  2193. }
  2194. $this->data ['printed'] = $printed;
  2195. $this->data ['toPrint'] = $toPrint;
  2196. $this->data ['memu'] = "invoice";
  2197. $this->data ['staff'] = $this->staff;
  2198. $this->data ['receiptMemu'] = 'invoicePrint';
  2199. $this->render ( "/admin/invoicePrint", $this->data );
  2200. }
  2201. /**
  2202. * 展示发票打印的详情页面
  2203. *
  2204. * @since 1.0.0
  2205. */
  2206. function invoicePrintDetail() {
  2207. Doo::loadClass ( 'XDeode' );
  2208. $XDeode = new XDeode ( 5 );
  2209. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  2210. $iid = $XDeode->decode ( $iid );
  2211. if (! is_numeric ( $iid ))
  2212. die ( 'illegal request' );
  2213. Doo::loadModel ( 'invoice' );
  2214. $invoice = new invoice ();
  2215. Doo::loadModel ( 'invoiceOperationLog' );
  2216. $invoiceOperationLog = new invoiceOperationLog ();
  2217. Doo::loadModel ( 'invoicePaper' );
  2218. $invoicePaper = new invoicePaper ();
  2219. $invoiceDetail = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0, $iid );
  2220. if (empty ( $invoiceDetail ))
  2221. die ( 'illegal request' );
  2222. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $invoiceDetail ['invoiceType'] );
  2223. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  2224. if ($invoiceDetail ['settlementType'] == 1) {
  2225. Doo::loadModel ( 'invoiceTraining' );
  2226. $invoiceTraining = new invoiceTraining ();
  2227. $invoiceDetail ['invoiceTraining'] = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceDetail ['trainId'] );
  2228. }
  2229. $this->data ['invoicePaperList'] = $invoicePaperList;
  2230. $this->data ['invoiceDetail'] = $invoiceDetail;
  2231. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  2232. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  2233. $this->data ['memu'] = "invoice";
  2234. $this->data ['staff'] = $this->staff;
  2235. $this->data ['receiptMemu'] = 'invoicePrint';
  2236. $this->render ( "/admin/invoicePrintDetail", $this->data );
  2237. }
  2238. /**
  2239. * 所有待打印 发票
  2240. */
  2241. function invoicePrintStayAchieve() {
  2242. Doo::loadModel ( 'invoice' );
  2243. $invoice = new invoice ();
  2244. Doo::loadClass ( 'XDeode' );
  2245. $XDeode = new XDeode ( 5 );
  2246. Doo::loadModel ( 'staff' );
  2247. $staff = new staff ();
  2248. $MebSea = $this->get_args ( 'MebSea' ) ? urldecode ( $this->get_args ( 'MebSea' ) ) : "";
  2249. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  2250. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  2251. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  2252. Doo::loadModel ( 'invoiceTraining' );
  2253. $invoiceTraining = new invoiceTraining ();
  2254. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  2255. $page_size = 12;
  2256. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2257. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : "ALL";
  2258. // $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : "ALL";
  2259. $get = "/" . $status;
  2260. $con = ' and status=2 ';
  2261. if ($status == 'TOPRINT')
  2262. $con = ' and status=2 and printStatus=0 ';
  2263. elseif ($status == 'PRINTED')
  2264. $con = ' and status=2 and printStatus=1';
  2265. if ($invoiceType == 'ORDINARY')
  2266. $con .= ' and invoiceType=0 ';
  2267. elseif ($invoiceType == 'SPECIAL')
  2268. $con .= ' and invoiceType=1 ';
  2269. if ($invoiceTrain == 'ORDINARY')
  2270. $con .= ' and trainId=0 ';
  2271. elseif ($invoiceTrain == 'TRAIN')
  2272. $con .= ' and trainId!=0 ';
  2273. if ($invoiceTrainName != 'ALL') {
  2274. $trainId = $XDeode->decode ( $invoiceTrainName );
  2275. if (is_numeric ( $trainId ))
  2276. $con .= ' and trainId =' . $trainId;
  2277. }
  2278. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2279. $dateArr = explode ( ':', $date );
  2280. $D1 = '';
  2281. $D2 = '';
  2282. if (! empty ( $date )) {
  2283. $D1 = $dateArr [0];
  2284. $D2 = $dateArr [1];
  2285. }
  2286. if (! empty ( $D1 ) && ! empty ( $D2 ) && ! empty ( $date ))
  2287. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2288. if (! empty ( $MebSea )) {
  2289. $con .= ' and ( invoiceNo like "%' . $MebSea . '%" or invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  2290. }
  2291. $pageinfo ['page'] = array (
  2292. 'previous' => ''
  2293. );
  2294. $get .= "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&invoiceType=" . urlencode ( $invoiceType ) . "&invoiceTrain=" . urlencode ( $invoiceTrain ) . "";
  2295. $sql = " (untreadStatus=0 or untreadStatus=3) and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  2296. $action = "invoicePrintStayAchieve";
  2297. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2298. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2299. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  2300. $this->data ['trainList'] = $trainList;
  2301. $this->data ['invoiceType'] = $invoiceType;
  2302. $this->data ['invoiceTrain'] = $invoiceTrain;
  2303. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  2304. $this->data ['MebSeaEn'] = $MebSea;
  2305. $this->data ['MebSea'] = urlencode ( $MebSea );
  2306. $this->data ['get'] = $get;
  2307. $this->data ['page'] = $pageinfo;
  2308. $this->data ['date'] = $date;
  2309. $this->data ['status'] = $status;
  2310. $this->data ['invoiceType'] = $invoiceType;
  2311. $this->data ['memu'] = "invoice";
  2312. $this->data ['staff'] = $this->staff;
  2313. foreach ( $list as $key => $value ) {
  2314. $list [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2315. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2316. if (! empty ( $lastApprover )) {
  2317. $lastApproverKey = array_keys ( $lastApprover );
  2318. $lastApprover = end ( $lastApprover );
  2319. $staffDetail = $staff->getOne ( array (
  2320. 'where' => 'sid=' . end ( $lastApproverKey ),
  2321. 'asArray' => true
  2322. ) );
  2323. $lastApprover ['username'] = $staffDetail ['username'];
  2324. }
  2325. $list [$key] ['lastApprover'] = $lastApprover;
  2326. }
  2327. $this->data ['receiptMemu'] = 'invoicePrint';
  2328. $this->data ['list'] = $list;
  2329. $this->render ( "/admin/invoicePrintStayAchieve", $this->data );
  2330. }
  2331. /**
  2332. * 填写票号并完成打印
  2333. * @since 1.0.0
  2334. */
  2335. function invoicePrintDo() {
  2336. Doo::loadModel ( 'invoice' );
  2337. $invoice = new invoice ();
  2338. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2339. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  2340. $invoicePrintType = $this->get_args ( 'invoicePrintType' ) ? $this->get_args ( 'invoicePrintType' ) : "";
  2341. $iid = $invoice->authcode ( $iid );
  2342. if (! is_numeric ( $iid ))
  2343. die ( 'illegal request' );
  2344. if (! empty ( $iid ) && ! empty ( $invoiceNo )) {
  2345. Doo::loadModel ( 'invoiceOperationLog' );
  2346. $invoiceOperationLog = new invoiceOperationLog ();
  2347. Doo::loadModel ( 'invoiceStatistics' );
  2348. $invoiceStatistics = new invoiceStatistics ();
  2349. $XDeode = new XDeode ( 5 );
  2350. Doo::loadModel ( 'invoicePaper' );
  2351. $invoicePaper = new invoicePaper ();
  2352. $invoicePrintDetail = $invoice->getInvoiceByPrint ( $iid );
  2353. if (empty ( $invoicePrintDetail ))
  2354. die ( 'illegal request' );
  2355. //
  2356. $ipid = $XDeode->decode ( $invoiceNo );
  2357. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  2358. if (empty ( $paperDetail ))
  2359. die ( 'illegal request' );
  2360. $invoicePaper = new invoicePaper ();
  2361. $item = array (
  2362. 'iid' => $iid,
  2363. 'ipid' => $ipid
  2364. );
  2365. $invoicePaper->setInvoicePaperByCondition ( $item );
  2366. $item = array (
  2367. 'iid' => $iid,
  2368. 'printStatus' => 1,
  2369. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2370. 'printer' => $this->staff [0] ['username'],
  2371. 'printTime' => date ( "Y-m-d H:i:s" ),
  2372. 'invoiceNo' => $paperDetail ['invoiceNo']
  2373. );
  2374. $invoice->setInvoiceByCondition ( $item );
  2375. $item = array (
  2376. 'date' => date ( "Y-m-d H:i:s" ),
  2377. 'operation' => '打印发票号:' . $paperDetail ['invoiceNo'],
  2378. 'status' => 5,
  2379. 'img' => $this->staff [0] ['avatar'],
  2380. 'username' => $this->staff [0] ['username'],
  2381. 'uid' => $this->staff [0] ['sid'],
  2382. 'category' => $this->staff [0] ['category'],
  2383. 'iid' => $iid
  2384. );
  2385. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2386. // 去统计--负票不汇总
  2387. if ($invoicePrintDetail ['untreadStatus'] != 4) {
  2388. $item = array (
  2389. 'date' => date ( "Y-m-d H:i:s" ),
  2390. 'priceClass' => 1,
  2391. 'cid' => $invoicePrintDetail ['cid'],
  2392. 'staff' => $invoicePrintDetail ['sid'],
  2393. 'invoicePrice' => $invoicePrintDetail ['invoicePrice']
  2394. );
  2395. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2396. }
  2397. // 发送通知信息到微信-去除
  2398. // $this->setWXMsg($iid,'PRINT');
  2399. // 发票信息库
  2400. $this->autoUpdateInvoiceInfoBase ( $invoicePrintDetail );
  2401. // 申请人获取微信通知
  2402. Doo::loadModel ( 'staff' );
  2403. $staff = new staff ();
  2404. Doo::loadClass ( 'XDeode' );
  2405. $XDeode = new XDeode ( 5 );
  2406. $username2 = $staff->getOne ( array (
  2407. 'select' => 'wxid',
  2408. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2409. 'asArray' => TRUE
  2410. ) );
  2411. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '完成打印';
  2412. $msg = '';
  2413. $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/' . $XDeode->encode ( $invoicePrintDetail ['iid'] ) . '.html';
  2414. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2415. if (empty ( $invoicePrintType ))
  2416. return "/invoicePrint";
  2417. else
  2418. return "/invoicePrintStayAchieve";
  2419. }
  2420. }
  2421. /**
  2422. * 需要邮寄的发票
  2423. * @since 1.0.0
  2424. */
  2425. function invoicePost() {
  2426. Doo::loadModel ( 'invoice' );
  2427. $invoice = new invoice ();
  2428. Doo::loadModel ( 'express' );
  2429. $express = new express ();
  2430. $invoicePost = $invoice->getPostByInvoice ();
  2431. $invoicePosted = $invoice->getPostByInvoice ( 1 );
  2432. $expressList = $express->getExpressByAll ();
  2433. $invoicePostExpress = "";
  2434. if (isset ( $_COOKIE ["invoicePostExpress"] ))
  2435. $invoicePostExpress = $_COOKIE ["invoicePostExpress"];
  2436. $this->data ['invoicePostExpress'] = $invoicePostExpress;
  2437. $this->data ['expressList'] = $expressList;
  2438. $this->data ['invoicePost'] = $invoicePost;
  2439. $this->data ['invoicePosted'] = $invoicePosted;
  2440. $this->data ['memu'] = "invoice";
  2441. $this->data ['staff'] = $this->staff;
  2442. $this->data ['receiptMemu'] = 'invoicePost';
  2443. $this->render ( "/admin/invoicePost", $this->data );
  2444. }
  2445. /**
  2446. * 添加发票邮寄信息
  2447. */
  2448. function invoiceExpressAddDo() {
  2449. Doo::loadModel ( 'invoice' );
  2450. $invoice = new invoice ();
  2451. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2452. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2453. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2454. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2455. $iid = $iid = $invoice->authcode ( $iid );
  2456. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2457. die ( 'illegal request' );
  2458. $invoicePrintDetail = $invoice->getInvoiceByIid ( $iid );
  2459. setcookie ( 'invoicePostExpress', $expressNumber );
  2460. $item = array (
  2461. 'iid' => $iid,
  2462. 'postStatus' => 1,
  2463. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2464. 'postTime' => date ( "Y-m-d H:i:s" ),
  2465. 'expressCompany' => $expressCompany,
  2466. 'expressNumber' => $expressNumber,
  2467. 'actualItems' => $actualItems,
  2468. 'poster' => $this->staff [0] ['username']
  2469. );
  2470. $invoice->setInvoiceByCondition ( $item );
  2471. // 微信通知-去掉
  2472. // $this->setWXMsg ( $iid );
  2473. Doo::loadModel ( 'staff' );
  2474. $staff = new staff ();
  2475. Doo::loadClass ( 'XDeode' );
  2476. $XDeode = new XDeode ( 5 );
  2477. $username2 = $staff->getOne ( array (
  2478. 'select' => 'wxid',
  2479. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2480. 'asArray' => TRUE
  2481. ) );
  2482. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '已邮寄';
  2483. $expCom = explode ( ":", $invoicePrintDetail ['expressCompany'] );
  2484. if (empty ( $expCom ))
  2485. $expCom [0] = '';
  2486. $msg = $expCom [0] . ':' . $invoicePrintDetail ['expressNumber'] . '';
  2487. $url = 'https://m.kuaidi100.com/result.jsp?nu=' . $invoicePrintDetail ['expressNumber'];
  2488. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2489. return '/invoicePost';
  2490. }
  2491. function invoiceExpressUpdateDo() {
  2492. Doo::loadModel ( 'invoice' );
  2493. $invoice = new invoice ();
  2494. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  2495. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2496. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2497. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2498. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2499. $iid = $invoice->authcode ( $iid );
  2500. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2501. die ( 'illegal request' );
  2502. $item = array (
  2503. 'iid' => $iid,
  2504. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2505. 'expressCompany' => $expressCompany,
  2506. 'expressNumber' => $expressNumber,
  2507. 'actualItems' => $actualItems,
  2508. 'poster' => $this->staff [0] ['username']
  2509. );
  2510. $invoice->setInvoiceByCondition ( $item );
  2511. return $action;
  2512. }
  2513. /**
  2514. * 可退票管理
  2515. */
  2516. function invoiceUntreadIsAchieve() {
  2517. Doo::loadModel ( 'invoice' );
  2518. $invoice = new invoice ();
  2519. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2520. /*
  2521. * Doo::loadClass ( 'XDeode' ); $XDeode = new XDeode ( 5 ); $page_size = 18; $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1; $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : ""; $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ); $dateArr = explode ( ':', $date ); $D1 = ''; $D2 = ''; if (! empty ( $date )) { $D1 = $dateArr [0]; $D2 = $dateArr [1]; } $con = ''; if (! empty ( $D1 ) && ! empty ( $D2 )) $con = ' and bindTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" '; // if ($date == 'MONTHO') // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)'; // elseif ($date == 'MONTHT') // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)'; // elseif ($date == 'MONTHY') // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)'; if (! empty ( $MebSea )) { $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )'; } $pageinfo ['page'] = array ( 'previous' => '' );
  2522. */
  2523. if (empty ( $MebSea )) {//
  2524. $con = ' and invoiceNo like "NULL" ';
  2525. } else {
  2526. $con = ' and (invoiceNo like "%' . $MebSea . '%" or invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  2527. }
  2528. // printStatus=1 and
  2529. $sql = " (untreadStatus=0 or untreadStatus=3) and status=2 and sid=" . $this->staff [0] ['sid'] . $con;
  2530. /*
  2531. * $action = "invoiceUntreadIsAchieve"; $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" ); $limit = $pageinfo ['lower'] . ',' . $page_size;
  2532. */
  2533. $limit = '0,20';
  2534. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2535. // print_r($list);
  2536. $this->data ['MebSeaEn'] = $MebSea;
  2537. /*
  2538. * $this->data ['get'] = $get; $this->data ['page'] = $pageinfo; $this->data ['date'] = $date;
  2539. */
  2540. $this->data ['list'] = $list;
  2541. $this->data ['memu'] = "invoice";
  2542. $this->data ['staff'] = $this->staff;
  2543. $this->data ['receiptMemu'] = 'invoice';
  2544. $this->render ( "/admin/invoiceUntreadIsAchieve", $this->data );
  2545. }
  2546. // 已经退票的发票
  2547. function invoiceUntreadED() {
  2548. Doo::loadModel ( 'invoice' );
  2549. $invoice = new invoice ();
  2550. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2551. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "";
  2552. Doo::loadClass ( 'XDeode' );
  2553. $XDeode = new XDeode ( 5 );
  2554. $page_size = 18;
  2555. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2556. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2557. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  2558. $dateArr = explode ( ':', $date );
  2559. $D1 = '';
  2560. $D2 = '';
  2561. if (! empty ( $date )) {
  2562. $D1 = $dateArr [0];
  2563. $D2 = $dateArr [1];
  2564. }
  2565. $con = '';
  2566. if (! empty ( $D1 ) && ! empty ( $D2 )) {
  2567. $con = ' and bindTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2568. }
  2569. // if ($date == 'MONTHO')
  2570. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  2571. // elseif ($date == 'MONTHT')
  2572. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  2573. // elseif ($date == 'MONTHY')
  2574. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  2575. if (! empty ( $MebSea )) {
  2576. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  2577. }
  2578. if ($invoiceType == 'ORDINARY') {
  2579. $con .= ' and invoiceType=0 ';
  2580. } elseif ($invoiceType == 'SPECIAL') {
  2581. $con .= ' and invoiceType=1 ';
  2582. }
  2583. $pageinfo ['page'] = array (
  2584. 'previous' => ''
  2585. );
  2586. // printStatus=1 and
  2587. $sql = " (untreadStatus=2 ) and status=2 and sid=" . $this->staff [0] ['sid'] . $con;
  2588. $action = "invoiceUntreadED";
  2589. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2590. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2591. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2592. // print_r($list);
  2593. $this->data ['MebSeaEn'] = $MebSea;
  2594. $this->data ['get'] = $get;
  2595. $this->data ['page'] = $pageinfo;
  2596. $this->data ['date'] = $date;
  2597. $this->data ['invoiceType'] = $invoiceType;
  2598. $this->data ['list'] = $list;
  2599. $this->data ['memu'] = "invoice";
  2600. $this->data ['staff'] = $this->staff;
  2601. $this->data ['receiptMemu'] = 'invoice';
  2602. $this->render ( "/admin/invoiceUntreadED", $this->data );
  2603. }
  2604. /**
  2605. * 退票处理页面
  2606. */
  2607. function invoiceUntread() {
  2608. Doo::loadModel ( 'invoice' );
  2609. $invoice = new invoice ();
  2610. $untreadInvoice = $invoice->getInvoiceByUntreadStatus ( 1, 0, 50 );
  2611. $establishedInvoice = $invoice->getInvoiceByUntreadStatus ( 2 );
  2612. foreach ( $establishedInvoice as $key => $value ) {
  2613. // months
  2614. $lossDate = strtotime ( "+1 month", strtotime ( $value ['OperationLog'] ['date'] ) );
  2615. $nowDate = strtotime ( 'now' );
  2616. $establishedInvoice [$key] ['lossShow'] = false;
  2617. if ($lossDate < $nowDate)
  2618. $establishedInvoice [$key] ['lossShow'] = true;
  2619. }
  2620. $this->data ['untreadInvoice'] = $untreadInvoice;
  2621. $this->data ['establishedInvoice'] = $establishedInvoice;
  2622. $this->data ['memu'] = "invoice";
  2623. $this->data ['staff'] = $this->staff;
  2624. $this->data ['receiptMemu'] = 'invoiceUntread';
  2625. $this->render ( "/admin/invoiceUntread", $this->data );
  2626. }
  2627. /**
  2628. * 确认收到退回的发票,开票状态为退回 //收款状态解绑,公司统计扣除入账额度
  2629. */
  2630. function invoiceUntreadEstablishedDo() {
  2631. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  2632. Doo::loadModel ( 'invoice' );
  2633. $invoice = new invoice ();
  2634. Doo::loadModel ( 'invoiceOperationLog' );
  2635. $invoiceOperationLog = new invoiceOperationLog ();
  2636. Doo::loadModel ( 'invoiceReceivables' );
  2637. Doo::loadModel ( 'invoiceStatistics' );
  2638. $iid = $invoice->authcode ( $untreadIidKey );
  2639. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2640. die ( 'illegal request' );
  2641. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  2642. if ($invoiceDetails ['untreadStatus'] != 1)
  2643. die ( 'illegal request untreadStatus error !=1' );
  2644. $item = array (
  2645. 'iid' => $iid,
  2646. // 'irid'=>'',
  2647. 'untreadStatus' => 2,
  2648. 'updateTime' => date ( "Y-m-d H:i:s" )
  2649. );
  2650. $invoice->setInvoiceByCondition ( $item );
  2651. $item = array (
  2652. 'date' => date ( "Y-m-d H:i:s" ),
  2653. 'operation' => '已确认退票',
  2654. 'status' => 6,
  2655. 'img' => $this->staff [0] ['avatar'],
  2656. 'username' => $this->staff [0] ['username'],
  2657. 'uid' => $this->staff [0] ['sid'],
  2658. 'category' => $this->staff [0] ['category'],
  2659. 'iid' => $iid
  2660. );
  2661. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2662. // 收款解绑以及入账扣除 收款扣除
  2663. if (! empty ( $invoiceDetails ['irid'] )) {
  2664. $iridList = explode ( ',', $invoiceDetails ['irid'] );
  2665. foreach ( $iridList as $value ) {
  2666. $invoiceReceivables = new invoiceReceivables ();
  2667. $irDetails = $invoiceReceivables->getOne ( array (
  2668. 'where' => " irid=" . $value . ' and bindStatus=1',
  2669. 'asArray' => TRUE
  2670. ) );
  2671. $item = array (
  2672. 'irid' => $value,
  2673. 'bindStatus' => 0,
  2674. 'untreadStatus' => 1,
  2675. 'untreadStaff' => $invoiceDetails ['userName'],
  2676. 'unbundlingTime' => date ( "Y-m-d H:i:s" ),
  2677. 'iid' => 0
  2678. );
  2679. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2680. if (! empty ( $irDetails )) {
  2681. // 扣除入账
  2682. $invoiceStatistics = new invoiceStatistics ();
  2683. $item = array (
  2684. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2685. 'priceClass' => 3,
  2686. 'cid' => $invoiceDetails ['cid'],
  2687. 'staff' => $invoiceDetails ['sid'],
  2688. 'accountPrice' => - $irDetails ['receivablesPrice']
  2689. );
  2690. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2691. // 扣除收款
  2692. $invoiceStatistics = new invoiceStatistics ();
  2693. $item = array (
  2694. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2695. 'priceClass' => 2,
  2696. 'cid' => $invoiceDetails ['cid'],
  2697. 'staff' => $invoiceDetails ['sid'],
  2698. 'irid' => $irDetails ['irid'],
  2699. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  2700. );
  2701. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2702. }
  2703. // 解绑时删除收入流水
  2704. Doo::loadModel ( 'wasteBook' );
  2705. $wasteBook = new wasteBook ();
  2706. $wasteBook->delete ( array (
  2707. 'where' => 'dataID=' . $value . ' and accountType=7',
  2708. 'limit' => 1
  2709. ) );
  2710. }
  2711. }
  2712. return "/invoiceUntread";
  2713. }
  2714. function invoiceUntreadRecallDo() {
  2715. $iidKey = isset ( $this->params ['iidKey'] ) ? $this->params ['iidKey'] : "";
  2716. Doo::loadModel ( 'invoice' );
  2717. $invoice = new invoice ();
  2718. Doo::loadClass ( 'XDeode' );
  2719. $XDeode = new XDeode ( 5 );
  2720. Doo::loadModel ( 'invoiceOperationLog' );
  2721. $invoiceOperationLog = new invoiceOperationLog ();
  2722. $iid = $XDeode->decode ( $iidKey );
  2723. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  2724. if (empty ( $invoiceDetail )) {
  2725. die ( 'illegal request-DATANULL' );
  2726. }
  2727. $item = array (
  2728. 'iid' => $iid,
  2729. 'untreadStatus' => 0
  2730. );
  2731. $invoice->setInvoiceByCondition ( $item );
  2732. $item = array (
  2733. 'date' => date ( "Y-m-d H:i:s" ),
  2734. 'operation' => '撤回申请退票',
  2735. 'status' => 13,
  2736. 'img' => $this->staff [0] ['avatar'],
  2737. 'username' => $this->staff [0] ['username'],
  2738. 'uid' => $this->staff [0] ['sid'],
  2739. 'category' => $this->staff [0] ['category'],
  2740. 'iid' => $iid
  2741. );
  2742. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2743. return "/invoiceUntread";
  2744. }
  2745. /**
  2746. * 建立负票,关联原来发票
  2747. */
  2748. function invoiceLossDo() {
  2749. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2750. if (! empty ( $iidKey )) {
  2751. Doo::loadClass ( 'XDeode' );
  2752. $XDeode = new XDeode ( 5 );
  2753. Doo::loadModel ( 'invoice' );
  2754. $invoice = new invoice ();
  2755. Doo::loadModel ( 'invoiceOperationLog' );
  2756. $invoiceOperationLog = new invoiceOperationLog ();
  2757. $iidKey = $XDeode->decode ( $iidKey );
  2758. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  2759. // 拷贝插入一条发票数据
  2760. $iid = $invoice->setInvoiceLoss ( $iidKey );
  2761. // 更新负票
  2762. $invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  2763. $invoice = new invoice ();
  2764. $item = array (
  2765. 'iid' => $iid,
  2766. 'sid' => $this->staff [0] ['sid'],
  2767. 'userName' => $this->staff [0] ['username'],
  2768. 'cid' => $this->staff [0] ['cid'],
  2769. 'categoryName' => $this->staff [0] ['category'],
  2770. 'invoiceQuantity' => - $invoiceDetail ['invoiceQuantity'],
  2771. 'invoicePrice' => - $invoiceDetail ['invoicePrice'],
  2772. 'invoiceSerial' => $invoiceSerial,
  2773. 'invoiceNo' => '',
  2774. 'printStatus' => 0,
  2775. 'untreadStatus' => 4,
  2776. // 关联发票号
  2777. 'lossIid' => $invoiceDetail ['iid']
  2778. );
  2779. $invoice->setInvoiceByCondition ( $item );
  2780. // 更新原发票
  2781. $invoice = new invoice ();
  2782. $item = array (
  2783. 'iid' => $invoiceDetail ['iid'],
  2784. 'lossIid' => $iid
  2785. );
  2786. $invoice->setInvoiceByCondition ( $item );
  2787. // 操作日志
  2788. $item = array (
  2789. 'date' => date ( "Y-m-d H:i:s" ),
  2790. 'operation' => "创建负票" . $invoiceSerial,
  2791. 'status' => 12,
  2792. 'img' => $this->staff [0] ['avatar'],
  2793. 'username' => $this->staff [0] ['username'],
  2794. 'uid' => $this->staff [0] ['sid'],
  2795. 'category' => $this->staff [0] ['category'],
  2796. 'iid' => $iid
  2797. );
  2798. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2799. // print_r($invoiceDetail);
  2800. // echo $iid;die;
  2801. }
  2802. return '/invoiceUntread';
  2803. }
  2804. /**
  2805. * 上传银行到账 收款文件
  2806. */
  2807. function invoiceReceivablesBankUpload() {
  2808. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  2809. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  2810. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  2811. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  2812. header ( "HTTP/1.1 500 Internal Server Error" );
  2813. echo "POST exceeded maximum allowed size.";
  2814. exit ( 0 );
  2815. }
  2816. // Settings
  2817. $save_path = DOO::conf ()->SITE_PATH . "upload/invoiceReceivablesBank/"; // The path were we will save the file (getcwd() may not be reliable and should be tested in your environment)
  2818. $upload_name = "Filedata";
  2819. $file_name = "";
  2820. $nk = time ();
  2821. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  2822. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  2823. echo "文件无法保存.";
  2824. exit ( 0 );
  2825. }
  2826. echo json_encode ( array (
  2827. 'filename' => $file_name,
  2828. 'id' => $nk
  2829. ) );
  2830. exit ( 0 );
  2831. }
  2832. /**
  2833. * 解析银行到账收款execl并导入库中
  2834. */
  2835. function invoiceReceivablesImport() {
  2836. $path = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  2837. if ($path != "") {
  2838. Doo::loadModel ( 'invoiceReceivables' );
  2839. $invoiceReceivables = new invoiceReceivables ();
  2840. Doo::loadClass ( 'invoice.func' );
  2841. Doo::loadModel ( 'invoiceROLog' );
  2842. $invoiceROLog = new invoiceROLog ();
  2843. Doo::loadModel ( 'invoiceStatistics' );
  2844. $invoiceStatistics = new invoiceStatistics ();
  2845. $exlArray = formatExcelToArrayBank ( DOO::conf ()->SITE_PATH . "upload/invoiceReceivablesBank/" . $path );
  2846. $bankBatchNumber = 'BBN_' . time ();
  2847. Doo::db ()->beginTransaction ();
  2848. // 批量存储收款--由于必须获得收款ID,
  2849. $sql = 'INSERT INTO CLD_invoiceReceivables (OriginalPrice,receivablesPrice, receivablesMessage,receivablesSerial,receivablesBank,receivablesDate,inputStaff,date,receivablesCategory,receivablesStaff,bankBatchNumber,recepitTitleMark)
  2850. VALUES ';
  2851. $date = date ( "Y-m-d" );
  2852. $receivablesList = array ();
  2853. foreach ( $exlArray as $key => $value ) {
  2854. $receivablesSql = '(' . $value ["receivablesPrice"] . ',' . $value ["receivablesPrice"] . ',"' . $value ["receivablesMessage"] . '",' . '"#SK' . date ( "Ymd" ) . mt_rand ( 1000, 9999 ) . '","' . $value ["receivablesBank"] . '","' . $value ["receivablesDate"] . '","' . $this->staff [0] ['username'] . '","' . $date . '","PUBLIC","PUBLIC","' . $bankBatchNumber . '","' . $value ["receivablesMessage"] . '")';
  2855. array_push ( $receivablesList, $receivablesSql );
  2856. }
  2857. $sql = $sql . implode ( ',', $receivablesList );
  2858. // echo $sql;
  2859. Doo::db ()->query ( $sql );
  2860. // 批量存储收款统计
  2861. // 获得刚刚导入数据的irid组-缺少办事处和人员
  2862. $iridList = $invoiceReceivables->getInvoiceReceivablesByBBN ( $bankBatchNumber );
  2863. // 没有irid 回滚所有操作
  2864. if (empty ( $iridList )) {
  2865. Doo::db ()->rollBack ();
  2866. header ( 'Content-Type:text/html;charset=utf-8' );
  2867. die ( '文档或数据不正确,请重新<a href="/invoiceReceivables">上传</a>.' );
  2868. }
  2869. $sql = 'INSERT INTO CLD_invoiceStatistics (date, priceClass,irid,receivablesPrice)
  2870. VALUES ';
  2871. $statisticsList = array ();
  2872. foreach ( $iridList as $value ) {
  2873. $statisticsSql = '("' . $date . '",2,' . $value ['irid'] . ',' . $value ["receivablesPrice"] . ')';
  2874. array_push ( $statisticsList, $statisticsSql );
  2875. }
  2876. $sql = $sql . implode ( ',', $statisticsList );
  2877. Doo::db ()->query ( $sql );
  2878. // 批量存储操作日志
  2879. $sql = 'INSERT INTO CLD_invoiceROLog (operation, date,status,img, username,uid,category,irid)
  2880. VALUES ';
  2881. $ROLogList = array ();
  2882. foreach ( $iridList as $value ) {
  2883. $ROLogSql = '("' . $this->staff [0] ['username'] . ' 转入 公共待认领款项","' . $date . '",1,"' . $this->staff [0] ['avatar'] . '","' . $this->staff [0] ['username'] . '","' . $this->staff [0] ['sid'] . '","' . $this->staff [0] ['category'] . '","' . $value ['irid'] . '")';
  2884. array_push ( $ROLogList, $ROLogSql );
  2885. }
  2886. $sql = $sql . implode ( ',', $ROLogList );
  2887. Doo::db ()->query ( $sql );
  2888. // 批量写入流水
  2889. $sql = 'INSERT INTO CLD_wasteBook (dataID, expensesType,accountType,accountPriceShow, accountPrice,accountBank,category,cid,name,sid,inputDate)
  2890. VALUES ';
  2891. $wasteBookList = array ();
  2892. foreach ( $iridList as $value ) {
  2893. $accountBank = '';
  2894. if ($value ['receivablesBank'] == '纵横广发') {
  2895. $accountBank = 'CGBDeposit';
  2896. } elseif ($value ['receivablesBank'] == '纵横工行') {
  2897. $accountBank = 'ICBCDeposit';
  2898. } elseif ($value ['receivablesBank'] == '华润银行') {
  2899. $accountBank = 'HUADeposit';
  2900. } elseif ($value ['receivablesBank'] == '个人广发') {
  2901. $accountBank = 'PersonalDeposit';
  2902. }
  2903. $wasteBookSql = '("' . $value ['irid'] . ' ",1,7,"' . $value ['receivablesPrice'] . '","' . $value ['receivablesPrice'] . '","' . $accountBank . '",
  2904. "' . $this->staff [0] ['category'] . '","' . $this->staff [0] ['cid'] . '","' . $this->staff [0] ['username'] . '","' . $this->staff [0] ['sid'] . '","' . date ( "Y-m-d H:i:s" ) . '")';
  2905. array_push ( $wasteBookList, $wasteBookSql );
  2906. }
  2907. $sql = $sql . implode ( ',', $wasteBookList );
  2908. Doo::db ()->query ( $sql );
  2909. Doo::db ()->commit ();
  2910. return "/invoiceReceivables";
  2911. }
  2912. echo 'no file';
  2913. }
  2914. function invoiceReceivables() {
  2915. $invoiceTC = $this->get_args ( 'invoiceTC' ) ? $this->get_args ( 'invoiceTC' ) : '';
  2916. Doo::loadModel ( 'L_category' );
  2917. $lCategory = new L_category ();
  2918. Doo::loadModel ( 'staff' );
  2919. $staff = new staff ();
  2920. Doo::loadModel ( 'invoiceReceivables' );
  2921. $invoiceReceivables = new invoiceReceivables ();
  2922. Doo::loadModel ( 'invoice' );
  2923. $invoice = new invoice ();
  2924. Doo::loadClass ( 'XDeode' );
  2925. $XDeode = new XDeode ( 5 );
  2926. $category = $lCategory->getCategory ();
  2927. $staffList = $staff->getStaffByCid ( $this->staff [0] ['cid'] );
  2928. $sql = 'bindStatus=1 and iid!=0';
  2929. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByNew ( 4, $sql );
  2930. // 获取未入账发票
  2931. $invoiceUnAccount = $invoice->getInvoiceByUnAccount ( $invoiceTC );
  2932. $invoiceExistAccount = $invoice->getInvoiceByUnAccount ( '', true );
  2933. foreach ( $invoiceUnAccount as $key => $value ) {
  2934. $invoiceUnAccount [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2935. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2936. if (! empty ( $lastApprover )) {
  2937. $lastApproverKey = array_keys ( $lastApprover );
  2938. $lastApprover = end ( $lastApprover );
  2939. $staffDetail = $staff->getOne ( array (
  2940. 'where' => 'sid=' . end ( $lastApproverKey ),
  2941. 'asArray' => true
  2942. ) );
  2943. $lastApprover ['username'] = $staffDetail ['username'];
  2944. }
  2945. $invoiceUnAccount [$key] ['lastApprover'] = $lastApprover;
  2946. }
  2947. foreach ( $invoiceExistAccount as $key => $value ) {
  2948. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  2949. if (empty ( $irList ))
  2950. $irList [0] ['sumPrice'] = 0;
  2951. $balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  2952. $invoiceExistAccount [$key] ['existAccount'] = $irList [0] ['sumPrice'];
  2953. $invoiceExistAccount [$key] ['balance'] = $balance;
  2954. }
  2955. $receivablesInput = $invoiceReceivables->getInvoiceReceivablesByInput ();
  2956. $halfList = $invoiceReceivables->getInvoiceReceivablesByHalf ();
  2957. $this->data ['halfList'] = $halfList;
  2958. $this->data ['halfCount'] = count ( $halfList );
  2959. // print_r($receivablesList);
  2960. $this->data ['receivablesDate'] = date ( "Y-m-d" );
  2961. $this->data ['ieaCount'] = count ( $invoiceExistAccount );
  2962. $this->data ['invoiceExistAccount'] = $invoiceExistAccount;
  2963. $this->data ['receivablesInput'] = $receivablesInput;
  2964. $this->data ['year'] = date ( 'Y' );
  2965. $this->data ['invoiceUnAccount'] = $invoiceUnAccount;
  2966. $this->data ['receivablesList'] = $receivablesList;
  2967. $this->data ['staffList'] = $staffList;
  2968. $this->data ['category'] = $category;
  2969. $this->data ['memu'] = "invoice";
  2970. $this->data ['staff'] = $this->staff;
  2971. $this->data ['receiptMemu'] = 'invoiceReceivables';
  2972. $this->render ( "/admin/invoiceReceivables", $this->data );
  2973. }
  2974. /**
  2975. * 设置收款认领地区
  2976. */
  2977. function setInvoiceReceivablesClaim() {
  2978. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  2979. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  2980. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  2981. if (! empty ( $iridKey ) && ! empty ( $receivablesCategory )) {
  2982. Doo::loadModel ( 'invoiceReceivables' );
  2983. $invoiceReceivables = new invoiceReceivables ();
  2984. Doo::loadClass ( 'XDeode' );
  2985. $XDeode = new XDeode ( 5 );
  2986. Doo::loadModel ( 'invoiceROLog' );
  2987. $invoiceROLog = new invoiceROLog ();
  2988. $irid = $XDeode->decode ( $iridKey );
  2989. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  2990. if (empty ( $irDetail ))
  2991. die ( 'illegal request' );
  2992. $item = array (
  2993. 'irid' => $irid,
  2994. 'receivablesCategory' => $receivablesCategory
  2995. );
  2996. if ($receivablesCategory != 'PUBLIC') {
  2997. $item += array (
  2998. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  2999. 'inputType' => 1
  3000. );
  3001. }
  3002. $invoiceReceivables = new invoiceReceivables ();
  3003. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3004. // 收款操作日志
  3005. $item = array (
  3006. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 ",
  3007. 'date' => date ( "Y-m-d" ),
  3008. 'status' => 1,
  3009. 'img' => $this->staff [0] ['avatar'],
  3010. 'username' => $this->staff [0] ['username'],
  3011. 'uid' => $this->staff [0] ['sid'],
  3012. 'category' => $this->staff [0] ['category'],
  3013. 'irid' => $irid
  3014. );
  3015. $invoiceROLog->setInvoiceROLog ( $item );
  3016. if (empty ( $action ))
  3017. return '/invoiceReceivables';
  3018. else
  3019. return "/invoiceReceivablesAS";
  3020. }
  3021. die ( 'illegal request' );
  3022. }
  3023. /**
  3024. * 新添加收款直接入账发票
  3025. */
  3026. function invoiceCompareClaimPrice() {
  3027. // 收款录入
  3028. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  3029. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3030. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3031. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3032. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3033. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $iidKey )) {
  3034. Doo::loadModel ( 'invoiceReceivables' );
  3035. $invoiceReceivables = new invoiceReceivables ();
  3036. Doo::loadModel ( 'invoiceROLog' );
  3037. $invoiceROLog = new invoiceROLog ();
  3038. Doo::loadModel ( 'invoiceStatistics' );
  3039. Doo::loadModel ( 'invoice' );
  3040. $invoice = new invoice ();
  3041. Doo::loadClass ( 'XDeode' );
  3042. $XDeode = new XDeode ( 5 );
  3043. Doo::loadModel ( 'invoiceOperationLog' );
  3044. $invoiceOperationLog = new invoiceOperationLog ();
  3045. $iidKey = $XDeode->decode ( $iidKey );
  3046. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  3047. if (! ($invoiceDetail ['status'] == 2 && $invoiceDetail ['printStatus'] == 1 && $invoiceDetail ['untreadStatus'] == 0))
  3048. die ( 'illegal request' );
  3049. $receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  3050. // 收款录入 并绑定发票
  3051. Doo::db ()->beginTransaction ();
  3052. $bindStatus = 0;
  3053. if ($receivablesPrice <= $invoiceDetail ['invoicePrice']){
  3054. $bindStatus = 1;
  3055. }
  3056. $titleMark = $invoiceDetail ['invoiceTitle'];
  3057. if (! empty ( $invoiceDetail ['invoiceCompany'] ))
  3058. $titleMark = $invoiceDetail ['invoiceCompany'];
  3059. $item = array (
  3060. 'recepitTitleMark' => $titleMark,
  3061. 'bindStatus' => $bindStatus,
  3062. 'iid' => $invoiceDetail ['iid'],
  3063. 'bindPrice' => $invoiceDetail ['invoicePrice'],
  3064. 'bindDate' => date ( "Y-m-d H:i:s" ),
  3065. 'receivablesPrice' => $receivablesPrice,
  3066. 'OriginalPrice' => $receivablesPrice,
  3067. 'receivablesMessage' => $receivablesMessage,
  3068. 'receivablesSerial' => $receivablesSerial,
  3069. 'receivablesBank' => $receivablesBank,
  3070. 'receivablesDate' => $receivablesDate,
  3071. 'inputStaff' => $this->staff [0] ['username'],
  3072. 'accountClerk' => $this->staff [0] ['username'],
  3073. 'date' => date ( "Y-m-d" ),
  3074. 'receivablesCategory' => $invoiceDetail ['cid'] . ':' . $invoiceDetail ['categoryName'],
  3075. 'receivablesStaff' => $invoiceDetail ['sid'] . '-' . $invoiceDetail ['userName'],
  3076. 'confirmTime' => date ( "Y-m-d H:i:s" )
  3077. );
  3078. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  3079. $item = array ();
  3080. // 收款操作日志
  3081. $item = array (
  3082. 'operation' => $this->staff [0] ['username'] . " 转入 " . $invoiceDetail ['userName']
  3083. );
  3084. $item += array (
  3085. 'date' => date ( "Y-m-d" ),
  3086. 'status' => 1,
  3087. 'img' => $this->staff [0] ['avatar'],
  3088. 'username' => $this->staff [0] ['username'],
  3089. 'uid' => $this->staff [0] ['sid'],
  3090. 'category' => $this->staff [0] ['category'],
  3091. 'irid' => $irid
  3092. );
  3093. $invoiceROLog->setInvoiceROLog ( $item );
  3094. // 收款统计
  3095. $invoiceStatistics = new invoiceStatistics ();
  3096. $item = array (
  3097. 'date' => $receivablesDate,
  3098. 'priceClass' => 2,
  3099. 'irid' => $irid,
  3100. 'cid' => $invoiceDetail ['cid'],
  3101. 'staff' => $invoiceDetail ['sid'],
  3102. 'receivablesPrice' => $receivablesPrice
  3103. );
  3104. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3105. // 收款 入 发票
  3106. $detail = $invoiceDetail;
  3107. $iridString = "";
  3108. if (empty ( $detail ['irid'] ))
  3109. $iridString = $irid;
  3110. else
  3111. $iridString = $detail ['irid'] . ',' . $irid;
  3112. $item = array (
  3113. 'irid' => $iridString,
  3114. 'bindTime' => date ( "Y-m-d H:i:s" ),
  3115. 'updateTime' => date ( "Y-m-d H:i:s" ),
  3116. 'iid' => $detail ['iid']
  3117. );
  3118. $invoiceReceivables = new invoiceReceivables ();
  3119. $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  3120. if ($detail ['invoicePrice'] <= $sum)
  3121. $item += array (
  3122. 'untreadStatus' => 3
  3123. );
  3124. $invoice->setInvoiceByCondition ( $item );
  3125. // 操作日志
  3126. $item = array (
  3127. 'date' => date ( "Y-m-d H:i:s" ),
  3128. 'operation' => "收款入账" . $receivablesSerial . "到发票" . $detail ['invoiceSerial'],
  3129. 'status' => 8,
  3130. 'img' => $this->staff [0] ['avatar'],
  3131. 'username' => $this->staff [0] ['username'],
  3132. 'uid' => $this->staff [0] ['sid'],
  3133. 'category' => $this->staff [0] ['category'],
  3134. 'iid' => $detail ['iid']
  3135. );
  3136. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3137. // 入账汇总
  3138. $invoiceStatistics = new invoiceStatistics ();
  3139. // $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $iridString );
  3140. // $accountPrice = 0;
  3141. // foreach ( $list as $key => $value ) {
  3142. // $accountPrice += $value ['receivablesPrice'];
  3143. // }
  3144. $item = array (
  3145. 'date' => $receivablesDate,
  3146. 'priceClass' => 3,
  3147. 'cid' => $invoiceDetail ['cid'],
  3148. 'staff' => $invoiceDetail ['sid'],
  3149. 'accountPrice' => $receivablesPrice
  3150. );
  3151. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3152. // 公司流水记录
  3153. Doo::loadModel ( 'wasteBook' );
  3154. $wasteBook = new wasteBook ();
  3155. $abDetail = $wasteBook->getAccountBookByAid ( 2, 7, $irid );
  3156. $accountBank = '';
  3157. if ($receivablesBank == '纵横广发') {
  3158. $accountBank = 'CGBDeposit';
  3159. } elseif ($receivablesBank == '纵横工行') {
  3160. $accountBank = 'ICBCDeposit';
  3161. } elseif ($receivablesBank == '华润银行') {
  3162. $accountBank = 'HUADeposit';
  3163. } elseif ($receivablesBank == '个人广发') {
  3164. $accountBank = 'PersonalDeposit';
  3165. }
  3166. if (empty ( $abDetail )) {
  3167. $item = array (
  3168. 'dataID' => $irid,
  3169. 'expensesType' => 1,
  3170. 'accountType' => 7,
  3171. 'accountPrice' => $receivablesPrice,
  3172. 'accountPriceShow' => $receivablesPrice,
  3173. 'accountBank' => $accountBank,
  3174. 'category' => $this->staff [0] ['category'],
  3175. 'cid' => $this->staff [0] ['cid'],
  3176. 'name' => $this->staff [0] ['username'],
  3177. 'sid' => $this->staff [0] ['sid'],
  3178. 'inputDate' => date ( "Y-m-d H:i:s" )
  3179. );
  3180. $wasteBook->setAccountBookStatistics ( $item );
  3181. }
  3182. Doo::db ()->commit ();
  3183. }
  3184. return '/invoiceReceivables';
  3185. }
  3186. /**
  3187. * 录入收款数据
  3188. * @return string
  3189. */
  3190. function invoiceReceivablesDo() {
  3191. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3192. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3193. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3194. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3195. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3196. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  3197. Doo::loadModel ( 'invoiceReceivables' );
  3198. $invoiceReceivables = new invoiceReceivables ();
  3199. Doo::loadModel ( 'invoiceROLog' );
  3200. $invoiceROLog = new invoiceROLog ();
  3201. Doo::loadModel ( 'invoiceStatistics' );
  3202. $invoiceStatistics = new invoiceStatistics ();
  3203. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $receivablesCategory ) && ! empty ( $receivablesStaff )) {
  3204. $item = array (
  3205. 'receivablesPrice' => $receivablesPrice,
  3206. 'OriginalPrice' => $receivablesPrice,
  3207. 'receivablesMessage' => $receivablesMessage,
  3208. 'receivablesSerial' => "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  3209. 'receivablesBank' => $receivablesBank,
  3210. 'receivablesDate' => $receivablesDate,
  3211. 'inputStaff' => $this->staff [0] ['username'],
  3212. 'date' => date ( "Y-m-d" ),
  3213. 'receivablesCategory' => $receivablesCategory,
  3214. 'receivablesStaff' => $receivablesStaff
  3215. );
  3216. if ($receivablesCategory != 'PUBLIC') {
  3217. $item += array (
  3218. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3219. 'inputType' => 1
  3220. );
  3221. }
  3222. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  3223. $item = array ();
  3224. // 收款操作日志
  3225. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3226. $item = array (
  3227. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  3228. );
  3229. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3230. $item = array (
  3231. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  3232. );
  3233. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3234. $receivablesStaff = explode ( '-', $receivablesStaff );
  3235. $item = array (
  3236. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  3237. );
  3238. }
  3239. $item += array (
  3240. 'date' => date ( "Y-m-d" ),
  3241. 'status' => 1,
  3242. 'img' => $this->staff [0] ['avatar'],
  3243. 'username' => $this->staff [0] ['username'],
  3244. 'uid' => $this->staff [0] ['sid'],
  3245. 'category' => $this->staff [0] ['category'],
  3246. 'irid' => $irid
  3247. );
  3248. $invoiceROLog->setInvoiceROLog ( $item );
  3249. $item = array (
  3250. 'date' => $receivablesDate,
  3251. 'priceClass' => 2,
  3252. 'irid' => $irid,
  3253. 'receivablesPrice' => $receivablesPrice
  3254. );
  3255. if ($receivablesCategory != 'PUBLIC') {
  3256. $receivablesCategory = explode ( ":", $receivablesCategory );
  3257. $item += array (
  3258. 'cid' => $receivablesCategory [0]
  3259. );
  3260. }
  3261. if ($receivablesStaff2 != 'PUBLIC') {
  3262. $receivablesStaff = explode ( "-", $receivablesStaff2 );
  3263. $item += array (
  3264. 'staff' => $receivablesStaff [0]
  3265. );
  3266. }
  3267. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3268. $toparty = $this->getWxidByCategory ( $receivablesCategory [1] );
  3269. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  3270. $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  3271. if ($toparty != 0)
  3272. $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  3273. // 公司流水记录
  3274. Doo::loadModel ( 'wasteBook' );
  3275. $wasteBook = new wasteBook ();
  3276. $abDetail = $wasteBook->getAccountBookByAid ( 1, 7, $irid );
  3277. $accountBank = '';
  3278. if ($receivablesBank == '纵横广发') {
  3279. $accountBank = 'CGBDeposit';
  3280. } elseif ($receivablesBank == '纵横工行') {
  3281. $accountBank = 'ICBCDeposit';
  3282. } elseif ($receivablesBank == '华润银行') {
  3283. $accountBank = 'HUADeposit';
  3284. } elseif ($receivablesBank == '个人广发') {
  3285. $accountBank = 'PersonalDeposit';
  3286. }
  3287. $item = array (
  3288. 'dataID' => $irid,
  3289. 'expensesType' => 1,
  3290. 'accountType' => 7,
  3291. 'accountPriceShow' => $receivablesPrice,
  3292. 'accountPrice' => $receivablesPrice,
  3293. 'accountBank' => $accountBank,
  3294. 'category' => $this->staff [0] ['category'],
  3295. 'cid' => $this->staff [0] ['cid'],
  3296. 'name' => $this->staff [0] ['username'],
  3297. 'sid' => $this->staff [0] ['sid'],
  3298. 'inputDate' => date ( "Y-m-d H:i:s" )
  3299. );
  3300. $wasteBook->setAccountBookStatistics ( $item );
  3301. }
  3302. return "/invoiceReceivables";
  3303. }
  3304. /**
  3305. * 收款认领页面-包括公共认领 办事处认领 最近已认领数据
  3306. */
  3307. function invoiceReceivablesClaim() {
  3308. Doo::loadModel ( 'invoiceReceivables' );
  3309. $invoiceReceivables = new invoiceReceivables ();
  3310. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  3311. $this->data ['receivablesList'] = $receivablesList;
  3312. $this->data ['memu'] = "invoice";
  3313. $this->data ['staff'] = $this->staff;
  3314. $this->data ['receiptMemu'] = 'invoiceReceivablesClaim';
  3315. $this->render ( "/admin/invoiceReceivablesClaim", $this->data );
  3316. }
  3317. function invoiceReceivablesTitleMarkSet() {
  3318. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  3319. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  3320. if (empty ( $iridKey ) || empty ( $recepitTitleMark ))
  3321. die ( 'illegal request' );
  3322. Doo::loadModel ( 'invoiceReceivables' );
  3323. $invoiceReceivables = new invoiceReceivables ();
  3324. Doo::loadClass ( 'XDeode' );
  3325. $XDeode = new XDeode ( 5 );
  3326. $irid = $XDeode->decode ( $iridKey );
  3327. if (! is_numeric ( $irid ))
  3328. die ( 'illegal request' );
  3329. $invoiceReceivables->recepitTitleMark = $recepitTitleMark;
  3330. $invoiceReceivables->update ( array (
  3331. 'where' => 'irid = ' . $irid
  3332. ) );
  3333. return '/invoiceReceivablesClaim';
  3334. }
  3335. /**
  3336. * 更新收款相关数据
  3337. */
  3338. function invoiceReceivablesUpdateClaim() {
  3339. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3340. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3341. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3342. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3343. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3344. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  3345. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  3346. if (empty ( $claimKey ))
  3347. die ( 'illegal request' );
  3348. Doo::loadModel ( 'invoiceReceivables' );
  3349. $invoiceReceivables = new invoiceReceivables ();
  3350. Doo::loadModel ( 'invoiceROLog' );
  3351. $invoiceROLog = new invoiceROLog ();
  3352. $con = ' and iid=0 and bindStatus=0'; // and receivablesCategory!="PUBLIC" and receivablesStaff!="PUBLIC"
  3353. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  3354. if (empty ( $detail ))
  3355. die ( 'illegal request' );
  3356. $invoiceReceivables = new invoiceReceivables ();
  3357. $item = array (
  3358. 'irid' => $detail ['irid']
  3359. );
  3360. if ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3361. $item += array (
  3362. 'confirmTime' => date ( "Y-m-d H:i:s" )
  3363. );
  3364. }
  3365. if (! empty ( $receivablesCategory ))
  3366. $item += array (
  3367. 'receivablesCategory' => $receivablesCategory
  3368. );
  3369. if (! empty ( $receivablesStaff ))
  3370. $item += array (
  3371. 'receivablesStaff' => $receivablesStaff
  3372. );
  3373. if (! empty ( $receivablesPrice ))
  3374. $item += array (
  3375. 'receivablesPrice' => $receivablesPrice
  3376. );
  3377. if (! empty ( $receivablesMessage ))
  3378. $item += array (
  3379. 'receivablesMessage' => $receivablesMessage
  3380. );
  3381. if (! empty ( $receivablesBank ))
  3382. $item += array (
  3383. 'receivablesBank' => $receivablesBank
  3384. );
  3385. if (! empty ( $receivablesDate ))
  3386. $item += array (
  3387. 'receivablesDate' => $receivablesDate
  3388. );
  3389. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3390. // 收款操作日志
  3391. $item = array ();
  3392. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3393. $item = array (
  3394. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  3395. );
  3396. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3397. $item = array (
  3398. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  3399. );
  3400. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3401. $receivablesStaff = explode ( '-', $receivablesStaff );
  3402. $item = array (
  3403. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  3404. );
  3405. }
  3406. $item += array (
  3407. 'date' => date ( "Y-m-d" ),
  3408. 'status' => 1,
  3409. 'img' => $this->staff [0] ['avatar'],
  3410. 'username' => $this->staff [0] ['username'],
  3411. 'uid' => $this->staff [0] ['sid'],
  3412. 'category' => $this->staff [0] ['category'],
  3413. 'irid' => $detail ['irid']
  3414. );
  3415. $invoiceROLog->setInvoiceROLog ( $item );
  3416. return '/invoiceReceivablesAS';
  3417. }
  3418. function invoiceReceivablesDelete() {
  3419. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  3420. $skll = $this->get_args ( 'skll' ) ? $this->get_args ( 'skll' ) : "";
  3421. if ($skll != '删除到款')
  3422. die ( 'illegal request' );
  3423. if (empty ( $claimKey ))
  3424. die ( 'illegal request' );
  3425. Doo::loadModel ( 'invoiceReceivables' );
  3426. $invoiceReceivables = new invoiceReceivables ();
  3427. $con = ' and bindStatus=0 ';
  3428. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  3429. if (empty ( $detail ))
  3430. die ( 'illegal request' );
  3431. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  3432. // 扣除收款汇总信息 汇总
  3433. Doo::loadModel ( 'invoiceStatistics' );
  3434. $invoiceStatistics = new invoiceStatistics ();
  3435. $item = array (
  3436. 'date' => $detail ['receivablesDate'],
  3437. 'priceClass' => 2,
  3438. 'irid' => $detail ['irid'],
  3439. 'receivablesPrice' => - $detail ['receivablesPrice']
  3440. );
  3441. if ($detail ['receivablesCategory'] != 'PUBLIC') {
  3442. $receivablesCategory = explode ( ":", $detail ['receivablesCategory'] );
  3443. $item += array (
  3444. 'cid' => $receivablesCategory [0]
  3445. );
  3446. }
  3447. if ($detail ['receivablesStaff'] != 'PUBLIC') {
  3448. $receivablesStaff = explode ( "-", $detail ['receivablesStaff'] );
  3449. $item += array (
  3450. 'staff' => $receivablesStaff [0]
  3451. );
  3452. }
  3453. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3454. // 公司流水-删除时删除流水
  3455. Doo::loadModel ( 'wasteBook' );
  3456. $wasteBook = new wasteBook ();
  3457. $wasteBook->delete ( array (
  3458. 'where' => 'dataID=' . $detail ['irid'] . ' and accountType=7',
  3459. 'limit' => 1
  3460. ) );
  3461. return '/invoiceReceivablesAS';
  3462. }
  3463. /**
  3464. * 管理员录入的收款 ,确认认领到谁的名下.统计收款金额
  3465. */
  3466. function invoiceReceivablesAscription() {
  3467. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  3468. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  3469. Doo::loadModel ( 'invoiceReceivables' );
  3470. $invoiceReceivables = new invoiceReceivables ();
  3471. Doo::loadModel ( 'invoiceROLog' );
  3472. $invoiceROLog = new invoiceROLog ();
  3473. Doo::loadModel ( 'invoiceStatistics' );
  3474. $invoiceStatistics = new invoiceStatistics ();
  3475. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  3476. if (! empty ( $detail ) && $detail ['receivablesStaff'] == 'PUBLIC' && ! empty ( $recepitTitleMark )) {
  3477. $item = array (
  3478. 'irid' => $detail ['irid'],
  3479. 'receivablesCategory' => $this->staff [0] ['cid'] . ":" . $this->staff [0] ['category'],
  3480. 'receivablesStaff' => $this->staff [0] ['sid'] . "-" . $this->staff [0] ['username'],
  3481. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3482. 'recepitTitleMark' => $recepitTitleMark,
  3483. 'source' => 1
  3484. );
  3485. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3486. $item = array (
  3487. 'date' => date ( "Y-m-d" ),
  3488. 'operation' => $this->staff [0] ['username'] . " 认领 ",
  3489. 'status' => 2,
  3490. 'img' => $this->staff [0] ['avatar'],
  3491. 'username' => $this->staff [0] ['username'],
  3492. 'uid' => $this->staff [0] ['sid'],
  3493. 'category' => $this->staff [0] ['category'],
  3494. 'irid' => $irid
  3495. );
  3496. $invoiceROLog->setInvoiceROLog ( $item );
  3497. $item = array (
  3498. 'cid' => $this->staff [0] ['cid'],
  3499. 'staff' => $this->staff [0] ['sid']
  3500. );
  3501. $invoiceStatistics->updateInvoiceStatisticsByIrid ( $item, $detail ['irid'], 2 );
  3502. }
  3503. return "/invoiceReceivablesClaim";
  3504. }
  3505. /**
  3506. */
  3507. function invoiceMyReceivables() {
  3508. Doo::loadModel ( 'invoiceReceivables' );
  3509. $invoiceReceivables = new invoiceReceivables ();
  3510. Doo::loadModel ( 'invoiceStatistics' );
  3511. $invoiceStatistics = new invoiceStatistics ();
  3512. $isMonth = $invoiceStatistics->getStatisticsByMonth ( $this->staff [0] ['sid'] );
  3513. $year = date ( "Y" );
  3514. $tmp_date = date ( "Ym" );
  3515. $tmp_year = substr ( $tmp_date, 0, 4 );
  3516. $tmp_mon = substr ( $tmp_date, 4, 2 );
  3517. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  3518. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  3519. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . ".htm";
  3520. $htm = $this->showCache ( $path );
  3521. $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  3522. $this->data ['isMonth'] = $isMonth;
  3523. $this->data ['htm'] = $htm;
  3524. $this->data ['list'] = $list;
  3525. $this->data ['memu'] = "invoice";
  3526. $this->data ['staff'] = $this->staff;
  3527. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  3528. $this->render ( "/admin/invoiceMyReceivables", $this->data );
  3529. }
  3530. /**
  3531. * 纸票管理
  3532. */
  3533. function invoicePaper() {
  3534. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3535. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3536. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3537. $this->data ['dateString'] = $date;
  3538. $this->data ['status'] = $status;
  3539. $this->data ['invoiceType'] = $invoiceType;
  3540. $this->data ['memu'] = "invoice";
  3541. $this->data ['staff'] = $this->staff;
  3542. $this->data ['receiptMemu'] = 'invoicePaper';
  3543. $this->render ( "/admin/invoicePaper", $this->data );
  3544. }
  3545. /**
  3546. * 获得纸票分页数据
  3547. */
  3548. function ajaxGetinvoicePaperAchieve() {
  3549. Doo::loadModel ( 'invoicePaper' );
  3550. $invoicePaper = new invoicePaper ();
  3551. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3552. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3553. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ORDINARY";
  3554. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3555. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  3556. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  3557. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  3558. $MebSea = $this->get_args ( 'search' );
  3559. $MebSea = $MebSea ['value'];
  3560. $page_size = $length;
  3561. $con = '';
  3562. if ($status == 'ALL')
  3563. $con = ' where 1 ';
  3564. elseif ($status == 'PRINTED')
  3565. $con = ' where a.iid!=0 '; // $con = ' where b.isDelete=0 and a.iid!=0 and b.status=2 and b.untreadStatus=0 ';
  3566. elseif ($status == 'UNPRINT')
  3567. $con = ' where a.iid=0 '; // $con = ' where b.isDelete=0 and a.iid=0 and b.status=2 and b.untreadStatus=0 ';
  3568. elseif ($status == 'TICKET')
  3569. $con = ' where b.isDelete=0 and b.untreadStatus=2';
  3570. if ($invoiceType == 'ORDINARY')
  3571. $con .= ' and a.invoiceType=0 ';
  3572. elseif ($invoiceType == 'SPECIAL')
  3573. $con .= ' and a.invoiceType=1 ';
  3574. $dateArr = explode ( ':', $date );
  3575. $D1 = $dateString = '';
  3576. $D2 = '';
  3577. if (! empty ( $date )) {
  3578. $D1 = $dateArr [0];
  3579. if (isset ( $dateArr [1] ))
  3580. $D2 = $dateArr [1];
  3581. else
  3582. $D2 = '';
  3583. $dateString = $D1 . " : " . $D2;
  3584. }
  3585. if (! empty ( $D1 ) && ! empty ( $D2 ))
  3586. $con .= ' and b.printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  3587. elseif (! empty ( $D1 ) && empty ( $D2 ))
  3588. $con .= ' and b.printTime like "%' . $D1 . '%" ';
  3589. if (! empty ( $MebSea ))
  3590. $con .= ' and ( b.invoiceTitle like "%' . $MebSea . '%" or b.invoiceCompany like "%' . $MebSea . '%" or a.invoiceNo like "%' . $MebSea . '%" )';
  3591. $invoiceTotal = $invoicePaper->getInvoicePaperCount ();
  3592. $sql = ' ' . $con;
  3593. $limit = $page . ',' . $page_size;
  3594. $list = $invoicePaper->getInvoicePaper ( $limit, $sql, 'desc' );
  3595. $paperList = array ();
  3596. foreach ( $list as $key => $value ) {
  3597. $irDetail = array ();
  3598. if ($value ['iid'] == 0)
  3599. array_push ( $irDetail, '<a href="javascript:if(window.confirm(\'确认删除?\'))window.location=\'/invoicePaperDel/' . $value ['ipidKey'] . '\'" >删除</a>' );
  3600. else
  3601. array_push ( $irDetail, '' );
  3602. array_push ( $irDetail, $value ['invoiceCode'] );
  3603. array_push ( $irDetail, $value ['invoiceNo'] );
  3604. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKey'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  3605. if ($value ['invoiceType'] == 1)
  3606. array_push ( $irDetail, $value ['invoiceCompany'] );
  3607. else
  3608. array_push ( $irDetail, $value ['invoiceTitle'] );
  3609. if ($value ['invoiceType'] == 1)
  3610. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  3611. else
  3612. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  3613. array_push ( $irDetail, $value ['invoiceElement'] );
  3614. array_push ( $irDetail, $value ['categoryName'] . '-' . $value ['userName'] );
  3615. array_push ( $irDetail, $value ['printTime'] );
  3616. array_push ( $paperList, $irDetail );
  3617. }
  3618. // $approvalListJson = json_encode ( $approvalList );
  3619. $recordsFiltered = $invoiceTotal;
  3620. echo json_encode ( array (
  3621. "draw" => intval ( $draw ),
  3622. "recordsTotal" => intval ( $invoiceTotal ),
  3623. "recordsFiltered" => intval ( $recordsFiltered ),
  3624. "data" => $paperList
  3625. ), JSON_UNESCAPED_UNICODE );
  3626. }
  3627. function invoicePaperDel() {
  3628. $ipidKey = isset ( $this->params ['ipidKey'] ) ? $this->params ['ipidKey'] : "";
  3629. $XDeode = new XDeode ( 5 );
  3630. $ipid = $XDeode->decode ( $ipidKey );
  3631. if (empty ( $ipid ))
  3632. die ( 'illegal request' );
  3633. Doo::loadModel ( 'invoicePaper' );
  3634. $invoicePaper = new invoicePaper ();
  3635. $invoicePaper->delete ( array (
  3636. 'where' => 'ipid=' . $ipid . ' and iid=0',
  3637. 'limit' => 1
  3638. ) );
  3639. return '/invoicePaper';
  3640. }
  3641. /**
  3642. * 添加纸质发票号
  3643. */
  3644. function invoicePaperAdd() {
  3645. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : '0';
  3646. $invoiceCode = $this->get_args ( 'invoiceCode' ) ? $this->get_args ( 'invoiceCode' ) : "";
  3647. $invoiceNoStart = $this->get_args ( 'invoiceNoStart' ) && is_numeric ( $this->get_args ( 'invoiceNoStart' ) ) ? $this->get_args ( 'invoiceNoStart' ) : 0;
  3648. $invoiceNoTotal = $this->get_args ( 'invoiceNoTotal' ) && is_numeric ( $this->get_args ( 'invoiceNoTotal' ) ) ? $this->get_args ( 'invoiceNoTotal' ) : 0;
  3649. if ($invoiceType != '' && ! empty ( $invoiceCode ) && ! empty ( $invoiceNoStart ) && ! empty ( $invoiceNoTotal )) {
  3650. $sum = $invoiceNoStart + $invoiceNoTotal;
  3651. if (empty ( $sum ))
  3652. die ( 'illegal request' );
  3653. // echo $invoiceNoStart;
  3654. // echo $sum;
  3655. // echo strlen((int)$invoiceNoStart);
  3656. $sumLenght = strlen ( $invoiceNoStart ) - strlen ( ( int ) $invoiceNoStart );
  3657. Doo::db ()->beginTransaction ();
  3658. // 批量存储纸质发票
  3659. $date = date ( "Y-m-d H:i:s" );
  3660. $sql = 'INSERT INTO CLD_invoicePaper (invoiceType, invoiceCode,invoiceNo,date)
  3661. VALUES ';
  3662. $paperList = array ();
  3663. for($invoiceNoStart; $invoiceNoStart <= $sum - 1; $invoiceNoStart ++) {
  3664. // 数字前面自加0
  3665. $INLENGHT = strlen ( ( int ) $invoiceNoStart ) + $sumLenght;
  3666. $var = sprintf ( "%0" . $INLENGHT . "d", $invoiceNoStart );
  3667. $paperSql = '(' . $invoiceType . ',"' . $invoiceCode . '","' . $var . '","' . $date . '")';
  3668. array_push ( $paperList, $paperSql );
  3669. }
  3670. if (empty ( $paperList ))
  3671. die ( 'illegal request' );
  3672. $sql = $sql . implode ( ',', $paperList );
  3673. Doo::db ()->query ( $sql );
  3674. Doo::db ()->commit ();
  3675. return 'invoicePaper';
  3676. }
  3677. die ( 'illegal request' );
  3678. }
  3679. /**
  3680. * 收款绑定发票 ,//一个收款只能绑定一个发票
  3681. */
  3682. function invoiceBindReceivables() {
  3683. $claimKey = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  3684. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  3685. Doo::loadModel ( 'invoice' );
  3686. $invoice = new invoice ();
  3687. Doo::loadModel ( 'invoiceReceivables' );
  3688. $invoiceReceivables = new invoiceReceivables ();
  3689. Doo::loadModel ( 'invoiceOperationLog' );
  3690. $invoiceOperationLog = new invoiceOperationLog ();
  3691. if (empty ( $invoiceKey ) || empty ( $claimKey ))
  3692. die ( 'illegal request' );
  3693. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  3694. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey );
  3695. if (empty ( $detail ) && empty ( $detailM ))
  3696. die ( 'illegal request' );
  3697. if ($detail ['untreadStatus'] == 3)
  3698. die ( 'illegal request' );
  3699. // 修改 绑定状态改为 金额
  3700. $invoiceReceivables = new invoiceReceivables ();
  3701. //有BUG-需修改
  3702. $invoicePrice = $detail ['invoicePrice'] + $detailM ['bindPrice'];
  3703. if ($detailM ['receivablesPrice'] > $invoicePrice) {
  3704. $item = array (
  3705. 'bindPrice' => $invoicePrice
  3706. );
  3707. } elseif ($detailM ['receivablesPrice'] <= $invoicePrice) {
  3708. $item = array (
  3709. 'bindPrice' => $invoicePrice,
  3710. 'bindStatus' => 1,
  3711. 'bindDate' => date ( "Y-m-d H:i:s" )
  3712. );
  3713. } else {
  3714. die ( 'illegal request' );
  3715. }
  3716. if ($detailM ['iid'] == 0) {
  3717. $item += array (
  3718. 'iid' => $detail ['iid']
  3719. );
  3720. } else {
  3721. $iidExtend = explode ( ',', $detailM ['iidExtend'] );
  3722. array_push ( $iidExtend, $detail ['iid'] );
  3723. $item += array (
  3724. 'iidExtend' => implode ( ',', $iidExtend )
  3725. );
  3726. }
  3727. $titleMark = $detail ['invoiceTitle'];
  3728. if (! empty ( $detail ['invoiceCompany'] ))
  3729. $titleMark = $detail ['invoiceCompany'];
  3730. $item += array (
  3731. 'irid' => $detailM ['irid'],
  3732. 'recepitTitleMark' => $titleMark,
  3733. 'accountClerk' => $this->staff [0] ['username']
  3734. );
  3735. // 如何没有人收款 则自动绑定收款
  3736. if ($detailM ['receivablesCategory'] == 'PUBLIC' || $detailM ['receivablesStaff'] == 'PUBLIC') {
  3737. $item += array (
  3738. 'receivablesCategory' => $detail ['cid'] . ':' . $detail ['categoryName'],
  3739. 'receivablesStaff' => $detail ['sid'] . '-' . $detail ['userName']
  3740. );
  3741. }
  3742. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3743. $iridString = "";
  3744. if (empty ( $detail ['irid'] ))
  3745. $iridString = $detailM ['irid'];
  3746. else
  3747. $iridString = $detail ['irid'] . ',' . $detailM ['irid'];
  3748. $item = array (
  3749. 'iid' => $detail ['iid'],
  3750. 'irid' => $iridString
  3751. );
  3752. $invoiceReceivables = new invoiceReceivables ();
  3753. $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  3754. if ($detail ['invoicePrice'] <= $sum)
  3755. $item += array (
  3756. 'untreadStatus' => 3,
  3757. 'bindTime' => date ( "Y-m-d H:i:s" )
  3758. );
  3759. // print_r($item);
  3760. // echo $sum;die;
  3761. $invoice->setInvoiceByCondition ( $item );
  3762. // 操作日志
  3763. $item = array (
  3764. 'date' => date ( "Y-m-d H:i:s" ),
  3765. 'operation' => "收款" . $detailM ['receivablesSerial'] . "入账到发票" . $detail ['invoiceSerial'],
  3766. 'status' => 8,
  3767. 'img' => $this->staff [0] ['avatar'],
  3768. 'username' => $this->staff [0] ['username'],
  3769. 'uid' => $this->staff [0] ['sid'],
  3770. 'category' => $this->staff [0] ['category'],
  3771. 'iid' => $detail ['iid']
  3772. );
  3773. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3774. Doo::loadModel ( 'invoiceStatistics' );
  3775. $invoiceStatistics = new invoiceStatistics ();
  3776. $item = array (
  3777. 'date' => $detailM ['receivablesDate'],
  3778. 'priceClass' => 3,
  3779. 'cid' => $detail ['cid'],
  3780. 'staff' => $detail ['sid'],
  3781. 'accountPrice' => $detailM ['receivablesPrice']
  3782. );
  3783. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3784. // 公司流水记录
  3785. // Doo::loadModel ( 'wasteBook' );
  3786. // $wasteBook = new wasteBook ();
  3787. // $abDetail = $wasteBook->getAccountBookByAid (1,8,$detail ['iid'] );
  3788. // $accountBank='';
  3789. // if ($detailM ['receivablesBank']=='纵横广发'){
  3790. // $accountBank='CGBDeposit';
  3791. // }elseif($detailM ['receivablesBank']=='纵横工行'){
  3792. // $accountBank='ICBCDeposit';
  3793. // }elseif($detailM ['receivablesBank']=='华润银行'){
  3794. // $accountBank='HUADeposit';
  3795. // }elseif($detailM ['receivablesBank']=='个人广发'){
  3796. // $accountBank='PersonalDeposit';
  3797. // }
  3798. // if (empty($abDetail)){
  3799. // $item = array (
  3800. // 'dataID' => $detail ['iid'],
  3801. // 'expensesType' => 1,
  3802. // 'accountType' => 8,
  3803. // 'accountPriceShow'=>$detail ['invoicePrice'],
  3804. // 'accountPrice'=>$detail ['invoicePrice'],
  3805. // 'accountBank'=>$accountBank,
  3806. // 'category'=>$this->staff[0]['category'],
  3807. // 'cid'=>$this->staff[0]['cid'],
  3808. // 'name'=>$this->staff[0]['username'],
  3809. // 'sid'=>$this->staff[0]['sid'],
  3810. // 'inputDate'=>date ( "Y-m-d H:i:s" )
  3811. // );
  3812. // $wasteBook->setAccountBookStatistics($item);
  3813. // }
  3814. return "/invoiceReceivables";
  3815. }
  3816. /**
  3817. * 核销 动作,确认入账统计 发票收款完成--需求更变 废弃 function invoiceEnterReceivables() { $invoiceKey = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : ""; // $invoiceClaim = $this->get_args ( 'invoiceClaim' ) ? $this->get_args ( 'invoiceClaim' ) : ""; Doo::loadModel ( 'invoice' ); $invoice = new invoice (); Doo::loadModel ( 'invoiceOperationLog' ); $invoiceOperationLog = new invoiceOperationLog (); Doo::loadModel ( 'invoiceStatistics' ); $invoiceStatistics = new invoiceStatistics (); Doo::loadModel ( 'invoiceReceivables' ); $invoiceReceivables = new invoiceReceivables (); $detail = $invoice->getInvoiceByIid ( $invoiceKey ); if (empty ( $detail )) die ( 'illegal request' ); if (empty ( $detail ['irid'] )) die ( 'illegal request' ); $item = array ( 'untreadStatus' => 3, 'updateTime' => date ( "Y-m-d H:i:s" ), 'iid' => $detail ['iid'] ); $invoice->setInvoiceByCondition ( $item ); // 操作日志 $item = array ( 'date' => date ( "Y-m-d H:i:s" ), 'operation' => "发票" . $detail ['invoiceSerial'] . "收款完成", 'status' => 9, 'img' => $this->staff [0] ['avatar'], 'username' => $this->staff [0] ['username'], 'uid' => $this->staff [0] ['sid'], 'category' => $this->staff [0] ['category'], 'iid' => $detail ['iid'] ); $invoiceOperationLog->setInvoiceOperationLog ( $item ); $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $detail ['irid'] ); $accountPrice = 0; foreach ( $list as $key => $value ) { $accountPrice += $value ['receivablesPrice']; } $item = array ( 'date' => date ( "Y-m-d H:i:s" ), 'priceClass' => 3, 'cid' => $this->staff [0] ['cid'], 'staff' => $this->staff [0] ['sid'], 'accountPrice' => $accountPrice ); $invoiceStatistics->setInvoiceStatisticsByCondition ( $item ); return "/invoice"; }
  3818. */
  3819. function invoiceAggregate() {
  3820. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3821. Doo::loadModel ( 'invoiceStatistics' );
  3822. $invoiceStatistics = new invoiceStatistics ();
  3823. Doo::loadModel ( 'L_category' );
  3824. $Lcategory = new L_category ();
  3825. $isList = $invoiceStatistics->getInvoiceStatisticsByYear ( $year );
  3826. $LcategoryList = $Lcategory->getCategory ();
  3827. // print_r($isList);
  3828. $html = ""; // $invoicePriceCategory=0;$receivablesPriceCategory=0;$accountPriceCategory=0;
  3829. foreach ( $LcategoryList as $key => $value ) {
  3830. $html .= '<tr><th><a href="/invoiceAggregateCategory/' . $value ['cidKey'] . '">' . $value ['title'] . '</a></th>';
  3831. $month = 1;
  3832. $invoicePriceYear = 0;
  3833. $receivablesPriceYear = 0;
  3834. $accountPriceYear = 0;
  3835. for(; $month <= 12; $month ++) {
  3836. $flag = true;
  3837. foreach ( $isList ['statisticsMonthCid'] as $k => $v ) {
  3838. if ($value ['cid'] == $v ['cid'] && $month == $v ['month']) {
  3839. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  3840. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  3841. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  3842. ';
  3843. $invoicePriceYear += $v ['invoicePrice'];
  3844. $receivablesPriceYear += $v ['receivablesPrice'];
  3845. $accountPriceYear += $v ['accountPrice'];
  3846. $flag = false;
  3847. break;
  3848. }
  3849. }
  3850. if ($flag)
  3851. $html .= '<td class="taR"></td>
  3852. <td class="taR"></td>
  3853. <td class="taR"><b></b></td>
  3854. ';
  3855. }
  3856. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  3857. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  3858. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  3859. ';
  3860. $html .= '</tr>';
  3861. }
  3862. $html .= '<tr><th><b class="colGreen">月合计</b></th>';
  3863. $invoicePriceYear = 0;
  3864. $receivablesPriceYear = 0;
  3865. $accountPriceYear = 0;
  3866. for($month = 1; $month <= 12; $month ++) {
  3867. $flag = true;
  3868. foreach ( $isList ['statisticsMonth'] as $k => $v ) {
  3869. if ($month == $v ['month']) {
  3870. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  3871. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  3872. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  3873. ';
  3874. $invoicePriceYear += $v ['invoicePrice'];
  3875. $receivablesPriceYear += $v ['receivablesPrice'];
  3876. $accountPriceYear += $v ['accountPrice'];
  3877. $flag = false;
  3878. break;
  3879. }
  3880. }
  3881. if ($flag) {
  3882. $html .= '<td class="taR"></td>
  3883. <td class="taR"></td>
  3884. <td class="taR"><b></b></td>
  3885. ';
  3886. }
  3887. }
  3888. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  3889. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  3890. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  3891. ';
  3892. $html .= '</tr>';
  3893. // print_r($isList);
  3894. $this->data ['html'] = $html;
  3895. $this->data ['LcategoryList'] = $LcategoryList;
  3896. $this->data ['isList'] = $isList;
  3897. $this->data ['year'] = $year;
  3898. $this->data ['memu'] = "invoice";
  3899. $this->data ['staff'] = $this->staff;
  3900. $this->data ['receiptMemu'] = 'invoiceAggregate';
  3901. $this->render ( "/admin/invoiceAggregate", $this->data );
  3902. }
  3903. function invoiceAggregateStaff() {
  3904. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3905. Doo::loadModel ( 'invoiceStatistics' );
  3906. $invoiceStatistics = new invoiceStatistics ();
  3907. Doo::loadModel ( 'L_category' );
  3908. $Lcategory = new L_category ();
  3909. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year );
  3910. $staffList = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year );
  3911. $cStaff = $Lcategory->getCategoryStaff ();
  3912. $html = '';
  3913. foreach ( $cStaff as $key => $value ) {
  3914. $categoryFir = true;
  3915. foreach ( $value ['staff'] as $k => $v ) {
  3916. if ($categoryFir) {
  3917. $width = count ( $value ['staff'] ) + 1;
  3918. $html .= '<tr><th rowspan="' . $width . '">' . $value ['title'] . ' </th>';
  3919. $categoryFir = false;
  3920. } else
  3921. $html .= '<tr>';
  3922. $html .= '<th>' . $v ['username'] . '</th>';
  3923. $invoicePriceStaffYear = 0;
  3924. $receivablesPriceStaffYear = 0;
  3925. $accountPriceStaffYear = 0;
  3926. for($month = 1; $month <= 12; $month ++) {
  3927. $flag = true;
  3928. foreach ( $staffList ['statisticsMonthStaff'] as $sl => $slv ) {
  3929. if ($v ['sid'] == $slv ['staff'] && $month == $slv ['month']) {
  3930. $html .= '<td class="taR">¥' . $slv ['invoicePrice'] . '</td>
  3931. <td class="taR">¥' . $slv ['receivablesPrice'] . '</td>
  3932. <td class="taR"><b>¥' . $slv ['accountPrice'] . '</b></td>
  3933. ';
  3934. $invoicePriceStaffYear += $slv ['invoicePrice'];
  3935. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  3936. $accountPriceStaffYear += $slv ['accountPrice'];
  3937. $flag = false;
  3938. break;
  3939. }
  3940. }
  3941. if ($flag)
  3942. $html .= '<td class="taR"></td>
  3943. <td class="taR"></td>
  3944. <td class="taR"><b></b></td>
  3945. ';
  3946. }
  3947. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  3948. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  3949. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  3950. ';
  3951. }
  3952. $html .= '</tr>';
  3953. // 小计
  3954. if (! empty ( $value ['staff'] )) {
  3955. $html .= '<tr><th class="taR">小计</th>';
  3956. $invoicePriceStaffYear = 0;
  3957. $receivablesPriceStaffYear = 0;
  3958. $accountPriceStaffYear = 0;
  3959. for($month = 1; $month <= 12; $month ++) {
  3960. $flag = true;
  3961. foreach ( $staffList ['statisticsMonthCid'] as $smc => $smcv ) {
  3962. if ($value ['cid'] == $smcv ['cid'] && $month == $slv ['month']) {
  3963. $html .= '<td class="taR">¥' . $smcv ['invoicePrice'] . '</td>
  3964. <td class="taR">¥' . $smcv ['receivablesPrice'] . '</td>
  3965. <td class="taR"><b>¥' . $smcv ['accountPrice'] . '</b></td>
  3966. ';
  3967. $invoicePriceStaffYear += $slv ['invoicePrice'];
  3968. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  3969. $accountPriceStaffYear += $slv ['accountPrice'];
  3970. $flag = false;
  3971. break;
  3972. }
  3973. }
  3974. if ($flag)
  3975. $html .= '<td class="taR"></td>
  3976. <td class="taR"></td>
  3977. <td class="taR"><b></b></td>
  3978. ';
  3979. }
  3980. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  3981. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  3982. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  3983. ';
  3984. $html .= '</tr>';
  3985. }
  3986. }
  3987. $html .= '<tr class="warning"><th colspan="2"><b class="colGreen" >月合计</b></th>';
  3988. $invoicePriceYear = 0;
  3989. $receivablesPriceYear = 0;
  3990. $accountPriceYear = 0;
  3991. for($month = 1; $month <= 12; $month ++) {
  3992. $flag = true;
  3993. foreach ( $staffList ['statisticsMonth'] as $k => $v ) {
  3994. if ($month == $v ['month']) {
  3995. $html .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>
  3996. <td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>
  3997. <td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>
  3998. ';
  3999. $invoicePriceYear += $v ['invoicePrice'];
  4000. $receivablesPriceYear += $v ['receivablesPrice'];
  4001. $accountPriceYear += $v ['accountPrice'];
  4002. $flag = false;
  4003. break;
  4004. }
  4005. }
  4006. if ($flag)
  4007. $html .= '<td class="taR"></td>
  4008. <td class="taR"></td>
  4009. <td class="taR"><b></b></td>
  4010. ';
  4011. }
  4012. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  4013. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  4014. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  4015. ';
  4016. $html .= '</tr>';
  4017. $this->data ['html'] = $html;
  4018. $this->data ['isList'] = $toteList;
  4019. $this->data ['year'] = $year;
  4020. $this->data ['memu'] = "invoice";
  4021. $this->data ['staff'] = $this->staff;
  4022. $this->data ['receiptMemu'] = 'invoiceAggregate';
  4023. $this->render ( "/admin/invoiceAggregateStaff", $this->data );
  4024. }
  4025. function invoiceAggregateCategory() {
  4026. Doo::loadClass ( 'XDeode' );
  4027. $XDeode = new XDeode ( 5 );
  4028. $cid = $cidKey = isset ( $this->params ['cid'] ) ? $this->params ['cid'] : "";
  4029. $cid = $XDeode->decode ( $cid );
  4030. if (! is_numeric ( $cid ))
  4031. die ( 'illegal request' );
  4032. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  4033. Doo::loadModel ( 'invoiceStatistics' );
  4034. $invoiceStatistics = new invoiceStatistics ();
  4035. Doo::loadModel ( 'staff' );
  4036. $staff = new staff ();
  4037. $list = $staff->getStaffByCid ( $cid );
  4038. $isCategory = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year, $cid );
  4039. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year, $cid );
  4040. if (empty ( $list ))
  4041. die ( '该办事处没有成员' );
  4042. $htmlA = $htmlB = $htmlC = $html = '';
  4043. foreach ( $list as $key => $value ) {
  4044. $htmlA = '<tr><th rowspan="3">' . $value ['username'] . '</th><th class="taC">开票</th>';
  4045. $htmlB = '<tr><th class="taC">收款</th>';
  4046. $htmlC = '<tr><th class="taC">入账</th>';
  4047. $invoicePriceStaffYear = 0;
  4048. $receivablesPriceStaffYear = 0;
  4049. $accountPriceStaffYear = 0;
  4050. for($month = 1; $month <= 12; $month ++) {
  4051. $flag = true;
  4052. foreach ( $isCategory ['statisticsMonthStaff'] as $k => $v ) {
  4053. if ($value ['sid'] == $v ['staff'] && $month == $v ['month']) {
  4054. $htmlA .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>';
  4055. $htmlB .= '<td class="taR">¥' . $v ['receivablesPrice'] . '</td>';
  4056. $htmlC .= '<td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>';
  4057. $invoicePriceStaffYear += $v ['invoicePrice'];
  4058. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  4059. $accountPriceStaffYear += $v ['accountPrice'];
  4060. $flag = false;
  4061. break;
  4062. }
  4063. }
  4064. if ($flag) {
  4065. $htmlA .= '<td class="taR">-</td>';
  4066. $htmlB .= '<td class="taR">-</td>';
  4067. $htmlC .= '<td class="taR"><b>-</b></td>';
  4068. }
  4069. }
  4070. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  4071. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  4072. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  4073. $htmlA .= '</tr>';
  4074. $htmlB .= '</tr>';
  4075. $htmlC .= '</tr>';
  4076. $html .= $htmlA . $htmlB . $htmlC;
  4077. }
  4078. $htmlA = $htmlB = $htmlC = "";
  4079. $htmlA = '<tr><th rowspan="3">月合计</th><th class="taC">开票</th>';
  4080. $htmlB = '<tr><th class="taC">收款</th>';
  4081. $htmlC = '<tr><th class="taC">入账</th>';
  4082. $invoicePriceStaffYear = 0;
  4083. $receivablesPriceStaffYear = 0;
  4084. $accountPriceStaffYear = 0;
  4085. for($month = 1; $month <= 12; $month ++) {
  4086. $flag = true;
  4087. foreach ( $isCategory ['statisticsMonth'] as $k => $v ) {
  4088. if ($month == $v ['month']) {
  4089. $htmlA .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>';
  4090. $htmlB .= '<td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>';
  4091. $htmlC .= '<td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>';
  4092. $invoicePriceStaffYear += $v ['invoicePrice'];
  4093. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  4094. $accountPriceStaffYear += $v ['accountPrice'];
  4095. $flag = false;
  4096. break;
  4097. }
  4098. }
  4099. if ($flag) {
  4100. $htmlA .= '<td class="taR">-</td>';
  4101. $htmlB .= '<td class="taR">-</td>';
  4102. $htmlC .= '<td class="taR"><b>-</b></td>';
  4103. }
  4104. }
  4105. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  4106. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  4107. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  4108. $htmlA .= '</tr>';
  4109. $htmlB .= '</tr>';
  4110. $htmlC .= '</tr>';
  4111. $html .= $htmlA . $htmlB . $htmlC;
  4112. $this->data ['html'] = $html;
  4113. $this->data ['cidKey'] = $cidKey;
  4114. $this->data ['slist'] = $list;
  4115. $this->data ['isList'] = $toteList;
  4116. $this->data ['year'] = $year;
  4117. $this->data ['memu'] = "invoice";
  4118. $this->data ['staff'] = $this->staff;
  4119. $this->data ['receiptMemu'] = 'invoiceAggregate';
  4120. $this->render ( "/admin/invoiceAggregateCategory", $this->data );
  4121. }
  4122. /**
  4123. * 办事处汇总信息
  4124. */
  4125. function invoiceAggregateCategoryDetail() {
  4126. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  4127. Doo::loadClass ( 'XDeode' );
  4128. $XDeode = new XDeode ( 5 );
  4129. Doo::loadModel ( 'invoiceStatistics' );
  4130. $invoiceStatistics = new invoiceStatistics ();
  4131. Doo::loadModel ( 'L_category' );
  4132. $category = new L_category ();
  4133. Doo::loadModel ( 'invoice' );
  4134. $invoice = new invoice ();
  4135. Doo::loadModel ( 'staff' );
  4136. $staff = new staff ();
  4137. Doo::loadModel ( "invoiceCategoryManage" );
  4138. $invoiceCategoryManage = new invoiceCategoryManage ();
  4139. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4140. $cidList = array ();
  4141. foreach ( $imcStaff as $key => $value ) {
  4142. array_push ( $cidList, $value ['cid'] );
  4143. if (empty ( $cidKey ))
  4144. $cidKey = $XDeode->encode ( $value ['cid'] );
  4145. }
  4146. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  4147. $cid = $XDeode->decode ( $cidKey );
  4148. $month = date ( "m", strtotime ( "-1 month" ) );
  4149. $YearMonth = date ( "Y-m", strtotime ( "-1 month" ) );
  4150. $redis = new Redis ();
  4151. $redis->connect ( '127.0.0.1', '6379' );
  4152. $redisKey = ''; // date('Y-m-d').'_iacd_'.$cid;
  4153. $redisValue = ''; // $redis->lrange($redisKey, 0, -1);
  4154. if (empty ( $redisValue )) {
  4155. $isMC = $invoiceStatistics->getInvoiceStatistiscsMothByCategory ( $cid );
  4156. $schedule = $invoice->getInvoiceScheduleByCid ( $cid );
  4157. // 获得办事处人员下的汇总
  4158. $slist = $staff->getStaffByCid ( $cid );
  4159. $ismsbMonth = $invoiceStatistics->getISMSByCategoryByMonth ( $cid, $YearMonth ); // 上一个月的汇总
  4160. $ismsb = $invoiceStatistics->getISMSByCategory ( $cid ); // 当月汇总
  4161. $ISAS = $invoiceStatistics->getISASByCategory ( $cid ); // 全部汇总
  4162. $scheduleStaff = $invoice->getInvoiceScheduleByCidGroupSid ( $cid ); // 完成度
  4163. foreach ( $slist as $key => $value ) {
  4164. $slist [$key] ['invoicePrice'] = 0;
  4165. $slist [$key] ['receivablesPrice'] = 0;
  4166. $slist [$key] ['accountPrice'] = 0;
  4167. $slist [$key] ['invoiceAllPrice'] = 0;
  4168. $slist [$key] ['receivablesAllPrice'] = 0;
  4169. $slist [$key] ['accountAllPrice'] = 0;
  4170. $slist [$key] ['schedule'] = 0;
  4171. $slist [$key] ['invoiceMonthPrice'] = 0;
  4172. $slist [$key] ['receivablesMonthPrice'] = 0;
  4173. $slist [$key] ['accountMonthPrice'] = 0;
  4174. foreach ( $ismsbMonth as $y => $l ) {
  4175. if ($value ['sid'] == $l ['staff']) {
  4176. $slist [$key] ['invoiceMonthPrice'] = $l ['invoicePrice'];
  4177. $slist [$key] ['receivablesMonthPrice'] = $l ['receivablesPrice'];
  4178. $slist [$key] ['accountMonthPrice'] = $l ['accountPrice'];
  4179. }
  4180. }
  4181. foreach ( $ismsb as $k => $v ) {
  4182. if ($value ['sid'] == $v ['staff']) {
  4183. $slist [$key] ['invoicePrice'] = $v ['invoicePrice'];
  4184. $slist [$key] ['receivablesPrice'] = $v ['receivablesPrice'];
  4185. $slist [$key] ['accountPrice'] = $v ['accountPrice'];
  4186. }
  4187. }
  4188. foreach ( $ISAS as $e => $a ) {
  4189. if ($value ['sid'] == $a ['staff']) {
  4190. $slist [$key] ['invoiceAllPrice'] = $a ['invoicePrice'];
  4191. $slist [$key] ['receivablesAllPrice'] = $a ['receivablesPrice'];
  4192. $slist [$key] ['accountAllPrice'] = $a ['accountPrice'];
  4193. }
  4194. }
  4195. if (isset ( $scheduleStaff [$value ['sid']] ))
  4196. $slist [$key] ['schedule'] = $scheduleStaff [$value ['sid']];
  4197. }
  4198. $this->data ['cidKey'] = $cidKey;
  4199. $schedule = ( int ) ($schedule * 100);
  4200. $this->data ['slist'] = $slist;
  4201. $this->data ['isMC'] = $isMC;
  4202. $this->data ['schedule'] = $schedule;
  4203. $slist = json_encode ( $slist );
  4204. $isMC = json_encode ( $isMC );
  4205. $schedule = json_encode ( $schedule );
  4206. $redis->lpush ( $redisKey, $slist );
  4207. $redis->lpush ( $redisKey, $isMC );
  4208. $redis->lpush ( $redisKey, $schedule );
  4209. } else {
  4210. $this->data ['cidKey'] = $cidKey;
  4211. $this->data ['slist'] = json_decode ( $redisValue [2], true );
  4212. $this->data ['isMC'] = json_decode ( $redisValue [1], true );
  4213. $this->data ['schedule'] = json_decode ( $redisValue [0], true );
  4214. }
  4215. $this->data ['month'] = $month;
  4216. $this->data ['categoryList'] = $categoryList;
  4217. $this->data ['memu'] = "invoice";
  4218. $this->data ['staff'] = $this->staff;
  4219. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4220. $this->render ( "/admin/invoiceAggregateCategoryDetail", $this->data );
  4221. }
  4222. /**
  4223. * 办事处人员汇总详情
  4224. */
  4225. function invoiceAggregateStaffDetail() {
  4226. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  4227. // $sidKey = isset ( $this->params ['sidKey'] ) ? $this->params ['sidKey'] : '';
  4228. Doo::loadClass ( 'XDeode' );
  4229. $XDeode = new XDeode ( 5 );
  4230. Doo::loadModel ( 'invoice' );
  4231. $invoice = new invoice ();
  4232. Doo::loadModel ( 'staff' );
  4233. $staff = new staff ();
  4234. Doo::loadModel ( "invoiceCategoryManage" );
  4235. $invoiceCategoryManage = new invoiceCategoryManage ();
  4236. $sid = $XDeode->decode ( $sidKey );
  4237. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4238. $cidList = array ();
  4239. foreach ( $imcStaff as $key => $value ) {
  4240. array_push ( $cidList, $value ['cid'] );
  4241. if (empty ( $cidKey ))
  4242. $cidKey = $XDeode->encode ( $value ['cid'] );
  4243. }
  4244. $cidString = implode ( ',', $cidList );
  4245. $staffList = $staff->getStaffInCid ( $cidString );
  4246. $staffDetail = $staff->getStaffBySid ( $sid );
  4247. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4248. $page_size = 18;
  4249. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4250. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4251. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  4252. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  4253. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  4254. $dateArr = explode ( ':', $date );
  4255. $D1 = '';
  4256. $D2 = '';
  4257. if (! empty ( $date )) {
  4258. $D1 = $dateArr [0] . " 00:00:00 ";
  4259. if (isset ( $dateArr [1] ))
  4260. $D2 = $dateArr [1] . " 23:59:59 ";
  4261. else
  4262. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4263. // $D2 = $dateArr [1];
  4264. }
  4265. $con = ' status=2 ';
  4266. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4267. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4268. if ($status == 'UNRECORD')
  4269. $con .= ' and printStatus=1 and untreadStatus=0';
  4270. elseif ($status == 'RECORD')
  4271. $con .= ' and printStatus=1 and untreadStatus=3';
  4272. elseif ($status == 'BOUNCED')
  4273. $con .= ' and untreadStatus=2';
  4274. elseif ($status == 'PARTRECORD')
  4275. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  4276. elseif ($status == 'All') {
  4277. $con .= ' and ( untreadStatus=2 or untreadStatus=0 or untreadStatus=3 )';
  4278. }
  4279. $con .= ' and sid=' . $sid;
  4280. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  4281. if (! empty ( $MebSea )) {
  4282. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  4283. }
  4284. $pageinfo ['page'] = array (
  4285. 'previous' => ''
  4286. );
  4287. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateStaffDetail", $get, "" );
  4288. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4289. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  4290. $this->data ['staffDetail'] = $staffDetail;
  4291. $this->data ['staffList'] = $staffList;
  4292. $this->data ['MebSeaEn'] = $MebSea;
  4293. $this->data ['MebSea'] = urlencode ( $MebSea );
  4294. $this->data ['date'] = $date;
  4295. $this->data ['page'] = $pageinfo;
  4296. $this->data ['get'] = $get;
  4297. $this->data ['list'] = $list;
  4298. $this->data ['status'] = $status;
  4299. $this->data ['sidKey'] = $sidKey;
  4300. $this->data ['memu'] = "invoice";
  4301. $this->data ['staff'] = $this->staff;
  4302. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4303. $this->render ( "/admin/invoiceAggregateStaffDetail", $this->data );
  4304. }
  4305. /**
  4306. * 办事处人员汇总收款情
  4307. */
  4308. function invoiceAggregateStaffReceivablesDetail() {
  4309. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  4310. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  4311. Doo::loadModel ( 'invoiceReceivables' );
  4312. $invoiceReceivables = new invoiceReceivables ();
  4313. Doo::loadModel ( 'staff' );
  4314. $staff = new staff ();
  4315. Doo::loadModel ( "invoiceCategoryManage" );
  4316. $invoiceCategoryManage = new invoiceCategoryManage ();
  4317. Doo::loadClass ( 'XDeode' );
  4318. $XDeode = new XDeode ( 5 );
  4319. $sid = $XDeode->decode ( $sidKey );
  4320. $staffDetail = $staff->getStaffBySid ( $sid );
  4321. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4322. $cidList = array ();
  4323. foreach ( $imcStaff as $key => $value ) {
  4324. array_push ( $cidList, $value ['cid'] );
  4325. if (empty ( $cidKey ))
  4326. $cidKey = $XDeode->encode ( $value ['cid'] );
  4327. }
  4328. $cidString = implode ( ',', $cidList );
  4329. $staffList = $staff->getStaffInCid ( $cidString );
  4330. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4331. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  4332. $page_size = 10;
  4333. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4334. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4335. if ($timeType == "BINDOTP") {
  4336. $status = 'Credited';
  4337. }
  4338. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  4339. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  4340. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  4341. $dateArr = explode ( ':', $date );
  4342. $D1 = '';
  4343. $D2 = '';
  4344. if (! empty ( $date )) {
  4345. $D1 = $dateArr [0] . " 00:00:00 ";
  4346. if (isset ( $dateArr [1] ))
  4347. $D2 = $dateArr [1] . " 23:59:59 ";
  4348. else
  4349. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4350. }
  4351. $con = ' a.receivablesStaff like "%' . $staffDetail ['username'] . '%" ';
  4352. $descField = 'a.bindDate';
  4353. if ($timeType == 'CREATE')
  4354. $descField = 'a.date';
  4355. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4356. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4357. elseif (! empty ( $D1 ) && empty ( $D2 ))
  4358. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  4359. if ($status == 'Unclaimed')
  4360. $con .= ' and a.bindStatus=0';
  4361. elseif ($status == 'Credited')
  4362. $con .= ' and a.bindStatus=1';
  4363. elseif ($status == 'Claim')
  4364. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  4365. elseif ($status == 'BBN')
  4366. $con .= ' and a.bindPrice>a.receivablesPrice';
  4367. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  4368. if (! empty ( $MebSea )) {
  4369. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" )';
  4370. }
  4371. $pageinfo ['page'] = array (
  4372. 'previous' => ''
  4373. );
  4374. $sql = 'select group_concat(b.invoiceSerial) as invoiceSerial ,group_concat(b.iid) as invoiceId
  4375. from CLD_invoiceReceivables as a left join CLD_invoice as b on
  4376. find_in_set(b.iid,a.iidExtend) or a.iid=b.iid
  4377. where ' . $con . ' group by a.irid ';
  4378. $pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceAggregateStaffReceivablesDetail", $get, "" );
  4379. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4380. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', 'printTime' );
  4381. foreach ( $list as $key => $value ) {
  4382. $list [$key] ['category'] = '';
  4383. if ($value ['receivablesCategory'] != 'PUBLIC') {
  4384. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  4385. $list [$key] ['category'] = $receivablesCategory [1];
  4386. }
  4387. }
  4388. // print_r($list);
  4389. $this->data ['staffDetail'] = $staffDetail;
  4390. $this->data ['sidKey'] = $sidKey;
  4391. $this->data ['staffList'] = $staffList;
  4392. $this->data ['timeType'] = $timeType;
  4393. $this->data ['MebSeaEn'] = $MebSea;
  4394. $this->data ['MebSea'] = urlencode ( $MebSea );
  4395. $this->data ['date'] = $date;
  4396. $this->data ['page'] = $pageinfo;
  4397. $this->data ['get'] = $get;
  4398. $this->data ['list'] = $list;
  4399. $this->data ['status'] = $status;
  4400. $this->data ['memu'] = "invoice";
  4401. $this->data ['staff'] = $this->staff;
  4402. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4403. $this->render ( "/admin/invoiceAggregateStaffReceivablesDetail", $this->data );
  4404. }
  4405. function invoiceAchieve() {
  4406. Doo::loadModel ( 'invoice' );
  4407. $invoice = new invoice ();
  4408. Doo::loadClass ( 'XDeode' );
  4409. $XDeode = new XDeode ( 5 );
  4410. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4411. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4412. $page_size = 18;
  4413. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4414. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4415. $get = "/" . $date;
  4416. $con = '';
  4417. if ($date == 'MONTHO')
  4418. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4419. elseif ($date == 'MONTHT')
  4420. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4421. elseif ($date == 'MONTHY')
  4422. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4423. if (! empty ( $MebSea )) {
  4424. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4425. $get .= "/" . $MebSea;
  4426. }
  4427. $pageinfo ['page'] = array (
  4428. 'previous' => ''
  4429. );
  4430. $sql = 'status=2 and printStatus=1 and irid!="" and ( untreadStatus=3 or untreadStatus=0 ) and sid=' . $sid . $con;
  4431. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceAchieve", $get, "" );
  4432. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4433. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  4434. // print_r($pageinfo);
  4435. $this->data ['MebSeaEn'] = $MebSea;
  4436. $this->data ['MebSea'] = urlencode ( $MebSea );
  4437. $this->data ['get'] = $get;
  4438. $this->data ['page'] = $pageinfo;
  4439. $this->data ['list'] = $list;
  4440. $this->data ['date'] = $date;
  4441. $this->data ['memu'] = "invoice";
  4442. $this->data ['staff'] = $this->staff;
  4443. $this->data ['receiptMemu'] = 'invoice';
  4444. $this->render ( "/admin/invoiceAchieve", $this->data );
  4445. }
  4446. /**
  4447. */
  4448. function invoiceMyUnAccountAchieve() {
  4449. Doo::loadModel ( 'invoice' );
  4450. $invoice = new invoice ();
  4451. Doo::loadClass ( 'XDeode' );
  4452. $XDeode = new XDeode ( 5 );
  4453. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4454. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4455. $page_size = 18;
  4456. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4457. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4458. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4459. $dateArr = explode ( ':', $date );
  4460. $D1 = '';
  4461. $D2 = '';
  4462. if (! empty ( $date )) {
  4463. $D1 = $dateArr [0];
  4464. $D2 = $dateArr [1];
  4465. }
  4466. $con = '';
  4467. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4468. $con = ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4469. if (! empty ( $MebSea )) {
  4470. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4471. }
  4472. $pageinfo ['page'] = array (
  4473. 'previous' => ''
  4474. );
  4475. // and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  4476. $sql = " status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid= " . $sid . $con;
  4477. $action = "invoiceMyUnAccountAchieve";
  4478. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  4479. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4480. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 'desc', 'printTime' );
  4481. Doo::loadModel ( 'express' );
  4482. $express = new express ();
  4483. $expressList = $express->getExpressByAll ();
  4484. $this->data ['expressList'] = $expressList;
  4485. // print_r($list);
  4486. $this->data ['MebSeaEn'] = $MebSea;
  4487. $this->data ['get'] = $get;
  4488. $this->data ['page'] = $pageinfo;
  4489. $this->data ['date'] = $date;
  4490. $this->data ['list'] = $list;
  4491. $this->data ['memu'] = "invoice";
  4492. $this->data ['staff'] = $this->staff;
  4493. $this->data ['receiptMemu'] = 'invoice';
  4494. $this->render ( "/admin/invoiceMyUnAccountAchieve", $this->data );
  4495. }
  4496. function invoiceReceivablesAchieve() {
  4497. Doo::loadModel ( 'invoiceReceivables' );
  4498. $invoiceReceivables = new invoiceReceivables ();
  4499. Doo::loadClass ( 'XDeode' );
  4500. $XDeode = new XDeode ( 5 );
  4501. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4502. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  4503. $page_size = 12;
  4504. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4505. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4506. $get = "/" . $date;
  4507. $con = '';
  4508. if ($date == 'MONTHO')
  4509. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4510. elseif ($date == 'MONTHT')
  4511. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4512. elseif ($date == 'MONTHY')
  4513. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4514. if (! empty ( $MebSea )) {
  4515. $con .= ' and ( receivablesMessage like "%' . $MebSea . '%" or receivablesPrice like "%' . $MebSea . '%" )';
  4516. $get .= "/" . $MebSea;
  4517. }
  4518. $pageinfo ['page'] = array (
  4519. 'previous' => ''
  4520. );
  4521. $sql = " bindStatus=1 and receivablesStaff like '" . $sid . "-%' " . $con;
  4522. $pageinfo = $this->get_page ( "CLD_invoiceReceivables", $sql, $page, $page_size, "invoiceReceivablesAchieve", $get, "" );
  4523. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4524. $list = $invoiceReceivables->getReceivablesByUntreadStatusPage ( $limit, $sql );
  4525. // print_r($pageinfo);
  4526. $this->data ['MebSeaEn'] = $MebSea;
  4527. $this->data ['MebSea'] = urlencode ( $MebSea );
  4528. $this->data ['get'] = $get;
  4529. $this->data ['page'] = $pageinfo;
  4530. $this->data ['list'] = $list;
  4531. $this->data ['date'] = $date;
  4532. $this->data ['memu'] = "invoice";
  4533. $this->data ['staff'] = $this->staff;
  4534. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  4535. $this->render ( "/admin/invoiceReceivablesAchieve", $this->data );
  4536. }
  4537. /**
  4538. * 收款解绑
  4539. */
  4540. function invoiceUnBundLing() {
  4541. $unBundKey = $this->get_args ( 'unBundKey' ) ? $this->get_args ( 'unBundKey' ) : '';
  4542. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  4543. Doo::loadModel ( 'invoice' );
  4544. $invoice = new invoice ();
  4545. Doo::loadModel ( 'invoiceReceivables' );
  4546. $invoiceReceivables = new invoiceReceivables ();
  4547. Doo::loadModel ( 'invoiceOperationLog' );
  4548. $invoiceOperationLog = new invoiceOperationLog ();
  4549. Doo::loadModel ( 'invoiceROLog' );
  4550. $invoiceROLog = new invoiceROLog ();
  4551. Doo::loadModel ( 'invoiceStatistics' );
  4552. Doo::loadClass ( 'XDeode' );
  4553. $XDeode = new XDeode ( 5 );
  4554. if (empty ( $iidKey ) || empty ( $unBundKey ))
  4555. die ( 'illegal request' );
  4556. $iid = $XDeode->decode ( $iidKey );
  4557. $irid = $invoice->authcode ( $unBundKey );
  4558. if ((! empty ( $irid ) && ! is_numeric ( $irid )) || (! empty ( $iid ) && ! is_numeric ( $iid )))
  4559. die ( 'illegal request' );
  4560. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4561. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  4562. if (empty ( $irDetails ) || empty ( $invoiceDetails ) || (empty ( $irDetails ['iid'] ) && empty ( $irDetails ['iidExtend'] )) || $invoiceDetails ['untreadStatus'] == 2)
  4563. die ( 'illegal request' );
  4564. // 收款
  4565. $item = array (
  4566. 'irid' => $irDetails ['irid'],
  4567. 'bindPrice' => $irDetails ['bindPrice'] - $invoiceDetails ['invoicePrice'],
  4568. 'bindStatus' => 0
  4569. );
  4570. if ($irDetails ['iid'] == $iid)
  4571. $item += array (
  4572. 'iid' => 0
  4573. );
  4574. else {
  4575. $iidExtend = explode ( ',', $irDetails ['iidExtend'] );
  4576. foreach ( $iidExtend as $key => $value ) {
  4577. if ($value == $iid)
  4578. unset ( $iidExtend [$key] );
  4579. }
  4580. $iidExtend = implode ( ',', $iidExtend );
  4581. $item += array (
  4582. 'iidExtend' => $iidExtend
  4583. );
  4584. }
  4585. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4586. // 收款操作日志
  4587. $item = array (
  4588. 'operation' => $this->staff [0] ['username'] . " 解绑 " . $irDetails ['receivablesSerial'],
  4589. 'date' => date ( "Y-m-d" ),
  4590. 'status' => 3,
  4591. 'img' => $this->staff [0] ['avatar'],
  4592. 'username' => $this->staff [0] ['username'],
  4593. 'uid' => $this->staff [0] ['sid'],
  4594. 'category' => $this->staff [0] ['category'],
  4595. 'irid' => $irid
  4596. );
  4597. $invoiceROLog->setInvoiceROLog ( $item );
  4598. // 扣除入账统计金额
  4599. $invoiceStatistics = new invoiceStatistics ();
  4600. $item = array (
  4601. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  4602. 'priceClass' => 3,
  4603. 'cid' => $invoiceDetails ['cid'],
  4604. 'staff' => $invoiceDetails ['sid'],
  4605. 'accountPrice' => - $irDetails ['receivablesPrice']
  4606. );
  4607. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4608. // 扣除收款统计金额
  4609. $invoiceStatistics = new invoiceStatistics ();
  4610. $item = array (
  4611. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  4612. 'priceClass' => 2,
  4613. 'cid' => $invoiceDetails ['cid'],
  4614. 'staff' => $invoiceDetails ['sid'],
  4615. 'irid' => $irDetails ['irid'],
  4616. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  4617. );
  4618. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4619. // 发票解绑去收款ID
  4620. $iridString = $invoiceDetails ['irid'];
  4621. if (! empty ( $invoiceDetails ['irid'] )) {
  4622. $list = explode ( ',', $invoiceDetails ['irid'] );
  4623. foreach ( $list as $key => $value ) {
  4624. if ($value == $irDetails ['irid']) {
  4625. unset ( $list [$key] );
  4626. break;
  4627. }
  4628. }
  4629. $iridString = implode ( ",", $list );
  4630. }
  4631. $item = array (
  4632. 'iid' => $invoiceDetails ['iid'],
  4633. 'irid' => $iridString,
  4634. 'updateTime' => date ( "Y-m-d H:i:s" )
  4635. );
  4636. if ($invoiceDetails ['untreadStatus'] == 3)
  4637. $item += array (
  4638. 'untreadStatus' => 0
  4639. );
  4640. $invoice->setInvoiceByCondition ( $item );
  4641. $item = array (
  4642. 'date' => date ( "Y-m-d H:i:s" ),
  4643. 'operation' => '解绑 收款 ' . $irDetails ['receivablesSerial'],
  4644. 'status' => 11,
  4645. 'img' => $this->staff [0] ['avatar'],
  4646. 'username' => $this->staff [0] ['username'],
  4647. 'uid' => $this->staff [0] ['sid'],
  4648. 'category' => $this->staff [0] ['category'],
  4649. 'iid' => $invoiceDetails ['iid']
  4650. );
  4651. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  4652. // 公司流水-解绑时删除流水
  4653. Doo::loadModel ( 'wasteBook' );
  4654. $wasteBook = new wasteBook ();
  4655. // $wasteBook->delete ( array (
  4656. // 'where' => 'dataID=' . $irDetails ['irid'] . ' and accountType=7',
  4657. // 'limit' => 1
  4658. // ) );
  4659. // 银行
  4660. /*
  4661. * $abDetail = $wasteBook->getAccountBookByAid (2,7,$irDetails ['irid'] ); $accountBank=''; if ($irDetails ['receivablesBank']=='纵横广发'){ $accountBank='CGBDeposit'; }elseif($irDetails ['receivablesBank']=='纵横工行'){ $accountBank='ICBCDeposit'; }elseif($irDetails ['receivablesBank']=='华润银行'){ $accountBank='HUADeposit'; }elseif($irDetails ['receivablesBank']=='个人广发'){ $accountBank='PersonalDeposit'; } if (empty($abDetail)){ $item = array ( 'dataID' => $irDetails ['irid'], 'expensesType' => 2, 'accountType' => 7, 'accountPriceShow'=>$irDetails ['receivablesPrice'], 'accountPrice' => -$irDetails ['receivablesPrice'], 'accountBank'=>$accountBank, 'cid'=>$this->staff[0]['cid'], 'name'=>$this->staff[0]['username'], 'sid'=>$this->staff[0]['sid'], 'inputDate'=>date ( "Y-m-d H:i:s" ) ); $wasteBook->setAccountBookStatistics($item); }
  4662. */
  4663. return "/invoiceReceivablesAS";
  4664. }
  4665. /**
  4666. * 或者该收款下的所以发票
  4667. */
  4668. function ajaxGetInvoiceReceivablesByInvoice() {
  4669. $irid = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : '';
  4670. Doo::loadModel ( 'invoice' );
  4671. $invoice = new invoice ();
  4672. Doo::loadModel ( 'invoiceReceivables' );
  4673. $invoiceReceivables = new invoiceReceivables ();
  4674. $irid = $invoice->authcode ( $irid );
  4675. if (! empty ( $irid ) && ! is_numeric ( $irid ))
  4676. die ( 'illegal request' );
  4677. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4678. $iidString = $irDetails ['iid'];
  4679. $iidExtend = array_filter ( explode ( ',', $irDetails ['iidExtend'] ) );
  4680. if (! empty ( $irDetails ['iidExtend'] ))
  4681. $iidString .= ',' . implode ( ',', $iidExtend );
  4682. $invoiceList = $invoice->getInvoiceInIid ( $iidString, 'iid,invoiceSerial,invoicePrice,invoiceTitle,invoiceCompany,invoiceElement' );
  4683. $html = "";
  4684. foreach ( $invoiceList as $key => $value ) {
  4685. $title = $value ['invoiceTitle'];
  4686. if (! empty ( $value ['invoiceCompany'] ))
  4687. $title = $value ['invoiceCompany'];
  4688. $html .= '<tr><td>' . $value ['invoiceSerial'] . '</td><td>¥' . $value ['invoicePrice'] . '</td><td>' . $title . '</td><td>' . $value ['invoiceElement'] . '</td><td><input type="radio" name="iidKey" value="' . $value ['iidKey'] . '"></td></tr>';
  4689. }
  4690. echo json_encode ( array (
  4691. 'status' => 1,
  4692. 'html' => $html
  4693. ) );
  4694. }
  4695. /**
  4696. * 发票管理
  4697. */
  4698. function invoiceAS() {
  4699. Doo::loadModel ( 'invoice' );
  4700. $invoice = new invoice ();
  4701. Doo::loadModel ( 'invoiceReceivables' );
  4702. $invoiceReceivables = new invoiceReceivables ();
  4703. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4704. $page_size = 18;
  4705. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4706. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4707. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4708. $dateArr = explode ( ':', $date );
  4709. $D1 = '';
  4710. $D2 = '';
  4711. if (! empty ( $date )) {
  4712. $D1 = $dateArr [0] . " 00:00:00 ";
  4713. if (isset ( $dateArr [1] ))
  4714. $D2 = $dateArr [1] . " 23:59:59 ";
  4715. else
  4716. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4717. // $D2 = $dateArr [1];
  4718. }
  4719. $con = ' status=2 ';
  4720. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4721. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4722. if ($status == 'UNRECORD')
  4723. $con .= ' and printStatus=1 and untreadStatus=0';
  4724. elseif ($status == 'RECORD')
  4725. $con .= ' and printStatus=1 and untreadStatus=3';
  4726. elseif ($status == 'BOUNCED')
  4727. $con .= ' and untreadStatus=2';
  4728. elseif ($status == 'PARTRECORD')
  4729. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  4730. elseif ($status == 'All') {
  4731. $con .= ' and ( untreadStatus=2 or untreadStatus=1 or untreadStatus=0 or untreadStatus=3 )';
  4732. }
  4733. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4734. if (! empty ( $MebSea )) {
  4735. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  4736. }
  4737. $pageinfo ['page'] = array (
  4738. 'previous' => ''
  4739. );
  4740. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAS", $get, "" );
  4741. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4742. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  4743. $this->data ['MebSeaEn'] = $MebSea;
  4744. $this->data ['MebSea'] = urlencode ( $MebSea );
  4745. $this->data ['date'] = $date;
  4746. $this->data ['page'] = $pageinfo;
  4747. $this->data ['get'] = $get;
  4748. $this->data ['list'] = $list;
  4749. $this->data ['status'] = $status;
  4750. $this->data ['memu'] = "invoice";
  4751. $this->data ['staff'] = $this->staff;
  4752. $this->data ['receiptMemu'] = 'invoiceReceivables';
  4753. $this->render ( "/admin/invoiceAS", $this->data );
  4754. }
  4755. /**
  4756. * 收款管理
  4757. */
  4758. function invoiceReceivablesAS() {
  4759. Doo::loadModel ( 'invoiceReceivables' );
  4760. $invoiceReceivables = new invoiceReceivables ();
  4761. Doo::loadModel ( 'L_category' );
  4762. $lCategory = new L_category ();
  4763. $category = $lCategory->getCategory ();
  4764. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4765. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  4766. $page_size = 10;
  4767. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4768. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4769. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4770. $dateArr = explode ( ':', $date );
  4771. $D1 = '';
  4772. $D2 = '';
  4773. if (! empty ( $date )) {
  4774. $D1 = $dateArr [0]; // ." 00:00:00 ";
  4775. if (isset ( $dateArr [1] ))
  4776. $D2 = $dateArr [1]; // ." 23:59:59 ";
  4777. else
  4778. $D2 = $dateArr [0]; // ." 23:59:59 ";//date ( "Y-m-d" );
  4779. }
  4780. $descField = 'a.receivablesDate';
  4781. if ($timeType == 'CREATE')
  4782. $descField = 'a.date';
  4783. $con = '';
  4784. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4785. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4786. elseif (! empty ( $D1 ) && empty ( $D2 ))
  4787. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  4788. if ($status == 'Unclaimed')
  4789. $con .= ' and a.bindStatus=0';
  4790. elseif ($status == 'Credited')
  4791. $con .= ' and a.bindStatus=1';
  4792. elseif ($status == 'Claim')
  4793. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  4794. elseif ($status == 'BBN')
  4795. $con .= ' and a.bankBatchNumber!=""';
  4796. elseif ($status == 'REFUND')
  4797. $con .= ' and ( (a.bindStatus=0 and a.refundLog!="" ) or a.bindStatus=2)';
  4798. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4799. if (! empty ( $MebSea )) {
  4800. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" or a.receivablesSerial like "%' . $MebSea . '%" )';
  4801. }
  4802. $pageinfo ['page'] = array (
  4803. 'previous' => ''
  4804. );
  4805. if(!empty($con)){
  4806. $con=' where 1 '.$con;
  4807. }
  4808. $sql = 'select a.iid from CLD_invoiceReceivables as a
  4809. ' . $con ;
  4810. //echo $sql;
  4811. $pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceReceivablesAS", $get, "" );
  4812. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4813. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', $descField );
  4814. foreach ( $list as $key => $value ) {
  4815. $list [$key] ['category'] = '';
  4816. if ($value ['receivablesCategory'] != 'PUBLIC') {
  4817. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  4818. $list [$key] ['category'] = $receivablesCategory [1];
  4819. }
  4820. }
  4821. // print_r($list);
  4822. $this->data ['category'] = $category;
  4823. $this->data ['timeType'] = $timeType;
  4824. $this->data ['MebSeaEn'] = $MebSea;
  4825. $this->data ['MebSea'] = urlencode ( $MebSea );
  4826. $this->data ['date'] = $date;
  4827. $this->data ['page'] = $pageinfo;
  4828. $this->data ['get'] = $get;
  4829. $this->data ['list'] = $list;
  4830. $this->data ['status'] = $status;
  4831. $this->data ['memu'] = "invoice";
  4832. $this->data ['staff'] = $this->staff;
  4833. $this->data ['receiptMemu'] = 'invoiceReceivables';
  4834. $this->render ( "/admin/invoiceReceivablesAS", $this->data );
  4835. }
  4836. /**
  4837. * 删除一条收款
  4838. */
  4839. function delInvoiceReceivables() {
  4840. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  4841. if (empty ( $iridKey ))
  4842. die ( 'illegal request' );
  4843. Doo::loadClass ( 'XDeode' );
  4844. $XDeode = new XDeode ( 5 );
  4845. $irid = $XDeode->decode ( $iridKey );
  4846. Doo::loadModel ( 'invoiceReceivables' );
  4847. $invoiceReceivables = new invoiceReceivables ();
  4848. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4849. if (empty ( $detail ))
  4850. die ( 'illegal request' );
  4851. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  4852. // 扣除收款汇总信息 汇总
  4853. Doo::loadModel ( 'invoiceStatistics' );
  4854. $invoiceStatistics = new invoiceStatistics ();
  4855. $item = array (
  4856. 'date' => $detail ['receivablesDate'],
  4857. 'priceClass' => 2,
  4858. 'irid' => $detail ['irid'],
  4859. 'receivablesPrice' => - $detail ['receivablesPrice']
  4860. );
  4861. if ($detail ['receivablesCategory'] != 'PUBLIC') {
  4862. $receivablesCategory = explode ( ":", $detail ['receivablesCategory'] );
  4863. $item += array (
  4864. 'cid' => $receivablesCategory [0]
  4865. );
  4866. }
  4867. if ($detail ['receivablesStaff'] != 'PUBLIC') {
  4868. $receivablesStaff = explode ( "-", $detail ['receivablesStaff'] );
  4869. $item += array (
  4870. 'staff' => $receivablesStaff [0]
  4871. );
  4872. }
  4873. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4874. return '/invoiceReceivablesAS';
  4875. }
  4876. /**
  4877. * 添加退款信息
  4878. */
  4879. function setInvoiceReceivablesRefund() {
  4880. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  4881. $refundType = $this->get_args ( 'refundType' ) && is_numeric ( $this->get_args ( 'refundType' ) ) ? $this->get_args ( 'refundType' ) : '0';
  4882. $refundCompany = $this->get_args ( 'refundCompany' ) ? $this->get_args ( 'refundCompany' ) : "";
  4883. $refundNumber = $this->get_args ( 'refundNumber' ) ? $this->get_args ( 'refundNumber' ) : "";
  4884. $refundPrice = $this->get_args ( 'refundPrice' ) ? $this->get_args ( 'refundPrice' ) : "";
  4885. $refundRemarks = $this->get_args ( 'refundRemarks' ) ? $this->get_args ( 'refundRemarks' ) : "";
  4886. if ($refundPrice < 0)
  4887. die ( 'illegal request' );
  4888. if (! empty ( $iridKey ) && ! empty ( $refundCompany ) && ! empty ( $refundNumber ) && ! empty ( $refundPrice )) {
  4889. Doo::loadModel ( 'invoiceReceivables' );
  4890. $invoiceReceivables = new invoiceReceivables ();
  4891. Doo::loadModel ( 'invoiceRefund' );
  4892. $invoiceRefund = new invoiceRefund ();
  4893. $irid = $invoiceReceivables->authcode ( $iridKey );
  4894. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4895. if ($irDetail ['receivablesPrice'] < $refundPrice)
  4896. die ( 'illegal request' );
  4897. $invoiceReceivables = new invoiceReceivables ();
  4898. $refundLog = $this->staff [0] ['username'] . ' 退款 <b class="colRed">¥' . $refundPrice . '</b>
  4899. <br/><a href="#refunded" onclick="getRefundByDetail(\'' . $iridKey . '\')" data-toggle="modal">退款信息</a> <br/>' . date ( "Y-m-d H:i:s" ) . '
  4900. ';
  4901. $item = array (
  4902. 'irid' => $irid,
  4903. 'refundCompany' => $refundCompany,
  4904. 'refundNumber' => $refundNumber,
  4905. 'refundPrice' => $refundPrice,
  4906. 'refundRemarks' => $refundRemarks,
  4907. 'refundLog' => $refundLog
  4908. );
  4909. if ($refundType == 1) {
  4910. $item += array (
  4911. 'refundType' => $refundType,
  4912. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice,
  4913. 'bindStatus' => 2
  4914. );
  4915. } elseif ($refundType == 0 && $irDetail ['receivablesPrice'] <= $refundPrice) {
  4916. $item += array (
  4917. 'refundType' => 1,
  4918. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice,
  4919. 'bindStatus' => 2
  4920. );
  4921. } else {
  4922. $item += array (
  4923. 'refundType' => $refundType,
  4924. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice
  4925. );
  4926. }
  4927. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4928. // 添加退款记录
  4929. $item = array (
  4930. 'irid' => $irid,
  4931. 'refundType' => $refundType,
  4932. 'refundCompany' => $refundCompany,
  4933. 'refundNumber' => $refundNumber,
  4934. 'refundPrice' => $refundPrice,
  4935. 'refundLog' => $refundLog,
  4936. 'refundRemarks' => $refundRemarks,
  4937. 'date' => date ( "Y-m-d H:i:s" )
  4938. );
  4939. $invoiceRefund->addInvoiceRefund ( $item );
  4940. // 扣除收款汇总信息 汇总
  4941. Doo::loadModel ( 'invoiceStatistics' );
  4942. $invoiceStatistics = new invoiceStatistics ();
  4943. $item = array (
  4944. 'date' => $irDetail ['receivablesDate'],
  4945. 'priceClass' => 2,
  4946. 'irid' => $irDetail ['irid'],
  4947. 'receivablesPrice' => - $refundPrice
  4948. );
  4949. if ($irDetail ['receivablesCategory'] != 'PUBLIC') {
  4950. $receivablesCategory = explode ( ":", $irDetail ['receivablesCategory'] );
  4951. $item += array (
  4952. 'cid' => $receivablesCategory [0]
  4953. );
  4954. }
  4955. if ($irDetail ['receivablesStaff'] != 'PUBLIC') {
  4956. $receivablesStaff = explode ( "-", $irDetail ['receivablesStaff'] );
  4957. $item += array (
  4958. 'staff' => $receivablesStaff [0]
  4959. );
  4960. }
  4961. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4962. // 公司日常支出流水
  4963. Doo::loadModel ( 'wasteBook' );
  4964. $wasteBook = new wasteBook ();
  4965. $accountBank = '';
  4966. if ($irDetail ['receivablesBank'] == '纵横广发') {
  4967. $accountBank = 'CGBDeposit';
  4968. } elseif ($irDetail ['receivablesBank'] == '纵横工行') {
  4969. $accountBank = 'ICBCDeposit';
  4970. } elseif ($irDetail ['receivablesBank'] == '华润银行') {
  4971. $accountBank = 'HUADeposit';
  4972. } elseif ($irDetail ['receivablesBank'] == '个人广发') {
  4973. $accountBank = 'PersonalDeposit';
  4974. }
  4975. $itemWaste = array (
  4976. 'accountPrice' => - $refundPrice,
  4977. 'expensesType' => 2,
  4978. 'accountType' => 11,
  4979. 'accountPriceShow' => $refundPrice,
  4980. 'dataID' => $irid,
  4981. 'accountBank' => $accountBank,
  4982. 'category' => $this->staff [0] ['category'],
  4983. 'cid' => $this->staff [0] ['cid'],
  4984. 'name' => $this->staff [0] ['username'],
  4985. 'sid' => $this->staff [0] ['sid'],
  4986. 'inputDate' => date ( "Y-m-d H:i:s" )
  4987. );
  4988. $wasteBook->setAccountBookStatistics ( $itemWaste );
  4989. return '/invoiceReceivablesAS';
  4990. }
  4991. die ( 'illegal request' );
  4992. }
  4993. function ajaxCheckInvoiceReceivablesRefund() {
  4994. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  4995. $refundPrice = $this->get_args ( 'refundPrice' ) ? $this->get_args ( 'refundPrice' ) : "";
  4996. if ($refundPrice < 0) {
  4997. echo json_encode ( array (
  4998. 'error' => '金额不能为负'
  4999. ) );
  5000. die ();
  5001. }
  5002. if (! empty ( $refundPrice ) && ! empty ( $iridKey )) {
  5003. Doo::loadModel ( 'invoiceReceivables' );
  5004. $invoiceReceivables = new invoiceReceivables ();
  5005. $irid = $invoiceReceivables->authcode ( $iridKey );
  5006. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5007. if ($irDetail ['receivablesPrice'] < $refundPrice) {
  5008. echo json_encode ( array (
  5009. 'error' => '退款金额不能超过收款金额'
  5010. ) );
  5011. die ();
  5012. }
  5013. echo json_encode ( array (
  5014. 'ok' => '可以使用!'
  5015. ) );
  5016. die ();
  5017. }
  5018. }
  5019. /**
  5020. * 获得收款退款信息
  5021. */
  5022. function getRefundByDetail() {
  5023. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5024. Doo::loadModel ( 'invoiceReceivables' );
  5025. $invoiceReceivables = new invoiceReceivables ();
  5026. if (! empty ( $iridKey )) {
  5027. $irid = $invoiceReceivables->authcode ( $iridKey );
  5028. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5029. echo json_encode ( array (
  5030. 'status' => 1,
  5031. 'irDetail' => $irDetail
  5032. ) );
  5033. die ();
  5034. }
  5035. echo json_encode ( array (
  5036. 'status' => 2
  5037. ) );
  5038. }
  5039. /**
  5040. * 根据收款序列号获得收款退款信息
  5041. */
  5042. function ajaxGetInvoiceReceivablesBySerial() {
  5043. $receivablesSerial = $this->get_args ( 'receivablesSerial' ) ? $this->get_args ( 'receivablesSerial' ) : '';
  5044. if (! empty ( $receivablesSerial )) {
  5045. Doo::loadModel ( 'invoiceReceivables' );
  5046. $invoiceReceivables = new invoiceReceivables ();
  5047. // , ' and refundLog=""'
  5048. $irDetail = $invoiceReceivables->getInvoiceReceivablesBySerial ( $receivablesSerial );
  5049. $html = '';
  5050. if (! empty ( $irDetail ))
  5051. $html = '<td><b>¥' . $irDetail ['receivablesPrice'] . '</b></td>
  5052. <td>' . $irDetail ['receivablesMessage'] . '</td>
  5053. <td>' . $irDetail ['receivablesBank'] . '<br>' . $irDetail ['receivablesDate'] . '</td>
  5054. <td>' . $irDetail ['title'] . '-' . $irDetail ['username'] . '<br>' . $irDetail ['confirmTime'] . '</td>
  5055. <td>' . $irDetail ['recepitTitleMark'] . '
  5056. <input type="hidden" name="iridKey" id="iridKey" value="' . $irDetail ['iridKey'] . '">
  5057. </td>';
  5058. echo json_encode ( array (
  5059. 'status' => 1,
  5060. 'html' => $html,
  5061. 'irDetail' => $irDetail
  5062. ) );
  5063. die ();
  5064. }
  5065. echo json_encode ( array (
  5066. 'status' => 2
  5067. ) );
  5068. }
  5069. /**
  5070. * 绑定新收款
  5071. */
  5072. function relationNewInvoiceReceivables() {
  5073. $iridKeyOld = $this->get_args ( 'iridKeyOld' ) ? $this->get_args ( 'iridKeyOld' ) : '';
  5074. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5075. if (! empty ( $iridKeyOld ) && ! empty ( $iridKey )) {
  5076. Doo::loadModel ( 'invoiceReceivables' );
  5077. $invoiceReceivables = new invoiceReceivables ();
  5078. Doo::loadClass ( 'XDeode' );
  5079. $XDeode = new XDeode ( 5 );
  5080. $irid = $XDeode->decode ( $iridKey );
  5081. $iridOld = $invoiceReceivables->authcode ( $iridKeyOld );
  5082. echo $irid . 'bbb' . $iridOld;
  5083. $oldIrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $iridOld );
  5084. $IrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5085. if (empty ( $oldIrDetail ) || empty ( $IrDetail ))
  5086. die ( 'illegal request' );
  5087. $relationLog = $this->staff [0] ['username'] . ' 关联新款 <a href="#billing" onclick="invoiceReceivblesDivShow(\'' . $iridKey . '\',\'receivables\')" data-toggle="modal">' . $IrDetail ['receivablesSerial'] . '</a>
  5088. <br/>' . date ( "Y-m-d H:i:s" ) . '
  5089. ';
  5090. $invoiceReceivables = new invoiceReceivables ();
  5091. $item = array (
  5092. 'irid' => $iridOld,
  5093. 'relationIrid' => $irid,
  5094. 'relationLog' => $relationLog
  5095. );
  5096. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  5097. return '/invoiceReceivablesAS';
  5098. }
  5099. die ( 'illegal request' );
  5100. }
  5101. // function invoiceApprovalAchieve() {
  5102. // Doo::loadModel ( 'invoice' );
  5103. // $invoice = new invoice ();
  5104. // $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  5105. // $page_size = 12;
  5106. // $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5107. // $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  5108. // $get = "/" . $date;
  5109. // $con = '';
  5110. // if ($date == 'MONTHO')
  5111. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  5112. // elseif ($date == 'MONTHT')
  5113. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  5114. // elseif ($date == 'MONTHY')
  5115. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  5116. // if (! empty ( $MebSea )) {
  5117. // $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  5118. // $get .= "/" . $MebSea;
  5119. // }
  5120. // $pageinfo ['page'] = array (
  5121. // 'previous' => ''
  5122. // );
  5123. // $sql = '(status=1 or status=2 or status=3 or status=4) and processApprovals!=""' . $con; // echo $sql;
  5124. // $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", $get, "" );
  5125. // $limit = $pageinfo ['lower'] . ',' . $page_size;
  5126. // $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  5127. // // print_r($list);
  5128. // $this->data ['MebSeaEn'] = $MebSea;
  5129. // $this->data ['MebSea'] = urlencode ( $MebSea );
  5130. // $this->data ['get'] = $get;
  5131. // $this->data ['page'] = $pageinfo;
  5132. // $this->data ['list'] = $list;
  5133. // $this->data ['date'] = $date;
  5134. // $this->data ['memu'] = "invoice";
  5135. // $this->data ['staff'] = $this->staff;
  5136. // $this->data ['receiptMemu'] = 'invoiceApproval';
  5137. // $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  5138. // }
  5139. /**
  5140. * 获得审批发票的信息以及审批页面
  5141. */
  5142. function ajaxGetInvoiceApprovalDetail() {
  5143. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5144. if (empty ( $serial )) {
  5145. echo json_encode ( array (
  5146. 'status' => 2,
  5147. 'msg' => 'illegal request'
  5148. ) );
  5149. die ();
  5150. }
  5151. Doo::loadModel ( 'invoice' );
  5152. $invoice = new invoice ();
  5153. Doo::loadModel ( 'invoiceOperationLog' );
  5154. $invoiceOperationLog = new invoiceOperationLog ();
  5155. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5156. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5157. if (empty ( $detail ))
  5158. $html = '';
  5159. else {
  5160. $html = '
  5161. <form action="/invoiceApprovalDo" method="post" name="invoiceApproval" class="nice-validator n-yellow" novalidate="novalidate">
  5162. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  5163. <input type="hidden" name="status" value="">
  5164. <input type="hidden" name="divApproval" value="divApproval">
  5165. <div class="modal-dialog modal-lg">
  5166. <div class="modal-content"><div class="modal-header"><h3>发票审批详情</h3></div>
  5167. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  5168. <tr>
  5169. <th class="taC" width="150">发票审批</th><td><textarea name="opinion" style="width:98%" placeholder="在这写下您的审批意见,选填。"></textarea></td>
  5170. </tr>
  5171. <tr>
  5172. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5173. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5174. </tr>
  5175. <tr>
  5176. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5177. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5178. </tr>
  5179. <tr>
  5180. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5181. </td>
  5182. </tr>
  5183. <tr>
  5184. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5185. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5186. </tr>
  5187. <tr>
  5188. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5189. </tr></tbody></table>';
  5190. if ($detail ['invoiceType'] == 0)
  5191. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5192. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5193. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5194. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5195. </tr>';
  5196. else
  5197. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5198. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5199. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5200. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5201. ';
  5202. $html .= '<tr>
  5203. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5204. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5205. </tr>
  5206. <tr>
  5207. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5208. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5209. </tr></tbody></table>';
  5210. if ($detail ['doPost'] == 1) {
  5211. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5212. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5213. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5214. </tr><tr>
  5215. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5216. </tr><tr>
  5217. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5218. </tr>
  5219. ';
  5220. if ($detail ['expressCom'] == 'SF')
  5221. $html .= '<tr><th class="taC" width="150">快递单号</th><td colspan="3">' . $detail ['expressCompany'] . ' <a target="_blank" href="http://www.sf-express.com/cn/sc/dynamic_function/waybill/#search/bill-number/">' . $detail ['expressNumber'] . '</a> </td></tr>';
  5222. else
  5223. $html .= '<tr><th class="taC" width="150">快递单号</th><td colspan="3">' . $detail ['expressCompany'] . ' <a target="_blank" href="/invoiceExpress/' . $detail ['expressCom'] . '/' . $detail ['expressNumber'] . '.html">' . $detail ['expressNumber'] . '</a> </td></tr>';
  5224. $html .= '</tbody></table>';
  5225. }
  5226. if (! empty ( $invoiceOperationLogList )) {
  5227. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  5228. foreach ( $invoiceOperationLogList as $key => $value ) {
  5229. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5230. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5231. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5232. if ($value ['status'] == 2) {
  5233. $html .= '<span class="colGreen">同意</span>';
  5234. } elseif ($value ['status'] == 3) {
  5235. $html .= '<span class="colOrange">退回</span>';
  5236. } elseif ($value ['status'] == 5) {
  5237. $html .= '<span class="colGreen">打印</span>';
  5238. } elseif ($value ['status'] == 4) {
  5239. $html .= '<span class="colRed">终止</span>';
  5240. }
  5241. $html .= $value ['operation'] . '</p></blockquote>';
  5242. }
  5243. }
  5244. $html .= '</td></tr></tbody></table>';
  5245. }
  5246. $html .= '</div><div class="modal-footer">
  5247. <a href="javascript:void(0)" node-approval="approval" diss-data="2" class="button btn-done" data-placement="top" data-toggle="ctooltip" >同意</a>
  5248. <a href="javascript:void(0)" node-approval="approval" diss-data="3" class="button btn-back" data-placement="top" data-toggle="ctooltip" data-original-title="上报人修改后重新审批">退回</a>
  5249. <a href="javascript:void(0)" node-approval="approval" diss-data="4" class="button btn-undone" data-placement="top" data-toggle="ctooltip" data-original-title="终止发票申请">终止</a>
  5250. <a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>
  5251. </form>
  5252. <script type="text/javascript">
  5253. $("a[node-approval^=\'approval\']").click(function() {
  5254. $("input[name=\'status\']").val($(this).attr("diss-data"));
  5255. $("form[name=\'invoiceApproval\']").submit();
  5256. });
  5257. </script>
  5258. ';
  5259. }
  5260. echo json_encode ( array (
  5261. 'status' => 1,
  5262. 'html' => $html
  5263. ) );
  5264. die ();
  5265. }
  5266. /**
  5267. * 获得审批发票分页数据
  5268. */
  5269. function ajaxGetinvoiceApprovalAchieve() {
  5270. Doo::loadModel ( 'invoice' );
  5271. $invoice = new invoice ();
  5272. Doo::loadModel ( 'staff' );
  5273. $staff = new staff ();
  5274. Doo::loadClass ( 'XDeode' );
  5275. $XDeode = new XDeode ( 5 );
  5276. Doo::loadModel ( 'invoiceTraining' );
  5277. $invoiceTraining = new invoiceTraining ();
  5278. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  5279. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5280. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5281. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5282. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5283. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  5284. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  5285. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  5286. $MebSea = $this->get_args ( 'search' );
  5287. $MebSea = $MebSea ['value'];
  5288. $page_size = $length;
  5289. $con = '';
  5290. if ($status == 'ALL')
  5291. $con = ' (status=1 or status=2 or status=3 or status=4) and isDelete=0 ';
  5292. elseif ($status == 'PEND')
  5293. $con = ' isDelete=0 and status=1';
  5294. elseif ($status == 'APPROVED')
  5295. $con = ' isDelete=0 and status=2';
  5296. if ($invoiceType == 'ORDINARY')
  5297. $con .= ' and invoiceType=0 ';
  5298. elseif ($invoiceType == 'SPECIAL')
  5299. $con .= ' and invoiceType=1 ';
  5300. if ($invoiceTrain == 'ORDINARY')
  5301. $con .= ' and trainId=0 ';
  5302. elseif ($invoiceTrain == 'TRAIN')
  5303. $con .= ' and trainId!=0 ';
  5304. if ($invoiceTrainName != 'ALL') {
  5305. $trainId = $XDeode->decode ( $invoiceTrainName );
  5306. if (is_numeric ( $trainId ))
  5307. $con .= ' and trainId =' . $trainId;
  5308. }
  5309. $dateArr = explode ( ':', $date );
  5310. $D1 = $dateString = '';
  5311. $D2 = '';
  5312. if (! empty ( $date )) {
  5313. $D1 = $dateArr [0];
  5314. if (isset ( $dateArr [1] ))
  5315. $D2 = $dateArr [1];
  5316. else
  5317. $D2 = '';
  5318. $dateString = $D1 . " : " . $D2;
  5319. }
  5320. if (! empty ( $D1 ) && ! empty ( $D2 ))
  5321. $con .= ' and approvalTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  5322. elseif (! empty ( $D1 ) && empty ( $D2 ))
  5323. $con .= ' and approvalTime like "%' . $D1 . '%" ';
  5324. if (! empty ( $MebSea ))
  5325. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceSerial like "%' . $MebSea . '%" )';
  5326. // /
  5327. $pageinfo ['page'] = array (
  5328. 'previous' => ''
  5329. );
  5330. $sql = ' ' . $con;
  5331. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", '', "" );
  5332. $limit = $page . ',' . $page_size;
  5333. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  5334. $approvalList = array ();
  5335. $html = '<script type="text/javascript">
  5336. </script>';
  5337. // 结算结束不能修改方式
  5338. Doo::loadModel ( 'receipt' );
  5339. $receipt = new receipt ();
  5340. foreach ( $list as $key => $value ) {
  5341. $irDetail = array ();
  5342. // 结算方式
  5343. $receiptDetail = array ();
  5344. if ($value ['trainId'] != 0) {
  5345. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $value ['trainId'] );
  5346. }
  5347. if (! empty ( $receiptDetail )) {
  5348. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9) {
  5349. array_push ( $irDetail, '' );
  5350. } else {
  5351. if ($value ['status'] == 1 && $value ['pendingApprovals'] == $this->staff [0] ['sid']) {
  5352. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoiceApproval(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">审批发票</a>' );
  5353. } elseif ($value ['status'] == 2) {
  5354. array_push ( $irDetail, '<a href="#editPay" class="fnSettlementType" data-iidKey="' . $value ['iidKeyK'] . '" data-toggle="modal">结算方式</a>' );
  5355. } else
  5356. array_push ( $irDetail, '' );
  5357. }
  5358. } else {
  5359. if ($value ['status'] == 2) {
  5360. array_push ( $irDetail, '<a href="#editPay" class="fnSettlementType" data-iidKey="' . $value ['iidKeyK'] . '" data-toggle="modal">结算方式</a>' );
  5361. } else
  5362. array_push ( $irDetail, '' );
  5363. }
  5364. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  5365. if ($value ['invoiceType'] == 1)
  5366. array_push ( $irDetail, $value ['invoiceCompany'] );
  5367. else
  5368. array_push ( $irDetail, $value ['invoiceTitle'] );
  5369. array_push ( $irDetail, $value ['TIN'] );
  5370. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  5371. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  5372. array_push ( $irDetail, $value ['remark'] );
  5373. array_push ( $irDetail, $value ['invoiceElement'] );
  5374. array_push ( $irDetail, $value ['invoiceQuantity'] );
  5375. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  5376. if ($value ['invoiceType'] == 1) {
  5377. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  5378. } else {
  5379. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  5380. }
  5381. if ($value ['settlementType'] == 0) {
  5382. array_push ( $irDetail, '软件销售' );
  5383. } else {
  5384. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $value ['trainId'] );
  5385. array_push ( $irDetail, $itDetail ['trainName'] );
  5386. }
  5387. array_push ( $irDetail, $value ['recipients'] . $value ['recipientsPhone'] );
  5388. array_push ( $irDetail, $value ['recipientsAddress'] );
  5389. array_push ( $irDetail, $value ['mailItems'] );
  5390. array_push ( $irDetail, $value ['userName'] . '&nbsp;' . $value ['date'] );
  5391. $fchtml = $value ['OL'] ['operation'];
  5392. if (count ( $list ) == $page_size)
  5393. $fchtml = $value ['OL'] ['operation'] . $html;
  5394. // 最后的审批意见
  5395. array_push ( $irDetail, $fchtml );
  5396. if ($value ['status'] == 2)
  5397. array_push ( $irDetail, '<span class="colGreen">同意</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5398. elseif ($value ['status'] == 3)
  5399. array_push ( $irDetail, '<span class="colOrange">退回</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5400. elseif ($value ['status'] == 4)
  5401. array_push ( $irDetail, '<span class="colRed">终止</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5402. else
  5403. array_push ( $irDetail, '' );
  5404. array_push ( $approvalList, $irDetail );
  5405. }
  5406. // $approvalListJson = json_encode ( $approvalList );
  5407. $recordsFiltered = $pageinfo ['total_data'];
  5408. echo json_encode ( array (
  5409. "draw" => intval ( $draw ),
  5410. "recordsTotal" => intval ( $pageinfo ['total_data'] ),
  5411. "recordsFiltered" => intval ( $recordsFiltered ),
  5412. "data" => $approvalList
  5413. ), JSON_UNESCAPED_UNICODE );
  5414. }
  5415. /**
  5416. * 审批发票查看更多--重构
  5417. */
  5418. function invoiceApprovalAchieve() {
  5419. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'ALL';
  5420. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5421. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5422. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5423. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5424. Doo::loadModel ( 'invoiceTraining' );
  5425. $invoiceTraining = new invoiceTraining ();
  5426. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  5427. $this->data ['trainList'] = $trainList;
  5428. $this->data ['dateString'] = $date;
  5429. $this->data ['status'] = $status;
  5430. $this->data ['invoiceType'] = $invoiceType;
  5431. $this->data ['invoiceTrain'] = $invoiceTrain;
  5432. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  5433. $this->data ['memu'] = "invoice";
  5434. $this->data ['staff'] = $this->staff;
  5435. $this->data ['receiptMemu'] = 'invoiceApproval';
  5436. $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  5437. }
  5438. function invoiceTAchieve() {
  5439. Doo::loadModel ( 'invoice' );
  5440. $invoice = new invoice ();
  5441. Doo::loadClass ( 'XDeode' );
  5442. $XDeode = new XDeode ( 5 );
  5443. Doo::loadModel ( 'staff' );
  5444. $staff = new staff ();
  5445. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  5446. $page_size = 12;
  5447. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5448. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  5449. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5450. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5451. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5452. Doo::loadModel ( 'invoiceTraining' );
  5453. $invoiceTraining = new invoiceTraining ();
  5454. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  5455. $get = "/" . $date;
  5456. $con = '';
  5457. if ($date == 'MONTHO')
  5458. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  5459. elseif ($date == 'MONTHT')
  5460. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  5461. elseif ($date == 'MONTHY')
  5462. $con = ' and YEAR(updateTime) = YEAR(NOW())'; // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  5463. if ($invoiceType == 'ORDINARY')
  5464. $con .= ' and invoiceType=0 ';
  5465. elseif ($invoiceType == 'SPECIAL')
  5466. $con .= ' and invoiceType=1 ';
  5467. if ($invoiceTrain == 'ORDINARY')
  5468. $con .= ' and trainId=0 ';
  5469. elseif ($invoiceTrain == 'TRAIN')
  5470. $con .= ' and trainId!=0 ';
  5471. if ($invoiceTrainName != 'ALL') {
  5472. $trainId = $XDeode->decode ( $invoiceTrainName );
  5473. if (is_numeric ( $trainId ))
  5474. $con .= ' and trainId =' . $trainId;
  5475. }
  5476. if (! empty ( $MebSea )) {
  5477. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  5478. $get .= "/" . $MebSea;
  5479. }
  5480. $pageinfo ['page'] = array (
  5481. 'previous' => ''
  5482. );
  5483. $sql = "";
  5484. $action = "";
  5485. if ($this->ACTION == 'invoicePrintAchieve') {
  5486. $sql = "status=2 and printStatus=1 and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  5487. $action = "invoicePrintAchieve";
  5488. } elseif ($this->ACTION == 'invoicePostAchieve') {
  5489. // and untreadStatus=0
  5490. $sql = "postStatus=1 and doPost=1 and status=2 and isDelete=0" . $con;
  5491. $action = "invoicePostAchieve";
  5492. } elseif ($this->ACTION == 'invoiceUntreadAchieve') { // printStatus=1 and
  5493. $sql = " untreadStatus=2 and status=2 " . $con;
  5494. $action = "invoiceUntreadAchieve";
  5495. }
  5496. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  5497. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5498. $this->data ['MebSeaEn'] = $MebSea;
  5499. $this->data ['MebSea'] = urlencode ( $MebSea );
  5500. $this->data ['get'] = $get;
  5501. $this->data ['page'] = $pageinfo;
  5502. $this->data ['trainList'] = $trainList;
  5503. $this->data ['invoiceType'] = $invoiceType;
  5504. $this->data ['invoiceTrain'] = $invoiceTrain;
  5505. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  5506. $this->data ['date'] = $date;
  5507. $this->data ['memu'] = "invoice";
  5508. $this->data ['staff'] = $this->staff;
  5509. if ($this->ACTION == 'invoicePrintAchieve') {
  5510. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  5511. $this->data ['receiptMemu'] = 'invoicePrint';
  5512. $this->data ['list'] = $list;
  5513. $this->render ( "/admin/invoicePrintAchieve", $this->data );
  5514. } elseif ($this->ACTION == 'invoicePostAchieve') {
  5515. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  5516. Doo::loadModel ( 'express' );
  5517. $express = new express ();
  5518. $expressList = $express->getExpressByAll ();
  5519. $this->data ['expressList'] = $expressList;
  5520. $this->data ['receiptMemu'] = 'invoicePost';
  5521. $this->data ['list'] = $list;
  5522. $this->render ( "/admin/invoicePostAchieve", $this->data );
  5523. } elseif ($this->ACTION == 'invoiceUntreadAchieve') {
  5524. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  5525. $this->data ['receiptMemu'] = 'invoiceUntread';
  5526. $this->data ['list'] = $list;
  5527. $this->render ( "/admin/invoiceUntreadAchieve", $this->data );
  5528. }
  5529. }
  5530. /**
  5531. * 公司应收款
  5532. */
  5533. function invoiceAggregateCompanyDetail() {
  5534. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  5535. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  5536. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : 'ALL';
  5537. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  5538. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  5539. $titleORno = $this->get_args ( 'titleORno' ) ? $this->get_args ( 'titleORno' ) : "";
  5540. Doo::loadClass ( 'XDeode' );
  5541. $XDeode = new XDeode ( 5 );
  5542. Doo::loadModel ( 'invoice' );
  5543. $invoice = new invoice ();
  5544. Doo::loadModel ( 'staff' );
  5545. $staff = new staff ();
  5546. Doo::loadModel ( "invoiceCompanyManage" );
  5547. $invoiceCompanyManage = new invoiceCompanyManage ();
  5548. Doo::loadModel ( 'L_category' );
  5549. $category = new L_category ();
  5550. $sid = '';
  5551. if (! empty ( $sidKey )) {
  5552. $sid = $XDeode->decode ( $sidKey );
  5553. }
  5554. $staffDetail = $staff->getStaffBySid ( $sid );
  5555. $cid = '';
  5556. if (! empty ( $cidKey )) {
  5557. $cid = $XDeode->decode ( $cidKey );
  5558. }
  5559. $imcStaff = $invoiceCompanyManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  5560. $cidList = array ();
  5561. foreach ( $imcStaff as $key => $value ) {
  5562. array_push ( $cidList, $value ['cid'] );
  5563. }
  5564. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  5565. $cidString = implode ( ',', $cidList );
  5566. if (empty ( $cid ))
  5567. $staffList = $staff->getStaffInCid ( $cidString );
  5568. else
  5569. $staffList = $staff->getStaffByCidAll ( $cid ); //
  5570. //$MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  5571. $page_size = 25;
  5572. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5573. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  5574. $con = ' status=2 and untreadStatus!=2 ';
  5575. $statisticsCon = '';
  5576. if (! empty ( $year ) && is_numeric ( $year ))
  5577. $con .= ' and Year(printTime)=' . $year . '';
  5578. if (! empty ( $month ) && is_numeric ( $month ))
  5579. $con .= ' and Month(printTime)="' . $month . '" ';
  5580. if ($status == 'UNRECORD')
  5581. $con .= ' and printStatus=1 and untreadStatus=0';
  5582. elseif ($status == 'RECORD')
  5583. $con .= ' and printStatus=1 and untreadStatus=3';
  5584. elseif ($status == 'BOUNCED')
  5585. $con .= ' and untreadStatus=2';
  5586. elseif ($status == 'PARTRECORD')
  5587. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  5588. elseif ($status == 'All') {
  5589. $con .= ' and printStatus=1 and ( untreadStatus=0 or untreadStatus=3 )';
  5590. }
  5591. if (! empty ( $sid ) && is_numeric ( $sid ))
  5592. $con .= ' and sid=' . $sid;
  5593. if (! empty ( $cid ) && is_numeric ( $cid ))
  5594. $con .= ' and cid=' . $cid;
  5595. else
  5596. $con .= ' and cid in (' . $cidString . ')';
  5597. // 开票内容筛选
  5598. if (! empty ( $invoiceElement ) && $invoiceElement != 'ALL') {
  5599. $con .= ' and invoiceElement="' . $invoiceElement . '"';
  5600. }
  5601. $get = "/" . $status . "?cidKey=" . $cidKey . "&sidKey=" . $sidKey . "&year=" . $year . "&month=" . $month
  5602. . "&invoiceElement=" . $invoiceElement."&titleORno=".urlencode ( $titleORno );
  5603. if (! empty ( $titleORno )) {
  5604. $con .= ' and ( invoiceTitle like "%' . $titleORno . '%" or invoiceCompany like "%' . $titleORno . '%" or invoiceNo like "%'.$titleORno.'%" )';
  5605. }
  5606. $pageinfo ['page'] = array (
  5607. 'previous' => ''
  5608. );
  5609. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateCompanyDetail", $get, "" );
  5610. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5611. // 应收款合计
  5612. $ics = $invoice->getInvoiceCompanyStatistics ( $con );
  5613. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  5614. $monthHtml = "";
  5615. if ($year != "ALL") {
  5616. for($i = 1; $i <= 12; $i ++) {
  5617. if ($i == $month)
  5618. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  5619. else
  5620. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  5621. }
  5622. }
  5623. $this->data ['monthHtml'] = $monthHtml;
  5624. $this->data ['year'] = $year;
  5625. $this->data ['month'] = $month;
  5626. $this->data ['ics'] = $ics;
  5627. $this->data ['cidKey'] = $cidKey;
  5628. $this->data ['sid'] = $sid;
  5629. $this->data ['staffDetail'] = $staffDetail;
  5630. $this->data ['staffList'] = $staffList;
  5631. $this->data ['titleORnoEn'] = $titleORno;
  5632. $this->data ['titleORno'] = urlencode ( $titleORno );
  5633. $this->data ['invoiceDetail'] = array (
  5634. 'invoiceElement' => $invoiceElement
  5635. );
  5636. $this->data ['page'] = $pageinfo;
  5637. $this->data ['get'] = $get;
  5638. $this->data ['list'] = $list;
  5639. $this->data ['status'] = $status;
  5640. $this->data ['categoryList'] = $categoryList;
  5641. $this->data ['memu'] = "invoice";
  5642. $this->data ['staff'] = $this->staff;
  5643. $this->data ['receiptMemu'] = 'invoiceAggregateCompanyDetail';
  5644. $this->render ( "/admin/invoiceAggregateCompanyDetail", $this->data );
  5645. }
  5646. /**
  5647. * 获取一条收款信息
  5648. */
  5649. function ajaxGetInvoiceReceivables() {
  5650. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  5651. Doo::loadModel ( 'invoiceReceivables' );
  5652. $invoiceReceivables = new invoiceReceivables ();
  5653. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5654. echo json_encode ( array (
  5655. 'status' => 1,
  5656. 'detail' => $detail
  5657. ) );
  5658. }
  5659. /**
  5660. * 异步获取办事处用户
  5661. */
  5662. function ajaxGetStaffByCategory() {
  5663. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "";
  5664. Doo::loadModel ( 'staff' );
  5665. $staff = new staff ();
  5666. if ($cid == "PUBLIC") {
  5667. echo json_encode ( array (
  5668. 'status' => 1,
  5669. 'html' => '<option value="PUBLIC">办事处待认领款项</option>'
  5670. ) );
  5671. die ();
  5672. }
  5673. if (! is_numeric ( $cid )) {
  5674. echo json_encode ( array (
  5675. 'status' => 0,
  5676. 'msg' => 'illegal request'
  5677. ) );
  5678. die ();
  5679. }
  5680. $staffList = $staff->getStaffByCid ( $cid );
  5681. $html = '<option value="PUBLIC">办事处待认领款项</option>';
  5682. foreach ( $staffList as $key => $value ) {
  5683. $html .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  5684. }
  5685. echo json_encode ( array (
  5686. 'status' => 1,
  5687. 'html' => $html
  5688. ) );
  5689. }
  5690. /**
  5691. * 异步获取一条发票的邮寄信息
  5692. */
  5693. function ajaxGetInvoicePostDetail() {
  5694. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  5695. Doo::loadModel ( 'invoice' );
  5696. $invoice = new invoice ();
  5697. $iid = $invoice->authcode ( $iid );
  5698. Doo::loadModel ( 'express' );
  5699. $express = new express ();
  5700. $expressList = $express->getExpressByAll ();
  5701. if (! is_numeric ( $iid )) {
  5702. echo json_encode ( array (
  5703. 'status' => 0,
  5704. 'msg' => 'illegal request'
  5705. ) );
  5706. die ();
  5707. }
  5708. $select = "iid,recipients,recipientsPhone,recipientsAddress,mailItems,expressCompany,expressNumber,actualItems";
  5709. $invoiceDetail = $invoice->getInvoiceByIid ( $iid, $select );
  5710. $html = "";
  5711. foreach ( $expressList as $key => $value ) {
  5712. if ($value ['company'] == $invoiceDetail ['expressCompany'])
  5713. $html .= '<option selected value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  5714. else
  5715. $html .= '<option value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  5716. }
  5717. $invoiceDetail ['eaHtml'] = $html;
  5718. echo json_encode ( array (
  5719. 'status' => 1,
  5720. 'invoiceDetail' => $invoiceDetail
  5721. ) );
  5722. }
  5723. /**
  5724. *
  5725. * @deprecated --需求变更 废弃 function ajaxCompareClaimPrice() { $irid = $this->get_args ( 'irid' ) ? $this->get_args ( 'irid' ) : ""; $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : ""; Doo::loadModel ( 'invoice' ); $invoice = new invoice (); Doo::loadModel ( 'invoiceReceivables' ); $invoiceReceivables = new invoiceReceivables (); Doo::loadModel ( 'invoiceOperationLog' ); $invoiceOperationLog = new invoiceOperationLog (); $detail = $invoice->getInvoiceByIid ( $invoiceKey ); $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid ); if (empty ( $detail ) || empty ( $detailM )) { echo json_encode ( array ( 'status' => 2, 'msg' => '非法请求,请重新登录' ) ); die (); } $iridString = ""; if (empty ( $detail ['irid'] )) $iridString = $detailM ['irid']; else $iridString = $detail ['irid'] . ',' . $detailM ['irid']; $item = array ( 'irid' => $iridString, 'bindTime' => date ( "Y-m-d H:i:s" ), 'updateTime' => date ( "Y-m-d H:i:s" ), 'iid' => $detail ['iid'] ); $invoice->setInvoiceByCondition ( $item ); // 操作日志 $item = array ( 'date' => date ( "Y-m-d H:i:s" ), 'operation' => "收款入账" . $detailM ['receivablesSerial'] . "到发票" . $detail ['invoiceSerial'], 'status' => 8, 'img' => $this->staff [0] ['avatar'], 'username' => $this->staff [0] ['username'], 'uid' => $this->staff [0] ['sid'], 'category' => $this->staff [0] ['category'], 'iid' => $detail ['iid'] ); $invoiceOperationLog->setInvoiceOperationLog ( $item ); $item = array ( 'iid' => $detail ['iid'], 'irid' => $detailM ['irid'], 'bindDate' => date ( "Y-m-d H:i:s" ), 'bindStatus' => 1 ); $invoiceReceivables->setInvoiceReceivablesByCondition ( $item ); $price = 0; $priceStatus = 0; $isReceivables = 0; $invoiceReceivables = new invoiceReceivables (); $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $iridString ); if (! empty ( $list )) $isReceivables = 1; $receivablesPrice = 0; foreach ( $list as $key => $value ) { $receivablesPrice += $value ['receivablesPrice']; } if ($receivablesPrice > $detail ['invoicePrice']) { $price = $receivablesPrice - $detail ['invoicePrice']; $priceStatus = 1; } elseif ($receivablesPrice < $detail ['invoicePrice']) { $price = $detail ['invoicePrice'] - $receivablesPrice; $priceStatus = 2; } echo json_encode ( array ( 'status' => 1, 'html' => '<tr><td>¥' . $detailM ['receivablesPrice'] . '</td><td>' . $detailM ['receivablesMessage'] . '</td><td>' . $detailM ['receivablesBank'] . '</td> <td>' . $detailM ['receivablesDate'] . '</td><td><a node-remove="Da' . $detailM ['iridKey'] . '" href="javascript:void(0);">移除</a></td></tr> <script> $(\'a[node-remove="Da' . $detailM ['iridKey'] . '"]\').click(function() { var invoiceKey=$("input[name=\'key\']").val(); var irid= $(this).attr("p-data"); var iridKey="' . $detailM ["iridEn"] . '"; var element=($(this)); $("p[node-loading=\"true\"]").show(); $("p[node-loading=\"true\"]").html("移除处理中..."); $("p[node-msg=\"true2\"]").hide(); $("p[node-msg=\"true\"]").hide(); var url = "/ajaxReceivablesRemove"; $.ajax({ url : url, type : "post", cache : false, dataType : "json", data : { key : iridKey, invoiceKey:invoiceKey }, global : true, success : function(data) { $("input[name=\'invoiceKey\']").val("' . $detailM ['iridEn'] . '"); if (data.status == 1) { $(element).parent().parent().remove(); $("tbody[data-invoice=\"myReceivables\"]").append(data.html); $("p[node-loading=\"true\"]").hide(); if(data.priceStatus == 1){ $("p[node-msg=\"true\"]").html("收款金额超出开票金额 ¥"+data.price+"元,请谨慎操作。"); $("p[node-msg=\"true\"]").show(); }else if(data.priceStatus == 2&& data.isReceivables != 0){ $("p[node-msg=\"true\"]").html("收款金额少于开票金额 ¥"+data.price+"元,请谨慎操作。"); $("p[node-msg=\"true\"]").show(); } }else if(data.status == 2){ $("p[node-loading=\"true\"]").html(data.msg); } }, error : function(err) { } }); }); </script> ', 'price' => $price, 'priceStatus' => $priceStatus, 'isReceivables' => $isReceivables ) ); }
  5726. */
  5727. /**
  5728. *
  5729. * @deprecated 从发票中移除已经入账的收款 --需求变更 废弃 function ajaxReceivablesRemove() { $iridKey = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : ""; $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : ""; Doo::loadModel ( 'invoice' ); $invoice = new invoice (); Doo::loadModel ( 'invoiceReceivables' ); $invoiceReceivables = new invoiceReceivables (); Doo::loadModel ( 'invoiceOperationLog' ); $invoiceOperationLog = new invoiceOperationLog (); $detail = $invoice->getInvoiceByIid ( $invoiceKey ); $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $iridKey ); // echo $detail['irid']."<br/>"; $invoiceIrid = explode ( ",", $detail ['irid'] ); foreach ( $invoiceIrid as $key => $value ) { if ($value == $detailM ['irid']) unset ( $invoiceIrid [$key] ); } $invoiceIrid = implode ( ",", $invoiceIrid ); // echo $invoiceIrid."ddd"; // print_r($invoiceIrid); $item = array ( 'irid' => $invoiceIrid, 'iid' => $detail ['iid'] ); $invoice->setInvoiceByCondition ( $item ); $item = array ( 'iid' => 0, 'irid' => $detailM ['irid'], 'bindDate' => '', 'bindStatus' => 0 ); $invoiceReceivables->setInvoiceReceivablesByCondition ( $item ); // 操作日志 $item = array ( 'date' => date ( "Y-m-d H:i:s" ), 'operation' => "收款移除" . $detailM ['receivablesSerial'], 'status' => 10, 'img' => $this->staff [0] ['avatar'], 'username' => $this->staff [0] ['username'], 'uid' => $this->staff [0] ['sid'], 'category' => $this->staff [0] ['category'], 'iid' => $detail ['iid'] ); $invoiceOperationLog->setInvoiceOperationLog ( $item ); $price = 0; $priceStatus = 0; $isReceivables = 0; $invoiceReceivables = new invoiceReceivables (); $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $invoiceIrid ); if (! empty ( $list )) $isReceivables = 1; $receivablesPrice = 0; foreach ( $list as $key => $value ) { $receivablesPrice += $value ['receivablesPrice']; } if ($receivablesPrice > $detail ['invoicePrice']) { $price = $receivablesPrice - $detail ['invoicePrice']; $priceStatus = 1; } elseif ($receivablesPrice < $detail ['invoicePrice']) { $price = $detail ['invoicePrice'] - $receivablesPrice; $priceStatus = 2; } echo json_encode ( array ( 'status' => 1, 'html' => '<tr id="' . $detailM ['receivablesSerial'] . '" > <td>¥' . $detailM ['receivablesPrice'] . '</td> <td>' . $detailM ['receivablesMessage'] . '</td> <td>' . $detailM ['receivablesBank'] . '</td> <td>' . $detailM ['receivablesDate'] . '</td><td> <a href="javascript:void(0)" node-Claim="true_' . $detailM ['iridKey'] . '" p-data="' . $detailM ['iridEn'] . '" name="invoiceClaim" class="button">入账</a> </td></tr> <script> $(\'a[node-Claim="true_' . $detailM ['iridKey'] . '"]\').click(function() { var invoiceKey=$("input[name=\'key\']").val(); var irid= $(this).attr("p-data"); var element=($(this)); $("p[node-loading=\"true\"]").show(); $("p[node-loading=\"true\"]").html("入账处理中..."); $("p[node-msg=\"true2\"]").hide(); $("p[node-msg=\"true\"]").hide(); var url = "/ajaxCompareClaimPrice"; $.ajax({ url : url, type : "post", cache : false, dataType : "json", data : { irid : irid, invoiceKey:invoiceKey }, global : true, success : function(data) { $("input[name=\'invoiceKey\']").val("' . $detailM ['iridEn'] . '"); if (data.status == 1) { $(element).parent().parent().remove(); $("tbody[box-enter=\"true\"]").append(data.html); $("p[node-loading=\"true\"]").hide(); if(data.priceStatus == 1){ $("p[node-msg=\"true\"]").html("收款金额超出开票金额 ¥"+data.price+"元,请谨慎操作。"); $("p[node-msg=\"true\"]").show(); }else if(data.priceStatus == 2&& data.isReceivables != 0){ $("p[node-msg=\"true\"]").html("收款金额少于开票金额 ¥"+data.price+"元,请谨慎操作。"); $("p[node-msg=\"true\"]").show(); } }else if(data.status == 2){ $("p[node-loading=\"true\"]").html(data.msg); } }, error : function(err) { } }); }); </script> ', 'price' => $price, 'priceStatus' => $priceStatus, 'isReceivables' => $isReceivables ) ); }
  5730. */
  5731. /**
  5732. * 我的收款中 选择哪个发票入账,进行金额判断
  5733. */
  5734. function ajaxCompareInvoicePrice() {
  5735. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  5736. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  5737. Doo::loadModel ( 'invoice' );
  5738. $invoice = new invoice ();
  5739. Doo::loadModel ( 'invoiceReceivables' );
  5740. $invoiceReceivables = new invoiceReceivables ();
  5741. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  5742. $keyList = explode ( ';', $claimKey );
  5743. $receivablesPrice = 0;
  5744. foreach ( $keyList as $key => $value ) {
  5745. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $value );
  5746. $receivablesPrice += $detailM ['receivablesPrice'];
  5747. }
  5748. if ($receivablesPrice > $detail ['invoicePrice']) {
  5749. $price = $receivablesPrice - $detail ['invoicePrice'];
  5750. echo json_encode ( array (
  5751. 'status' => 1,
  5752. 'price' => $price
  5753. ) );
  5754. } else
  5755. echo json_encode ( array (
  5756. 'status' => 2
  5757. ) );
  5758. }
  5759. /**
  5760. * 获得打印发票
  5761. */
  5762. function ajaxGetInvoiceInfoByPrint() {
  5763. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5764. if (empty ( $serial )) {
  5765. echo json_encode ( array (
  5766. 'status' => 2,
  5767. 'msg' => 'illegal request'
  5768. ) );
  5769. die ();
  5770. }
  5771. Doo::loadModel ( 'invoice' );
  5772. $invoice = new invoice ();
  5773. Doo::loadModel ( 'invoiceOperationLog' );
  5774. $invoiceOperationLog = new invoiceOperationLog ();
  5775. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5776. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5777. Doo::loadModel ( 'invoicePaper' );
  5778. $invoicePaper = new invoicePaper ();
  5779. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $detail ['invoiceType'] );
  5780. if (empty ( $detail ))
  5781. $html = '';
  5782. else {
  5783. $html = '
  5784. <form action="/invoicePrintDo" method="post" name="invoicePrint" class="nice-validator n-yellow" onSubmit="return checkPrintForm()" novalidate="novalidate">
  5785. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  5786. <input type="hidden" name="invoicePrintType" value="invoicePrintType">
  5787. <div class="modal-dialog modal-lg">
  5788. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  5789. <div class="modal-body saeaList">
  5790. <table class="table table-bordered table-condensed"><tbody>
  5791. <tr>
  5792. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5793. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5794. </tr>
  5795. <tr>
  5796. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5797. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5798. </tr>
  5799. <tr>
  5800. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5801. </td>
  5802. </tr>
  5803. <tr>
  5804. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5805. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5806. </tr>
  5807. <tr>
  5808. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5809. </tr></tbody></table>';
  5810. if ($detail ['invoiceType'] == 0)
  5811. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5812. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5813. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5814. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5815. </tr>';
  5816. else
  5817. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5818. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5819. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5820. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5821. ';
  5822. $html .= '<tr>
  5823. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5824. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5825. </tr>
  5826. <tr>
  5827. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5828. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5829. </tr></tbody></table>';
  5830. if ($detail ['doPost'] == 1)
  5831. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5832. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5833. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5834. </tr><tr>
  5835. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5836. </tr><tr>
  5837. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5838. </tr></tbody></table>';
  5839. if (! empty ( $invoiceOperationLogList )) {
  5840. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th><th class="taC">发票打印</th></tr><tr><td>';
  5841. foreach ( $invoiceOperationLogList as $key => $value ) {
  5842. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5843. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5844. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5845. if ($value ['status'] == 2) {
  5846. $html .= '<span class="colGreen">同意</span>';
  5847. } elseif ($value ['status'] == 3) {
  5848. $html .= '<span class="colOrange">退回</span>';
  5849. } elseif ($value ['status'] == 5) {
  5850. $html .= '<span class="colGreen">打印</span>';
  5851. } elseif ($value ['status'] == 4) {
  5852. $html .= '<span class="colRed">终止</span>';
  5853. }
  5854. $html .= $value ['operation'] . '</p></blockquote>';
  5855. }
  5856. }
  5857. $html .= '</td>
  5858. <td><span class="colRed">*</span>
  5859. <select name="invoiceNo" id="invoiceNo" style="width:97%">';
  5860. foreach ( $invoicePaperList as $key => $value ) {
  5861. $html .= '<option value="' . $value ['ipidKey'] . '">No.' . $value ['invoiceNo'] . '</option>';
  5862. }
  5863. $html .= '</select>
  5864. <span class="red" id="p-msg"></span>
  5865. </td>
  5866. </tr></tbody></table>';
  5867. }
  5868. $html .= '</div><div class="modal-footer"><button type="submit" class="button btn-green" data-toggle="modal">完成打印</button><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div>
  5869. </div></div></form>
  5870. <link rel=stylesheet href="' . WEB_SITE_GLOBAL . 'css/jquery.validator.css">
  5871. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/jquery.validator.min.js"></script>
  5872. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/zh-CN.js"></script>
  5873. <script src="' . WEB_SITE_GLOBAL . 'js/invoice.validator.js"></script>
  5874. ';
  5875. }
  5876. echo json_encode ( array (
  5877. 'status' => 1,
  5878. 'html' => $html
  5879. ) );
  5880. die ();
  5881. }
  5882. /**
  5883. * @ 获得与我有关收款数据 --需求变更 废弃 function ajaxGetReceivalblesByStaff() { $iid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : ""; Doo::loadModel ( 'invoiceReceivables' ); $invoiceReceivables = new invoiceReceivables (); Doo::loadModel ( 'invoice' ); $invoice = new invoice (); $detail = $invoice->getInvoiceByIid ( $iid ); $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] ); $html = ""; $i = 1; foreach ( $list ['myClaim'] as $key => $value ) { $html .= '<tr id="' . $value ['receivablesSerial'] . '" > <td>¥' . $value ['receivablesPrice'] . '</td> <td>' . $value ['receivablesMessage'] . '</td> <td>' . $value ['receivablesBank'] . '</td> <td>' . $value ['receivablesDate'] . '</td>'; $html .= '<td> <a href="javascript:void(0)" node-Claim="true_' . $i . '" p-data="' . $value ['iidKey'] . '" name="invoiceClaim" class="button">入账</a> </td></tr> <script> $(\'a[node-Claim="true_' . $i . '"]\').click(function() { var invoiceKey=$("input[name=\'key\']").val(); var irid= $(this).attr("p-data"); var element=($(this)); $("p[node-loading=\"true\"]").show(); $("p[node-loading=\"true\"]").html("入账处理中..."); $("p[node-msg=\"true2\"]").hide(); $("p[node-msg=\"true\"]").hide(); var url = "/ajaxCompareClaimPrice"; $.ajax({ url : url, type : "post", cache : false, dataType : "json", data : { irid : irid, invoiceKey:invoiceKey }, global : true, success : function(data) { $("input[name=\'invoiceKey\']").val("' . $value ['iidKey'] . '"); if (data.status == 1) { $(element).parent().parent().remove(); $("tbody[box-enter=\"true\"]").append(data.html); $("p[node-loading=\"true\"]").hide(); if(data.priceStatus == 1){ $("p[node-msg=\"true\"]").html("收款金额超出开票金额 ¥"+data.price+"元,请谨慎操作。"); $("p[node-msg=\"true\"]").show(); }else if(data.priceStatus == 2&& data.isReceivables != 0){ $("p[node-msg=\"true\"]").html("收款金额少于开票金额 ¥"+data.price+"元,请谨慎操作。"); $("p[node-msg=\"true\"]").show(); } }else if(data.status == 2){ $("p[node-loading=\"true\"]").html(data.msg); } }, error : function(err) { } }); }); </script> '; $i ++; } $html2 = ""; $list2 = $invoiceReceivables->getInvoiceReceivablesByIid ( $iid, 1 ); foreach ( $list2 as $key => $value ) { $html2 .= '<tr id="' . $value ['receivablesSerial'] . '" > <td>¥' . $value ['receivablesPrice'] . '</td> <td>' . $value ['receivablesMessage'] . '</td> <td>' . $value ['receivablesBank'] . '</td> <td>' . $value ['receivablesDate'] . '</td>'; $html2 .= '<td> <a href="javascript:void(0)" node-remove="Da' . $value ['iridKey'] . '" >移除</a> </td></tr> <script> $(\'a[node-remove="Da' . $value ['iridKey'] . '"]\').click(function() { var invoiceKey=$("input[name=\'key\']").val(); var irid= $(this).attr("p-data"); var iridKey="' . $value ["iidKey"] . '"; var element=($(this)); $("p[node-loading=\"true\"]").show(); $("p[node-loading=\"true\"]").html("移除处理中..."); $("p[node-msg=\"true2\"]").hide(); $("p[node-msg=\"true\"]").hide(); var url = "/ajaxReceivablesRemove"; $.ajax({ url : url, type : "post", cache : false, dataType : "json", data : { key : iridKey, invoiceKey:invoiceKey }, global : true, success : function(data) { $("input[name=\'invoiceKey\']").val("' . $value ['iidKey'] . '"); if (data.status == 1) { $(element).parent().parent().remove(); $("tbody[data-invoice=\"myReceivables\"]").append(data.html); $("p[node-loading=\"true\"]").hide(); if(data.priceStatus == 1){ $("p[node-msg=\"true\"]").html("收款金额超出开票金额 ¥"+data.price+"元,请谨慎操作。"); $("p[node-msg=\"true\"]").show(); }else if(data.priceStatus == 2&& data.isReceivables != 0){ $("p[node-msg=\"true\"]").html("收款金额少于开票金额 ¥"+data.price+"元,请谨慎操作。"); $("p[node-msg=\"true\"]").show(); } }else if(data.status == 2){ $("p[node-loading=\"true\"]").html(data.msg); } }, error : function(err) { } }); }); </script> '; $i ++; } $price = 0; $priceStatus = 0; $isReceivables = 0; $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $detail ['irid'] ); if (! empty ( $list )) $isReceivables = 1; $receivablesPrice = 0; foreach ( $list as $key => $value ) { $receivablesPrice += $value ['receivablesPrice']; } if ($receivablesPrice > $detail ['invoicePrice']) { $price = $receivablesPrice - $detail ['invoicePrice']; $priceStatus = 1; } elseif ($receivablesPrice < $detail ['invoicePrice']) { $price = $detail ['invoicePrice'] - $receivablesPrice; $priceStatus = 2; } echo json_encode ( array ( 'status' => 1, 'html' => $html, 'html2' => $html2, 'price' => $price, 'priceStatus' => $priceStatus, 'isReceivables' => $isReceivables ) ); }
  5884. */
  5885. function ajaxGetInvoiceInfoByType() {
  5886. $type = $this->get_args ( 'type' ) ? $this->get_args ( 'type' ) : "";
  5887. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5888. $loss = $this->get_args ( 'loss' ) ? $this->get_args ( 'loss' ) : false;
  5889. if (empty ( $serial )) {
  5890. echo json_encode ( array (
  5891. 'status' => 2,
  5892. 'msg' => 'illegal request'
  5893. ) );
  5894. die ();
  5895. }
  5896. if ($type == 'INVOICE') {
  5897. Doo::loadModel ( 'invoice' );
  5898. $invoice = new invoice ();
  5899. Doo::loadModel ( 'invoiceOperationLog' );
  5900. $invoiceOperationLog = new invoiceOperationLog ();
  5901. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5902. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5903. if (empty ( $detail ))
  5904. $html = '';
  5905. else {
  5906. $html = '
  5907. <div class="modal-dialog modal-lg">
  5908. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  5909. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  5910. <tr>
  5911. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5912. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5913. </tr>
  5914. <tr>
  5915. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5916. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5917. </tr>
  5918. <tr>
  5919. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5920. </td>
  5921. </tr>
  5922. <tr>
  5923. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5924. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5925. </tr>
  5926. <tr>
  5927. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5928. </tr>';
  5929. if ($detail ['settlementType'] == 1)
  5930. $html .= '<tr>
  5931. <th class="taC" width="150">结算方式</th><td colspan="3">培训班(<a href="/invoiceTrainingDetail/' . $detail ['invoiceTraining'] ['trainingKey'] . '.html" target="_blank">' . $detail ['invoiceTraining'] ['trainName'] . '</a>)</td>
  5932. </tr>';
  5933. else
  5934. $html .= '<tr>
  5935. <th class="taC" width="150">结算方式</th><td colspan="3">软件销售</td>
  5936. </tr>';
  5937. $html .= ' </tbody></table>';
  5938. if ($detail ['invoiceType'] == 0)
  5939. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5940. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5941. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5942. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5943. </tr>';
  5944. else
  5945. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5946. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5947. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5948. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5949. ';
  5950. $html .= '<tr>
  5951. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5952. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5953. </tr>
  5954. <tr>
  5955. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5956. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5957. </tr></tbody></table>';
  5958. if ($detail ['doPost'] == 1) {
  5959. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5960. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5961. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5962. </tr><tr>
  5963. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5964. </tr><tr>
  5965. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5966. </tr>
  5967. ';
  5968. if ($detail ['expressCom'] == 'SF')
  5969. $html .= '<tr><th class="taC" width="150">快递单号</th><td colspan="3">' . $detail ['expressCompany'] . ' <a target="_blank" href="http://www.sf-express.com/cn/sc/dynamic_function/waybill/#search/bill-number/">' . $detail ['expressNumber'] . '</a> </td></tr>';
  5970. else
  5971. $html .= '<tr><th class="taC" width="150">快递单号</th><td colspan="3">' . $detail ['expressCompany'] . ' <a target="_blank" href="/invoiceExpress/' . $detail ['expressCom'] . '/' . $detail ['expressNumber'] . '.html">' . $detail ['expressNumber'] . '</a> </td></tr>';
  5972. $html .= '</tbody></table>';
  5973. }
  5974. if (! empty ( $invoiceOperationLogList )) {
  5975. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  5976. foreach ( $invoiceOperationLogList as $key => $value ) {
  5977. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5978. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5979. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5980. if ($value ['status'] == 2) {
  5981. $html .= '<span class="colGreen">同意</span>';
  5982. } elseif ($value ['status'] == 3) {
  5983. $html .= '<span class="colOrange">退回</span>';
  5984. } elseif ($value ['status'] == 5) {
  5985. $html .= '<span class="colGreen">打印</span>';
  5986. } elseif ($value ['status'] == 4) {
  5987. $html .= '<span class="colRed">终止</span>';
  5988. }
  5989. $html .= $value ['operation'] . '</p></blockquote>';
  5990. }
  5991. }
  5992. $html .= '</td></tr></tbody></table>';
  5993. }
  5994. $html .= '</div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  5995. }
  5996. echo json_encode ( array (
  5997. 'status' => 1,
  5998. 'html' => $html
  5999. ) );
  6000. die ();
  6001. } elseif ($type == 'RECEIVABLES') {
  6002. Doo::loadModel ( 'invoiceReceivables' );
  6003. $invoiceReceivables = new invoiceReceivables ();
  6004. Doo::loadModel ( 'invoiceRefund' );
  6005. $invoiceRefund = new invoiceRefund ();
  6006. $detail = $invoiceReceivables->getInvoiceReceivablesByIrsid ( $serial );
  6007. $ireList = $invoiceRefund->getInvoiceRefundIrid ( $detail ['irid'] );
  6008. if (empty ( $detail ))
  6009. $html = '';
  6010. else {
  6011. $html = '<div class="modal-dialog modal-lg"><div class="modal-content"><div class="modal-header"><h3>收款单详情</h3></div><div class="modal-body saeaList">
  6012. <table class="table table-bordered table-condensed">
  6013. <tbody><tr>
  6014. <th class="taC">收款流水号</th><td>' . $detail ['receivablesSerial'] . '</td>
  6015. <th class="taC">录入收款</th><td>' . $detail ['inputStaff'] . ' ' . $detail ['date'] . '</td>
  6016. </tr><tr>
  6017. <th class="taC">收款金额</th><td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  6018. <th class="taC">收款信息</th><td>' . $detail ['receivablesMessage'] . '</td>
  6019. </tr>
  6020. <tr>
  6021. <th class="taC">收款银行</th><td>' . $detail ['receivablesBank'] . '</td>
  6022. <th class="taC">银行到账</th><td>' . $detail ['receivablesDate'] . '</td>
  6023. </tr>
  6024. <tr>
  6025. <th class="taC">认领收款</th><td colspan="3">' . $detail ['inputStaff'] . ' 转入 ' . $detail ['username'] . ' ' . $detail ['confirmTime'] . '</td>
  6026. </tr>
  6027. </tbody></table>';
  6028. if (! empty ( $ireList )) {
  6029. $html .= '
  6030. <table class="table table-bordered table-condensed"><tbody><tr><th class="taC" colspan="5">退款记录</th></tr>
  6031. <tr>
  6032. <th class="taC">退款单位名称</th>
  6033. <th class="taC">退款的账号</th>
  6034. <th class="taC">退款金额</th>
  6035. <th class="taC">退款</th>
  6036. <th class="taC">备注</th>
  6037. </tr>
  6038. ';
  6039. foreach ( $ireList as $key => $value ) {
  6040. $refundLogList = explode ( "<br/>", $value ['refundLog'] );
  6041. $html .= '<tr>
  6042. <td>' . $value ['refundCompany'] . '</td>
  6043. <td>' . $value ['refundNumber'] . '</td>
  6044. <td><b class="colRed">¥' . $value ['refundPrice'] . '</b></td>
  6045. <td>' . $refundLogList [0] . $refundLogList [2] . '</td>
  6046. <td>' . $value ['refundRemarks'] . '</td>
  6047. </tr>
  6048. ';
  6049. }
  6050. }
  6051. $html .= '</tbody></table></div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  6052. }
  6053. echo json_encode ( array (
  6054. 'status' => 1,
  6055. 'html' => $html
  6056. ) );
  6057. die ();
  6058. } elseif ($type == 'IRTC') {
  6059. Doo::loadModel ( 'invoice' );
  6060. $invoice = new invoice ();
  6061. Doo::loadModel ( 'invoiceOperationLog' );
  6062. $invoiceOperationLog = new invoiceOperationLog ();
  6063. Doo::loadModel ( 'invoiceReceivables' );
  6064. $invoiceReceivables = new invoiceReceivables ();
  6065. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  6066. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  6067. if (empty ( $detail ))
  6068. $html = '';
  6069. else {
  6070. $receivablesPriceedHtml = '';
  6071. $receivablesPrice = $detail ['invoicePrice'];
  6072. if (! empty ( $detail ['irid'] )) {
  6073. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $detail ['irid'] );
  6074. if (empty ( $irList ))
  6075. $irList [0] ['sumPrice'] = 0;
  6076. $balance = $detail ['invoicePrice'] - $irList [0] ['sumPrice'];
  6077. $receivablesPriceedHtml = '<table class="table table-bordered table-condensed"><tbody><tr>
  6078. <th class="taC">已入账金额</th><td><b class="colGreen" style="font-size:18px">¥' . $irList [0] ['sumPrice'] . '</b></td>
  6079. <th class="taC">剩余入账金额</th><td><b class="colRed" style="font-size:18px">¥' . $balance . '</b></td>
  6080. </tr></tbody></table>';
  6081. $receivablesPrice = $balance;
  6082. }
  6083. if ($loss)
  6084. $detail ['invoicePrice'] = - $detail ['invoicePrice'];
  6085. $html = $receivablesPriceedHtml . '
  6086. <table class="table table-bordered table-condensed"><tbody>
  6087. <tr>
  6088. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  6089. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  6090. </tr>
  6091. <tr>
  6092. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  6093. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  6094. </tr>
  6095. <tr>
  6096. <th class="taC" width="150">发票备注</th><td colspan="3">' . $detail ['remark'] . '</td>
  6097. </tr>
  6098. <tr>
  6099. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  6100. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  6101. </tr>
  6102. <tr>
  6103. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  6104. </tr></tbody></table>';
  6105. if ($detail ['invoiceType'] == 0) {
  6106. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6107. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  6108. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  6109. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  6110. </tr>';
  6111. $receivablesMessage = $detail ['invoiceTitle'];
  6112. } else {
  6113. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6114. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  6115. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  6116. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  6117. ';
  6118. $receivablesMessage = $detail ['invoiceCompany'];
  6119. }
  6120. $html .= '<tr>
  6121. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  6122. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  6123. </tr>
  6124. <tr>
  6125. <th class="taC">开户银行</th><td>' . $detail ['bankAccount'] . '</td>
  6126. <th class="taC">银行账号</th><td>' . $detail ['bank'] . '</td>
  6127. </tr></tbody></table>';
  6128. if ($detail ['doPost'] == 1)
  6129. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  6130. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  6131. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  6132. </tr><tr>
  6133. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  6134. </tr><tr>
  6135. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  6136. </tr></tbody></table>';
  6137. if (! empty ( $invoiceOperationLogList )) {
  6138. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  6139. foreach ( $invoiceOperationLogList as $key => $value ) {
  6140. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  6141. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  6142. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  6143. if ($value ['status'] == 2) {
  6144. $html .= '<span class="colGreen">同意</span>';
  6145. } elseif ($value ['status'] == 3) {
  6146. $html .= '<span class="colOrange">退回</span>';
  6147. } elseif ($value ['status'] == 5) {
  6148. $html .= '<span class="colGreen">打印</span>';
  6149. }
  6150. $html .= $value ['operation'] . '</p></blockquote>';
  6151. }
  6152. }
  6153. $html .= '</td></tr></tbody></table>';
  6154. }
  6155. }
  6156. echo json_encode ( array (
  6157. 'status' => 1,
  6158. 'html' => $html,
  6159. 'receivablesPrice' => $receivablesPrice,
  6160. 'receivablesMessage' => $receivablesMessage,
  6161. 'receivablesDate' => date ( "Y-m-d" ),
  6162. 'iidKey' => $serial
  6163. ) );
  6164. die ();
  6165. }
  6166. }
  6167. function ajaxGetInvoiceReceivablesByStaff() {
  6168. $postData = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : "";
  6169. if (empty ( $postData )) {
  6170. echo json_encode ( array (
  6171. 'status' => 2,
  6172. 'msg' => 'illegal request'
  6173. ) );
  6174. die ();
  6175. }
  6176. Doo::loadModel ( 'invoiceReceivables' );
  6177. $invoiceReceivables = new invoiceReceivables ();
  6178. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $postData );
  6179. if (empty ( $detail )) {
  6180. echo json_encode ( array (
  6181. 'status' => 2,
  6182. 'msg' => 'illegal request'
  6183. ) );
  6184. die ();
  6185. }
  6186. Doo::loadModel ( 'L_category' );
  6187. $lCategory = new L_category ();
  6188. Doo::loadModel ( 'staff' );
  6189. $staff = new staff ();
  6190. $staffList = $staff->getStaffByCid ( $detail ['cid'] );
  6191. $category = $lCategory->getCategory ();
  6192. $categoryHtml = '<option post-data="PUBLIC" value="PUBLIC" >公共待认领款项</option>';
  6193. $staffHtml = '<option value="PUBLIC">办事处待认领款项</option>';
  6194. foreach ( $category as $key => $value ) {
  6195. $categoryHtml .= '<option post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  6196. if ($value ['cid'] == $detail ['cid'])
  6197. $categoryHtml .= '<option selected post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  6198. }
  6199. foreach ( $staffList as $key => $value ) {
  6200. $staffHtml .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  6201. if ($value ['sid'] == $detail ['sid'])
  6202. $staffHtml .= '<option selected value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  6203. }
  6204. $rbankHtml = '<option value="广发银行珠海分行柠溪支行">广发银行珠海分行柠溪支行</option>';
  6205. echo json_encode ( array (
  6206. 'status' => 1,
  6207. 'categoryHtml' => $categoryHtml,
  6208. 'staffHtml' => $staffHtml,
  6209. 'rbankHtml' => $rbankHtml,
  6210. 'detail' => $detail
  6211. ) );
  6212. }
  6213. function ajaxGetInvoiceReceivablesByIrid() {
  6214. $irid = $this->get_args ( 'irid' ) ? $this->get_args ( 'irid' ) : "";
  6215. if (empty ( $irid )) {
  6216. echo json_encode ( array (
  6217. 'status' => 2,
  6218. 'msg' => 'illegal request'
  6219. ) );
  6220. die ();
  6221. }
  6222. Doo::loadModel ( 'invoiceReceivables' );
  6223. $invoiceReceivables = new invoiceReceivables ();
  6224. Doo::loadModel ( 'invoice' );
  6225. $invoice = new invoice ();
  6226. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid ); // 入账完成 待定 and postStatus=1
  6227. $flag = true;
  6228. $invoiceDetail = $invoice->getInvoiceByTitle ( $detail ['recepitTitleMark'], 'EXACTLY', " and status=2 and printStatus=1 and untreadStatus=0 ", $flag ); //
  6229. $bakDetail = array ();
  6230. if ($flag === false) {
  6231. array_push ( $bakDetail, $invoiceDetail );
  6232. $invoiceDetail = $bakDetail;
  6233. }
  6234. $receivablesHtml = '<table class="table table-bordered table-condensed"><tbody><tr><th class="taC" width="70">收款金额</th><th class="taC">银行到账信息</th><th class="taC">银行/到账时间</th><th class="taC">收款认领</th><th class="taC">开票单位</th></tr>
  6235. <tr>
  6236. <td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  6237. <td>' . $detail ['receivablesMessage'] . '</td>
  6238. <td>' . $detail ['receivablesBank'] . '<br>' . $detail ['receivablesDate'] . '</td>
  6239. <td>' . $detail ['title'] . '-' . $detail ['username'] . '<br>' . $detail ['confirmTime'] . '</td>
  6240. <td>' . $detail ['recepitTitleMark'] . '</td>
  6241. </tr></tbody></table>';
  6242. $isInvoice = false;
  6243. $invoiceHtml = '';
  6244. if (empty ( $invoiceDetail )) {
  6245. $isInvoice = true;
  6246. } else {
  6247. $invoiceHtml = '<table class="table table-bordered table-condensed">
  6248. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody>';
  6249. foreach ( $invoiceDetail as $key => $value ) {
  6250. $invoiceHtml .= '<tr>';
  6251. if (! empty ( $value ['invoiceType'] )) {
  6252. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  6253. } else {
  6254. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  6255. }
  6256. if (! empty ( $value ['invoiceType'] )) {
  6257. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  6258. } else {
  6259. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  6260. }
  6261. $invoiceHtml .= '
  6262. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  6263. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  6264. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir" data-ikey="' . $value ['iidKey'] . '" href="javascript:void(0)">入账</a></td>
  6265. </tr>
  6266. ';
  6267. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  6268. if (empty ( $irList ))
  6269. $irList [0] ['sumPrice'] = 0;
  6270. $balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  6271. $priceString = '';
  6272. if ($balance < $detail ['receivablesPrice']) {
  6273. $priceString = '收款金额超过开票金额,';
  6274. }
  6275. if ($balance > $detail ['receivablesPrice']) {
  6276. $priceString = '收款金额低于开票金额,';
  6277. }
  6278. }
  6279. $invoiceHtml .= '
  6280. <script>
  6281. $(\'a[bind-receivables^="ir"]\').click(function() {
  6282. var data = $(this).attr("data-ikey");
  6283. $("input[name=\'invoiceKey\']").val(data);
  6284. var invoiceKey=data;
  6285. if(invoiceKey==""){
  6286. alert("入账错误,请重新刷新页面");
  6287. return false;
  6288. }
  6289. if(window.confirm("' . $priceString . '确定入账吗?")){
  6290. $("#IBR").submit();
  6291. }else{
  6292. return false;
  6293. }
  6294. });
  6295. </script>
  6296. ';
  6297. $invoiceHtml .= '</tbody></table>';
  6298. }
  6299. echo json_encode ( array (
  6300. 'status' => 1,
  6301. 'irkey' => $detail ['iridEn'],
  6302. 'receivablesHtml' => $receivablesHtml,
  6303. 'isInvoice' => $isInvoice,
  6304. 'invoiceHtml' => $invoiceHtml
  6305. ) );
  6306. }
  6307. function ajaxGetInvoiceReceivablesByTitle() {
  6308. $title = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  6309. if (empty ( $title )) {
  6310. echo json_encode ( array (
  6311. 'status' => 2,
  6312. 'msg' => 'illegal request'
  6313. ) );
  6314. die ();
  6315. }
  6316. Doo::loadModel ( 'invoice' );
  6317. $invoice = new invoice ();
  6318. $invoiceDetail = $invoice->getInvoiceByTitle ( $title, 'FUZZY', " and status=2 and printStatus=1 and untreadStatus=0 and irid='' ", true );
  6319. $invoiceHtml = '';
  6320. if (! empty ( $invoiceDetail )) {
  6321. $invoiceHtml = '<table class="table table-bordered table-condensed">
  6322. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody><tr>';
  6323. foreach ( $invoiceDetail as $key => $value ) {
  6324. if (! empty ( $value ['invoiceType'] )) {
  6325. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  6326. } else {
  6327. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  6328. }
  6329. if (! empty ( $value ['invoiceType'] )) {
  6330. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  6331. } else {
  6332. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  6333. }
  6334. $invoiceHtml .= '
  6335. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  6336. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  6337. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir' . $value ['iidKeyXD'] . '" data-ikey="' . $value ['iidKey'] . '" href="#">入账</a></td>
  6338. </tr>
  6339. ';
  6340. }
  6341. $invoiceHtml .= '</tbody></table>
  6342. <script>
  6343. $(\'a[bind-receivables^="ir"]\').click(function() {
  6344. var data = $(this).attr("data-ikey");
  6345. $("input[name=\'invoiceKey\']").val(data);
  6346. var invoiceKey=$("input[name=\'invoiceKey\']").val();
  6347. if(invoiceKey==""){
  6348. alert("入账错误,请重新刷新页面");
  6349. return false;
  6350. }
  6351. if(window.confirm("确定入账吗?")){
  6352. $("#IBR").submit();
  6353. }else{
  6354. return false;
  6355. }
  6356. });
  6357. </script>
  6358. ';
  6359. }
  6360. echo json_encode ( array (
  6361. 'status' => 1,
  6362. 'invoiceHtml' => $invoiceHtml
  6363. ) );
  6364. }
  6365. function ajaxInvoicePushNotice() {
  6366. Doo::loadModel ( 'invoice' );
  6367. $invoice = new invoice ();
  6368. $approval = $invoice->getOne ( array (
  6369. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  6370. 'desc' => 'iid',
  6371. 'asArray' => true
  6372. ) );
  6373. $isNotice = false;
  6374. if (! empty ( $approval ))
  6375. $isNotice = true;
  6376. $response = array (
  6377. 'error' => 0,
  6378. 'isNotice' => $isNotice
  6379. );
  6380. echo json_encode ( $response );
  6381. exit ();
  6382. }
  6383. public function ajaxCheckInvoiceNoUniqueness() {
  6384. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  6385. Doo::loadModel ( 'invoice' );
  6386. $invoice = new invoice ();
  6387. if (! empty ( $invoiceNo )) {
  6388. Doo::loadModel ( 'invoicePaper' );
  6389. $invoicePaper = new invoicePaper ();
  6390. Doo::loadClass ( 'XDeode' );
  6391. $XDeode = new XDeode ( 5 );
  6392. $ipid = $XDeode->decode ( $invoiceNo );
  6393. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  6394. $info = $invoice->getOne ( array (
  6395. 'where' => "invoiceNo = '" . $paperDetail ['invoiceNo'] . "'",
  6396. 'asArray' => TRUE
  6397. ) );
  6398. if (! empty ( $info )) {
  6399. echo json_encode ( array (
  6400. 'error' => '发票号已存在'
  6401. ) );
  6402. die ();
  6403. } else
  6404. echo json_encode ( array (
  6405. 'ok' => '可以使用!'
  6406. ) );
  6407. die ();
  6408. }
  6409. }
  6410. function ajaxCheckInvoicePrice() {
  6411. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) && is_numeric ( $this->get_args ( 'receivablesPrice' ) ) ? $this->get_args ( 'receivablesPrice' ) : "";
  6412. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  6413. Doo::loadModel ( 'invoice' );
  6414. $invoice = new invoice ();
  6415. Doo::loadModel ( 'invoiceReceivables' );
  6416. $invoiceReceivables = new invoiceReceivables ();
  6417. Doo::loadClass ( 'XDeode' );
  6418. $XDeode = new XDeode ( 5 );
  6419. if (! empty ( $receivablesPrice ) && ! empty ( $iidKey )) {
  6420. $iidKey = $XDeode->decode ( $iidKey );
  6421. $info = $invoice->getInvoiceByIid ( $iidKey );
  6422. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $info ['irid'] );
  6423. if (empty ( $irList ))
  6424. $irList [0] ['sumPrice'] = 0;
  6425. $balance = $info ['invoicePrice'] - $irList [0] ['sumPrice'];
  6426. if ($balance < $receivablesPrice) {
  6427. echo json_encode ( array (
  6428. 'error' => '收款金额超过开票金额。'
  6429. ) );
  6430. die ();
  6431. }
  6432. if ($balance > $receivablesPrice) {
  6433. echo json_encode ( array (
  6434. 'error' => '收款金额低于开票金额。'
  6435. ) );
  6436. die ();
  6437. }
  6438. }
  6439. }
  6440. function ajaxGetInvoiceByNew() {
  6441. Doo::loadModel ( 'invoice' );
  6442. $invoice = new invoice ();
  6443. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );
  6444. echo json_encode ( array (
  6445. 'status' => 1,
  6446. 'detail' => $detail
  6447. ) );
  6448. }
  6449. /**
  6450. * 旧输入导入
  6451. */
  6452. function importInvoice() {
  6453. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  6454. $data ['emsg'] = "";
  6455. if ($emsg != "")
  6456. $data ['emsg'] = "请填写完整的数据";
  6457. $data ['time'] = time ();
  6458. $this->render ( "/admin/invoiceImport", $data );
  6459. }
  6460. function uploadInvoice() {
  6461. // move_uploaded_file($_FILES['Filedata']['tmp_name'], "/upload/".$_FILES['Filedata']['name']);
  6462. if (isset ( $_FILES ['Filedata'] ['name'] )) {
  6463. $file = $_FILES ['Filedata'] ['tmp_name'];
  6464. $error = false;
  6465. if (! is_uploaded_file ( $file )) {
  6466. $error = '400 Bad Request';
  6467. }
  6468. if ($error) {
  6469. header ( 'HTTP/1.0 ' . $error );
  6470. die ( 'Error ' . $error );
  6471. } else {
  6472. include (DOO::conf ()->SITE_PATH . 'protected/plugin/io.han.php');
  6473. $this->IoHandler = new IoHandler ();
  6474. $pics = explode ( '.', $_FILES ['Filedata'] ['name'] );
  6475. // $filedir=$_POST['time'];
  6476. // 调用定义物理路径
  6477. $t = DOO::conf ()->SITE_PATH . "upload/invoice/";
  6478. $this->IoHandler->MakeDir ( $t );
  6479. $filename = $this->_GetFileEXT ( $_FILES ['Filedata'] ['name'] );
  6480. if ($filename != 'xlsx')
  6481. return "";
  6482. // $upload_dir = $t."/".time().rand(10,100).".".$filename;
  6483. $upload_file = iconv ( "UTF-8", "GB2312", $_FILES ["Filedata"] ["name"] );
  6484. $upload_dir = $t . "/" . $upload_file;
  6485. $k = move_uploaded_file ( $file, $upload_dir );
  6486. if ($k) {
  6487. $m = round ( $_FILES ['Filedata'] ['size'] / 1024 / 1024, 2 );
  6488. echo $pics [0] . "." . $filename . "#" . $m . "#" . $_FILES ['Filedata'] ['size'];
  6489. }
  6490. }
  6491. }
  6492. }
  6493. function importInvoiceDo() {
  6494. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  6495. if ($path != "") {
  6496. Doo::loadModel ( 'invoice' );
  6497. Doo::loadModel ( 'staff' );
  6498. $staff = new staff ();
  6499. Doo::loadModel ( 'invoiceStatistics' );
  6500. Doo::loadModel ( 'invoiceOperationLog' );
  6501. echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  6502. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . $path );
  6503. // print_r ( $exlArray );
  6504. // die ();
  6505. // echo json_encode($exlArray);die;
  6506. foreach ( $exlArray as $key => $value ) {
  6507. // 开票
  6508. $invoice = new invoice ();
  6509. $invoice->invoiceNo = $value ['invoiceNo'];
  6510. $invoice->invoiceType = 0;
  6511. if ($value ['invoiceType'] == '专')
  6512. $invoice->invoiceType = 1;
  6513. $invoice->invoicePrice = $value ['invoicePrice'];
  6514. $invoice->invoiceQuantity = 1;
  6515. $invoice->invoiceUnitPrice = $value ['invoicePrice'];
  6516. $invoice->invoiceTitle = $value ['invoiceTitle'];
  6517. if ($value ['invoiceType'] == '专')
  6518. $invoice->invoiceCompany = $value ['invoiceTitle'];
  6519. $invoice->userName = $value ['userName'];
  6520. $sDetail = $staff->getStaffByName ( $value ['userName'] );
  6521. $invoice->sid = $sDetail ['sid'];
  6522. $invoice->cid = $sDetail ['cid'];
  6523. $invoice->categoryName = $sDetail ['category'];
  6524. $invoice->invoiceElement = $value ['invoiceElement'];
  6525. $invoice->remark = $value ['remark'];
  6526. $invoice->date = $value ['date'];
  6527. $invoice->printTime = $value ['date'];
  6528. $invoice->ipSource = 1;
  6529. $invoice->printStatus = 1;
  6530. $invoice->status = 2;
  6531. $invoice->postStatus = 1;
  6532. $invoice->untreadStatus = 0;
  6533. $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  6534. $iid = $invoice->insert ();
  6535. // 汇总
  6536. $invoiceStatistics = new invoiceStatistics ();
  6537. //
  6538. $item = array (
  6539. 'date' => $value ['date'],
  6540. 'priceClass' => 1,
  6541. 'cid' => $sDetail ['cid'],
  6542. 'staff' => $sDetail ['sid'],
  6543. 'invoicePrice' => $value ['invoicePrice']
  6544. );
  6545. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  6546. $invoiceOperationLog = new invoiceOperationLog ();
  6547. $item = array (
  6548. 'date' => date ( "Y-m-d H:i:s" ),
  6549. 'operation' => date ( "Y-m-d" ) . " 导入",
  6550. 'status' => 1,
  6551. 'img' => $sDetail ['avatar'],
  6552. 'username' => $sDetail ['username'],
  6553. 'uid' => $sDetail ['sid'],
  6554. 'category' => $sDetail ['category'],
  6555. 'iid' => $iid
  6556. );
  6557. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  6558. }
  6559. return '/importInvoice?count=' . count ( $exlArray );
  6560. // return "/keyonline";
  6561. }
  6562. echo 'no file';
  6563. }
  6564. function importInvoiceReceivables() {
  6565. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  6566. $data ['emsg'] = "";
  6567. if ($emsg != "")
  6568. $data ['emsg'] = "请填写完整的数据";
  6569. $data ['time'] = time ();
  6570. $this->render ( "/admin/invoiceReceivablesImport", $data );
  6571. }
  6572. // 导入入账数据
  6573. function importInvoiceReceivablesDo() {
  6574. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  6575. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  6576. if ($path != "") {
  6577. Doo::loadModel ( 'invoiceReceivables' );
  6578. Doo::loadModel ( 'invoice' );
  6579. Doo::loadModel ( 'staff' );
  6580. $staff = new staff ();
  6581. Doo::loadModel ( 'invoiceStatistics' );
  6582. // echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  6583. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path ), 'invoiceReceivables' );
  6584. // print_r ( $exlArray );
  6585. // die ();
  6586. // echo json_encode($exlArray);die;
  6587. foreach ( $exlArray as $key => $value ) {
  6588. // 收款
  6589. $invoiceReceivables = new invoiceReceivables ();
  6590. $invoice = new invoice ();
  6591. $invoiceReceivables->bindStatus = 1;
  6592. $invoiceReceivables->receivablesPrice = $value ['receivablesPrice'];
  6593. $invoiceReceivables->receivablesMessage = $value ['receivablesMessage'];
  6594. $invoiceReceivables->receivablesBank = $value ['receivablesBank'];
  6595. $invoiceReceivables->receivablesDate = $value ['receivablesDate'];
  6596. $sDetail = $staff->getStaffByName ( $value ['receivablesStaff'] );
  6597. $invoiceReceivables->receivablesCategory = $sDetail ['cid'] . ':' . $sDetail ['category'];
  6598. $invoiceReceivables->receivablesStaff = $sDetail ['sid'] . '-' . $sDetail ['username'];
  6599. $invoiceReceivables->receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  6600. $invoiceReceivables->sourcePrice = $value ['sourcePrice'];
  6601. $iDetail = $invoice->getInvoiceByInvoiceNo ( $value ['invoiceNo'] );
  6602. $invoiceReceivables->iid = $iDetail ['iid'];
  6603. $irid = $invoiceReceivables->insert ();
  6604. // 发票绑定收款
  6605. $detail = $iDetail;
  6606. $iridString = "";
  6607. if (empty ( $detail ['irid'] ))
  6608. $iridString = $irid;
  6609. else
  6610. $iridString = $detail ['irid'] . ',' . $irid;
  6611. $item = array (
  6612. 'irid' => $iridString,
  6613. 'iid' => $detail ['iid']
  6614. );
  6615. $invoice->setInvoiceByCondition ( $item );
  6616. // 汇总
  6617. $invoiceStatistics = new invoiceStatistics ();
  6618. // 扣除入账统计金额
  6619. $item = array (
  6620. 'date' => $value ['receivablesDate'],
  6621. 'priceClass' => 3,
  6622. 'cid' => $sDetail ['cid'],
  6623. 'staff' => $sDetail ['sid'],
  6624. // 'irid' => $irid,
  6625. 'accountPrice' => $value ['receivablesPrice']
  6626. );
  6627. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  6628. }
  6629. return '/importInvoiceReceivables?count=' . count ( $exlArray );
  6630. echo 'data count ' . count ( $exlArray );
  6631. die ();
  6632. // return "/keyonline";
  6633. }
  6634. echo 'no file';
  6635. }
  6636. function formatExcelToArrayTrain($file_url = "") {
  6637. if (! file_exists ( $file_url )) {
  6638. return array ();
  6639. }
  6640. // Doo::loadClass ( 'PHPExcel' );
  6641. Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  6642. $PHPExcel = new PHPExcel ();
  6643. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  6644. if (! $PHPReader->canRead ( $file_url )) {
  6645. $PHPReader = new PHPExcel_Reader_Excel5 ();
  6646. if (! $PHPReader->canRead ( $file_url )) {
  6647. echo 'no Excel';
  6648. return;
  6649. }
  6650. }
  6651. $PHPExcel = $PHPReader->load ( $file_url );
  6652. /* * 读取excel文件中的第一个工作表 */
  6653. $currentSheet = $PHPExcel->getSheet ( 0 );
  6654. /* * 取得最大的列号 */
  6655. $allColumn = $currentSheet->getHighestColumn ();
  6656. /* * 取得一共有多少行 */
  6657. $allRow = $currentSheet->getHighestRow ();
  6658. $excel_array = array ();
  6659. // die($file_url);
  6660. $conk = 2;
  6661. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  6662. $excel_column = array ();
  6663. // 后期改进
  6664. if ($allColumn == 'AM')
  6665. $allColumn = 'Z';
  6666. /* * 从第A列开始输出 */
  6667. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  6668. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  6669. if ($val instanceof PHPExcel_RichText)
  6670. $val = $val->__toString ();
  6671. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  6672. // $val = "'" . addslashes ( $val ) . "'";
  6673. if ($currentColumn == 'A') {
  6674. $excel_column ['invoiceTitle'] = $val;
  6675. } elseif ($currentColumn == 'B')
  6676. $excel_column ['invoiceType'] = $val;
  6677. elseif ($currentColumn == 'C') {
  6678. $excel_column ['TIN'] = $val;
  6679. } elseif ($currentColumn == 'D') {
  6680. $excel_column ['address'] = $val;
  6681. } elseif ($currentColumn == 'E') {
  6682. $excel_column ['phone'] = $val;
  6683. } elseif ($currentColumn == 'F') {
  6684. $excel_column ['bank'] = $val;
  6685. } elseif ($currentColumn == 'G') {
  6686. $excel_column ['bankAccount'] = $val;
  6687. } elseif ($currentColumn == 'H') {
  6688. $excel_column ['invoiceElement'] = $val;
  6689. } elseif ($currentColumn == 'I') {
  6690. $excel_column ['invoiceQuantity'] = $val;
  6691. } elseif ($currentColumn == 'J') {
  6692. $excel_column ['invoiceUnitPrice'] = $val;
  6693. } elseif ($currentColumn == 'K') {
  6694. $excel_column ['remark'] = $val;
  6695. } elseif ($currentColumn == 'L') {
  6696. $excel_column ['recipientsAddress'] = $val;
  6697. } elseif ($currentColumn == 'M') {
  6698. $excel_column ['recipients'] = $val;
  6699. } elseif ($currentColumn == 'N') {
  6700. $excel_column ['recipientsPhone'] = $val;
  6701. }
  6702. }
  6703. if (! empty ( $excel_column ['invoiceTitle'] ) && ! empty ( $excel_column ['invoiceQuantity'] ) && ! empty ( $excel_column ['invoiceUnitPrice'] ))
  6704. array_push ( $excel_array, $excel_column );
  6705. }
  6706. return $excel_array;
  6707. }
  6708. /**
  6709. * 格式化excel文件为数组
  6710. * @param unknown_type $file_url
  6711. * @param unknown_type $mcid
  6712. */
  6713. function _format_excel_to_array($file_url = "", $sType = "") {
  6714. if (! file_exists ( $file_url )) {
  6715. return array ();
  6716. }
  6717. Doo::loadClass ( 'PHPExcel' );
  6718. // Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  6719. $PHPExcel = new PHPExcel ();
  6720. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  6721. if (! $PHPReader->canRead ( $file_url )) {
  6722. $PHPReader = new PHPExcel_Reader_Excel5 ();
  6723. if (! $PHPReader->canRead ( $file_url )) {
  6724. echo 'no Excel';
  6725. return;
  6726. }
  6727. }
  6728. $PHPExcel = $PHPReader->load ( $file_url );
  6729. /* * 读取excel文件中的第一个工作表 */
  6730. $currentSheet = $PHPExcel->getSheet ( 0 );
  6731. /* * 取得最大的列号 */
  6732. $allColumn = $currentSheet->getHighestColumn ();
  6733. /* * 取得一共有多少行 */
  6734. $allRow = $currentSheet->getHighestRow ();
  6735. $excel_array = array ();
  6736. // die($file_url);
  6737. $conk = 2;
  6738. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  6739. $excel_column = array ();
  6740. // 后期改进
  6741. if ($allColumn == 'AM')
  6742. $allColumn = 'Z';
  6743. /* * 从第A列开始输出 */
  6744. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  6745. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  6746. if ($val instanceof PHPExcel_RichText)
  6747. $val = $val->__toString ();
  6748. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  6749. // $val = "'" . addslashes ( $val ) . "'";
  6750. if ($sType == 'invoiceReceivables') {
  6751. if ($currentColumn == 'A')
  6752. $excel_column ['invoiceNo'] = $val;
  6753. elseif ($currentColumn == 'B')
  6754. $excel_column ['receivablesPrice'] = $val;
  6755. elseif ($currentColumn == 'C') {
  6756. $excel_column ['receivablesMessage'] = $val;
  6757. } elseif ($currentColumn == 'D') {
  6758. $excel_column ['receivablesBank'] = $val;
  6759. } elseif ($currentColumn == 'E') {
  6760. $excel_column ['receivablesDate'] = $this->excelTime ( $val );
  6761. } elseif ($currentColumn == 'F') {
  6762. $excel_column ['receivablesStaff'] = $val;
  6763. } elseif ($currentColumn == 'G') {
  6764. $excel_column ['sourcePrice'] = $val;
  6765. }
  6766. } elseif ($sType == "invoiceTrain") {
  6767. if ($currentColumn == 'A') {
  6768. $excel_column ['invoiceTitle'] = $val;
  6769. } elseif ($currentColumn == 'B')
  6770. $excel_column ['invoiceType'] = $val;
  6771. elseif ($currentColumn == 'C') {
  6772. $excel_column ['TIN'] = $val;
  6773. } elseif ($currentColumn == 'D') {
  6774. $excel_column ['address'] = $val;
  6775. } elseif ($currentColumn == 'E') {
  6776. $excel_column ['phone'] = $val;
  6777. } elseif ($currentColumn == 'F') {
  6778. $excel_column ['bank'] = $val;
  6779. } elseif ($currentColumn == 'G') {
  6780. $excel_column ['bankAccount'] = $val;
  6781. } elseif ($currentColumn == 'H') {
  6782. $excel_column ['invoiceElement'] = $val;
  6783. } elseif ($currentColumn == 'I') {
  6784. $excel_column ['invoiceQuantity'] = $val;
  6785. } elseif ($currentColumn == 'J') {
  6786. $excel_column ['invoiceUnitPrice'] = $val;
  6787. } elseif ($currentColumn == 'K') {
  6788. $excel_column ['remark'] = $val;
  6789. } elseif ($currentColumn == 'L') {
  6790. $excel_column ['recipientsAddress'] = $val;
  6791. } elseif ($currentColumn == 'M') {
  6792. $excel_column ['recipients'] = $val;
  6793. } elseif ($currentColumn == 'N') {
  6794. $excel_column ['recipientsPhone'] = $val;
  6795. }
  6796. } else {
  6797. if ($currentColumn == 'A')
  6798. $excel_column ['invoiceNo'] = $val;
  6799. elseif ($currentColumn == 'B')
  6800. $excel_column ['invoiceType'] = $val;
  6801. elseif ($currentColumn == 'C') {
  6802. $excel_column ['invoicePrice'] = $val;
  6803. } elseif ($currentColumn == 'D') {
  6804. $excel_column ['invoiceTitle'] = $val;
  6805. } elseif ($currentColumn == 'E') {
  6806. $excel_column ['userName'] = $val;
  6807. } elseif ($currentColumn == 'F') {
  6808. $excel_column ['categoryName'] = $val;
  6809. } elseif ($currentColumn == 'G') {
  6810. $excel_column ['invoiceElement'] = $val;
  6811. } elseif ($currentColumn == 'H') {
  6812. $excel_column ['remark'] = $val;
  6813. } elseif ($currentColumn == 'I') {
  6814. $excel_column ['date'] = $this->excelTime ( $val );
  6815. }
  6816. }
  6817. }
  6818. array_push ( $excel_array, $excel_column );
  6819. }
  6820. return $excel_array;
  6821. }
  6822. function excelTime($date, $time = false) {
  6823. if (function_exists ( 'GregorianToJD' )) {
  6824. if (is_numeric ( $date )) {
  6825. $jd = GregorianToJD ( 1, 1, 1970 );
  6826. $gregorian = JDToGregorian ( $jd + intval ( $date ) - 25569 );
  6827. $date = explode ( '/', $gregorian );
  6828. $date_str = str_pad ( $date [2], 4, '0', STR_PAD_LEFT ) . "-" . str_pad ( $date [0], 2, '0', STR_PAD_LEFT ) . "-" . str_pad ( $date [1], 2, '0', STR_PAD_LEFT ) . ($time ? " 00:00:00" : '');
  6829. return $date_str;
  6830. }
  6831. } else {
  6832. $date = $date > 25568 ? $date + 1 : 25569;
  6833. /* There was a bug if Converting date before 1-1-1970 (tstamp 0) */
  6834. $ofs = (70 * 365 + 17 + 2) * 86400;
  6835. $date = date ( "Y-m-d", ($date * 86400) - $ofs ) . ($time ? " 00:00:00" : '');
  6836. }
  6837. return $date;
  6838. }
  6839. /**
  6840. * 旧输入导入
  6841. */
  6842. function _GetFileEXT($filename) {
  6843. $pics = explode ( '.', $filename );
  6844. $num = count ( $pics );
  6845. return $pics [$num - 1];
  6846. }
  6847. function showCache($path = "", $sid = 0) {
  6848. // if (file_exists ( $path )) {
  6849. // $htm = file_get_contents ( $path );
  6850. // } else {
  6851. Doo::loadModel ( 'invoiceStatistics' );
  6852. $invoiceStatistics = new invoiceStatistics ();
  6853. $isBriefly = $invoiceStatistics->getBrieflyStatistics ( $sid );
  6854. $htm = '<tr><th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计开票</th>
  6855. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['invoicePrice'] . '</td>
  6856. <th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计入账</th>
  6857. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['accountPrice'] . '</td></tr>';
  6858. /*
  6859. * '<tr><th class="taC">今年累计开票</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['invoicePrice'] . '</td> <th class="taC">今年累计入账</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['accountPrice'] . '</td></tr>';
  6860. */
  6861. file_put_contents ( $path, $htm );
  6862. // }
  6863. return $htm;
  6864. }
  6865. /**
  6866. * 生成token
  6867. * @return string
  6868. */
  6869. function set_token() {
  6870. $str = md5 ( uniqid ( md5 ( microtime ( true ) ), true ) ); // 生成一个不会重复的字符串
  6871. $str = sha1 ( $str ); // 加密
  6872. return $str;
  6873. }
  6874. /**
  6875. * 获取get或者POST值
  6876. *
  6877. * @param string $name 属性名称
  6878. * @return fixed 值
  6879. */
  6880. function get_args($name) {
  6881. if (isset ( $_GET [$name] )) {
  6882. if (is_array ( $_GET [$name] ))
  6883. return $_GET [$name];
  6884. else
  6885. return addslashes ( $_GET [$name] );
  6886. } elseif (isset ( $_POST [$name] )) {
  6887. if (is_array ( $_POST [$name] ))
  6888. return $_POST [$name];
  6889. else
  6890. return addslashes ( $_POST [$name] );
  6891. } else
  6892. return false;
  6893. }
  6894. function SafeFilter(&$arr) {
  6895. $ra = Array (
  6896. '/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/',
  6897. '/script/',
  6898. '/javascript/',
  6899. '/vbscript/',
  6900. '/expression/',
  6901. '/applet/',
  6902. '/meta/',
  6903. '/xml/',
  6904. '/blink/',
  6905. '/link/',
  6906. '/style/',
  6907. '/embed/',
  6908. '/object/',
  6909. '/frame/',
  6910. '/layer/',
  6911. '/title/',
  6912. '/bgsound/',
  6913. '/base/',
  6914. '/onload/',
  6915. '/onunload/',
  6916. '/onchange/',
  6917. '/onsubmit/',
  6918. '/onreset/',
  6919. '/onselect/',
  6920. '/onblur/',
  6921. '/onfocus/',
  6922. '/onabort/',
  6923. '/onkeydown/',
  6924. '/onkeypress/',
  6925. '/onkeyup/',
  6926. '/onclick/',
  6927. '/ondblclick/',
  6928. '/onmousedown/',
  6929. '/onmousemove/',
  6930. '/onmouseout/',
  6931. '/onmouseover/',
  6932. '/onmouseup/',
  6933. '/onunload/'
  6934. );
  6935. if (is_array ( $arr )) {
  6936. foreach ( $arr as $key => $value ) {
  6937. if (! is_array ( $value )) {
  6938. if (! get_magic_quotes_gpc ()) // 不对magic_quotes_gpc转义过的字符使用addslashes(),避免双重转义。
  6939. {
  6940. $value = addslashes ( $value ); // 给单引号(')、双引号(")、反斜线(\)与 NUL(NULL 字符)加上反斜线转义
  6941. }
  6942. $value = preg_replace ( $ra, '', $value ); // 删除非打印字符,粗暴式过滤xss可疑字符串
  6943. $arr [$key] = htmlentities ( strip_tags ( $value ) ); // 去除 HTML 和 PHP 标记并转换为 HTML 实体
  6944. } else {
  6945. SafeFilter ( $arr [$key] );
  6946. }
  6947. }
  6948. }
  6949. }
  6950. /**
  6951. * Escape String
  6952. *
  6953. * @access public
  6954. * @param string
  6955. * @param bool whether or not the string will be used in a LIKE condition
  6956. * @return string
  6957. */
  6958. function escape_str($str, $like = FALSE) {
  6959. if (is_array ( $str )) {
  6960. foreach ( $str as $key => $val ) {
  6961. $str [$key] = $this->escape_str ( $val, $like );
  6962. }
  6963. return $str;
  6964. }
  6965. var_dump ( Doo::db ()->getDbObject () );
  6966. die ();
  6967. if (function_exists ( 'mysql_real_escape_string' ) and is_resource ( Doo::db ()->getDbObject () )) { // Doo::db ()->getDbObject()
  6968. $str = mysql_real_escape_string ( $str, Doo::db ()->getDbObject () );
  6969. } elseif (function_exists ( 'mysql_escape_string' )) {
  6970. $str = mysql_escape_string ( $str );
  6971. } else {
  6972. $str = addslashes ( $str );
  6973. }
  6974. // escape LIKE condition wildcards
  6975. if ($like === TRUE) {
  6976. $str = str_replace ( array (
  6977. '%',
  6978. '_'
  6979. ), array (
  6980. '\\%',
  6981. '\\_'
  6982. ), $str );
  6983. }
  6984. return $str;
  6985. }
  6986. /**
  6987. * 获得分页数据
  6988. * @param unknown_type $table
  6989. * @param unknown_type $condition
  6990. * @param unknown_type $on_page
  6991. * @param unknown_type $page_size
  6992. */
  6993. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  6994. $page_c = "";
  6995. $page ['previous'] = $this->get_previous ( $on_page );
  6996. $page ['on_page'] = $on_page;
  6997. $total_count = $this->get_table_count ( $table, $condition );
  6998. $total = intval ( $total_count / $page_size );
  6999. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  7000. $page ['total_data'] = $total_count;
  7001. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  7002. $i = 1;
  7003. $page_max = 1;
  7004. $page_width = 3;
  7005. if ($on_page >= $page_width) {
  7006. $page_max = intval ( $on_page / $page_width ) + 1;
  7007. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  7008. }
  7009. for(; $i <= $page ['total_page']; $i ++) {
  7010. if ($i == $on_page)
  7011. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  7012. else
  7013. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  7014. if ($i == ($page_width * $page_max))
  7015. break;
  7016. }
  7017. $page ['page'] = $page_c;
  7018. $page ['lower'] = (-- $on_page) * $page_size;
  7019. return $page;
  7020. }
  7021. /**
  7022. * 获取上一页
  7023. * @param unknown_type $on_page
  7024. */
  7025. function get_previous($on_page = 1) {
  7026. return $on_page != 0 ? $on_page - 1 : $on_page;
  7027. }
  7028. /**
  7029. * 获取总页数
  7030. * @param unknown_type $table
  7031. * @param unknown_type $condition
  7032. */
  7033. public function get_table_count($table = "", $condition = "") {
  7034. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  7035. $sql = "select count(*) as count from " . $table . " where " . $condition;
  7036. // echo $sql;die;
  7037. $query = Doo::db ()->query ( $sql );
  7038. $result = $query->fetch ();
  7039. return $result ['count'];
  7040. }
  7041. /**
  7042. * 获得分页数据
  7043. * @param unknown_type $table
  7044. * @param unknown_type $condition
  7045. * @param unknown_type $on_page
  7046. * @param unknown_type $page_size
  7047. */
  7048. function getPageBySql($sql = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  7049. $page_c = "";
  7050. $page ['previous'] = $this->get_previous ( $on_page );
  7051. $page ['on_page'] = $on_page;
  7052. $total_count = $this->getTableCountBySql ( $sql );
  7053. $total = intval ( $total_count / $page_size );
  7054. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  7055. $page ['total_data'] = $total_count;
  7056. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  7057. $i = 1;
  7058. $page_max = 1;
  7059. $page_width = 3;
  7060. if ($on_page >= $page_width) {
  7061. $page_max = intval ( $on_page / $page_width ) + 1;
  7062. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  7063. }
  7064. for(; $i <= $page ['total_page']; $i ++) {
  7065. if ($i == $on_page)
  7066. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  7067. else
  7068. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  7069. if ($i == ($page_width * $page_max))
  7070. break;
  7071. }
  7072. $page ['page'] = $page_c;
  7073. $page ['lower'] = (-- $on_page) * $page_size;
  7074. return $page;
  7075. }
  7076. /**
  7077. * 获得总页数 sql
  7078. * @param string $type
  7079. * @return boolean[]
  7080. */
  7081. public function getTableCountBySql($sql = "") {
  7082. echo $sql;
  7083. $query = Doo::db ()->query ( $sql );
  7084. $result = $query->fetchAll ();
  7085. return count ( $result );
  7086. }
  7087. function isInvoiceNew($type = "GLOBAL") {
  7088. Doo::loadModel ( 'invoice' );
  7089. $invoice = new invoice ();
  7090. Doo::loadModel ( 'invoiceReceivables' );
  7091. $invoiceReceivables = new invoiceReceivables ();
  7092. Doo::loadModel ( 'staff' );
  7093. $staff = new staff ();
  7094. $st = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  7095. // 我的发票待处理
  7096. $pendingInvoice = $invoice->getOne ( array ( // or (status=2 and printStatus=1 and untreadStatus=0 ) or (status=2 and printStatus=1 and untreadStatus=2 )
  7097. 'where' => "(status=3 or status=4) and isDelete=0 and sid=" . $st [0] ['sid'],
  7098. 'desc' => 'iid',
  7099. 'asArray' => TRUE
  7100. ) );
  7101. // 我的收款待入账
  7102. /*
  7103. * $myClaim = $invoiceReceivables->getOne ( array ( 'where' => " receivablesStaff like '" . $st [0] ['sid'] . "-%' and receivablesCategory like '" . $st [0] ['cid'] . ":%' and bindStatus=0", 'desc' => 'irid', 'asArray' => TRUE ) );
  7104. */
  7105. // 发票审批
  7106. $approval = $invoice->getOne ( array (
  7107. 'where' => 'status=1 and pendingApprovals=' . $st [0] ['sid'],
  7108. 'desc' => 'iid',
  7109. 'asArray' => true
  7110. ) );
  7111. // 发票邮寄
  7112. $post = $invoice->getOne ( array (
  7113. 'where' => "postStatus=0 and printStatus=1 and isDelete=0 and doPost=1 and status=2",
  7114. 'asArray' => TRUE
  7115. ) );
  7116. // 发票打印
  7117. $print = $invoice->getOne ( array (
  7118. 'where' => "status=2 and printStatus=0 and untreadStatus=0 and moldManage like '%[\"" . $st [0] ['sid'] . "\",%'",
  7119. 'desc' => 'iid',
  7120. 'asArray' => TRUE
  7121. ) );
  7122. // 发票退票 printStatus=1 and
  7123. $untread = $invoice->getOne ( array (
  7124. 'where' => " untreadStatus=1 and status=2 ",
  7125. 'asArray' => TRUE
  7126. ) );
  7127. $new = array (
  7128. 'GLOBAL' => FALSE,
  7129. 'pendingInvoice' => FALSE,
  7130. // 'myClaim' => FALSE,
  7131. 'approval' => FALSE,
  7132. 'post' => FALSE,
  7133. 'print' => FALSE,
  7134. 'untread' => FALSE
  7135. );
  7136. // || ! empty ( $myClaim )
  7137. if (! empty ( $pendingInvoice ) || ! empty ( $approval ) || ! empty ( $post ) || ! empty ( $print ) || ! empty ( $untread ))
  7138. $new ['GLOBAL'] = TRUE;
  7139. if (! empty ( $pendingInvoice ))
  7140. $new ['pendingInvoice'] = TRUE;
  7141. // if (! empty ( $myClaim ))
  7142. // $new ['myClaim'] = TRUE;
  7143. if (! empty ( $approval ))
  7144. $new ['approval'] = TRUE;
  7145. if (! empty ( $post ))
  7146. $new ['post'] = TRUE;
  7147. if (! empty ( $print ))
  7148. $new ['print'] = TRUE;
  7149. if (! empty ( $untread ))
  7150. $new ['untread'] = TRUE;
  7151. return $new;
  7152. }
  7153. function setWXMsg($rid, $typeMsg = '') {
  7154. Doo::loadModel ( 'invoice' );
  7155. $invoice = new invoice ();
  7156. $invoiceDetail = $invoice->getOne ( array (
  7157. 'where' => 'iid=' . $rid,
  7158. 'asArray' => true
  7159. ) );
  7160. if (! empty ( $invoiceDetail )) {
  7161. Doo::loadModel ( 'staff' );
  7162. $staff = new staff ();
  7163. $staffmsg = $staff->getOne ( array (
  7164. 'where' => "sid='" . $invoiceDetail ['sid'] . "'",
  7165. 'asArray' => TRUE
  7166. ) );
  7167. if (! empty ( $staffmsg ['wxid'] )) {
  7168. require_once (SITE_PATH . '/protected/class/client.php');
  7169. $client = new client ( 'http://m.cld.smartcost.com.cn/' );
  7170. $user = $staffmsg ['wxid'];
  7171. $expCom = explode ( ":", $invoiceDetail ['expressCompany'] );
  7172. if (empty ( $expCom ))
  7173. $expCom [0] = '';
  7174. $msg = "";
  7175. if (empty ( $typeMsg ))
  7176. $msg = '太好了,您的发票' . $invoiceDetail ['invoiceSerial'] . ' 已邮寄 ' . $expCom [0] . ' ,快递号: <a href="https://m.kuaidi100.com/result.jsp?nu=' . $invoiceDetail ['expressNumber'] . '" >' . $invoiceDetail ['expressNumber'] . '</a>';
  7177. elseif ($typeMsg == "PRINT")
  7178. $msg = '太好了,您的发票已打印完成。';
  7179. $result = $client->SendMsg ( $user, $msg, 'text' );
  7180. }
  7181. }
  7182. }
  7183. /**
  7184. * 获取微信部门
  7185. * @param string $category
  7186. * @return number|mixed
  7187. */
  7188. function getToparty($category = '') {
  7189. $token = $this->getAccessToken (); //
  7190. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token={$token}&id=5" ), true );
  7191. $toparty = 0;
  7192. foreach ( $result ['department'] as $key => $value ) {
  7193. if ($value ['name'] == $category)
  7194. $toparty = $value ['id'];
  7195. }
  7196. return $toparty;
  7197. }
  7198. /**
  7199. * 获得某部门下的用户
  7200. * @param string $toparty
  7201. */
  7202. function getUserByToparty($toparty = '') {
  7203. $token = $this->getAccessToken (); //
  7204. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token={$token}&department_id={$toparty}" ), true );
  7205. $userList = array ();
  7206. foreach ( $result ['userlist'] as $key => $value ) {
  7207. array_push ( $userList, "'" . $value ['userid'] . "'" );
  7208. }
  7209. return $userList;
  7210. }
  7211. function msgSendToparty($msg, $title, $url, $toparty, $text = '') {
  7212. $token = $this->getAccessToken ();
  7213. if ($text == 'text') {
  7214. $data = '{
  7215. "touser": "' . $toparty . '",
  7216. "toparty": "",
  7217. "totag": "",
  7218. "msgtype": "text",
  7219. "agentid": 1000002,
  7220. "text": {
  7221. "content": "' . $msg . '"
  7222. },
  7223. "safe":0
  7224. }';
  7225. }
  7226. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  7227. if ($result->errmsg != 'ok') {
  7228. return 0;
  7229. } else {
  7230. return 1;
  7231. }
  7232. }
  7233. /**
  7234. * 获得可以发送微信用户列表
  7235. * @param string $category
  7236. * @return string
  7237. */
  7238. function getWxidByCategory($category = "") {
  7239. if (empty ( $category ))
  7240. return "";
  7241. Doo::loadModel ( 'staff' );
  7242. $staff = new staff ();
  7243. $toparty = $this->getToparty ( $category );
  7244. $wxList = array ();
  7245. $wxString = "";
  7246. if (! empty ( $toparty )) {
  7247. $userList = $this->getUserByToparty ( $toparty );
  7248. $userCon = implode ( ',', $userList );
  7249. // echo $userCon;
  7250. $sidList = $staff->getStaffByWxid ( $userCon );
  7251. foreach ( $sidList as $key => $value ) {
  7252. $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  7253. if ($falg) {
  7254. array_push ( $wxList, $value ['wxid'] );
  7255. }
  7256. }
  7257. $wxString = implode ( '|', $wxList );
  7258. }
  7259. return $wxString;
  7260. }
  7261. /**
  7262. * 读取发送信息规则判断是否需要发送
  7263. * @param number $sid
  7264. * @param string $sendType
  7265. * @return boolean
  7266. */
  7267. function isSendNotification($sid = 0, $sendType = '') {
  7268. Doo::loadModel ( "notificationConf" );
  7269. $notificationConf = new notificationConf ();
  7270. $detail = $notificationConf->getNotificationConfBySid ( $sid );
  7271. $conf = array ();
  7272. $sendFlag = true;
  7273. if (! empty ( $detail )) {
  7274. $conf = json_decode ( $detail ['conf'], true );
  7275. if (! empty ( $sendType )) {
  7276. if (isset ( $conf [$sendType] )) {
  7277. if ($conf [$sendType] == "CLOSE")
  7278. $sendFlag = false;
  7279. elseif ($conf [$sendType] == "Weekend") {
  7280. $day = date ( "w" );
  7281. if (1 <= $day && 5 >= $day)
  7282. $sendFlag = false;
  7283. } elseif ($conf [$sendType] == "OneToFriday") {
  7284. $day = date ( "w" );
  7285. if (0 == $day || 6 == $day)
  7286. $sendFlag = false;
  7287. }
  7288. }
  7289. } else
  7290. $sendFlag = false;
  7291. }
  7292. return $sendFlag;
  7293. }
  7294. /**
  7295. * 根据规则发送信息
  7296. * @param unknown $msg
  7297. * @param unknown $title
  7298. * @param unknown $url
  7299. * @param unknown $user
  7300. * @param string $text
  7301. * @return number
  7302. */
  7303. private function msgSend($msg, $title, $url, $user, $sid = 0, $sendType = '') {
  7304. $token = $this->getAccessToken ();
  7305. $falg = $this->isSendNotification ( $sid, $sendType );
  7306. // if ($text == 'text') {
  7307. // $data = '{
  7308. // "touser": "' . $user . '",
  7309. // "toparty": "",
  7310. // "totag": "",
  7311. // "msgtype": "text",
  7312. // "agentid": 1000002,
  7313. // "text": {
  7314. // "content": "' . $msg . '"
  7315. // },
  7316. // "safe":0
  7317. // }';
  7318. // } else {
  7319. $data = '{
  7320. "touser": "' . $user . '",
  7321. "toparty": "",
  7322. "totag": "",
  7323. "msgtype": "news",
  7324. "agentid": 1000002,
  7325. "news": {
  7326. "articles":[
  7327. {
  7328. "title": "' . $title . '",
  7329. "description": "' . $msg . '",
  7330. "url": "' . $url . '",
  7331. "picurl": ""
  7332. }
  7333. ]
  7334. }
  7335. }';
  7336. // }
  7337. if ($falg) {
  7338. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  7339. if ($result->errmsg != 'ok') {
  7340. return 0;
  7341. } else {
  7342. return 1;
  7343. }
  7344. } else
  7345. return 0;
  7346. }
  7347. private function getAccessToken() {
  7348. // access_token 应该全局存储与更新,以下代码以写入到文件中做示例
  7349. // $file = './access_token.txt';
  7350. // $data = json_decode ( file_get_contents ( $file ) );
  7351. // if ($data->expire_time < time () or ! $data->expire_time) {
  7352. // 如果是企业号用以下URL获取access_token
  7353. $url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$this->appId&corpsecret=$this->appSecret";
  7354. // $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$this->appId&secret=$this->appSecret";
  7355. $res = json_decode ( $this->httpGet ( $url ) );
  7356. $access_token = $res->access_token;
  7357. // echo $access_token;
  7358. // if ($access_token) {
  7359. // $data->expire_time = time () + 7000;
  7360. // $data->access_token = $access_token;
  7361. // $fp = fopen ( $file, "w" );
  7362. // fwrite ( $fp, json_encode ( $data ) );
  7363. // fclose ( $fp );
  7364. // }
  7365. // } else {
  7366. // $access_token = $data->access_token;
  7367. // }
  7368. return $access_token;
  7369. }
  7370. private function httpGet($url) {
  7371. $curl = curl_init ();
  7372. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  7373. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  7374. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  7375. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  7376. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  7377. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  7378. curl_setopt ( $curl, CURLOPT_URL, $url );
  7379. $res = curl_exec ( $curl );
  7380. curl_close ( $curl );
  7381. return $res;
  7382. }
  7383. private function httpPost($url, $data) {
  7384. $curl = curl_init ();
  7385. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  7386. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  7387. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  7388. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  7389. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  7390. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  7391. curl_setopt ( $curl, CURLOPT_URL, $url );
  7392. curl_setopt ( $curl, CURLOPT_POST, 1 );
  7393. curl_setopt ( $curl, CURLOPT_POSTFIELDS, $data );
  7394. $res = curl_exec ( $curl );
  7395. curl_close ( $curl );
  7396. return $res;
  7397. }
  7398. }
  7399. ?>