InvoiceController.php 303 KB

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