InvoiceController.php 294 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049
  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' );
  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. // print_r($myInvoiceUnAccount);
  203. $this->data ['isMonth'] = $isMonth;
  204. $this->data ['htm'] = $htm;
  205. $this->data ['invoiceList'] = $invoiceList;
  206. $this->data ['receivablesList'] = $list;
  207. $this->data ['myInvoiceUnAccount'] = $myInvoiceUnAccount;
  208. $this->data ['memu'] = "invoice";
  209. $this->data ['staff'] = $this->staff;
  210. $this->data ['receiptMemu'] = 'invoice';
  211. $this->render ( "/admin/invoice", $this->data );
  212. }
  213. function invoiceExpress() {
  214. $expressCom = isset ( $this->params ['expressCom'] ) ? $this->params ['expressCom'] : "";
  215. $expressNumber = isset ( $this->params ['expressNumber'] ) ? $this->params ['expressNumber'] : "";
  216. $this->data ['expressCom'] = $expressCom;
  217. $this->data ['expressNumber'] = $expressNumber;
  218. $this->render ( "/admin/invoiceExpress", $this->data );
  219. }
  220. function invoiceAdd() {
  221. Doo::loadModel ( 'L_category' );
  222. $lCategory = new L_category ();
  223. $category = $lCategory->find ( array (
  224. 'asArray' => true
  225. ) );
  226. $this->data ['category'] = $category;
  227. $this->data ['memu'] = "invoice";
  228. $this->data ['staff'] = $this->staff;
  229. $this->data ['receiptMemu'] = 'invoice';
  230. $this->render ( "/admin/invoiceAdd", $this->data );
  231. }
  232. /**
  233. * 提交一份开票申请,并记录下操作日志
  234. *
  235. * @since 1.0.0
  236. * @var integer cid 办事处ID
  237. * @var integer invoiceType 发票类型
  238. * @var integer doPost 是否邮寄
  239. * @var integer invoicePrice 开票金额
  240. * @var string invoiceElement 开票内容
  241. * @var string invoiceTitle 发票抬头
  242. * @var string invoiceCompany 单位名称
  243. * @var string TIN 纳税人识别码
  244. * @var string address 注册地址
  245. * @var string phone 注册电话
  246. * @var string bank 开户银行
  247. * @var string bankAccount 银行账户
  248. * @var string recipients 收件人
  249. * @var string recipientsPhone 收件人手机/电话
  250. * @var string recipientsAddress 收件地址
  251. * @var string mailItems 邮寄物品
  252. * @var string remark 备注
  253. * @return string 返回跳转开票主页路径
  254. */
  255. function invoiceAddDo() {
  256. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  257. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  258. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  259. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  260. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  261. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  262. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  263. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  264. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  265. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  266. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  267. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  268. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  269. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  270. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  271. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  272. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  273. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  274. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  275. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  276. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  277. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  278. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  279. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  280. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  281. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  282. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  283. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  284. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  285. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  286. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  287. /*
  288. * $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;
  289. */
  290. if (empty ( $this->staff [0] ))
  291. die ( 'illegal request' );
  292. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement )) {
  293. Doo::loadModel ( 'invoice' );
  294. $invoice = new invoice ();
  295. Doo::loadModel ( 'L_category' );
  296. $lCategory = new L_category ();
  297. Doo::loadModel ( 'invoiceManage' );
  298. $invoiceManage = new invoiceManage ();
  299. Doo::loadModel ( 'invoiceOperationLog' );
  300. $invoiceOperationLog = new invoiceOperationLog ();
  301. $categoryDetil = $lCategory->getOne ( array (
  302. 'SELECT' => 'title',
  303. 'where' => 'cid=' . $cid,
  304. 'asArray' => true
  305. ) );
  306. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  307. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  308. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  309. // print_r(current($invoiceManageDetail ['staffList']));
  310. // die;
  311. $moldManage = array ();
  312. foreach ( $invoiceManageList as $key => $value ) {
  313. if ($value ['mold'] == '发票打印')
  314. $moldManage [$value ['mold']] = $value ['staffList'];
  315. elseif ($value ['mold'] == '发票邮寄')
  316. $moldManage [$value ['mold']] = $value ['staffList'];
  317. elseif ($value ['mold'] == '发票退票')
  318. $moldManage [$value ['mold']] = $value ['staffList'];
  319. }
  320. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  321. $item = array (
  322. 'cid' => $cid,
  323. 'categoryName' => $categoryDetil ['title'],
  324. 'invoiceElement' => $invoiceElement,
  325. 'invoiceQuantity' => $invoiceQuantity,
  326. 'invoiceUnitPrice' => $invoiceUnitPrice,
  327. 'invoicePrice' => $invoicePrice,
  328. 'invoiceType' => $invoiceType,
  329. 'doPost' => $doPost,
  330. 'status' => 1,
  331. 'invoiceSerial' => "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  332. 'date' => date ( "Y-m-d H:i:s" ),
  333. 'updateTime' => date ( "Y-m-d H:i:s" ),
  334. 'sid' => $this->staff [0] ['sid'],
  335. 'userName' => $this->staff [0] ['username'],
  336. 'invoiceManage' => $invoiceManageDetail ['staff'],
  337. 'pendingApprovals' => $pendingApprovalsSid,
  338. 'moldManage' => json_encode ( $moldManage ),
  339. 'remark' => $remark
  340. );
  341. if ($invoiceType == 0)
  342. $item += array (
  343. 'invoiceTitle' => $invoiceTitle,
  344. 'TIN' => $TINT,
  345. 'address' => $addressT,
  346. 'phone' => $phoneT,
  347. 'bank' => $bankT,
  348. 'bankAccount' => $bankAccountT
  349. );
  350. else {
  351. $item += array (
  352. 'invoiceCompany' => $invoiceCompany,
  353. 'TIN' => $TIN,
  354. 'address' => $address,
  355. 'phone' => $phone,
  356. 'bank' => $bank,
  357. 'bankAccount' => $bankAccount
  358. );
  359. }
  360. if ($doPost == 1) {
  361. $mailList = array (
  362. 'invoice' => 1,
  363. 'mailItems' => $mailItems
  364. );
  365. if (! empty ( $softLock ))
  366. $mailList += array (
  367. 'softLock' => $softLockNum
  368. );
  369. else
  370. $mailList += array (
  371. 'softLock' => 0
  372. );
  373. if (! empty ( $contract ))
  374. $mailList += array (
  375. 'contract' => $contractNum
  376. );
  377. else
  378. $mailList += array (
  379. 'contract' => 0
  380. );
  381. if (! empty ( $instructions ))
  382. $mailList += array (
  383. 'instructions' => $instructionsNum
  384. );
  385. else
  386. $mailList += array (
  387. 'instructions' => 0
  388. );
  389. if (! empty ( $remittance ))
  390. $mailList += array (
  391. 'remittance' => $remittance
  392. );
  393. else
  394. $mailList += array (
  395. 'remittance' => ''
  396. );
  397. $mailString = '发票x1,备注:' . $mailItems;
  398. if (! empty ( $softLock ))
  399. $mailString .= ',软件锁x' . $softLockNum;
  400. if (! empty ( $contract ))
  401. $mailString .= ',合同x' . $contractNum;
  402. if (! empty ( $instructions ))
  403. $mailString .= ',说明书x' . $instructionsNum;
  404. if (! empty ( $remittance ))
  405. $mailString .= ',汇款账号单';
  406. $item += array (
  407. 'recipients' => $recipients,
  408. 'recipientsPhone' => $recipientsPhone,
  409. 'recipientsAddress' => $recipientsAddress,
  410. 'mailItems' => $mailString,
  411. 'mailItemsJson' => json_encode ( $mailList )
  412. );
  413. }
  414. $iid = $invoice->addInvoice ( $item );
  415. $item = array (
  416. 'date' => date ( "Y-m-d H:i:s" ),
  417. 'operation' => "创建",
  418. 'status' => 1,
  419. 'img' => $this->staff [0] ['avatar'],
  420. 'username' => $this->staff [0] ['username'],
  421. 'uid' => $this->staff [0] ['sid'],
  422. 'category' => $this->staff [0] ['category'],
  423. 'iid' => $iid
  424. );
  425. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  426. $item = array (
  427. 'date' => date ( "Y-m-d H:i:s" ),
  428. 'operation' => "提交审批",
  429. 'status' => 1,
  430. 'img' => $this->staff [0] ['avatar'],
  431. 'username' => $this->staff [0] ['username'],
  432. 'uid' => $this->staff [0] ['sid'],
  433. 'category' => $this->staff [0] ['category'],
  434. 'iid' => $iid
  435. );
  436. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  437. Doo::loadModel ( 'staff' );
  438. $staff = new staff ();
  439. $username2 = $staff->getOne ( array (
  440. 'select' => 'wxid',
  441. 'where' => 'sid=' . $pendingApprovalsSid,
  442. 'asArray' => TRUE
  443. ) );
  444. // 发送微信审批通知
  445. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  446. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  447. }
  448. return "/invoice";
  449. }
  450. function invoiceEdit() {
  451. Doo::loadClass ( 'XDeode' );
  452. $XDeode = new XDeode ( 5 );
  453. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  454. $iid = $XDeode->decode ( $iid );
  455. if (! is_numeric ( $iid ))
  456. die ( 'illegal request' );
  457. Doo::loadModel ( 'invoice' );
  458. $invoice = new invoice ();
  459. Doo::loadModel ( 'invoiceOperationLog' );
  460. $invoiceOperationLog = new invoiceOperationLog ();
  461. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  462. $operation = $invoiceOperationLog->getInvoiceOperationByDropped ( $iid );
  463. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  464. $this->data ['operation'] = $operation;
  465. $this->data ['invoiceDetail'] = $invoiceDetail;
  466. $this->data ['memu'] = "invoice";
  467. $this->data ['staff'] = $this->staff;
  468. $this->data ['receiptMemu'] = 'invoice';
  469. $this->render ( "/admin/invoiceEdit", $this->data );
  470. }
  471. /**
  472. * 重新编辑退回的发票
  473. * @return string
  474. */
  475. function invoiceEditDo() {
  476. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  477. Doo::loadModel ( 'invoice' );
  478. $invoice = new invoice ();
  479. $iid = $invoice->authcode ( $iidKey );
  480. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  481. die ( 'illegal request' );
  482. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  483. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  484. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  485. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  486. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  487. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  488. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  489. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  490. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  491. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  492. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  493. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  494. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  495. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  496. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  497. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  498. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  499. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  500. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  501. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  502. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  503. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  504. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  505. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  506. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  507. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  508. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  509. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  510. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  511. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  512. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  513. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  514. Doo::loadModel ( 'invoiceManage' );
  515. $invoiceManage = new invoiceManage ();
  516. Doo::loadModel ( 'invoiceOperationLog' );
  517. $invoiceOperationLog = new invoiceOperationLog ();
  518. $cid = explode ( ':', $cid );
  519. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  520. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  521. $moldManage = array ();
  522. foreach ( $invoiceManageList as $key => $value ) {
  523. if ($value ['mold'] == '发票打印')
  524. $moldManage [$value ['mold']] = $value ['staffList'];
  525. elseif ($value ['mold'] == '发票邮寄')
  526. $moldManage [$value ['mold']] = $value ['staffList'];
  527. elseif ($value ['mold'] == '发票打印')
  528. $moldManage [$value ['mold']] = $value ['staffList'];
  529. }
  530. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  531. $item = array (
  532. 'iid' => $iid,
  533. 'cid' => $cid [0],
  534. 'categoryName' => $cid [1],
  535. 'invoiceElement' => $invoiceElement,
  536. 'invoiceQuantity' => $invoiceQuantity,
  537. 'invoiceUnitPrice' => $invoiceUnitPrice,
  538. 'invoicePrice' => $invoicePrice,
  539. 'invoiceType' => $invoiceType,
  540. 'doPost' => $doPost,
  541. 'status' => 1,
  542. 'updateTime' => date ( "Y-m-d H:i:s" ),
  543. 'remark' => $remark
  544. );
  545. if ($invoiceType == 0)
  546. $item += array (
  547. 'invoiceTitle' => $invoiceTitle,
  548. 'TIN' => $TINT,
  549. 'address' => $addressT,
  550. 'phone' => $phoneT,
  551. 'bank' => $bankT,
  552. 'bankAccount' => $bankAccountT
  553. );
  554. else {
  555. $item += array (
  556. 'invoiceCompany' => $invoiceCompany,
  557. 'TIN' => $TIN,
  558. 'address' => $address,
  559. 'phone' => $phone,
  560. 'bank' => $bank,
  561. 'bankAccount' => $bankAccount
  562. );
  563. }
  564. if ($doPost == 1) {
  565. $mailList = array (
  566. 'invoice' => 1,
  567. 'mailItems' => $mailItems
  568. );
  569. if (! empty ( $softLock ))
  570. $mailList += array (
  571. 'softLock' => $softLockNum
  572. );
  573. else
  574. $mailList += array (
  575. 'softLock' => '0'
  576. );
  577. if (! empty ( $contract ))
  578. $mailList += array (
  579. 'contract' => $contractNum
  580. );
  581. else
  582. $mailList += array (
  583. 'contract' => '0'
  584. );
  585. if (! empty ( $instructions ))
  586. $mailList += array (
  587. 'instructions' => $instructionsNum
  588. );
  589. else
  590. $mailList += array (
  591. 'instructions' => '0'
  592. );
  593. if (! empty ( $remittance ))
  594. $mailList += array (
  595. 'remittance' => $remittance
  596. );
  597. else
  598. $mailList += array (
  599. 'remittance' => ''
  600. );
  601. $mailString = '发票x1,备注:' . $mailItems;
  602. if (! empty ( $softLock ))
  603. $mailString .= ',软件锁x' . $softLockNum;
  604. if (! empty ( $contract ))
  605. $mailString .= ',合同x' . $contractNum;
  606. if (! empty ( $instructions ))
  607. $mailString .= ',说明书x' . $instructionsNum;
  608. if (! empty ( $remittance ))
  609. $mailString .= ',汇款账号单';
  610. $item += array (
  611. 'recipients' => $recipients,
  612. 'recipientsPhone' => $recipientsPhone,
  613. 'recipientsAddress' => $recipientsAddress,
  614. 'mailItems' => $mailString,
  615. 'mailItemsJson' => json_encode ( $mailList )
  616. );
  617. }
  618. $invoice->setInvoiceByCondition ( $item );
  619. $item = array (
  620. 'date' => date ( "Y-m-d H:i:s" ),
  621. 'operation' => "重新提交审批",
  622. 'status' => 1,
  623. 'img' => $this->staff [0] ['avatar'],
  624. 'username' => $this->staff [0] ['username'],
  625. 'uid' => $this->staff [0] ['sid'],
  626. 'category' => $this->staff [0] ['category'],
  627. 'iid' => $iid
  628. );
  629. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  630. }
  631. return "/invoice";
  632. }
  633. /**
  634. * 培训班
  635. */
  636. function invoiceTraining() {
  637. Doo::loadModel ( 'L_category' );
  638. $lCategory = new L_category ();
  639. Doo::loadModel ( 'invoiceTraining' );
  640. $invoiceTraining = new invoiceTraining ();
  641. $itTodoList = $invoiceTraining->getInvoiceTrainingByTodo ( '', $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  642. $itedList = $invoiceTraining->getInvoiceTrainingByStatus ( 2, '', $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  643. $category = $lCategory->getCategory ();
  644. $itid = array ();
  645. foreach ( $itTodoList as $value ) {
  646. array_push ( $itid, $value ['itid'] );
  647. }
  648. foreach ( $itedList as $value ) {
  649. array_push ( $itid, $value ['itid'] );
  650. }
  651. $itid = implode ( ',', $itid );
  652. $this->data ['itStatist'] = $invoiceTraining->getInvoiceTrainStatistics ( $itid );
  653. //print_r($itTodoList);
  654. $this->data ['trainCount'] = count ( $itTodoList ) + count ( $itedList );
  655. $this->data ['itTodoList'] = $itTodoList;
  656. $this->data ['itedList'] = $itedList;
  657. $this->data ['category'] = $category;
  658. $this->data ['memu'] = "invoice";
  659. $this->data ['staff'] = $this->staff;
  660. $this->data ['receiptMemu'] = 'invoiceTraining';
  661. $this->render ( "/admin/invoiceTraining", $this->data );
  662. }
  663. /**
  664. * 创建培训班
  665. */
  666. function invoiceTrainingAdd() {
  667. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  668. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  669. $trainDate = $this->get_args ( 'trainDate' ) ? $this->get_args ( 'trainDate' ) : "";
  670. if (empty ( $this->staff [0] ))
  671. die ( 'illegal request' );
  672. if (! empty ( $cid ) && ! empty ( $trainName ) && ! empty ( $trainDate )) {
  673. Doo::loadModel ( 'invoiceTraining' );
  674. $invoiceTraining = new invoiceTraining ();
  675. Doo::loadModel ( 'invoice' );
  676. $invoice = new invoice ();
  677. Doo::loadModel ( 'L_category' );
  678. $lCategory = new L_category ();
  679. Doo::loadModel ( 'invoiceManage' );
  680. $invoiceManage = new invoiceManage ();
  681. Doo::loadModel ( 'invoiceOperationLog' );
  682. $invoiceOperationLog = new invoiceOperationLog ();
  683. $item = array (
  684. 'cid' => $cid,
  685. 'trainName' => $trainName,
  686. 'trainDate' => $trainDate,
  687. 'creator' => $this->staff [0] ['sid'],
  688. 'creatorDate' => date ( "Y-m-d H:i:s" )
  689. );
  690. $itid = $invoiceTraining->addInvoiceTraining ( $item );
  691. }
  692. return "/invoiceTraining";
  693. }
  694. /**
  695. * 删除培训班
  696. */
  697. function invoiceTrainingDelDo() {
  698. $itid = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  699. if (! empty ( $itid )) {
  700. Doo::loadModel ( 'invoiceTraining' );
  701. $invoiceTraining = new invoiceTraining ();
  702. $invoiceTraining->delInvoiceTrainingByItid ( $itid );
  703. }
  704. return "/invoiceTraining";
  705. }
  706. /**
  707. * 培训班详情
  708. */
  709. function invoiceTrainingDetail() {
  710. $trainStatus = $this->get_args ( 'trainStatus' ) ? $this->get_args ( 'trainStatus' ) : "ALL";
  711. $itid = isset ( $this->params ['trainingKey'] ) ? $this->params ['trainingKey'] : "";
  712. Doo::loadModel ( 'invoiceTraining' );
  713. $invoiceTraining = new invoiceTraining ();
  714. Doo::loadModel ( 'invoiceStore' );
  715. $invoiceStore = new invoiceStore ();
  716. if (empty ( $itid ))
  717. die ( 'illegal request' );
  718. $con=' (b.untreadStatus is null or b.untreadStatus!=2) and ';
  719. if ($trainStatus=="SUBED")
  720. $con=' (b.untreadStatus is null ) and ';
  721. elseif($trainStatus=="APPROVAL")
  722. $con=' ( b.status=1 and b.untreadStatus!=2 ) and ';
  723. elseif($trainStatus=="TICKET")
  724. $con=' (b.printStatus=1 and b.status=2 and b.untreadStatus!=2) and ';
  725. $detail = $invoiceTraining->getInvoiceTrainingByItid ( $itid );
  726. $isList = $invoiceStore->getinvoiceStoreByItid ( $itid,$con );
  727. // print_r($isList);
  728. $trainlist = array ();
  729. foreach ( $isList as $key => $value ) {
  730. $irDetail = array ();
  731. if ($value ['apStatus'] == 1) {
  732. // array_push ( $irDetail, '' );
  733. array_push ( $irDetail, '<input disabled type="checkbox" >' );
  734. } else {
  735. array_push ( $irDetail, '<input type="checkbox" class="hide" id="' . $value ['storeKey'] . '" name="isBox" value="' . $value ['storeKey'] . '" > <a href="/invoiceStoreEdit/' . $value ['storeKey'] . '.html">编辑</a>
  736. <a href="#confirm" onclick="invoiceStoreApproval(\'' . $value ['storeKey'] . '\')" data-toggle="modal">提交审批</a>
  737. <a href="#del" node-iStore="del" data-key="' . $value ['storeKey'] . '" onclick="invoiceStoreDel(\'' . $value ['storeKey'] . '\')" data-toggle="modal" class="colRed">移除</a>' );
  738. }
  739. array_push ( $irDetail, $value ['invoiceSerial'] );
  740. if ($value ['invoiceType'] == 1)
  741. array_push ( $irDetail, $value ['invoiceCompany'] );
  742. else
  743. array_push ( $irDetail, $value ['invoiceTitle'] );
  744. array_push ( $irDetail, $value ['TIN'] );
  745. array_push ( $irDetail, $value ['userName'] );
  746. if (empty ( $value ['mailItems'] ) && $value ['apStatus'] != 1) {
  747. array_push ( $irDetail, '<a href="#confirm-erro" onclick="invoiceStoreMail(\'' . $value ['storeKey'] . '\')" data-toggle="modal">设置邮寄物品</a>' );
  748. } else
  749. array_push ( $irDetail, $value ['mailItems'] );
  750. array_push ( $irDetail, $value ['recipientsAddress'] . $value ['recipients'] . $value ['recipientsPhone'] );
  751. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  752. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  753. array_push ( $irDetail, $value ['invoiceElement'] );
  754. array_push ( $irDetail, $value ['invoiceQuantity'] );
  755. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  756. if ($value ['invoiceType'] == 1)
  757. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  758. else
  759. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  760. array_push ( $irDetail, $value ['remark'] );
  761. if ($value ['status'] == 1)
  762. array_push ( $irDetail, '审批中' );
  763. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1)
  764. array_push ( $irDetail, '已出票' );
  765. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1 && $value ['printStatus'] != 'irid' && ($value ['untreadStatus'] == 3 || $value ['untreadStatus'] == 0))
  766. array_push ( $irDetail, '已入账' );
  767. else
  768. array_push ( $irDetail, '' );
  769. array_push ( $irDetail, $value ['invoiceNo'] );
  770. array_push ( $irDetail, $value ['printTime'] );
  771. $html = '';
  772. foreach ( $value ['invoiceReceivables'] as $value ) {
  773. $html .= '&nbsp;<a href="#billing" node-invoice="INFO" data-type="receivables" data-iskey="' . $value [2] . '" data-toggle="modal">' . $value [1] . '</a>';
  774. }
  775. array_push ( $irDetail, $html );
  776. array_push ( $trainlist, $irDetail );
  777. }
  778. $trainlistJson = json_encode ( $trainlist );
  779. if (empty ( $detail ))
  780. die ( 'illegal request' );
  781. $this->data ['trainStatus'] = $trainStatus;
  782. $this->data ['itid'] = $itid;
  783. $this->data ['trainlistJson'] = $trainlistJson;
  784. $this->data ['iTrainDetail'] = $detail;
  785. $this->data ['memu'] = "invoice";
  786. $this->data ['staff'] = $this->staff;
  787. $this->data ['receiptMemu'] = 'invoiceTraining';
  788. $this->render ( "/admin/invoiceTrainingDetail", $this->data );
  789. }
  790. /**
  791. * 上传培训班发票
  792. * @return string
  793. */
  794. function invoiceTrainingUpload() {
  795. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  796. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  797. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  798. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  799. header ( "HTTP/1.1 500 Internal Server Error" );
  800. echo "POST exceeded maximum allowed size.";
  801. exit ( 0 );
  802. }
  803. // Settings
  804. $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)
  805. $upload_name = "Filedata";
  806. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  807. $extension_whitelist = array (
  808. "doc",
  809. "txt",
  810. "jpg",
  811. "gif",
  812. "png"
  813. ); // Allowed file extensions
  814. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  815. // Other variables
  816. $MAX_FILENAME_LENGTH = 260;
  817. $file_name = "";
  818. $file_extension = "";
  819. $uploadErrors = array (
  820. 0 => "文件上传成功",
  821. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  822. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  823. 3 => "上传的文件仅为部分文件",
  824. 4 => "没有文件上传",
  825. 6 => "缺少临时文件夹"
  826. );
  827. $nk = time ();
  828. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  829. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  830. echo "文件无法保存.";
  831. exit ( 0 );
  832. }
  833. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  834. echo json_encode ( array (
  835. 'filename' => $file_name,
  836. 'id' => $nk
  837. ) );
  838. exit ( 0 );
  839. }
  840. /**
  841. * 导入发票临时仓库
  842. */
  843. function invoiceStoreImport() {
  844. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  845. $trainingKey = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  846. $path = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  847. if ($path != "" && ! empty ( $trainingKey )) {
  848. Doo::loadModel ( 'invoiceStore' );
  849. Doo::loadModel ( 'staff' );
  850. $staff = new staff ();
  851. Doo::loadModel ( 'invoiceTraining' );
  852. $invoiceTraining = new invoiceTraining ();
  853. Doo::loadClass ( 'XDeode' );
  854. $XDeode = new XDeode ( 5 );
  855. $itid = $XDeode->decode ( $trainingKey );
  856. $exlArray = $this->formatExcelToArrayTrain ( DOO::conf ()->SITE_PATH . "upload/invoiceTraining/" . $path );
  857. $userName = $this->staff [0] ['username'];
  858. $sDetail = $staff->getStaffByName ( $userName );
  859. // die('sdd');
  860. // 可以优化
  861. foreach ( $exlArray as $key => $value ) {
  862. // 开票
  863. $invoice = new invoiceStore ();
  864. $invoice->trainId = $itid;
  865. $invoice->invoiceType = 0;
  866. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  867. $invoice->invoiceType = 1;
  868. $invoice->invoiceQuantity = $value ['invoiceQuantity'];
  869. $invoice->invoiceUnitPrice = $value ['invoiceUnitPrice'];
  870. $invoice->invoicePrice = $value ['invoiceQuantity'] * $value ['invoiceUnitPrice'];
  871. $invoice->invoiceTitle = $value ['invoiceTitle'];
  872. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  873. $invoice->invoiceCompany = $value ['invoiceTitle'];
  874. $invoice->userName = $userName;
  875. $invoice->sid = $sDetail ['sid'];
  876. $invoice->cid = $sDetail ['cid'];
  877. $invoice->categoryName = $sDetail ['category'];
  878. $invoice->invoiceElement = $value ['invoiceElement'];
  879. $invoice->remark = $value ['remark'];
  880. // $invoice->date = $value ['date'];
  881. // $invoice->printTime = $value ['date'];
  882. $invoice->ipSource = 1;
  883. $invoice->printStatus = 1;
  884. $invoice->status = 2;
  885. $invoice->postStatus = 1;
  886. $invoice->untreadStatus = 0;
  887. // $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  888. $invoice->TIN = $value ['TIN'];
  889. $invoice->address = $value ['address'];
  890. $invoice->phone = $value ['phone'];
  891. $invoice->bank = $value ['bank'];
  892. $invoice->bankAccount = $value ['bankAccount'];
  893. $invoice->recipientsAddress = $value ['recipientsAddress'];
  894. $invoice->recipients = $value ['recipients'];
  895. $invoice->recipientsPhone = $value ['recipientsPhone'];
  896. $iid = $invoice->insert ();
  897. }
  898. // 加入发票总数量
  899. $item = array (
  900. 'itid' => $itid,
  901. 'invoiceTotal' => count ( $exlArray )
  902. );
  903. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  904. return '/invoiceTrainingDetail/' . $trainingKey . ".html";
  905. }
  906. echo 'no file';
  907. }
  908. /**
  909. * 编辑仓库里的发票
  910. */
  911. function invoiceStoreEdit() {
  912. Doo::loadClass ( 'XDeode' );
  913. $XDeode = new XDeode ( 5 );
  914. $iid = isset ( $this->params ['storeKey'] ) ? $this->params ['storeKey'] : "";
  915. $iid = $XDeode->decode ( $iid );
  916. if (! is_numeric ( $iid ))
  917. die ( 'illegal request' );
  918. Doo::loadModel ( 'invoiceStore' );
  919. $invoiceStore = new invoiceStore ();
  920. $invoiceDetail = $invoiceStore->getInvoiceStoreByIsid ( $iid );
  921. // print_r($invoiceDetail);
  922. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  923. $this->data ['invoiceDetail'] = $invoiceDetail;
  924. $this->data ['memu'] = "invoice";
  925. $this->data ['staff'] = $this->staff;
  926. $this->data ['receiptMemu'] = 'invoiceTraining';
  927. $this->render ( "/admin/invoiceStoreEdit", $this->data );
  928. }
  929. function invoiceStoreEditDo() {
  930. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  931. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  932. Doo::loadModel ( 'invoiceStore' );
  933. $invoice = new invoiceStore ();
  934. Doo::loadClass ( 'XDeode' );
  935. $XDeode = new XDeode ( 5 );
  936. $iid = $XDeode->decode ( $storeKey );
  937. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  938. die ( 'illegal request' );
  939. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  940. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  941. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  942. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  943. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  944. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  945. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  946. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  947. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  948. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  949. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  950. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  951. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  952. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  953. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  954. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  955. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  956. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  957. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  958. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  959. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  960. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  961. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  962. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  963. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  964. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  965. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  966. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  967. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  968. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  969. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  970. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  971. $cid = explode ( ':', $cid );
  972. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  973. $item = array (
  974. 'isid' => $iid,
  975. 'cid' => $cid [0],
  976. 'categoryName' => $cid [1],
  977. 'invoiceElement' => $invoiceElement,
  978. 'invoiceQuantity' => $invoiceQuantity,
  979. 'invoiceUnitPrice' => $invoiceUnitPrice,
  980. 'invoicePrice' => $invoicePrice,
  981. 'invoiceType' => $invoiceType,
  982. 'doPost' => $doPost,
  983. 'status' => 1,
  984. 'updateTime' => date ( "Y-m-d H:i:s" ),
  985. 'remark' => $remark
  986. );
  987. if ($invoiceType == 0)
  988. $item += array (
  989. 'invoiceTitle' => $invoiceTitle,
  990. 'TIN' => $TINT,
  991. 'address' => $addressT,
  992. 'phone' => $phoneT,
  993. 'bank' => $bankT,
  994. 'bankAccount' => $bankAccountT
  995. );
  996. else {
  997. $item += array (
  998. 'invoiceCompany' => $invoiceCompany,
  999. 'TIN' => $TIN,
  1000. 'address' => $address,
  1001. 'phone' => $phone,
  1002. 'bank' => $bank,
  1003. 'bankAccount' => $bankAccount
  1004. );
  1005. }
  1006. if ($doPost == 1) {
  1007. $mailList = array (
  1008. 'invoice' => 1,
  1009. 'mailItems' => $mailItems
  1010. );
  1011. if (! empty ( $softLock ))
  1012. $mailList += array (
  1013. 'softLock' => $softLockNum
  1014. );
  1015. else
  1016. $mailList += array (
  1017. 'softLock' => '0'
  1018. );
  1019. if (! empty ( $contract ))
  1020. $mailList += array (
  1021. 'contract' => $contractNum
  1022. );
  1023. else
  1024. $mailList += array (
  1025. 'contract' => '0'
  1026. );
  1027. if (! empty ( $instructions ))
  1028. $mailList += array (
  1029. 'instructions' => $instructionsNum
  1030. );
  1031. else
  1032. $mailList += array (
  1033. 'instructions' => '0'
  1034. );
  1035. if (! empty ( $remittance ))
  1036. $mailList += array (
  1037. 'remittance' => $remittance
  1038. );
  1039. else
  1040. $mailList += array (
  1041. 'remittance' => ''
  1042. );
  1043. $mailString = '发票x1,备注:' . $mailItems;
  1044. if (! empty ( $softLock ))
  1045. $mailString .= ',软件锁x' . $softLockNum;
  1046. if (! empty ( $contract ))
  1047. $mailString .= ',合同x' . $contractNum;
  1048. if (! empty ( $instructions ))
  1049. $mailString .= ',说明书x' . $instructionsNum;
  1050. if (! empty ( $remittance ))
  1051. $mailString .= ',汇款账号单';
  1052. $item += array (
  1053. 'recipients' => $recipients,
  1054. 'recipientsPhone' => $recipientsPhone,
  1055. 'recipientsAddress' => $recipientsAddress,
  1056. 'mailItems' => $mailString,
  1057. 'mailItemsJson' => json_encode ( $mailList )
  1058. );
  1059. }
  1060. $invoice->setInvoiceStoreByCondition ( $item );
  1061. }
  1062. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1063. }
  1064. /**
  1065. *
  1066. * @return string
  1067. */
  1068. function invoiceStoreDelete() {
  1069. Doo::loadClass ( 'XDeode' );
  1070. $XDeode = new XDeode ( 5 );
  1071. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1072. $iStoreKey = $this->get_args ( 'iStoreKey' ) ? $this->get_args ( 'iStoreKey' ) : 0;
  1073. $isid = $XDeode->decode ( $iStoreKey );
  1074. $itid = $XDeode->decode ( $trainKey );
  1075. if (! is_numeric ( $isid ))
  1076. die ( 'illegal request' );
  1077. Doo::loadModel ( 'invoiceStore' );
  1078. $invoiceStore = new invoiceStore ();
  1079. $invoiceStore->delete ( array (
  1080. 'where' => 'isid=' . $isid,
  1081. 'limit' => 1
  1082. ) );
  1083. Doo::loadModel ( 'invoiceTraining' );
  1084. $invoiceTraining = new invoiceTraining ();
  1085. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1086. $item = array (
  1087. 'itid' => $itid,
  1088. 'invoiceTotal' => $itDetail ['invoiceTotal'] - 1
  1089. );
  1090. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1091. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1092. }
  1093. /**
  1094. * 批量删除库里发票
  1095. */
  1096. function invoiceStoreBatchDelete() {
  1097. Doo::loadClass ( 'XDeode' );
  1098. $XDeode = new XDeode ( 5 );
  1099. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1100. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1101. $tid = $XDeode->decode ( $trainKey );
  1102. if (! is_numeric ( $tid ) && ! empty ( $storeKey ))
  1103. die ( 'illegal request' );
  1104. Doo::loadModel ( 'invoiceStore' );
  1105. $isidKeyList = explode ( ',', $storeKey );
  1106. $isidList = array ();
  1107. foreach ( $isidKeyList as $value ) {
  1108. $isid = $XDeode->decode ( $value );
  1109. if (! empty ( $isid ) && is_numeric ( $isid ))
  1110. array_push ( $isidList, $isid );
  1111. }
  1112. $isidString = implode ( ',', $isidList );
  1113. $invoiceStore = new invoiceStore ();
  1114. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,apStatus' );
  1115. $isidList = array ();
  1116. foreach ( $isList as $key => $value ) {
  1117. if ($value ['apStatus'] == 0)
  1118. array_push ( $isidList, $value ['isid'] );
  1119. }
  1120. $isidString = implode ( ',', $isidList );
  1121. // print_r($isList);
  1122. // echo $isidString;
  1123. $invoiceStore = new invoiceStore ();
  1124. $invoiceStore->delete ( array (
  1125. 'where' => "isid in ( " . $isidString . ")",
  1126. 'asArray' => TRUE
  1127. ) );
  1128. Doo::loadModel ( 'invoiceTraining' );
  1129. $invoiceTraining = new invoiceTraining ();
  1130. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1131. $item = array (
  1132. 'itid' => $tid,
  1133. 'invoiceTotal' => $itDetail ['invoiceTotal'] - count ( $isidList )
  1134. );
  1135. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1136. // echo $tid;
  1137. // echo $storeKey;
  1138. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1139. }
  1140. /**
  1141. * 仓库发票提交审批
  1142. * @return string
  1143. */
  1144. function invoiceStoreApproval() {
  1145. Doo::loadClass ( 'XDeode' );
  1146. $XDeode = new XDeode ( 5 );
  1147. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1148. $iStoreKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1149. $isid = $XDeode->decode ( $iStoreKey );
  1150. $trainId = $XDeode->decode ( $trainKey );
  1151. if (! is_numeric ( $isid ))
  1152. die ( 'illegal request' );
  1153. Doo::loadModel ( 'invoiceStore' );
  1154. Doo::loadModel ( 'invoice' );
  1155. $invoice = new invoice ();
  1156. // 加入限制必须填写入开票内容和邮寄物品
  1157. $invoiceStore = new invoiceStore ();
  1158. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid, 'isid,trainId ,invoiceElement,mailItemsJson' );
  1159. if (empty ( $isDetail ['invoiceElement'] ) || empty ( $isDetail ['mailItemsJson'] )) {
  1160. header ( 'Content-Type:text/html;charset=utf-8' );
  1161. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1162. }
  1163. // 拷贝插入一条发票数据
  1164. $invoiceStore = new invoiceStore ();
  1165. $iid = $invoiceStore->setInvoiceStoreToApproval ( $isid );
  1166. $invoiceStore = new invoiceStore ();
  1167. $item = array (
  1168. 'isid' => $isid,
  1169. 'iid' => $iid,
  1170. 'apStatus' => 1
  1171. );
  1172. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1173. Doo::loadModel ( 'invoiceManage' );
  1174. $invoiceManage = new invoiceManage ();
  1175. Doo::loadModel ( 'invoiceOperationLog' );
  1176. $invoiceOperationLog = new invoiceOperationLog ();
  1177. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1178. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1179. $moldManage = array ();
  1180. foreach ( $invoiceManageList as $key => $value ) {
  1181. if ($value ['mold'] == '发票打印')
  1182. $moldManage [$value ['mold']] = $value ['staffList'];
  1183. elseif ($value ['mold'] == '发票邮寄')
  1184. $moldManage [$value ['mold']] = $value ['staffList'];
  1185. elseif ($value ['mold'] == '发票退票')
  1186. $moldManage [$value ['mold']] = $value ['staffList'];
  1187. }
  1188. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1189. $item = array (
  1190. 'iid' => $iid,
  1191. 'invoiceSerial' => "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  1192. 'date' => date ( "Y-m-d H:i:s" ),
  1193. 'status' => 1,
  1194. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1195. 'trainId' => $trainId,
  1196. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1197. 'moldManage' => json_encode ( $moldManage ),
  1198. 'pendingApprovals' => $pendingApprovalsSid
  1199. );
  1200. $invoice->setInvoiceByCondition ( $item );
  1201. Doo::loadModel ( 'invoiceTraining' );
  1202. $invoiceTraining = new invoiceTraining ();
  1203. $item = array (
  1204. 'itid' => $trainId,
  1205. 'submitStatus' => 1
  1206. );
  1207. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1208. $item = array (
  1209. 'date' => date ( "Y-m-d H:i:s" ),
  1210. 'operation' => "创建",
  1211. 'status' => 1,
  1212. 'img' => $this->staff [0] ['avatar'],
  1213. 'username' => $this->staff [0] ['username'],
  1214. 'uid' => $this->staff [0] ['sid'],
  1215. 'category' => $this->staff [0] ['category'],
  1216. 'iid' => $iid
  1217. );
  1218. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1219. $item = array (
  1220. 'date' => date ( "Y-m-d H:i:s" ),
  1221. 'operation' => "提交审批",
  1222. 'status' => 1,
  1223. 'img' => $this->staff [0] ['avatar'],
  1224. 'username' => $this->staff [0] ['username'],
  1225. 'uid' => $this->staff [0] ['sid'],
  1226. 'category' => $this->staff [0] ['category'],
  1227. 'iid' => $iid
  1228. );
  1229. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1230. Doo::loadModel ( 'staff' );
  1231. $staff = new staff ();
  1232. $username2 = $staff->getOne ( array (
  1233. 'select' => 'wxid',
  1234. 'where' => 'sid=' . $pendingApprovalsSid,
  1235. 'asArray' => TRUE
  1236. ) );
  1237. // 发送微信审批通知
  1238. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1239. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1240. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1241. }
  1242. /**
  1243. * 批量提交发票
  1244. * @return string
  1245. */
  1246. function invoiceStoreBatchApproval() {
  1247. Doo::loadClass ( 'XDeode' );
  1248. $XDeode = new XDeode ( 5 );
  1249. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1250. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1251. $trainId = $XDeode->decode ( $trainKey );
  1252. $isidKeyList = explode ( ',', $storeKey );
  1253. $isidList = array ();
  1254. foreach ( $isidKeyList as $value ) {
  1255. $isid = $XDeode->decode ( $value );
  1256. if (! empty ( $isid ) && is_numeric ( $isid ))
  1257. array_push ( $isidList, $isid );
  1258. }
  1259. $isidString = implode ( ',', $isidList );
  1260. if (! is_numeric ( $trainId ))
  1261. die ( 'illegal request' );
  1262. Doo::loadModel ( 'invoiceStore' );
  1263. Doo::loadModel ( 'invoice' );
  1264. // 判断哪些已经加入审批过
  1265. // 加入限制必须填写入开票内容和邮寄物品
  1266. $invoiceStore = new invoiceStore ();
  1267. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,trainId ,invoiceElement,mailItemsJson' );
  1268. foreach ( $isList as $key => $value ) {
  1269. if (empty ( $value ['invoiceElement'] ) || empty ( $value ['mailItemsJson'] )) {
  1270. header ( 'Content-Type:text/html;charset=utf-8' );
  1271. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1272. }
  1273. }
  1274. // 拷贝插入一条发票数据
  1275. $invoiceStore = new invoiceStore ();
  1276. $invoiceStore->setInvoiceStoreBatchToApproval ( $isidString );
  1277. $invoiceStore = new invoiceStore ();
  1278. $item = array (
  1279. 'apStatus' => 1
  1280. );
  1281. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1282. // 获得正式发票ID
  1283. $invoice = new invoice ();
  1284. $iidList = $invoice->getInvoiceByIstoreid ( $isidString, 'iid,isid' );
  1285. $sqlList = array ();
  1286. $iidString = '';
  1287. $iida = array ();
  1288. foreach ( $iidList as $key => $value ) {
  1289. $sqlList [$value ['isid']] = $value ['iid'];
  1290. array_push ( $iida, $value ['iid'] );
  1291. }
  1292. $iidString = implode ( ',', $iida );
  1293. $ids = implode ( ',', array_keys ( $sqlList ) );
  1294. $sql = "UPDATE CLD_invoiceStore SET iid = CASE isid ";
  1295. foreach ( $sqlList as $id => $ordinal ) {
  1296. $sql .= sprintf ( "WHEN %d THEN %d ", $id, $ordinal );
  1297. }
  1298. $sql .= "END WHERE isid IN ($ids)";
  1299. $invoiceStore = new invoiceStore ();
  1300. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1301. Doo::loadModel ( 'invoiceManage' );
  1302. $invoiceManage = new invoiceManage ();
  1303. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1304. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1305. $moldManage = array ();
  1306. foreach ( $invoiceManageList as $key => $value ) {
  1307. if ($value ['mold'] == '发票打印')
  1308. $moldManage [$value ['mold']] = $value ['staffList'];
  1309. elseif ($value ['mold'] == '发票邮寄')
  1310. $moldManage [$value ['mold']] = $value ['staffList'];
  1311. elseif ($value ['mold'] == '发票退票')
  1312. $moldManage [$value ['mold']] = $value ['staffList'];
  1313. }
  1314. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1315. // 批量更新发票信息
  1316. $item = array (
  1317. 'date' => date ( "Y-m-d H:i:s" ),
  1318. 'status' => 1,
  1319. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1320. 'trainId' => $trainId,
  1321. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1322. 'moldManage' => json_encode ( $moldManage ),
  1323. 'pendingApprovals' => $pendingApprovalsSid
  1324. );
  1325. $invoice = new invoice ();
  1326. $invoice->BatchInvoiceByCondition ( $item, $iidString );
  1327. // 批量更新发票序列号
  1328. $sqlList = array ();
  1329. foreach ( $iida as $value ) {
  1330. $sqlList [$value] = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1331. }
  1332. $ids = implode ( ',', array_keys ( $sqlList ) );
  1333. $sql = "UPDATE CLD_invoice SET invoiceSerial = CASE iid ";
  1334. foreach ( $sqlList as $id => $ordinal ) {
  1335. $sql .= sprintf ( "WHEN %d THEN '%s' ", $id, $ordinal );
  1336. }
  1337. $sql .= "END WHERE iid IN ($ids)";
  1338. $invoiceStore = new invoiceStore ();
  1339. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1340. // 批量生产操作日志
  1341. Doo::loadModel ( 'invoiceOperationLog' );
  1342. $sqlList = array ();
  1343. foreach ( $iida as $key => $value ) {
  1344. $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 . '"),
  1345. ("' . 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 . '") ';
  1346. array_push ( $sqlList, $sql );
  1347. }
  1348. $iolSql = implode ( ',', $sqlList );
  1349. $sql = "INSERT INTO `CLD_invoiceOperationLog` (`date`, `operation`, `status`, `img`, `username`, `uid`, `category`, `iid`) VALUES " . $iolSql;
  1350. $invoiceOperationLog = new invoiceOperationLog ();
  1351. $invoiceOperationLog->setInvoiceOperationLogBySql ( $sql );
  1352. Doo::loadModel ( 'invoiceTraining' );
  1353. $invoiceTraining = new invoiceTraining ();
  1354. $item = array (
  1355. 'itid' => $trainId,
  1356. 'submitStatus' => 1
  1357. );
  1358. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1359. Doo::loadModel ( 'staff' );
  1360. $staff = new staff ();
  1361. $username2 = $staff->getOne ( array (
  1362. 'select' => 'wxid',
  1363. 'where' => 'sid=' . $pendingApprovalsSid,
  1364. 'asArray' => TRUE
  1365. ) );
  1366. // 发送微信审批通知
  1367. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1368. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1369. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1370. }
  1371. /**
  1372. */
  1373. function invoiceStoreMailItemSet() {
  1374. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1375. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1376. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1377. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1378. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1379. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1380. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1381. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1382. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1383. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1384. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1385. Doo::loadClass ( 'XDeode' );
  1386. $XDeode = new XDeode ( 5 );
  1387. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1388. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1389. $isid = $XDeode->decode ( $storeKey );
  1390. $trainId = $XDeode->decode ( $trainKey );
  1391. if (! is_numeric ( $isid ))
  1392. die ( 'illegal request' );
  1393. Doo::loadModel ( 'invoiceStore' );
  1394. $invoiceStore = new invoiceStore ();
  1395. $mailList = array (
  1396. 'invoice' => 1,
  1397. 'mailItems' => $mailItems
  1398. );
  1399. if (! empty ( $softLock ))
  1400. $mailList += array (
  1401. 'softLock' => $softLockNum
  1402. );
  1403. else
  1404. $mailList += array (
  1405. 'softLock' => 0
  1406. );
  1407. if (! empty ( $contract ))
  1408. $mailList += array (
  1409. 'contract' => $contractNum
  1410. );
  1411. else
  1412. $mailList += array (
  1413. 'contract' => 0
  1414. );
  1415. if (! empty ( $instructions ))
  1416. $mailList += array (
  1417. 'instructions' => $instructionsNum
  1418. );
  1419. else
  1420. $mailList += array (
  1421. 'instructions' => 0
  1422. );
  1423. if (! empty ( $remittance ))
  1424. $mailList += array (
  1425. 'remittance' => $remittance
  1426. );
  1427. else
  1428. $mailList += array (
  1429. 'remittance' => ''
  1430. );
  1431. $mailString = '发票x1,备注:' . $mailItems;
  1432. if (! empty ( $softLock ))
  1433. $mailString .= ',软件锁x' . $softLockNum;
  1434. if (! empty ( $contract ))
  1435. $mailString .= ',合同x' . $contractNum;
  1436. if (! empty ( $instructions ))
  1437. $mailString .= ',说明书x' . $instructionsNum;
  1438. if (! empty ( $remittance ))
  1439. $mailString .= ',汇款账号单';
  1440. $item = array (
  1441. 'isid' => $isid,
  1442. 'doPost' => 1,
  1443. 'mailItems' => $mailString,
  1444. 'mailItemsJson' => json_encode ( $mailList )
  1445. );
  1446. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1447. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1448. }
  1449. /**
  1450. * 批量设置邮寄物品
  1451. */
  1452. function invoiceStoreBatchMailItemSet() {
  1453. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1454. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1455. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1456. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1457. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1458. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1459. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1460. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1461. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1462. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1463. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1464. Doo::loadClass ( 'XDeode' );
  1465. $XDeode = new XDeode ( 5 );
  1466. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1467. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1468. $isidKeyList = explode ( ',', $storeKey );
  1469. $isidList = array ();
  1470. foreach ( $isidKeyList as $value ) {
  1471. $isid = $XDeode->decode ( $value );
  1472. if (! empty ( $isid ) && is_numeric ( $isid ))
  1473. array_push ( $isidList, $isid );
  1474. }
  1475. $isidString = implode ( ',', $isidList );
  1476. $trainId = $XDeode->decode ( $trainKey );
  1477. if (! is_numeric ( $isid ))
  1478. die ( 'illegal request' );
  1479. Doo::loadModel ( 'invoiceStore' );
  1480. $invoiceStore = new invoiceStore ();
  1481. $mailList = array (
  1482. 'invoice' => 1,
  1483. 'mailItems' => $mailItems
  1484. );
  1485. if (! empty ( $softLock ))
  1486. $mailList += array (
  1487. 'softLock' => $softLockNum
  1488. );
  1489. else
  1490. $mailList += array (
  1491. 'softLock' => 0
  1492. );
  1493. if (! empty ( $contract ))
  1494. $mailList += array (
  1495. 'contract' => $contractNum
  1496. );
  1497. else
  1498. $mailList += array (
  1499. 'contract' => 0
  1500. );
  1501. if (! empty ( $instructions ))
  1502. $mailList += array (
  1503. 'instructions' => $instructionsNum
  1504. );
  1505. else
  1506. $mailList += array (
  1507. 'instructions' => 0
  1508. );
  1509. if (! empty ( $remittance ))
  1510. $mailList += array (
  1511. 'remittance' => $remittance
  1512. );
  1513. else
  1514. $mailList += array (
  1515. 'remittance' => ''
  1516. );
  1517. $mailString = '发票x1,备注:' . $mailItems;
  1518. if (! empty ( $softLock ))
  1519. $mailString .= ',软件锁x' . $softLockNum;
  1520. if (! empty ( $contract ))
  1521. $mailString .= ',合同x' . $contractNum;
  1522. if (! empty ( $instructions ))
  1523. $mailString .= ',说明书x' . $instructionsNum;
  1524. if (! empty ( $remittance ))
  1525. $mailString .= ',汇款账号单';
  1526. $item = array (
  1527. 'doPost' => 1,
  1528. 'mailItems' => $mailString,
  1529. 'mailItemsJson' => json_encode ( $mailList )
  1530. );
  1531. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1532. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1533. }
  1534. /**
  1535. * 废弃
  1536. */
  1537. function ajaxGetMailItemByIstore() {
  1538. Doo::loadClass ( 'XDeode' );
  1539. $XDeode = new XDeode ( 5 );
  1540. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1541. $isid = $XDeode->decode ( $storeKey );
  1542. if (! is_numeric ( $isid ))
  1543. die ( 'illegal request' );
  1544. Doo::loadModel ( 'invoiceStore' );
  1545. $invoiceStore = new invoiceStore ();
  1546. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid );
  1547. $isDetail ['mailItemsJson'] = json_decode ( $isDetail ['mailItemsJson'], true );
  1548. echo json_encode ( $isDetail ['mailItemsJson'] );
  1549. exit ();
  1550. }
  1551. /**
  1552. * 终止开票
  1553. */
  1554. function invoiceDroppedDo() {
  1555. $droppedIidKey = $this->get_args ( 'droppedIidKey' ) ? $this->get_args ( 'droppedIidKey' ) : '';
  1556. Doo::loadModel ( 'invoice' );
  1557. $invoice = new invoice ();
  1558. Doo::loadModel ( 'invoiceOperationLog' );
  1559. $invoiceOperationLog = new invoiceOperationLog ();
  1560. $iid = $invoice->authcode ( $droppedIidKey );
  1561. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1562. die ( 'illegal request' );
  1563. $item = array (
  1564. 'iid' => $iid,
  1565. 'status' => 4,
  1566. 'updateTime' => date ( "Y-m-d H:i:s" )
  1567. );
  1568. $invoice->setInvoiceByCondition ( $item );
  1569. $item = array (
  1570. 'date' => date ( "Y-m-d H:i:s" ),
  1571. 'operation' => '终止了开票',
  1572. 'status' => 4,
  1573. 'img' => $this->staff [0] ['avatar'],
  1574. 'username' => $this->staff [0] ['username'],
  1575. 'uid' => $this->staff [0] ['sid'],
  1576. 'category' => $this->staff [0] ['category'],
  1577. 'iid' => $iid
  1578. );
  1579. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1580. return "/invoice";
  1581. }
  1582. /**
  1583. * 更新退票的邮寄信息
  1584. */
  1585. function invoiceUntreadMailDo() {
  1586. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  1587. $untreadCompany = $this->get_args ( 'untreadCompany' ) ? $this->get_args ( 'untreadCompany' ) : "";
  1588. $untreadNumber = $this->get_args ( 'untreadNumber' ) ? $this->get_args ( 'untreadNumber' ) : "";
  1589. $untreadItems = $this->get_args ( 'untreadItems' ) ? $this->get_args ( 'untreadItems' ) : "";
  1590. Doo::loadModel ( 'invoice' );
  1591. $invoice = new invoice ();
  1592. $iid = $invoice->authcode ( $untreadIidKey );
  1593. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1594. die ( 'illegal request' );
  1595. $item = array (
  1596. 'iid' => $iid,
  1597. 'untreadCompany' => $untreadCompany,
  1598. 'untreadNumber' => $untreadNumber,
  1599. 'untreadItems' => $untreadItems
  1600. );
  1601. $invoice->setInvoiceByCondition ( $item );
  1602. return "/invoice";
  1603. }
  1604. /**
  1605. * 申请退票 --
  1606. */
  1607. function invoiceUntreadDo() {
  1608. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  1609. $untreadReason = $this->get_args ( 'untreadReason' ) ? $this->get_args ( 'untreadReason' ) : "";
  1610. $untreadPost = $this->get_args ( 'untreadPost' ) ? $this->get_args ( 'untreadPost' ) : "";
  1611. Doo::loadModel ( 'invoice' );
  1612. $invoice = new invoice ();
  1613. Doo::loadModel ( 'invoiceOperationLog' );
  1614. $invoiceOperationLog = new invoiceOperationLog ();
  1615. Doo::loadModel ( 'invoiceReceivables' );
  1616. $invoiceReceivables = new invoiceReceivables ();
  1617. $iid = $invoice->authcode ( $untreadIidKey );
  1618. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1619. die ( 'illegal request' );
  1620. /*
  1621. * 需求变革 有绑定收款也可以退票 $lt = $invoiceReceivables->getInvoiceReceivablesByIid ( $untreadIidKey ); if (! empty ( $lt )) { header ( 'Content-Type:text/html;charset=utf-8' ); die ( '该发票有收款绑定,请先移除!' ); }
  1622. */
  1623. $item = array (
  1624. 'iid' => $iid,
  1625. 'untreadStatus' => 1,
  1626. 'untreadReason' => $untreadReason,
  1627. 'untreadPost' => $untreadPost,
  1628. 'updateTime' => date ( "Y-m-d H:i:s" )
  1629. );
  1630. $invoice->setInvoiceByCondition ( $item );
  1631. $item = array (
  1632. 'date' => date ( "Y-m-d H:i:s" ),
  1633. 'operation' => '申请退票',
  1634. 'status' => 7,
  1635. 'img' => $this->staff [0] ['avatar'],
  1636. 'username' => $this->staff [0] ['username'],
  1637. 'uid' => $this->staff [0] ['sid'],
  1638. 'category' => $this->staff [0] ['category'],
  1639. 'iid' => $iid
  1640. );
  1641. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1642. return "/invoice";
  1643. }
  1644. /**
  1645. * 删除已终止的开票
  1646. */
  1647. function invoiceDelDo() {
  1648. Doo::loadModel ( 'invoice' );
  1649. $invoice = new invoice ();
  1650. Doo::loadModel ( 'invoiceOperationLog' );
  1651. $invoiceOperationLog = new invoiceOperationLog ();
  1652. Doo::loadClass ( 'XDeode' );
  1653. $XDeode = new XDeode ( 5 );
  1654. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  1655. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  1656. $iid = $XDeode->decode ( $iid );
  1657. Doo::loadModel ( 'invoiceStore' );
  1658. $invoiceStore = new invoiceStore ();
  1659. if (! is_numeric ( $iid ))
  1660. die ( 'illegal request' );
  1661. $invoiceDetail = $invoice->getMyInvoice ( $sid, $iid );
  1662. if (empty ( $invoiceDetail ))
  1663. die ( 'illegal request' );
  1664. $item = array (
  1665. 'iid' => $iid,
  1666. 'isDelete' => 1,
  1667. 'updateTime' => date ( "Y-m-d H:i:s" )
  1668. );
  1669. $invoice->setInvoiceByCondition ( $item );
  1670. $item = array (
  1671. 'date' => date ( "Y-m-d H:i:s" ),
  1672. 'operation' => '删除了已终止的发票',
  1673. 'status' => 4,
  1674. 'img' => $this->staff [0] ['avatar'],
  1675. 'username' => $this->staff [0] ['username'],
  1676. 'uid' => $this->staff [0] ['sid'],
  1677. 'category' => $this->staff [0] ['category'],
  1678. 'iid' => $iid
  1679. );
  1680. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1681. // 删除培训班发票仓库里的发票
  1682. $invoiceStore->delInvoiceStoreByIsid ( $invoiceDetail ['isid'] );
  1683. return "/invoice";
  1684. }
  1685. /**
  1686. */
  1687. function invoiceApproval() {
  1688. Doo::loadModel ( 'invoice' );
  1689. $invoice = new invoice ();
  1690. Doo::loadClass ( 'XDeode' );
  1691. $XDeode = new XDeode ( 5 );
  1692. Doo::loadModel ( 'staff' );
  1693. $staff = new staff ();
  1694. $invoiceList = $invoice->find ( array (
  1695. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  1696. 'desc' => 'iid',
  1697. 'limit' => 10,
  1698. 'asArray' => true
  1699. ) );
  1700. foreach ( $invoiceList as $key => $value ) {
  1701. $invoiceList [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1702. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1703. if (! empty ( $lastApprover )) {
  1704. $lastApproverKey = array_keys ( $lastApprover );
  1705. $lastApprover = end ( $lastApprover );
  1706. $staffDetail = $staff->getOne ( array (
  1707. 'where' => 'sid=' . end ( $lastApproverKey ),
  1708. 'asArray' => true
  1709. ) );
  1710. $lastApprover ['username'] = $staffDetail ['username'];
  1711. }
  1712. $invoiceList [$key] ['lastApprover'] = $lastApprover;
  1713. }
  1714. $ilist = $invoice->getInvoiceByProcessStatus ();
  1715. foreach ( $ilist as $key => $value ) {
  1716. $ilist [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1717. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1718. if (! empty ( $lastApprover )) {
  1719. $lastApproverKey = array_keys ( $lastApprover );
  1720. $lastApprover = end ( $lastApprover );
  1721. $staffDetail = $staff->getOne ( array (
  1722. 'where' => 'sid=' . end ( $lastApproverKey ),
  1723. 'asArray' => true
  1724. ) );
  1725. $lastApprover ['username'] = $staffDetail ['username'];
  1726. }
  1727. $ilist [$key] ['lastApprover'] = $lastApprover;
  1728. }
  1729. // print_r($ilist);
  1730. $this->data ['invoiceList'] = $invoiceList;
  1731. $this->data ['ilist'] = $ilist;
  1732. $this->data ['memu'] = "invoice";
  1733. $this->data ['staff'] = $this->staff;
  1734. $this->data ['receiptMemu'] = 'invoiceApproval';
  1735. $this->render ( "/admin/invoiceApproval", $this->data );
  1736. }
  1737. function invoiceDetail() {
  1738. Doo::loadClass ( 'XDeode' );
  1739. $XDeode = new XDeode ( 5 );
  1740. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  1741. $iid = $XDeode->decode ( $iid );
  1742. if (! is_numeric ( $iid ))
  1743. die ( 'illegal request' );
  1744. Doo::loadModel ( 'invoice' );
  1745. $invoice = new invoice ();
  1746. Doo::loadModel ( 'invoiceOperationLog' );
  1747. $invoiceOperationLog = new invoiceOperationLog ();
  1748. $invoiceDetail = $invoice->getOne ( array (
  1749. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'] . ' and iid=' . $iid,
  1750. 'asArray' => true
  1751. ) );
  1752. if (empty ( $invoiceDetail ))
  1753. die ( 'illegal request' );
  1754. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  1755. $this->data ['invoiceDetail'] = $invoiceDetail;
  1756. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  1757. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  1758. $this->data ['memu'] = "invoice";
  1759. $this->data ['staff'] = $this->staff;
  1760. $this->data ['receiptMemu'] = 'invoiceApproval';
  1761. $this->render ( "/admin/invoiceApprovalDetail", $this->data );
  1762. }
  1763. /**
  1764. * 对发票进行审批,其中操作有终止,退回,同意动作。操作成功并记录下操作日志
  1765. *
  1766. * @since 1.0.0
  1767. * @var integer iid 开票ID 已加密
  1768. * @var integer status 发票审批状态
  1769. * @var integer opintion 审批发票的意见
  1770. * @return string 如操作成功返回审批首页
  1771. */
  1772. function invoiceApprovalDo() {
  1773. Doo::loadModel ( 'invoice' );
  1774. $invoice = new invoice ();
  1775. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  1776. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  1777. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  1778. $divApproval = $this->get_args ( 'divApproval' ) ? $this->get_args ( 'divApproval' ) : "";
  1779. $iid = $invoice->authcode ( $iid );
  1780. if (! is_numeric ( $iid ))
  1781. die ( 'illegal request' );
  1782. // && ! empty ( $opinion )
  1783. if (! empty ( $iid ) && ! empty ( $status )) {
  1784. if (! ($status == 2 || $status == 3 || $status == 4))
  1785. die ( 'illegal request' );
  1786. Doo::loadModel ( 'invoiceOperationLog' );
  1787. $invoiceOperationLog = new invoiceOperationLog ();
  1788. $invoiceDetail = $invoice->getOne ( array (
  1789. 'where' => 'status=1 and iid=' . $iid . ' and pendingApprovals=' . $this->staff [0] ['sid'],
  1790. 'asArray' => true
  1791. ) );
  1792. if (empty ( $invoiceDetail ))
  1793. die ( 'illegal request' );
  1794. $processApprovals = json_decode ( $invoiceDetail ['processApprovals'], true );
  1795. $invoiceManage = json_decode ( $invoiceDetail ['invoiceManage'], true );
  1796. if ($status == 3) {
  1797. $invoice->status = $status;
  1798. $item = array (
  1799. 'operation' => $opinion
  1800. );
  1801. } else {
  1802. if (empty ( $processApprovals )) {
  1803. $processApprovals = array (
  1804. $this->staff [0] ['sid'] => array (
  1805. 'date' => date ( "Y-m-d H:i:s" ),
  1806. 'opinion' => $opinion,
  1807. 'status' => $status
  1808. )
  1809. );
  1810. // var_dump(next($invoiceManage));
  1811. $nextInvoiceManage = next ( $invoiceManage );
  1812. // print_r($nextInvoiceManage);
  1813. if ($status != 4 && $nextInvoiceManage !== false)
  1814. $invoice->pendingApprovals = $nextInvoiceManage [0];
  1815. $invoice->processApprovals = json_encode ( $processApprovals );
  1816. // var_dump($invoice);
  1817. // print_r($invoiceManage);
  1818. } else {
  1819. $processApprovals [$this->staff [0] ['sid']] = array (
  1820. 'date' => date ( "Y-m-d H:i:s" ),
  1821. 'opinion' => $opinion,
  1822. 'status' => $status
  1823. );
  1824. $pendingApprovals = 0;
  1825. foreach ( $invoiceManage as $key => $value ) {
  1826. if ($value [0] == $this->staff [0] ['sid']) {
  1827. if (isset ( $invoiceManage [$key + 1] ))
  1828. $pendingApprovals = $invoiceManage [$key + 1] [0];
  1829. break;
  1830. }
  1831. }
  1832. if ($status != 4 && ! empty ( $pendingApprovals ))
  1833. $invoice->pendingApprovals = $pendingApprovals;
  1834. $invoice->processApprovals = json_encode ( $processApprovals );
  1835. }
  1836. $item = array (
  1837. 'operation' => $opinion
  1838. );
  1839. if (count ( $processApprovals ) == count ( $invoiceManage ) && $status != 4) {
  1840. $invoice->status = $status;
  1841. $invoice->pendingApprovals = 0;
  1842. $invoice->approvalTime = date ( "Y-m-d H:i:s" );
  1843. } elseif ($status == 4) {
  1844. $invoice->status = $status;
  1845. $item = array (
  1846. 'operation' => $opinion
  1847. );
  1848. }
  1849. }
  1850. $invoice->updateTime = date ( "Y-m-d H:i:s" );
  1851. $invoice->update ( array (
  1852. 'where' => 'iid=' . $iid
  1853. ) );
  1854. $item += array (
  1855. 'date' => date ( "Y-m-d H:i:s" ),
  1856. 'img' => $this->staff [0] ['avatar'],
  1857. 'username' => $this->staff [0] ['username'],
  1858. 'uid' => $this->staff [0] ['sid'],
  1859. 'category' => $this->staff [0] ['category'],
  1860. 'status' => $status,
  1861. 'iid' => $iid
  1862. );
  1863. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1864. if (empty ( $divApproval ))
  1865. return '/invoiceApproval';
  1866. else
  1867. return '/invoiceApprovalAchieve/PEND';
  1868. }
  1869. die ( 'illegal request' );
  1870. }
  1871. /**
  1872. * 展示需要打印的发票数据
  1873. *
  1874. * @since 1.0.0
  1875. */
  1876. function invoicePrint() {
  1877. Doo::loadModel ( 'invoice' );
  1878. $invoice = new invoice ();
  1879. Doo::loadClass ( 'XDeode' );
  1880. $XDeode = new XDeode ( 5 );
  1881. Doo::loadModel ( 'staff' );
  1882. $staff = new staff ();
  1883. $toPrint = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0 );
  1884. $printed = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 1 );
  1885. foreach ( $toPrint as $key => $value ) {
  1886. $toPrint [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1887. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1888. if (! empty ( $lastApprover )) {
  1889. $lastApproverKey = array_keys ( $lastApprover );
  1890. $lastApprover = end ( $lastApprover );
  1891. $staffDetail = $staff->getOne ( array (
  1892. 'where' => 'sid=' . end ( $lastApproverKey ),
  1893. 'asArray' => true
  1894. ) );
  1895. $lastApprover ['username'] = $staffDetail ['username'];
  1896. }
  1897. $toPrint [$key] ['lastApprover'] = $lastApprover;
  1898. }
  1899. foreach ( $printed as $key => $value ) {
  1900. $printed [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1901. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1902. if (! empty ( $lastApprover )) {
  1903. $lastApproverKey = array_keys ( $lastApprover );
  1904. $lastApprover = end ( $lastApprover );
  1905. $staffDetail = $staff->getOne ( array (
  1906. 'where' => 'sid=' . end ( $lastApproverKey ),
  1907. 'asArray' => true
  1908. ) );
  1909. $lastApprover ['username'] = $staffDetail ['username'];
  1910. }
  1911. $printed [$key] ['lastApprover'] = $lastApprover;
  1912. }
  1913. $this->data ['printed'] = $printed;
  1914. $this->data ['toPrint'] = $toPrint;
  1915. $this->data ['memu'] = "invoice";
  1916. $this->data ['staff'] = $this->staff;
  1917. $this->data ['receiptMemu'] = 'invoicePrint';
  1918. $this->render ( "/admin/invoicePrint", $this->data );
  1919. }
  1920. /**
  1921. * 展示发票打印的详情页面
  1922. *
  1923. * @since 1.0.0
  1924. */
  1925. function invoicePrintDetail() {
  1926. Doo::loadClass ( 'XDeode' );
  1927. $XDeode = new XDeode ( 5 );
  1928. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  1929. $iid = $XDeode->decode ( $iid );
  1930. if (! is_numeric ( $iid ))
  1931. die ( 'illegal request' );
  1932. Doo::loadModel ( 'invoice' );
  1933. $invoice = new invoice ();
  1934. Doo::loadModel ( 'invoiceOperationLog' );
  1935. $invoiceOperationLog = new invoiceOperationLog ();
  1936. Doo::loadModel ( 'invoicePaper' );
  1937. $invoicePaper = new invoicePaper ();
  1938. $invoiceDetail = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0, $iid );
  1939. if (empty ( $invoiceDetail ))
  1940. die ( 'illegal request' );
  1941. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $invoiceDetail ['invoiceType'] );
  1942. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  1943. $this->data ['invoicePaperList'] = $invoicePaperList;
  1944. $this->data ['invoiceDetail'] = $invoiceDetail;
  1945. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  1946. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  1947. $this->data ['memu'] = "invoice";
  1948. $this->data ['staff'] = $this->staff;
  1949. $this->data ['receiptMemu'] = 'invoicePrint';
  1950. $this->render ( "/admin/invoicePrintDetail", $this->data );
  1951. }
  1952. /**
  1953. * 所有待打印 发票
  1954. */
  1955. function invoicePrintStayAchieve() {
  1956. Doo::loadModel ( 'invoice' );
  1957. $invoice = new invoice ();
  1958. Doo::loadClass ( 'XDeode' );
  1959. $XDeode = new XDeode ( 5 );
  1960. Doo::loadModel ( 'staff' );
  1961. $staff = new staff ();
  1962. $MebSea = $this->get_args ( 'MebSea' ) ? urldecode ( $this->get_args ( 'MebSea' ) ) : "";
  1963. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  1964. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  1965. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  1966. Doo::loadModel ( 'invoiceTraining' );
  1967. $invoiceTraining = new invoiceTraining ();
  1968. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  1969. $page_size = 12;
  1970. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  1971. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : "ALL";
  1972. // $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : "ALL";
  1973. $get = "/" . $status;
  1974. $con = ' and status=2 ';
  1975. if ($status == 'TOPRINT')
  1976. $con = ' and status=2 and printStatus=0 ';
  1977. elseif ($status == 'PRINTED')
  1978. $con = ' and status=2 and printStatus=1';
  1979. if ($invoiceType == 'ORDINARY')
  1980. $con .= ' and invoiceType=0 ';
  1981. elseif ($invoiceType == 'SPECIAL')
  1982. $con .= ' and invoiceType=1 ';
  1983. if ($invoiceTrain == 'ORDINARY')
  1984. $con .= ' and trainId=0 ';
  1985. elseif ($invoiceTrain == 'TRAIN')
  1986. $con .= ' and trainId!=0 ';
  1987. if ($invoiceTrainName != 'ALL') {
  1988. $trainId = $XDeode->decode ( $invoiceTrainName );
  1989. if (is_numeric ( $trainId ))
  1990. $con .= ' and trainId =' . $trainId;
  1991. }
  1992. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  1993. $dateArr = explode ( ':', $date );
  1994. $D1 = '';
  1995. $D2 = '';
  1996. if (! empty ( $date )) {
  1997. $D1 = $dateArr [0];
  1998. $D2 = $dateArr [1];
  1999. }
  2000. if (! empty ( $D1 ) && ! empty ( $D2 ) && ! empty ( $date ))
  2001. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2002. if (! empty ( $MebSea )) {
  2003. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  2004. }
  2005. $pageinfo ['page'] = array (
  2006. 'previous' => ''
  2007. );
  2008. $get .= "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  2009. $sql = " (untreadStatus=0 or untreadStatus=3) and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  2010. $action = "invoicePrintStayAchieve";
  2011. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2012. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2013. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  2014. $this->data ['trainList'] = $trainList;
  2015. $this->data ['invoiceType'] = $invoiceType;
  2016. $this->data ['invoiceTrain'] = $invoiceTrain;
  2017. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  2018. $this->data ['MebSeaEn'] = $MebSea;
  2019. $this->data ['MebSea'] = urlencode ( $MebSea );
  2020. $this->data ['get'] = $get;
  2021. $this->data ['page'] = $pageinfo;
  2022. $this->data ['date'] = $date;
  2023. $this->data ['status'] = $status;
  2024. $this->data ['memu'] = "invoice";
  2025. $this->data ['staff'] = $this->staff;
  2026. foreach ( $list as $key => $value ) {
  2027. $list [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2028. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2029. if (! empty ( $lastApprover )) {
  2030. $lastApproverKey = array_keys ( $lastApprover );
  2031. $lastApprover = end ( $lastApprover );
  2032. $staffDetail = $staff->getOne ( array (
  2033. 'where' => 'sid=' . end ( $lastApproverKey ),
  2034. 'asArray' => true
  2035. ) );
  2036. $lastApprover ['username'] = $staffDetail ['username'];
  2037. }
  2038. $list [$key] ['lastApprover'] = $lastApprover;
  2039. }
  2040. $this->data ['receiptMemu'] = 'invoicePrint';
  2041. $this->data ['list'] = $list;
  2042. $this->render ( "/admin/invoicePrintStayAchieve", $this->data );
  2043. }
  2044. /**
  2045. * 填写票号并完成打印
  2046. * @since 1.0.0
  2047. */
  2048. function invoicePrintDo() {
  2049. Doo::loadModel ( 'invoice' );
  2050. $invoice = new invoice ();
  2051. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2052. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  2053. $invoicePrintType = $this->get_args ( 'invoicePrintType' ) ? $this->get_args ( 'invoicePrintType' ) : "";
  2054. $iid = $invoice->authcode ( $iid );
  2055. if (! is_numeric ( $iid ))
  2056. die ( 'illegal request' );
  2057. if (! empty ( $iid ) && ! empty ( $invoiceNo )) {
  2058. Doo::loadModel ( 'invoiceOperationLog' );
  2059. $invoiceOperationLog = new invoiceOperationLog ();
  2060. Doo::loadModel ( 'invoiceStatistics' );
  2061. $invoiceStatistics = new invoiceStatistics ();
  2062. $XDeode = new XDeode ( 5 );
  2063. Doo::loadModel ( 'invoicePaper' );
  2064. $invoicePaper = new invoicePaper ();
  2065. $invoicePrintDetail = $invoice->getInvoiceByPrint ( $iid );
  2066. if (empty ( $invoicePrintDetail ))
  2067. die ( 'illegal request' );
  2068. //
  2069. $ipid = $XDeode->decode ( $invoiceNo );
  2070. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  2071. if (empty ( $paperDetail ))
  2072. die ( 'illegal request' );
  2073. $invoicePaper = new invoicePaper ();
  2074. $item = array (
  2075. 'iid' => $iid,
  2076. 'ipid' => $ipid
  2077. );
  2078. $invoicePaper->setInvoicePaperByCondition ( $item );
  2079. $item = array (
  2080. 'iid' => $iid,
  2081. 'printStatus' => 1,
  2082. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2083. 'printer' => $this->staff [0] ['username'],
  2084. 'printTime' => date ( "Y-m-d H:i:s" ),
  2085. 'invoiceNo' => $paperDetail ['invoiceNo']
  2086. );
  2087. $invoice->setInvoiceByCondition ( $item );
  2088. $item = array (
  2089. 'date' => date ( "Y-m-d H:i:s" ),
  2090. 'operation' => '打印发票号:' . $paperDetail ['invoiceNo'],
  2091. 'status' => 5,
  2092. 'img' => $this->staff [0] ['avatar'],
  2093. 'username' => $this->staff [0] ['username'],
  2094. 'uid' => $this->staff [0] ['sid'],
  2095. 'category' => $this->staff [0] ['category'],
  2096. 'iid' => $iid
  2097. );
  2098. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2099. // 去统计--负票不汇总
  2100. if ($invoicePrintDetail ['untreadStatus'] != 4) {
  2101. $item = array (
  2102. 'date' => date ( "Y-m-d H:i:s" ),
  2103. 'priceClass' => 1,
  2104. 'cid' => $invoicePrintDetail ['cid'],
  2105. 'staff' => $invoicePrintDetail ['sid'],
  2106. 'invoicePrice' => $invoicePrintDetail ['invoicePrice']
  2107. );
  2108. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2109. }
  2110. // 发送通知信息到微信-去除
  2111. // $this->setWXMsg($iid,'PRINT');
  2112. // 申请人获取微信通知
  2113. Doo::loadModel ( 'staff' );
  2114. $staff = new staff ();
  2115. Doo::loadClass ( 'XDeode' );
  2116. $XDeode = new XDeode ( 5 );
  2117. $username2 = $staff->getOne ( array (
  2118. 'select' => 'wxid',
  2119. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2120. 'asArray' => TRUE
  2121. ) );
  2122. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '完成打印';
  2123. $msg = '';
  2124. $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/' . $XDeode->encode ( $invoicePrintDetail ['iid'] ) . '.html';
  2125. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2126. if (empty ( $invoicePrintType ))
  2127. return "/invoicePrint";
  2128. else
  2129. return "/invoicePrintStayAchieve";
  2130. }
  2131. }
  2132. /**
  2133. * 需要邮寄的发票
  2134. * @since 1.0.0
  2135. */
  2136. function invoicePost() {
  2137. Doo::loadModel ( 'invoice' );
  2138. $invoice = new invoice ();
  2139. Doo::loadModel ( 'express' );
  2140. $express = new express ();
  2141. $invoicePost = $invoice->getPostByInvoice ();
  2142. $invoicePosted = $invoice->getPostByInvoice ( 1 );
  2143. $expressList = $express->getExpressByAll ();
  2144. $invoicePostExpress = "";
  2145. if (isset ( $_COOKIE ["invoicePostExpress"] ))
  2146. $invoicePostExpress = $_COOKIE ["invoicePostExpress"];
  2147. $this->data ['invoicePostExpress'] = $invoicePostExpress;
  2148. $this->data ['expressList'] = $expressList;
  2149. $this->data ['invoicePost'] = $invoicePost;
  2150. $this->data ['invoicePosted'] = $invoicePosted;
  2151. $this->data ['memu'] = "invoice";
  2152. $this->data ['staff'] = $this->staff;
  2153. $this->data ['receiptMemu'] = 'invoicePost';
  2154. $this->render ( "/admin/invoicePost", $this->data );
  2155. }
  2156. /**
  2157. * 添加发票邮寄信息
  2158. */
  2159. function invoiceExpressAddDo() {
  2160. Doo::loadModel ( 'invoice' );
  2161. $invoice = new invoice ();
  2162. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2163. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2164. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2165. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2166. $iid = $iid = $invoice->authcode ( $iid );
  2167. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2168. die ( 'illegal request' );
  2169. $invoicePrintDetail = $invoice->getInvoiceByIid ( $iid );
  2170. setcookie ( 'invoicePostExpress', $expressNumber );
  2171. $item = array (
  2172. 'iid' => $iid,
  2173. 'postStatus' => 1,
  2174. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2175. 'postTime' => date ( "Y-m-d H:i:s" ),
  2176. 'expressCompany' => $expressCompany,
  2177. 'expressNumber' => $expressNumber,
  2178. 'actualItems' => $actualItems,
  2179. 'poster' => $this->staff [0] ['username']
  2180. );
  2181. $invoice->setInvoiceByCondition ( $item );
  2182. // 微信通知-去掉
  2183. // $this->setWXMsg ( $iid );
  2184. Doo::loadModel ( 'staff' );
  2185. $staff = new staff ();
  2186. Doo::loadClass ( 'XDeode' );
  2187. $XDeode = new XDeode ( 5 );
  2188. $username2 = $staff->getOne ( array (
  2189. 'select' => 'wxid',
  2190. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2191. 'asArray' => TRUE
  2192. ) );
  2193. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '已邮寄';
  2194. $expCom = explode ( ":", $invoicePrintDetail ['expressCompany'] );
  2195. if (empty ( $expCom ))
  2196. $expCom [0] = '';
  2197. $msg = $expCom [0] . ':' . $invoicePrintDetail ['expressNumber'] . '';
  2198. $url = 'https://m.kuaidi100.com/result.jsp?nu=' . $invoicePrintDetail ['expressNumber'];
  2199. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2200. return '/invoicePost';
  2201. }
  2202. function invoiceExpressUpdateDo() {
  2203. Doo::loadModel ( 'invoice' );
  2204. $invoice = new invoice ();
  2205. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  2206. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2207. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2208. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2209. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2210. $iid = $invoice->authcode ( $iid );
  2211. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2212. die ( 'illegal request' );
  2213. $item = array (
  2214. 'iid' => $iid,
  2215. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2216. 'expressCompany' => $expressCompany,
  2217. 'expressNumber' => $expressNumber,
  2218. 'actualItems' => $actualItems,
  2219. 'poster' => $this->staff [0] ['username']
  2220. );
  2221. $invoice->setInvoiceByCondition ( $item );
  2222. return $action;
  2223. }
  2224. /**
  2225. * 可退票管理
  2226. */
  2227. function invoiceUntreadIsAchieve() {
  2228. Doo::loadModel ( 'invoice' );
  2229. $invoice = new invoice ();
  2230. Doo::loadClass ( 'XDeode' );
  2231. $XDeode = new XDeode ( 5 );
  2232. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2233. $page_size = 18;
  2234. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2235. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2236. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  2237. $dateArr = explode ( ':', $date );
  2238. $D1 = '';
  2239. $D2 = '';
  2240. if (! empty ( $date )) {
  2241. $D1 = $dateArr [0];
  2242. $D2 = $dateArr [1];
  2243. }
  2244. $con = '';
  2245. if (! empty ( $D1 ) && ! empty ( $D2 ))
  2246. $con = ' and bindTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2247. // if ($date == 'MONTHO')
  2248. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  2249. // elseif ($date == 'MONTHT')
  2250. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  2251. // elseif ($date == 'MONTHY')
  2252. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  2253. if (! empty ( $MebSea )) {
  2254. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  2255. }
  2256. $pageinfo ['page'] = array (
  2257. 'previous' => ''
  2258. );
  2259. // printStatus=1 and
  2260. $sql = " (untreadStatus=0 or untreadStatus=3) and status=2 and sid=" . $this->staff [0] ['sid'] . $con;
  2261. $action = "invoiceUntreadIsAchieve";
  2262. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2263. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2264. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2265. // print_r($list);
  2266. $this->data ['MebSeaEn'] = $MebSea;
  2267. // $this->data ['MebSea'] = urlencode ( $MebSea );
  2268. $this->data ['get'] = $get;
  2269. $this->data ['page'] = $pageinfo;
  2270. $this->data ['date'] = $date;
  2271. $this->data ['list'] = $list;
  2272. $this->data ['memu'] = "invoice";
  2273. $this->data ['staff'] = $this->staff;
  2274. $this->data ['receiptMemu'] = 'invoice';
  2275. $this->render ( "/admin/invoiceUntreadIsAchieve", $this->data );
  2276. }
  2277. /**
  2278. * 退票处理页面
  2279. */
  2280. function invoiceUntread() {
  2281. Doo::loadModel ( 'invoice' );
  2282. $invoice = new invoice ();
  2283. $untreadInvoice = $invoice->getInvoiceByUntreadStatus ( 1 );
  2284. $establishedInvoice = $invoice->getInvoiceByUntreadStatus ( 2 );
  2285. foreach ( $establishedInvoice as $key => $value ) {
  2286. // months
  2287. $lossDate = strtotime ( "+1 month", strtotime ( $value ['OperationLog'] ['date'] ) );
  2288. $nowDate = strtotime ( 'now' );
  2289. $establishedInvoice [$key] ['lossShow'] = false;
  2290. if ($lossDate < $nowDate)
  2291. $establishedInvoice [$key] ['lossShow'] = true;
  2292. }
  2293. $this->data ['untreadInvoice'] = $untreadInvoice;
  2294. $this->data ['establishedInvoice'] = $establishedInvoice;
  2295. $this->data ['memu'] = "invoice";
  2296. $this->data ['staff'] = $this->staff;
  2297. $this->data ['receiptMemu'] = 'invoiceUntread';
  2298. $this->render ( "/admin/invoiceUntread", $this->data );
  2299. }
  2300. /**
  2301. * 确认收到退回的发票,开票状态为退回 //收款状态解绑,公司统计扣除入账额度
  2302. */
  2303. function invoiceUntreadEstablishedDo() {
  2304. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  2305. Doo::loadModel ( 'invoice' );
  2306. $invoice = new invoice ();
  2307. Doo::loadModel ( 'invoiceOperationLog' );
  2308. $invoiceOperationLog = new invoiceOperationLog ();
  2309. Doo::loadModel ( 'invoiceReceivables' );
  2310. Doo::loadModel ( 'invoiceStatistics' );
  2311. $iid = $invoice->authcode ( $untreadIidKey );
  2312. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2313. die ( 'illegal request' );
  2314. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  2315. if ($invoiceDetails ['untreadStatus'] != 1)
  2316. die ( 'illegal request' );
  2317. $item = array (
  2318. 'iid' => $iid,
  2319. // 'irid'=>'',
  2320. 'untreadStatus' => 2,
  2321. 'updateTime' => date ( "Y-m-d H:i:s" )
  2322. );
  2323. $invoice->setInvoiceByCondition ( $item );
  2324. $item = array (
  2325. 'date' => date ( "Y-m-d H:i:s" ),
  2326. 'operation' => '已确认退票',
  2327. 'status' => 6,
  2328. 'img' => $this->staff [0] ['avatar'],
  2329. 'username' => $this->staff [0] ['username'],
  2330. 'uid' => $this->staff [0] ['sid'],
  2331. 'category' => $this->staff [0] ['category'],
  2332. 'iid' => $iid
  2333. );
  2334. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2335. // 收款解绑以及入账扣除 收款扣除
  2336. if (! empty ( $invoiceDetails ['irid'] )) {
  2337. $iridList = explode ( ',', $invoiceDetails ['irid'] );
  2338. foreach ( $iridList as $value ) {
  2339. $invoiceReceivables = new invoiceReceivables ();
  2340. $irDetails = $invoiceReceivables->getOne ( array (
  2341. 'where' => " irid=" . $value . ' and bindStatus=1',
  2342. 'asArray' => TRUE
  2343. ) );
  2344. $item = array (
  2345. 'irid' => $value,
  2346. 'bindStatus' => 0,
  2347. 'untreadStatus' => 1,
  2348. 'untreadStaff' => $invoiceDetails ['userName'],
  2349. 'unbundlingTime' => date ( "Y-m-d H:i:s" ),
  2350. 'iid' => 0
  2351. );
  2352. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2353. if (! empty ( $irDetails )) {
  2354. // 扣除入账
  2355. $invoiceStatistics = new invoiceStatistics ();
  2356. $item = array (
  2357. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2358. 'priceClass' => 3,
  2359. 'cid' => $invoiceDetails ['cid'],
  2360. 'staff' => $invoiceDetails ['sid'],
  2361. 'accountPrice' => - $irDetails ['receivablesPrice']
  2362. );
  2363. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2364. // 扣除收款
  2365. $invoiceStatistics = new invoiceStatistics ();
  2366. $item = array (
  2367. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2368. 'priceClass' => 2,
  2369. 'cid' => $invoiceDetails ['cid'],
  2370. 'staff' => $invoiceDetails ['sid'],
  2371. 'irid' => $irDetails ['irid'],
  2372. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  2373. );
  2374. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2375. }
  2376. //解绑时删除收入流水
  2377. Doo::loadModel ( 'wasteBook' );
  2378. $wasteBook = new wasteBook ();
  2379. $wasteBook->delete ( array (
  2380. 'where' => 'dataID=' . $value.' and accountType=7',
  2381. 'limit' => 1
  2382. ) );
  2383. }
  2384. }
  2385. return "/invoiceUntread";
  2386. }
  2387. /**
  2388. * 建立负票,关联原来发票
  2389. */
  2390. function invoiceLossDo() {
  2391. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2392. if (! empty ( $iidKey )) {
  2393. Doo::loadClass ( 'XDeode' );
  2394. $XDeode = new XDeode ( 5 );
  2395. Doo::loadModel ( 'invoice' );
  2396. $invoice = new invoice ();
  2397. Doo::loadModel ( 'invoiceOperationLog' );
  2398. $invoiceOperationLog = new invoiceOperationLog ();
  2399. $iidKey = $XDeode->decode ( $iidKey );
  2400. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  2401. // 拷贝插入一条发票数据
  2402. $iid = $invoice->setInvoiceLoss ( $iidKey );
  2403. // 更新负票
  2404. $invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  2405. $invoice = new invoice ();
  2406. $item = array (
  2407. 'iid' => $iid,
  2408. 'sid' => $this->staff [0] ['sid'],
  2409. 'userName' => $this->staff [0] ['username'],
  2410. 'cid' => $this->staff [0] ['cid'],
  2411. 'categoryName' => $this->staff [0] ['category'],
  2412. 'invoiceQuantity' => - $invoiceDetail ['invoiceQuantity'],
  2413. 'invoicePrice' => - $invoiceDetail ['invoicePrice'],
  2414. 'invoiceSerial' => $invoiceSerial,
  2415. 'invoiceNo' => '',
  2416. 'printStatus' => 0,
  2417. 'untreadStatus' => 4,
  2418. // 关联发票号
  2419. 'lossIid' => $invoiceDetail ['iid']
  2420. );
  2421. $invoice->setInvoiceByCondition ( $item );
  2422. // 更新原发票
  2423. $invoice = new invoice ();
  2424. $item = array (
  2425. 'iid' => $invoiceDetail ['iid'],
  2426. 'lossIid' => $iid
  2427. );
  2428. $invoice->setInvoiceByCondition ( $item );
  2429. // 操作日志
  2430. $item = array (
  2431. 'date' => date ( "Y-m-d H:i:s" ),
  2432. 'operation' => "创建负票" . $invoiceSerial,
  2433. 'status' => 12,
  2434. 'img' => $this->staff [0] ['avatar'],
  2435. 'username' => $this->staff [0] ['username'],
  2436. 'uid' => $this->staff [0] ['sid'],
  2437. 'category' => $this->staff [0] ['category'],
  2438. 'iid' => $iid
  2439. );
  2440. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2441. // print_r($invoiceDetail);
  2442. // echo $iid;die;
  2443. }
  2444. return '/invoiceUntread';
  2445. }
  2446. /**
  2447. * 上传银行到账 收款文件
  2448. */
  2449. function invoiceReceivablesBankUpload() {
  2450. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  2451. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  2452. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  2453. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  2454. header ( "HTTP/1.1 500 Internal Server Error" );
  2455. echo "POST exceeded maximum allowed size.";
  2456. exit ( 0 );
  2457. }
  2458. // Settings
  2459. $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)
  2460. $upload_name = "Filedata";
  2461. $file_name = "";
  2462. $nk = time ();
  2463. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  2464. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  2465. echo "文件无法保存.";
  2466. exit ( 0 );
  2467. }
  2468. echo json_encode ( array (
  2469. 'filename' => $file_name,
  2470. 'id' => $nk
  2471. ) );
  2472. exit ( 0 );
  2473. }
  2474. /**
  2475. * 解析银行到账收款execl并导入库中
  2476. */
  2477. function invoiceReceivablesImport() {
  2478. $path = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  2479. if ($path != "") {
  2480. Doo::loadModel ( 'invoiceReceivables' );
  2481. $invoiceReceivables = new invoiceReceivables ();
  2482. Doo::loadClass ( 'invoice.func' );
  2483. Doo::loadModel ( 'invoiceROLog' );
  2484. $invoiceROLog = new invoiceROLog ();
  2485. Doo::loadModel ( 'invoiceStatistics' );
  2486. $invoiceStatistics = new invoiceStatistics ();
  2487. $exlArray = formatExcelToArrayBank ( DOO::conf ()->SITE_PATH . "upload/invoiceReceivablesBank/" . $path );
  2488. $bankBatchNumber = 'BBN_' . time ();
  2489. Doo::db ()->beginTransaction ();
  2490. // 批量存储收款--由于必须获得收款ID,
  2491. $sql = 'INSERT INTO CLD_invoiceReceivables (OriginalPrice,receivablesPrice, receivablesMessage,receivablesSerial,receivablesBank,receivablesDate,inputStaff,date,receivablesCategory,receivablesStaff,bankBatchNumber,recepitTitleMark)
  2492. VALUES ';
  2493. $date = date ( "Y-m-d" );
  2494. $receivablesList = array ();
  2495. foreach ( $exlArray as $key => $value ) {
  2496. $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"] . '")';
  2497. array_push ( $receivablesList, $receivablesSql );
  2498. }
  2499. $sql = $sql . implode ( ',', $receivablesList );
  2500. // echo $sql;
  2501. Doo::db ()->query ( $sql );
  2502. // 批量存储收款统计
  2503. // 获得刚刚导入数据的irid组-缺少办事处和人员
  2504. $iridList = $invoiceReceivables->getInvoiceReceivablesByBBN ( $bankBatchNumber );
  2505. // 没有irid 回滚所有操作
  2506. if (empty ( $iridList )) {
  2507. Doo::db ()->rollBack ();
  2508. header ( 'Content-Type:text/html;charset=utf-8' );
  2509. die ( '文档或数据不正确,请重新<a href="/invoiceReceivables">上传</a>.' );
  2510. }
  2511. $sql = 'INSERT INTO CLD_invoiceStatistics (date, priceClass,irid,receivablesPrice)
  2512. VALUES ';
  2513. $statisticsList = array ();
  2514. foreach ( $iridList as $value ) {
  2515. $statisticsSql = '("' . $date . '",2,' . $value ['irid'] . ',' . $value ["receivablesPrice"] . ')';
  2516. array_push ( $statisticsList, $statisticsSql );
  2517. }
  2518. $sql = $sql . implode ( ',', $statisticsList );
  2519. Doo::db ()->query ( $sql );
  2520. // 批量存储操作日志
  2521. $sql = 'INSERT INTO CLD_invoiceROLog (operation, date,status,img, username,uid,category,irid)
  2522. VALUES ';
  2523. $ROLogList = array ();
  2524. foreach ( $iridList as $value ) {
  2525. $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'] . '")';
  2526. array_push ( $ROLogList, $ROLogSql );
  2527. }
  2528. $sql = $sql . implode ( ',', $ROLogList );
  2529. Doo::db ()->query ( $sql );
  2530. Doo::db ()->commit ();
  2531. return "/invoiceReceivables";
  2532. }
  2533. echo 'no file';
  2534. }
  2535. function invoiceReceivables() {
  2536. $invoiceTC = $this->get_args ( 'invoiceTC' ) ? $this->get_args ( 'invoiceTC' ) : '';
  2537. Doo::loadModel ( 'L_category' );
  2538. $lCategory = new L_category ();
  2539. Doo::loadModel ( 'staff' );
  2540. $staff = new staff ();
  2541. Doo::loadModel ( 'invoiceReceivables' );
  2542. $invoiceReceivables = new invoiceReceivables ();
  2543. Doo::loadModel ( 'invoice' );
  2544. $invoice = new invoice ();
  2545. Doo::loadClass ( 'XDeode' );
  2546. $XDeode = new XDeode ( 5 );
  2547. $category = $lCategory->getCategory ();
  2548. $staffList = $staff->getStaffByCid ( $this->staff [0] ['cid'] );
  2549. $sql = 'bindStatus=1 and iid!=0';
  2550. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByNew ( 4, $sql );
  2551. // 获取未入账发票
  2552. $invoiceUnAccount = $invoice->getInvoiceByUnAccount ( $invoiceTC );
  2553. $invoiceExistAccount = $invoice->getInvoiceByUnAccount ( '', true );
  2554. foreach ( $invoiceUnAccount as $key => $value ) {
  2555. $invoiceUnAccount [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2556. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2557. if (! empty ( $lastApprover )) {
  2558. $lastApproverKey = array_keys ( $lastApprover );
  2559. $lastApprover = end ( $lastApprover );
  2560. $staffDetail = $staff->getOne ( array (
  2561. 'where' => 'sid=' . end ( $lastApproverKey ),
  2562. 'asArray' => true
  2563. ) );
  2564. $lastApprover ['username'] = $staffDetail ['username'];
  2565. }
  2566. $invoiceUnAccount [$key] ['lastApprover'] = $lastApprover;
  2567. }
  2568. foreach ( $invoiceExistAccount as $key => $value ) {
  2569. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  2570. if (empty ( $irList ))
  2571. $irList [0] ['sumPrice'] = 0;
  2572. $balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  2573. $invoiceExistAccount [$key] ['existAccount'] = $irList [0] ['sumPrice'];
  2574. $invoiceExistAccount [$key] ['balance'] = $balance;
  2575. }
  2576. $receivablesInput = $invoiceReceivables->getInvoiceReceivablesByInput ();
  2577. $halfList = $invoiceReceivables->getInvoiceReceivablesByHalf ();
  2578. $this->data ['halfList'] = $halfList;
  2579. $this->data ['halfCount'] = count ( $halfList );
  2580. // print_r($receivablesList);
  2581. $this->data ['receivablesDate'] = date ( "Y-m-d" );
  2582. $this->data ['ieaCount'] = count ( $invoiceExistAccount );
  2583. $this->data ['invoiceExistAccount'] = $invoiceExistAccount;
  2584. $this->data ['receivablesInput'] = $receivablesInput;
  2585. $this->data ['year'] = date ( 'Y' );
  2586. $this->data ['invoiceUnAccount'] = $invoiceUnAccount;
  2587. $this->data ['receivablesList'] = $receivablesList;
  2588. $this->data ['staffList'] = $staffList;
  2589. $this->data ['category'] = $category;
  2590. $this->data ['memu'] = "invoice";
  2591. $this->data ['staff'] = $this->staff;
  2592. $this->data ['receiptMemu'] = 'invoiceReceivables';
  2593. $this->render ( "/admin/invoiceReceivables", $this->data );
  2594. }
  2595. /**
  2596. * 设置收款认领地区
  2597. */
  2598. function setInvoiceReceivablesClaim() {
  2599. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  2600. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  2601. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  2602. if (! empty ( $iridKey ) && ! empty ( $receivablesCategory )) {
  2603. Doo::loadModel ( 'invoiceReceivables' );
  2604. $invoiceReceivables = new invoiceReceivables ();
  2605. Doo::loadClass ( 'XDeode' );
  2606. $XDeode = new XDeode ( 5 );
  2607. Doo::loadModel ( 'invoiceROLog' );
  2608. $invoiceROLog = new invoiceROLog ();
  2609. $irid = $XDeode->decode ( $iridKey );
  2610. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  2611. if (empty ( $irDetail ))
  2612. die ( 'illegal request' );
  2613. $item = array (
  2614. 'irid' => $irid,
  2615. 'receivablesCategory' => $receivablesCategory
  2616. );
  2617. if ($receivablesCategory != 'PUBLIC') {
  2618. $item += array (
  2619. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  2620. 'inputType' => 1
  2621. );
  2622. }
  2623. $invoiceReceivables = new invoiceReceivables ();
  2624. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2625. // 收款操作日志
  2626. $item = array (
  2627. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 ",
  2628. 'date' => date ( "Y-m-d" ),
  2629. 'status' => 1,
  2630. 'img' => $this->staff [0] ['avatar'],
  2631. 'username' => $this->staff [0] ['username'],
  2632. 'uid' => $this->staff [0] ['sid'],
  2633. 'category' => $this->staff [0] ['category'],
  2634. 'irid' => $irid
  2635. );
  2636. $invoiceROLog->setInvoiceROLog ( $item );
  2637. if (empty ( $action ))
  2638. return '/invoiceReceivables';
  2639. else
  2640. return "/invoiceReceivablesAS";
  2641. }
  2642. die ( 'illegal request' );
  2643. }
  2644. /**
  2645. * 新添加收款直接入账发票
  2646. */
  2647. function invoiceCompareClaimPrice() {
  2648. // 收款录入
  2649. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2650. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  2651. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  2652. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  2653. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  2654. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $iidKey )) {
  2655. Doo::loadModel ( 'invoiceReceivables' );
  2656. $invoiceReceivables = new invoiceReceivables ();
  2657. Doo::loadModel ( 'invoiceROLog' );
  2658. $invoiceROLog = new invoiceROLog ();
  2659. Doo::loadModel ( 'invoiceStatistics' );
  2660. Doo::loadModel ( 'invoice' );
  2661. $invoice = new invoice ();
  2662. Doo::loadClass ( 'XDeode' );
  2663. $XDeode = new XDeode ( 5 );
  2664. Doo::loadModel ( 'invoiceOperationLog' );
  2665. $invoiceOperationLog = new invoiceOperationLog ();
  2666. $iidKey = $XDeode->decode ( $iidKey );
  2667. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  2668. if (! ($invoiceDetail ['status'] == 2 && $invoiceDetail ['printStatus'] == 1 && $invoiceDetail ['untreadStatus'] == 0))
  2669. die ( 'illegal request' );
  2670. $receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  2671. // 收款录入 并绑定发票
  2672. Doo::db ()->beginTransaction ();
  2673. $bindStatus = 0;
  2674. if ($receivablesPrice <= $invoiceDetail ['invoicePrice'])
  2675. $bindStatus = 1;
  2676. $item = array (
  2677. 'bindStatus' => $bindStatus,
  2678. 'iid' => $invoiceDetail ['iid'],
  2679. 'bindPrice' => $invoiceDetail ['invoicePrice'],
  2680. 'bindDate' => date ( "Y-m-d H:i:s" ),
  2681. 'receivablesPrice' => $receivablesPrice,
  2682. 'OriginalPrice' => $receivablesPrice,
  2683. 'receivablesMessage' => $receivablesMessage,
  2684. 'receivablesSerial' => $receivablesSerial,
  2685. 'receivablesBank' => $receivablesBank,
  2686. 'receivablesDate' => $receivablesDate,
  2687. 'inputStaff' => $this->staff [0] ['username'],
  2688. 'accountClerk' => $this->staff [0] ['username'],
  2689. 'date' => date ( "Y-m-d" ),
  2690. 'receivablesCategory' => $invoiceDetail ['cid'] . ':' . $invoiceDetail ['categoryName'],
  2691. 'receivablesStaff' => $invoiceDetail ['sid'] . '-' . $invoiceDetail ['userName'],
  2692. 'confirmTime' => date ( "Y-m-d H:i:s" )
  2693. );
  2694. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  2695. $item = array ();
  2696. // 收款操作日志
  2697. $item = array (
  2698. 'operation' => $this->staff [0] ['username'] . " 转入 " . $invoiceDetail ['userName']
  2699. );
  2700. $item += array (
  2701. 'date' => date ( "Y-m-d" ),
  2702. 'status' => 1,
  2703. 'img' => $this->staff [0] ['avatar'],
  2704. 'username' => $this->staff [0] ['username'],
  2705. 'uid' => $this->staff [0] ['sid'],
  2706. 'category' => $this->staff [0] ['category'],
  2707. 'irid' => $irid
  2708. );
  2709. $invoiceROLog->setInvoiceROLog ( $item );
  2710. // 收款统计
  2711. $invoiceStatistics = new invoiceStatistics ();
  2712. $item = array (
  2713. 'date' => $receivablesDate,
  2714. 'priceClass' => 2,
  2715. 'irid' => $irid,
  2716. 'cid' => $invoiceDetail ['cid'],
  2717. 'staff' => $invoiceDetail ['sid'],
  2718. 'receivablesPrice' => $receivablesPrice
  2719. );
  2720. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2721. // 收款 入 发票
  2722. $detail = $invoiceDetail;
  2723. $iridString = "";
  2724. if (empty ( $detail ['irid'] ))
  2725. $iridString = $irid;
  2726. else
  2727. $iridString = $detail ['irid'] . ',' . $irid;
  2728. $item = array (
  2729. 'irid' => $iridString,
  2730. 'bindTime' => date ( "Y-m-d H:i:s" ),
  2731. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2732. 'iid' => $detail ['iid']
  2733. );
  2734. $invoiceReceivables = new invoiceReceivables ();
  2735. $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  2736. if ($detail ['invoicePrice'] <= $sum)
  2737. $item += array (
  2738. 'untreadStatus' => 3
  2739. );
  2740. $invoice->setInvoiceByCondition ( $item );
  2741. // 操作日志
  2742. $item = array (
  2743. 'date' => date ( "Y-m-d H:i:s" ),
  2744. 'operation' => "收款入账" . $receivablesSerial . "到发票" . $detail ['invoiceSerial'],
  2745. 'status' => 8,
  2746. 'img' => $this->staff [0] ['avatar'],
  2747. 'username' => $this->staff [0] ['username'],
  2748. 'uid' => $this->staff [0] ['sid'],
  2749. 'category' => $this->staff [0] ['category'],
  2750. 'iid' => $detail ['iid']
  2751. );
  2752. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2753. // 入账汇总
  2754. $invoiceStatistics = new invoiceStatistics ();
  2755. // $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $iridString );
  2756. // $accountPrice = 0;
  2757. // foreach ( $list as $key => $value ) {
  2758. // $accountPrice += $value ['receivablesPrice'];
  2759. // }
  2760. $item = array (
  2761. 'date' => $receivablesDate,
  2762. 'priceClass' => 3,
  2763. 'cid' => $invoiceDetail ['cid'],
  2764. 'staff' => $invoiceDetail ['sid'],
  2765. 'accountPrice' => $receivablesPrice
  2766. );
  2767. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2768. //公司流水记录
  2769. Doo::loadModel ( 'wasteBook' );
  2770. $wasteBook = new wasteBook ();
  2771. $abDetail = $wasteBook->getAccountBookByAid (2,7,$irid );
  2772. $accountBank='';
  2773. if ($receivablesBank=='纵横广发'){
  2774. $accountBank='CGBDeposit';
  2775. }elseif($receivablesBank=='纵横工行'){
  2776. $accountBank='ICBCDeposit';
  2777. }elseif($receivablesBank=='华润银行'){
  2778. $accountBank='HUADeposit';
  2779. }elseif($receivablesBank=='个人广发'){
  2780. $accountBank='PersonalDeposit';
  2781. }
  2782. //银行
  2783. if (empty($abDetail)){
  2784. $item = array (
  2785. 'dataID' => $irid,
  2786. 'expensesType' => 1,
  2787. 'accountType' => 7,
  2788. 'accountPrice'=>$receivablesPrice,
  2789. 'accountPriceShow'=>$receivablesPrice,
  2790. 'accountBank'=>$accountBank,
  2791. 'category'=>$this->staff[0]['category'],
  2792. 'cid'=>$this->staff[0]['cid'],
  2793. 'name'=>$this->staff[0]['username'],
  2794. 'sid'=>$this->staff[0]['sid'],
  2795. 'inputDate'=>date ( "Y-m-d H:i:s" )
  2796. );
  2797. $wasteBook->setAccountBookStatistics($item);
  2798. }
  2799. Doo::db ()->commit ();
  2800. }
  2801. return '/invoiceReceivables';
  2802. }
  2803. /**
  2804. * 录入收款数据
  2805. * @return string
  2806. */
  2807. function invoiceReceivablesDo() {
  2808. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  2809. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  2810. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  2811. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  2812. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  2813. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  2814. Doo::loadModel ( 'invoiceReceivables' );
  2815. $invoiceReceivables = new invoiceReceivables ();
  2816. Doo::loadModel ( 'invoiceROLog' );
  2817. $invoiceROLog = new invoiceROLog ();
  2818. Doo::loadModel ( 'invoiceStatistics' );
  2819. $invoiceStatistics = new invoiceStatistics ();
  2820. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $receivablesCategory ) && ! empty ( $receivablesStaff )) {
  2821. $item = array (
  2822. 'receivablesPrice' => $receivablesPrice,
  2823. 'OriginalPrice' => $receivablesPrice,
  2824. 'receivablesMessage' => $receivablesMessage,
  2825. 'receivablesSerial' => "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  2826. 'receivablesBank' => $receivablesBank,
  2827. 'receivablesDate' => $receivablesDate,
  2828. 'inputStaff' => $this->staff [0] ['username'],
  2829. 'date' => date ( "Y-m-d" ),
  2830. 'receivablesCategory' => $receivablesCategory,
  2831. 'receivablesStaff' => $receivablesStaff
  2832. );
  2833. if ($receivablesCategory != 'PUBLIC') {
  2834. $item += array (
  2835. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  2836. 'inputType' => 1
  2837. );
  2838. }
  2839. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  2840. $item = array ();
  2841. // 收款操作日志
  2842. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  2843. $item = array (
  2844. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  2845. );
  2846. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  2847. $item = array (
  2848. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  2849. );
  2850. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  2851. $receivablesStaff = explode ( '-', $receivablesStaff );
  2852. $item = array (
  2853. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  2854. );
  2855. }
  2856. $item += array (
  2857. 'date' => date ( "Y-m-d" ),
  2858. 'status' => 1,
  2859. 'img' => $this->staff [0] ['avatar'],
  2860. 'username' => $this->staff [0] ['username'],
  2861. 'uid' => $this->staff [0] ['sid'],
  2862. 'category' => $this->staff [0] ['category'],
  2863. 'irid' => $irid
  2864. );
  2865. $invoiceROLog->setInvoiceROLog ( $item );
  2866. $item = array (
  2867. 'date' => $receivablesDate,
  2868. 'priceClass' => 2,
  2869. 'irid' => $irid,
  2870. 'receivablesPrice' => $receivablesPrice
  2871. );
  2872. if ($receivablesCategory != 'PUBLIC') {
  2873. $receivablesCategory = explode ( ":", $receivablesCategory );
  2874. $item += array (
  2875. 'cid' => $receivablesCategory [0]
  2876. );
  2877. }
  2878. if ($receivablesStaff2 != 'PUBLIC') {
  2879. $receivablesStaff = explode ( "-", $receivablesStaff2 );
  2880. $item += array (
  2881. 'staff' => $receivablesStaff [0]
  2882. );
  2883. }
  2884. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2885. $toparty = $this->getWxidByCategory ( $receivablesCategory [1] );
  2886. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  2887. $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  2888. if ($toparty != 0)
  2889. $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  2890. }
  2891. return "/invoiceReceivables";
  2892. }
  2893. /**
  2894. * 收款认领页面-包括公共认领 办事处认领 最近已认领数据
  2895. */
  2896. function invoiceReceivablesClaim() {
  2897. Doo::loadModel ( 'invoiceReceivables' );
  2898. $invoiceReceivables = new invoiceReceivables ();
  2899. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  2900. $this->data ['receivablesList'] = $receivablesList;
  2901. $this->data ['memu'] = "invoice";
  2902. $this->data ['staff'] = $this->staff;
  2903. $this->data ['receiptMemu'] = 'invoiceReceivablesClaim';
  2904. $this->render ( "/admin/invoiceReceivablesClaim", $this->data );
  2905. }
  2906. function invoiceReceivablesTitleMarkSet() {
  2907. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  2908. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  2909. if (empty ( $iridKey ) || empty ( $recepitTitleMark ))
  2910. die ( 'illegal request' );
  2911. Doo::loadModel ( 'invoiceReceivables' );
  2912. $invoiceReceivables = new invoiceReceivables ();
  2913. Doo::loadClass ( 'XDeode' );
  2914. $XDeode = new XDeode ( 5 );
  2915. $irid = $XDeode->decode ( $iridKey );
  2916. if (! is_numeric ( $irid ))
  2917. die ( 'illegal request' );
  2918. $invoiceReceivables->recepitTitleMark = $recepitTitleMark;
  2919. $invoiceReceivables->update ( array (
  2920. 'where' => 'irid = ' . $irid
  2921. ) );
  2922. return '/invoiceReceivablesClaim';
  2923. }
  2924. /**
  2925. * 更新收款相关数据
  2926. */
  2927. function invoiceReceivablesUpdateClaim() {
  2928. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  2929. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  2930. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  2931. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  2932. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  2933. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  2934. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  2935. if (empty ( $claimKey ))
  2936. die ( 'illegal request' );
  2937. Doo::loadModel ( 'invoiceReceivables' );
  2938. $invoiceReceivables = new invoiceReceivables ();
  2939. Doo::loadModel ( 'invoiceROLog' );
  2940. $invoiceROLog = new invoiceROLog ();
  2941. $con = ' and iid=0 and bindStatus=0'; // and receivablesCategory!="PUBLIC" and receivablesStaff!="PUBLIC"
  2942. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  2943. if (empty ( $detail ))
  2944. die ( 'illegal request' );
  2945. $invoiceReceivables = new invoiceReceivables ();
  2946. $item = array (
  2947. 'irid' => $detail ['irid']
  2948. );
  2949. if ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  2950. $item += array (
  2951. 'confirmTime' => date ( "Y-m-d H:i:s" )
  2952. );
  2953. }
  2954. if (! empty ( $receivablesCategory ))
  2955. $item += array (
  2956. 'receivablesCategory' => $receivablesCategory
  2957. );
  2958. if (! empty ( $receivablesStaff ))
  2959. $item += array (
  2960. 'receivablesStaff' => $receivablesStaff
  2961. );
  2962. if (! empty ( $receivablesPrice ))
  2963. $item += array (
  2964. 'receivablesPrice' => $receivablesPrice
  2965. );
  2966. if (! empty ( $receivablesMessage ))
  2967. $item += array (
  2968. 'receivablesMessage' => $receivablesMessage
  2969. );
  2970. if (! empty ( $receivablesBank ))
  2971. $item += array (
  2972. 'receivablesBank' => $receivablesBank
  2973. );
  2974. if (! empty ( $receivablesDate ))
  2975. $item += array (
  2976. 'receivablesDate' => $receivablesDate
  2977. );
  2978. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2979. // 收款操作日志
  2980. $item = array ();
  2981. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  2982. $item = array (
  2983. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  2984. );
  2985. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  2986. $item = array (
  2987. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  2988. );
  2989. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  2990. $receivablesStaff = explode ( '-', $receivablesStaff );
  2991. $item = array (
  2992. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  2993. );
  2994. }
  2995. $item += array (
  2996. 'date' => date ( "Y-m-d" ),
  2997. 'status' => 1,
  2998. 'img' => $this->staff [0] ['avatar'],
  2999. 'username' => $this->staff [0] ['username'],
  3000. 'uid' => $this->staff [0] ['sid'],
  3001. 'category' => $this->staff [0] ['category'],
  3002. 'irid' => $detail ['irid']
  3003. );
  3004. $invoiceROLog->setInvoiceROLog ( $item );
  3005. return '/invoiceReceivablesAS';
  3006. }
  3007. function invoiceReceivablesDelete() {
  3008. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  3009. $skll = $this->get_args ( 'skll' ) ? $this->get_args ( 'skll' ) : "";
  3010. if ($skll != '删除到款')
  3011. die ( 'illegal request' );
  3012. if (empty ( $claimKey ))
  3013. die ( 'illegal request' );
  3014. Doo::loadModel ( 'invoiceReceivables' );
  3015. $invoiceReceivables = new invoiceReceivables ();
  3016. $con = ' and bindStatus=0 ';
  3017. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  3018. if (empty ( $detail ))
  3019. die ( 'illegal request' );
  3020. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  3021. // 扣除收款汇总信息 汇总
  3022. Doo::loadModel ( 'invoiceStatistics' );
  3023. $invoiceStatistics = new invoiceStatistics ();
  3024. $item = array (
  3025. 'date' => $detail ['receivablesDate'],
  3026. 'priceClass' => 2,
  3027. 'irid' => $detail ['irid'],
  3028. 'receivablesPrice' => - $detail ['receivablesPrice']
  3029. );
  3030. if ($detail ['receivablesCategory'] != 'PUBLIC') {
  3031. $receivablesCategory = explode ( ":", $detail ['receivablesCategory'] );
  3032. $item += array (
  3033. 'cid' => $receivablesCategory [0]
  3034. );
  3035. }
  3036. if ($detail ['receivablesStaff'] != 'PUBLIC') {
  3037. $receivablesStaff = explode ( "-", $detail ['receivablesStaff'] );
  3038. $item += array (
  3039. 'staff' => $receivablesStaff [0]
  3040. );
  3041. }
  3042. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3043. return '/invoiceReceivablesAS';
  3044. }
  3045. /**
  3046. * 管理员录入的收款 ,确认认领到谁的名下.统计收款金额
  3047. */
  3048. function invoiceReceivablesAscription() {
  3049. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  3050. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  3051. Doo::loadModel ( 'invoiceReceivables' );
  3052. $invoiceReceivables = new invoiceReceivables ();
  3053. Doo::loadModel ( 'invoiceROLog' );
  3054. $invoiceROLog = new invoiceROLog ();
  3055. Doo::loadModel ( 'invoiceStatistics' );
  3056. $invoiceStatistics = new invoiceStatistics ();
  3057. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  3058. if (! empty ( $detail ) && $detail ['receivablesStaff'] == 'PUBLIC' && ! empty ( $recepitTitleMark )) {
  3059. $item = array (
  3060. 'irid' => $detail ['irid'],
  3061. 'receivablesCategory' => $this->staff [0] ['cid'] . ":" . $this->staff [0] ['category'],
  3062. 'receivablesStaff' => $this->staff [0] ['sid'] . "-" . $this->staff [0] ['username'],
  3063. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3064. 'recepitTitleMark' => $recepitTitleMark,
  3065. 'source' => 1
  3066. );
  3067. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3068. $item = array (
  3069. 'date' => date ( "Y-m-d" ),
  3070. 'operation' => $this->staff [0] ['username'] . " 认领 ",
  3071. 'status' => 2,
  3072. 'img' => $this->staff [0] ['avatar'],
  3073. 'username' => $this->staff [0] ['username'],
  3074. 'uid' => $this->staff [0] ['sid'],
  3075. 'category' => $this->staff [0] ['category'],
  3076. 'irid' => $irid
  3077. );
  3078. $invoiceROLog->setInvoiceROLog ( $item );
  3079. $item = array (
  3080. 'cid' => $this->staff [0] ['cid'],
  3081. 'staff' => $this->staff [0] ['sid']
  3082. );
  3083. $invoiceStatistics->updateInvoiceStatisticsByIrid ( $item, $detail ['irid'], 2 );
  3084. }
  3085. return "/invoiceReceivablesClaim";
  3086. }
  3087. /**
  3088. */
  3089. function invoiceMyReceivables() {
  3090. Doo::loadModel ( 'invoiceReceivables' );
  3091. $invoiceReceivables = new invoiceReceivables ();
  3092. Doo::loadModel ( 'invoiceStatistics' );
  3093. $invoiceStatistics = new invoiceStatistics ();
  3094. $isMonth = $invoiceStatistics->getStatisticsByMonth ( $this->staff [0] ['sid'] );
  3095. $year = date ( "Y" );
  3096. $tmp_date = date ( "Ym" );
  3097. $tmp_year = substr ( $tmp_date, 0, 4 );
  3098. $tmp_mon = substr ( $tmp_date, 4, 2 );
  3099. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  3100. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  3101. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . ".htm";
  3102. $htm = $this->showCache ( $path );
  3103. $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  3104. $this->data ['isMonth'] = $isMonth;
  3105. $this->data ['htm'] = $htm;
  3106. $this->data ['list'] = $list;
  3107. $this->data ['memu'] = "invoice";
  3108. $this->data ['staff'] = $this->staff;
  3109. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  3110. $this->render ( "/admin/invoiceMyReceivables", $this->data );
  3111. }
  3112. /**
  3113. * 纸票管理
  3114. */
  3115. function invoicePaper() {
  3116. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3117. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3118. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3119. $this->data ['dateString'] = $date;
  3120. $this->data ['status'] = $status;
  3121. $this->data ['invoiceType'] = $invoiceType;
  3122. $this->data ['memu'] = "invoice";
  3123. $this->data ['staff'] = $this->staff;
  3124. $this->data ['receiptMemu'] = 'invoicePaper';
  3125. $this->render ( "/admin/invoicePaper", $this->data );
  3126. }
  3127. /**
  3128. * 获得纸票分页数据
  3129. */
  3130. function ajaxGetinvoicePaperAchieve() {
  3131. Doo::loadModel ( 'invoicePaper' );
  3132. $invoicePaper = new invoicePaper ();
  3133. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3134. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3135. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ORDINARY";
  3136. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3137. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  3138. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  3139. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  3140. $MebSea = $this->get_args ( 'search' );
  3141. $MebSea = $MebSea ['value'];
  3142. $page_size = $length;
  3143. $con = '';
  3144. if ($status == 'ALL')
  3145. $con = ' where 1 ';
  3146. elseif ($status == 'PRINTED')
  3147. $con = ' where b.isDelete=0 and b.status=2 and b.untreadStatus=0 and b.printStatus=1 ';
  3148. elseif ($status == 'UNPRINT')
  3149. $con = ' where b.isDelete=0 and b.status=2 and b.untreadStatus=0 and b.printStatus=0 ';
  3150. elseif ($status == 'TICKET')
  3151. $con = ' where b.isDelete=0 and b.untreadStatus=2';
  3152. if ($invoiceType == 'ORDINARY')
  3153. $con .= ' and a.invoiceType=0 ';
  3154. elseif ($invoiceType == 'SPECIAL')
  3155. $con .= ' and a.invoiceType=1 ';
  3156. $dateArr = explode ( ':', $date );
  3157. $D1 = $dateString = '';
  3158. $D2 = '';
  3159. if (! empty ( $date )) {
  3160. $D1 = $dateArr [0];
  3161. if (isset ( $dateArr [1] ))
  3162. $D2 = $dateArr [1];
  3163. else
  3164. $D2 = '';
  3165. $dateString = $D1 . " : " . $D2;
  3166. }
  3167. if (! empty ( $D1 ) && ! empty ( $D2 ))
  3168. $con .= ' and b.printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  3169. elseif (! empty ( $D1 ) && empty ( $D2 ))
  3170. $con .= ' and b.printTime like "%' . $D1 . '%" ';
  3171. if (! empty ( $MebSea ))
  3172. $con .= ' and ( b.invoiceTitle like "%' . $MebSea . '%" or b.invoiceCompany like "%' . $MebSea . '%" or a.invoiceNo like "%' . $MebSea . '%" )';
  3173. $invoiceTotal = $invoicePaper->getInvoicePaperCount ();
  3174. $sql = ' ' . $con;
  3175. $limit = $page . ',' . $page_size;
  3176. $list = $invoicePaper->getInvoicePaper ( $limit, $sql, 'desc' );
  3177. $paperList = array ();
  3178. foreach ( $list as $key => $value ) {
  3179. $irDetail = array ();
  3180. if ($value ['iid'] == 0)
  3181. array_push ( $irDetail, '<a href="javascript:if(window.confirm(\'确认删除?\'))window.location=\'/invoicePaperDel/' . $value ['ipidKey'] . '\'" >删除</a>' );
  3182. else
  3183. array_push ( $irDetail, '' );
  3184. array_push ( $irDetail, $value ['invoiceCode'] );
  3185. array_push ( $irDetail, $value ['invoiceNo'] );
  3186. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKey'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  3187. if ($value ['invoiceType'] == 1)
  3188. array_push ( $irDetail, $value ['invoiceCompany'] );
  3189. else
  3190. array_push ( $irDetail, $value ['invoiceTitle'] );
  3191. if ($value ['invoiceType'] == 1)
  3192. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  3193. else
  3194. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  3195. array_push ( $irDetail, $value ['invoiceElement'] );
  3196. array_push ( $irDetail, $value ['categoryName'] . '-' . $value ['userName'] );
  3197. array_push ( $irDetail, $value ['printTime'] );
  3198. array_push ( $paperList, $irDetail );
  3199. }
  3200. // $approvalListJson = json_encode ( $approvalList );
  3201. $recordsFiltered = $invoiceTotal;
  3202. echo json_encode ( array (
  3203. "draw" => intval ( $draw ),
  3204. "recordsTotal" => intval ( $invoiceTotal ),
  3205. "recordsFiltered" => intval ( $recordsFiltered ),
  3206. "data" => $paperList
  3207. ), JSON_UNESCAPED_UNICODE );
  3208. }
  3209. function invoicePaperDel() {
  3210. $ipidKey = isset ( $this->params ['ipidKey'] ) ? $this->params ['ipidKey'] : "";
  3211. $XDeode = new XDeode ( 5 );
  3212. $ipid = $XDeode->decode ( $ipidKey );
  3213. if (empty ( $ipid ))
  3214. die ( 'illegal request' );
  3215. Doo::loadModel ( 'invoicePaper' );
  3216. $invoicePaper = new invoicePaper ();
  3217. $invoicePaper->delete ( array (
  3218. 'where' => 'ipid=' . $ipid . ' and iid=0',
  3219. 'limit' => 1
  3220. ) );
  3221. return '/invoicePaper';
  3222. }
  3223. /**
  3224. * 添加纸质发票号
  3225. */
  3226. function invoicePaperAdd() {
  3227. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : '0';
  3228. $invoiceCode = $this->get_args ( 'invoiceCode' ) ? $this->get_args ( 'invoiceCode' ) : "";
  3229. $invoiceNoStart = $this->get_args ( 'invoiceNoStart' ) && is_numeric ( $this->get_args ( 'invoiceNoStart' ) ) ? $this->get_args ( 'invoiceNoStart' ) : 0;
  3230. $invoiceNoTotal = $this->get_args ( 'invoiceNoTotal' ) && is_numeric ( $this->get_args ( 'invoiceNoTotal' ) ) ? $this->get_args ( 'invoiceNoTotal' ) : 0;
  3231. if ($invoiceType != '' && ! empty ( $invoiceCode ) && ! empty ( $invoiceNoStart ) && ! empty ( $invoiceNoTotal )) {
  3232. $sum = $invoiceNoStart + $invoiceNoTotal;
  3233. if (empty ( $sum ))
  3234. die ( 'illegal request' );
  3235. //echo $invoiceNoStart;
  3236. // echo $sum;
  3237. // echo strlen((int)$invoiceNoStart);
  3238. $sumLenght=strlen($invoiceNoStart)-strlen((int)$invoiceNoStart);
  3239. Doo::db ()->beginTransaction ();
  3240. // 批量存储纸质发票
  3241. $date = date ( "Y-m-d H:i:s" );
  3242. $sql = 'INSERT INTO CLD_invoicePaper (invoiceType, invoiceCode,invoiceNo,date)
  3243. VALUES ';
  3244. $paperList = array ();
  3245. for($invoiceNoStart; $invoiceNoStart <= $sum - 1; $invoiceNoStart ++) {
  3246. //数字前面自加0
  3247. $INLENGHT=strlen((int)$invoiceNoStart)+$sumLenght;
  3248. $var=sprintf("%0".$INLENGHT."d", $invoiceNoStart);
  3249. $paperSql = '(' . $invoiceType . ',"' . $invoiceCode . '","' . $var . '","' . $date . '")';
  3250. array_push ( $paperList, $paperSql );
  3251. }
  3252. if (empty ( $paperList ))
  3253. die ( 'illegal request' );
  3254. $sql = $sql . implode ( ',', $paperList );
  3255. Doo::db ()->query ( $sql );
  3256. Doo::db ()->commit ();
  3257. return 'invoicePaper';
  3258. }
  3259. die ( 'illegal request' );
  3260. }
  3261. /**
  3262. * 收款绑定发票 ,//一个收款只能绑定一个发票
  3263. */
  3264. function invoiceBindReceivables() {
  3265. $claimKey = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  3266. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  3267. Doo::loadModel ( 'invoice' );
  3268. $invoice = new invoice ();
  3269. Doo::loadModel ( 'invoiceReceivables' );
  3270. $invoiceReceivables = new invoiceReceivables ();
  3271. Doo::loadModel ( 'invoiceOperationLog' );
  3272. $invoiceOperationLog = new invoiceOperationLog ();
  3273. if (empty ( $invoiceKey ) || empty ( $claimKey ))
  3274. die ( 'illegal request' );
  3275. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  3276. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey );
  3277. if (empty ( $detail ) && empty ( $detailM ))
  3278. die ( 'illegal request' );
  3279. if ($detail ['untreadStatus'] == 3)
  3280. die ( 'illegal request' );
  3281. // 修改 绑定状态改为 金额
  3282. $invoiceReceivables = new invoiceReceivables ();
  3283. $invoicePrice = $detail ['invoicePrice'] + $detailM ['bindPrice'];
  3284. if ($detailM ['receivablesPrice'] > $invoicePrice) {
  3285. $item = array (
  3286. 'bindPrice' => $invoicePrice
  3287. );
  3288. } elseif ($detailM ['receivablesPrice'] <= $invoicePrice) {
  3289. $item = array (
  3290. 'bindPrice' => $invoicePrice,
  3291. 'bindStatus' => 1,
  3292. 'bindDate' => date ( "Y-m-d H:i:s" )
  3293. );
  3294. } else {
  3295. die ( 'illegal request' );
  3296. }
  3297. if ($detailM ['iid'] == 0) {
  3298. $item += array (
  3299. 'iid' => $detail ['iid']
  3300. );
  3301. } else {
  3302. $iidExtend = explode ( ',', $detailM ['iidExtend'] );
  3303. array_push ( $iidExtend, $detail ['iid'] );
  3304. $item += array (
  3305. 'iidExtend' => implode ( ',', $iidExtend )
  3306. );
  3307. }
  3308. $item += array (
  3309. 'irid' => $detailM ['irid'],
  3310. 'accountClerk' => $this->staff [0] ['username']
  3311. );
  3312. // 如何没有人收款 则自动绑定收款
  3313. if ($detailM ['receivablesCategory'] == 'PUBLIC' || $detailM ['receivablesStaff'] == 'PUBLIC') {
  3314. $item += array (
  3315. 'receivablesCategory' => $detail ['cid'] . ':' . $detail ['categoryName'],
  3316. 'receivablesStaff' => $detail ['sid'] . '-' . $detail ['userName']
  3317. );
  3318. }
  3319. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3320. $iridString = "";
  3321. if (empty ( $detail ['irid'] ))
  3322. $iridString = $detailM ['irid'];
  3323. else
  3324. $iridString = $detail ['irid'] . ',' . $detailM ['irid'];
  3325. $item = array (
  3326. 'iid' => $detail ['iid'],
  3327. 'irid' => $iridString
  3328. );
  3329. $invoiceReceivables = new invoiceReceivables ();
  3330. $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  3331. if ($detail ['invoicePrice'] <= $sum)
  3332. $item += array (
  3333. 'untreadStatus' => 3,
  3334. 'bindTime' => date ( "Y-m-d H:i:s" )
  3335. );
  3336. // print_r($item);
  3337. // echo $sum;die;
  3338. $invoice->setInvoiceByCondition ( $item );
  3339. // 操作日志
  3340. $item = array (
  3341. 'date' => date ( "Y-m-d H:i:s" ),
  3342. 'operation' => "收款" . $detailM ['receivablesSerial'] . "入账到发票" . $detail ['invoiceSerial'],
  3343. 'status' => 8,
  3344. 'img' => $this->staff [0] ['avatar'],
  3345. 'username' => $this->staff [0] ['username'],
  3346. 'uid' => $this->staff [0] ['sid'],
  3347. 'category' => $this->staff [0] ['category'],
  3348. 'iid' => $detail ['iid']
  3349. );
  3350. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3351. Doo::loadModel ( 'invoiceStatistics' );
  3352. $invoiceStatistics = new invoiceStatistics ();
  3353. $item = array (
  3354. 'date' => $detailM ['receivablesDate'],
  3355. 'priceClass' => 3,
  3356. 'cid' => $detail ['cid'],
  3357. 'staff' => $detail ['sid'],
  3358. 'accountPrice' => $detailM ['receivablesPrice']
  3359. );
  3360. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3361. //公司流水记录
  3362. Doo::loadModel ( 'wasteBook' );
  3363. $wasteBook = new wasteBook ();
  3364. $abDetail = $wasteBook->getAccountBookByAid (1,8,$detail ['iid'] );
  3365. $accountBank='';
  3366. if ($detailM ['receivablesBank']=='纵横广发'){
  3367. $accountBank='CGBDeposit';
  3368. }elseif($detailM ['receivablesBank']=='纵横工行'){
  3369. $accountBank='ICBCDeposit';
  3370. }elseif($detailM ['receivablesBank']=='华润银行'){
  3371. $accountBank='HUADeposit';
  3372. }elseif($detailM ['receivablesBank']=='个人广发'){
  3373. $accountBank='PersonalDeposit';
  3374. }
  3375. //银行
  3376. if (empty($abDetail)){
  3377. $item = array (
  3378. 'dataID' => $detail ['iid'],
  3379. 'expensesType' => 1,
  3380. 'accountType' => 8,
  3381. 'accountPriceShow'=>$detail ['invoicePrice'],
  3382. 'accountPrice'=>$detail ['invoicePrice'],
  3383. 'accountBank'=>$accountBank,
  3384. 'category'=>$this->staff[0]['category'],
  3385. 'cid'=>$this->staff[0]['cid'],
  3386. 'name'=>$this->staff[0]['username'],
  3387. 'sid'=>$this->staff[0]['sid'],
  3388. 'inputDate'=>date ( "Y-m-d H:i:s" )
  3389. );
  3390. $wasteBook->setAccountBookStatistics($item);
  3391. }
  3392. return "/invoiceReceivables";
  3393. }
  3394. /**
  3395. * 核销 动作,确认入账统计 发票收款完成--需求更变 废弃 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"; }
  3396. */
  3397. function invoiceAggregate() {
  3398. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3399. Doo::loadModel ( 'invoiceStatistics' );
  3400. $invoiceStatistics = new invoiceStatistics ();
  3401. Doo::loadModel ( 'L_category' );
  3402. $Lcategory = new L_category ();
  3403. $isList = $invoiceStatistics->getInvoiceStatisticsByYear ( $year );
  3404. $LcategoryList = $Lcategory->getCategory ();
  3405. // print_r($isList);
  3406. $html = ""; // $invoicePriceCategory=0;$receivablesPriceCategory=0;$accountPriceCategory=0;
  3407. foreach ( $LcategoryList as $key => $value ) {
  3408. $html .= '<tr><th><a href="/invoiceAggregateCategory/' . $value ['cidKey'] . '">' . $value ['title'] . '</a></th>';
  3409. $month = 1;
  3410. $invoicePriceYear = 0;
  3411. $receivablesPriceYear = 0;
  3412. $accountPriceYear = 0;
  3413. for(; $month <= 12; $month ++) {
  3414. $flag = true;
  3415. foreach ( $isList ['statisticsMonthCid'] as $k => $v ) {
  3416. if ($value ['cid'] == $v ['cid'] && $month == $v ['month']) {
  3417. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  3418. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  3419. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  3420. ';
  3421. $invoicePriceYear += $v ['invoicePrice'];
  3422. $receivablesPriceYear += $v ['receivablesPrice'];
  3423. $accountPriceYear += $v ['accountPrice'];
  3424. $flag = false;
  3425. break;
  3426. }
  3427. }
  3428. if ($flag)
  3429. $html .= '<td class="taR"></td>
  3430. <td class="taR"></td>
  3431. <td class="taR"><b></b></td>
  3432. ';
  3433. }
  3434. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  3435. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  3436. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  3437. ';
  3438. $html .= '</tr>';
  3439. }
  3440. $html .= '<tr><th><b class="colGreen">月合计</b></th>';
  3441. $invoicePriceYear = 0;
  3442. $receivablesPriceYear = 0;
  3443. $accountPriceYear = 0;
  3444. for($month = 1; $month <= 12; $month ++) {
  3445. $flag = true;
  3446. foreach ( $isList ['statisticsMonth'] as $k => $v ) {
  3447. if ($month == $v ['month']) {
  3448. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  3449. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  3450. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  3451. ';
  3452. $invoicePriceYear += $v ['invoicePrice'];
  3453. $receivablesPriceYear += $v ['receivablesPrice'];
  3454. $accountPriceYear += $v ['accountPrice'];
  3455. $flag = false;
  3456. break;
  3457. }
  3458. }
  3459. if ($flag) {
  3460. $html .= '<td class="taR"></td>
  3461. <td class="taR"></td>
  3462. <td class="taR"><b></b></td>
  3463. ';
  3464. }
  3465. }
  3466. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  3467. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  3468. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  3469. ';
  3470. $html .= '</tr>';
  3471. // print_r($isList);
  3472. $this->data ['html'] = $html;
  3473. $this->data ['LcategoryList'] = $LcategoryList;
  3474. $this->data ['isList'] = $isList;
  3475. $this->data ['year'] = $year;
  3476. $this->data ['memu'] = "invoice";
  3477. $this->data ['staff'] = $this->staff;
  3478. $this->data ['receiptMemu'] = 'invoiceAggregate';
  3479. $this->render ( "/admin/invoiceAggregate", $this->data );
  3480. }
  3481. function invoiceAggregateStaff() {
  3482. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3483. Doo::loadModel ( 'invoiceStatistics' );
  3484. $invoiceStatistics = new invoiceStatistics ();
  3485. Doo::loadModel ( 'L_category' );
  3486. $Lcategory = new L_category ();
  3487. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year );
  3488. $staffList = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year );
  3489. $cStaff = $Lcategory->getCategoryStaff ();
  3490. $html = '';
  3491. foreach ( $cStaff as $key => $value ) {
  3492. $categoryFir = true;
  3493. foreach ( $value ['staff'] as $k => $v ) {
  3494. if ($categoryFir) {
  3495. $width = count ( $value ['staff'] ) + 1;
  3496. $html .= '<tr><th rowspan="' . $width . '">' . $value ['title'] . ' </th>';
  3497. $categoryFir = false;
  3498. } else
  3499. $html .= '<tr>';
  3500. $html .= '<th>' . $v ['username'] . '</th>';
  3501. $invoicePriceStaffYear = 0;
  3502. $receivablesPriceStaffYear = 0;
  3503. $accountPriceStaffYear = 0;
  3504. for($month = 1; $month <= 12; $month ++) {
  3505. $flag = true;
  3506. foreach ( $staffList ['statisticsMonthStaff'] as $sl => $slv ) {
  3507. if ($v ['sid'] == $slv ['staff'] && $month == $slv ['month']) {
  3508. $html .= '<td class="taR">¥' . $slv ['invoicePrice'] . '</td>
  3509. <td class="taR">¥' . $slv ['receivablesPrice'] . '</td>
  3510. <td class="taR"><b>¥' . $slv ['accountPrice'] . '</b></td>
  3511. ';
  3512. $invoicePriceStaffYear += $slv ['invoicePrice'];
  3513. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  3514. $accountPriceStaffYear += $slv ['accountPrice'];
  3515. $flag = false;
  3516. break;
  3517. }
  3518. }
  3519. if ($flag)
  3520. $html .= '<td class="taR"></td>
  3521. <td class="taR"></td>
  3522. <td class="taR"><b></b></td>
  3523. ';
  3524. }
  3525. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  3526. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  3527. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  3528. ';
  3529. }
  3530. $html .= '</tr>';
  3531. // 小计
  3532. if (! empty ( $value ['staff'] )) {
  3533. $html .= '<tr><th class="taR">小计</th>';
  3534. $invoicePriceStaffYear = 0;
  3535. $receivablesPriceStaffYear = 0;
  3536. $accountPriceStaffYear = 0;
  3537. for($month = 1; $month <= 12; $month ++) {
  3538. $flag = true;
  3539. foreach ( $staffList ['statisticsMonthCid'] as $smc => $smcv ) {
  3540. if ($value ['cid'] == $smcv ['cid'] && $month == $slv ['month']) {
  3541. $html .= '<td class="taR">¥' . $smcv ['invoicePrice'] . '</td>
  3542. <td class="taR">¥' . $smcv ['receivablesPrice'] . '</td>
  3543. <td class="taR"><b>¥' . $smcv ['accountPrice'] . '</b></td>
  3544. ';
  3545. $invoicePriceStaffYear += $slv ['invoicePrice'];
  3546. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  3547. $accountPriceStaffYear += $slv ['accountPrice'];
  3548. $flag = false;
  3549. break;
  3550. }
  3551. }
  3552. if ($flag)
  3553. $html .= '<td class="taR"></td>
  3554. <td class="taR"></td>
  3555. <td class="taR"><b></b></td>
  3556. ';
  3557. }
  3558. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  3559. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  3560. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  3561. ';
  3562. $html .= '</tr>';
  3563. }
  3564. }
  3565. $html .= '<tr class="warning"><th colspan="2"><b class="colGreen" >月合计</b></th>';
  3566. $invoicePriceYear = 0;
  3567. $receivablesPriceYear = 0;
  3568. $accountPriceYear = 0;
  3569. for($month = 1; $month <= 12; $month ++) {
  3570. $flag = true;
  3571. foreach ( $staffList ['statisticsMonth'] as $k => $v ) {
  3572. if ($month == $v ['month']) {
  3573. $html .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>
  3574. <td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>
  3575. <td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>
  3576. ';
  3577. $invoicePriceYear += $v ['invoicePrice'];
  3578. $receivablesPriceYear += $v ['receivablesPrice'];
  3579. $accountPriceYear += $v ['accountPrice'];
  3580. $flag = false;
  3581. break;
  3582. }
  3583. }
  3584. if ($flag)
  3585. $html .= '<td class="taR"></td>
  3586. <td class="taR"></td>
  3587. <td class="taR"><b></b></td>
  3588. ';
  3589. }
  3590. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  3591. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  3592. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  3593. ';
  3594. $html .= '</tr>';
  3595. $this->data ['html'] = $html;
  3596. $this->data ['isList'] = $toteList;
  3597. $this->data ['year'] = $year;
  3598. $this->data ['memu'] = "invoice";
  3599. $this->data ['staff'] = $this->staff;
  3600. $this->data ['receiptMemu'] = 'invoiceAggregate';
  3601. $this->render ( "/admin/invoiceAggregateStaff", $this->data );
  3602. }
  3603. function invoiceAggregateCategory() {
  3604. Doo::loadClass ( 'XDeode' );
  3605. $XDeode = new XDeode ( 5 );
  3606. $cid = $cidKey = isset ( $this->params ['cid'] ) ? $this->params ['cid'] : "";
  3607. $cid = $XDeode->decode ( $cid );
  3608. if (! is_numeric ( $cid ))
  3609. die ( 'illegal request' );
  3610. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3611. Doo::loadModel ( 'invoiceStatistics' );
  3612. $invoiceStatistics = new invoiceStatistics ();
  3613. Doo::loadModel ( 'staff' );
  3614. $staff = new staff ();
  3615. $list = $staff->getStaffByCid ( $cid );
  3616. $isCategory = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year, $cid );
  3617. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year, $cid );
  3618. if (empty ( $list ))
  3619. die ( '该办事处没有成员' );
  3620. $htmlA = $htmlB = $htmlC = $html = '';
  3621. foreach ( $list as $key => $value ) {
  3622. $htmlA = '<tr><th rowspan="3">' . $value ['username'] . '</th><th class="taC">开票</th>';
  3623. $htmlB = '<tr><th class="taC">收款</th>';
  3624. $htmlC = '<tr><th class="taC">入账</th>';
  3625. $invoicePriceStaffYear = 0;
  3626. $receivablesPriceStaffYear = 0;
  3627. $accountPriceStaffYear = 0;
  3628. for($month = 1; $month <= 12; $month ++) {
  3629. $flag = true;
  3630. foreach ( $isCategory ['statisticsMonthStaff'] as $k => $v ) {
  3631. if ($value ['sid'] == $v ['staff'] && $month == $v ['month']) {
  3632. $htmlA .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>';
  3633. $htmlB .= '<td class="taR">¥' . $v ['receivablesPrice'] . '</td>';
  3634. $htmlC .= '<td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>';
  3635. $invoicePriceStaffYear += $v ['invoicePrice'];
  3636. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  3637. $accountPriceStaffYear += $v ['accountPrice'];
  3638. $flag = false;
  3639. break;
  3640. }
  3641. }
  3642. if ($flag) {
  3643. $htmlA .= '<td class="taR">-</td>';
  3644. $htmlB .= '<td class="taR">-</td>';
  3645. $htmlC .= '<td class="taR"><b>-</b></td>';
  3646. }
  3647. }
  3648. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  3649. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  3650. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  3651. $htmlA .= '</tr>';
  3652. $htmlB .= '</tr>';
  3653. $htmlC .= '</tr>';
  3654. $html .= $htmlA . $htmlB . $htmlC;
  3655. }
  3656. $htmlA = $htmlB = $htmlC = "";
  3657. $htmlA = '<tr><th rowspan="3">月合计</th><th class="taC">开票</th>';
  3658. $htmlB = '<tr><th class="taC">收款</th>';
  3659. $htmlC = '<tr><th class="taC">入账</th>';
  3660. $invoicePriceStaffYear = 0;
  3661. $receivablesPriceStaffYear = 0;
  3662. $accountPriceStaffYear = 0;
  3663. for($month = 1; $month <= 12; $month ++) {
  3664. $flag = true;
  3665. foreach ( $isCategory ['statisticsMonth'] as $k => $v ) {
  3666. if ($month == $v ['month']) {
  3667. $htmlA .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>';
  3668. $htmlB .= '<td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>';
  3669. $htmlC .= '<td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>';
  3670. $invoicePriceStaffYear += $v ['invoicePrice'];
  3671. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  3672. $accountPriceStaffYear += $v ['accountPrice'];
  3673. $flag = false;
  3674. break;
  3675. }
  3676. }
  3677. if ($flag) {
  3678. $htmlA .= '<td class="taR">-</td>';
  3679. $htmlB .= '<td class="taR">-</td>';
  3680. $htmlC .= '<td class="taR"><b>-</b></td>';
  3681. }
  3682. }
  3683. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  3684. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  3685. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  3686. $htmlA .= '</tr>';
  3687. $htmlB .= '</tr>';
  3688. $htmlC .= '</tr>';
  3689. $html .= $htmlA . $htmlB . $htmlC;
  3690. $this->data ['html'] = $html;
  3691. $this->data ['cidKey'] = $cidKey;
  3692. $this->data ['slist'] = $list;
  3693. $this->data ['isList'] = $toteList;
  3694. $this->data ['year'] = $year;
  3695. $this->data ['memu'] = "invoice";
  3696. $this->data ['staff'] = $this->staff;
  3697. $this->data ['receiptMemu'] = 'invoiceAggregate';
  3698. $this->render ( "/admin/invoiceAggregateCategory", $this->data );
  3699. }
  3700. /**
  3701. * 办事处汇总信息
  3702. */
  3703. function invoiceAggregateCategoryDetail() {
  3704. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  3705. Doo::loadClass ( 'XDeode' );
  3706. $XDeode = new XDeode ( 5 );
  3707. Doo::loadModel ( 'invoiceStatistics' );
  3708. $invoiceStatistics = new invoiceStatistics ();
  3709. Doo::loadModel ( 'L_category' );
  3710. $category = new L_category ();
  3711. Doo::loadModel ( 'invoice' );
  3712. $invoice = new invoice ();
  3713. Doo::loadModel ( 'staff' );
  3714. $staff = new staff ();
  3715. Doo::loadModel ( "invoiceCategoryManage" );
  3716. $invoiceCategoryManage = new invoiceCategoryManage ();
  3717. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  3718. $cidList = array ();
  3719. foreach ( $imcStaff as $key => $value ) {
  3720. array_push ( $cidList, $value ['cid'] );
  3721. if (empty ( $cidKey ))
  3722. $cidKey = $XDeode->encode ( $value ['cid'] );
  3723. }
  3724. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  3725. $cid = $XDeode->decode ( $cidKey );
  3726. $month = date ( "m", strtotime ( "-1 month" ) );
  3727. $redis = new Redis ();
  3728. $redis->connect ( '127.0.0.1', '6379' );
  3729. $redisKey = ''; // date('Y-m-d').'_iacd_'.$cid;
  3730. $redisValue = ''; // $redis->lrange($redisKey, 0, -1);
  3731. if (empty ( $redisValue )) {
  3732. $isMC = $invoiceStatistics->getInvoiceStatistiscsMothByCategory ( $cid );
  3733. $schedule = $invoice->getInvoiceScheduleByCid ( $cid );
  3734. // 获得办事处人员下的汇总
  3735. $slist = $staff->getStaffByCid ( $cid );
  3736. $ismsbMonth = $invoiceStatistics->getISMSByCategoryByMonth ( $cid, $month ); // 上一个月的汇总
  3737. $ismsb = $invoiceStatistics->getISMSByCategory ( $cid ); // 当月汇总
  3738. $ISAS = $invoiceStatistics->getISASByCategory ( $cid ); // 全部汇总
  3739. $scheduleStaff = $invoice->getInvoiceScheduleByCidGroupSid ( $cid ); // 完成度
  3740. foreach ( $slist as $key => $value ) {
  3741. $slist [$key] ['invoicePrice'] = 0;
  3742. $slist [$key] ['receivablesPrice'] = 0;
  3743. $slist [$key] ['accountPrice'] = 0;
  3744. $slist [$key] ['invoiceAllPrice'] = 0;
  3745. $slist [$key] ['receivablesAllPrice'] = 0;
  3746. $slist [$key] ['accountAllPrice'] = 0;
  3747. $slist [$key] ['schedule'] = 0;
  3748. $slist [$key] ['invoiceMonthPrice'] = 0;
  3749. $slist [$key] ['receivablesMonthPrice'] = 0;
  3750. $slist [$key] ['accountMonthPrice'] = 0;
  3751. foreach ( $ismsbMonth as $y => $l ) {
  3752. if ($value ['sid'] == $l ['staff']) {
  3753. $slist [$key] ['invoiceMonthPrice'] = $l ['invoicePrice'];
  3754. $slist [$key] ['receivablesMonthPrice'] = $l ['receivablesPrice'];
  3755. $slist [$key] ['accountMonthPrice'] = $l ['accountPrice'];
  3756. }
  3757. }
  3758. foreach ( $ismsb as $k => $v ) {
  3759. if ($value ['sid'] == $v ['staff']) {
  3760. $slist [$key] ['invoicePrice'] = $v ['invoicePrice'];
  3761. $slist [$key] ['receivablesPrice'] = $v ['receivablesPrice'];
  3762. $slist [$key] ['accountPrice'] = $v ['accountPrice'];
  3763. }
  3764. }
  3765. foreach ( $ISAS as $e => $a ) {
  3766. if ($value ['sid'] == $a ['staff']) {
  3767. $slist [$key] ['invoiceAllPrice'] = $a ['invoicePrice'];
  3768. $slist [$key] ['receivablesAllPrice'] = $a ['receivablesPrice'];
  3769. $slist [$key] ['accountAllPrice'] = $a ['accountPrice'];
  3770. }
  3771. }
  3772. if (isset ( $scheduleStaff [$value ['sid']] ))
  3773. $slist [$key] ['schedule'] = $scheduleStaff [$value ['sid']];
  3774. }
  3775. $this->data ['cidKey'] = $cidKey;
  3776. $schedule = ( int ) ($schedule * 100);
  3777. $this->data ['slist'] = $slist;
  3778. $this->data ['isMC'] = $isMC;
  3779. $this->data ['schedule'] = $schedule;
  3780. $slist = json_encode ( $slist );
  3781. $isMC = json_encode ( $isMC );
  3782. $schedule = json_encode ( $schedule );
  3783. $redis->lpush ( $redisKey, $slist );
  3784. $redis->lpush ( $redisKey, $isMC );
  3785. $redis->lpush ( $redisKey, $schedule );
  3786. } else {
  3787. $this->data ['cidKey'] = $cidKey;
  3788. $this->data ['slist'] = json_decode ( $redisValue [2], true );
  3789. $this->data ['isMC'] = json_decode ( $redisValue [1], true );
  3790. $this->data ['schedule'] = json_decode ( $redisValue [0], true );
  3791. }
  3792. $this->data ['month'] = $month;
  3793. $this->data ['categoryList'] = $categoryList;
  3794. $this->data ['memu'] = "invoice";
  3795. $this->data ['staff'] = $this->staff;
  3796. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  3797. $this->render ( "/admin/invoiceAggregateCategoryDetail", $this->data );
  3798. }
  3799. /**
  3800. * 办事处人员汇总详情
  3801. */
  3802. function invoiceAggregateStaffDetail() {
  3803. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  3804. // $sidKey = isset ( $this->params ['sidKey'] ) ? $this->params ['sidKey'] : '';
  3805. Doo::loadClass ( 'XDeode' );
  3806. $XDeode = new XDeode ( 5 );
  3807. Doo::loadModel ( 'invoice' );
  3808. $invoice = new invoice ();
  3809. Doo::loadModel ( 'staff' );
  3810. $staff = new staff ();
  3811. Doo::loadModel ( "invoiceCategoryManage" );
  3812. $invoiceCategoryManage = new invoiceCategoryManage ();
  3813. $sid = $XDeode->decode ( $sidKey );
  3814. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  3815. $cidList = array ();
  3816. foreach ( $imcStaff as $key => $value ) {
  3817. array_push ( $cidList, $value ['cid'] );
  3818. if (empty ( $cidKey ))
  3819. $cidKey = $XDeode->encode ( $value ['cid'] );
  3820. }
  3821. $cidString = implode ( ',', $cidList );
  3822. $staffList = $staff->getStaffInCid ( $cidString );
  3823. $staffDetail = $staff->getStaffBySid ( $sid );
  3824. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  3825. $page_size = 18;
  3826. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  3827. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  3828. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  3829. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  3830. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  3831. $dateArr = explode ( ':', $date );
  3832. $D1 = '';
  3833. $D2 = '';
  3834. if (! empty ( $date )) {
  3835. $D1 = $dateArr [0] . " 00:00:00 ";
  3836. if (isset ( $dateArr [1] ))
  3837. $D2 = $dateArr [1] . " 23:59:59 ";
  3838. else
  3839. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  3840. // $D2 = $dateArr [1];
  3841. }
  3842. $con = ' status=2 ';
  3843. if (! empty ( $D1 ) && ! empty ( $D2 ))
  3844. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  3845. if ($status == 'UNRECORD')
  3846. $con .= ' and printStatus=1 and untreadStatus=0';
  3847. elseif ($status == 'RECORD')
  3848. $con .= ' and printStatus=1 and untreadStatus=3';
  3849. elseif ($status == 'BOUNCED')
  3850. $con .= ' and untreadStatus=2';
  3851. elseif ($status == 'PARTRECORD')
  3852. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  3853. elseif ($status == 'All') {
  3854. $con .= ' and ( untreadStatus=2 or untreadStatus=0 or untreadStatus=3 )';
  3855. }
  3856. $con .= ' and sid=' . $sid;
  3857. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  3858. if (! empty ( $MebSea )) {
  3859. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  3860. }
  3861. $pageinfo ['page'] = array (
  3862. 'previous' => ''
  3863. );
  3864. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateStaffDetail", $get, "" );
  3865. $limit = $pageinfo ['lower'] . ',' . $page_size;
  3866. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  3867. $this->data ['staffDetail'] = $staffDetail;
  3868. $this->data ['staffList'] = $staffList;
  3869. $this->data ['MebSeaEn'] = $MebSea;
  3870. $this->data ['MebSea'] = urlencode ( $MebSea );
  3871. $this->data ['date'] = $date;
  3872. $this->data ['page'] = $pageinfo;
  3873. $this->data ['get'] = $get;
  3874. $this->data ['list'] = $list;
  3875. $this->data ['status'] = $status;
  3876. $this->data ['sidKey'] = $sidKey;
  3877. $this->data ['memu'] = "invoice";
  3878. $this->data ['staff'] = $this->staff;
  3879. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  3880. $this->render ( "/admin/invoiceAggregateStaffDetail", $this->data );
  3881. }
  3882. /**
  3883. * 办事处人员汇总收款情
  3884. */
  3885. function invoiceAggregateStaffReceivablesDetail() {
  3886. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  3887. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  3888. Doo::loadModel ( 'invoiceReceivables' );
  3889. $invoiceReceivables = new invoiceReceivables ();
  3890. Doo::loadModel ( 'staff' );
  3891. $staff = new staff ();
  3892. Doo::loadModel ( "invoiceCategoryManage" );
  3893. $invoiceCategoryManage = new invoiceCategoryManage ();
  3894. Doo::loadClass ( 'XDeode' );
  3895. $XDeode = new XDeode ( 5 );
  3896. $sid = $XDeode->decode ( $sidKey );
  3897. $staffDetail = $staff->getStaffBySid ( $sid );
  3898. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  3899. $cidList = array ();
  3900. foreach ( $imcStaff as $key => $value ) {
  3901. array_push ( $cidList, $value ['cid'] );
  3902. if (empty ( $cidKey ))
  3903. $cidKey = $XDeode->encode ( $value ['cid'] );
  3904. }
  3905. $cidString = implode ( ',', $cidList );
  3906. $staffList = $staff->getStaffInCid ( $cidString );
  3907. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  3908. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  3909. $page_size = 10;
  3910. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  3911. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  3912. if ($timeType == "BINDOTP") {
  3913. $status = 'Credited';
  3914. }
  3915. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  3916. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  3917. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  3918. $dateArr = explode ( ':', $date );
  3919. $D1 = '';
  3920. $D2 = '';
  3921. if (! empty ( $date )) {
  3922. $D1 = $dateArr [0] . " 00:00:00 ";
  3923. if (isset ( $dateArr [1] ))
  3924. $D2 = $dateArr [1] . " 23:59:59 ";
  3925. else
  3926. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  3927. }
  3928. $con = ' a.receivablesStaff like "%' . $staffDetail ['username'] . '%" ';
  3929. $descField = 'a.bindDate';
  3930. if ($timeType == 'CREATE')
  3931. $descField = 'a.date';
  3932. if (! empty ( $D1 ) && ! empty ( $D2 ))
  3933. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  3934. elseif (! empty ( $D1 ) && empty ( $D2 ))
  3935. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  3936. if ($status == 'Unclaimed')
  3937. $con .= ' and a.bindStatus=0';
  3938. elseif ($status == 'Credited')
  3939. $con .= ' and a.bindStatus=1';
  3940. elseif ($status == 'Claim')
  3941. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  3942. elseif ($status == 'BBN')
  3943. $con .= ' and a.bindPrice>a.receivablesPrice';
  3944. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  3945. if (! empty ( $MebSea )) {
  3946. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" )';
  3947. }
  3948. $pageinfo ['page'] = array (
  3949. 'previous' => ''
  3950. );
  3951. $sql = 'select group_concat(b.invoiceSerial) as invoiceSerial ,group_concat(b.iid) as invoiceId
  3952. from CLD_invoiceReceivables as a left join CLD_invoice as b on
  3953. find_in_set(b.iid,a.iidExtend) or a.iid=b.iid
  3954. where ' . $con . ' group by a.irid ';
  3955. $pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceAggregateStaffReceivablesDetail", $get, "" );
  3956. $limit = $pageinfo ['lower'] . ',' . $page_size;
  3957. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', 'printTime' );
  3958. foreach ( $list as $key => $value ) {
  3959. $list [$key] ['category'] = '';
  3960. if ($value ['receivablesCategory'] != 'PUBLIC') {
  3961. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  3962. $list [$key] ['category'] = $receivablesCategory [1];
  3963. }
  3964. }
  3965. // print_r($list);
  3966. $this->data ['staffDetail'] = $staffDetail;
  3967. $this->data ['sidKey'] = $sidKey;
  3968. $this->data ['staffList'] = $staffList;
  3969. $this->data ['timeType'] = $timeType;
  3970. $this->data ['MebSeaEn'] = $MebSea;
  3971. $this->data ['MebSea'] = urlencode ( $MebSea );
  3972. $this->data ['date'] = $date;
  3973. $this->data ['page'] = $pageinfo;
  3974. $this->data ['get'] = $get;
  3975. $this->data ['list'] = $list;
  3976. $this->data ['status'] = $status;
  3977. $this->data ['memu'] = "invoice";
  3978. $this->data ['staff'] = $this->staff;
  3979. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  3980. $this->render ( "/admin/invoiceAggregateStaffReceivablesDetail", $this->data );
  3981. }
  3982. function invoiceAchieve() {
  3983. Doo::loadModel ( 'invoice' );
  3984. $invoice = new invoice ();
  3985. Doo::loadClass ( 'XDeode' );
  3986. $XDeode = new XDeode ( 5 );
  3987. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  3988. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  3989. $page_size = 18;
  3990. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  3991. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  3992. $get = "/" . $date;
  3993. $con = '';
  3994. if ($date == 'MONTHO')
  3995. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  3996. elseif ($date == 'MONTHT')
  3997. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  3998. elseif ($date == 'MONTHY')
  3999. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4000. if (! empty ( $MebSea )) {
  4001. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4002. $get .= "/" . $MebSea;
  4003. }
  4004. $pageinfo ['page'] = array (
  4005. 'previous' => ''
  4006. );
  4007. $sql = 'status=2 and printStatus=1 and irid!="" and ( untreadStatus=3 or untreadStatus=0 ) and sid=' . $sid . $con;
  4008. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceAchieve", $get, "" );
  4009. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4010. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  4011. // print_r($pageinfo);
  4012. $this->data ['MebSeaEn'] = $MebSea;
  4013. $this->data ['MebSea'] = urlencode ( $MebSea );
  4014. $this->data ['get'] = $get;
  4015. $this->data ['page'] = $pageinfo;
  4016. $this->data ['list'] = $list;
  4017. $this->data ['date'] = $date;
  4018. $this->data ['memu'] = "invoice";
  4019. $this->data ['staff'] = $this->staff;
  4020. $this->data ['receiptMemu'] = 'invoice';
  4021. $this->render ( "/admin/invoiceAchieve", $this->data );
  4022. }
  4023. /**
  4024. *
  4025. */
  4026. function invoiceMyUnAccountAchieve() {
  4027. Doo::loadModel ( 'invoice' );
  4028. $invoice = new invoice ();
  4029. Doo::loadClass ( 'XDeode' );
  4030. $XDeode = new XDeode ( 5 );
  4031. Doo::loadModel ( 'staff' );
  4032. $staff = new staff ();
  4033. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4034. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4035. $page_size = 18;
  4036. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4037. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4038. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4039. $dateArr = explode ( ':', $date );
  4040. $D1 = '';
  4041. $D2 = '';
  4042. if (! empty ( $date )) {
  4043. $D1 = $dateArr [0];
  4044. $D2 = $dateArr [1];
  4045. }
  4046. $con = '';
  4047. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4048. $con = ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4049. if (! empty ( $MebSea )) {
  4050. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4051. }
  4052. $pageinfo ['page'] = array (
  4053. 'previous' => ''
  4054. );
  4055. // and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  4056. $sql = " status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid= " . $sid . $con;
  4057. $action = "invoiceMyUnAccountAchieve";
  4058. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  4059. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4060. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  4061. Doo::loadModel ( 'express' );
  4062. $express = new express ();
  4063. $expressList = $express->getExpressByAll ();
  4064. $this->data ['expressList'] = $expressList;
  4065. // print_r($list);
  4066. $this->data ['MebSeaEn'] = $MebSea;
  4067. $this->data ['get'] = $get;
  4068. $this->data ['page'] = $pageinfo;
  4069. $this->data ['date'] = $date;
  4070. $this->data ['list'] = $list;
  4071. $this->data ['memu'] = "invoice";
  4072. $this->data ['staff'] = $this->staff;
  4073. $this->data ['receiptMemu'] = 'invoice';
  4074. $this->render ( "/admin/invoiceMyUnAccountAchieve", $this->data );
  4075. }
  4076. function invoiceReceivablesAchieve() {
  4077. Doo::loadModel ( 'invoiceReceivables' );
  4078. $invoiceReceivables = new invoiceReceivables ();
  4079. Doo::loadClass ( 'XDeode' );
  4080. $XDeode = new XDeode ( 5 );
  4081. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4082. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  4083. $page_size = 12;
  4084. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4085. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4086. $get = "/" . $date;
  4087. $con = '';
  4088. if ($date == 'MONTHO')
  4089. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4090. elseif ($date == 'MONTHT')
  4091. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4092. elseif ($date == 'MONTHY')
  4093. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4094. if (! empty ( $MebSea )) {
  4095. $con .= ' and ( receivablesMessage like "%' . $MebSea . '%" or receivablesPrice like "%' . $MebSea . '%" )';
  4096. $get .= "/" . $MebSea;
  4097. }
  4098. $pageinfo ['page'] = array (
  4099. 'previous' => ''
  4100. );
  4101. $sql = " bindStatus=1 and receivablesStaff like '" . $sid . "_%' " . $con;
  4102. $pageinfo = $this->get_page ( "CLD_invoiceReceivables", $sql, $page, $page_size, "invoiceReceivablesAchieve", $get, "" );
  4103. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4104. $list = $invoiceReceivables->getReceivablesByUntreadStatusPage ( $limit, $sql );
  4105. // print_r($pageinfo);
  4106. $this->data ['MebSeaEn'] = $MebSea;
  4107. $this->data ['MebSea'] = urlencode ( $MebSea );
  4108. $this->data ['get'] = $get;
  4109. $this->data ['page'] = $pageinfo;
  4110. $this->data ['list'] = $list;
  4111. $this->data ['date'] = $date;
  4112. $this->data ['memu'] = "invoice";
  4113. $this->data ['staff'] = $this->staff;
  4114. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  4115. $this->render ( "/admin/invoiceReceivablesAchieve", $this->data );
  4116. }
  4117. /**
  4118. * 收款解绑
  4119. */
  4120. function invoiceUnBundLing() {
  4121. $unBundKey = $this->get_args ( 'unBundKey' ) ? $this->get_args ( 'unBundKey' ) : '';
  4122. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  4123. Doo::loadModel ( 'invoice' );
  4124. $invoice = new invoice ();
  4125. Doo::loadModel ( 'invoiceReceivables' );
  4126. $invoiceReceivables = new invoiceReceivables ();
  4127. Doo::loadModel ( 'invoiceOperationLog' );
  4128. $invoiceOperationLog = new invoiceOperationLog ();
  4129. Doo::loadModel ( 'invoiceROLog' );
  4130. $invoiceROLog = new invoiceROLog ();
  4131. Doo::loadModel ( 'invoiceStatistics' );
  4132. Doo::loadClass ( 'XDeode' );
  4133. $XDeode = new XDeode ( 5 );
  4134. if (empty ( $iidKey )||empty($unBundKey))
  4135. die ( 'illegal request' );
  4136. $iid = $XDeode->decode ( $iidKey );
  4137. $irid = $invoice->authcode ( $unBundKey );
  4138. if ((! empty ( $irid ) && ! is_numeric ( $irid )) || (! empty ( $iid ) && ! is_numeric ( $iid )))
  4139. die ( 'illegal request' );
  4140. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4141. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  4142. if (empty ( $irDetails ) || empty ( $invoiceDetails ) || (empty ( $irDetails ['iid'] ) && empty ( $irDetails ['iidExtend'] )) || $invoiceDetails ['untreadStatus'] == 2)
  4143. die ( 'illegal request' );
  4144. // 收款
  4145. $item = array (
  4146. 'irid' => $irDetails ['irid'],
  4147. 'bindPrice' => $irDetails ['bindPrice'] - $invoiceDetails ['invoicePrice'],
  4148. 'bindStatus' => 0
  4149. );
  4150. if ($irDetails ['iid'] == $iid)
  4151. $item += array (
  4152. 'iid' => 0
  4153. );
  4154. else {
  4155. $iidExtend = explode ( ',', $irDetails ['iidExtend'] );
  4156. foreach ( $iidExtend as $key => $value ) {
  4157. if ($value == $iid)
  4158. unset ( $iidExtend [$key] );
  4159. }
  4160. $iidExtend = implode ( ',', $iidExtend );
  4161. $item += array (
  4162. 'iidExtend' => $iidExtend
  4163. );
  4164. }
  4165. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4166. // 收款操作日志
  4167. $item = array (
  4168. 'operation' => $this->staff [0] ['username'] . " 解绑 " . $irDetails ['receivablesSerial'],
  4169. 'date' => date ( "Y-m-d" ),
  4170. 'status' => 3,
  4171. 'img' => $this->staff [0] ['avatar'],
  4172. 'username' => $this->staff [0] ['username'],
  4173. 'uid' => $this->staff [0] ['sid'],
  4174. 'category' => $this->staff [0] ['category'],
  4175. 'irid' => $irid
  4176. );
  4177. $invoiceROLog->setInvoiceROLog ( $item );
  4178. // 扣除入账统计金额
  4179. $invoiceStatistics = new invoiceStatistics ();
  4180. $item = array (
  4181. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  4182. 'priceClass' => 3,
  4183. 'cid' => $invoiceDetails ['cid'],
  4184. 'staff' => $invoiceDetails ['sid'],
  4185. 'accountPrice' => - $irDetails ['receivablesPrice']
  4186. );
  4187. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4188. // 扣除收款统计金额
  4189. $invoiceStatistics = new invoiceStatistics ();
  4190. $item = array (
  4191. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  4192. 'priceClass' => 2,
  4193. 'cid' => $invoiceDetails ['cid'],
  4194. 'staff' => $invoiceDetails ['sid'],
  4195. 'irid' => $irDetails ['irid'],
  4196. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  4197. );
  4198. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4199. // 发票解绑去收款ID
  4200. $iridString = $invoiceDetails ['irid'];
  4201. if (! empty ( $invoiceDetails ['irid'] )) {
  4202. $list = explode ( ',', $invoiceDetails ['irid'] );
  4203. foreach ( $list as $key => $value ) {
  4204. if ($value == $irDetails ['irid']) {
  4205. unset ( $list [$key] );
  4206. break;
  4207. }
  4208. }
  4209. $iridString = implode ( ",", $list );
  4210. }
  4211. $item = array (
  4212. 'iid' => $invoiceDetails ['iid'],
  4213. 'irid' => $iridString,
  4214. 'updateTime' => date ( "Y-m-d H:i:s" )
  4215. );
  4216. if ($invoiceDetails ['untreadStatus'] == 3)
  4217. $item += array (
  4218. 'untreadStatus' => 0
  4219. );
  4220. $invoice->setInvoiceByCondition ( $item );
  4221. $item = array (
  4222. 'date' => date ( "Y-m-d H:i:s" ),
  4223. 'operation' => '解绑 收款 ' . $irDetails ['receivablesSerial'],
  4224. 'status' => 11,
  4225. 'img' => $this->staff [0] ['avatar'],
  4226. 'username' => $this->staff [0] ['username'],
  4227. 'uid' => $this->staff [0] ['sid'],
  4228. 'category' => $this->staff [0] ['category'],
  4229. 'iid' => $invoiceDetails ['iid']
  4230. );
  4231. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  4232. //公司流水-解绑时删除流水
  4233. Doo::loadModel ( 'wasteBook' );
  4234. $wasteBook = new wasteBook ();
  4235. $wasteBook->delete ( array (
  4236. 'where' => 'dataID=' . $irDetails ['irid'].' and accountType=7',
  4237. 'limit' => 1
  4238. ) );
  4239. //银行
  4240. /*
  4241. $abDetail = $wasteBook->getAccountBookByAid (2,7,$irDetails ['irid'] );
  4242. $accountBank='';
  4243. if ($irDetails ['receivablesBank']=='纵横广发'){
  4244. $accountBank='CGBDeposit';
  4245. }elseif($irDetails ['receivablesBank']=='纵横工行'){
  4246. $accountBank='ICBCDeposit';
  4247. }elseif($irDetails ['receivablesBank']=='华润银行'){
  4248. $accountBank='HUADeposit';
  4249. }elseif($irDetails ['receivablesBank']=='个人广发'){
  4250. $accountBank='PersonalDeposit';
  4251. }
  4252. if (empty($abDetail)){
  4253. $item = array (
  4254. 'dataID' => $irDetails ['irid'],
  4255. 'expensesType' => 2,
  4256. 'accountType' => 7,
  4257. 'accountPriceShow'=>$irDetails ['receivablesPrice'],
  4258. 'accountPrice' => -$irDetails ['receivablesPrice'],
  4259. 'accountBank'=>$accountBank,
  4260. 'cid'=>$this->staff[0]['cid'],
  4261. 'name'=>$this->staff[0]['username'],
  4262. 'sid'=>$this->staff[0]['sid'],
  4263. 'inputDate'=>date ( "Y-m-d H:i:s" )
  4264. );
  4265. $wasteBook->setAccountBookStatistics($item);
  4266. }
  4267. */
  4268. return "/invoiceReceivablesAS";
  4269. }
  4270. /**
  4271. * 或者该收款下的所以发票
  4272. */
  4273. function ajaxGetInvoiceReceivablesByInvoice() {
  4274. $irid = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : '';
  4275. Doo::loadModel ( 'invoice' );
  4276. $invoice = new invoice ();
  4277. Doo::loadModel ( 'invoiceReceivables' );
  4278. $invoiceReceivables = new invoiceReceivables ();
  4279. $irid = $invoice->authcode ( $irid );
  4280. if (! empty ( $irid ) && ! is_numeric ( $irid ))
  4281. die ( 'illegal request' );
  4282. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4283. $iidString = $irDetails ['iid'];
  4284. $iidExtend = array_filter ( explode ( ',', $irDetails ['iidExtend'] ) );
  4285. if (! empty ( $irDetails ['iidExtend'] ))
  4286. $iidString .= ',' . implode ( ',', $iidExtend );
  4287. $invoiceList = $invoice->getInvoiceInIid ( $iidString, 'iid,invoiceSerial,invoicePrice,invoiceTitle,invoiceCompany,invoiceElement' );
  4288. $html = "";
  4289. foreach ( $invoiceList as $key => $value ) {
  4290. $title = $value ['invoiceTitle'];
  4291. if (! empty ( $value ['invoiceCompany'] ))
  4292. $title = $value ['invoiceCompany'];
  4293. $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>';
  4294. }
  4295. echo json_encode ( array (
  4296. 'status' => 1,
  4297. 'html' => $html
  4298. ) );
  4299. }
  4300. /**
  4301. * 发票管理
  4302. */
  4303. function invoiceAS() {
  4304. Doo::loadModel ( 'invoice' );
  4305. $invoice = new invoice ();
  4306. Doo::loadModel ( 'invoiceReceivables' );
  4307. $invoiceReceivables = new invoiceReceivables ();
  4308. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4309. $page_size = 18;
  4310. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4311. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4312. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4313. $dateArr = explode ( ':', $date );
  4314. $D1 = '';
  4315. $D2 = '';
  4316. if (! empty ( $date )) {
  4317. $D1 = $dateArr [0] . " 00:00:00 ";
  4318. if (isset ( $dateArr [1] ))
  4319. $D2 = $dateArr [1] . " 23:59:59 ";
  4320. else
  4321. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4322. // $D2 = $dateArr [1];
  4323. }
  4324. $con = ' status=2 ';
  4325. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4326. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4327. if ($status == 'UNRECORD')
  4328. $con .= ' and printStatus=1 and untreadStatus=0';
  4329. elseif ($status == 'RECORD')
  4330. $con .= ' and printStatus=1 and untreadStatus=3';
  4331. elseif ($status == 'BOUNCED')
  4332. $con .= ' and untreadStatus=2';
  4333. elseif ($status == 'PARTRECORD')
  4334. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  4335. elseif ($status == 'All') {
  4336. $con .= ' and ( untreadStatus=2 or untreadStatus=1 or untreadStatus=0 or untreadStatus=3 )';
  4337. }
  4338. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4339. if (! empty ( $MebSea )) {
  4340. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  4341. }
  4342. $pageinfo ['page'] = array (
  4343. 'previous' => ''
  4344. );
  4345. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAS", $get, "" );
  4346. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4347. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  4348. $this->data ['MebSeaEn'] = $MebSea;
  4349. $this->data ['MebSea'] = urlencode ( $MebSea );
  4350. $this->data ['date'] = $date;
  4351. $this->data ['page'] = $pageinfo;
  4352. $this->data ['get'] = $get;
  4353. $this->data ['list'] = $list;
  4354. $this->data ['status'] = $status;
  4355. $this->data ['memu'] = "invoice";
  4356. $this->data ['staff'] = $this->staff;
  4357. $this->data ['receiptMemu'] = 'invoiceReceivables';
  4358. $this->render ( "/admin/invoiceAS", $this->data );
  4359. }
  4360. /**
  4361. * 收款管理
  4362. */
  4363. function invoiceReceivablesAS() {
  4364. Doo::loadModel ( 'invoiceReceivables' );
  4365. $invoiceReceivables = new invoiceReceivables ();
  4366. Doo::loadModel ( 'L_category' );
  4367. $lCategory = new L_category ();
  4368. $category = $lCategory->getCategory ();
  4369. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4370. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  4371. $page_size = 10;
  4372. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4373. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4374. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4375. $dateArr = explode ( ':', $date );
  4376. $D1 = '';
  4377. $D2 = '';
  4378. if (! empty ( $date )) {
  4379. $D1 = $dateArr [0]; // ." 00:00:00 ";
  4380. if (isset ( $dateArr [1] ))
  4381. $D2 = $dateArr [1]; // ." 23:59:59 ";
  4382. else
  4383. $D2 = $dateArr [0]; // ." 23:59:59 ";//date ( "Y-m-d" );
  4384. }
  4385. $descField = 'a.receivablesDate';
  4386. if ($timeType == 'CREATE')
  4387. $descField = 'a.date';
  4388. $con = '1';
  4389. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4390. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4391. elseif (! empty ( $D1 ) && empty ( $D2 ))
  4392. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  4393. if ($status == 'Unclaimed')
  4394. $con .= ' and a.bindStatus=0';
  4395. elseif ($status == 'Credited')
  4396. $con .= ' and a.bindStatus=1';
  4397. elseif ($status == 'Claim')
  4398. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  4399. elseif ($status == 'BBN')
  4400. $con .= ' and a.bankBatchNumber!=""';
  4401. elseif ($status == 'REFUND')
  4402. $con .= ' and ( (a.bindStatus=0 and a.refundLog!="" ) or a.bindStatus=2)';
  4403. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4404. if (! empty ( $MebSea )) {
  4405. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" or a.receivablesSerial like "%' . $MebSea . '%" )';
  4406. }
  4407. $pageinfo ['page'] = array (
  4408. 'previous' => ''
  4409. );
  4410. $sql = 'select group_concat(b.invoiceSerial) as invoiceSerial ,group_concat(b.iid) as invoiceId
  4411. from CLD_invoiceReceivables as a left join CLD_invoice as b on
  4412. find_in_set(b.iid,a.iidExtend) or a.iid=b.iid
  4413. where ' . $con . ' group by a.irid ';
  4414. $pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceReceivablesAS", $get, "" );
  4415. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4416. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', $descField );
  4417. foreach ( $list as $key => $value ) {
  4418. $list [$key] ['category'] = '';
  4419. if ($value ['receivablesCategory'] != 'PUBLIC') {
  4420. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  4421. $list [$key] ['category'] = $receivablesCategory [1];
  4422. }
  4423. }
  4424. // print_r($list);
  4425. $this->data ['category'] = $category;
  4426. $this->data ['timeType'] = $timeType;
  4427. $this->data ['MebSeaEn'] = $MebSea;
  4428. $this->data ['MebSea'] = urlencode ( $MebSea );
  4429. $this->data ['date'] = $date;
  4430. $this->data ['page'] = $pageinfo;
  4431. $this->data ['get'] = $get;
  4432. $this->data ['list'] = $list;
  4433. $this->data ['status'] = $status;
  4434. $this->data ['memu'] = "invoice";
  4435. $this->data ['staff'] = $this->staff;
  4436. $this->data ['receiptMemu'] = 'invoiceReceivables';
  4437. $this->render ( "/admin/invoiceReceivablesAS", $this->data );
  4438. }
  4439. /**
  4440. * 删除一条收款
  4441. */
  4442. function delInvoiceReceivables() {
  4443. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  4444. if (empty ( $iridKey ))
  4445. die ( 'illegal request' );
  4446. Doo::loadClass ( 'XDeode' );
  4447. $XDeode = new XDeode ( 5 );
  4448. $irid = $XDeode->decode ( $iridKey );
  4449. Doo::loadModel ( 'invoiceReceivables' );
  4450. $invoiceReceivables = new invoiceReceivables ();
  4451. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4452. if (empty ( $detail ))
  4453. die ( 'illegal request' );
  4454. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  4455. // 扣除收款汇总信息 汇总
  4456. Doo::loadModel ( 'invoiceStatistics' );
  4457. $invoiceStatistics = new invoiceStatistics ();
  4458. $item = array (
  4459. 'date' => $detail ['receivablesDate'],
  4460. 'priceClass' => 2,
  4461. 'irid' => $detail ['irid'],
  4462. 'receivablesPrice' => - $detail ['receivablesPrice']
  4463. );
  4464. if ($detail ['receivablesCategory'] != 'PUBLIC') {
  4465. $receivablesCategory = explode ( ":", $detail ['receivablesCategory'] );
  4466. $item += array (
  4467. 'cid' => $receivablesCategory [0]
  4468. );
  4469. }
  4470. if ($detail ['receivablesStaff'] != 'PUBLIC') {
  4471. $receivablesStaff = explode ( "-", $detail ['receivablesStaff'] );
  4472. $item += array (
  4473. 'staff' => $receivablesStaff [0]
  4474. );
  4475. }
  4476. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4477. return '/invoiceReceivablesAS';
  4478. }
  4479. /**
  4480. * 添加退款信息
  4481. */
  4482. function setInvoiceReceivablesRefund() {
  4483. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  4484. $refundType = $this->get_args ( 'refundType' ) && is_numeric ( $this->get_args ( 'refundType' ) ) ? $this->get_args ( 'refundType' ) : '0';
  4485. $refundCompany = $this->get_args ( 'refundCompany' ) ? $this->get_args ( 'refundCompany' ) : "";
  4486. $refundNumber = $this->get_args ( 'refundNumber' ) ? $this->get_args ( 'refundNumber' ) : "";
  4487. $refundPrice = $this->get_args ( 'refundPrice' ) ? $this->get_args ( 'refundPrice' ) : "";
  4488. $refundRemarks = $this->get_args ( 'refundRemarks' ) ? $this->get_args ( 'refundRemarks' ) : "";
  4489. if ($refundPrice < 0)
  4490. die ( 'illegal request' );
  4491. if (! empty ( $iridKey ) && ! empty ( $refundCompany ) && ! empty ( $refundNumber ) && ! empty ( $refundPrice )) {
  4492. Doo::loadModel ( 'invoiceReceivables' );
  4493. $invoiceReceivables = new invoiceReceivables ();
  4494. Doo::loadModel ( 'invoiceRefund' );
  4495. $invoiceRefund = new invoiceRefund ();
  4496. $irid = $invoiceReceivables->authcode ( $iridKey );
  4497. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4498. if ($irDetail ['receivablesPrice'] < $refundPrice)
  4499. die ( 'illegal request' );
  4500. $invoiceReceivables = new invoiceReceivables ();
  4501. $refundLog = $this->staff [0] ['username'] . ' 退款 <b class="colRed">¥' . $refundPrice . '</b>
  4502. <br/><a href="#refunded" onclick="getRefundByDetail(\'' . $iridKey . '\')" data-toggle="modal">退款信息</a> <br/>' . date ( "Y-m-d H:i:s" ) . '
  4503. ';
  4504. $item = array (
  4505. 'irid' => $irid,
  4506. 'refundCompany' => $refundCompany,
  4507. 'refundNumber' => $refundNumber,
  4508. 'refundPrice' => $refundPrice,
  4509. 'refundRemarks' => $refundRemarks,
  4510. 'refundLog' => $refundLog
  4511. );
  4512. if ($refundType == 1) {
  4513. $item += array (
  4514. 'refundType' => $refundType,
  4515. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice,
  4516. 'bindStatus' => 2
  4517. );
  4518. } elseif ($refundType == 0 && $irDetail ['receivablesPrice'] <= $refundPrice) {
  4519. $item += array (
  4520. 'refundType' => 1,
  4521. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice,
  4522. 'bindStatus' => 2
  4523. );
  4524. } else {
  4525. $item += array (
  4526. 'refundType' => $refundType,
  4527. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice
  4528. );
  4529. }
  4530. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4531. // 添加退款记录
  4532. $item = array (
  4533. 'irid' => $irid,
  4534. 'refundType' => $refundType,
  4535. 'refundCompany' => $refundCompany,
  4536. 'refundNumber' => $refundNumber,
  4537. 'refundPrice' => $refundPrice,
  4538. 'refundLog' => $refundLog,
  4539. 'refundRemarks' => $refundRemarks,
  4540. 'date' => date ( "Y-m-d H:i:s" )
  4541. );
  4542. $invoiceRefund->addInvoiceRefund ( $item );
  4543. // 扣除收款汇总信息 汇总
  4544. Doo::loadModel ( 'invoiceStatistics' );
  4545. $invoiceStatistics = new invoiceStatistics ();
  4546. $item = array (
  4547. 'date' => $irDetail ['receivablesDate'],
  4548. 'priceClass' => 2,
  4549. 'irid' => $irDetail ['irid'],
  4550. 'receivablesPrice' => - $refundPrice
  4551. );
  4552. if ($irDetail ['receivablesCategory'] != 'PUBLIC') {
  4553. $receivablesCategory = explode ( ":", $irDetail ['receivablesCategory'] );
  4554. $item += array (
  4555. 'cid' => $receivablesCategory [0]
  4556. );
  4557. }
  4558. if ($irDetail ['receivablesStaff'] != 'PUBLIC') {
  4559. $receivablesStaff = explode ( "-", $irDetail ['receivablesStaff'] );
  4560. $item += array (
  4561. 'staff' => $receivablesStaff [0]
  4562. );
  4563. }
  4564. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4565. return '/invoiceReceivablesAS';
  4566. }
  4567. die ( 'illegal request' );
  4568. }
  4569. function ajaxCheckInvoiceReceivablesRefund() {
  4570. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  4571. $refundPrice = $this->get_args ( 'refundPrice' ) ? $this->get_args ( 'refundPrice' ) : "";
  4572. if ($refundPrice < 0) {
  4573. echo json_encode ( array (
  4574. 'error' => '金额不能为负'
  4575. ) );
  4576. die ();
  4577. }
  4578. if (! empty ( $refundPrice ) && ! empty ( $iridKey )) {
  4579. Doo::loadModel ( 'invoiceReceivables' );
  4580. $invoiceReceivables = new invoiceReceivables ();
  4581. $irid = $invoiceReceivables->authcode ( $iridKey );
  4582. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4583. if ($irDetail ['receivablesPrice'] < $refundPrice) {
  4584. echo json_encode ( array (
  4585. 'error' => '退款金额不能超过收款金额'
  4586. ) );
  4587. die ();
  4588. }
  4589. echo json_encode ( array (
  4590. 'ok' => '可以使用!'
  4591. ) );
  4592. die ();
  4593. }
  4594. }
  4595. /**
  4596. * 获得收款退款信息
  4597. */
  4598. function getRefundByDetail() {
  4599. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  4600. Doo::loadModel ( 'invoiceReceivables' );
  4601. $invoiceReceivables = new invoiceReceivables ();
  4602. if (! empty ( $iridKey )) {
  4603. $irid = $invoiceReceivables->authcode ( $iridKey );
  4604. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4605. echo json_encode ( array (
  4606. 'status' => 1,
  4607. 'irDetail' => $irDetail
  4608. ) );
  4609. die ();
  4610. }
  4611. echo json_encode ( array (
  4612. 'status' => 2
  4613. ) );
  4614. }
  4615. /**
  4616. * 根据收款序列号获得收款退款信息
  4617. */
  4618. function ajaxGetInvoiceReceivablesBySerial() {
  4619. $receivablesSerial = $this->get_args ( 'receivablesSerial' ) ? $this->get_args ( 'receivablesSerial' ) : '';
  4620. if (! empty ( $receivablesSerial )) {
  4621. Doo::loadModel ( 'invoiceReceivables' );
  4622. $invoiceReceivables = new invoiceReceivables ();
  4623. // , ' and refundLog=""'
  4624. $irDetail = $invoiceReceivables->getInvoiceReceivablesBySerial ( $receivablesSerial );
  4625. $html = '';
  4626. if (! empty ( $irDetail ))
  4627. $html = '<td><b>¥' . $irDetail ['receivablesPrice'] . '</b></td>
  4628. <td>' . $irDetail ['receivablesMessage'] . '</td>
  4629. <td>' . $irDetail ['receivablesBank'] . '<br>' . $irDetail ['receivablesDate'] . '</td>
  4630. <td>' . $irDetail ['title'] . '-' . $irDetail ['username'] . '<br>' . $irDetail ['confirmTime'] . '</td>
  4631. <td>' . $irDetail ['recepitTitleMark'] . '
  4632. <input type="hidden" name="iridKey" id="iridKey" value="' . $irDetail ['iridKey'] . '">
  4633. </td>';
  4634. echo json_encode ( array (
  4635. 'status' => 1,
  4636. 'html' => $html,
  4637. 'irDetail' => $irDetail
  4638. ) );
  4639. die ();
  4640. }
  4641. echo json_encode ( array (
  4642. 'status' => 2
  4643. ) );
  4644. }
  4645. /**
  4646. * 绑定新收款
  4647. */
  4648. function relationNewInvoiceReceivables() {
  4649. $iridKeyOld = $this->get_args ( 'iridKeyOld' ) ? $this->get_args ( 'iridKeyOld' ) : '';
  4650. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  4651. if (! empty ( $iridKeyOld ) && ! empty ( $iridKey )) {
  4652. Doo::loadModel ( 'invoiceReceivables' );
  4653. $invoiceReceivables = new invoiceReceivables ();
  4654. Doo::loadClass ( 'XDeode' );
  4655. $XDeode = new XDeode ( 5 );
  4656. $irid = $XDeode->decode ( $iridKey );
  4657. $iridOld = $invoiceReceivables->authcode ( $iridKeyOld );
  4658. echo $irid . 'bbb' . $iridOld;
  4659. $oldIrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $iridOld );
  4660. $IrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4661. if (empty ( $oldIrDetail ) || empty ( $IrDetail ))
  4662. die ( 'illegal request' );
  4663. $relationLog = $this->staff [0] ['username'] . ' 关联新款 <a href="#billing" onclick="invoiceReceivblesDivShow(\'' . $iridKey . '\',\'receivables\')" data-toggle="modal">' . $IrDetail ['receivablesSerial'] . '</a>
  4664. <br/>' . date ( "Y-m-d H:i:s" ) . '
  4665. ';
  4666. $invoiceReceivables = new invoiceReceivables ();
  4667. $item = array (
  4668. 'irid' => $iridOld,
  4669. 'relationIrid' => $irid,
  4670. 'relationLog' => $relationLog
  4671. );
  4672. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4673. return '/invoiceReceivablesAS';
  4674. }
  4675. die ( 'illegal request' );
  4676. }
  4677. // function invoiceApprovalAchieve() {
  4678. // Doo::loadModel ( 'invoice' );
  4679. // $invoice = new invoice ();
  4680. // $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  4681. // $page_size = 12;
  4682. // $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4683. // $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4684. // $get = "/" . $date;
  4685. // $con = '';
  4686. // if ($date == 'MONTHO')
  4687. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4688. // elseif ($date == 'MONTHT')
  4689. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4690. // elseif ($date == 'MONTHY')
  4691. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4692. // if (! empty ( $MebSea )) {
  4693. // $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4694. // $get .= "/" . $MebSea;
  4695. // }
  4696. // $pageinfo ['page'] = array (
  4697. // 'previous' => ''
  4698. // );
  4699. // $sql = '(status=1 or status=2 or status=3 or status=4) and processApprovals!=""' . $con; // echo $sql;
  4700. // $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", $get, "" );
  4701. // $limit = $pageinfo ['lower'] . ',' . $page_size;
  4702. // $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  4703. // // print_r($list);
  4704. // $this->data ['MebSeaEn'] = $MebSea;
  4705. // $this->data ['MebSea'] = urlencode ( $MebSea );
  4706. // $this->data ['get'] = $get;
  4707. // $this->data ['page'] = $pageinfo;
  4708. // $this->data ['list'] = $list;
  4709. // $this->data ['date'] = $date;
  4710. // $this->data ['memu'] = "invoice";
  4711. // $this->data ['staff'] = $this->staff;
  4712. // $this->data ['receiptMemu'] = 'invoiceApproval';
  4713. // $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  4714. // }
  4715. /**
  4716. * 获得审批发票的信息以及审批页面
  4717. */
  4718. function ajaxGetInvoiceApprovalDetail() {
  4719. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  4720. if (empty ( $serial )) {
  4721. echo json_encode ( array (
  4722. 'status' => 2,
  4723. 'msg' => 'illegal request'
  4724. ) );
  4725. die ();
  4726. }
  4727. Doo::loadModel ( 'invoice' );
  4728. $invoice = new invoice ();
  4729. Doo::loadModel ( 'invoiceOperationLog' );
  4730. $invoiceOperationLog = new invoiceOperationLog ();
  4731. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  4732. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  4733. if (empty ( $detail ))
  4734. $html = '';
  4735. else {
  4736. $html = '
  4737. <form action="/invoiceApprovalDo" method="post" name="invoiceApproval" class="nice-validator n-yellow" novalidate="novalidate">
  4738. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  4739. <input type="hidden" name="status" value="">
  4740. <input type="hidden" name="divApproval" value="divApproval">
  4741. <div class="modal-dialog modal-lg">
  4742. <div class="modal-content"><div class="modal-header"><h3>发票审批详情</h3></div>
  4743. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  4744. <tr>
  4745. <th class="taC" width="150">发票审批</th><td><textarea name="opinion" style="width:98%" placeholder="在这写下您的审批意见,选填。"></textarea></td>
  4746. </tr>
  4747. <tr>
  4748. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  4749. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  4750. </tr>
  4751. <tr>
  4752. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  4753. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  4754. </tr>
  4755. <tr>
  4756. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  4757. </td>
  4758. </tr>
  4759. <tr>
  4760. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  4761. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  4762. </tr>
  4763. <tr>
  4764. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  4765. </tr></tbody></table>';
  4766. if ($detail ['invoiceType'] == 0)
  4767. $html .= '<table class="table table-bordered table-condensed"><tbody>
  4768. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  4769. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  4770. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  4771. </tr>';
  4772. else
  4773. $html .= '<table class="table table-bordered table-condensed"><tbody>
  4774. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  4775. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  4776. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  4777. ';
  4778. $html .= '<tr>
  4779. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  4780. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  4781. </tr>
  4782. <tr>
  4783. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  4784. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  4785. </tr></tbody></table>';
  4786. if ($detail ['doPost'] == 1) {
  4787. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  4788. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  4789. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  4790. </tr><tr>
  4791. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  4792. </tr><tr>
  4793. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  4794. </tr>
  4795. ';
  4796. if ($detail ['expressCom'] == 'SF')
  4797. $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>';
  4798. else
  4799. $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>';
  4800. $html .= '</tbody></table>';
  4801. }
  4802. if (! empty ( $invoiceOperationLogList )) {
  4803. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  4804. foreach ( $invoiceOperationLogList as $key => $value ) {
  4805. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  4806. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  4807. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  4808. if ($value ['status'] == 2) {
  4809. $html .= '<span class="colGreen">同意</span>';
  4810. } elseif ($value ['status'] == 3) {
  4811. $html .= '<span class="colOrange">退回</span>';
  4812. } elseif ($value ['status'] == 5) {
  4813. $html .= '<span class="colGreen">打印</span>';
  4814. } elseif ($value ['status'] == 4) {
  4815. $html .= '<span class="colRed">终止</span>';
  4816. }
  4817. $html .= $value ['operation'] . '</p></blockquote>';
  4818. }
  4819. }
  4820. $html .= '</td></tr></tbody></table>';
  4821. }
  4822. $html .= '</div><div class="modal-footer">
  4823. <a href="javascript:void(0)" node-approval="approval" diss-data="2" class="button btn-done" data-placement="top" data-toggle="ctooltip" >同意</a>
  4824. <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>
  4825. <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>
  4826. <a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>
  4827. </form>
  4828. <script type="text/javascript">
  4829. $("a[node-approval^=\'approval\']").click(function() {
  4830. $("input[name=\'status\']").val($(this).attr("diss-data"));
  4831. $("form[name=\'invoiceApproval\']").submit();
  4832. });
  4833. </script>
  4834. ';
  4835. }
  4836. echo json_encode ( array (
  4837. 'status' => 1,
  4838. 'html' => $html
  4839. ) );
  4840. die ();
  4841. }
  4842. /**
  4843. * 获得审批发票分页数据
  4844. */
  4845. function ajaxGetinvoiceApprovalAchieve() {
  4846. Doo::loadModel ( 'invoice' );
  4847. $invoice = new invoice ();
  4848. Doo::loadModel ( 'staff' );
  4849. $staff = new staff ();
  4850. Doo::loadClass ( 'XDeode' );
  4851. $XDeode = new XDeode ( 5 );
  4852. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  4853. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  4854. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  4855. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  4856. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4857. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  4858. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  4859. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  4860. $MebSea = $this->get_args ( 'search' );
  4861. $MebSea = $MebSea ['value'];
  4862. $page_size = $length;
  4863. $con = '';
  4864. if ($status == 'ALL')
  4865. $con = ' (status=1 or status=2 or status=3 or status=4) and isDelete=0 ';
  4866. elseif ($status == 'PEND')
  4867. $con = ' isDelete=0 and status=1';
  4868. elseif ($status == 'APPROVED')
  4869. $con = ' isDelete=0 and status=2';
  4870. if ($invoiceType == 'ORDINARY')
  4871. $con .= ' and invoiceType=0 ';
  4872. elseif ($invoiceType == 'SPECIAL')
  4873. $con .= ' and invoiceType=1 ';
  4874. if ($invoiceTrain == 'ORDINARY')
  4875. $con .= ' and trainId=0 ';
  4876. elseif ($invoiceTrain == 'TRAIN')
  4877. $con .= ' and trainId!=0 ';
  4878. if ($invoiceTrainName != 'ALL') {
  4879. $trainId = $XDeode->decode ( $invoiceTrainName );
  4880. if (is_numeric ( $trainId ))
  4881. $con .= ' and trainId =' . $trainId;
  4882. }
  4883. $dateArr = explode ( ':', $date );
  4884. $D1 = $dateString = '';
  4885. $D2 = '';
  4886. if (! empty ( $date )) {
  4887. $D1 = $dateArr [0];
  4888. if (isset ( $dateArr [1] ))
  4889. $D2 = $dateArr [1];
  4890. else
  4891. $D2 = '';
  4892. $dateString = $D1 . " : " . $D2;
  4893. }
  4894. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4895. $con .= ' and approvalTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4896. elseif (! empty ( $D1 ) && empty ( $D2 ))
  4897. $con .= ' and approvalTime like "%' . $D1 . '%" ';
  4898. if (! empty ( $MebSea ))
  4899. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceSerial like "%' . $MebSea . '%" )';
  4900. // /
  4901. $pageinfo ['page'] = array (
  4902. 'previous' => ''
  4903. );
  4904. $sql = ' ' . $con;
  4905. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", '', "" );
  4906. $limit = $page . ',' . $page_size;
  4907. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  4908. $approvalList = array ();
  4909. $html = '
  4910. <script type="text/javascript">
  4911. </script>
  4912. ';
  4913. foreach ( $list as $key => $value ) {
  4914. $irDetail = array ();
  4915. if ($value ['status'] == 1 && $value ['pendingApprovals'] == $this->staff [0] ['sid']) {
  4916. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoiceApproval(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">审批发票</a>' );
  4917. } else
  4918. array_push ( $irDetail, '' );
  4919. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  4920. if ($value ['invoiceType'] == 1)
  4921. array_push ( $irDetail, $value ['invoiceCompany'] );
  4922. else
  4923. array_push ( $irDetail, $value ['invoiceTitle'] );
  4924. array_push ( $irDetail, $value ['TIN'] );
  4925. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  4926. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  4927. array_push ( $irDetail, $value ['remark'] );
  4928. array_push ( $irDetail, $value ['invoiceElement'] );
  4929. array_push ( $irDetail, $value ['invoiceQuantity'] );
  4930. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  4931. if ($value ['invoiceType'] == 1)
  4932. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  4933. else
  4934. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  4935. array_push ( $irDetail, $value ['recipients'] . $value ['recipientsPhone'] );
  4936. array_push ( $irDetail, $value ['recipientsAddress'] );
  4937. array_push ( $irDetail, $value ['mailItems'] );
  4938. array_push ( $irDetail, $value ['userName'] . '&nbsp;' . $value ['date'] );
  4939. $fchtml = $value ['OL'] ['operation'];
  4940. if (count ( $list ) == $page_size)
  4941. $fchtml = $value ['OL'] ['operation'] . $html;
  4942. // 最后的审批意见
  4943. array_push ( $irDetail, $fchtml );
  4944. if ($value ['status'] == 2)
  4945. array_push ( $irDetail, '<span class="colGreen">同意</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  4946. elseif ($value ['status'] == 3)
  4947. array_push ( $irDetail, '<span class="colOrange">退回</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  4948. elseif ($value ['status'] == 4)
  4949. array_push ( $irDetail, '<span class="colRed">终止</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  4950. else
  4951. array_push ( $irDetail, '' );
  4952. array_push ( $approvalList, $irDetail );
  4953. }
  4954. // $approvalListJson = json_encode ( $approvalList );
  4955. $recordsFiltered = $pageinfo ['total_data'];
  4956. echo json_encode ( array (
  4957. "draw" => intval ( $draw ),
  4958. "recordsTotal" => intval ( $pageinfo ['total_data'] ),
  4959. "recordsFiltered" => intval ( $recordsFiltered ),
  4960. "data" => $approvalList
  4961. ), JSON_UNESCAPED_UNICODE );
  4962. }
  4963. /**
  4964. * 审批发票查看更多--重构
  4965. */
  4966. function invoiceApprovalAchieve() {
  4967. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'ALL';
  4968. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  4969. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  4970. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  4971. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4972. Doo::loadModel ( 'invoiceTraining' );
  4973. $invoiceTraining = new invoiceTraining ();
  4974. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  4975. $this->data ['trainList'] = $trainList;
  4976. $this->data ['dateString'] = $date;
  4977. $this->data ['status'] = $status;
  4978. $this->data ['invoiceType'] = $invoiceType;
  4979. $this->data ['invoiceTrain'] = $invoiceTrain;
  4980. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  4981. $this->data ['memu'] = "invoice";
  4982. $this->data ['staff'] = $this->staff;
  4983. $this->data ['receiptMemu'] = 'invoiceApproval';
  4984. $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  4985. }
  4986. function invoiceTAchieve() {
  4987. Doo::loadModel ( 'invoice' );
  4988. $invoice = new invoice ();
  4989. Doo::loadClass ( 'XDeode' );
  4990. $XDeode = new XDeode ( 5 );
  4991. Doo::loadModel ( 'staff' );
  4992. $staff = new staff ();
  4993. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  4994. $page_size = 12;
  4995. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4996. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4997. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  4998. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  4999. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5000. Doo::loadModel ( 'invoiceTraining' );
  5001. $invoiceTraining = new invoiceTraining ();
  5002. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  5003. $get = "/" . $date;
  5004. $con = '';
  5005. if ($date == 'MONTHO')
  5006. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  5007. elseif ($date == 'MONTHT')
  5008. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  5009. elseif ($date == 'MONTHY')
  5010. $con =' and YEAR(updateTime) = YEAR(NOW())';//$con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  5011. if ($invoiceType == 'ORDINARY')
  5012. $con .= ' and invoiceType=0 ';
  5013. elseif ($invoiceType == 'SPECIAL')
  5014. $con .= ' and invoiceType=1 ';
  5015. if ($invoiceTrain == 'ORDINARY')
  5016. $con .= ' and trainId=0 ';
  5017. elseif ($invoiceTrain == 'TRAIN')
  5018. $con .= ' and trainId!=0 ';
  5019. if ($invoiceTrainName != 'ALL') {
  5020. $trainId = $XDeode->decode ( $invoiceTrainName );
  5021. if (is_numeric ( $trainId ))
  5022. $con .= ' and trainId =' . $trainId;
  5023. }
  5024. if (! empty ( $MebSea )) {
  5025. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  5026. $get .= "/" . $MebSea;
  5027. }
  5028. $pageinfo ['page'] = array (
  5029. 'previous' => ''
  5030. );
  5031. $sql = "";
  5032. $action = "";
  5033. if ($this->ACTION == 'invoicePrintAchieve') {
  5034. $sql = "status=2 and printStatus=1 and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  5035. $action = "invoicePrintAchieve";
  5036. } elseif ($this->ACTION == 'invoicePostAchieve') {
  5037. // and untreadStatus=0
  5038. $sql = "postStatus=1 and doPost=1 and status=2 and isDelete=0" . $con;
  5039. $action = "invoicePostAchieve";
  5040. } elseif ($this->ACTION == 'invoiceUntreadAchieve') { // printStatus=1 and
  5041. $sql = " untreadStatus=2 and status=2 " . $con;
  5042. $action = "invoiceUntreadAchieve";
  5043. }
  5044. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  5045. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5046. $this->data ['MebSeaEn'] = $MebSea;
  5047. $this->data ['MebSea'] = urlencode ( $MebSea );
  5048. $this->data ['get'] = $get;
  5049. $this->data ['page'] = $pageinfo;
  5050. $this->data ['trainList'] = $trainList;
  5051. $this->data ['invoiceType'] = $invoiceType;
  5052. $this->data ['invoiceTrain'] = $invoiceTrain;
  5053. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  5054. $this->data ['date'] = $date;
  5055. $this->data ['memu'] = "invoice";
  5056. $this->data ['staff'] = $this->staff;
  5057. if ($this->ACTION == 'invoicePrintAchieve') {
  5058. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  5059. $this->data ['receiptMemu'] = 'invoicePrint';
  5060. $this->data ['list'] = $list;
  5061. $this->render ( "/admin/invoicePrintAchieve", $this->data );
  5062. } elseif ($this->ACTION == 'invoicePostAchieve') {
  5063. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  5064. Doo::loadModel ( 'express' );
  5065. $express = new express ();
  5066. $expressList = $express->getExpressByAll ();
  5067. $this->data ['expressList'] = $expressList;
  5068. $this->data ['receiptMemu'] = 'invoicePost';
  5069. $this->data ['list'] = $list;
  5070. $this->render ( "/admin/invoicePostAchieve", $this->data );
  5071. } elseif ($this->ACTION == 'invoiceUntreadAchieve') {
  5072. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  5073. $this->data ['receiptMemu'] = 'invoiceUntread';
  5074. $this->data ['list'] = $list;
  5075. $this->render ( "/admin/invoiceUntreadAchieve", $this->data );
  5076. }
  5077. }
  5078. /**
  5079. * 公司应收款
  5080. */
  5081. function invoiceAggregateCompanyDetail() {
  5082. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  5083. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  5084. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : 'ALL';
  5085. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  5086. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  5087. Doo::loadClass ( 'XDeode' );
  5088. $XDeode = new XDeode ( 5 );
  5089. Doo::loadModel ( 'invoice' );
  5090. $invoice = new invoice ();
  5091. Doo::loadModel ( 'staff' );
  5092. $staff = new staff ();
  5093. Doo::loadModel ( "invoiceCompanyManage" );
  5094. $invoiceCompanyManage = new invoiceCompanyManage ();
  5095. Doo::loadModel ( 'L_category' );
  5096. $category = new L_category ();
  5097. $sid = '';
  5098. if (! empty ( $sidKey ))
  5099. $sid = $XDeode->decode ( $sidKey );
  5100. $staffDetail = $staff->getStaffBySid ( $sid );
  5101. $cid = '';
  5102. if (! empty ( $cidKey ))
  5103. $cid = $XDeode->decode ( $cidKey );
  5104. $imcStaff = $invoiceCompanyManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  5105. $cidList = array ();
  5106. foreach ( $imcStaff as $key => $value ) {
  5107. array_push ( $cidList, $value ['cid'] );
  5108. }
  5109. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  5110. $cidString = implode ( ',', $cidList );
  5111. if (empty ( $cid ))
  5112. $staffList = $staff->getStaffInCid ( $cidString );
  5113. else
  5114. $staffList = $staff->getStaffByCid ( $cid ); //
  5115. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  5116. $page_size = 25;
  5117. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5118. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  5119. $con = ' status=2 and untreadStatus!=2 ';
  5120. $statisticsCon = '';
  5121. if (! empty ( $year ) && is_numeric ( $year ))
  5122. $con .= ' and Year(printTime)=' . $year . '';
  5123. if (! empty ( $month ) && is_numeric ( $month ))
  5124. $con .= ' and Month(printTime)="' . $month . '" ';
  5125. if ($status == 'UNRECORD')
  5126. $con .= ' and printStatus=1 and untreadStatus=0';
  5127. elseif ($status == 'RECORD')
  5128. $con .= ' and printStatus=1 and untreadStatus=3';
  5129. elseif ($status == 'BOUNCED')
  5130. $con .= ' and untreadStatus=2';
  5131. elseif ($status == 'PARTRECORD')
  5132. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  5133. elseif ($status == 'All') {
  5134. $con .= ' and printStatus=1 and ( untreadStatus=0 or untreadStatus=3 )';
  5135. }
  5136. if (! empty ( $sid ) && is_numeric ( $sid ))
  5137. $con .= ' and sid=' . $sid;
  5138. if (! empty ( $cid ) && is_numeric ( $cid ))
  5139. $con .= ' and cid=' . $cid;
  5140. else
  5141. $con .= ' and cid in (' . $cidString . ')';
  5142. // 开票内容筛选
  5143. if (! empty ( $invoiceElement ) && $invoiceElement != 'ALL') {
  5144. $con .= ' and invoiceElement="' . $invoiceElement . '"';
  5145. }
  5146. $get = "/" . $status . "?cidKey=" . $cidKey . "&sidKey=" . $sidKey . "&year=" . $year . "&month=" . $month . "&invoiceElement=" . $invoiceElement;
  5147. if (! empty ( $MebSea )) {
  5148. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  5149. }
  5150. $pageinfo ['page'] = array (
  5151. 'previous' => ''
  5152. );
  5153. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateCompanyDetail", $get, "" );
  5154. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5155. // 应收款合计
  5156. $ics = $invoice->getInvoiceCompanyStatistics ( $con );
  5157. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  5158. $monthHtml = "";
  5159. if ($year != "ALL") {
  5160. for($i = 1; $i <= 12; $i ++) {
  5161. if ($i == $month)
  5162. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  5163. else
  5164. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  5165. }
  5166. }
  5167. $this->data ['monthHtml'] = $monthHtml;
  5168. $this->data ['year'] = $year;
  5169. $this->data ['month'] = $month;
  5170. $this->data ['ics'] = $ics;
  5171. $this->data ['cidKey'] = $cidKey;
  5172. $this->data ['sid'] = $sid;
  5173. $this->data ['staffDetail'] = $staffDetail;
  5174. $this->data ['staffList'] = $staffList;
  5175. $this->data ['MebSeaEn'] = $MebSea;
  5176. $this->data ['MebSea'] = urlencode ( $MebSea );
  5177. $this->data ['invoiceDetail'] = array (
  5178. 'invoiceElement' => $invoiceElement
  5179. );
  5180. $this->data ['page'] = $pageinfo;
  5181. $this->data ['get'] = $get;
  5182. $this->data ['list'] = $list;
  5183. $this->data ['status'] = $status;
  5184. $this->data ['categoryList'] = $categoryList;
  5185. $this->data ['memu'] = "invoice";
  5186. $this->data ['staff'] = $this->staff;
  5187. $this->data ['receiptMemu'] = 'invoiceAggregateCompanyDetail';
  5188. $this->render ( "/admin/invoiceAggregateCompanyDetail", $this->data );
  5189. }
  5190. /**
  5191. * 获取一条收款信息
  5192. */
  5193. function ajaxGetInvoiceReceivables() {
  5194. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  5195. Doo::loadModel ( 'invoiceReceivables' );
  5196. $invoiceReceivables = new invoiceReceivables ();
  5197. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5198. echo json_encode ( array (
  5199. 'status' => 1,
  5200. 'detail' => $detail
  5201. ) );
  5202. }
  5203. /**
  5204. * 异步获取办事处用户
  5205. */
  5206. function ajaxGetStaffByCategory() {
  5207. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "";
  5208. Doo::loadModel ( 'staff' );
  5209. $staff = new staff ();
  5210. if ($cid == "PUBLIC") {
  5211. echo json_encode ( array (
  5212. 'status' => 1,
  5213. 'html' => '<option value="PUBLIC">办事处待认领款项</option>'
  5214. ) );
  5215. die ();
  5216. }
  5217. if (! is_numeric ( $cid )) {
  5218. echo json_encode ( array (
  5219. 'status' => 0,
  5220. 'msg' => 'illegal request'
  5221. ) );
  5222. die ();
  5223. }
  5224. $staffList = $staff->getStaffByCid ( $cid );
  5225. $html = '<option value="PUBLIC">办事处待认领款项</option>';
  5226. foreach ( $staffList as $key => $value ) {
  5227. $html .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  5228. }
  5229. echo json_encode ( array (
  5230. 'status' => 1,
  5231. 'html' => $html
  5232. ) );
  5233. }
  5234. /**
  5235. * 异步获取一条发票的邮寄信息
  5236. */
  5237. function ajaxGetInvoicePostDetail() {
  5238. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  5239. Doo::loadModel ( 'invoice' );
  5240. $invoice = new invoice ();
  5241. $iid = $invoice->authcode ( $iid );
  5242. Doo::loadModel ( 'express' );
  5243. $express = new express ();
  5244. $expressList = $express->getExpressByAll ();
  5245. if (! is_numeric ( $iid )) {
  5246. echo json_encode ( array (
  5247. 'status' => 0,
  5248. 'msg' => 'illegal request'
  5249. ) );
  5250. die ();
  5251. }
  5252. $select = "iid,recipients,recipientsPhone,recipientsAddress,mailItems,expressCompany,expressNumber,actualItems";
  5253. $invoiceDetail = $invoice->getInvoiceByIid ( $iid, $select );
  5254. $html = "";
  5255. foreach ( $expressList as $key => $value ) {
  5256. if ($value ['company'] == $invoiceDetail ['expressCompany'])
  5257. $html .= '<option selected value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  5258. else
  5259. $html .= '<option value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  5260. }
  5261. $invoiceDetail ['eaHtml'] = $html;
  5262. echo json_encode ( array (
  5263. 'status' => 1,
  5264. 'invoiceDetail' => $invoiceDetail
  5265. ) );
  5266. }
  5267. /**
  5268. *
  5269. * @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 ) ); }
  5270. */
  5271. /**
  5272. *
  5273. * @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 ) ); }
  5274. */
  5275. /**
  5276. * 我的收款中 选择哪个发票入账,进行金额判断
  5277. */
  5278. function ajaxCompareInvoicePrice() {
  5279. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  5280. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  5281. Doo::loadModel ( 'invoice' );
  5282. $invoice = new invoice ();
  5283. Doo::loadModel ( 'invoiceReceivables' );
  5284. $invoiceReceivables = new invoiceReceivables ();
  5285. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  5286. $keyList = explode ( ';', $claimKey );
  5287. $receivablesPrice = 0;
  5288. foreach ( $keyList as $key => $value ) {
  5289. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $value );
  5290. $receivablesPrice += $detailM ['receivablesPrice'];
  5291. }
  5292. if ($receivablesPrice > $detail ['invoicePrice']) {
  5293. $price = $receivablesPrice - $detail ['invoicePrice'];
  5294. echo json_encode ( array (
  5295. 'status' => 1,
  5296. 'price' => $price
  5297. ) );
  5298. } else
  5299. echo json_encode ( array (
  5300. 'status' => 2
  5301. ) );
  5302. }
  5303. /**
  5304. * 获得打印发票
  5305. */
  5306. function ajaxGetInvoiceInfoByPrint() {
  5307. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5308. if (empty ( $serial )) {
  5309. echo json_encode ( array (
  5310. 'status' => 2,
  5311. 'msg' => 'illegal request'
  5312. ) );
  5313. die ();
  5314. }
  5315. Doo::loadModel ( 'invoice' );
  5316. $invoice = new invoice ();
  5317. Doo::loadModel ( 'invoiceOperationLog' );
  5318. $invoiceOperationLog = new invoiceOperationLog ();
  5319. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5320. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5321. Doo::loadModel ( 'invoicePaper' );
  5322. $invoicePaper = new invoicePaper ();
  5323. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $detail ['invoiceType'] );
  5324. if (empty ( $detail ))
  5325. $html = '';
  5326. else {
  5327. $html = '
  5328. <form action="/invoicePrintDo" method="post" name="invoicePrint" class="nice-validator n-yellow" onSubmit="return checkPrintForm()" novalidate="novalidate">
  5329. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  5330. <input type="hidden" name="invoicePrintType" value="invoicePrintType">
  5331. <div class="modal-dialog modal-lg">
  5332. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  5333. <div class="modal-body saeaList">
  5334. <table class="table table-bordered table-condensed"><tbody>
  5335. <tr>
  5336. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5337. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5338. </tr>
  5339. <tr>
  5340. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5341. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5342. </tr>
  5343. <tr>
  5344. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5345. </td>
  5346. </tr>
  5347. <tr>
  5348. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5349. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5350. </tr>
  5351. <tr>
  5352. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5353. </tr></tbody></table>';
  5354. if ($detail ['invoiceType'] == 0)
  5355. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5356. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5357. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5358. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5359. </tr>';
  5360. else
  5361. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5362. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5363. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5364. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5365. ';
  5366. $html .= '<tr>
  5367. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5368. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5369. </tr>
  5370. <tr>
  5371. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5372. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5373. </tr></tbody></table>';
  5374. if ($detail ['doPost'] == 1)
  5375. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5376. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5377. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5378. </tr><tr>
  5379. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5380. </tr><tr>
  5381. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5382. </tr></tbody></table>';
  5383. if (! empty ( $invoiceOperationLogList )) {
  5384. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th><th class="taC">发票打印</th></tr><tr><td>';
  5385. foreach ( $invoiceOperationLogList as $key => $value ) {
  5386. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5387. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5388. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5389. if ($value ['status'] == 2) {
  5390. $html .= '<span class="colGreen">同意</span>';
  5391. } elseif ($value ['status'] == 3) {
  5392. $html .= '<span class="colOrange">退回</span>';
  5393. } elseif ($value ['status'] == 5) {
  5394. $html .= '<span class="colGreen">打印</span>';
  5395. } elseif ($value ['status'] == 4) {
  5396. $html .= '<span class="colRed">终止</span>';
  5397. }
  5398. $html .= $value ['operation'] . '</p></blockquote>';
  5399. }
  5400. }
  5401. $html .= '</td>
  5402. <td><span class="colRed">*</span>
  5403. <select name="invoiceNo" id="invoiceNo" style="width:97%">';
  5404. foreach ( $invoicePaperList as $key => $value ) {
  5405. $html .= '<option value="' . $value ['ipidKey'] . '">No.' . $value ['invoiceNo'] . '</option>';
  5406. }
  5407. $html .= '</select>
  5408. <span class="red" id="p-msg"></span>
  5409. </td>
  5410. </tr></tbody></table>';
  5411. }
  5412. $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>
  5413. </div></div></form>
  5414. <link rel=stylesheet href="' . WEB_SITE_GLOBAL . 'css/jquery.validator.css">
  5415. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/jquery.validator.min.js"></script>
  5416. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/zh-CN.js"></script>
  5417. <script src="' . WEB_SITE_GLOBAL . 'js/invoice.validator.js"></script>
  5418. ';
  5419. }
  5420. echo json_encode ( array (
  5421. 'status' => 1,
  5422. 'html' => $html
  5423. ) );
  5424. die ();
  5425. }
  5426. /**
  5427. * @ 获得与我有关收款数据 --需求变更 废弃 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 ) ); }
  5428. */
  5429. function ajaxGetInvoiceInfoByType() {
  5430. $type = $this->get_args ( 'type' ) ? $this->get_args ( 'type' ) : "";
  5431. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5432. $loss = $this->get_args ( 'loss' ) ? $this->get_args ( 'loss' ) : false;
  5433. if (empty ( $serial )) {
  5434. echo json_encode ( array (
  5435. 'status' => 2,
  5436. 'msg' => 'illegal request'
  5437. ) );
  5438. die ();
  5439. }
  5440. if ($type == 'INVOICE') {
  5441. Doo::loadModel ( 'invoice' );
  5442. $invoice = new invoice ();
  5443. Doo::loadModel ( 'invoiceOperationLog' );
  5444. $invoiceOperationLog = new invoiceOperationLog ();
  5445. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5446. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5447. if (empty ( $detail ))
  5448. $html = '';
  5449. else {
  5450. $html = '
  5451. <div class="modal-dialog modal-lg">
  5452. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  5453. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  5454. <tr>
  5455. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5456. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5457. </tr>
  5458. <tr>
  5459. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5460. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5461. </tr>
  5462. <tr>
  5463. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5464. </td>
  5465. </tr>
  5466. <tr>
  5467. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5468. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5469. </tr>
  5470. <tr>
  5471. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5472. </tr></tbody></table>';
  5473. if ($detail ['invoiceType'] == 0)
  5474. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5475. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5476. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5477. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5478. </tr>';
  5479. else
  5480. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5481. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5482. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5483. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5484. ';
  5485. $html .= '<tr>
  5486. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5487. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5488. </tr>
  5489. <tr>
  5490. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5491. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5492. </tr></tbody></table>';
  5493. if ($detail ['doPost'] == 1) {
  5494. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5495. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5496. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5497. </tr><tr>
  5498. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5499. </tr><tr>
  5500. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5501. </tr>
  5502. ';
  5503. if ($detail ['expressCom'] == 'SF')
  5504. $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>';
  5505. else
  5506. $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>';
  5507. $html .= '</tbody></table>';
  5508. }
  5509. if (! empty ( $invoiceOperationLogList )) {
  5510. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  5511. foreach ( $invoiceOperationLogList as $key => $value ) {
  5512. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5513. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5514. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5515. if ($value ['status'] == 2) {
  5516. $html .= '<span class="colGreen">同意</span>';
  5517. } elseif ($value ['status'] == 3) {
  5518. $html .= '<span class="colOrange">退回</span>';
  5519. } elseif ($value ['status'] == 5) {
  5520. $html .= '<span class="colGreen">打印</span>';
  5521. } elseif ($value ['status'] == 4) {
  5522. $html .= '<span class="colRed">终止</span>';
  5523. }
  5524. $html .= $value ['operation'] . '</p></blockquote>';
  5525. }
  5526. }
  5527. $html .= '</td></tr></tbody></table>';
  5528. }
  5529. $html .= '</div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  5530. }
  5531. echo json_encode ( array (
  5532. 'status' => 1,
  5533. 'html' => $html
  5534. ) );
  5535. die ();
  5536. } elseif ($type == 'RECEIVABLES') {
  5537. Doo::loadModel ( 'invoiceReceivables' );
  5538. $invoiceReceivables = new invoiceReceivables ();
  5539. Doo::loadModel ( 'invoiceRefund' );
  5540. $invoiceRefund = new invoiceRefund ();
  5541. $detail = $invoiceReceivables->getInvoiceReceivablesByIrsid ( $serial );
  5542. $ireList = $invoiceRefund->getInvoiceRefundIrid ( $detail ['irid'] );
  5543. if (empty ( $detail ))
  5544. $html = '';
  5545. else {
  5546. $html = '<div class="modal-dialog modal-lg"><div class="modal-content"><div class="modal-header"><h3>收款单详情</h3></div><div class="modal-body saeaList">
  5547. <table class="table table-bordered table-condensed">
  5548. <tbody><tr>
  5549. <th class="taC">收款流水号</th><td>' . $detail ['receivablesSerial'] . '</td>
  5550. <th class="taC">录入收款</th><td>' . $detail ['inputStaff'] . ' ' . $detail ['date'] . '</td>
  5551. </tr><tr>
  5552. <th class="taC">收款金额</th><td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  5553. <th class="taC">收款信息</th><td>' . $detail ['receivablesMessage'] . '</td>
  5554. </tr>
  5555. <tr>
  5556. <th class="taC">收款银行</th><td>' . $detail ['receivablesBank'] . '</td>
  5557. <th class="taC">银行到账</th><td>' . $detail ['receivablesDate'] . '</td>
  5558. </tr>
  5559. <tr>
  5560. <th class="taC">认领收款</th><td colspan="3">' . $detail ['inputStaff'] . ' 转入 ' . $detail ['username'] . ' ' . $detail ['confirmTime'] . '</td>
  5561. </tr>
  5562. </tbody></table>';
  5563. if (! empty ( $ireList )) {
  5564. $html .= '
  5565. <table class="table table-bordered table-condensed"><tbody><tr><th class="taC" colspan="5">退款记录</th></tr>
  5566. <tr>
  5567. <th class="taC">退款单位名称</th>
  5568. <th class="taC">退款的账号</th>
  5569. <th class="taC">退款金额</th>
  5570. <th class="taC">退款</th>
  5571. <th class="taC">备注</th>
  5572. </tr>
  5573. ';
  5574. foreach ( $ireList as $key => $value ) {
  5575. $refundLogList = explode ( "<br/>", $value ['refundLog'] );
  5576. $html .= '<tr>
  5577. <td>' . $value ['refundCompany'] . '</td>
  5578. <td>' . $value ['refundNumber'] . '</td>
  5579. <td><b class="colRed">¥' . $value ['refundPrice'] . '</b></td>
  5580. <td>' . $refundLogList [0] . $refundLogList [2] . '</td>
  5581. <td>' . $value ['refundRemarks'] . '</td>
  5582. </tr>
  5583. ';
  5584. }
  5585. }
  5586. $html .= '</tbody></table></div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  5587. }
  5588. echo json_encode ( array (
  5589. 'status' => 1,
  5590. 'html' => $html
  5591. ) );
  5592. die ();
  5593. } elseif ($type == 'IRTC') {
  5594. Doo::loadModel ( 'invoice' );
  5595. $invoice = new invoice ();
  5596. Doo::loadModel ( 'invoiceOperationLog' );
  5597. $invoiceOperationLog = new invoiceOperationLog ();
  5598. Doo::loadModel ( 'invoiceReceivables' );
  5599. $invoiceReceivables = new invoiceReceivables ();
  5600. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5601. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5602. if (empty ( $detail ))
  5603. $html = '';
  5604. else {
  5605. $receivablesPriceedHtml = '';
  5606. $receivablesPrice = $detail ['invoicePrice'];
  5607. if (! empty ( $detail ['irid'] )) {
  5608. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $detail ['irid'] );
  5609. if (empty ( $irList ))
  5610. $irList [0] ['sumPrice'] = 0;
  5611. $balance = $detail ['invoicePrice'] - $irList [0] ['sumPrice'];
  5612. $receivablesPriceedHtml = '<table class="table table-bordered table-condensed"><tbody><tr>
  5613. <th class="taC">已入账金额</th><td><b class="colGreen" style="font-size:18px">¥' . $irList [0] ['sumPrice'] . '</b></td>
  5614. <th class="taC">剩余入账金额</th><td><b class="colRed" style="font-size:18px">¥' . $balance . '</b></td>
  5615. </tr></tbody></table>';
  5616. $receivablesPrice = $balance;
  5617. }
  5618. if ($loss)
  5619. $detail ['invoicePrice'] = - $detail ['invoicePrice'];
  5620. $html = $receivablesPriceedHtml . '
  5621. <table class="table table-bordered table-condensed"><tbody>
  5622. <tr>
  5623. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5624. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5625. </tr>
  5626. <tr>
  5627. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5628. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5629. </tr>
  5630. <tr>
  5631. <th class="taC" width="150">发票备注</th><td colspan="3">' . $detail ['remark'] . '</td>
  5632. </tr>
  5633. <tr>
  5634. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5635. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5636. </tr>
  5637. <tr>
  5638. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5639. </tr></tbody></table>';
  5640. if ($detail ['invoiceType'] == 0) {
  5641. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5642. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5643. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5644. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5645. </tr>';
  5646. $receivablesMessage = $detail ['invoiceTitle'];
  5647. } else {
  5648. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5649. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5650. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5651. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5652. ';
  5653. $receivablesMessage = $detail ['invoiceCompany'];
  5654. }
  5655. $html .= '<tr>
  5656. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5657. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5658. </tr>
  5659. <tr>
  5660. <th class="taC">开户银行</th><td>' . $detail ['bankAccount'] . '</td>
  5661. <th class="taC">银行账号</th><td>' . $detail ['bank'] . '</td>
  5662. </tr></tbody></table>';
  5663. if ($detail ['doPost'] == 1)
  5664. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5665. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5666. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5667. </tr><tr>
  5668. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5669. </tr><tr>
  5670. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5671. </tr></tbody></table>';
  5672. if (! empty ( $invoiceOperationLogList )) {
  5673. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  5674. foreach ( $invoiceOperationLogList as $key => $value ) {
  5675. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5676. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5677. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5678. if ($value ['status'] == 2) {
  5679. $html .= '<span class="colGreen">同意</span>';
  5680. } elseif ($value ['status'] == 3) {
  5681. $html .= '<span class="colOrange">退回</span>';
  5682. } elseif ($value ['status'] == 5) {
  5683. $html .= '<span class="colGreen">打印</span>';
  5684. }
  5685. $html .= $value ['operation'] . '</p></blockquote>';
  5686. }
  5687. }
  5688. $html .= '</td></tr></tbody></table>';
  5689. }
  5690. }
  5691. echo json_encode ( array (
  5692. 'status' => 1,
  5693. 'html' => $html,
  5694. 'receivablesPrice' => $receivablesPrice,
  5695. 'receivablesMessage' => $receivablesMessage,
  5696. 'receivablesDate' => date ( "Y-m-d" ),
  5697. 'iidKey' => $serial
  5698. ) );
  5699. die ();
  5700. }
  5701. }
  5702. function ajaxGetInvoiceReceivablesByStaff() {
  5703. $postData = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : "";
  5704. if (empty ( $postData )) {
  5705. echo json_encode ( array (
  5706. 'status' => 2,
  5707. 'msg' => 'illegal request'
  5708. ) );
  5709. die ();
  5710. }
  5711. Doo::loadModel ( 'invoiceReceivables' );
  5712. $invoiceReceivables = new invoiceReceivables ();
  5713. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $postData );
  5714. if (empty ( $detail )) {
  5715. echo json_encode ( array (
  5716. 'status' => 2,
  5717. 'msg' => 'illegal request'
  5718. ) );
  5719. die ();
  5720. }
  5721. Doo::loadModel ( 'L_category' );
  5722. $lCategory = new L_category ();
  5723. Doo::loadModel ( 'staff' );
  5724. $staff = new staff ();
  5725. $staffList = $staff->getStaffByCid ( $detail ['cid'] );
  5726. $category = $lCategory->getCategory ();
  5727. $categoryHtml = '<option post-data="PUBLIC" value="PUBLIC" >公共待认领款项</option>';
  5728. $staffHtml = '<option value="PUBLIC">办事处待认领款项</option>';
  5729. foreach ( $category as $key => $value ) {
  5730. $categoryHtml .= '<option post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  5731. if ($value ['cid'] == $detail ['cid'])
  5732. $categoryHtml .= '<option selected post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  5733. }
  5734. foreach ( $staffList as $key => $value ) {
  5735. $staffHtml .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  5736. if ($value ['sid'] == $detail ['sid'])
  5737. $staffHtml .= '<option selected value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  5738. }
  5739. $rbankHtml = '<option value="广发银行珠海分行柠溪支行">广发银行珠海分行柠溪支行</option>';
  5740. echo json_encode ( array (
  5741. 'status' => 1,
  5742. 'categoryHtml' => $categoryHtml,
  5743. 'staffHtml' => $staffHtml,
  5744. 'rbankHtml' => $rbankHtml,
  5745. 'detail' => $detail
  5746. ) );
  5747. }
  5748. function ajaxGetInvoiceReceivablesByIrid() {
  5749. $irid = $this->get_args ( 'irid' ) ? $this->get_args ( 'irid' ) : "";
  5750. if (empty ( $irid )) {
  5751. echo json_encode ( array (
  5752. 'status' => 2,
  5753. 'msg' => 'illegal request'
  5754. ) );
  5755. die ();
  5756. }
  5757. Doo::loadModel ( 'invoiceReceivables' );
  5758. $invoiceReceivables = new invoiceReceivables ();
  5759. Doo::loadModel ( 'invoice' );
  5760. $invoice = new invoice ();
  5761. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid ); // 入账完成 待定 and postStatus=1
  5762. $flag = true;
  5763. $invoiceDetail = $invoice->getInvoiceByTitle ( $detail ['recepitTitleMark'], 'EXACTLY', " and status=2 and printStatus=1 and untreadStatus=0 ", $flag ); //
  5764. $bakDetail = array ();
  5765. if ($flag === false) {
  5766. array_push ( $bakDetail, $invoiceDetail );
  5767. $invoiceDetail = $bakDetail;
  5768. }
  5769. $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>
  5770. <tr>
  5771. <td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  5772. <td>' . $detail ['receivablesMessage'] . '</td>
  5773. <td>' . $detail ['receivablesBank'] . '<br>' . $detail ['receivablesDate'] . '</td>
  5774. <td>' . $detail ['title'] . '-' . $detail ['username'] . '<br>' . $detail ['confirmTime'] . '</td>
  5775. <td>' . $detail ['recepitTitleMark'] . '</td>
  5776. </tr></tbody></table>';
  5777. $isInvoice = false;
  5778. $invoiceHtml = '';
  5779. if (empty ( $invoiceDetail )) {
  5780. $isInvoice = true;
  5781. } else {
  5782. $invoiceHtml = '<table class="table table-bordered table-condensed">
  5783. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody>';
  5784. foreach ( $invoiceDetail as $key => $value ) {
  5785. $invoiceHtml .= '<tr>';
  5786. if (! empty ( $value ['invoiceType'] )) {
  5787. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  5788. } else {
  5789. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  5790. }
  5791. if (! empty ( $value ['invoiceType'] )) {
  5792. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  5793. } else {
  5794. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  5795. }
  5796. $invoiceHtml .= '
  5797. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  5798. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  5799. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir" data-ikey="' . $value ['iidKey'] . '" href="javascript:void(0)">入账</a></td>
  5800. </tr>
  5801. ';
  5802. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  5803. if (empty ( $irList ))
  5804. $irList [0] ['sumPrice'] = 0;
  5805. $balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  5806. $priceString = '';
  5807. if ($balance < $detail ['receivablesPrice']) {
  5808. $priceString = '收款金额超过开票金额,';
  5809. }
  5810. if ($balance > $detail ['receivablesPrice']) {
  5811. $priceString = '收款金额低于开票金额,';
  5812. }
  5813. }
  5814. $invoiceHtml .= '
  5815. <script>
  5816. $(\'a[bind-receivables^="ir"]\').click(function() {
  5817. var data = $(this).attr("data-ikey");
  5818. $("input[name=\'invoiceKey\']").val(data);
  5819. var invoiceKey=data;
  5820. if(invoiceKey==""){
  5821. alert("入账错误,请重新刷新页面");
  5822. return false;
  5823. }
  5824. if(window.confirm("' . $priceString . '确定入账吗?")){
  5825. $("#IBR").submit();
  5826. }else{
  5827. return false;
  5828. }
  5829. });
  5830. </script>
  5831. ';
  5832. $invoiceHtml .= '</tbody></table>';
  5833. }
  5834. echo json_encode ( array (
  5835. 'status' => 1,
  5836. 'irkey' => $detail ['iridEn'],
  5837. 'receivablesHtml' => $receivablesHtml,
  5838. 'isInvoice' => $isInvoice,
  5839. 'invoiceHtml' => $invoiceHtml
  5840. ) );
  5841. }
  5842. function ajaxGetInvoiceReceivablesByTitle() {
  5843. $title = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  5844. if (empty ( $title )) {
  5845. echo json_encode ( array (
  5846. 'status' => 2,
  5847. 'msg' => 'illegal request'
  5848. ) );
  5849. die ();
  5850. }
  5851. Doo::loadModel ( 'invoice' );
  5852. $invoice = new invoice ();
  5853. $invoiceDetail = $invoice->getInvoiceByTitle ( $title, 'FUZZY', " and status=2 and printStatus=1 and untreadStatus=0 and irid='' ", true );
  5854. $invoiceHtml = '';
  5855. if (! empty ( $invoiceDetail )) {
  5856. $invoiceHtml = '<table class="table table-bordered table-condensed">
  5857. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody><tr>';
  5858. foreach ( $invoiceDetail as $key => $value ) {
  5859. if (! empty ( $value ['invoiceType'] )) {
  5860. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  5861. } else {
  5862. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  5863. }
  5864. if (! empty ( $value ['invoiceType'] )) {
  5865. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  5866. } else {
  5867. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  5868. }
  5869. $invoiceHtml .= '
  5870. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  5871. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  5872. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir' . $value ['iidKeyXD'] . '" data-ikey="' . $value ['iidKey'] . '" href="#">入账</a></td>
  5873. </tr>
  5874. ';
  5875. }
  5876. $invoiceHtml .= '</tbody></table>
  5877. <script>
  5878. $(\'a[bind-receivables^="ir"]\').click(function() {
  5879. var data = $(this).attr("data-ikey");
  5880. $("input[name=\'invoiceKey\']").val(data);
  5881. var invoiceKey=$("input[name=\'invoiceKey\']").val();
  5882. if(invoiceKey==""){
  5883. alert("入账错误,请重新刷新页面");
  5884. return false;
  5885. }
  5886. if(window.confirm("确定入账吗?")){
  5887. $("#IBR").submit();
  5888. }else{
  5889. return false;
  5890. }
  5891. });
  5892. </script>
  5893. ';
  5894. }
  5895. echo json_encode ( array (
  5896. 'status' => 1,
  5897. 'invoiceHtml' => $invoiceHtml
  5898. ) );
  5899. }
  5900. function ajaxInvoicePushNotice() {
  5901. Doo::loadModel ( 'invoice' );
  5902. $invoice = new invoice ();
  5903. $approval = $invoice->getOne ( array (
  5904. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  5905. 'desc' => 'iid',
  5906. 'asArray' => true
  5907. ) );
  5908. $isNotice = false;
  5909. if (! empty ( $approval ))
  5910. $isNotice = true;
  5911. $response = array (
  5912. 'error' => 0,
  5913. 'isNotice' => $isNotice
  5914. );
  5915. echo json_encode ( $response );
  5916. exit ();
  5917. }
  5918. public function ajaxCheckInvoiceNoUniqueness() {
  5919. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  5920. Doo::loadModel ( 'invoice' );
  5921. $invoice = new invoice ();
  5922. if (! empty ( $invoiceNo )) {
  5923. Doo::loadModel ( 'invoicePaper' );
  5924. $invoicePaper = new invoicePaper ();
  5925. Doo::loadClass ( 'XDeode' );
  5926. $XDeode = new XDeode ( 5 );
  5927. $ipid = $XDeode->decode ( $invoiceNo );
  5928. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  5929. $info = $invoice->getOne ( array (
  5930. 'where' => "invoiceNo = '" . $paperDetail ['invoiceNo'] . "'",
  5931. 'asArray' => TRUE
  5932. ) );
  5933. if (! empty ( $info )) {
  5934. echo json_encode ( array (
  5935. 'error' => '发票号已存在'
  5936. ) );
  5937. die ();
  5938. } else
  5939. echo json_encode ( array (
  5940. 'ok' => '可以使用!'
  5941. ) );
  5942. die ();
  5943. }
  5944. }
  5945. function ajaxCheckInvoicePrice() {
  5946. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) && is_numeric ( $this->get_args ( 'receivablesPrice' ) ) ? $this->get_args ( 'receivablesPrice' ) : "";
  5947. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  5948. Doo::loadModel ( 'invoice' );
  5949. $invoice = new invoice ();
  5950. Doo::loadModel ( 'invoiceReceivables' );
  5951. $invoiceReceivables = new invoiceReceivables ();
  5952. Doo::loadClass ( 'XDeode' );
  5953. $XDeode = new XDeode ( 5 );
  5954. if (! empty ( $receivablesPrice ) && ! empty ( $iidKey )) {
  5955. $iidKey = $XDeode->decode ( $iidKey );
  5956. $info = $invoice->getInvoiceByIid ( $iidKey );
  5957. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $info ['irid'] );
  5958. if (empty ( $irList ))
  5959. $irList [0] ['sumPrice'] = 0;
  5960. $balance = $info ['invoicePrice'] - $irList [0] ['sumPrice'];
  5961. if ($balance < $receivablesPrice) {
  5962. echo json_encode ( array (
  5963. 'error' => '收款金额超过开票金额。'
  5964. ) );
  5965. die ();
  5966. }
  5967. if ($balance > $receivablesPrice) {
  5968. echo json_encode ( array (
  5969. 'error' => '收款金额低于开票金额。'
  5970. ) );
  5971. die ();
  5972. }
  5973. }
  5974. }
  5975. /**
  5976. * 旧输入导入
  5977. */
  5978. function importInvoice() {
  5979. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  5980. $data ['emsg'] = "";
  5981. if ($emsg != "")
  5982. $data ['emsg'] = "请填写完整的数据";
  5983. $data ['time'] = time ();
  5984. $this->render ( "/admin/invoiceImport", $data );
  5985. }
  5986. function uploadInvoice() {
  5987. // move_uploaded_file($_FILES['Filedata']['tmp_name'], "/upload/".$_FILES['Filedata']['name']);
  5988. if (isset ( $_FILES ['Filedata'] ['name'] )) {
  5989. $file = $_FILES ['Filedata'] ['tmp_name'];
  5990. $error = false;
  5991. if (! is_uploaded_file ( $file )) {
  5992. $error = '400 Bad Request';
  5993. }
  5994. if ($error) {
  5995. header ( 'HTTP/1.0 ' . $error );
  5996. die ( 'Error ' . $error );
  5997. } else {
  5998. include (DOO::conf ()->SITE_PATH . 'protected/plugin/io.han.php');
  5999. $this->IoHandler = new IoHandler ();
  6000. $pics = explode ( '.', $_FILES ['Filedata'] ['name'] );
  6001. // $filedir=$_POST['time'];
  6002. // 调用定义物理路径
  6003. $t = DOO::conf ()->SITE_PATH . "upload/invoice/";
  6004. $this->IoHandler->MakeDir ( $t );
  6005. $filename = $this->_GetFileEXT ( $_FILES ['Filedata'] ['name'] );
  6006. if ($filename != 'xlsx')
  6007. return "";
  6008. // $upload_dir = $t."/".time().rand(10,100).".".$filename;
  6009. $upload_file = iconv ( "UTF-8", "GB2312", $_FILES ["Filedata"] ["name"] );
  6010. $upload_dir = $t . "/" . $upload_file;
  6011. $k = move_uploaded_file ( $file, $upload_dir );
  6012. if ($k) {
  6013. $m = round ( $_FILES ['Filedata'] ['size'] / 1024 / 1024, 2 );
  6014. echo $pics [0] . "." . $filename . "#" . $m . "#" . $_FILES ['Filedata'] ['size'];
  6015. }
  6016. }
  6017. }
  6018. }
  6019. function importInvoiceDo() {
  6020. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  6021. if ($path != "") {
  6022. Doo::loadModel ( 'invoice' );
  6023. Doo::loadModel ( 'staff' );
  6024. $staff = new staff ();
  6025. Doo::loadModel ( 'invoiceStatistics' );
  6026. Doo::loadModel ( 'invoiceOperationLog' );
  6027. echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  6028. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . $path );
  6029. // print_r ( $exlArray );
  6030. // die ();
  6031. // echo json_encode($exlArray);die;
  6032. foreach ( $exlArray as $key => $value ) {
  6033. // 开票
  6034. $invoice = new invoice ();
  6035. $invoice->invoiceNo = $value ['invoiceNo'];
  6036. $invoice->invoiceType = 0;
  6037. if ($value ['invoiceType'] == '专')
  6038. $invoice->invoiceType = 1;
  6039. $invoice->invoicePrice = $value ['invoicePrice'];
  6040. $invoice->invoiceQuantity = 1;
  6041. $invoice->invoiceUnitPrice = $value ['invoicePrice'];
  6042. $invoice->invoiceTitle = $value ['invoiceTitle'];
  6043. if ($value ['invoiceType'] == '专')
  6044. $invoice->invoiceCompany = $value ['invoiceTitle'];
  6045. $invoice->userName = $value ['userName'];
  6046. $sDetail = $staff->getStaffByName ( $value ['userName'] );
  6047. $invoice->sid = $sDetail ['sid'];
  6048. $invoice->cid = $sDetail ['cid'];
  6049. $invoice->categoryName = $sDetail ['category'];
  6050. $invoice->invoiceElement = $value ['invoiceElement'];
  6051. $invoice->remark = $value ['remark'];
  6052. $invoice->date = $value ['date'];
  6053. $invoice->printTime = $value ['date'];
  6054. $invoice->ipSource = 1;
  6055. $invoice->printStatus = 1;
  6056. $invoice->status = 2;
  6057. $invoice->postStatus = 1;
  6058. $invoice->untreadStatus = 0;
  6059. $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  6060. $iid = $invoice->insert ();
  6061. // 汇总
  6062. $invoiceStatistics = new invoiceStatistics ();
  6063. //
  6064. $item = array (
  6065. 'date' => $value ['date'],
  6066. 'priceClass' => 1,
  6067. 'cid' => $sDetail ['cid'],
  6068. 'staff' => $sDetail ['sid'],
  6069. 'invoicePrice' => $value ['invoicePrice']
  6070. );
  6071. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  6072. $invoiceOperationLog = new invoiceOperationLog ();
  6073. $item = array (
  6074. 'date' => date ( "Y-m-d H:i:s" ),
  6075. 'operation' => date ( "Y-m-d" ) . " 导入",
  6076. 'status' => 1,
  6077. 'img' => $sDetail ['avatar'],
  6078. 'username' => $sDetail ['username'],
  6079. 'uid' => $sDetail ['sid'],
  6080. 'category' => $sDetail ['category'],
  6081. 'iid' => $iid
  6082. );
  6083. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  6084. }
  6085. return '/importInvoice?count=' . count ( $exlArray );
  6086. // return "/keyonline";
  6087. }
  6088. echo 'no file';
  6089. }
  6090. function importInvoiceReceivables() {
  6091. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  6092. $data ['emsg'] = "";
  6093. if ($emsg != "")
  6094. $data ['emsg'] = "请填写完整的数据";
  6095. $data ['time'] = time ();
  6096. $this->render ( "/admin/invoiceReceivablesImport", $data );
  6097. }
  6098. // 导入入账数据
  6099. function importInvoiceReceivablesDo() {
  6100. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  6101. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  6102. if ($path != "") {
  6103. Doo::loadModel ( 'invoiceReceivables' );
  6104. Doo::loadModel ( 'invoice' );
  6105. Doo::loadModel ( 'staff' );
  6106. $staff = new staff ();
  6107. Doo::loadModel ( 'invoiceStatistics' );
  6108. // echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  6109. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path ), 'invoiceReceivables' );
  6110. // print_r ( $exlArray );
  6111. // die ();
  6112. // echo json_encode($exlArray);die;
  6113. foreach ( $exlArray as $key => $value ) {
  6114. // 收款
  6115. $invoiceReceivables = new invoiceReceivables ();
  6116. $invoice = new invoice ();
  6117. $invoiceReceivables->bindStatus = 1;
  6118. $invoiceReceivables->receivablesPrice = $value ['receivablesPrice'];
  6119. $invoiceReceivables->receivablesMessage = $value ['receivablesMessage'];
  6120. $invoiceReceivables->receivablesBank = $value ['receivablesBank'];
  6121. $invoiceReceivables->receivablesDate = $value ['receivablesDate'];
  6122. $sDetail = $staff->getStaffByName ( $value ['receivablesStaff'] );
  6123. $invoiceReceivables->receivablesCategory = $sDetail ['cid'] . ':' . $sDetail ['category'];
  6124. $invoiceReceivables->receivablesStaff = $sDetail ['sid'] . '-' . $sDetail ['username'];
  6125. $invoiceReceivables->receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  6126. $invoiceReceivables->sourcePrice = $value ['sourcePrice'];
  6127. $iDetail = $invoice->getInvoiceByInvoiceNo ( $value ['invoiceNo'] );
  6128. $invoiceReceivables->iid = $iDetail ['iid'];
  6129. $irid = $invoiceReceivables->insert ();
  6130. // 发票绑定收款
  6131. $detail = $iDetail;
  6132. $iridString = "";
  6133. if (empty ( $detail ['irid'] ))
  6134. $iridString = $irid;
  6135. else
  6136. $iridString = $detail ['irid'] . ',' . $irid;
  6137. $item = array (
  6138. 'irid' => $iridString,
  6139. 'iid' => $detail ['iid']
  6140. );
  6141. $invoice->setInvoiceByCondition ( $item );
  6142. // 汇总
  6143. $invoiceStatistics = new invoiceStatistics ();
  6144. // 扣除入账统计金额
  6145. $item = array (
  6146. 'date' => $value ['receivablesDate'],
  6147. 'priceClass' => 3,
  6148. 'cid' => $sDetail ['cid'],
  6149. 'staff' => $sDetail ['sid'],
  6150. // 'irid' => $irid,
  6151. 'accountPrice' => $value ['receivablesPrice']
  6152. );
  6153. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  6154. }
  6155. return '/importInvoiceReceivables?count=' . count ( $exlArray );
  6156. echo 'data count ' . count ( $exlArray );
  6157. die ();
  6158. // return "/keyonline";
  6159. }
  6160. echo 'no file';
  6161. }
  6162. function formatExcelToArrayTrain($file_url = "") {
  6163. if (! file_exists ( $file_url )) {
  6164. return array ();
  6165. }
  6166. // Doo::loadClass ( 'PHPExcel' );
  6167. Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  6168. $PHPExcel = new PHPExcel ();
  6169. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  6170. if (! $PHPReader->canRead ( $file_url )) {
  6171. $PHPReader = new PHPExcel_Reader_Excel5 ();
  6172. if (! $PHPReader->canRead ( $file_url )) {
  6173. echo 'no Excel';
  6174. return;
  6175. }
  6176. }
  6177. $PHPExcel = $PHPReader->load ( $file_url );
  6178. /* * 读取excel文件中的第一个工作表 */
  6179. $currentSheet = $PHPExcel->getSheet ( 0 );
  6180. /* * 取得最大的列号 */
  6181. $allColumn = $currentSheet->getHighestColumn ();
  6182. /* * 取得一共有多少行 */
  6183. $allRow = $currentSheet->getHighestRow ();
  6184. $excel_array = array ();
  6185. // die($file_url);
  6186. $conk = 2;
  6187. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  6188. $excel_column = array ();
  6189. // 后期改进
  6190. if ($allColumn == 'AM')
  6191. $allColumn = 'Z';
  6192. /* * 从第A列开始输出 */
  6193. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  6194. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  6195. if ($val instanceof PHPExcel_RichText)
  6196. $val = $val->__toString ();
  6197. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  6198. // $val = "'" . addslashes ( $val ) . "'";
  6199. if ($currentColumn == 'A') {
  6200. $excel_column ['invoiceTitle'] = $val;
  6201. } elseif ($currentColumn == 'B')
  6202. $excel_column ['invoiceType'] = $val;
  6203. elseif ($currentColumn == 'C') {
  6204. $excel_column ['TIN'] = $val;
  6205. } elseif ($currentColumn == 'D') {
  6206. $excel_column ['address'] = $val;
  6207. } elseif ($currentColumn == 'E') {
  6208. $excel_column ['phone'] = $val;
  6209. } elseif ($currentColumn == 'F') {
  6210. $excel_column ['bank'] = $val;
  6211. } elseif ($currentColumn == 'G') {
  6212. $excel_column ['bankAccount'] = $val;
  6213. } elseif ($currentColumn == 'H') {
  6214. $excel_column ['invoiceElement'] = $val;
  6215. } elseif ($currentColumn == 'I') {
  6216. $excel_column ['invoiceQuantity'] = $val;
  6217. } elseif ($currentColumn == 'J') {
  6218. $excel_column ['invoiceUnitPrice'] = $val;
  6219. } elseif ($currentColumn == 'K') {
  6220. $excel_column ['remark'] = $val;
  6221. } elseif ($currentColumn == 'L') {
  6222. $excel_column ['recipientsAddress'] = $val;
  6223. } elseif ($currentColumn == 'M') {
  6224. $excel_column ['recipients'] = $val;
  6225. } elseif ($currentColumn == 'N') {
  6226. $excel_column ['recipientsPhone'] = $val;
  6227. }
  6228. }
  6229. if (! empty ( $excel_column ['invoiceTitle'] ) && ! empty ( $excel_column ['invoiceQuantity'] ) && ! empty ( $excel_column ['invoiceUnitPrice'] ))
  6230. array_push ( $excel_array, $excel_column );
  6231. }
  6232. return $excel_array;
  6233. }
  6234. /**
  6235. * 格式化excel文件为数组
  6236. * @param unknown_type $file_url
  6237. * @param unknown_type $mcid
  6238. */
  6239. function _format_excel_to_array($file_url = "", $sType = "") {
  6240. if (! file_exists ( $file_url )) {
  6241. return array ();
  6242. }
  6243. Doo::loadClass ( 'PHPExcel' );
  6244. // Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  6245. $PHPExcel = new PHPExcel ();
  6246. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  6247. if (! $PHPReader->canRead ( $file_url )) {
  6248. $PHPReader = new PHPExcel_Reader_Excel5 ();
  6249. if (! $PHPReader->canRead ( $file_url )) {
  6250. echo 'no Excel';
  6251. return;
  6252. }
  6253. }
  6254. $PHPExcel = $PHPReader->load ( $file_url );
  6255. /* * 读取excel文件中的第一个工作表 */
  6256. $currentSheet = $PHPExcel->getSheet ( 0 );
  6257. /* * 取得最大的列号 */
  6258. $allColumn = $currentSheet->getHighestColumn ();
  6259. /* * 取得一共有多少行 */
  6260. $allRow = $currentSheet->getHighestRow ();
  6261. $excel_array = array ();
  6262. // die($file_url);
  6263. $conk = 2;
  6264. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  6265. $excel_column = array ();
  6266. // 后期改进
  6267. if ($allColumn == 'AM')
  6268. $allColumn = 'Z';
  6269. /* * 从第A列开始输出 */
  6270. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  6271. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  6272. if ($val instanceof PHPExcel_RichText)
  6273. $val = $val->__toString ();
  6274. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  6275. // $val = "'" . addslashes ( $val ) . "'";
  6276. if ($sType == 'invoiceReceivables') {
  6277. if ($currentColumn == 'A')
  6278. $excel_column ['invoiceNo'] = $val;
  6279. elseif ($currentColumn == 'B')
  6280. $excel_column ['receivablesPrice'] = $val;
  6281. elseif ($currentColumn == 'C') {
  6282. $excel_column ['receivablesMessage'] = $val;
  6283. } elseif ($currentColumn == 'D') {
  6284. $excel_column ['receivablesBank'] = $val;
  6285. } elseif ($currentColumn == 'E') {
  6286. $excel_column ['receivablesDate'] = $this->excelTime ( $val );
  6287. } elseif ($currentColumn == 'F') {
  6288. $excel_column ['receivablesStaff'] = $val;
  6289. } elseif ($currentColumn == 'G') {
  6290. $excel_column ['sourcePrice'] = $val;
  6291. }
  6292. } elseif ($sType == "invoiceTrain") {
  6293. if ($currentColumn == 'A') {
  6294. $excel_column ['invoiceTitle'] = $val;
  6295. } elseif ($currentColumn == 'B')
  6296. $excel_column ['invoiceType'] = $val;
  6297. elseif ($currentColumn == 'C') {
  6298. $excel_column ['TIN'] = $val;
  6299. } elseif ($currentColumn == 'D') {
  6300. $excel_column ['address'] = $val;
  6301. } elseif ($currentColumn == 'E') {
  6302. $excel_column ['phone'] = $val;
  6303. } elseif ($currentColumn == 'F') {
  6304. $excel_column ['bank'] = $val;
  6305. } elseif ($currentColumn == 'G') {
  6306. $excel_column ['bankAccount'] = $val;
  6307. } elseif ($currentColumn == 'H') {
  6308. $excel_column ['invoiceElement'] = $val;
  6309. } elseif ($currentColumn == 'I') {
  6310. $excel_column ['invoiceQuantity'] = $val;
  6311. } elseif ($currentColumn == 'J') {
  6312. $excel_column ['invoiceUnitPrice'] = $val;
  6313. } elseif ($currentColumn == 'K') {
  6314. $excel_column ['remark'] = $val;
  6315. } elseif ($currentColumn == 'L') {
  6316. $excel_column ['recipientsAddress'] = $val;
  6317. } elseif ($currentColumn == 'M') {
  6318. $excel_column ['recipients'] = $val;
  6319. } elseif ($currentColumn == 'N') {
  6320. $excel_column ['recipientsPhone'] = $val;
  6321. }
  6322. } else {
  6323. if ($currentColumn == 'A')
  6324. $excel_column ['invoiceNo'] = $val;
  6325. elseif ($currentColumn == 'B')
  6326. $excel_column ['invoiceType'] = $val;
  6327. elseif ($currentColumn == 'C') {
  6328. $excel_column ['invoicePrice'] = $val;
  6329. } elseif ($currentColumn == 'D') {
  6330. $excel_column ['invoiceTitle'] = $val;
  6331. } elseif ($currentColumn == 'E') {
  6332. $excel_column ['userName'] = $val;
  6333. } elseif ($currentColumn == 'F') {
  6334. $excel_column ['categoryName'] = $val;
  6335. } elseif ($currentColumn == 'G') {
  6336. $excel_column ['invoiceElement'] = $val;
  6337. } elseif ($currentColumn == 'H') {
  6338. $excel_column ['remark'] = $val;
  6339. } elseif ($currentColumn == 'I') {
  6340. $excel_column ['date'] = $this->excelTime ( $val );
  6341. }
  6342. }
  6343. }
  6344. array_push ( $excel_array, $excel_column );
  6345. }
  6346. return $excel_array;
  6347. }
  6348. function excelTime($date, $time = false) {
  6349. if (function_exists ( 'GregorianToJD' )) {
  6350. if (is_numeric ( $date )) {
  6351. $jd = GregorianToJD ( 1, 1, 1970 );
  6352. $gregorian = JDToGregorian ( $jd + intval ( $date ) - 25569 );
  6353. $date = explode ( '/', $gregorian );
  6354. $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" : '');
  6355. return $date_str;
  6356. }
  6357. } else {
  6358. $date = $date > 25568 ? $date + 1 : 25569;
  6359. /* There was a bug if Converting date before 1-1-1970 (tstamp 0) */
  6360. $ofs = (70 * 365 + 17 + 2) * 86400;
  6361. $date = date ( "Y-m-d", ($date * 86400) - $ofs ) . ($time ? " 00:00:00" : '');
  6362. }
  6363. return $date;
  6364. }
  6365. /**
  6366. * 旧输入导入
  6367. */
  6368. function _GetFileEXT($filename) {
  6369. $pics = explode ( '.', $filename );
  6370. $num = count ( $pics );
  6371. return $pics [$num - 1];
  6372. }
  6373. function showCache($path = "", $sid = 0) {
  6374. // if (file_exists ( $path )) {
  6375. // $htm = file_get_contents ( $path );
  6376. // } else {
  6377. Doo::loadModel ( 'invoiceStatistics' );
  6378. $invoiceStatistics = new invoiceStatistics ();
  6379. $isBriefly = $invoiceStatistics->getBrieflyStatistics ( $sid );
  6380. $htm = '<tr><th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计开票</th>
  6381. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['invoicePrice'] . '</td>
  6382. <th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计入账</th>
  6383. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['accountPrice'] . '</td></tr>';
  6384. /*
  6385. * '<tr><th class="taC">今年累计开票</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['invoicePrice'] . '</td> <th class="taC">今年累计入账</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['accountPrice'] . '</td></tr>';
  6386. */
  6387. file_put_contents ( $path, $htm );
  6388. // }
  6389. return $htm;
  6390. }
  6391. /**
  6392. * 获取get或者POST值
  6393. *
  6394. * @param string $name 属性名称
  6395. * @return fixed 值
  6396. */
  6397. function get_args($name) {
  6398. if (isset ( $_GET [$name] )) {
  6399. if (is_array ( $_GET [$name] ))
  6400. return $_GET [$name];
  6401. else
  6402. return addslashes ( $_GET [$name] );
  6403. } elseif (isset ( $_POST [$name] )) {
  6404. if (is_array ( $_POST [$name] ))
  6405. return $_POST [$name];
  6406. else
  6407. return addslashes ( $_POST [$name] );
  6408. } else
  6409. return false;
  6410. }
  6411. function SafeFilter(&$arr) {
  6412. $ra = Array (
  6413. '/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/',
  6414. '/script/',
  6415. '/javascript/',
  6416. '/vbscript/',
  6417. '/expression/',
  6418. '/applet/',
  6419. '/meta/',
  6420. '/xml/',
  6421. '/blink/',
  6422. '/link/',
  6423. '/style/',
  6424. '/embed/',
  6425. '/object/',
  6426. '/frame/',
  6427. '/layer/',
  6428. '/title/',
  6429. '/bgsound/',
  6430. '/base/',
  6431. '/onload/',
  6432. '/onunload/',
  6433. '/onchange/',
  6434. '/onsubmit/',
  6435. '/onreset/',
  6436. '/onselect/',
  6437. '/onblur/',
  6438. '/onfocus/',
  6439. '/onabort/',
  6440. '/onkeydown/',
  6441. '/onkeypress/',
  6442. '/onkeyup/',
  6443. '/onclick/',
  6444. '/ondblclick/',
  6445. '/onmousedown/',
  6446. '/onmousemove/',
  6447. '/onmouseout/',
  6448. '/onmouseover/',
  6449. '/onmouseup/',
  6450. '/onunload/'
  6451. );
  6452. if (is_array ( $arr )) {
  6453. foreach ( $arr as $key => $value ) {
  6454. if (! is_array ( $value )) {
  6455. if (! get_magic_quotes_gpc ()) // 不对magic_quotes_gpc转义过的字符使用addslashes(),避免双重转义。
  6456. {
  6457. $value = addslashes ( $value ); // 给单引号(')、双引号(")、反斜线(\)与 NUL(NULL 字符)加上反斜线转义
  6458. }
  6459. $value = preg_replace ( $ra, '', $value ); // 删除非打印字符,粗暴式过滤xss可疑字符串
  6460. $arr [$key] = htmlentities ( strip_tags ( $value ) ); // 去除 HTML 和 PHP 标记并转换为 HTML 实体
  6461. } else {
  6462. SafeFilter ( $arr [$key] );
  6463. }
  6464. }
  6465. }
  6466. }
  6467. /**
  6468. * Escape String
  6469. *
  6470. * @access public
  6471. * @param string
  6472. * @param bool whether or not the string will be used in a LIKE condition
  6473. * @return string
  6474. */
  6475. function escape_str($str, $like = FALSE) {
  6476. if (is_array ( $str )) {
  6477. foreach ( $str as $key => $val ) {
  6478. $str [$key] = $this->escape_str ( $val, $like );
  6479. }
  6480. return $str;
  6481. }
  6482. var_dump ( Doo::db ()->getDbObject () );
  6483. die ();
  6484. if (function_exists ( 'mysql_real_escape_string' ) and is_resource ( Doo::db ()->getDbObject () )) { // Doo::db ()->getDbObject()
  6485. $str = mysql_real_escape_string ( $str, Doo::db ()->getDbObject () );
  6486. } elseif (function_exists ( 'mysql_escape_string' )) {
  6487. $str = mysql_escape_string ( $str );
  6488. } else {
  6489. $str = addslashes ( $str );
  6490. }
  6491. // escape LIKE condition wildcards
  6492. if ($like === TRUE) {
  6493. $str = str_replace ( array (
  6494. '%',
  6495. '_'
  6496. ), array (
  6497. '\\%',
  6498. '\\_'
  6499. ), $str );
  6500. }
  6501. return $str;
  6502. }
  6503. /**
  6504. * 获得分页数据
  6505. * @param unknown_type $table
  6506. * @param unknown_type $condition
  6507. * @param unknown_type $on_page
  6508. * @param unknown_type $page_size
  6509. */
  6510. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  6511. $page_c = "";
  6512. $page ['previous'] = $this->get_previous ( $on_page );
  6513. $page ['on_page'] = $on_page;
  6514. $total_count = $this->get_table_count ( $table, $condition );
  6515. $total = intval ( $total_count / $page_size );
  6516. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  6517. $page ['total_data'] = $total_count;
  6518. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  6519. $i = 1;
  6520. $page_max = 1;
  6521. $page_width = 3;
  6522. if ($on_page >= $page_width) {
  6523. $page_max = intval ( $on_page / $page_width ) + 1;
  6524. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  6525. }
  6526. for(; $i <= $page ['total_page']; $i ++) {
  6527. if ($i == $on_page)
  6528. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  6529. else
  6530. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  6531. if ($i == ($page_width * $page_max))
  6532. break;
  6533. }
  6534. $page ['page'] = $page_c;
  6535. $page ['lower'] = (-- $on_page) * $page_size;
  6536. return $page;
  6537. }
  6538. /**
  6539. * 获取上一页
  6540. * @param unknown_type $on_page
  6541. */
  6542. function get_previous($on_page = 1) {
  6543. return $on_page != 0 ? $on_page - 1 : $on_page;
  6544. }
  6545. /**
  6546. * 获取总页数
  6547. * @param unknown_type $table
  6548. * @param unknown_type $condition
  6549. */
  6550. public function get_table_count($table = "", $condition = "") {
  6551. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  6552. $sql = "select count(*) as count from " . $table . " where " . $condition;
  6553. // echo $sql;die;
  6554. $query = Doo::db ()->query ( $sql );
  6555. $result = $query->fetch ();
  6556. return $result ['count'];
  6557. }
  6558. /**
  6559. * 获得分页数据
  6560. * @param unknown_type $table
  6561. * @param unknown_type $condition
  6562. * @param unknown_type $on_page
  6563. * @param unknown_type $page_size
  6564. */
  6565. function getPageBySql($sql = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  6566. $page_c = "";
  6567. $page ['previous'] = $this->get_previous ( $on_page );
  6568. $page ['on_page'] = $on_page;
  6569. $total_count = $this->getTableCountBySql ( $sql );
  6570. $total = intval ( $total_count / $page_size );
  6571. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  6572. $page ['total_data'] = $total_count;
  6573. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  6574. $i = 1;
  6575. $page_max = 1;
  6576. $page_width = 3;
  6577. if ($on_page >= $page_width) {
  6578. $page_max = intval ( $on_page / $page_width ) + 1;
  6579. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  6580. }
  6581. for(; $i <= $page ['total_page']; $i ++) {
  6582. if ($i == $on_page)
  6583. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  6584. else
  6585. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  6586. if ($i == ($page_width * $page_max))
  6587. break;
  6588. }
  6589. $page ['page'] = $page_c;
  6590. $page ['lower'] = (-- $on_page) * $page_size;
  6591. return $page;
  6592. }
  6593. /**
  6594. * 获得总页数 sql
  6595. * @param string $type
  6596. * @return boolean[]
  6597. */
  6598. public function getTableCountBySql($sql = "") {
  6599. $query = Doo::db ()->query ( $sql );
  6600. $result = $query->fetchAll ();
  6601. return count ( $result );
  6602. }
  6603. function isInvoiceNew($type = "GLOBAL") {
  6604. Doo::loadModel ( 'invoice' );
  6605. $invoice = new invoice ();
  6606. Doo::loadModel ( 'invoiceReceivables' );
  6607. $invoiceReceivables = new invoiceReceivables ();
  6608. Doo::loadModel ( 'staff' );
  6609. $staff = new staff ();
  6610. $st = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  6611. // 我的发票待处理
  6612. $pendingInvoice = $invoice->getOne ( array ( // or (status=2 and printStatus=1 and untreadStatus=0 ) or (status=2 and printStatus=1 and untreadStatus=2 )
  6613. 'where' => "(status=3 or status=4) and isDelete=0 and sid=" . $st [0] ['sid'],
  6614. 'desc' => 'iid',
  6615. 'asArray' => TRUE
  6616. ) );
  6617. // 我的收款待入账
  6618. /*
  6619. * $myClaim = $invoiceReceivables->getOne ( array ( 'where' => " receivablesStaff like '" . $st [0] ['sid'] . "-%' and receivablesCategory like '" . $st [0] ['cid'] . ":%' and bindStatus=0", 'desc' => 'irid', 'asArray' => TRUE ) );
  6620. */
  6621. // 发票审批
  6622. $approval = $invoice->getOne ( array (
  6623. 'where' => 'status=1 and pendingApprovals=' . $st [0] ['sid'],
  6624. 'desc' => 'iid',
  6625. 'asArray' => true
  6626. ) );
  6627. // 发票邮寄
  6628. $post = $invoice->getOne ( array (
  6629. 'where' => "postStatus=0 and printStatus=1 and isDelete=0 and doPost=1 and status=2",
  6630. 'asArray' => TRUE
  6631. ) );
  6632. // 发票打印
  6633. $print = $invoice->getOne ( array (
  6634. 'where' => "status=2 and printStatus=0 and untreadStatus=0 and moldManage like '%[\"" . $st [0] ['sid'] . "\",%'",
  6635. 'desc' => 'iid',
  6636. 'asArray' => TRUE
  6637. ) );
  6638. // 发票退票 printStatus=1 and
  6639. $untread = $invoice->getOne ( array (
  6640. 'where' => " untreadStatus=1 and status=2 ",
  6641. 'asArray' => TRUE
  6642. ) );
  6643. $new = array (
  6644. 'GLOBAL' => FALSE,
  6645. 'pendingInvoice' => FALSE,
  6646. // 'myClaim' => FALSE,
  6647. 'approval' => FALSE,
  6648. 'post' => FALSE,
  6649. 'print' => FALSE,
  6650. 'untread' => FALSE
  6651. );
  6652. // || ! empty ( $myClaim )
  6653. if (! empty ( $pendingInvoice ) || ! empty ( $approval ) || ! empty ( $post ) || ! empty ( $print ) || ! empty ( $untread ))
  6654. $new ['GLOBAL'] = TRUE;
  6655. if (! empty ( $pendingInvoice ))
  6656. $new ['pendingInvoice'] = TRUE;
  6657. // if (! empty ( $myClaim ))
  6658. // $new ['myClaim'] = TRUE;
  6659. if (! empty ( $approval ))
  6660. $new ['approval'] = TRUE;
  6661. if (! empty ( $post ))
  6662. $new ['post'] = TRUE;
  6663. if (! empty ( $print ))
  6664. $new ['print'] = TRUE;
  6665. if (! empty ( $untread ))
  6666. $new ['untread'] = TRUE;
  6667. return $new;
  6668. }
  6669. function setWXMsg($rid, $typeMsg = '') {
  6670. Doo::loadModel ( 'invoice' );
  6671. $invoice = new invoice ();
  6672. $invoiceDetail = $invoice->getOne ( array (
  6673. 'where' => 'iid=' . $rid,
  6674. 'asArray' => true
  6675. ) );
  6676. if (! empty ( $invoiceDetail )) {
  6677. Doo::loadModel ( 'staff' );
  6678. $staff = new staff ();
  6679. $staffmsg = $staff->getOne ( array (
  6680. 'where' => "sid='" . $invoiceDetail ['sid'] . "'",
  6681. 'asArray' => TRUE
  6682. ) );
  6683. if (! empty ( $staffmsg ['wxid'] )) {
  6684. require_once (SITE_PATH . '/protected/class/client.php');
  6685. $client = new client ( 'http://m.cld.smartcost.com.cn/' );
  6686. $user = $staffmsg ['wxid'];
  6687. $expCom = explode ( ":", $invoiceDetail ['expressCompany'] );
  6688. if (empty ( $expCom ))
  6689. $expCom [0] = '';
  6690. $msg = "";
  6691. if (empty ( $typeMsg ))
  6692. $msg = '太好了,您的发票' . $invoiceDetail ['invoiceSerial'] . ' 已邮寄 ' . $expCom [0] . ' ,快递号: <a href="https://m.kuaidi100.com/result.jsp?nu=' . $invoiceDetail ['expressNumber'] . '" >' . $invoiceDetail ['expressNumber'] . '</a>';
  6693. elseif ($typeMsg == "PRINT")
  6694. $msg = '太好了,您的发票已打印完成。';
  6695. $result = $client->SendMsg ( $user, $msg, 'text' );
  6696. }
  6697. }
  6698. }
  6699. /**
  6700. * 获取微信部门
  6701. * @param string $category
  6702. * @return number|mixed
  6703. */
  6704. function getToparty($category = '') {
  6705. $token = $this->getAccessToken (); //
  6706. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token={$token}&id=5" ), true );
  6707. $toparty = 0;
  6708. foreach ( $result ['department'] as $key => $value ) {
  6709. if ($value ['name'] == $category)
  6710. $toparty = $value ['id'];
  6711. }
  6712. return $toparty;
  6713. }
  6714. /**
  6715. * 获得某部门下的用户
  6716. * @param string $toparty
  6717. */
  6718. function getUserByToparty($toparty = '') {
  6719. $token = $this->getAccessToken (); //
  6720. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token={$token}&department_id={$toparty}" ), true );
  6721. $userList = array ();
  6722. foreach ( $result ['userlist'] as $key => $value ) {
  6723. array_push ( $userList, "'" . $value ['userid'] . "'" );
  6724. }
  6725. return $userList;
  6726. }
  6727. function msgSendToparty($msg, $title, $url, $toparty, $text = '') {
  6728. $token = $this->getAccessToken ();
  6729. if ($text == 'text') {
  6730. $data = '{
  6731. "touser": "' . $toparty . '",
  6732. "toparty": "",
  6733. "totag": "",
  6734. "msgtype": "text",
  6735. "agentid": 1000002,
  6736. "text": {
  6737. "content": "' . $msg . '"
  6738. },
  6739. "safe":0
  6740. }';
  6741. }
  6742. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  6743. if ($result->errmsg != 'ok') {
  6744. return 0;
  6745. } else {
  6746. return 1;
  6747. }
  6748. }
  6749. /**
  6750. * 获得可以发送微信用户列表
  6751. * @param string $category
  6752. * @return string
  6753. */
  6754. function getWxidByCategory($category = "") {
  6755. if (empty ( $category ))
  6756. return "";
  6757. Doo::loadModel ( 'staff' );
  6758. $staff = new staff ();
  6759. $toparty = $this->getToparty ( $category );
  6760. $wxList = array ();
  6761. $wxString = "";
  6762. if (! empty ( $toparty )) {
  6763. $userList = $this->getUserByToparty ( $toparty );
  6764. $userCon = implode ( ',', $userList );
  6765. // echo $userCon;
  6766. $sidList = $staff->getStaffByWxid ( $userCon );
  6767. foreach ( $sidList as $key => $value ) {
  6768. $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  6769. if ($falg) {
  6770. array_push ( $wxList, $value ['wxid'] );
  6771. }
  6772. }
  6773. $wxString = implode ( '|', $wxList );
  6774. }
  6775. return $wxString;
  6776. }
  6777. /**
  6778. * 读取发送信息规则判断是否需要发送
  6779. * @param number $sid
  6780. * @param string $sendType
  6781. * @return boolean
  6782. */
  6783. function isSendNotification($sid = 0, $sendType = '') {
  6784. Doo::loadModel ( "notificationConf" );
  6785. $notificationConf = new notificationConf ();
  6786. $detail = $notificationConf->getNotificationConfBySid ( $sid );
  6787. $conf = array ();
  6788. $sendFlag = true;
  6789. if (! empty ( $detail )) {
  6790. $conf = json_decode ( $detail ['conf'], true );
  6791. if (! empty ( $sendType )) {
  6792. if (isset ( $conf [$sendType] )) {
  6793. if ($conf [$sendType] == "CLOSE")
  6794. $sendFlag = false;
  6795. elseif ($conf [$sendType] == "Weekend") {
  6796. $day = date ( "w" );
  6797. if (1 <= $day && 5 >= $day)
  6798. $sendFlag = false;
  6799. } elseif ($conf [$sendType] == "OneToFriday") {
  6800. $day = date ( "w" );
  6801. if (0 == $day || 6 == $day)
  6802. $sendFlag = false;
  6803. }
  6804. }
  6805. } else
  6806. $sendFlag = false;
  6807. }
  6808. return $sendFlag;
  6809. }
  6810. /**
  6811. * 根据规则发送信息
  6812. * @param unknown $msg
  6813. * @param unknown $title
  6814. * @param unknown $url
  6815. * @param unknown $user
  6816. * @param string $text
  6817. * @return number
  6818. */
  6819. private function msgSend($msg, $title, $url, $user, $sid = 0, $sendType = '') {
  6820. $token = $this->getAccessToken ();
  6821. $falg = $this->isSendNotification ( $sid, $sendType );
  6822. // if ($text == 'text') {
  6823. // $data = '{
  6824. // "touser": "' . $user . '",
  6825. // "toparty": "",
  6826. // "totag": "",
  6827. // "msgtype": "text",
  6828. // "agentid": 1000002,
  6829. // "text": {
  6830. // "content": "' . $msg . '"
  6831. // },
  6832. // "safe":0
  6833. // }';
  6834. // } else {
  6835. $data = '{
  6836. "touser": "' . $user . '",
  6837. "toparty": "",
  6838. "totag": "",
  6839. "msgtype": "news",
  6840. "agentid": 1000002,
  6841. "news": {
  6842. "articles":[
  6843. {
  6844. "title": "' . $title . '",
  6845. "description": "' . $msg . '",
  6846. "url": "' . $url . '",
  6847. "picurl": ""
  6848. }
  6849. ]
  6850. }
  6851. }';
  6852. // }
  6853. if ($falg) {
  6854. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  6855. if ($result->errmsg != 'ok') {
  6856. return 0;
  6857. } else {
  6858. return 1;
  6859. }
  6860. } else
  6861. return 0;
  6862. }
  6863. private function getAccessToken() {
  6864. // access_token 应该全局存储与更新,以下代码以写入到文件中做示例
  6865. // $file = './access_token.txt';
  6866. // $data = json_decode ( file_get_contents ( $file ) );
  6867. // if ($data->expire_time < time () or ! $data->expire_time) {
  6868. // 如果是企业号用以下URL获取access_token
  6869. $url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$this->appId&corpsecret=$this->appSecret";
  6870. // $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$this->appId&secret=$this->appSecret";
  6871. $res = json_decode ( $this->httpGet ( $url ) );
  6872. $access_token = $res->access_token;
  6873. // echo $access_token;
  6874. // if ($access_token) {
  6875. // $data->expire_time = time () + 7000;
  6876. // $data->access_token = $access_token;
  6877. // $fp = fopen ( $file, "w" );
  6878. // fwrite ( $fp, json_encode ( $data ) );
  6879. // fclose ( $fp );
  6880. // }
  6881. // } else {
  6882. // $access_token = $data->access_token;
  6883. // }
  6884. return $access_token;
  6885. }
  6886. private function httpGet($url) {
  6887. $curl = curl_init ();
  6888. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  6889. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  6890. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  6891. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  6892. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  6893. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  6894. curl_setopt ( $curl, CURLOPT_URL, $url );
  6895. $res = curl_exec ( $curl );
  6896. curl_close ( $curl );
  6897. return $res;
  6898. }
  6899. private function httpPost($url, $data) {
  6900. $curl = curl_init ();
  6901. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  6902. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  6903. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  6904. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  6905. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  6906. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  6907. curl_setopt ( $curl, CURLOPT_URL, $url );
  6908. curl_setopt ( $curl, CURLOPT_POST, 1 );
  6909. curl_setopt ( $curl, CURLOPT_POSTFIELDS, $data );
  6910. $res = curl_exec ( $curl );
  6911. curl_close ( $curl );
  6912. return $res;
  6913. }
  6914. }
  6915. ?>