InvoiceController.php 314 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562
  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. // 获得已退票功能
  203. $untreadStatusList = $invoice->getMyInvoiceByUntreadStatus ( 2, 0, 5, $sid );
  204. $this->data ['untreadStatusList'] = $untreadStatusList;
  205. // print_r($untreadStatusList);
  206. $this->data ['isMonth'] = $isMonth;
  207. $this->data ['htm'] = $htm;
  208. $this->data ['invoiceList'] = $invoiceList;
  209. $this->data ['receivablesList'] = $list;
  210. $this->data ['myInvoiceUnAccount'] = $myInvoiceUnAccount;
  211. $this->data ['memu'] = "invoice";
  212. $this->data ['staff'] = $this->staff;
  213. $this->data ['receiptMemu'] = 'invoice';
  214. $this->render ( "/admin/invoice", $this->data );
  215. }
  216. function invoiceExpress() {
  217. $expressCom = isset ( $this->params ['expressCom'] ) ? $this->params ['expressCom'] : "";
  218. $expressNumber = isset ( $this->params ['expressNumber'] ) ? $this->params ['expressNumber'] : "";
  219. $this->data ['expressCom'] = $expressCom;
  220. $this->data ['expressNumber'] = $expressNumber;
  221. $this->render ( "/admin/invoiceExpress", $this->data );
  222. }
  223. function invoiceAdd() {
  224. session_start ();
  225. Doo::loadModel ( 'invoice' );
  226. $invoice = new invoice ();
  227. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );
  228. Doo::loadModel ( 'L_category' );
  229. $lCategory = new L_category ();
  230. $category = $lCategory->find ( array (
  231. 'asArray' => true
  232. ) );
  233. $this->data ['category'] = $category;
  234. Doo::loadModel ( 'invoiceTraining' );
  235. $invoiceTraining = new invoiceTraining ();
  236. $itList = $invoiceTraining->getInvoiceTrainingByCid ( $this->staff [0] ['cid'] );
  237. Doo::loadModel ( 'receipt' );
  238. $receipt = new receipt ();
  239. foreach ( $itList as $key => $value ) { // 不展示已结算完结的培训班
  240. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $value ['itid'] );
  241. if (! empty ( $receiptDetail )) {
  242. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9) {
  243. unset ( $itList [$key] );
  244. }
  245. }
  246. }
  247. $this->data ['itList'] = $itList;
  248. $token = $this->set_token ();
  249. $_SESSION ['token_' . $this->staff [0] ['sidKey']] = $token;
  250. $this->data ['token'] = $token;
  251. $this->data ['memu'] = "invoice";
  252. $this->data ['staff'] = $this->staff;
  253. $this->data ['receiptMemu'] = 'invoice';
  254. $this->render ( "/admin/invoiceAdd", $this->data );
  255. }
  256. /**
  257. * 自更新发票信息库
  258. * @param unknown $invoicePrintDetail
  259. */
  260. function autoUpdateInvoiceInfoBase($invoicePrintDetail) {
  261. // 发票信息库
  262. Doo::loadModel ( 'invoiceInfoBase' );
  263. $invoiceInfoBase = new invoiceInfoBase ();
  264. $updateDate = strtotime ( $invoicePrintDetail ['date'] );
  265. $TIN = $invoicePrintDetail ['TIN'];
  266. $invoiceTitle = $invoicePrintDetail ['invoiceTitle'];
  267. if (empty ( $invoiceTitle ))
  268. $invoiceTitle = $invoicePrintDetail ['invoiceCompany'];
  269. $IIBList = $invoiceInfoBase->getInvoiceInfoByTT ( $TIN, $invoiceTitle );
  270. // 确认有该条发票信息
  271. $invoiceInfoBase = new invoiceInfoBase ();
  272. if (! empty ( $IIBList )) {
  273. // 发票库里的信息数量
  274. $IIBListCount = count ( $IIBList );
  275. if ($IIBListCount == 1) { // 更新发票--提交是最新的时间
  276. $item = array (
  277. 'iibID' => $IIBList [0] ['iibID'],
  278. 'invoiceTitle' => $invoiceTitle,
  279. 'TIN' => $TIN
  280. );
  281. if (! empty ( $invoicePrintDetail ['address'] )) {
  282. $item += array (
  283. 'address' => $invoicePrintDetail ['address']
  284. );
  285. }
  286. if (! empty ( $invoicePrintDetail ['phone'] )) {
  287. $item += array (
  288. 'phone' => $invoicePrintDetail ['phone']
  289. );
  290. }
  291. if (! empty ( $invoicePrintDetail ['bank'] )) {
  292. $item += array (
  293. 'bank' => $invoicePrintDetail ['bank']
  294. );
  295. }
  296. if (! empty ( $invoicePrintDetail ['bankAccount'] )) {
  297. $item += array (
  298. 'bankAccount' => $invoicePrintDetail ['bankAccount']
  299. );
  300. }
  301. if ($updateDate >= strtotime ($IIBList [0] ['updateDate'])) {
  302. $item += array (
  303. 'updateDate' => $invoicePrintDetail ['date']
  304. );
  305. $invoiceInfoBase->setInvoiceInfoBaseByCondition ( $item );
  306. }
  307. } else { // 删除多张发票,重新添加发票
  308. $iibIDStr = '';
  309. $iibID = array ();
  310. foreach ( $IIBList as $key => $value ) {
  311. array_push ( $iibID, $value ['iibID'] );
  312. }
  313. $iibIDStr = implode ( ",", $iibID ); // 删除
  314. $invoiceInfoBase->delInvoiceInfoBaseByIibStr ( $iibIDStr );
  315. $item = array (
  316. 'invoiceTitle' => $invoiceTitle,
  317. 'TIN' => $TIN,
  318. 'address' => $invoicePrintDetail ['address'],
  319. 'phone' => $invoicePrintDetail ['phone'],
  320. 'bank' => $invoicePrintDetail ['bank'],
  321. 'bankAccount' => $invoicePrintDetail ['bankAccount'],
  322. 'updateDate' => $invoicePrintDetail ['date']
  323. );
  324. $invoiceInfoBase->addInvoiceInfoBase ( $item );
  325. }
  326. } else { // 没有新增发票信息
  327. $item = array (
  328. 'invoiceTitle' => $invoiceTitle,
  329. 'TIN' => $TIN,
  330. 'address' => $invoicePrintDetail ['address'],
  331. 'phone' => $invoicePrintDetail ['phone'],
  332. 'bank' => $invoicePrintDetail ['bank'],
  333. 'bankAccount' => $invoicePrintDetail ['bankAccount'],
  334. 'updateDate' => $invoicePrintDetail ['date']
  335. );
  336. $invoiceInfoBase->addInvoiceInfoBase ( $item );
  337. }
  338. }
  339. function invoiceAddFill() {
  340. session_start ();
  341. Doo::loadModel ( 'invoice' );
  342. $invoice = new invoice ();
  343. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );
  344. Doo::loadModel ( 'L_category' );
  345. $lCategory = new L_category ();
  346. $category = $lCategory->find ( array (
  347. 'asArray' => true
  348. ) );
  349. $this->data ['category'] = $category;
  350. Doo::loadModel ( 'invoiceTraining' );
  351. $invoiceTraining = new invoiceTraining ();
  352. $itList = $invoiceTraining->getInvoiceTrainingByCid ( $this->staff [0] ['cid'] );
  353. $this->data ['itList'] = $itList;
  354. Doo::loadModel ( 'invoice' );
  355. $invoice = new invoice ();
  356. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );
  357. $detail ['mailItemsArray'] = json_decode ( $detail ['mailItemsJson'], true );
  358. $token = $this->set_token ();
  359. $_SESSION ['token_' . $this->staff [0] ['sidKey']] = $token;
  360. $this->data ['token'] = $token;
  361. $this->data ['invoiceDetail'] = $detail;
  362. $this->data ['memu'] = "invoice";
  363. $this->data ['staff'] = $this->staff;
  364. $this->data ['receiptMemu'] = 'invoice';
  365. $this->render ( "/admin/invoiceAddFill", $this->data );
  366. }
  367. /**
  368. * 提交一份开票申请,并记录下操作日志
  369. *
  370. * @since 1.0.0
  371. * @var integer cid 办事处ID
  372. * @var integer invoiceType 发票类型
  373. * @var integer doPost 是否邮寄
  374. * @var integer invoicePrice 开票金额
  375. * @var string invoiceElement 开票内容
  376. * @var string invoiceTitle 发票抬头
  377. * @var string invoiceCompany 单位名称
  378. * @var string TIN 纳税人识别码
  379. * @var string address 注册地址
  380. * @var string phone 注册电话
  381. * @var string bank 开户银行
  382. * @var string bankAccount 银行账户
  383. * @var string recipients 收件人
  384. * @var string recipientsPhone 收件人手机/电话
  385. * @var string recipientsAddress 收件地址
  386. * @var string mailItems 邮寄物品
  387. * @var string remark 备注
  388. * @return string 返回跳转开票主页路径
  389. */
  390. function invoiceAddDo() {
  391. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  392. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  393. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  394. // $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  395. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  396. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  397. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  398. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  399. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  400. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  401. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  402. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  403. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  404. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  405. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  406. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  407. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  408. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  409. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  410. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  411. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  412. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  413. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  414. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  415. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  416. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  417. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  418. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  419. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  420. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  421. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  422. $trainId = $this->get_args ( 'trainId' ) ? $this->get_args ( 'trainId' ) : 0;
  423. $settlementType = $this->get_args ( 'settlementType' ) ? $this->get_args ( 'settlementType' ) : "";
  424. /*
  425. * $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;
  426. */
  427. $token = $this->get_args ( 'token' ) ? $this->get_args ( 'token' ) : "";
  428. if (empty ( $token )) {
  429. die ( 'illegal request-token' );
  430. } else {
  431. session_start ();
  432. if ($_SESSION ['token_' . $this->staff [0] ['sidKey']] != $token) {
  433. header ( 'Content-Type:text/html;charset=utf-8' );
  434. die ( '请勿重复申请发票' );
  435. } else {
  436. $_SESSION ['token_' . $this->staff [0] ['sidKey']] = '';
  437. }
  438. }
  439. if ($invoiceType == 1) {
  440. $temporary = $invoiceQuantity * $invoiceUnitPrice;
  441. if ($temporary > 10000) {
  442. header ( 'Content-Type:text/html;charset=utf-8' );
  443. die ( '专用发票总金额暂时不能超过10000.00(一万)元。' );
  444. // die ( 'illegal request-Please priceError' );
  445. }
  446. }
  447. if (empty ( $this->staff [0] ))
  448. die ( 'illegal request-Please login' );
  449. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $settlementType )) {
  450. Doo::loadModel ( 'invoice' );
  451. $invoice = new invoice ();
  452. Doo::loadModel ( 'L_category' );
  453. $lCategory = new L_category ();
  454. Doo::loadModel ( 'invoiceManage' );
  455. $invoiceManage = new invoiceManage ();
  456. Doo::loadModel ( 'invoiceOperationLog' );
  457. $invoiceOperationLog = new invoiceOperationLog ();
  458. Doo::loadClass ( 'XDeode' );
  459. $XDeode = new XDeode ( 5 );
  460. $trainId = $XDeode->decode ( $trainId );
  461. $categoryDetil = $lCategory->getOne ( array (
  462. 'SELECT' => 'title',
  463. 'where' => 'cid=' . $cid,
  464. 'asArray' => true
  465. ) );
  466. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  467. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  468. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  469. // print_r(current($invoiceManageDetail ['staffList']));
  470. // die;
  471. $moldManage = array ();
  472. foreach ( $invoiceManageList as $key => $value ) {
  473. if ($value ['mold'] == '发票打印')
  474. $moldManage [$value ['mold']] = $value ['staffList'];
  475. elseif ($value ['mold'] == '发票邮寄')
  476. $moldManage [$value ['mold']] = $value ['staffList'];
  477. elseif ($value ['mold'] == '发票退票')
  478. $moldManage [$value ['mold']] = $value ['staffList'];
  479. }
  480. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  481. $st = '';
  482. if ($settlementType == 'SOFTWARE') {
  483. $st = 0;
  484. $trainId = 0;
  485. } elseif ($settlementType == 'TRAINING') {
  486. $st = 1;
  487. if (empty ( $trainId ) && ! is_numeric ( $trainId )) {
  488. die ( 'illegal request-trainingIdError' );
  489. }
  490. } else {
  491. die ( 'illegal request-settlementError' );
  492. }
  493. $item = array (
  494. 'cid' => $cid,
  495. 'categoryName' => $categoryDetil ['title'],
  496. 'invoiceElement' => $invoiceElement,
  497. 'invoiceQuantity' => $invoiceQuantity,
  498. 'invoiceUnitPrice' => $invoiceUnitPrice,
  499. 'invoicePrice' => $invoicePrice,
  500. 'invoiceType' => $invoiceType,
  501. 'settlementType' => $st,
  502. 'doPost' => $doPost,
  503. 'status' => 1,
  504. 'invoiceSerial' => "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  505. 'date' => date ( "Y-m-d H:i:s" ),
  506. 'updateTime' => date ( "Y-m-d H:i:s" ),
  507. 'sid' => $this->staff [0] ['sid'],
  508. 'userName' => $this->staff [0] ['username'],
  509. 'invoiceManage' => $invoiceManageDetail ['staff'],
  510. 'pendingApprovals' => $pendingApprovalsSid,
  511. 'moldManage' => json_encode ( $moldManage ),
  512. 'remark' => $remark,
  513. 'trainId' => $trainId
  514. );
  515. if ($invoiceType == 0)
  516. $item += array (
  517. 'invoiceTitle' => $invoiceTitle,
  518. 'TIN' => $TINT,
  519. 'address' => $addressT,
  520. 'phone' => $phoneT,
  521. 'bank' => $bankT,
  522. 'bankAccount' => $bankAccountT
  523. );
  524. else {
  525. $item += array (
  526. 'invoiceCompany' => $invoiceCompany,
  527. 'TIN' => $TIN,
  528. 'address' => $address,
  529. 'phone' => $phone,
  530. 'bank' => $bank,
  531. 'bankAccount' => $bankAccount
  532. );
  533. }
  534. if ($doPost == 1) {
  535. $mailList = array (
  536. 'invoice' => 1,
  537. 'mailItems' => $mailItems
  538. );
  539. if (! empty ( $softLock ))
  540. $mailList += array (
  541. 'softLock' => $softLockNum
  542. );
  543. else
  544. $mailList += array (
  545. 'softLock' => 0
  546. );
  547. if (! empty ( $contract ))
  548. $mailList += array (
  549. 'contract' => $contractNum
  550. );
  551. else
  552. $mailList += array (
  553. 'contract' => 0
  554. );
  555. if (! empty ( $instructions ))
  556. $mailList += array (
  557. 'instructions' => $instructionsNum
  558. );
  559. else
  560. $mailList += array (
  561. 'instructions' => 0
  562. );
  563. if (! empty ( $remittance ))
  564. $mailList += array (
  565. 'remittance' => $remittance
  566. );
  567. else
  568. $mailList += array (
  569. 'remittance' => ''
  570. );
  571. $mailString = '发票x1张,备注:' . $mailItems;
  572. if (! empty ( $softLock ))
  573. $mailString .= ',软件锁x' . $softLockNum . '个';
  574. if (! empty ( $contract ))
  575. $mailString .= ',合同x' . $contractNum . '份';
  576. if (! empty ( $instructions ))
  577. $mailString .= ',说明书x' . $instructionsNum . '本';
  578. if (! empty ( $remittance ))
  579. $mailString .= ',汇款账号单(张)';
  580. $item += array (
  581. 'recipients' => $recipients,
  582. 'recipientsPhone' => $recipientsPhone,
  583. 'recipientsAddress' => $recipientsAddress,
  584. 'mailItems' => $mailString,
  585. 'mailItemsJson' => json_encode ( $mailList )
  586. );
  587. }
  588. $iid = $invoice->addInvoice ( $item );
  589. // 如果是培训班结算 创建培训班发票到培训班备份中
  590. if (! empty ( $st ) && $st == 1) {
  591. Doo::loadModel ( 'invoiceStore' );
  592. $invoiceStore = new invoiceStore ();
  593. Doo::loadModel ( 'invoiceTraining' );
  594. $invoiceTraining = new invoiceTraining ();
  595. $isid = $invoiceStore->setInvoiceToInvoiceStore ( $iid );
  596. $itemIS = array (
  597. 'isid' => $isid,
  598. 'ipSource' => 1,
  599. 'apStatus' => 1,
  600. 'iid' => $iid
  601. );
  602. $invoiceStore->setInvoiceStoreByCondition ( $itemIS );
  603. // 更新培训班总数量
  604. $detailIT = $invoiceTraining->getInvoiceTrainingByItid ( $trainId );
  605. $item = array (
  606. 'itid' => $trainId,
  607. 'invoiceTotal' => $detailIT ['invoiceTotal'] + 1,
  608. 'submitStatus' => 1
  609. );
  610. $itid = $invoiceTraining->setInvoiceTrainByCondition ( $item );
  611. }
  612. // 操作日志
  613. $item = array (
  614. 'date' => date ( "Y-m-d H:i:s" ),
  615. 'operation' => "创建",
  616. 'status' => 1,
  617. 'img' => $this->staff [0] ['avatar'],
  618. 'username' => $this->staff [0] ['username'],
  619. 'uid' => $this->staff [0] ['sid'],
  620. 'category' => $this->staff [0] ['category'],
  621. 'iid' => $iid
  622. );
  623. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  624. $item = array (
  625. 'date' => date ( "Y-m-d H:i:s" ),
  626. 'operation' => "提交审批",
  627. 'status' => 1,
  628. 'img' => $this->staff [0] ['avatar'],
  629. 'username' => $this->staff [0] ['username'],
  630. 'uid' => $this->staff [0] ['sid'],
  631. 'category' => $this->staff [0] ['category'],
  632. 'iid' => $iid
  633. );
  634. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  635. Doo::loadModel ( 'staff' );
  636. $staff = new staff ();
  637. $username2 = $staff->getOne ( array (
  638. 'select' => 'wxid',
  639. 'where' => 'sid=' . $pendingApprovalsSid,
  640. 'asArray' => TRUE
  641. ) );
  642. // 发送微信审批通知
  643. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  644. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  645. }
  646. return "/invoice";
  647. }
  648. function invoiceEdit() {
  649. Doo::loadClass ( 'XDeode' );
  650. $XDeode = new XDeode ( 5 );
  651. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  652. $iid = $XDeode->decode ( $iid );
  653. if (! is_numeric ( $iid ))
  654. die ( 'illegal request' );
  655. Doo::loadModel ( 'invoice' );
  656. $invoice = new invoice ();
  657. Doo::loadModel ( 'invoiceOperationLog' );
  658. $invoiceOperationLog = new invoiceOperationLog ();
  659. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  660. $operation = $invoiceOperationLog->getInvoiceOperationByDropped ( $iid );
  661. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  662. $this->data ['operation'] = $operation;
  663. $this->data ['invoiceDetail'] = $invoiceDetail;
  664. $this->data ['memu'] = "invoice";
  665. $this->data ['staff'] = $this->staff;
  666. $this->data ['receiptMemu'] = 'invoice';
  667. $this->render ( "/admin/invoiceEdit", $this->data );
  668. }
  669. /**
  670. * 重新编辑退回的发票
  671. * @return string
  672. */
  673. function invoiceEditDo() {
  674. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  675. Doo::loadModel ( 'invoice' );
  676. $invoice = new invoice ();
  677. $iid = $invoice->authcode ( $iidKey );
  678. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  679. die ( 'illegal request' );
  680. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  681. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  682. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  683. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  684. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  685. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  686. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  687. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  688. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  689. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  690. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  691. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  692. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  693. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  694. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  695. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  696. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  697. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  698. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  699. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  700. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  701. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  702. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  703. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  704. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  705. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  706. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  707. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  708. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  709. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  710. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  711. if ($invoiceType == 1) {
  712. $temporary = $invoiceQuantity * $invoiceUnitPrice;
  713. if ($temporary > 10000)
  714. die ( 'illegal request-Please priceError' );
  715. }
  716. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  717. Doo::loadModel ( 'invoiceManage' );
  718. $invoiceManage = new invoiceManage ();
  719. Doo::loadModel ( 'invoiceOperationLog' );
  720. $invoiceOperationLog = new invoiceOperationLog ();
  721. Doo::loadModel ( 'invoiceStore' );
  722. $invoiceStore = new invoiceStore ();
  723. $cid = explode ( ':', $cid );
  724. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  725. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  726. $moldManage = array ();
  727. foreach ( $invoiceManageList as $key => $value ) {
  728. if ($value ['mold'] == '发票打印')
  729. $moldManage [$value ['mold']] = $value ['staffList'];
  730. elseif ($value ['mold'] == '发票邮寄')
  731. $moldManage [$value ['mold']] = $value ['staffList'];
  732. elseif ($value ['mold'] == '发票打印')
  733. $moldManage [$value ['mold']] = $value ['staffList'];
  734. }
  735. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  736. $item = array (
  737. 'iid' => $iid,
  738. 'cid' => $cid [0],
  739. 'categoryName' => $cid [1],
  740. 'invoiceElement' => $invoiceElement,
  741. 'invoiceQuantity' => $invoiceQuantity,
  742. 'invoiceUnitPrice' => $invoiceUnitPrice,
  743. 'invoicePrice' => $invoicePrice,
  744. 'invoiceType' => $invoiceType,
  745. 'doPost' => $doPost,
  746. 'status' => 1,
  747. 'updateTime' => date ( "Y-m-d H:i:s" ),
  748. 'remark' => $remark
  749. );
  750. if ($invoiceType == 0)
  751. $item += array (
  752. 'invoiceTitle' => $invoiceTitle,
  753. 'TIN' => $TINT,
  754. 'address' => $addressT,
  755. 'phone' => $phoneT,
  756. 'bank' => $bankT,
  757. 'bankAccount' => $bankAccountT
  758. );
  759. else {
  760. $item += array (
  761. 'invoiceCompany' => $invoiceCompany,
  762. 'TIN' => $TIN,
  763. 'address' => $address,
  764. 'phone' => $phone,
  765. 'bank' => $bank,
  766. 'bankAccount' => $bankAccount
  767. );
  768. }
  769. if ($doPost == 1) {
  770. $mailList = array (
  771. 'invoice' => 1,
  772. 'mailItems' => $mailItems
  773. );
  774. if (! empty ( $softLock ))
  775. $mailList += array (
  776. 'softLock' => $softLockNum
  777. );
  778. else
  779. $mailList += array (
  780. 'softLock' => '0'
  781. );
  782. if (! empty ( $contract ))
  783. $mailList += array (
  784. 'contract' => $contractNum
  785. );
  786. else
  787. $mailList += array (
  788. 'contract' => '0'
  789. );
  790. if (! empty ( $instructions ))
  791. $mailList += array (
  792. 'instructions' => $instructionsNum
  793. );
  794. else
  795. $mailList += array (
  796. 'instructions' => '0'
  797. );
  798. if (! empty ( $remittance ))
  799. $mailList += array (
  800. 'remittance' => $remittance
  801. );
  802. else
  803. $mailList += array (
  804. 'remittance' => ''
  805. );
  806. $mailString = '发票x1,备注:' . $mailItems;
  807. if (! empty ( $softLock ))
  808. $mailString .= ',软件锁x' . $softLockNum;
  809. if (! empty ( $contract ))
  810. $mailString .= ',合同x' . $contractNum;
  811. if (! empty ( $instructions ))
  812. $mailString .= ',说明书x' . $instructionsNum;
  813. if (! empty ( $remittance ))
  814. $mailString .= ',汇款账号单';
  815. $item += array (
  816. 'recipients' => $recipients,
  817. 'recipientsPhone' => $recipientsPhone,
  818. 'recipientsAddress' => $recipientsAddress,
  819. 'mailItems' => $mailString,
  820. 'mailItemsJson' => json_encode ( $mailList )
  821. );
  822. }
  823. $invoice->setInvoiceByCondition ( $item );
  824. // 更新培训班仓库里的发票
  825. $detail = $invoice->getInvoiceByIid ( $iid );
  826. if (! empty ( $detail ['isid'] )) {
  827. $invoiceStore->isid = $detail ['isid'];
  828. $invoiceStore->invoiceQuantity = $invoiceQuantity;
  829. $invoiceStore->invoiceUnitPrice = $invoiceUnitPrice;
  830. $invoiceStore->invoicePrice = $invoicePrice;
  831. $invoiceStore->update ();
  832. }
  833. $item = array (
  834. 'date' => date ( "Y-m-d H:i:s" ),
  835. 'operation' => "重新提交审批",
  836. 'status' => 1,
  837. 'img' => $this->staff [0] ['avatar'],
  838. 'username' => $this->staff [0] ['username'],
  839. 'uid' => $this->staff [0] ['sid'],
  840. 'category' => $this->staff [0] ['category'],
  841. 'iid' => $iid
  842. );
  843. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  844. }
  845. return "/invoice";
  846. }
  847. /**
  848. * 培训班
  849. */
  850. function invoiceTraining() {
  851. Doo::loadModel ( 'L_category' );
  852. $lCategory = new L_category ();
  853. Doo::loadModel ( 'invoiceTraining' );
  854. $invoiceTraining = new invoiceTraining ();
  855. Doo::loadModel ( 'invoiceTrainManage' );
  856. $invoiceTrainManage = new invoiceTrainManage ();
  857. $imcStaff = $invoiceTrainManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  858. $cidList = array ();
  859. foreach ( $imcStaff as $key => $value ) {
  860. array_push ( $cidList, $value ['cid'] );
  861. }
  862. if (empty ( $cidList )) {
  863. $cidString = $this->staff [0] ['cid'];
  864. } else {
  865. $cidString = implode ( ',', $cidList );
  866. $cidString .= $cidString . ',' . $this->staff [0] ['cid'];
  867. }
  868. $itTodoList = $invoiceTraining->getInvoiceTrainingByTodo ( '', $cidString, $this->staff [0] ['sid'] );
  869. $itedList = $invoiceTraining->getInvoiceTrainingByStatus ( 2, '', $cidString, $this->staff [0] ['sid'] );
  870. $category = $lCategory->getCategory ();
  871. $itid = array ();
  872. foreach ( $itTodoList as $key => $value ) {
  873. array_push ( $itid, $value ['itid'] );
  874. // 如果入账100%更新为已完成
  875. if ($itTodoList [$key] ['arriveSchedule'] >= 100) {
  876. $invoiceTraining = new invoiceTraining ();
  877. $invoiceTraining->itid = $value ['itid'];
  878. $invoiceTraining->status = 2;
  879. $invoiceTraining->update ();
  880. }
  881. }
  882. foreach ( $itedList as $value ) {
  883. array_push ( $itid, $value ['itid'] );
  884. }
  885. $itid = implode ( ',', $itid );
  886. $this->data ['itStatist'] = $invoiceTraining->getInvoiceTrainStatistics ( $itid );
  887. // print_r($itTodoList);
  888. $this->data ['trainCount'] = count ( $itTodoList ) + count ( $itedList );
  889. $this->data ['itTodoList'] = $itTodoList;
  890. $this->data ['itedList'] = $itedList;
  891. $this->data ['category'] = $category;
  892. $this->data ['memu'] = "invoice";
  893. $this->data ['staff'] = $this->staff;
  894. $this->data ['receiptMemu'] = 'invoiceTraining';
  895. $this->render ( "/admin/invoiceTraining", $this->data );
  896. }
  897. /**
  898. * 创建培训班
  899. */
  900. function invoiceTrainingAdd() {
  901. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  902. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  903. $trainDate = $this->get_args ( 'trainDate' ) ? $this->get_args ( 'trainDate' ) : "";
  904. if (empty ( $this->staff [0] ))
  905. die ( 'illegal request' );
  906. if (! empty ( $cid ) && ! empty ( $trainName ) && ! empty ( $trainDate )) {
  907. Doo::loadModel ( 'invoiceTraining' );
  908. $invoiceTraining = new invoiceTraining ();
  909. Doo::loadModel ( 'invoice' );
  910. $invoice = new invoice ();
  911. Doo::loadModel ( 'L_category' );
  912. $lCategory = new L_category ();
  913. Doo::loadModel ( 'invoiceManage' );
  914. $invoiceManage = new invoiceManage ();
  915. Doo::loadModel ( 'invoiceOperationLog' );
  916. $invoiceOperationLog = new invoiceOperationLog ();
  917. $item = array (
  918. 'cid' => $cid,
  919. 'trainName' => $trainName,
  920. 'trainDate' => $trainDate,
  921. 'creator' => $this->staff [0] ['sid'],
  922. 'creatorDate' => date ( "Y-m-d H:i:s" )
  923. );
  924. $itid = $invoiceTraining->addInvoiceTraining ( $item );
  925. }
  926. return "/invoiceTraining";
  927. }
  928. /**
  929. * 删除培训班
  930. */
  931. function invoiceTrainingDelDo() {
  932. $itid = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  933. if (! empty ( $itid )) {
  934. Doo::loadModel ( 'invoiceTraining' );
  935. $invoiceTraining = new invoiceTraining ();
  936. $invoiceTraining->delInvoiceTrainingByItid ( $itid );
  937. }
  938. return "/invoiceTraining";
  939. }
  940. /**
  941. * 培训班详情
  942. */
  943. function invoiceTrainingDetail() {
  944. $trainStatus = $this->get_args ( 'trainStatus' ) ? $this->get_args ( 'trainStatus' ) : "ALL";
  945. $itid = isset ( $this->params ['trainingKey'] ) ? $this->params ['trainingKey'] : "";
  946. Doo::loadModel ( 'invoiceTraining' );
  947. $invoiceTraining = new invoiceTraining ();
  948. Doo::loadModel ( 'invoiceStore' );
  949. $invoiceStore = new invoiceStore ();
  950. if (empty ( $itid ))
  951. die ( 'illegal request' );
  952. $con = ' (b.untreadStatus is null or b.untreadStatus!=2) and ';
  953. if ($trainStatus == "SUBED")
  954. $con = ' (b.untreadStatus is null ) and ';
  955. elseif ($trainStatus == "APPROVAL")
  956. $con = ' ( b.status=1 and b.untreadStatus!=2 ) and ';
  957. elseif ($trainStatus == "TICKET")
  958. $con = ' (b.printStatus=1 and b.status=2 and b.untreadStatus!=2) and ';
  959. elseif ($trainStatus == "TICKETING") {
  960. $con = ' (b.status=2 and b.untreadStatus=1) and ';
  961. }
  962. $detail = $invoiceTraining->getInvoiceTrainingByItid ( $itid );
  963. $isList = $invoiceStore->getinvoiceStoreByItid ( $itid, $con );
  964. // print_r($isList);
  965. $trainlist = array ();
  966. foreach ( $isList as $key => $value ) {
  967. $irDetail = array ();
  968. if ($value ['apStatus'] == 1) {
  969. // array_push ( $irDetail, '' );
  970. array_push ( $irDetail, '<input disabled type="checkbox" style="display:none" >' );
  971. } else {
  972. array_push ( $irDetail, '<input type="checkbox" class="hide" id="' . $value ['storeKey'] . '" name="isBox" value="' . $value ['storeKey'] . '" > <a href="/invoiceStoreEdit/' . $value ['storeKey'] . '.html">编辑</a>
  973. <a href="#confirm" onclick="invoiceStoreApproval(\'' . $value ['storeKey'] . '\')" data-toggle="modal">提交审批</a>
  974. <a href="#del" node-iStore="del" data-key="' . $value ['storeKey'] . '" onclick="invoiceStoreDel(\'' . $value ['storeKey'] . '\')" data-toggle="modal" class="colRed">移除</a>' );
  975. }
  976. array_push ( $irDetail, $value ['invoiceSerial'] );
  977. if ($value ['invoiceType'] == 1)
  978. array_push ( $irDetail, $value ['invoiceCompany'] );
  979. else
  980. array_push ( $irDetail, $value ['invoiceTitle'] );
  981. array_push ( $irDetail, $value ['TIN'] );
  982. array_push ( $irDetail, $value ['userName'] );
  983. if (empty ( $value ['mailItems'] ) && $value ['apStatus'] != 1) {
  984. array_push ( $irDetail, '<a href="#confirm-erro" onclick="invoiceStoreMail(\'' . $value ['storeKey'] . '\')" data-toggle="modal">设置邮寄物品</a>' );
  985. } else
  986. array_push ( $irDetail, $value ['mailItems'] );
  987. array_push ( $irDetail, $value ['recipientsAddress'] . $value ['recipients'] . $value ['recipientsPhone'] );
  988. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  989. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  990. array_push ( $irDetail, $value ['invoiceElement'] );
  991. array_push ( $irDetail, $value ['invoiceQuantity'] );
  992. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  993. if ($value ['invoiceType'] == 1)
  994. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  995. else
  996. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  997. array_push ( $irDetail, $value ['remark'] );
  998. if ($value ['status'] == 1)
  999. array_push ( $irDetail, '审批中' );
  1000. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1)
  1001. array_push ( $irDetail, '已出票' );
  1002. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1 && $value ['printStatus'] != 'irid' && ($value ['untreadStatus'] == 3 || $value ['untreadStatus'] == 0))
  1003. array_push ( $irDetail, '已入账' );
  1004. else
  1005. array_push ( $irDetail, '' );
  1006. array_push ( $irDetail, $value ['invoiceNo'] );
  1007. array_push ( $irDetail, $value ['printTime'] );
  1008. $html = '';
  1009. foreach ( $value ['invoiceReceivables'] as $value ) {
  1010. $html .= '&nbsp;<a href="#billing" node-invoice="INFO" data-type="receivables" data-iskey="' . $value [2] . '" data-toggle="modal">' . $value [1] . '</a>';
  1011. }
  1012. array_push ( $irDetail, $html );
  1013. array_push ( $trainlist, $irDetail );
  1014. }
  1015. $trainlistJson = json_encode ( $trainlist );
  1016. if (empty ( $detail ))
  1017. die ( 'illegal request' );
  1018. // 培训班结算是否有和是否已经结算完成
  1019. Doo::loadModel ( 'receipt' );
  1020. $receipt = new receipt ();
  1021. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $itid );
  1022. $this->data ['receiptDetail'] = $receiptDetail;
  1023. $this->data ['trainStatus'] = $trainStatus;
  1024. $this->data ['itid'] = $itid;
  1025. $this->data ['trainlistJson'] = $trainlistJson;
  1026. $this->data ['iTrainDetail'] = $detail;
  1027. $this->data ['memu'] = "invoice";
  1028. $this->data ['staff'] = $this->staff;
  1029. $this->data ['receiptMemu'] = 'invoiceTraining';
  1030. $this->render ( "/admin/invoiceTrainingDetail", $this->data );
  1031. }
  1032. /**
  1033. * 上传培训班发票
  1034. * @return string
  1035. */
  1036. function invoiceTrainingUpload() {
  1037. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  1038. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  1039. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  1040. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  1041. header ( "HTTP/1.1 500 Internal Server Error" );
  1042. echo "POST exceeded maximum allowed size.";
  1043. exit ( 0 );
  1044. }
  1045. // Settings
  1046. $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)
  1047. $upload_name = "Filedata";
  1048. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  1049. $extension_whitelist = array (
  1050. "doc",
  1051. "txt",
  1052. "jpg",
  1053. "gif",
  1054. "png"
  1055. ); // Allowed file extensions
  1056. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  1057. // Other variables
  1058. $MAX_FILENAME_LENGTH = 260;
  1059. $file_name = "";
  1060. $file_extension = "";
  1061. $uploadErrors = array (
  1062. 0 => "文件上传成功",
  1063. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  1064. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  1065. 3 => "上传的文件仅为部分文件",
  1066. 4 => "没有文件上传",
  1067. 6 => "缺少临时文件夹"
  1068. );
  1069. $nk = time ();
  1070. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  1071. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  1072. echo "文件无法保存.";
  1073. exit ( 0 );
  1074. }
  1075. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  1076. echo json_encode ( array (
  1077. 'filename' => $file_name,
  1078. 'id' => $nk
  1079. ) );
  1080. exit ( 0 );
  1081. }
  1082. /**
  1083. * 导入发票临时仓库
  1084. */
  1085. function invoiceStoreImport() {
  1086. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  1087. $trainingKey = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  1088. $path = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  1089. if ($path != "" && ! empty ( $trainingKey )) {
  1090. Doo::loadModel ( 'invoiceStore' );
  1091. Doo::loadModel ( 'staff' );
  1092. $staff = new staff ();
  1093. Doo::loadModel ( 'invoiceTraining' );
  1094. $invoiceTraining = new invoiceTraining ();
  1095. Doo::loadClass ( 'XDeode' );
  1096. $XDeode = new XDeode ( 5 );
  1097. $itid = $XDeode->decode ( $trainingKey );
  1098. // 培训班结算是否有和是否已经结算完成
  1099. Doo::loadModel ( 'receipt' );
  1100. $receipt = new receipt ();
  1101. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $itid );
  1102. if (! empty ( $receiptDetail )) {
  1103. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9)
  1104. die ( 'illegal request--status' );
  1105. }
  1106. $exlArray = $this->formatExcelToArrayTrain ( DOO::conf ()->SITE_PATH . "upload/invoiceTraining/" . $path );
  1107. $userName = $this->staff [0] ['username'];
  1108. $sDetail = $staff->getStaffByName ( $userName );
  1109. // die('sdd');
  1110. // 可以优化
  1111. foreach ( $exlArray as $key => $value ) {
  1112. // 开票
  1113. $invoice = new invoiceStore ();
  1114. $invoice->trainId = $itid;
  1115. $invoice->invoiceType = 0;
  1116. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  1117. $invoice->invoiceType = 1;
  1118. $invoice->invoiceQuantity = $value ['invoiceQuantity'];
  1119. $invoice->invoiceUnitPrice = $value ['invoiceUnitPrice'];
  1120. $invoice->invoicePrice = $value ['invoiceQuantity'] * $value ['invoiceUnitPrice'];
  1121. $invoice->invoiceTitle = $value ['invoiceTitle'];
  1122. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  1123. $invoice->invoiceCompany = $value ['invoiceTitle'];
  1124. $invoice->userName = $userName;
  1125. $invoice->sid = $sDetail ['sid'];
  1126. $invoice->cid = $sDetail ['cid'];
  1127. $invoice->categoryName = $sDetail ['category'];
  1128. $invoice->invoiceElement = $value ['invoiceElement'];
  1129. $invoice->remark = $value ['remark'];
  1130. // $invoice->date = $value ['date'];
  1131. // $invoice->printTime = $value ['date'];
  1132. $invoice->ipSource = 1;
  1133. $invoice->printStatus = 0;
  1134. $invoice->status = 0;
  1135. $invoice->postStatus = 1;
  1136. $invoice->untreadStatus = 0;
  1137. // $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1138. $invoice->TIN = $value ['TIN'];
  1139. $invoice->address = $value ['address'];
  1140. $invoice->phone = $value ['phone'];
  1141. $invoice->bank = $value ['bank'];
  1142. $invoice->bankAccount = $value ['bankAccount'];
  1143. $invoice->recipientsAddress = $value ['recipientsAddress'];
  1144. $invoice->recipients = $value ['recipients'];
  1145. $invoice->recipientsPhone = $value ['recipientsPhone'];
  1146. $iid = $invoice->insert ();
  1147. }
  1148. // 加入发票总数量
  1149. $item = array (
  1150. 'itid' => $itid,
  1151. 'invoiceTotal' => count ( $exlArray )
  1152. );
  1153. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1154. return '/invoiceTrainingDetail/' . $trainingKey . ".html";
  1155. }
  1156. echo 'no file';
  1157. }
  1158. /**
  1159. * 编辑仓库里的发票
  1160. */
  1161. function invoiceStoreEdit() {
  1162. Doo::loadClass ( 'XDeode' );
  1163. $XDeode = new XDeode ( 5 );
  1164. $iid = isset ( $this->params ['storeKey'] ) ? $this->params ['storeKey'] : "";
  1165. $iid = $XDeode->decode ( $iid );
  1166. if (! is_numeric ( $iid ))
  1167. die ( 'illegal request' );
  1168. Doo::loadModel ( 'invoiceStore' );
  1169. $invoiceStore = new invoiceStore ();
  1170. $invoiceDetail = $invoiceStore->getInvoiceStoreByIsid ( $iid );
  1171. // print_r($invoiceDetail);
  1172. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  1173. $this->data ['invoiceDetail'] = $invoiceDetail;
  1174. $this->data ['memu'] = "invoice";
  1175. $this->data ['staff'] = $this->staff;
  1176. $this->data ['receiptMemu'] = 'invoiceTraining';
  1177. $this->render ( "/admin/invoiceStoreEdit", $this->data );
  1178. }
  1179. function invoiceStoreEditDo() {
  1180. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1181. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1182. Doo::loadModel ( 'invoiceStore' );
  1183. $invoice = new invoiceStore ();
  1184. Doo::loadClass ( 'XDeode' );
  1185. $XDeode = new XDeode ( 5 );
  1186. $iid = $XDeode->decode ( $storeKey );
  1187. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1188. die ( 'illegal request' );
  1189. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  1190. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  1191. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  1192. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  1193. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  1194. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  1195. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  1196. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  1197. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  1198. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  1199. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  1200. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  1201. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  1202. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  1203. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1204. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1205. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1206. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1207. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  1208. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  1209. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  1210. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  1211. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  1212. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  1213. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1214. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1215. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1216. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1217. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1218. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1219. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1220. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  1221. $cid = explode ( ':', $cid );
  1222. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  1223. $item = array (
  1224. 'isid' => $iid,
  1225. 'cid' => $cid [0],
  1226. 'categoryName' => $cid [1],
  1227. 'invoiceElement' => $invoiceElement,
  1228. 'invoiceQuantity' => $invoiceQuantity,
  1229. 'invoiceUnitPrice' => $invoiceUnitPrice,
  1230. 'invoicePrice' => $invoicePrice,
  1231. 'invoiceType' => $invoiceType,
  1232. 'doPost' => $doPost,
  1233. 'status' => 1,
  1234. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1235. 'remark' => $remark
  1236. );
  1237. if ($invoiceType == 0)
  1238. $item += array (
  1239. 'invoiceTitle' => $invoiceTitle,
  1240. 'TIN' => $TINT,
  1241. 'address' => $addressT,
  1242. 'phone' => $phoneT,
  1243. 'bank' => $bankT,
  1244. 'bankAccount' => $bankAccountT
  1245. );
  1246. else {
  1247. $item += array (
  1248. 'invoiceCompany' => $invoiceCompany,
  1249. 'TIN' => $TIN,
  1250. 'address' => $address,
  1251. 'phone' => $phone,
  1252. 'bank' => $bank,
  1253. 'bankAccount' => $bankAccount
  1254. );
  1255. }
  1256. if ($doPost == 1) {
  1257. $mailList = array (
  1258. 'invoice' => 1,
  1259. 'mailItems' => $mailItems
  1260. );
  1261. if (! empty ( $softLock ))
  1262. $mailList += array (
  1263. 'softLock' => $softLockNum
  1264. );
  1265. else
  1266. $mailList += array (
  1267. 'softLock' => '0'
  1268. );
  1269. if (! empty ( $contract ))
  1270. $mailList += array (
  1271. 'contract' => $contractNum
  1272. );
  1273. else
  1274. $mailList += array (
  1275. 'contract' => '0'
  1276. );
  1277. if (! empty ( $instructions ))
  1278. $mailList += array (
  1279. 'instructions' => $instructionsNum
  1280. );
  1281. else
  1282. $mailList += array (
  1283. 'instructions' => '0'
  1284. );
  1285. if (! empty ( $remittance ))
  1286. $mailList += array (
  1287. 'remittance' => $remittance
  1288. );
  1289. else
  1290. $mailList += array (
  1291. 'remittance' => ''
  1292. );
  1293. $mailString = '发票x1,备注:' . $mailItems;
  1294. if (! empty ( $softLock ))
  1295. $mailString .= ',软件锁x' . $softLockNum;
  1296. if (! empty ( $contract ))
  1297. $mailString .= ',合同x' . $contractNum;
  1298. if (! empty ( $instructions ))
  1299. $mailString .= ',说明书x' . $instructionsNum;
  1300. if (! empty ( $remittance ))
  1301. $mailString .= ',汇款账号单';
  1302. $item += array (
  1303. 'recipients' => $recipients,
  1304. 'recipientsPhone' => $recipientsPhone,
  1305. 'recipientsAddress' => $recipientsAddress,
  1306. 'mailItems' => $mailString,
  1307. 'mailItemsJson' => json_encode ( $mailList )
  1308. );
  1309. }
  1310. $invoice->setInvoiceStoreByCondition ( $item );
  1311. }
  1312. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1313. }
  1314. /**
  1315. *
  1316. * @return string
  1317. */
  1318. function invoiceStoreDelete() {
  1319. Doo::loadClass ( 'XDeode' );
  1320. $XDeode = new XDeode ( 5 );
  1321. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1322. $iStoreKey = $this->get_args ( 'iStoreKey' ) ? $this->get_args ( 'iStoreKey' ) : 0;
  1323. $isid = $XDeode->decode ( $iStoreKey );
  1324. $itid = $XDeode->decode ( $trainKey );
  1325. if (! is_numeric ( $isid ))
  1326. die ( 'illegal request' );
  1327. Doo::loadModel ( 'invoiceStore' );
  1328. $invoiceStore = new invoiceStore ();
  1329. $invoiceStore->delete ( array (
  1330. 'where' => 'isid=' . $isid,
  1331. 'limit' => 1
  1332. ) );
  1333. Doo::loadModel ( 'invoiceTraining' );
  1334. $invoiceTraining = new invoiceTraining ();
  1335. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1336. $item = array (
  1337. 'itid' => $itid,
  1338. 'invoiceTotal' => $itDetail ['invoiceTotal'] - 1
  1339. );
  1340. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1341. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1342. }
  1343. /**
  1344. * 批量删除库里发票
  1345. */
  1346. function invoiceStoreBatchDelete() {
  1347. Doo::loadClass ( 'XDeode' );
  1348. $XDeode = new XDeode ( 5 );
  1349. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1350. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1351. if (empty ( $trainKey ) || empty ( $storeKey ))
  1352. die ( 'illegal request-IdKey' );
  1353. $tid = $XDeode->decode ( $trainKey );
  1354. if (! is_numeric ( $tid ) && ! empty ( $storeKey ))
  1355. die ( 'illegal request' );
  1356. Doo::loadModel ( 'invoiceStore' );
  1357. $isidKeyList = explode ( ',', $storeKey );
  1358. $isidList = array ();
  1359. foreach ( $isidKeyList as $value ) {
  1360. $isid = $XDeode->decode ( $value );
  1361. if (! empty ( $isid ) && is_numeric ( $isid ))
  1362. array_push ( $isidList, $isid );
  1363. }
  1364. $isidString = implode ( ',', $isidList );
  1365. $invoiceStore = new invoiceStore ();
  1366. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,apStatus' );
  1367. $isidList = array ();
  1368. foreach ( $isList as $key => $value ) {
  1369. if ($value ['apStatus'] == 0)
  1370. array_push ( $isidList, $value ['isid'] );
  1371. }
  1372. $isidString = implode ( ',', $isidList );
  1373. // print_r($isList);
  1374. // echo $isidString;
  1375. $invoiceStore = new invoiceStore ();
  1376. $invoiceStore->delete ( array (
  1377. 'where' => "isid in ( " . $isidString . ")",
  1378. 'asArray' => TRUE
  1379. ) );
  1380. Doo::loadModel ( 'invoiceTraining' );
  1381. $invoiceTraining = new invoiceTraining ();
  1382. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1383. $item = array (
  1384. 'itid' => $tid,
  1385. 'invoiceTotal' => $itDetail ['invoiceTotal'] - count ( $isidList )
  1386. );
  1387. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1388. // echo $tid;
  1389. // echo $storeKey;
  1390. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1391. }
  1392. /**
  1393. * 仓库发票提交审批
  1394. * @return string
  1395. */
  1396. function invoiceStoreApproval() {
  1397. Doo::loadClass ( 'XDeode' );
  1398. $XDeode = new XDeode ( 5 );
  1399. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1400. $iStoreKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1401. $isid = $XDeode->decode ( $iStoreKey );
  1402. $trainId = $XDeode->decode ( $trainKey );
  1403. if (! is_numeric ( $isid ))
  1404. die ( 'illegal request' );
  1405. Doo::loadModel ( 'invoiceStore' );
  1406. Doo::loadModel ( 'invoice' );
  1407. $invoice = new invoice ();
  1408. // 加入限制必须填写入开票内容和邮寄物品
  1409. $invoiceStore = new invoiceStore ();
  1410. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid, 'isid,trainId ,invoiceElement,mailItemsJson' );
  1411. if (empty ( $isDetail ['invoiceElement'] ) || empty ( $isDetail ['mailItemsJson'] )) {
  1412. header ( 'Content-Type:text/html;charset=utf-8' );
  1413. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1414. }
  1415. // 拷贝插入一条发票数据
  1416. $invoiceStore = new invoiceStore ();
  1417. $iid = $invoiceStore->setInvoiceStoreToApproval ( $isid );
  1418. $invoiceStore = new invoiceStore ();
  1419. $item = array (
  1420. 'isid' => $isid,
  1421. 'iid' => $iid,
  1422. 'apStatus' => 1
  1423. );
  1424. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1425. Doo::loadModel ( 'invoiceManage' );
  1426. $invoiceManage = new invoiceManage ();
  1427. Doo::loadModel ( 'invoiceOperationLog' );
  1428. $invoiceOperationLog = new invoiceOperationLog ();
  1429. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1430. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1431. $moldManage = array ();
  1432. foreach ( $invoiceManageList as $key => $value ) {
  1433. if ($value ['mold'] == '发票打印')
  1434. $moldManage [$value ['mold']] = $value ['staffList'];
  1435. elseif ($value ['mold'] == '发票邮寄')
  1436. $moldManage [$value ['mold']] = $value ['staffList'];
  1437. elseif ($value ['mold'] == '发票退票')
  1438. $moldManage [$value ['mold']] = $value ['staffList'];
  1439. }
  1440. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1441. $item = array (
  1442. 'iid' => $iid,
  1443. 'isid' => $isid,
  1444. 'invoiceSerial' => "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  1445. 'date' => date ( "Y-m-d H:i:s" ),
  1446. 'status' => 1,
  1447. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1448. 'trainId' => $trainId,
  1449. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1450. 'moldManage' => json_encode ( $moldManage ),
  1451. 'settlementType' => 1,
  1452. 'pendingApprovals' => $pendingApprovalsSid
  1453. );
  1454. $invoice->setInvoiceByCondition ( $item );
  1455. Doo::loadModel ( 'invoiceTraining' );
  1456. $invoiceTraining = new invoiceTraining ();
  1457. $item = array (
  1458. 'itid' => $trainId,
  1459. 'submitStatus' => 1
  1460. );
  1461. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1462. $item = array (
  1463. 'date' => date ( "Y-m-d H:i:s" ),
  1464. 'operation' => "创建",
  1465. 'status' => 1,
  1466. 'img' => $this->staff [0] ['avatar'],
  1467. 'username' => $this->staff [0] ['username'],
  1468. 'uid' => $this->staff [0] ['sid'],
  1469. 'category' => $this->staff [0] ['category'],
  1470. 'iid' => $iid
  1471. );
  1472. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1473. $item = array (
  1474. 'date' => date ( "Y-m-d H:i:s" ),
  1475. 'operation' => "提交审批",
  1476. 'status' => 1,
  1477. 'img' => $this->staff [0] ['avatar'],
  1478. 'username' => $this->staff [0] ['username'],
  1479. 'uid' => $this->staff [0] ['sid'],
  1480. 'category' => $this->staff [0] ['category'],
  1481. 'iid' => $iid
  1482. );
  1483. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1484. Doo::loadModel ( 'staff' );
  1485. $staff = new staff ();
  1486. $username2 = $staff->getOne ( array (
  1487. 'select' => 'wxid',
  1488. 'where' => 'sid=' . $pendingApprovalsSid,
  1489. 'asArray' => TRUE
  1490. ) );
  1491. // 发送微信审批通知
  1492. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1493. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1494. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1495. }
  1496. /**
  1497. * 批量提交发票
  1498. * @return string
  1499. */
  1500. function invoiceStoreBatchApproval() {
  1501. Doo::loadClass ( 'XDeode' );
  1502. $XDeode = new XDeode ( 5 );
  1503. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1504. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1505. if (empty ( $trainKey ) || empty ( $storeKey ))
  1506. die ( 'illegal request-IdKey' );
  1507. $trainId = $XDeode->decode ( $trainKey );
  1508. $isidKeyList = explode ( ',', $storeKey );
  1509. $isidList = array ();
  1510. foreach ( $isidKeyList as $value ) {
  1511. $isid = $XDeode->decode ( $value );
  1512. if (! empty ( $isid ) && is_numeric ( $isid ))
  1513. array_push ( $isidList, $isid );
  1514. }
  1515. $isidString = implode ( ',', $isidList );
  1516. if (! is_numeric ( $trainId ))
  1517. die ( 'illegal request' );
  1518. Doo::loadModel ( 'invoiceStore' );
  1519. Doo::loadModel ( 'invoice' );
  1520. // 判断哪些已经加入审批过
  1521. // 加入限制必须填写入开票内容和邮寄物品
  1522. $invoiceStore = new invoiceStore ();
  1523. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,trainId ,invoiceElement,mailItemsJson' );
  1524. foreach ( $isList as $key => $value ) {
  1525. if (empty ( $value ['invoiceElement'] ) || empty ( $value ['mailItemsJson'] )) {
  1526. header ( 'Content-Type:text/html;charset=utf-8' );
  1527. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1528. }
  1529. }
  1530. // 拷贝插入一条发票数据
  1531. $invoiceStore = new invoiceStore ();
  1532. $invoiceStore->setInvoiceStoreBatchToApproval ( $isidString );
  1533. $invoiceStore = new invoiceStore ();
  1534. $item = array (
  1535. 'apStatus' => 1
  1536. );
  1537. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1538. // 获得正式发票ID
  1539. $invoice = new invoice ();
  1540. $iidList = $invoice->getInvoiceByIstoreid ( $isidString, 'iid,isid' );
  1541. $sqlList = array ();
  1542. $iidString = '';
  1543. $iida = array ();
  1544. foreach ( $iidList as $key => $value ) {
  1545. $sqlList [$value ['isid']] = $value ['iid'];
  1546. array_push ( $iida, $value ['iid'] );
  1547. }
  1548. $iidString = implode ( ',', $iida );
  1549. $ids = implode ( ',', array_keys ( $sqlList ) );
  1550. $sql = "UPDATE CLD_invoiceStore SET iid = CASE isid ";
  1551. foreach ( $sqlList as $id => $ordinal ) {
  1552. $sql .= sprintf ( "WHEN %d THEN %d ", $id, $ordinal );
  1553. }
  1554. $sql .= "END WHERE isid IN ($ids)";
  1555. $invoiceStore = new invoiceStore ();
  1556. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1557. Doo::loadModel ( 'invoiceManage' );
  1558. $invoiceManage = new invoiceManage ();
  1559. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1560. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1561. $moldManage = array ();
  1562. foreach ( $invoiceManageList as $key => $value ) {
  1563. if ($value ['mold'] == '发票打印')
  1564. $moldManage [$value ['mold']] = $value ['staffList'];
  1565. elseif ($value ['mold'] == '发票邮寄')
  1566. $moldManage [$value ['mold']] = $value ['staffList'];
  1567. elseif ($value ['mold'] == '发票退票')
  1568. $moldManage [$value ['mold']] = $value ['staffList'];
  1569. }
  1570. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1571. // 批量更新发票信息
  1572. $item = array (
  1573. 'date' => date ( "Y-m-d H:i:s" ),
  1574. 'status' => 1,
  1575. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1576. 'trainId' => $trainId,
  1577. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1578. 'moldManage' => json_encode ( $moldManage ),
  1579. 'settlementType' => 1,
  1580. 'pendingApprovals' => $pendingApprovalsSid
  1581. );
  1582. $invoice = new invoice ();
  1583. $invoice->BatchInvoiceByCondition ( $item, $iidString );
  1584. // 批量更新发票中仓库isid
  1585. $sql = "UPDATE CLD_invoiceStore SET isid = CASE iid ";
  1586. foreach ( $sqlList as $isid => $iid ) {
  1587. $sql .= sprintf ( "WHEN %d THEN %d ", $iid, $isid );
  1588. }
  1589. $sql .= "END WHERE iid IN ($iidString)";
  1590. $invoice = new invoice ();
  1591. $invoice->UpdateBatchInvoice ( $sql );
  1592. // 批量更新发票序列号
  1593. $sqlList = array ();
  1594. foreach ( $iida as $value ) {
  1595. $sqlList [$value] = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1596. }
  1597. $ids = implode ( ',', array_keys ( $sqlList ) );
  1598. $sql = "UPDATE CLD_invoice SET invoiceSerial = CASE iid ";
  1599. foreach ( $sqlList as $id => $ordinal ) {
  1600. $sql .= sprintf ( "WHEN %d THEN '%s' ", $id, $ordinal );
  1601. }
  1602. $sql .= "END WHERE iid IN ($ids)";
  1603. $invoiceStore = new invoiceStore ();
  1604. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1605. // 批量生产操作日志
  1606. Doo::loadModel ( 'invoiceOperationLog' );
  1607. $sqlList = array ();
  1608. foreach ( $iida as $key => $value ) {
  1609. $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 . '"),
  1610. ("' . 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 . '") ';
  1611. array_push ( $sqlList, $sql );
  1612. }
  1613. $iolSql = implode ( ',', $sqlList );
  1614. $sql = "INSERT INTO `CLD_invoiceOperationLog` (`date`, `operation`, `status`, `img`, `username`, `uid`, `category`, `iid`) VALUES " . $iolSql;
  1615. $invoiceOperationLog = new invoiceOperationLog ();
  1616. $invoiceOperationLog->setInvoiceOperationLogBySql ( $sql );
  1617. Doo::loadModel ( 'invoiceTraining' );
  1618. $invoiceTraining = new invoiceTraining ();
  1619. $item = array (
  1620. 'itid' => $trainId,
  1621. 'submitStatus' => 1
  1622. );
  1623. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1624. Doo::loadModel ( 'staff' );
  1625. $staff = new staff ();
  1626. $username2 = $staff->getOne ( array (
  1627. 'select' => 'wxid',
  1628. 'where' => 'sid=' . $pendingApprovalsSid,
  1629. 'asArray' => TRUE
  1630. ) );
  1631. // 发送微信审批通知
  1632. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1633. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1634. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1635. }
  1636. /**
  1637. */
  1638. function invoiceStoreMailItemSet() {
  1639. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1640. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1641. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1642. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1643. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1644. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1645. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1646. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1647. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1648. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1649. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1650. Doo::loadClass ( 'XDeode' );
  1651. $XDeode = new XDeode ( 5 );
  1652. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1653. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1654. $isid = $XDeode->decode ( $storeKey );
  1655. $trainId = $XDeode->decode ( $trainKey );
  1656. if (! is_numeric ( $isid ))
  1657. die ( 'illegal request' );
  1658. Doo::loadModel ( 'invoiceStore' );
  1659. $invoiceStore = new invoiceStore ();
  1660. $mailList = array (
  1661. 'invoice' => 1,
  1662. 'mailItems' => $mailItems
  1663. );
  1664. if (! empty ( $softLock ))
  1665. $mailList += array (
  1666. 'softLock' => $softLockNum
  1667. );
  1668. else
  1669. $mailList += array (
  1670. 'softLock' => 0
  1671. );
  1672. if (! empty ( $contract ))
  1673. $mailList += array (
  1674. 'contract' => $contractNum
  1675. );
  1676. else
  1677. $mailList += array (
  1678. 'contract' => 0
  1679. );
  1680. if (! empty ( $instructions ))
  1681. $mailList += array (
  1682. 'instructions' => $instructionsNum
  1683. );
  1684. else
  1685. $mailList += array (
  1686. 'instructions' => 0
  1687. );
  1688. if (! empty ( $remittance ))
  1689. $mailList += array (
  1690. 'remittance' => $remittance
  1691. );
  1692. else
  1693. $mailList += array (
  1694. 'remittance' => ''
  1695. );
  1696. $mailString = '发票x1,备注:' . $mailItems;
  1697. if (! empty ( $softLock ))
  1698. $mailString .= ',软件锁x' . $softLockNum;
  1699. if (! empty ( $contract ))
  1700. $mailString .= ',合同x' . $contractNum;
  1701. if (! empty ( $instructions ))
  1702. $mailString .= ',说明书x' . $instructionsNum;
  1703. if (! empty ( $remittance ))
  1704. $mailString .= ',汇款账号单';
  1705. $item = array (
  1706. 'isid' => $isid,
  1707. 'doPost' => 1,
  1708. 'mailItems' => $mailString,
  1709. 'mailItemsJson' => json_encode ( $mailList )
  1710. );
  1711. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1712. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1713. }
  1714. /**
  1715. * 批量设置邮寄物品
  1716. */
  1717. function invoiceStoreBatchMailItemSet() {
  1718. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1719. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1720. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1721. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1722. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1723. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1724. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1725. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1726. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1727. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1728. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1729. Doo::loadClass ( 'XDeode' );
  1730. $XDeode = new XDeode ( 5 );
  1731. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1732. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1733. if (empty ( $trainKey ) || empty ( $storeKey ))
  1734. die ( 'illegal request-IdKey' );
  1735. $isidKeyList = explode ( ',', $storeKey );
  1736. $isidList = array ();
  1737. foreach ( $isidKeyList as $value ) {
  1738. $isid = $XDeode->decode ( $value );
  1739. if (! empty ( $isid ) && is_numeric ( $isid ))
  1740. array_push ( $isidList, $isid );
  1741. }
  1742. $isidString = implode ( ',', $isidList );
  1743. $trainId = $XDeode->decode ( $trainKey );
  1744. if (! is_numeric ( $isid ))
  1745. die ( 'illegal request' );
  1746. Doo::loadModel ( 'invoiceStore' );
  1747. $invoiceStore = new invoiceStore ();
  1748. $mailList = array (
  1749. 'invoice' => 1,
  1750. 'mailItems' => $mailItems
  1751. );
  1752. if (! empty ( $softLock ))
  1753. $mailList += array (
  1754. 'softLock' => $softLockNum
  1755. );
  1756. else
  1757. $mailList += array (
  1758. 'softLock' => 0
  1759. );
  1760. if (! empty ( $contract ))
  1761. $mailList += array (
  1762. 'contract' => $contractNum
  1763. );
  1764. else
  1765. $mailList += array (
  1766. 'contract' => 0
  1767. );
  1768. if (! empty ( $instructions ))
  1769. $mailList += array (
  1770. 'instructions' => $instructionsNum
  1771. );
  1772. else
  1773. $mailList += array (
  1774. 'instructions' => 0
  1775. );
  1776. if (! empty ( $remittance ))
  1777. $mailList += array (
  1778. 'remittance' => $remittance
  1779. );
  1780. else
  1781. $mailList += array (
  1782. 'remittance' => ''
  1783. );
  1784. $mailString = '发票x1,备注:' . $mailItems;
  1785. if (! empty ( $softLock ))
  1786. $mailString .= ',软件锁x' . $softLockNum;
  1787. if (! empty ( $contract ))
  1788. $mailString .= ',合同x' . $contractNum;
  1789. if (! empty ( $instructions ))
  1790. $mailString .= ',说明书x' . $instructionsNum;
  1791. if (! empty ( $remittance ))
  1792. $mailString .= ',汇款账号单';
  1793. $item = array (
  1794. 'doPost' => 1,
  1795. 'mailItems' => $mailString,
  1796. 'mailItemsJson' => json_encode ( $mailList )
  1797. );
  1798. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1799. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1800. }
  1801. /**
  1802. * 废弃
  1803. */
  1804. function ajaxGetMailItemByIstore() {
  1805. Doo::loadClass ( 'XDeode' );
  1806. $XDeode = new XDeode ( 5 );
  1807. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1808. $isid = $XDeode->decode ( $storeKey );
  1809. if (! is_numeric ( $isid ))
  1810. die ( 'illegal request' );
  1811. Doo::loadModel ( 'invoiceStore' );
  1812. $invoiceStore = new invoiceStore ();
  1813. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid );
  1814. $isDetail ['mailItemsJson'] = json_decode ( $isDetail ['mailItemsJson'], true );
  1815. echo json_encode ( $isDetail ['mailItemsJson'] );
  1816. exit ();
  1817. }
  1818. /**
  1819. * 终止开票
  1820. */
  1821. function invoiceDroppedDo() {
  1822. $droppedIidKey = $this->get_args ( 'droppedIidKey' ) ? $this->get_args ( 'droppedIidKey' ) : '';
  1823. Doo::loadModel ( 'invoice' );
  1824. $invoice = new invoice ();
  1825. Doo::loadModel ( 'invoiceOperationLog' );
  1826. $invoiceOperationLog = new invoiceOperationLog ();
  1827. $iid = $invoice->authcode ( $droppedIidKey );
  1828. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1829. die ( 'illegal request' );
  1830. $item = array (
  1831. 'iid' => $iid,
  1832. 'status' => 4,
  1833. 'updateTime' => date ( "Y-m-d H:i:s" )
  1834. );
  1835. $invoice->setInvoiceByCondition ( $item );
  1836. $item = array (
  1837. 'date' => date ( "Y-m-d H:i:s" ),
  1838. 'operation' => '终止了开票',
  1839. 'status' => 4,
  1840. 'img' => $this->staff [0] ['avatar'],
  1841. 'username' => $this->staff [0] ['username'],
  1842. 'uid' => $this->staff [0] ['sid'],
  1843. 'category' => $this->staff [0] ['category'],
  1844. 'iid' => $iid
  1845. );
  1846. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1847. return "/invoice";
  1848. }
  1849. /**
  1850. * 更新退票的邮寄信息
  1851. */
  1852. function invoiceUntreadMailDo() {
  1853. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  1854. $untreadCompany = $this->get_args ( 'untreadCompany' ) ? $this->get_args ( 'untreadCompany' ) : "";
  1855. $untreadNumber = $this->get_args ( 'untreadNumber' ) ? $this->get_args ( 'untreadNumber' ) : "";
  1856. $untreadItems = $this->get_args ( 'untreadItems' ) ? $this->get_args ( 'untreadItems' ) : "";
  1857. Doo::loadModel ( 'invoice' );
  1858. $invoice = new invoice ();
  1859. $iid = $invoice->authcode ( $untreadIidKey );
  1860. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1861. die ( 'illegal request' );
  1862. $item = array (
  1863. 'iid' => $iid,
  1864. 'untreadCompany' => $untreadCompany,
  1865. 'untreadNumber' => $untreadNumber,
  1866. 'untreadItems' => $untreadItems
  1867. );
  1868. $invoice->setInvoiceByCondition ( $item );
  1869. return "/invoice";
  1870. }
  1871. /**
  1872. * 申请退票 --
  1873. */
  1874. function invoiceUntreadDo() {
  1875. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  1876. $untreadReason = $this->get_args ( 'untreadReason' ) ? $this->get_args ( 'untreadReason' ) : "";
  1877. $untreadPost = $this->get_args ( 'untreadPost' ) ? $this->get_args ( 'untreadPost' ) : "";
  1878. Doo::loadModel ( 'invoice' );
  1879. $invoice = new invoice ();
  1880. Doo::loadModel ( 'invoiceOperationLog' );
  1881. $invoiceOperationLog = new invoiceOperationLog ();
  1882. Doo::loadModel ( 'invoiceReceivables' );
  1883. $invoiceReceivables = new invoiceReceivables ();
  1884. $iid = $invoice->authcode ( $untreadIidKey );
  1885. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1886. die ( 'illegal request' );
  1887. /*
  1888. * 需求变革 有绑定收款也可以退票 $lt = $invoiceReceivables->getInvoiceReceivablesByIid ( $untreadIidKey ); if (! empty ( $lt )) { header ( 'Content-Type:text/html;charset=utf-8' ); die ( '该发票有收款绑定,请先移除!' ); }
  1889. */
  1890. $item = array (
  1891. 'iid' => $iid,
  1892. 'untreadStatus' => 1,
  1893. 'untreadReason' => $untreadReason,
  1894. 'untreadPost' => $untreadPost,
  1895. 'updateTime' => date ( "Y-m-d H:i:s" )
  1896. );
  1897. $invoice->setInvoiceByCondition ( $item );
  1898. $item = array (
  1899. 'date' => date ( "Y-m-d H:i:s" ),
  1900. 'operation' => '申请退票',
  1901. 'status' => 7,
  1902. 'img' => $this->staff [0] ['avatar'],
  1903. 'username' => $this->staff [0] ['username'],
  1904. 'uid' => $this->staff [0] ['sid'],
  1905. 'category' => $this->staff [0] ['category'],
  1906. 'iid' => $iid
  1907. );
  1908. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1909. return "/invoice";
  1910. }
  1911. /**
  1912. * 删除已终止的开票
  1913. */
  1914. function invoiceDelDo() {
  1915. Doo::loadModel ( 'invoice' );
  1916. $invoice = new invoice ();
  1917. Doo::loadModel ( 'invoiceOperationLog' );
  1918. $invoiceOperationLog = new invoiceOperationLog ();
  1919. Doo::loadClass ( 'XDeode' );
  1920. $XDeode = new XDeode ( 5 );
  1921. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  1922. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  1923. $iid = $XDeode->decode ( $iid );
  1924. Doo::loadModel ( 'invoiceStore' );
  1925. $invoiceStore = new invoiceStore ();
  1926. if (! is_numeric ( $iid ))
  1927. die ( 'illegal request' );
  1928. $invoiceDetail = $invoice->getMyInvoice ( $sid, $iid );
  1929. if (empty ( $invoiceDetail ))
  1930. die ( 'illegal request' );
  1931. $item = array (
  1932. 'iid' => $iid,
  1933. 'isDelete' => 1,
  1934. 'updateTime' => date ( "Y-m-d H:i:s" )
  1935. );
  1936. $invoice->setInvoiceByCondition ( $item );
  1937. $item = array (
  1938. 'date' => date ( "Y-m-d H:i:s" ),
  1939. 'operation' => '删除了已终止的发票',
  1940. 'status' => 4,
  1941. 'img' => $this->staff [0] ['avatar'],
  1942. 'username' => $this->staff [0] ['username'],
  1943. 'uid' => $this->staff [0] ['sid'],
  1944. 'category' => $this->staff [0] ['category'],
  1945. 'iid' => $iid
  1946. );
  1947. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1948. // 删除培训班发票仓库里的发票
  1949. $invoiceStore->delInvoiceStoreByIsid ( $invoiceDetail ['isid'] );
  1950. return "/invoice";
  1951. }
  1952. /**
  1953. */
  1954. function invoiceApproval() {
  1955. Doo::loadModel ( 'invoice' );
  1956. $invoice = new invoice ();
  1957. Doo::loadClass ( 'XDeode' );
  1958. $XDeode = new XDeode ( 5 );
  1959. Doo::loadModel ( 'staff' );
  1960. $staff = new staff ();
  1961. $invoiceList = $invoice->find ( array (
  1962. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  1963. 'desc' => 'iid',
  1964. 'limit' => 10,
  1965. 'asArray' => true
  1966. ) );
  1967. foreach ( $invoiceList as $key => $value ) {
  1968. $invoiceList [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1969. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1970. if (! empty ( $lastApprover )) {
  1971. $lastApproverKey = array_keys ( $lastApprover );
  1972. $lastApprover = end ( $lastApprover );
  1973. $staffDetail = $staff->getOne ( array (
  1974. 'where' => 'sid=' . end ( $lastApproverKey ),
  1975. 'asArray' => true
  1976. ) );
  1977. $lastApprover ['username'] = $staffDetail ['username'];
  1978. }
  1979. $invoiceList [$key] ['lastApprover'] = $lastApprover;
  1980. }
  1981. $ilist = $invoice->getInvoiceByProcessStatus ();
  1982. foreach ( $ilist as $key => $value ) {
  1983. $ilist [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1984. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1985. if (! empty ( $lastApprover )) {
  1986. $lastApproverKey = array_keys ( $lastApprover );
  1987. $lastApprover = end ( $lastApprover );
  1988. $staffDetail = $staff->getOne ( array (
  1989. 'where' => 'sid=' . end ( $lastApproverKey ),
  1990. 'asArray' => true
  1991. ) );
  1992. $lastApprover ['username'] = $staffDetail ['username'];
  1993. }
  1994. $ilist [$key] ['lastApprover'] = $lastApprover;
  1995. }
  1996. // print_r($ilist);
  1997. $this->data ['invoiceList'] = $invoiceList;
  1998. $this->data ['ilist'] = $ilist;
  1999. $this->data ['memu'] = "invoice";
  2000. $this->data ['staff'] = $this->staff;
  2001. $this->data ['receiptMemu'] = 'invoiceApproval';
  2002. $this->render ( "/admin/invoiceApproval", $this->data );
  2003. }
  2004. function invoiceDetail() {
  2005. Doo::loadClass ( 'XDeode' );
  2006. $XDeode = new XDeode ( 5 );
  2007. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  2008. $iid = $XDeode->decode ( $iid );
  2009. if (! is_numeric ( $iid ))
  2010. die ( 'illegal request' );
  2011. Doo::loadModel ( 'invoice' );
  2012. $invoice = new invoice ();
  2013. Doo::loadModel ( 'invoiceOperationLog' );
  2014. $invoiceOperationLog = new invoiceOperationLog ();
  2015. $invoiceDetail = $invoice->getOne ( array (
  2016. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'] . ' and iid=' . $iid,
  2017. 'asArray' => true
  2018. ) );
  2019. if (empty ( $invoiceDetail ))
  2020. die ( 'illegal request' );
  2021. if ($invoiceDetail ['settlementType'] == 1) {
  2022. Doo::loadModel ( 'invoiceTraining' );
  2023. $invoiceTraining = new invoiceTraining ();
  2024. $invoiceDetail ['invoiceTraining'] = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceDetail ['trainId'] );
  2025. }
  2026. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  2027. $this->data ['invoiceDetail'] = $invoiceDetail;
  2028. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  2029. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  2030. $this->data ['memu'] = "invoice";
  2031. $this->data ['staff'] = $this->staff;
  2032. $this->data ['receiptMemu'] = 'invoiceApproval';
  2033. $this->render ( "/admin/invoiceApprovalDetail", $this->data );
  2034. }
  2035. /**
  2036. * 对发票进行审批,其中操作有终止,退回,同意动作。操作成功并记录下操作日志
  2037. *
  2038. * @since 1.0.0
  2039. * @var integer iid 开票ID 已加密
  2040. * @var integer status 发票审批状态
  2041. * @var integer opintion 审批发票的意见
  2042. * @return string 如操作成功返回审批首页
  2043. */
  2044. function invoiceApprovalDo() {
  2045. Doo::loadModel ( 'invoice' );
  2046. $invoice = new invoice ();
  2047. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2048. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  2049. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  2050. $divApproval = $this->get_args ( 'divApproval' ) ? $this->get_args ( 'divApproval' ) : "";
  2051. $iid = $invoice->authcode ( $iid );
  2052. if (! is_numeric ( $iid ))
  2053. die ( 'illegal request' );
  2054. // && ! empty ( $opinion )
  2055. if (! empty ( $iid ) && ! empty ( $status )) {
  2056. if (! ($status == 2 || $status == 3 || $status == 4))
  2057. die ( 'illegal request' );
  2058. Doo::loadModel ( 'invoiceOperationLog' );
  2059. $invoiceOperationLog = new invoiceOperationLog ();
  2060. $invoiceDetail = $invoice->getOne ( array (
  2061. 'where' => 'status=1 and iid=' . $iid . ' and pendingApprovals=' . $this->staff [0] ['sid'],
  2062. 'asArray' => true
  2063. ) );
  2064. if (empty ( $invoiceDetail ))
  2065. die ( 'illegal request' );
  2066. $processApprovals = json_decode ( $invoiceDetail ['processApprovals'], true );
  2067. $invoiceManage = json_decode ( $invoiceDetail ['invoiceManage'], true );
  2068. if ($status == 3) {
  2069. $invoice->status = $status;
  2070. $item = array (
  2071. 'operation' => $opinion
  2072. );
  2073. } else {
  2074. if (empty ( $processApprovals )) {
  2075. $processApprovals = array (
  2076. $this->staff [0] ['sid'] => array (
  2077. 'date' => date ( "Y-m-d H:i:s" ),
  2078. 'opinion' => $opinion,
  2079. 'status' => $status
  2080. )
  2081. );
  2082. // var_dump(next($invoiceManage));
  2083. $nextInvoiceManage = next ( $invoiceManage );
  2084. // print_r($nextInvoiceManage);
  2085. if ($status != 4 && $nextInvoiceManage !== false)
  2086. $invoice->pendingApprovals = $nextInvoiceManage [0];
  2087. $invoice->processApprovals = json_encode ( $processApprovals );
  2088. // var_dump($invoice);
  2089. // print_r($invoiceManage);
  2090. } else {
  2091. $processApprovals [$this->staff [0] ['sid']] = array (
  2092. 'date' => date ( "Y-m-d H:i:s" ),
  2093. 'opinion' => $opinion,
  2094. 'status' => $status
  2095. );
  2096. $pendingApprovals = 0;
  2097. foreach ( $invoiceManage as $key => $value ) {
  2098. if ($value [0] == $this->staff [0] ['sid']) {
  2099. if (isset ( $invoiceManage [$key + 1] ))
  2100. $pendingApprovals = $invoiceManage [$key + 1] [0];
  2101. break;
  2102. }
  2103. }
  2104. if ($status != 4 && ! empty ( $pendingApprovals ))
  2105. $invoice->pendingApprovals = $pendingApprovals;
  2106. $invoice->processApprovals = json_encode ( $processApprovals );
  2107. }
  2108. $item = array (
  2109. 'operation' => $opinion
  2110. );
  2111. if (count ( $processApprovals ) == count ( $invoiceManage ) && $status != 4) {
  2112. $invoice->status = $status;
  2113. $invoice->pendingApprovals = 0;
  2114. $invoice->approvalTime = date ( "Y-m-d H:i:s" );
  2115. } elseif ($status == 4) {
  2116. $invoice->status = $status;
  2117. $item = array (
  2118. 'operation' => $opinion
  2119. );
  2120. }
  2121. }
  2122. $invoice->updateTime = date ( "Y-m-d H:i:s" );
  2123. $invoice->update ( array (
  2124. 'where' => 'iid=' . $iid
  2125. ) );
  2126. $item += array (
  2127. 'date' => date ( "Y-m-d H:i:s" ),
  2128. 'img' => $this->staff [0] ['avatar'],
  2129. 'username' => $this->staff [0] ['username'],
  2130. 'uid' => $this->staff [0] ['sid'],
  2131. 'category' => $this->staff [0] ['category'],
  2132. 'status' => $status,
  2133. 'iid' => $iid
  2134. );
  2135. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2136. if (empty ( $divApproval ))
  2137. return '/invoiceApproval';
  2138. else
  2139. return '/invoiceApprovalAchieve/PEND';
  2140. }
  2141. die ( 'illegal request' );
  2142. }
  2143. /**
  2144. * 展示需要打印的发票数据
  2145. *
  2146. * @since 1.0.0
  2147. */
  2148. function invoicePrint() {
  2149. Doo::loadModel ( 'invoice' );
  2150. $invoice = new invoice ();
  2151. Doo::loadClass ( 'XDeode' );
  2152. $XDeode = new XDeode ( 5 );
  2153. Doo::loadModel ( 'staff' );
  2154. $staff = new staff ();
  2155. $toPrint = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0 );
  2156. $printed = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 1 );
  2157. foreach ( $toPrint as $key => $value ) {
  2158. $toPrint [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2159. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2160. if (! empty ( $lastApprover )) {
  2161. $lastApproverKey = array_keys ( $lastApprover );
  2162. $lastApprover = end ( $lastApprover );
  2163. $staffDetail = $staff->getOne ( array (
  2164. 'where' => 'sid=' . end ( $lastApproverKey ),
  2165. 'asArray' => true
  2166. ) );
  2167. $lastApprover ['username'] = $staffDetail ['username'];
  2168. }
  2169. $toPrint [$key] ['lastApprover'] = $lastApprover;
  2170. }
  2171. foreach ( $printed as $key => $value ) {
  2172. $printed [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2173. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2174. if (! empty ( $lastApprover )) {
  2175. $lastApproverKey = array_keys ( $lastApprover );
  2176. $lastApprover = end ( $lastApprover );
  2177. $staffDetail = $staff->getOne ( array (
  2178. 'where' => 'sid=' . end ( $lastApproverKey ),
  2179. 'asArray' => true
  2180. ) );
  2181. $lastApprover ['username'] = $staffDetail ['username'];
  2182. }
  2183. $printed [$key] ['lastApprover'] = $lastApprover;
  2184. }
  2185. $this->data ['printed'] = $printed;
  2186. $this->data ['toPrint'] = $toPrint;
  2187. $this->data ['memu'] = "invoice";
  2188. $this->data ['staff'] = $this->staff;
  2189. $this->data ['receiptMemu'] = 'invoicePrint';
  2190. $this->render ( "/admin/invoicePrint", $this->data );
  2191. }
  2192. /**
  2193. * 展示发票打印的详情页面
  2194. *
  2195. * @since 1.0.0
  2196. */
  2197. function invoicePrintDetail() {
  2198. Doo::loadClass ( 'XDeode' );
  2199. $XDeode = new XDeode ( 5 );
  2200. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  2201. $iid = $XDeode->decode ( $iid );
  2202. if (! is_numeric ( $iid ))
  2203. die ( 'illegal request' );
  2204. Doo::loadModel ( 'invoice' );
  2205. $invoice = new invoice ();
  2206. Doo::loadModel ( 'invoiceOperationLog' );
  2207. $invoiceOperationLog = new invoiceOperationLog ();
  2208. Doo::loadModel ( 'invoicePaper' );
  2209. $invoicePaper = new invoicePaper ();
  2210. $invoiceDetail = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0, $iid );
  2211. if (empty ( $invoiceDetail ))
  2212. die ( 'illegal request' );
  2213. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $invoiceDetail ['invoiceType'] );
  2214. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  2215. if ($invoiceDetail ['settlementType'] == 1) {
  2216. Doo::loadModel ( 'invoiceTraining' );
  2217. $invoiceTraining = new invoiceTraining ();
  2218. $invoiceDetail ['invoiceTraining'] = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceDetail ['trainId'] );
  2219. }
  2220. $this->data ['invoicePaperList'] = $invoicePaperList;
  2221. $this->data ['invoiceDetail'] = $invoiceDetail;
  2222. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  2223. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  2224. $this->data ['memu'] = "invoice";
  2225. $this->data ['staff'] = $this->staff;
  2226. $this->data ['receiptMemu'] = 'invoicePrint';
  2227. $this->render ( "/admin/invoicePrintDetail", $this->data );
  2228. }
  2229. /**
  2230. * 所有待打印 发票
  2231. */
  2232. function invoicePrintStayAchieve() {
  2233. Doo::loadModel ( 'invoice' );
  2234. $invoice = new invoice ();
  2235. Doo::loadClass ( 'XDeode' );
  2236. $XDeode = new XDeode ( 5 );
  2237. Doo::loadModel ( 'staff' );
  2238. $staff = new staff ();
  2239. $MebSea = $this->get_args ( 'MebSea' ) ? urldecode ( $this->get_args ( 'MebSea' ) ) : "";
  2240. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  2241. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  2242. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  2243. Doo::loadModel ( 'invoiceTraining' );
  2244. $invoiceTraining = new invoiceTraining ();
  2245. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  2246. $page_size = 12;
  2247. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2248. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : "ALL";
  2249. // $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : "ALL";
  2250. $get = "/" . $status;
  2251. $con = ' and status=2 ';
  2252. if ($status == 'TOPRINT')
  2253. $con = ' and status=2 and printStatus=0 ';
  2254. elseif ($status == 'PRINTED')
  2255. $con = ' and status=2 and printStatus=1';
  2256. if ($invoiceType == 'ORDINARY')
  2257. $con .= ' and invoiceType=0 ';
  2258. elseif ($invoiceType == 'SPECIAL')
  2259. $con .= ' and invoiceType=1 ';
  2260. if ($invoiceTrain == 'ORDINARY')
  2261. $con .= ' and trainId=0 ';
  2262. elseif ($invoiceTrain == 'TRAIN')
  2263. $con .= ' and trainId!=0 ';
  2264. if ($invoiceTrainName != 'ALL') {
  2265. $trainId = $XDeode->decode ( $invoiceTrainName );
  2266. if (is_numeric ( $trainId ))
  2267. $con .= ' and trainId =' . $trainId;
  2268. }
  2269. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2270. $dateArr = explode ( ':', $date );
  2271. $D1 = '';
  2272. $D2 = '';
  2273. if (! empty ( $date )) {
  2274. $D1 = $dateArr [0];
  2275. $D2 = $dateArr [1];
  2276. }
  2277. if (! empty ( $D1 ) && ! empty ( $D2 ) && ! empty ( $date ))
  2278. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2279. if (! empty ( $MebSea )) {
  2280. $con .= ' and ( invoiceNo like "%' . $MebSea . '%" or invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  2281. }
  2282. $pageinfo ['page'] = array (
  2283. 'previous' => ''
  2284. );
  2285. $get .= "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&invoiceType=" . urlencode ( $invoiceType ) . "&invoiceTrain=" . urlencode ( $invoiceTrain ) . "";
  2286. $sql = " (untreadStatus=0 or untreadStatus=3) and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  2287. $action = "invoicePrintStayAchieve";
  2288. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2289. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2290. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  2291. $this->data ['trainList'] = $trainList;
  2292. $this->data ['invoiceType'] = $invoiceType;
  2293. $this->data ['invoiceTrain'] = $invoiceTrain;
  2294. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  2295. $this->data ['MebSeaEn'] = $MebSea;
  2296. $this->data ['MebSea'] = urlencode ( $MebSea );
  2297. $this->data ['get'] = $get;
  2298. $this->data ['page'] = $pageinfo;
  2299. $this->data ['date'] = $date;
  2300. $this->data ['status'] = $status;
  2301. $this->data ['invoiceType'] = $invoiceType;
  2302. $this->data ['memu'] = "invoice";
  2303. $this->data ['staff'] = $this->staff;
  2304. foreach ( $list as $key => $value ) {
  2305. $list [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2306. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2307. if (! empty ( $lastApprover )) {
  2308. $lastApproverKey = array_keys ( $lastApprover );
  2309. $lastApprover = end ( $lastApprover );
  2310. $staffDetail = $staff->getOne ( array (
  2311. 'where' => 'sid=' . end ( $lastApproverKey ),
  2312. 'asArray' => true
  2313. ) );
  2314. $lastApprover ['username'] = $staffDetail ['username'];
  2315. }
  2316. $list [$key] ['lastApprover'] = $lastApprover;
  2317. }
  2318. $this->data ['receiptMemu'] = 'invoicePrint';
  2319. $this->data ['list'] = $list;
  2320. $this->render ( "/admin/invoicePrintStayAchieve", $this->data );
  2321. }
  2322. /**
  2323. * 填写票号并完成打印
  2324. * @since 1.0.0
  2325. */
  2326. function invoicePrintDo() {
  2327. Doo::loadModel ( 'invoice' );
  2328. $invoice = new invoice ();
  2329. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2330. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  2331. $invoicePrintType = $this->get_args ( 'invoicePrintType' ) ? $this->get_args ( 'invoicePrintType' ) : "";
  2332. $iid = $invoice->authcode ( $iid );
  2333. if (! is_numeric ( $iid ))
  2334. die ( 'illegal request' );
  2335. if (! empty ( $iid ) && ! empty ( $invoiceNo )) {
  2336. Doo::loadModel ( 'invoiceOperationLog' );
  2337. $invoiceOperationLog = new invoiceOperationLog ();
  2338. Doo::loadModel ( 'invoiceStatistics' );
  2339. $invoiceStatistics = new invoiceStatistics ();
  2340. $XDeode = new XDeode ( 5 );
  2341. Doo::loadModel ( 'invoicePaper' );
  2342. $invoicePaper = new invoicePaper ();
  2343. $invoicePrintDetail = $invoice->getInvoiceByPrint ( $iid );
  2344. if (empty ( $invoicePrintDetail ))
  2345. die ( 'illegal request' );
  2346. //
  2347. $ipid = $XDeode->decode ( $invoiceNo );
  2348. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  2349. if (empty ( $paperDetail ))
  2350. die ( 'illegal request' );
  2351. $invoicePaper = new invoicePaper ();
  2352. $item = array (
  2353. 'iid' => $iid,
  2354. 'ipid' => $ipid
  2355. );
  2356. $invoicePaper->setInvoicePaperByCondition ( $item );
  2357. $item = array (
  2358. 'iid' => $iid,
  2359. 'printStatus' => 1,
  2360. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2361. 'printer' => $this->staff [0] ['username'],
  2362. 'printTime' => date ( "Y-m-d H:i:s" ),
  2363. 'invoiceNo' => $paperDetail ['invoiceNo']
  2364. );
  2365. $invoice->setInvoiceByCondition ( $item );
  2366. $item = array (
  2367. 'date' => date ( "Y-m-d H:i:s" ),
  2368. 'operation' => '打印发票号:' . $paperDetail ['invoiceNo'],
  2369. 'status' => 5,
  2370. 'img' => $this->staff [0] ['avatar'],
  2371. 'username' => $this->staff [0] ['username'],
  2372. 'uid' => $this->staff [0] ['sid'],
  2373. 'category' => $this->staff [0] ['category'],
  2374. 'iid' => $iid
  2375. );
  2376. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2377. // 去统计--负票不汇总
  2378. if ($invoicePrintDetail ['untreadStatus'] != 4) {
  2379. $item = array (
  2380. 'date' => date ( "Y-m-d H:i:s" ),
  2381. 'priceClass' => 1,
  2382. 'cid' => $invoicePrintDetail ['cid'],
  2383. 'staff' => $invoicePrintDetail ['sid'],
  2384. 'invoicePrice' => $invoicePrintDetail ['invoicePrice']
  2385. );
  2386. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2387. }
  2388. // 发送通知信息到微信-去除
  2389. // $this->setWXMsg($iid,'PRINT');
  2390. // 发票信息库
  2391. $this->autoUpdateInvoiceInfoBase ( $invoicePrintDetail );
  2392. // 申请人获取微信通知
  2393. Doo::loadModel ( 'staff' );
  2394. $staff = new staff ();
  2395. Doo::loadClass ( 'XDeode' );
  2396. $XDeode = new XDeode ( 5 );
  2397. $username2 = $staff->getOne ( array (
  2398. 'select' => 'wxid',
  2399. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2400. 'asArray' => TRUE
  2401. ) );
  2402. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '完成打印';
  2403. $msg = '';
  2404. $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/' . $XDeode->encode ( $invoicePrintDetail ['iid'] ) . '.html';
  2405. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2406. if (empty ( $invoicePrintType ))
  2407. return "/invoicePrint";
  2408. else
  2409. return "/invoicePrintStayAchieve";
  2410. }
  2411. }
  2412. /**
  2413. * 需要邮寄的发票
  2414. * @since 1.0.0
  2415. */
  2416. function invoicePost() {
  2417. Doo::loadModel ( 'invoice' );
  2418. $invoice = new invoice ();
  2419. Doo::loadModel ( 'express' );
  2420. $express = new express ();
  2421. $invoicePost = $invoice->getPostByInvoice ();
  2422. $invoicePosted = $invoice->getPostByInvoice ( 1 );
  2423. $expressList = $express->getExpressByAll ();
  2424. $invoicePostExpress = "";
  2425. if (isset ( $_COOKIE ["invoicePostExpress"] ))
  2426. $invoicePostExpress = $_COOKIE ["invoicePostExpress"];
  2427. $this->data ['invoicePostExpress'] = $invoicePostExpress;
  2428. $this->data ['expressList'] = $expressList;
  2429. $this->data ['invoicePost'] = $invoicePost;
  2430. $this->data ['invoicePosted'] = $invoicePosted;
  2431. $this->data ['memu'] = "invoice";
  2432. $this->data ['staff'] = $this->staff;
  2433. $this->data ['receiptMemu'] = 'invoicePost';
  2434. $this->render ( "/admin/invoicePost", $this->data );
  2435. }
  2436. /**
  2437. * 添加发票邮寄信息
  2438. */
  2439. function invoiceExpressAddDo() {
  2440. Doo::loadModel ( 'invoice' );
  2441. $invoice = new invoice ();
  2442. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2443. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2444. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2445. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2446. $iid = $iid = $invoice->authcode ( $iid );
  2447. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2448. die ( 'illegal request' );
  2449. $invoicePrintDetail = $invoice->getInvoiceByIid ( $iid );
  2450. setcookie ( 'invoicePostExpress', $expressNumber );
  2451. $item = array (
  2452. 'iid' => $iid,
  2453. 'postStatus' => 1,
  2454. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2455. 'postTime' => date ( "Y-m-d H:i:s" ),
  2456. 'expressCompany' => $expressCompany,
  2457. 'expressNumber' => $expressNumber,
  2458. 'actualItems' => $actualItems,
  2459. 'poster' => $this->staff [0] ['username']
  2460. );
  2461. $invoice->setInvoiceByCondition ( $item );
  2462. // 微信通知-去掉
  2463. // $this->setWXMsg ( $iid );
  2464. Doo::loadModel ( 'staff' );
  2465. $staff = new staff ();
  2466. Doo::loadClass ( 'XDeode' );
  2467. $XDeode = new XDeode ( 5 );
  2468. $username2 = $staff->getOne ( array (
  2469. 'select' => 'wxid',
  2470. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2471. 'asArray' => TRUE
  2472. ) );
  2473. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '已邮寄';
  2474. $expCom = explode ( ":", $invoicePrintDetail ['expressCompany'] );
  2475. if (empty ( $expCom ))
  2476. $expCom [0] = '';
  2477. $msg = $expCom [0] . ':' . $invoicePrintDetail ['expressNumber'] . '';
  2478. $url = 'https://m.kuaidi100.com/result.jsp?nu=' . $invoicePrintDetail ['expressNumber'];
  2479. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2480. return '/invoicePost';
  2481. }
  2482. function invoiceExpressUpdateDo() {
  2483. Doo::loadModel ( 'invoice' );
  2484. $invoice = new invoice ();
  2485. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  2486. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2487. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2488. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2489. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2490. $iid = $invoice->authcode ( $iid );
  2491. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2492. die ( 'illegal request' );
  2493. $item = array (
  2494. 'iid' => $iid,
  2495. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2496. 'expressCompany' => $expressCompany,
  2497. 'expressNumber' => $expressNumber,
  2498. 'actualItems' => $actualItems,
  2499. 'poster' => $this->staff [0] ['username']
  2500. );
  2501. $invoice->setInvoiceByCondition ( $item );
  2502. return $action;
  2503. }
  2504. /**
  2505. * 可退票管理
  2506. */
  2507. function invoiceUntreadIsAchieve() {
  2508. Doo::loadModel ( 'invoice' );
  2509. $invoice = new invoice ();
  2510. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2511. /*
  2512. * Doo::loadClass ( 'XDeode' ); $XDeode = new XDeode ( 5 ); $page_size = 18; $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1; $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : ""; $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ); $dateArr = explode ( ':', $date ); $D1 = ''; $D2 = ''; if (! empty ( $date )) { $D1 = $dateArr [0]; $D2 = $dateArr [1]; } $con = ''; if (! empty ( $D1 ) && ! empty ( $D2 )) $con = ' and bindTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" '; // if ($date == 'MONTHO') // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)'; // elseif ($date == 'MONTHT') // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)'; // elseif ($date == 'MONTHY') // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)'; if (! empty ( $MebSea )) { $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )'; } $pageinfo ['page'] = array ( 'previous' => '' );
  2513. */
  2514. if (empty ( $MebSea )) {
  2515. $con = ' and invoiceNo like "NULL" ';
  2516. } else {
  2517. $con = ' and (invoiceNo like "%' . $MebSea . '%" or invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  2518. }
  2519. // printStatus=1 and
  2520. $sql = " (untreadStatus=0 or untreadStatus=3) and status=2 and sid=" . $this->staff [0] ['sid'] . $con;
  2521. /*
  2522. * $action = "invoiceUntreadIsAchieve"; $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" ); $limit = $pageinfo ['lower'] . ',' . $page_size;
  2523. */
  2524. $limit = '0,20';
  2525. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2526. // print_r($list);
  2527. $this->data ['MebSeaEn'] = $MebSea;
  2528. /*
  2529. * $this->data ['get'] = $get; $this->data ['page'] = $pageinfo; $this->data ['date'] = $date;
  2530. */
  2531. $this->data ['list'] = $list;
  2532. $this->data ['memu'] = "invoice";
  2533. $this->data ['staff'] = $this->staff;
  2534. $this->data ['receiptMemu'] = 'invoice';
  2535. $this->render ( "/admin/invoiceUntreadIsAchieve", $this->data );
  2536. }
  2537. // 已经退票的发票
  2538. function invoiceUntreadED() {
  2539. Doo::loadModel ( 'invoice' );
  2540. $invoice = new invoice ();
  2541. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2542. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "";
  2543. Doo::loadClass ( 'XDeode' );
  2544. $XDeode = new XDeode ( 5 );
  2545. $page_size = 18;
  2546. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2547. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2548. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  2549. $dateArr = explode ( ':', $date );
  2550. $D1 = '';
  2551. $D2 = '';
  2552. if (! empty ( $date )) {
  2553. $D1 = $dateArr [0];
  2554. $D2 = $dateArr [1];
  2555. }
  2556. $con = '';
  2557. if (! empty ( $D1 ) && ! empty ( $D2 )) {
  2558. $con = ' and bindTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2559. }
  2560. // if ($date == 'MONTHO')
  2561. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  2562. // elseif ($date == 'MONTHT')
  2563. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  2564. // elseif ($date == 'MONTHY')
  2565. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  2566. if (! empty ( $MebSea )) {
  2567. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  2568. }
  2569. if ($invoiceType == 'ORDINARY') {
  2570. $con .= ' and invoiceType=0 ';
  2571. } elseif ($invoiceType == 'SPECIAL') {
  2572. $con .= ' and invoiceType=1 ';
  2573. }
  2574. $pageinfo ['page'] = array (
  2575. 'previous' => ''
  2576. );
  2577. // printStatus=1 and
  2578. $sql = " (untreadStatus=2 ) and status=2 and sid=" . $this->staff [0] ['sid'] . $con;
  2579. $action = "invoiceUntreadED";
  2580. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2581. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2582. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2583. // print_r($list);
  2584. $this->data ['MebSeaEn'] = $MebSea;
  2585. $this->data ['get'] = $get;
  2586. $this->data ['page'] = $pageinfo;
  2587. $this->data ['date'] = $date;
  2588. $this->data ['invoiceType'] = $invoiceType;
  2589. $this->data ['list'] = $list;
  2590. $this->data ['memu'] = "invoice";
  2591. $this->data ['staff'] = $this->staff;
  2592. $this->data ['receiptMemu'] = 'invoice';
  2593. $this->render ( "/admin/invoiceUntreadED", $this->data );
  2594. }
  2595. /**
  2596. * 退票处理页面
  2597. */
  2598. function invoiceUntread() {
  2599. Doo::loadModel ( 'invoice' );
  2600. $invoice = new invoice ();
  2601. $untreadInvoice = $invoice->getInvoiceByUntreadStatus ( 1, 0, 50 );
  2602. $establishedInvoice = $invoice->getInvoiceByUntreadStatus ( 2 );
  2603. foreach ( $establishedInvoice as $key => $value ) {
  2604. // months
  2605. $lossDate = strtotime ( "+1 month", strtotime ( $value ['OperationLog'] ['date'] ) );
  2606. $nowDate = strtotime ( 'now' );
  2607. $establishedInvoice [$key] ['lossShow'] = false;
  2608. if ($lossDate < $nowDate)
  2609. $establishedInvoice [$key] ['lossShow'] = true;
  2610. }
  2611. $this->data ['untreadInvoice'] = $untreadInvoice;
  2612. $this->data ['establishedInvoice'] = $establishedInvoice;
  2613. $this->data ['memu'] = "invoice";
  2614. $this->data ['staff'] = $this->staff;
  2615. $this->data ['receiptMemu'] = 'invoiceUntread';
  2616. $this->render ( "/admin/invoiceUntread", $this->data );
  2617. }
  2618. /**
  2619. * 确认收到退回的发票,开票状态为退回 //收款状态解绑,公司统计扣除入账额度
  2620. */
  2621. function invoiceUntreadEstablishedDo() {
  2622. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  2623. Doo::loadModel ( 'invoice' );
  2624. $invoice = new invoice ();
  2625. Doo::loadModel ( 'invoiceOperationLog' );
  2626. $invoiceOperationLog = new invoiceOperationLog ();
  2627. Doo::loadModel ( 'invoiceReceivables' );
  2628. Doo::loadModel ( 'invoiceStatistics' );
  2629. $iid = $invoice->authcode ( $untreadIidKey );
  2630. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2631. die ( 'illegal request' );
  2632. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  2633. if ($invoiceDetails ['untreadStatus'] != 1)
  2634. die ( 'illegal request' );
  2635. $item = array (
  2636. 'iid' => $iid,
  2637. // 'irid'=>'',
  2638. 'untreadStatus' => 2,
  2639. 'updateTime' => date ( "Y-m-d H:i:s" )
  2640. );
  2641. $invoice->setInvoiceByCondition ( $item );
  2642. $item = array (
  2643. 'date' => date ( "Y-m-d H:i:s" ),
  2644. 'operation' => '已确认退票',
  2645. 'status' => 6,
  2646. 'img' => $this->staff [0] ['avatar'],
  2647. 'username' => $this->staff [0] ['username'],
  2648. 'uid' => $this->staff [0] ['sid'],
  2649. 'category' => $this->staff [0] ['category'],
  2650. 'iid' => $iid
  2651. );
  2652. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2653. // 收款解绑以及入账扣除 收款扣除
  2654. if (! empty ( $invoiceDetails ['irid'] )) {
  2655. $iridList = explode ( ',', $invoiceDetails ['irid'] );
  2656. foreach ( $iridList as $value ) {
  2657. $invoiceReceivables = new invoiceReceivables ();
  2658. $irDetails = $invoiceReceivables->getOne ( array (
  2659. 'where' => " irid=" . $value . ' and bindStatus=1',
  2660. 'asArray' => TRUE
  2661. ) );
  2662. $item = array (
  2663. 'irid' => $value,
  2664. 'bindStatus' => 0,
  2665. 'untreadStatus' => 1,
  2666. 'untreadStaff' => $invoiceDetails ['userName'],
  2667. 'unbundlingTime' => date ( "Y-m-d H:i:s" ),
  2668. 'iid' => 0
  2669. );
  2670. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2671. if (! empty ( $irDetails )) {
  2672. // 扣除入账
  2673. $invoiceStatistics = new invoiceStatistics ();
  2674. $item = array (
  2675. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2676. 'priceClass' => 3,
  2677. 'cid' => $invoiceDetails ['cid'],
  2678. 'staff' => $invoiceDetails ['sid'],
  2679. 'accountPrice' => - $irDetails ['receivablesPrice']
  2680. );
  2681. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2682. // 扣除收款
  2683. $invoiceStatistics = new invoiceStatistics ();
  2684. $item = array (
  2685. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2686. 'priceClass' => 2,
  2687. 'cid' => $invoiceDetails ['cid'],
  2688. 'staff' => $invoiceDetails ['sid'],
  2689. 'irid' => $irDetails ['irid'],
  2690. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  2691. );
  2692. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2693. }
  2694. // 解绑时删除收入流水
  2695. Doo::loadModel ( 'wasteBook' );
  2696. $wasteBook = new wasteBook ();
  2697. $wasteBook->delete ( array (
  2698. 'where' => 'dataID=' . $value . ' and accountType=7',
  2699. 'limit' => 1
  2700. ) );
  2701. }
  2702. }
  2703. return "/invoiceUntread";
  2704. }
  2705. function invoiceUntreadRecallDo() {
  2706. $iidKey = isset ( $this->params ['iidKey'] ) ? $this->params ['iidKey'] : "";
  2707. Doo::loadModel ( 'invoice' );
  2708. $invoice = new invoice ();
  2709. Doo::loadClass ( 'XDeode' );
  2710. $XDeode = new XDeode ( 5 );
  2711. Doo::loadModel ( 'invoiceOperationLog' );
  2712. $invoiceOperationLog = new invoiceOperationLog ();
  2713. $iid = $XDeode->decode ( $iidKey );
  2714. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  2715. if (empty ( $invoiceDetail )) {
  2716. die ( 'illegal request-DATANULL' );
  2717. }
  2718. $item = array (
  2719. 'iid' => $iid,
  2720. 'untreadStatus' => 0
  2721. );
  2722. $invoice->setInvoiceByCondition ( $item );
  2723. $item = array (
  2724. 'date' => date ( "Y-m-d H:i:s" ),
  2725. 'operation' => '撤回申请退票',
  2726. 'status' => 13,
  2727. 'img' => $this->staff [0] ['avatar'],
  2728. 'username' => $this->staff [0] ['username'],
  2729. 'uid' => $this->staff [0] ['sid'],
  2730. 'category' => $this->staff [0] ['category'],
  2731. 'iid' => $iid
  2732. );
  2733. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2734. return "/invoiceUntread";
  2735. }
  2736. /**
  2737. * 建立负票,关联原来发票
  2738. */
  2739. function invoiceLossDo() {
  2740. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2741. if (! empty ( $iidKey )) {
  2742. Doo::loadClass ( 'XDeode' );
  2743. $XDeode = new XDeode ( 5 );
  2744. Doo::loadModel ( 'invoice' );
  2745. $invoice = new invoice ();
  2746. Doo::loadModel ( 'invoiceOperationLog' );
  2747. $invoiceOperationLog = new invoiceOperationLog ();
  2748. $iidKey = $XDeode->decode ( $iidKey );
  2749. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  2750. // 拷贝插入一条发票数据
  2751. $iid = $invoice->setInvoiceLoss ( $iidKey );
  2752. // 更新负票
  2753. $invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  2754. $invoice = new invoice ();
  2755. $item = array (
  2756. 'iid' => $iid,
  2757. 'sid' => $this->staff [0] ['sid'],
  2758. 'userName' => $this->staff [0] ['username'],
  2759. 'cid' => $this->staff [0] ['cid'],
  2760. 'categoryName' => $this->staff [0] ['category'],
  2761. 'invoiceQuantity' => - $invoiceDetail ['invoiceQuantity'],
  2762. 'invoicePrice' => - $invoiceDetail ['invoicePrice'],
  2763. 'invoiceSerial' => $invoiceSerial,
  2764. 'invoiceNo' => '',
  2765. 'printStatus' => 0,
  2766. 'untreadStatus' => 4,
  2767. // 关联发票号
  2768. 'lossIid' => $invoiceDetail ['iid']
  2769. );
  2770. $invoice->setInvoiceByCondition ( $item );
  2771. // 更新原发票
  2772. $invoice = new invoice ();
  2773. $item = array (
  2774. 'iid' => $invoiceDetail ['iid'],
  2775. 'lossIid' => $iid
  2776. );
  2777. $invoice->setInvoiceByCondition ( $item );
  2778. // 操作日志
  2779. $item = array (
  2780. 'date' => date ( "Y-m-d H:i:s" ),
  2781. 'operation' => "创建负票" . $invoiceSerial,
  2782. 'status' => 12,
  2783. 'img' => $this->staff [0] ['avatar'],
  2784. 'username' => $this->staff [0] ['username'],
  2785. 'uid' => $this->staff [0] ['sid'],
  2786. 'category' => $this->staff [0] ['category'],
  2787. 'iid' => $iid
  2788. );
  2789. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2790. // print_r($invoiceDetail);
  2791. // echo $iid;die;
  2792. }
  2793. return '/invoiceUntread';
  2794. }
  2795. /**
  2796. * 上传银行到账 收款文件
  2797. */
  2798. function invoiceReceivablesBankUpload() {
  2799. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  2800. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  2801. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  2802. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  2803. header ( "HTTP/1.1 500 Internal Server Error" );
  2804. echo "POST exceeded maximum allowed size.";
  2805. exit ( 0 );
  2806. }
  2807. // Settings
  2808. $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)
  2809. $upload_name = "Filedata";
  2810. $file_name = "";
  2811. $nk = time ();
  2812. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  2813. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  2814. echo "文件无法保存.";
  2815. exit ( 0 );
  2816. }
  2817. echo json_encode ( array (
  2818. 'filename' => $file_name,
  2819. 'id' => $nk
  2820. ) );
  2821. exit ( 0 );
  2822. }
  2823. /**
  2824. * 解析银行到账收款execl并导入库中
  2825. */
  2826. function invoiceReceivablesImport() {
  2827. $path = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  2828. if ($path != "") {
  2829. Doo::loadModel ( 'invoiceReceivables' );
  2830. $invoiceReceivables = new invoiceReceivables ();
  2831. Doo::loadClass ( 'invoice.func' );
  2832. Doo::loadModel ( 'invoiceROLog' );
  2833. $invoiceROLog = new invoiceROLog ();
  2834. Doo::loadModel ( 'invoiceStatistics' );
  2835. $invoiceStatistics = new invoiceStatistics ();
  2836. $exlArray = formatExcelToArrayBank ( DOO::conf ()->SITE_PATH . "upload/invoiceReceivablesBank/" . $path );
  2837. $bankBatchNumber = 'BBN_' . time ();
  2838. Doo::db ()->beginTransaction ();
  2839. // 批量存储收款--由于必须获得收款ID,
  2840. $sql = 'INSERT INTO CLD_invoiceReceivables (OriginalPrice,receivablesPrice, receivablesMessage,receivablesSerial,receivablesBank,receivablesDate,inputStaff,date,receivablesCategory,receivablesStaff,bankBatchNumber,recepitTitleMark)
  2841. VALUES ';
  2842. $date = date ( "Y-m-d" );
  2843. $receivablesList = array ();
  2844. foreach ( $exlArray as $key => $value ) {
  2845. $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"] . '")';
  2846. array_push ( $receivablesList, $receivablesSql );
  2847. }
  2848. $sql = $sql . implode ( ',', $receivablesList );
  2849. // echo $sql;
  2850. Doo::db ()->query ( $sql );
  2851. // 批量存储收款统计
  2852. // 获得刚刚导入数据的irid组-缺少办事处和人员
  2853. $iridList = $invoiceReceivables->getInvoiceReceivablesByBBN ( $bankBatchNumber );
  2854. // 没有irid 回滚所有操作
  2855. if (empty ( $iridList )) {
  2856. Doo::db ()->rollBack ();
  2857. header ( 'Content-Type:text/html;charset=utf-8' );
  2858. die ( '文档或数据不正确,请重新<a href="/invoiceReceivables">上传</a>.' );
  2859. }
  2860. $sql = 'INSERT INTO CLD_invoiceStatistics (date, priceClass,irid,receivablesPrice)
  2861. VALUES ';
  2862. $statisticsList = array ();
  2863. foreach ( $iridList as $value ) {
  2864. $statisticsSql = '("' . $date . '",2,' . $value ['irid'] . ',' . $value ["receivablesPrice"] . ')';
  2865. array_push ( $statisticsList, $statisticsSql );
  2866. }
  2867. $sql = $sql . implode ( ',', $statisticsList );
  2868. Doo::db ()->query ( $sql );
  2869. // 批量存储操作日志
  2870. $sql = 'INSERT INTO CLD_invoiceROLog (operation, date,status,img, username,uid,category,irid)
  2871. VALUES ';
  2872. $ROLogList = array ();
  2873. foreach ( $iridList as $value ) {
  2874. $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'] . '")';
  2875. array_push ( $ROLogList, $ROLogSql );
  2876. }
  2877. $sql = $sql . implode ( ',', $ROLogList );
  2878. Doo::db ()->query ( $sql );
  2879. // 批量写入流水
  2880. $sql = 'INSERT INTO CLD_wasteBook (dataID, expensesType,accountType,accountPriceShow, accountPrice,accountBank,category,cid,name,sid,inputDate)
  2881. VALUES ';
  2882. $wasteBookList = array ();
  2883. foreach ( $iridList as $value ) {
  2884. $accountBank = '';
  2885. if ($value ['receivablesBank'] == '纵横广发') {
  2886. $accountBank = 'CGBDeposit';
  2887. } elseif ($value ['receivablesBank'] == '纵横工行') {
  2888. $accountBank = 'ICBCDeposit';
  2889. } elseif ($value ['receivablesBank'] == '华润银行') {
  2890. $accountBank = 'HUADeposit';
  2891. } elseif ($value ['receivablesBank'] == '个人广发') {
  2892. $accountBank = 'PersonalDeposit';
  2893. }
  2894. $wasteBookSql = '("' . $value ['irid'] . ' ",1,7,"' . $value ['receivablesPrice'] . '","' . $value ['receivablesPrice'] . '","' . $accountBank . '",
  2895. "' . $this->staff [0] ['category'] . '","' . $this->staff [0] ['cid'] . '","' . $this->staff [0] ['username'] . '","' . $this->staff [0] ['sid'] . '","' . date ( "Y-m-d H:i:s" ) . '")';
  2896. array_push ( $wasteBookList, $wasteBookSql );
  2897. }
  2898. $sql = $sql . implode ( ',', $wasteBookList );
  2899. Doo::db ()->query ( $sql );
  2900. Doo::db ()->commit ();
  2901. return "/invoiceReceivables";
  2902. }
  2903. echo 'no file';
  2904. }
  2905. function invoiceReceivables() {
  2906. $invoiceTC = $this->get_args ( 'invoiceTC' ) ? $this->get_args ( 'invoiceTC' ) : '';
  2907. Doo::loadModel ( 'L_category' );
  2908. $lCategory = new L_category ();
  2909. Doo::loadModel ( 'staff' );
  2910. $staff = new staff ();
  2911. Doo::loadModel ( 'invoiceReceivables' );
  2912. $invoiceReceivables = new invoiceReceivables ();
  2913. Doo::loadModel ( 'invoice' );
  2914. $invoice = new invoice ();
  2915. Doo::loadClass ( 'XDeode' );
  2916. $XDeode = new XDeode ( 5 );
  2917. $category = $lCategory->getCategory ();
  2918. $staffList = $staff->getStaffByCid ( $this->staff [0] ['cid'] );
  2919. $sql = 'bindStatus=1 and iid!=0';
  2920. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByNew ( 4, $sql );
  2921. // 获取未入账发票
  2922. $invoiceUnAccount = $invoice->getInvoiceByUnAccount ( $invoiceTC );
  2923. $invoiceExistAccount = $invoice->getInvoiceByUnAccount ( '', true );
  2924. foreach ( $invoiceUnAccount as $key => $value ) {
  2925. $invoiceUnAccount [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2926. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2927. if (! empty ( $lastApprover )) {
  2928. $lastApproverKey = array_keys ( $lastApprover );
  2929. $lastApprover = end ( $lastApprover );
  2930. $staffDetail = $staff->getOne ( array (
  2931. 'where' => 'sid=' . end ( $lastApproverKey ),
  2932. 'asArray' => true
  2933. ) );
  2934. $lastApprover ['username'] = $staffDetail ['username'];
  2935. }
  2936. $invoiceUnAccount [$key] ['lastApprover'] = $lastApprover;
  2937. }
  2938. foreach ( $invoiceExistAccount as $key => $value ) {
  2939. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  2940. if (empty ( $irList ))
  2941. $irList [0] ['sumPrice'] = 0;
  2942. $balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  2943. $invoiceExistAccount [$key] ['existAccount'] = $irList [0] ['sumPrice'];
  2944. $invoiceExistAccount [$key] ['balance'] = $balance;
  2945. }
  2946. $receivablesInput = $invoiceReceivables->getInvoiceReceivablesByInput ();
  2947. $halfList = $invoiceReceivables->getInvoiceReceivablesByHalf ();
  2948. $this->data ['halfList'] = $halfList;
  2949. $this->data ['halfCount'] = count ( $halfList );
  2950. // print_r($receivablesList);
  2951. $this->data ['receivablesDate'] = date ( "Y-m-d" );
  2952. $this->data ['ieaCount'] = count ( $invoiceExistAccount );
  2953. $this->data ['invoiceExistAccount'] = $invoiceExistAccount;
  2954. $this->data ['receivablesInput'] = $receivablesInput;
  2955. $this->data ['year'] = date ( 'Y' );
  2956. $this->data ['invoiceUnAccount'] = $invoiceUnAccount;
  2957. $this->data ['receivablesList'] = $receivablesList;
  2958. $this->data ['staffList'] = $staffList;
  2959. $this->data ['category'] = $category;
  2960. $this->data ['memu'] = "invoice";
  2961. $this->data ['staff'] = $this->staff;
  2962. $this->data ['receiptMemu'] = 'invoiceReceivables';
  2963. $this->render ( "/admin/invoiceReceivables", $this->data );
  2964. }
  2965. /**
  2966. * 设置收款认领地区
  2967. */
  2968. function setInvoiceReceivablesClaim() {
  2969. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  2970. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  2971. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  2972. if (! empty ( $iridKey ) && ! empty ( $receivablesCategory )) {
  2973. Doo::loadModel ( 'invoiceReceivables' );
  2974. $invoiceReceivables = new invoiceReceivables ();
  2975. Doo::loadClass ( 'XDeode' );
  2976. $XDeode = new XDeode ( 5 );
  2977. Doo::loadModel ( 'invoiceROLog' );
  2978. $invoiceROLog = new invoiceROLog ();
  2979. $irid = $XDeode->decode ( $iridKey );
  2980. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  2981. if (empty ( $irDetail ))
  2982. die ( 'illegal request' );
  2983. $item = array (
  2984. 'irid' => $irid,
  2985. 'receivablesCategory' => $receivablesCategory
  2986. );
  2987. if ($receivablesCategory != 'PUBLIC') {
  2988. $item += array (
  2989. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  2990. 'inputType' => 1
  2991. );
  2992. }
  2993. $invoiceReceivables = new invoiceReceivables ();
  2994. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2995. // 收款操作日志
  2996. $item = array (
  2997. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 ",
  2998. 'date' => date ( "Y-m-d" ),
  2999. 'status' => 1,
  3000. 'img' => $this->staff [0] ['avatar'],
  3001. 'username' => $this->staff [0] ['username'],
  3002. 'uid' => $this->staff [0] ['sid'],
  3003. 'category' => $this->staff [0] ['category'],
  3004. 'irid' => $irid
  3005. );
  3006. $invoiceROLog->setInvoiceROLog ( $item );
  3007. if (empty ( $action ))
  3008. return '/invoiceReceivables';
  3009. else
  3010. return "/invoiceReceivablesAS";
  3011. }
  3012. die ( 'illegal request' );
  3013. }
  3014. /**
  3015. * 新添加收款直接入账发票
  3016. */
  3017. function invoiceCompareClaimPrice() {
  3018. // 收款录入
  3019. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  3020. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3021. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3022. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3023. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3024. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $iidKey )) {
  3025. Doo::loadModel ( 'invoiceReceivables' );
  3026. $invoiceReceivables = new invoiceReceivables ();
  3027. Doo::loadModel ( 'invoiceROLog' );
  3028. $invoiceROLog = new invoiceROLog ();
  3029. Doo::loadModel ( 'invoiceStatistics' );
  3030. Doo::loadModel ( 'invoice' );
  3031. $invoice = new invoice ();
  3032. Doo::loadClass ( 'XDeode' );
  3033. $XDeode = new XDeode ( 5 );
  3034. Doo::loadModel ( 'invoiceOperationLog' );
  3035. $invoiceOperationLog = new invoiceOperationLog ();
  3036. $iidKey = $XDeode->decode ( $iidKey );
  3037. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  3038. if (! ($invoiceDetail ['status'] == 2 && $invoiceDetail ['printStatus'] == 1 && $invoiceDetail ['untreadStatus'] == 0))
  3039. die ( 'illegal request' );
  3040. $receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  3041. // 收款录入 并绑定发票
  3042. Doo::db ()->beginTransaction ();
  3043. $bindStatus = 0;
  3044. if ($receivablesPrice <= $invoiceDetail ['invoicePrice'])
  3045. $bindStatus = 1;
  3046. $titleMark = $invoiceDetail ['invoiceTitle'];
  3047. if (! empty ( $invoiceDetail ['invoiceCompany'] ))
  3048. $titleMark = $invoiceDetail ['invoiceCompany'];
  3049. $item = array (
  3050. 'recepitTitleMark' => $titleMark,
  3051. 'bindStatus' => $bindStatus,
  3052. 'iid' => $invoiceDetail ['iid'],
  3053. 'bindPrice' => $invoiceDetail ['invoicePrice'],
  3054. 'bindDate' => date ( "Y-m-d H:i:s" ),
  3055. 'receivablesPrice' => $receivablesPrice,
  3056. 'OriginalPrice' => $receivablesPrice,
  3057. 'receivablesMessage' => $receivablesMessage,
  3058. 'receivablesSerial' => $receivablesSerial,
  3059. 'receivablesBank' => $receivablesBank,
  3060. 'receivablesDate' => $receivablesDate,
  3061. 'inputStaff' => $this->staff [0] ['username'],
  3062. 'accountClerk' => $this->staff [0] ['username'],
  3063. 'date' => date ( "Y-m-d" ),
  3064. 'receivablesCategory' => $invoiceDetail ['cid'] . ':' . $invoiceDetail ['categoryName'],
  3065. 'receivablesStaff' => $invoiceDetail ['sid'] . '-' . $invoiceDetail ['userName'],
  3066. 'confirmTime' => date ( "Y-m-d H:i:s" )
  3067. );
  3068. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  3069. $item = array ();
  3070. // 收款操作日志
  3071. $item = array (
  3072. 'operation' => $this->staff [0] ['username'] . " 转入 " . $invoiceDetail ['userName']
  3073. );
  3074. $item += array (
  3075. 'date' => date ( "Y-m-d" ),
  3076. 'status' => 1,
  3077. 'img' => $this->staff [0] ['avatar'],
  3078. 'username' => $this->staff [0] ['username'],
  3079. 'uid' => $this->staff [0] ['sid'],
  3080. 'category' => $this->staff [0] ['category'],
  3081. 'irid' => $irid
  3082. );
  3083. $invoiceROLog->setInvoiceROLog ( $item );
  3084. // 收款统计
  3085. $invoiceStatistics = new invoiceStatistics ();
  3086. $item = array (
  3087. 'date' => $receivablesDate,
  3088. 'priceClass' => 2,
  3089. 'irid' => $irid,
  3090. 'cid' => $invoiceDetail ['cid'],
  3091. 'staff' => $invoiceDetail ['sid'],
  3092. 'receivablesPrice' => $receivablesPrice
  3093. );
  3094. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3095. // 收款 入 发票
  3096. $detail = $invoiceDetail;
  3097. $iridString = "";
  3098. if (empty ( $detail ['irid'] ))
  3099. $iridString = $irid;
  3100. else
  3101. $iridString = $detail ['irid'] . ',' . $irid;
  3102. $item = array (
  3103. 'irid' => $iridString,
  3104. 'bindTime' => date ( "Y-m-d H:i:s" ),
  3105. 'updateTime' => date ( "Y-m-d H:i:s" ),
  3106. 'iid' => $detail ['iid']
  3107. );
  3108. $invoiceReceivables = new invoiceReceivables ();
  3109. $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  3110. if ($detail ['invoicePrice'] <= $sum)
  3111. $item += array (
  3112. 'untreadStatus' => 3
  3113. );
  3114. $invoice->setInvoiceByCondition ( $item );
  3115. // 操作日志
  3116. $item = array (
  3117. 'date' => date ( "Y-m-d H:i:s" ),
  3118. 'operation' => "收款入账" . $receivablesSerial . "到发票" . $detail ['invoiceSerial'],
  3119. 'status' => 8,
  3120. 'img' => $this->staff [0] ['avatar'],
  3121. 'username' => $this->staff [0] ['username'],
  3122. 'uid' => $this->staff [0] ['sid'],
  3123. 'category' => $this->staff [0] ['category'],
  3124. 'iid' => $detail ['iid']
  3125. );
  3126. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3127. // 入账汇总
  3128. $invoiceStatistics = new invoiceStatistics ();
  3129. // $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $iridString );
  3130. // $accountPrice = 0;
  3131. // foreach ( $list as $key => $value ) {
  3132. // $accountPrice += $value ['receivablesPrice'];
  3133. // }
  3134. $item = array (
  3135. 'date' => $receivablesDate,
  3136. 'priceClass' => 3,
  3137. 'cid' => $invoiceDetail ['cid'],
  3138. 'staff' => $invoiceDetail ['sid'],
  3139. 'accountPrice' => $receivablesPrice
  3140. );
  3141. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3142. // 公司流水记录
  3143. Doo::loadModel ( 'wasteBook' );
  3144. $wasteBook = new wasteBook ();
  3145. $abDetail = $wasteBook->getAccountBookByAid ( 2, 7, $irid );
  3146. $accountBank = '';
  3147. if ($receivablesBank == '纵横广发') {
  3148. $accountBank = 'CGBDeposit';
  3149. } elseif ($receivablesBank == '纵横工行') {
  3150. $accountBank = 'ICBCDeposit';
  3151. } elseif ($receivablesBank == '华润银行') {
  3152. $accountBank = 'HUADeposit';
  3153. } elseif ($receivablesBank == '个人广发') {
  3154. $accountBank = 'PersonalDeposit';
  3155. }
  3156. if (empty ( $abDetail )) {
  3157. $item = array (
  3158. 'dataID' => $irid,
  3159. 'expensesType' => 1,
  3160. 'accountType' => 7,
  3161. 'accountPrice' => $receivablesPrice,
  3162. 'accountPriceShow' => $receivablesPrice,
  3163. 'accountBank' => $accountBank,
  3164. 'category' => $this->staff [0] ['category'],
  3165. 'cid' => $this->staff [0] ['cid'],
  3166. 'name' => $this->staff [0] ['username'],
  3167. 'sid' => $this->staff [0] ['sid'],
  3168. 'inputDate' => date ( "Y-m-d H:i:s" )
  3169. );
  3170. $wasteBook->setAccountBookStatistics ( $item );
  3171. }
  3172. Doo::db ()->commit ();
  3173. }
  3174. return '/invoiceReceivables';
  3175. }
  3176. /**
  3177. * 录入收款数据
  3178. * @return string
  3179. */
  3180. function invoiceReceivablesDo() {
  3181. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3182. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3183. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3184. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3185. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3186. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  3187. Doo::loadModel ( 'invoiceReceivables' );
  3188. $invoiceReceivables = new invoiceReceivables ();
  3189. Doo::loadModel ( 'invoiceROLog' );
  3190. $invoiceROLog = new invoiceROLog ();
  3191. Doo::loadModel ( 'invoiceStatistics' );
  3192. $invoiceStatistics = new invoiceStatistics ();
  3193. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $receivablesCategory ) && ! empty ( $receivablesStaff )) {
  3194. $item = array (
  3195. 'receivablesPrice' => $receivablesPrice,
  3196. 'OriginalPrice' => $receivablesPrice,
  3197. 'receivablesMessage' => $receivablesMessage,
  3198. 'receivablesSerial' => "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  3199. 'receivablesBank' => $receivablesBank,
  3200. 'receivablesDate' => $receivablesDate,
  3201. 'inputStaff' => $this->staff [0] ['username'],
  3202. 'date' => date ( "Y-m-d" ),
  3203. 'receivablesCategory' => $receivablesCategory,
  3204. 'receivablesStaff' => $receivablesStaff
  3205. );
  3206. if ($receivablesCategory != 'PUBLIC') {
  3207. $item += array (
  3208. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3209. 'inputType' => 1
  3210. );
  3211. }
  3212. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  3213. $item = array ();
  3214. // 收款操作日志
  3215. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3216. $item = array (
  3217. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  3218. );
  3219. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3220. $item = array (
  3221. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  3222. );
  3223. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3224. $receivablesStaff = explode ( '-', $receivablesStaff );
  3225. $item = array (
  3226. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  3227. );
  3228. }
  3229. $item += array (
  3230. 'date' => date ( "Y-m-d" ),
  3231. 'status' => 1,
  3232. 'img' => $this->staff [0] ['avatar'],
  3233. 'username' => $this->staff [0] ['username'],
  3234. 'uid' => $this->staff [0] ['sid'],
  3235. 'category' => $this->staff [0] ['category'],
  3236. 'irid' => $irid
  3237. );
  3238. $invoiceROLog->setInvoiceROLog ( $item );
  3239. $item = array (
  3240. 'date' => $receivablesDate,
  3241. 'priceClass' => 2,
  3242. 'irid' => $irid,
  3243. 'receivablesPrice' => $receivablesPrice
  3244. );
  3245. if ($receivablesCategory != 'PUBLIC') {
  3246. $receivablesCategory = explode ( ":", $receivablesCategory );
  3247. $item += array (
  3248. 'cid' => $receivablesCategory [0]
  3249. );
  3250. }
  3251. if ($receivablesStaff2 != 'PUBLIC') {
  3252. $receivablesStaff = explode ( "-", $receivablesStaff2 );
  3253. $item += array (
  3254. 'staff' => $receivablesStaff [0]
  3255. );
  3256. }
  3257. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3258. $toparty = $this->getWxidByCategory ( $receivablesCategory [1] );
  3259. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  3260. $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  3261. if ($toparty != 0)
  3262. $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  3263. // 公司流水记录
  3264. Doo::loadModel ( 'wasteBook' );
  3265. $wasteBook = new wasteBook ();
  3266. $abDetail = $wasteBook->getAccountBookByAid ( 1, 7, $irid );
  3267. $accountBank = '';
  3268. if ($receivablesBank == '纵横广发') {
  3269. $accountBank = 'CGBDeposit';
  3270. } elseif ($receivablesBank == '纵横工行') {
  3271. $accountBank = 'ICBCDeposit';
  3272. } elseif ($receivablesBank == '华润银行') {
  3273. $accountBank = 'HUADeposit';
  3274. } elseif ($receivablesBank == '个人广发') {
  3275. $accountBank = 'PersonalDeposit';
  3276. }
  3277. $item = array (
  3278. 'dataID' => $irid,
  3279. 'expensesType' => 1,
  3280. 'accountType' => 7,
  3281. 'accountPriceShow' => $receivablesPrice,
  3282. 'accountPrice' => $receivablesPrice,
  3283. 'accountBank' => $accountBank,
  3284. 'category' => $this->staff [0] ['category'],
  3285. 'cid' => $this->staff [0] ['cid'],
  3286. 'name' => $this->staff [0] ['username'],
  3287. 'sid' => $this->staff [0] ['sid'],
  3288. 'inputDate' => date ( "Y-m-d H:i:s" )
  3289. );
  3290. $wasteBook->setAccountBookStatistics ( $item );
  3291. }
  3292. return "/invoiceReceivables";
  3293. }
  3294. /**
  3295. * 收款认领页面-包括公共认领 办事处认领 最近已认领数据
  3296. */
  3297. function invoiceReceivablesClaim() {
  3298. Doo::loadModel ( 'invoiceReceivables' );
  3299. $invoiceReceivables = new invoiceReceivables ();
  3300. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  3301. $this->data ['receivablesList'] = $receivablesList;
  3302. $this->data ['memu'] = "invoice";
  3303. $this->data ['staff'] = $this->staff;
  3304. $this->data ['receiptMemu'] = 'invoiceReceivablesClaim';
  3305. $this->render ( "/admin/invoiceReceivablesClaim", $this->data );
  3306. }
  3307. function invoiceReceivablesTitleMarkSet() {
  3308. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  3309. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  3310. if (empty ( $iridKey ) || empty ( $recepitTitleMark ))
  3311. die ( 'illegal request' );
  3312. Doo::loadModel ( 'invoiceReceivables' );
  3313. $invoiceReceivables = new invoiceReceivables ();
  3314. Doo::loadClass ( 'XDeode' );
  3315. $XDeode = new XDeode ( 5 );
  3316. $irid = $XDeode->decode ( $iridKey );
  3317. if (! is_numeric ( $irid ))
  3318. die ( 'illegal request' );
  3319. $invoiceReceivables->recepitTitleMark = $recepitTitleMark;
  3320. $invoiceReceivables->update ( array (
  3321. 'where' => 'irid = ' . $irid
  3322. ) );
  3323. return '/invoiceReceivablesClaim';
  3324. }
  3325. /**
  3326. * 更新收款相关数据
  3327. */
  3328. function invoiceReceivablesUpdateClaim() {
  3329. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3330. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3331. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3332. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3333. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3334. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  3335. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  3336. if (empty ( $claimKey ))
  3337. die ( 'illegal request' );
  3338. Doo::loadModel ( 'invoiceReceivables' );
  3339. $invoiceReceivables = new invoiceReceivables ();
  3340. Doo::loadModel ( 'invoiceROLog' );
  3341. $invoiceROLog = new invoiceROLog ();
  3342. $con = ' and iid=0 and bindStatus=0'; // and receivablesCategory!="PUBLIC" and receivablesStaff!="PUBLIC"
  3343. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  3344. if (empty ( $detail ))
  3345. die ( 'illegal request' );
  3346. $invoiceReceivables = new invoiceReceivables ();
  3347. $item = array (
  3348. 'irid' => $detail ['irid']
  3349. );
  3350. if ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3351. $item += array (
  3352. 'confirmTime' => date ( "Y-m-d H:i:s" )
  3353. );
  3354. }
  3355. if (! empty ( $receivablesCategory ))
  3356. $item += array (
  3357. 'receivablesCategory' => $receivablesCategory
  3358. );
  3359. if (! empty ( $receivablesStaff ))
  3360. $item += array (
  3361. 'receivablesStaff' => $receivablesStaff
  3362. );
  3363. if (! empty ( $receivablesPrice ))
  3364. $item += array (
  3365. 'receivablesPrice' => $receivablesPrice
  3366. );
  3367. if (! empty ( $receivablesMessage ))
  3368. $item += array (
  3369. 'receivablesMessage' => $receivablesMessage
  3370. );
  3371. if (! empty ( $receivablesBank ))
  3372. $item += array (
  3373. 'receivablesBank' => $receivablesBank
  3374. );
  3375. if (! empty ( $receivablesDate ))
  3376. $item += array (
  3377. 'receivablesDate' => $receivablesDate
  3378. );
  3379. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3380. // 收款操作日志
  3381. $item = array ();
  3382. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3383. $item = array (
  3384. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  3385. );
  3386. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3387. $item = array (
  3388. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  3389. );
  3390. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3391. $receivablesStaff = explode ( '-', $receivablesStaff );
  3392. $item = array (
  3393. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  3394. );
  3395. }
  3396. $item += array (
  3397. 'date' => date ( "Y-m-d" ),
  3398. 'status' => 1,
  3399. 'img' => $this->staff [0] ['avatar'],
  3400. 'username' => $this->staff [0] ['username'],
  3401. 'uid' => $this->staff [0] ['sid'],
  3402. 'category' => $this->staff [0] ['category'],
  3403. 'irid' => $detail ['irid']
  3404. );
  3405. $invoiceROLog->setInvoiceROLog ( $item );
  3406. return '/invoiceReceivablesAS';
  3407. }
  3408. function invoiceReceivablesDelete() {
  3409. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  3410. $skll = $this->get_args ( 'skll' ) ? $this->get_args ( 'skll' ) : "";
  3411. if ($skll != '删除到款')
  3412. die ( 'illegal request' );
  3413. if (empty ( $claimKey ))
  3414. die ( 'illegal request' );
  3415. Doo::loadModel ( 'invoiceReceivables' );
  3416. $invoiceReceivables = new invoiceReceivables ();
  3417. $con = ' and bindStatus=0 ';
  3418. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  3419. if (empty ( $detail ))
  3420. die ( 'illegal request' );
  3421. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  3422. // 扣除收款汇总信息 汇总
  3423. Doo::loadModel ( 'invoiceStatistics' );
  3424. $invoiceStatistics = new invoiceStatistics ();
  3425. $item = array (
  3426. 'date' => $detail ['receivablesDate'],
  3427. 'priceClass' => 2,
  3428. 'irid' => $detail ['irid'],
  3429. 'receivablesPrice' => - $detail ['receivablesPrice']
  3430. );
  3431. if ($detail ['receivablesCategory'] != 'PUBLIC') {
  3432. $receivablesCategory = explode ( ":", $detail ['receivablesCategory'] );
  3433. $item += array (
  3434. 'cid' => $receivablesCategory [0]
  3435. );
  3436. }
  3437. if ($detail ['receivablesStaff'] != 'PUBLIC') {
  3438. $receivablesStaff = explode ( "-", $detail ['receivablesStaff'] );
  3439. $item += array (
  3440. 'staff' => $receivablesStaff [0]
  3441. );
  3442. }
  3443. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3444. // 公司流水-删除时删除流水
  3445. Doo::loadModel ( 'wasteBook' );
  3446. $wasteBook = new wasteBook ();
  3447. $wasteBook->delete ( array (
  3448. 'where' => 'dataID=' . $detail ['irid'] . ' and accountType=7',
  3449. 'limit' => 1
  3450. ) );
  3451. return '/invoiceReceivablesAS';
  3452. }
  3453. /**
  3454. * 管理员录入的收款 ,确认认领到谁的名下.统计收款金额
  3455. */
  3456. function invoiceReceivablesAscription() {
  3457. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  3458. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  3459. Doo::loadModel ( 'invoiceReceivables' );
  3460. $invoiceReceivables = new invoiceReceivables ();
  3461. Doo::loadModel ( 'invoiceROLog' );
  3462. $invoiceROLog = new invoiceROLog ();
  3463. Doo::loadModel ( 'invoiceStatistics' );
  3464. $invoiceStatistics = new invoiceStatistics ();
  3465. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  3466. if (! empty ( $detail ) && $detail ['receivablesStaff'] == 'PUBLIC' && ! empty ( $recepitTitleMark )) {
  3467. $item = array (
  3468. 'irid' => $detail ['irid'],
  3469. 'receivablesCategory' => $this->staff [0] ['cid'] . ":" . $this->staff [0] ['category'],
  3470. 'receivablesStaff' => $this->staff [0] ['sid'] . "-" . $this->staff [0] ['username'],
  3471. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3472. 'recepitTitleMark' => $recepitTitleMark,
  3473. 'source' => 1
  3474. );
  3475. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3476. $item = array (
  3477. 'date' => date ( "Y-m-d" ),
  3478. 'operation' => $this->staff [0] ['username'] . " 认领 ",
  3479. 'status' => 2,
  3480. 'img' => $this->staff [0] ['avatar'],
  3481. 'username' => $this->staff [0] ['username'],
  3482. 'uid' => $this->staff [0] ['sid'],
  3483. 'category' => $this->staff [0] ['category'],
  3484. 'irid' => $irid
  3485. );
  3486. $invoiceROLog->setInvoiceROLog ( $item );
  3487. $item = array (
  3488. 'cid' => $this->staff [0] ['cid'],
  3489. 'staff' => $this->staff [0] ['sid']
  3490. );
  3491. $invoiceStatistics->updateInvoiceStatisticsByIrid ( $item, $detail ['irid'], 2 );
  3492. }
  3493. return "/invoiceReceivablesClaim";
  3494. }
  3495. /**
  3496. */
  3497. function invoiceMyReceivables() {
  3498. Doo::loadModel ( 'invoiceReceivables' );
  3499. $invoiceReceivables = new invoiceReceivables ();
  3500. Doo::loadModel ( 'invoiceStatistics' );
  3501. $invoiceStatistics = new invoiceStatistics ();
  3502. $isMonth = $invoiceStatistics->getStatisticsByMonth ( $this->staff [0] ['sid'] );
  3503. $year = date ( "Y" );
  3504. $tmp_date = date ( "Ym" );
  3505. $tmp_year = substr ( $tmp_date, 0, 4 );
  3506. $tmp_mon = substr ( $tmp_date, 4, 2 );
  3507. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  3508. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  3509. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . ".htm";
  3510. $htm = $this->showCache ( $path );
  3511. $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  3512. $this->data ['isMonth'] = $isMonth;
  3513. $this->data ['htm'] = $htm;
  3514. $this->data ['list'] = $list;
  3515. $this->data ['memu'] = "invoice";
  3516. $this->data ['staff'] = $this->staff;
  3517. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  3518. $this->render ( "/admin/invoiceMyReceivables", $this->data );
  3519. }
  3520. /**
  3521. * 纸票管理
  3522. */
  3523. function invoicePaper() {
  3524. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3525. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3526. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3527. $this->data ['dateString'] = $date;
  3528. $this->data ['status'] = $status;
  3529. $this->data ['invoiceType'] = $invoiceType;
  3530. $this->data ['memu'] = "invoice";
  3531. $this->data ['staff'] = $this->staff;
  3532. $this->data ['receiptMemu'] = 'invoicePaper';
  3533. $this->render ( "/admin/invoicePaper", $this->data );
  3534. }
  3535. /**
  3536. * 获得纸票分页数据
  3537. */
  3538. function ajaxGetinvoicePaperAchieve() {
  3539. Doo::loadModel ( 'invoicePaper' );
  3540. $invoicePaper = new invoicePaper ();
  3541. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3542. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3543. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ORDINARY";
  3544. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3545. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  3546. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  3547. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  3548. $MebSea = $this->get_args ( 'search' );
  3549. $MebSea = $MebSea ['value'];
  3550. $page_size = $length;
  3551. $con = '';
  3552. if ($status == 'ALL')
  3553. $con = ' where 1 ';
  3554. elseif ($status == 'PRINTED')
  3555. $con = ' where a.iid!=0 '; // $con = ' where b.isDelete=0 and a.iid!=0 and b.status=2 and b.untreadStatus=0 ';
  3556. elseif ($status == 'UNPRINT')
  3557. $con = ' where a.iid=0 '; // $con = ' where b.isDelete=0 and a.iid=0 and b.status=2 and b.untreadStatus=0 ';
  3558. elseif ($status == 'TICKET')
  3559. $con = ' where b.isDelete=0 and b.untreadStatus=2';
  3560. if ($invoiceType == 'ORDINARY')
  3561. $con .= ' and a.invoiceType=0 ';
  3562. elseif ($invoiceType == 'SPECIAL')
  3563. $con .= ' and a.invoiceType=1 ';
  3564. $dateArr = explode ( ':', $date );
  3565. $D1 = $dateString = '';
  3566. $D2 = '';
  3567. if (! empty ( $date )) {
  3568. $D1 = $dateArr [0];
  3569. if (isset ( $dateArr [1] ))
  3570. $D2 = $dateArr [1];
  3571. else
  3572. $D2 = '';
  3573. $dateString = $D1 . " : " . $D2;
  3574. }
  3575. if (! empty ( $D1 ) && ! empty ( $D2 ))
  3576. $con .= ' and b.printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  3577. elseif (! empty ( $D1 ) && empty ( $D2 ))
  3578. $con .= ' and b.printTime like "%' . $D1 . '%" ';
  3579. if (! empty ( $MebSea ))
  3580. $con .= ' and ( b.invoiceTitle like "%' . $MebSea . '%" or b.invoiceCompany like "%' . $MebSea . '%" or a.invoiceNo like "%' . $MebSea . '%" )';
  3581. $invoiceTotal = $invoicePaper->getInvoicePaperCount ();
  3582. $sql = ' ' . $con;
  3583. $limit = $page . ',' . $page_size;
  3584. $list = $invoicePaper->getInvoicePaper ( $limit, $sql, 'desc' );
  3585. $paperList = array ();
  3586. foreach ( $list as $key => $value ) {
  3587. $irDetail = array ();
  3588. if ($value ['iid'] == 0)
  3589. array_push ( $irDetail, '<a href="javascript:if(window.confirm(\'确认删除?\'))window.location=\'/invoicePaperDel/' . $value ['ipidKey'] . '\'" >删除</a>' );
  3590. else
  3591. array_push ( $irDetail, '' );
  3592. array_push ( $irDetail, $value ['invoiceCode'] );
  3593. array_push ( $irDetail, $value ['invoiceNo'] );
  3594. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKey'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  3595. if ($value ['invoiceType'] == 1)
  3596. array_push ( $irDetail, $value ['invoiceCompany'] );
  3597. else
  3598. array_push ( $irDetail, $value ['invoiceTitle'] );
  3599. if ($value ['invoiceType'] == 1)
  3600. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  3601. else
  3602. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  3603. array_push ( $irDetail, $value ['invoiceElement'] );
  3604. array_push ( $irDetail, $value ['categoryName'] . '-' . $value ['userName'] );
  3605. array_push ( $irDetail, $value ['printTime'] );
  3606. array_push ( $paperList, $irDetail );
  3607. }
  3608. // $approvalListJson = json_encode ( $approvalList );
  3609. $recordsFiltered = $invoiceTotal;
  3610. echo json_encode ( array (
  3611. "draw" => intval ( $draw ),
  3612. "recordsTotal" => intval ( $invoiceTotal ),
  3613. "recordsFiltered" => intval ( $recordsFiltered ),
  3614. "data" => $paperList
  3615. ), JSON_UNESCAPED_UNICODE );
  3616. }
  3617. function invoicePaperDel() {
  3618. $ipidKey = isset ( $this->params ['ipidKey'] ) ? $this->params ['ipidKey'] : "";
  3619. $XDeode = new XDeode ( 5 );
  3620. $ipid = $XDeode->decode ( $ipidKey );
  3621. if (empty ( $ipid ))
  3622. die ( 'illegal request' );
  3623. Doo::loadModel ( 'invoicePaper' );
  3624. $invoicePaper = new invoicePaper ();
  3625. $invoicePaper->delete ( array (
  3626. 'where' => 'ipid=' . $ipid . ' and iid=0',
  3627. 'limit' => 1
  3628. ) );
  3629. return '/invoicePaper';
  3630. }
  3631. /**
  3632. * 添加纸质发票号
  3633. */
  3634. function invoicePaperAdd() {
  3635. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : '0';
  3636. $invoiceCode = $this->get_args ( 'invoiceCode' ) ? $this->get_args ( 'invoiceCode' ) : "";
  3637. $invoiceNoStart = $this->get_args ( 'invoiceNoStart' ) && is_numeric ( $this->get_args ( 'invoiceNoStart' ) ) ? $this->get_args ( 'invoiceNoStart' ) : 0;
  3638. $invoiceNoTotal = $this->get_args ( 'invoiceNoTotal' ) && is_numeric ( $this->get_args ( 'invoiceNoTotal' ) ) ? $this->get_args ( 'invoiceNoTotal' ) : 0;
  3639. if ($invoiceType != '' && ! empty ( $invoiceCode ) && ! empty ( $invoiceNoStart ) && ! empty ( $invoiceNoTotal )) {
  3640. $sum = $invoiceNoStart + $invoiceNoTotal;
  3641. if (empty ( $sum ))
  3642. die ( 'illegal request' );
  3643. // echo $invoiceNoStart;
  3644. // echo $sum;
  3645. // echo strlen((int)$invoiceNoStart);
  3646. $sumLenght = strlen ( $invoiceNoStart ) - strlen ( ( int ) $invoiceNoStart );
  3647. Doo::db ()->beginTransaction ();
  3648. // 批量存储纸质发票
  3649. $date = date ( "Y-m-d H:i:s" );
  3650. $sql = 'INSERT INTO CLD_invoicePaper (invoiceType, invoiceCode,invoiceNo,date)
  3651. VALUES ';
  3652. $paperList = array ();
  3653. for($invoiceNoStart; $invoiceNoStart <= $sum - 1; $invoiceNoStart ++) {
  3654. // 数字前面自加0
  3655. $INLENGHT = strlen ( ( int ) $invoiceNoStart ) + $sumLenght;
  3656. $var = sprintf ( "%0" . $INLENGHT . "d", $invoiceNoStart );
  3657. $paperSql = '(' . $invoiceType . ',"' . $invoiceCode . '","' . $var . '","' . $date . '")';
  3658. array_push ( $paperList, $paperSql );
  3659. }
  3660. if (empty ( $paperList ))
  3661. die ( 'illegal request' );
  3662. $sql = $sql . implode ( ',', $paperList );
  3663. Doo::db ()->query ( $sql );
  3664. Doo::db ()->commit ();
  3665. return 'invoicePaper';
  3666. }
  3667. die ( 'illegal request' );
  3668. }
  3669. /**
  3670. * 收款绑定发票 ,//一个收款只能绑定一个发票
  3671. */
  3672. function invoiceBindReceivables() {
  3673. $claimKey = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  3674. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  3675. Doo::loadModel ( 'invoice' );
  3676. $invoice = new invoice ();
  3677. Doo::loadModel ( 'invoiceReceivables' );
  3678. $invoiceReceivables = new invoiceReceivables ();
  3679. Doo::loadModel ( 'invoiceOperationLog' );
  3680. $invoiceOperationLog = new invoiceOperationLog ();
  3681. if (empty ( $invoiceKey ) || empty ( $claimKey ))
  3682. die ( 'illegal request' );
  3683. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  3684. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey );
  3685. if (empty ( $detail ) && empty ( $detailM ))
  3686. die ( 'illegal request' );
  3687. if ($detail ['untreadStatus'] == 3)
  3688. die ( 'illegal request' );
  3689. // 修改 绑定状态改为 金额
  3690. $invoiceReceivables = new invoiceReceivables ();
  3691. $invoicePrice = $detail ['invoicePrice'] + $detailM ['bindPrice'];
  3692. if ($detailM ['receivablesPrice'] > $invoicePrice) {
  3693. $item = array (
  3694. 'bindPrice' => $invoicePrice
  3695. );
  3696. } elseif ($detailM ['receivablesPrice'] <= $invoicePrice) {
  3697. $item = array (
  3698. 'bindPrice' => $invoicePrice,
  3699. 'bindStatus' => 1,
  3700. 'bindDate' => date ( "Y-m-d H:i:s" )
  3701. );
  3702. } else {
  3703. die ( 'illegal request' );
  3704. }
  3705. if ($detailM ['iid'] == 0) {
  3706. $item += array (
  3707. 'iid' => $detail ['iid']
  3708. );
  3709. } else {
  3710. $iidExtend = explode ( ',', $detailM ['iidExtend'] );
  3711. array_push ( $iidExtend, $detail ['iid'] );
  3712. $item += array (
  3713. 'iidExtend' => implode ( ',', $iidExtend )
  3714. );
  3715. }
  3716. $titleMark = $detail ['invoiceTitle'];
  3717. if (! empty ( $detail ['invoiceCompany'] ))
  3718. $titleMark = $detail ['invoiceCompany'];
  3719. $item += array (
  3720. 'irid' => $detailM ['irid'],
  3721. 'recepitTitleMark' => $titleMark,
  3722. 'accountClerk' => $this->staff [0] ['username']
  3723. );
  3724. // 如何没有人收款 则自动绑定收款
  3725. if ($detailM ['receivablesCategory'] == 'PUBLIC' || $detailM ['receivablesStaff'] == 'PUBLIC') {
  3726. $item += array (
  3727. 'receivablesCategory' => $detail ['cid'] . ':' . $detail ['categoryName'],
  3728. 'receivablesStaff' => $detail ['sid'] . '-' . $detail ['userName']
  3729. );
  3730. }
  3731. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3732. $iridString = "";
  3733. if (empty ( $detail ['irid'] ))
  3734. $iridString = $detailM ['irid'];
  3735. else
  3736. $iridString = $detail ['irid'] . ',' . $detailM ['irid'];
  3737. $item = array (
  3738. 'iid' => $detail ['iid'],
  3739. 'irid' => $iridString
  3740. );
  3741. $invoiceReceivables = new invoiceReceivables ();
  3742. $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  3743. if ($detail ['invoicePrice'] <= $sum)
  3744. $item += array (
  3745. 'untreadStatus' => 3,
  3746. 'bindTime' => date ( "Y-m-d H:i:s" )
  3747. );
  3748. // print_r($item);
  3749. // echo $sum;die;
  3750. $invoice->setInvoiceByCondition ( $item );
  3751. // 操作日志
  3752. $item = array (
  3753. 'date' => date ( "Y-m-d H:i:s" ),
  3754. 'operation' => "收款" . $detailM ['receivablesSerial'] . "入账到发票" . $detail ['invoiceSerial'],
  3755. 'status' => 8,
  3756. 'img' => $this->staff [0] ['avatar'],
  3757. 'username' => $this->staff [0] ['username'],
  3758. 'uid' => $this->staff [0] ['sid'],
  3759. 'category' => $this->staff [0] ['category'],
  3760. 'iid' => $detail ['iid']
  3761. );
  3762. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3763. Doo::loadModel ( 'invoiceStatistics' );
  3764. $invoiceStatistics = new invoiceStatistics ();
  3765. $item = array (
  3766. 'date' => $detailM ['receivablesDate'],
  3767. 'priceClass' => 3,
  3768. 'cid' => $detail ['cid'],
  3769. 'staff' => $detail ['sid'],
  3770. 'accountPrice' => $detailM ['receivablesPrice']
  3771. );
  3772. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3773. // 公司流水记录
  3774. // Doo::loadModel ( 'wasteBook' );
  3775. // $wasteBook = new wasteBook ();
  3776. // $abDetail = $wasteBook->getAccountBookByAid (1,8,$detail ['iid'] );
  3777. // $accountBank='';
  3778. // if ($detailM ['receivablesBank']=='纵横广发'){
  3779. // $accountBank='CGBDeposit';
  3780. // }elseif($detailM ['receivablesBank']=='纵横工行'){
  3781. // $accountBank='ICBCDeposit';
  3782. // }elseif($detailM ['receivablesBank']=='华润银行'){
  3783. // $accountBank='HUADeposit';
  3784. // }elseif($detailM ['receivablesBank']=='个人广发'){
  3785. // $accountBank='PersonalDeposit';
  3786. // }
  3787. // if (empty($abDetail)){
  3788. // $item = array (
  3789. // 'dataID' => $detail ['iid'],
  3790. // 'expensesType' => 1,
  3791. // 'accountType' => 8,
  3792. // 'accountPriceShow'=>$detail ['invoicePrice'],
  3793. // 'accountPrice'=>$detail ['invoicePrice'],
  3794. // 'accountBank'=>$accountBank,
  3795. // 'category'=>$this->staff[0]['category'],
  3796. // 'cid'=>$this->staff[0]['cid'],
  3797. // 'name'=>$this->staff[0]['username'],
  3798. // 'sid'=>$this->staff[0]['sid'],
  3799. // 'inputDate'=>date ( "Y-m-d H:i:s" )
  3800. // );
  3801. // $wasteBook->setAccountBookStatistics($item);
  3802. // }
  3803. return "/invoiceReceivables";
  3804. }
  3805. /**
  3806. * 核销 动作,确认入账统计 发票收款完成--需求更变 废弃 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"; }
  3807. */
  3808. function invoiceAggregate() {
  3809. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3810. Doo::loadModel ( 'invoiceStatistics' );
  3811. $invoiceStatistics = new invoiceStatistics ();
  3812. Doo::loadModel ( 'L_category' );
  3813. $Lcategory = new L_category ();
  3814. $isList = $invoiceStatistics->getInvoiceStatisticsByYear ( $year );
  3815. $LcategoryList = $Lcategory->getCategory ();
  3816. // print_r($isList);
  3817. $html = ""; // $invoicePriceCategory=0;$receivablesPriceCategory=0;$accountPriceCategory=0;
  3818. foreach ( $LcategoryList as $key => $value ) {
  3819. $html .= '<tr><th><a href="/invoiceAggregateCategory/' . $value ['cidKey'] . '">' . $value ['title'] . '</a></th>';
  3820. $month = 1;
  3821. $invoicePriceYear = 0;
  3822. $receivablesPriceYear = 0;
  3823. $accountPriceYear = 0;
  3824. for(; $month <= 12; $month ++) {
  3825. $flag = true;
  3826. foreach ( $isList ['statisticsMonthCid'] as $k => $v ) {
  3827. if ($value ['cid'] == $v ['cid'] && $month == $v ['month']) {
  3828. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  3829. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  3830. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  3831. ';
  3832. $invoicePriceYear += $v ['invoicePrice'];
  3833. $receivablesPriceYear += $v ['receivablesPrice'];
  3834. $accountPriceYear += $v ['accountPrice'];
  3835. $flag = false;
  3836. break;
  3837. }
  3838. }
  3839. if ($flag)
  3840. $html .= '<td class="taR"></td>
  3841. <td class="taR"></td>
  3842. <td class="taR"><b></b></td>
  3843. ';
  3844. }
  3845. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  3846. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  3847. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  3848. ';
  3849. $html .= '</tr>';
  3850. }
  3851. $html .= '<tr><th><b class="colGreen">月合计</b></th>';
  3852. $invoicePriceYear = 0;
  3853. $receivablesPriceYear = 0;
  3854. $accountPriceYear = 0;
  3855. for($month = 1; $month <= 12; $month ++) {
  3856. $flag = true;
  3857. foreach ( $isList ['statisticsMonth'] as $k => $v ) {
  3858. if ($month == $v ['month']) {
  3859. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  3860. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  3861. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  3862. ';
  3863. $invoicePriceYear += $v ['invoicePrice'];
  3864. $receivablesPriceYear += $v ['receivablesPrice'];
  3865. $accountPriceYear += $v ['accountPrice'];
  3866. $flag = false;
  3867. break;
  3868. }
  3869. }
  3870. if ($flag) {
  3871. $html .= '<td class="taR"></td>
  3872. <td class="taR"></td>
  3873. <td class="taR"><b></b></td>
  3874. ';
  3875. }
  3876. }
  3877. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  3878. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  3879. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  3880. ';
  3881. $html .= '</tr>';
  3882. // print_r($isList);
  3883. $this->data ['html'] = $html;
  3884. $this->data ['LcategoryList'] = $LcategoryList;
  3885. $this->data ['isList'] = $isList;
  3886. $this->data ['year'] = $year;
  3887. $this->data ['memu'] = "invoice";
  3888. $this->data ['staff'] = $this->staff;
  3889. $this->data ['receiptMemu'] = 'invoiceAggregate';
  3890. $this->render ( "/admin/invoiceAggregate", $this->data );
  3891. }
  3892. function invoiceAggregateStaff() {
  3893. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3894. Doo::loadModel ( 'invoiceStatistics' );
  3895. $invoiceStatistics = new invoiceStatistics ();
  3896. Doo::loadModel ( 'L_category' );
  3897. $Lcategory = new L_category ();
  3898. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year );
  3899. $staffList = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year );
  3900. $cStaff = $Lcategory->getCategoryStaff ();
  3901. $html = '';
  3902. foreach ( $cStaff as $key => $value ) {
  3903. $categoryFir = true;
  3904. foreach ( $value ['staff'] as $k => $v ) {
  3905. if ($categoryFir) {
  3906. $width = count ( $value ['staff'] ) + 1;
  3907. $html .= '<tr><th rowspan="' . $width . '">' . $value ['title'] . ' </th>';
  3908. $categoryFir = false;
  3909. } else
  3910. $html .= '<tr>';
  3911. $html .= '<th>' . $v ['username'] . '</th>';
  3912. $invoicePriceStaffYear = 0;
  3913. $receivablesPriceStaffYear = 0;
  3914. $accountPriceStaffYear = 0;
  3915. for($month = 1; $month <= 12; $month ++) {
  3916. $flag = true;
  3917. foreach ( $staffList ['statisticsMonthStaff'] as $sl => $slv ) {
  3918. if ($v ['sid'] == $slv ['staff'] && $month == $slv ['month']) {
  3919. $html .= '<td class="taR">¥' . $slv ['invoicePrice'] . '</td>
  3920. <td class="taR">¥' . $slv ['receivablesPrice'] . '</td>
  3921. <td class="taR"><b>¥' . $slv ['accountPrice'] . '</b></td>
  3922. ';
  3923. $invoicePriceStaffYear += $slv ['invoicePrice'];
  3924. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  3925. $accountPriceStaffYear += $slv ['accountPrice'];
  3926. $flag = false;
  3927. break;
  3928. }
  3929. }
  3930. if ($flag)
  3931. $html .= '<td class="taR"></td>
  3932. <td class="taR"></td>
  3933. <td class="taR"><b></b></td>
  3934. ';
  3935. }
  3936. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  3937. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  3938. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  3939. ';
  3940. }
  3941. $html .= '</tr>';
  3942. // 小计
  3943. if (! empty ( $value ['staff'] )) {
  3944. $html .= '<tr><th class="taR">小计</th>';
  3945. $invoicePriceStaffYear = 0;
  3946. $receivablesPriceStaffYear = 0;
  3947. $accountPriceStaffYear = 0;
  3948. for($month = 1; $month <= 12; $month ++) {
  3949. $flag = true;
  3950. foreach ( $staffList ['statisticsMonthCid'] as $smc => $smcv ) {
  3951. if ($value ['cid'] == $smcv ['cid'] && $month == $slv ['month']) {
  3952. $html .= '<td class="taR">¥' . $smcv ['invoicePrice'] . '</td>
  3953. <td class="taR">¥' . $smcv ['receivablesPrice'] . '</td>
  3954. <td class="taR"><b>¥' . $smcv ['accountPrice'] . '</b></td>
  3955. ';
  3956. $invoicePriceStaffYear += $slv ['invoicePrice'];
  3957. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  3958. $accountPriceStaffYear += $slv ['accountPrice'];
  3959. $flag = false;
  3960. break;
  3961. }
  3962. }
  3963. if ($flag)
  3964. $html .= '<td class="taR"></td>
  3965. <td class="taR"></td>
  3966. <td class="taR"><b></b></td>
  3967. ';
  3968. }
  3969. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  3970. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  3971. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  3972. ';
  3973. $html .= '</tr>';
  3974. }
  3975. }
  3976. $html .= '<tr class="warning"><th colspan="2"><b class="colGreen" >月合计</b></th>';
  3977. $invoicePriceYear = 0;
  3978. $receivablesPriceYear = 0;
  3979. $accountPriceYear = 0;
  3980. for($month = 1; $month <= 12; $month ++) {
  3981. $flag = true;
  3982. foreach ( $staffList ['statisticsMonth'] as $k => $v ) {
  3983. if ($month == $v ['month']) {
  3984. $html .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>
  3985. <td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>
  3986. <td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>
  3987. ';
  3988. $invoicePriceYear += $v ['invoicePrice'];
  3989. $receivablesPriceYear += $v ['receivablesPrice'];
  3990. $accountPriceYear += $v ['accountPrice'];
  3991. $flag = false;
  3992. break;
  3993. }
  3994. }
  3995. if ($flag)
  3996. $html .= '<td class="taR"></td>
  3997. <td class="taR"></td>
  3998. <td class="taR"><b></b></td>
  3999. ';
  4000. }
  4001. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  4002. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  4003. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  4004. ';
  4005. $html .= '</tr>';
  4006. $this->data ['html'] = $html;
  4007. $this->data ['isList'] = $toteList;
  4008. $this->data ['year'] = $year;
  4009. $this->data ['memu'] = "invoice";
  4010. $this->data ['staff'] = $this->staff;
  4011. $this->data ['receiptMemu'] = 'invoiceAggregate';
  4012. $this->render ( "/admin/invoiceAggregateStaff", $this->data );
  4013. }
  4014. function invoiceAggregateCategory() {
  4015. Doo::loadClass ( 'XDeode' );
  4016. $XDeode = new XDeode ( 5 );
  4017. $cid = $cidKey = isset ( $this->params ['cid'] ) ? $this->params ['cid'] : "";
  4018. $cid = $XDeode->decode ( $cid );
  4019. if (! is_numeric ( $cid ))
  4020. die ( 'illegal request' );
  4021. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  4022. Doo::loadModel ( 'invoiceStatistics' );
  4023. $invoiceStatistics = new invoiceStatistics ();
  4024. Doo::loadModel ( 'staff' );
  4025. $staff = new staff ();
  4026. $list = $staff->getStaffByCid ( $cid );
  4027. $isCategory = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year, $cid );
  4028. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year, $cid );
  4029. if (empty ( $list ))
  4030. die ( '该办事处没有成员' );
  4031. $htmlA = $htmlB = $htmlC = $html = '';
  4032. foreach ( $list as $key => $value ) {
  4033. $htmlA = '<tr><th rowspan="3">' . $value ['username'] . '</th><th class="taC">开票</th>';
  4034. $htmlB = '<tr><th class="taC">收款</th>';
  4035. $htmlC = '<tr><th class="taC">入账</th>';
  4036. $invoicePriceStaffYear = 0;
  4037. $receivablesPriceStaffYear = 0;
  4038. $accountPriceStaffYear = 0;
  4039. for($month = 1; $month <= 12; $month ++) {
  4040. $flag = true;
  4041. foreach ( $isCategory ['statisticsMonthStaff'] as $k => $v ) {
  4042. if ($value ['sid'] == $v ['staff'] && $month == $v ['month']) {
  4043. $htmlA .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>';
  4044. $htmlB .= '<td class="taR">¥' . $v ['receivablesPrice'] . '</td>';
  4045. $htmlC .= '<td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>';
  4046. $invoicePriceStaffYear += $v ['invoicePrice'];
  4047. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  4048. $accountPriceStaffYear += $v ['accountPrice'];
  4049. $flag = false;
  4050. break;
  4051. }
  4052. }
  4053. if ($flag) {
  4054. $htmlA .= '<td class="taR">-</td>';
  4055. $htmlB .= '<td class="taR">-</td>';
  4056. $htmlC .= '<td class="taR"><b>-</b></td>';
  4057. }
  4058. }
  4059. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  4060. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  4061. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  4062. $htmlA .= '</tr>';
  4063. $htmlB .= '</tr>';
  4064. $htmlC .= '</tr>';
  4065. $html .= $htmlA . $htmlB . $htmlC;
  4066. }
  4067. $htmlA = $htmlB = $htmlC = "";
  4068. $htmlA = '<tr><th rowspan="3">月合计</th><th class="taC">开票</th>';
  4069. $htmlB = '<tr><th class="taC">收款</th>';
  4070. $htmlC = '<tr><th class="taC">入账</th>';
  4071. $invoicePriceStaffYear = 0;
  4072. $receivablesPriceStaffYear = 0;
  4073. $accountPriceStaffYear = 0;
  4074. for($month = 1; $month <= 12; $month ++) {
  4075. $flag = true;
  4076. foreach ( $isCategory ['statisticsMonth'] as $k => $v ) {
  4077. if ($month == $v ['month']) {
  4078. $htmlA .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>';
  4079. $htmlB .= '<td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>';
  4080. $htmlC .= '<td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>';
  4081. $invoicePriceStaffYear += $v ['invoicePrice'];
  4082. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  4083. $accountPriceStaffYear += $v ['accountPrice'];
  4084. $flag = false;
  4085. break;
  4086. }
  4087. }
  4088. if ($flag) {
  4089. $htmlA .= '<td class="taR">-</td>';
  4090. $htmlB .= '<td class="taR">-</td>';
  4091. $htmlC .= '<td class="taR"><b>-</b></td>';
  4092. }
  4093. }
  4094. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  4095. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  4096. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  4097. $htmlA .= '</tr>';
  4098. $htmlB .= '</tr>';
  4099. $htmlC .= '</tr>';
  4100. $html .= $htmlA . $htmlB . $htmlC;
  4101. $this->data ['html'] = $html;
  4102. $this->data ['cidKey'] = $cidKey;
  4103. $this->data ['slist'] = $list;
  4104. $this->data ['isList'] = $toteList;
  4105. $this->data ['year'] = $year;
  4106. $this->data ['memu'] = "invoice";
  4107. $this->data ['staff'] = $this->staff;
  4108. $this->data ['receiptMemu'] = 'invoiceAggregate';
  4109. $this->render ( "/admin/invoiceAggregateCategory", $this->data );
  4110. }
  4111. /**
  4112. * 办事处汇总信息
  4113. */
  4114. function invoiceAggregateCategoryDetail() {
  4115. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  4116. Doo::loadClass ( 'XDeode' );
  4117. $XDeode = new XDeode ( 5 );
  4118. Doo::loadModel ( 'invoiceStatistics' );
  4119. $invoiceStatistics = new invoiceStatistics ();
  4120. Doo::loadModel ( 'L_category' );
  4121. $category = new L_category ();
  4122. Doo::loadModel ( 'invoice' );
  4123. $invoice = new invoice ();
  4124. Doo::loadModel ( 'staff' );
  4125. $staff = new staff ();
  4126. Doo::loadModel ( "invoiceCategoryManage" );
  4127. $invoiceCategoryManage = new invoiceCategoryManage ();
  4128. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4129. $cidList = array ();
  4130. foreach ( $imcStaff as $key => $value ) {
  4131. array_push ( $cidList, $value ['cid'] );
  4132. if (empty ( $cidKey ))
  4133. $cidKey = $XDeode->encode ( $value ['cid'] );
  4134. }
  4135. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  4136. $cid = $XDeode->decode ( $cidKey );
  4137. $month = date ( "m", strtotime ( "-1 month" ) );
  4138. $YearMonth = date ( "Y-m", strtotime ( "-1 month" ) );
  4139. $redis = new Redis ();
  4140. $redis->connect ( '127.0.0.1', '6379' );
  4141. $redisKey = ''; // date('Y-m-d').'_iacd_'.$cid;
  4142. $redisValue = ''; // $redis->lrange($redisKey, 0, -1);
  4143. if (empty ( $redisValue )) {
  4144. $isMC = $invoiceStatistics->getInvoiceStatistiscsMothByCategory ( $cid );
  4145. $schedule = $invoice->getInvoiceScheduleByCid ( $cid );
  4146. // 获得办事处人员下的汇总
  4147. $slist = $staff->getStaffByCid ( $cid );
  4148. $ismsbMonth = $invoiceStatistics->getISMSByCategoryByMonth ( $cid, $YearMonth ); // 上一个月的汇总
  4149. $ismsb = $invoiceStatistics->getISMSByCategory ( $cid ); // 当月汇总
  4150. $ISAS = $invoiceStatistics->getISASByCategory ( $cid ); // 全部汇总
  4151. $scheduleStaff = $invoice->getInvoiceScheduleByCidGroupSid ( $cid ); // 完成度
  4152. foreach ( $slist as $key => $value ) {
  4153. $slist [$key] ['invoicePrice'] = 0;
  4154. $slist [$key] ['receivablesPrice'] = 0;
  4155. $slist [$key] ['accountPrice'] = 0;
  4156. $slist [$key] ['invoiceAllPrice'] = 0;
  4157. $slist [$key] ['receivablesAllPrice'] = 0;
  4158. $slist [$key] ['accountAllPrice'] = 0;
  4159. $slist [$key] ['schedule'] = 0;
  4160. $slist [$key] ['invoiceMonthPrice'] = 0;
  4161. $slist [$key] ['receivablesMonthPrice'] = 0;
  4162. $slist [$key] ['accountMonthPrice'] = 0;
  4163. foreach ( $ismsbMonth as $y => $l ) {
  4164. if ($value ['sid'] == $l ['staff']) {
  4165. $slist [$key] ['invoiceMonthPrice'] = $l ['invoicePrice'];
  4166. $slist [$key] ['receivablesMonthPrice'] = $l ['receivablesPrice'];
  4167. $slist [$key] ['accountMonthPrice'] = $l ['accountPrice'];
  4168. }
  4169. }
  4170. foreach ( $ismsb as $k => $v ) {
  4171. if ($value ['sid'] == $v ['staff']) {
  4172. $slist [$key] ['invoicePrice'] = $v ['invoicePrice'];
  4173. $slist [$key] ['receivablesPrice'] = $v ['receivablesPrice'];
  4174. $slist [$key] ['accountPrice'] = $v ['accountPrice'];
  4175. }
  4176. }
  4177. foreach ( $ISAS as $e => $a ) {
  4178. if ($value ['sid'] == $a ['staff']) {
  4179. $slist [$key] ['invoiceAllPrice'] = $a ['invoicePrice'];
  4180. $slist [$key] ['receivablesAllPrice'] = $a ['receivablesPrice'];
  4181. $slist [$key] ['accountAllPrice'] = $a ['accountPrice'];
  4182. }
  4183. }
  4184. if (isset ( $scheduleStaff [$value ['sid']] ))
  4185. $slist [$key] ['schedule'] = $scheduleStaff [$value ['sid']];
  4186. }
  4187. $this->data ['cidKey'] = $cidKey;
  4188. $schedule = ( int ) ($schedule * 100);
  4189. $this->data ['slist'] = $slist;
  4190. $this->data ['isMC'] = $isMC;
  4191. $this->data ['schedule'] = $schedule;
  4192. $slist = json_encode ( $slist );
  4193. $isMC = json_encode ( $isMC );
  4194. $schedule = json_encode ( $schedule );
  4195. $redis->lpush ( $redisKey, $slist );
  4196. $redis->lpush ( $redisKey, $isMC );
  4197. $redis->lpush ( $redisKey, $schedule );
  4198. } else {
  4199. $this->data ['cidKey'] = $cidKey;
  4200. $this->data ['slist'] = json_decode ( $redisValue [2], true );
  4201. $this->data ['isMC'] = json_decode ( $redisValue [1], true );
  4202. $this->data ['schedule'] = json_decode ( $redisValue [0], true );
  4203. }
  4204. $this->data ['month'] = $month;
  4205. $this->data ['categoryList'] = $categoryList;
  4206. $this->data ['memu'] = "invoice";
  4207. $this->data ['staff'] = $this->staff;
  4208. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4209. $this->render ( "/admin/invoiceAggregateCategoryDetail", $this->data );
  4210. }
  4211. /**
  4212. * 办事处人员汇总详情
  4213. */
  4214. function invoiceAggregateStaffDetail() {
  4215. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  4216. // $sidKey = isset ( $this->params ['sidKey'] ) ? $this->params ['sidKey'] : '';
  4217. Doo::loadClass ( 'XDeode' );
  4218. $XDeode = new XDeode ( 5 );
  4219. Doo::loadModel ( 'invoice' );
  4220. $invoice = new invoice ();
  4221. Doo::loadModel ( 'staff' );
  4222. $staff = new staff ();
  4223. Doo::loadModel ( "invoiceCategoryManage" );
  4224. $invoiceCategoryManage = new invoiceCategoryManage ();
  4225. $sid = $XDeode->decode ( $sidKey );
  4226. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4227. $cidList = array ();
  4228. foreach ( $imcStaff as $key => $value ) {
  4229. array_push ( $cidList, $value ['cid'] );
  4230. if (empty ( $cidKey ))
  4231. $cidKey = $XDeode->encode ( $value ['cid'] );
  4232. }
  4233. $cidString = implode ( ',', $cidList );
  4234. $staffList = $staff->getStaffInCid ( $cidString );
  4235. $staffDetail = $staff->getStaffBySid ( $sid );
  4236. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4237. $page_size = 18;
  4238. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4239. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4240. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  4241. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  4242. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  4243. $dateArr = explode ( ':', $date );
  4244. $D1 = '';
  4245. $D2 = '';
  4246. if (! empty ( $date )) {
  4247. $D1 = $dateArr [0] . " 00:00:00 ";
  4248. if (isset ( $dateArr [1] ))
  4249. $D2 = $dateArr [1] . " 23:59:59 ";
  4250. else
  4251. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4252. // $D2 = $dateArr [1];
  4253. }
  4254. $con = ' status=2 ';
  4255. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4256. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4257. if ($status == 'UNRECORD')
  4258. $con .= ' and printStatus=1 and untreadStatus=0';
  4259. elseif ($status == 'RECORD')
  4260. $con .= ' and printStatus=1 and untreadStatus=3';
  4261. elseif ($status == 'BOUNCED')
  4262. $con .= ' and untreadStatus=2';
  4263. elseif ($status == 'PARTRECORD')
  4264. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  4265. elseif ($status == 'All') {
  4266. $con .= ' and ( untreadStatus=2 or untreadStatus=0 or untreadStatus=3 )';
  4267. }
  4268. $con .= ' and sid=' . $sid;
  4269. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  4270. if (! empty ( $MebSea )) {
  4271. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  4272. }
  4273. $pageinfo ['page'] = array (
  4274. 'previous' => ''
  4275. );
  4276. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateStaffDetail", $get, "" );
  4277. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4278. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  4279. $this->data ['staffDetail'] = $staffDetail;
  4280. $this->data ['staffList'] = $staffList;
  4281. $this->data ['MebSeaEn'] = $MebSea;
  4282. $this->data ['MebSea'] = urlencode ( $MebSea );
  4283. $this->data ['date'] = $date;
  4284. $this->data ['page'] = $pageinfo;
  4285. $this->data ['get'] = $get;
  4286. $this->data ['list'] = $list;
  4287. $this->data ['status'] = $status;
  4288. $this->data ['sidKey'] = $sidKey;
  4289. $this->data ['memu'] = "invoice";
  4290. $this->data ['staff'] = $this->staff;
  4291. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4292. $this->render ( "/admin/invoiceAggregateStaffDetail", $this->data );
  4293. }
  4294. /**
  4295. * 办事处人员汇总收款情
  4296. */
  4297. function invoiceAggregateStaffReceivablesDetail() {
  4298. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  4299. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  4300. Doo::loadModel ( 'invoiceReceivables' );
  4301. $invoiceReceivables = new invoiceReceivables ();
  4302. Doo::loadModel ( 'staff' );
  4303. $staff = new staff ();
  4304. Doo::loadModel ( "invoiceCategoryManage" );
  4305. $invoiceCategoryManage = new invoiceCategoryManage ();
  4306. Doo::loadClass ( 'XDeode' );
  4307. $XDeode = new XDeode ( 5 );
  4308. $sid = $XDeode->decode ( $sidKey );
  4309. $staffDetail = $staff->getStaffBySid ( $sid );
  4310. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4311. $cidList = array ();
  4312. foreach ( $imcStaff as $key => $value ) {
  4313. array_push ( $cidList, $value ['cid'] );
  4314. if (empty ( $cidKey ))
  4315. $cidKey = $XDeode->encode ( $value ['cid'] );
  4316. }
  4317. $cidString = implode ( ',', $cidList );
  4318. $staffList = $staff->getStaffInCid ( $cidString );
  4319. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4320. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  4321. $page_size = 10;
  4322. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4323. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4324. if ($timeType == "BINDOTP") {
  4325. $status = 'Credited';
  4326. }
  4327. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  4328. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  4329. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  4330. $dateArr = explode ( ':', $date );
  4331. $D1 = '';
  4332. $D2 = '';
  4333. if (! empty ( $date )) {
  4334. $D1 = $dateArr [0] . " 00:00:00 ";
  4335. if (isset ( $dateArr [1] ))
  4336. $D2 = $dateArr [1] . " 23:59:59 ";
  4337. else
  4338. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4339. }
  4340. $con = ' a.receivablesStaff like "%' . $staffDetail ['username'] . '%" ';
  4341. $descField = 'a.bindDate';
  4342. if ($timeType == 'CREATE')
  4343. $descField = 'a.date';
  4344. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4345. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4346. elseif (! empty ( $D1 ) && empty ( $D2 ))
  4347. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  4348. if ($status == 'Unclaimed')
  4349. $con .= ' and a.bindStatus=0';
  4350. elseif ($status == 'Credited')
  4351. $con .= ' and a.bindStatus=1';
  4352. elseif ($status == 'Claim')
  4353. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  4354. elseif ($status == 'BBN')
  4355. $con .= ' and a.bindPrice>a.receivablesPrice';
  4356. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  4357. if (! empty ( $MebSea )) {
  4358. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" )';
  4359. }
  4360. $pageinfo ['page'] = array (
  4361. 'previous' => ''
  4362. );
  4363. $sql = 'select group_concat(b.invoiceSerial) as invoiceSerial ,group_concat(b.iid) as invoiceId
  4364. from CLD_invoiceReceivables as a left join CLD_invoice as b on
  4365. find_in_set(b.iid,a.iidExtend) or a.iid=b.iid
  4366. where ' . $con . ' group by a.irid ';
  4367. $pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceAggregateStaffReceivablesDetail", $get, "" );
  4368. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4369. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', 'printTime' );
  4370. foreach ( $list as $key => $value ) {
  4371. $list [$key] ['category'] = '';
  4372. if ($value ['receivablesCategory'] != 'PUBLIC') {
  4373. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  4374. $list [$key] ['category'] = $receivablesCategory [1];
  4375. }
  4376. }
  4377. // print_r($list);
  4378. $this->data ['staffDetail'] = $staffDetail;
  4379. $this->data ['sidKey'] = $sidKey;
  4380. $this->data ['staffList'] = $staffList;
  4381. $this->data ['timeType'] = $timeType;
  4382. $this->data ['MebSeaEn'] = $MebSea;
  4383. $this->data ['MebSea'] = urlencode ( $MebSea );
  4384. $this->data ['date'] = $date;
  4385. $this->data ['page'] = $pageinfo;
  4386. $this->data ['get'] = $get;
  4387. $this->data ['list'] = $list;
  4388. $this->data ['status'] = $status;
  4389. $this->data ['memu'] = "invoice";
  4390. $this->data ['staff'] = $this->staff;
  4391. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4392. $this->render ( "/admin/invoiceAggregateStaffReceivablesDetail", $this->data );
  4393. }
  4394. function invoiceAchieve() {
  4395. Doo::loadModel ( 'invoice' );
  4396. $invoice = new invoice ();
  4397. Doo::loadClass ( 'XDeode' );
  4398. $XDeode = new XDeode ( 5 );
  4399. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4400. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4401. $page_size = 18;
  4402. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4403. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4404. $get = "/" . $date;
  4405. $con = '';
  4406. if ($date == 'MONTHO')
  4407. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4408. elseif ($date == 'MONTHT')
  4409. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4410. elseif ($date == 'MONTHY')
  4411. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4412. if (! empty ( $MebSea )) {
  4413. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4414. $get .= "/" . $MebSea;
  4415. }
  4416. $pageinfo ['page'] = array (
  4417. 'previous' => ''
  4418. );
  4419. $sql = 'status=2 and printStatus=1 and irid!="" and ( untreadStatus=3 or untreadStatus=0 ) and sid=' . $sid . $con;
  4420. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceAchieve", $get, "" );
  4421. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4422. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  4423. // print_r($pageinfo);
  4424. $this->data ['MebSeaEn'] = $MebSea;
  4425. $this->data ['MebSea'] = urlencode ( $MebSea );
  4426. $this->data ['get'] = $get;
  4427. $this->data ['page'] = $pageinfo;
  4428. $this->data ['list'] = $list;
  4429. $this->data ['date'] = $date;
  4430. $this->data ['memu'] = "invoice";
  4431. $this->data ['staff'] = $this->staff;
  4432. $this->data ['receiptMemu'] = 'invoice';
  4433. $this->render ( "/admin/invoiceAchieve", $this->data );
  4434. }
  4435. /**
  4436. */
  4437. function invoiceMyUnAccountAchieve() {
  4438. Doo::loadModel ( 'invoice' );
  4439. $invoice = new invoice ();
  4440. Doo::loadClass ( 'XDeode' );
  4441. $XDeode = new XDeode ( 5 );
  4442. Doo::loadModel ( 'staff' );
  4443. $staff = new staff ();
  4444. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4445. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4446. $page_size = 18;
  4447. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4448. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4449. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4450. $dateArr = explode ( ':', $date );
  4451. $D1 = '';
  4452. $D2 = '';
  4453. if (! empty ( $date )) {
  4454. $D1 = $dateArr [0];
  4455. $D2 = $dateArr [1];
  4456. }
  4457. $con = '';
  4458. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4459. $con = ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4460. if (! empty ( $MebSea )) {
  4461. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4462. }
  4463. $pageinfo ['page'] = array (
  4464. 'previous' => ''
  4465. );
  4466. // and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  4467. $sql = " status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid= " . $sid . $con;
  4468. $action = "invoiceMyUnAccountAchieve";
  4469. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  4470. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4471. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 'desc', 'printTime' );
  4472. Doo::loadModel ( 'express' );
  4473. $express = new express ();
  4474. $expressList = $express->getExpressByAll ();
  4475. $this->data ['expressList'] = $expressList;
  4476. // print_r($list);
  4477. $this->data ['MebSeaEn'] = $MebSea;
  4478. $this->data ['get'] = $get;
  4479. $this->data ['page'] = $pageinfo;
  4480. $this->data ['date'] = $date;
  4481. $this->data ['list'] = $list;
  4482. $this->data ['memu'] = "invoice";
  4483. $this->data ['staff'] = $this->staff;
  4484. $this->data ['receiptMemu'] = 'invoice';
  4485. $this->render ( "/admin/invoiceMyUnAccountAchieve", $this->data );
  4486. }
  4487. function invoiceReceivablesAchieve() {
  4488. Doo::loadModel ( 'invoiceReceivables' );
  4489. $invoiceReceivables = new invoiceReceivables ();
  4490. Doo::loadClass ( 'XDeode' );
  4491. $XDeode = new XDeode ( 5 );
  4492. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4493. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  4494. $page_size = 12;
  4495. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4496. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4497. $get = "/" . $date;
  4498. $con = '';
  4499. if ($date == 'MONTHO')
  4500. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4501. elseif ($date == 'MONTHT')
  4502. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4503. elseif ($date == 'MONTHY')
  4504. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4505. if (! empty ( $MebSea )) {
  4506. $con .= ' and ( receivablesMessage like "%' . $MebSea . '%" or receivablesPrice like "%' . $MebSea . '%" )';
  4507. $get .= "/" . $MebSea;
  4508. }
  4509. $pageinfo ['page'] = array (
  4510. 'previous' => ''
  4511. );
  4512. $sql = " bindStatus=1 and receivablesStaff like '" . $sid . "-%' " . $con;
  4513. $pageinfo = $this->get_page ( "CLD_invoiceReceivables", $sql, $page, $page_size, "invoiceReceivablesAchieve", $get, "" );
  4514. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4515. $list = $invoiceReceivables->getReceivablesByUntreadStatusPage ( $limit, $sql );
  4516. // print_r($pageinfo);
  4517. $this->data ['MebSeaEn'] = $MebSea;
  4518. $this->data ['MebSea'] = urlencode ( $MebSea );
  4519. $this->data ['get'] = $get;
  4520. $this->data ['page'] = $pageinfo;
  4521. $this->data ['list'] = $list;
  4522. $this->data ['date'] = $date;
  4523. $this->data ['memu'] = "invoice";
  4524. $this->data ['staff'] = $this->staff;
  4525. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  4526. $this->render ( "/admin/invoiceReceivablesAchieve", $this->data );
  4527. }
  4528. /**
  4529. * 收款解绑
  4530. */
  4531. function invoiceUnBundLing() {
  4532. $unBundKey = $this->get_args ( 'unBundKey' ) ? $this->get_args ( 'unBundKey' ) : '';
  4533. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  4534. Doo::loadModel ( 'invoice' );
  4535. $invoice = new invoice ();
  4536. Doo::loadModel ( 'invoiceReceivables' );
  4537. $invoiceReceivables = new invoiceReceivables ();
  4538. Doo::loadModel ( 'invoiceOperationLog' );
  4539. $invoiceOperationLog = new invoiceOperationLog ();
  4540. Doo::loadModel ( 'invoiceROLog' );
  4541. $invoiceROLog = new invoiceROLog ();
  4542. Doo::loadModel ( 'invoiceStatistics' );
  4543. Doo::loadClass ( 'XDeode' );
  4544. $XDeode = new XDeode ( 5 );
  4545. if (empty ( $iidKey ) || empty ( $unBundKey ))
  4546. die ( 'illegal request' );
  4547. $iid = $XDeode->decode ( $iidKey );
  4548. $irid = $invoice->authcode ( $unBundKey );
  4549. if ((! empty ( $irid ) && ! is_numeric ( $irid )) || (! empty ( $iid ) && ! is_numeric ( $iid )))
  4550. die ( 'illegal request' );
  4551. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4552. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  4553. if (empty ( $irDetails ) || empty ( $invoiceDetails ) || (empty ( $irDetails ['iid'] ) && empty ( $irDetails ['iidExtend'] )) || $invoiceDetails ['untreadStatus'] == 2)
  4554. die ( 'illegal request' );
  4555. // 收款
  4556. $item = array (
  4557. 'irid' => $irDetails ['irid'],
  4558. 'bindPrice' => $irDetails ['bindPrice'] - $invoiceDetails ['invoicePrice'],
  4559. 'bindStatus' => 0
  4560. );
  4561. if ($irDetails ['iid'] == $iid)
  4562. $item += array (
  4563. 'iid' => 0
  4564. );
  4565. else {
  4566. $iidExtend = explode ( ',', $irDetails ['iidExtend'] );
  4567. foreach ( $iidExtend as $key => $value ) {
  4568. if ($value == $iid)
  4569. unset ( $iidExtend [$key] );
  4570. }
  4571. $iidExtend = implode ( ',', $iidExtend );
  4572. $item += array (
  4573. 'iidExtend' => $iidExtend
  4574. );
  4575. }
  4576. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4577. // 收款操作日志
  4578. $item = array (
  4579. 'operation' => $this->staff [0] ['username'] . " 解绑 " . $irDetails ['receivablesSerial'],
  4580. 'date' => date ( "Y-m-d" ),
  4581. 'status' => 3,
  4582. 'img' => $this->staff [0] ['avatar'],
  4583. 'username' => $this->staff [0] ['username'],
  4584. 'uid' => $this->staff [0] ['sid'],
  4585. 'category' => $this->staff [0] ['category'],
  4586. 'irid' => $irid
  4587. );
  4588. $invoiceROLog->setInvoiceROLog ( $item );
  4589. // 扣除入账统计金额
  4590. $invoiceStatistics = new invoiceStatistics ();
  4591. $item = array (
  4592. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  4593. 'priceClass' => 3,
  4594. 'cid' => $invoiceDetails ['cid'],
  4595. 'staff' => $invoiceDetails ['sid'],
  4596. 'accountPrice' => - $irDetails ['receivablesPrice']
  4597. );
  4598. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4599. // 扣除收款统计金额
  4600. $invoiceStatistics = new invoiceStatistics ();
  4601. $item = array (
  4602. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  4603. 'priceClass' => 2,
  4604. 'cid' => $invoiceDetails ['cid'],
  4605. 'staff' => $invoiceDetails ['sid'],
  4606. 'irid' => $irDetails ['irid'],
  4607. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  4608. );
  4609. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4610. // 发票解绑去收款ID
  4611. $iridString = $invoiceDetails ['irid'];
  4612. if (! empty ( $invoiceDetails ['irid'] )) {
  4613. $list = explode ( ',', $invoiceDetails ['irid'] );
  4614. foreach ( $list as $key => $value ) {
  4615. if ($value == $irDetails ['irid']) {
  4616. unset ( $list [$key] );
  4617. break;
  4618. }
  4619. }
  4620. $iridString = implode ( ",", $list );
  4621. }
  4622. $item = array (
  4623. 'iid' => $invoiceDetails ['iid'],
  4624. 'irid' => $iridString,
  4625. 'updateTime' => date ( "Y-m-d H:i:s" )
  4626. );
  4627. if ($invoiceDetails ['untreadStatus'] == 3)
  4628. $item += array (
  4629. 'untreadStatus' => 0
  4630. );
  4631. $invoice->setInvoiceByCondition ( $item );
  4632. $item = array (
  4633. 'date' => date ( "Y-m-d H:i:s" ),
  4634. 'operation' => '解绑 收款 ' . $irDetails ['receivablesSerial'],
  4635. 'status' => 11,
  4636. 'img' => $this->staff [0] ['avatar'],
  4637. 'username' => $this->staff [0] ['username'],
  4638. 'uid' => $this->staff [0] ['sid'],
  4639. 'category' => $this->staff [0] ['category'],
  4640. 'iid' => $invoiceDetails ['iid']
  4641. );
  4642. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  4643. // 公司流水-解绑时删除流水
  4644. Doo::loadModel ( 'wasteBook' );
  4645. $wasteBook = new wasteBook ();
  4646. // $wasteBook->delete ( array (
  4647. // 'where' => 'dataID=' . $irDetails ['irid'] . ' and accountType=7',
  4648. // 'limit' => 1
  4649. // ) );
  4650. // 银行
  4651. /*
  4652. * $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); }
  4653. */
  4654. return "/invoiceReceivablesAS";
  4655. }
  4656. /**
  4657. * 或者该收款下的所以发票
  4658. */
  4659. function ajaxGetInvoiceReceivablesByInvoice() {
  4660. $irid = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : '';
  4661. Doo::loadModel ( 'invoice' );
  4662. $invoice = new invoice ();
  4663. Doo::loadModel ( 'invoiceReceivables' );
  4664. $invoiceReceivables = new invoiceReceivables ();
  4665. $irid = $invoice->authcode ( $irid );
  4666. if (! empty ( $irid ) && ! is_numeric ( $irid ))
  4667. die ( 'illegal request' );
  4668. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4669. $iidString = $irDetails ['iid'];
  4670. $iidExtend = array_filter ( explode ( ',', $irDetails ['iidExtend'] ) );
  4671. if (! empty ( $irDetails ['iidExtend'] ))
  4672. $iidString .= ',' . implode ( ',', $iidExtend );
  4673. $invoiceList = $invoice->getInvoiceInIid ( $iidString, 'iid,invoiceSerial,invoicePrice,invoiceTitle,invoiceCompany,invoiceElement' );
  4674. $html = "";
  4675. foreach ( $invoiceList as $key => $value ) {
  4676. $title = $value ['invoiceTitle'];
  4677. if (! empty ( $value ['invoiceCompany'] ))
  4678. $title = $value ['invoiceCompany'];
  4679. $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>';
  4680. }
  4681. echo json_encode ( array (
  4682. 'status' => 1,
  4683. 'html' => $html
  4684. ) );
  4685. }
  4686. /**
  4687. * 发票管理
  4688. */
  4689. function invoiceAS() {
  4690. Doo::loadModel ( 'invoice' );
  4691. $invoice = new invoice ();
  4692. Doo::loadModel ( 'invoiceReceivables' );
  4693. $invoiceReceivables = new invoiceReceivables ();
  4694. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4695. $page_size = 18;
  4696. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4697. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4698. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4699. $dateArr = explode ( ':', $date );
  4700. $D1 = '';
  4701. $D2 = '';
  4702. if (! empty ( $date )) {
  4703. $D1 = $dateArr [0] . " 00:00:00 ";
  4704. if (isset ( $dateArr [1] ))
  4705. $D2 = $dateArr [1] . " 23:59:59 ";
  4706. else
  4707. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4708. // $D2 = $dateArr [1];
  4709. }
  4710. $con = ' status=2 ';
  4711. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4712. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4713. if ($status == 'UNRECORD')
  4714. $con .= ' and printStatus=1 and untreadStatus=0';
  4715. elseif ($status == 'RECORD')
  4716. $con .= ' and printStatus=1 and untreadStatus=3';
  4717. elseif ($status == 'BOUNCED')
  4718. $con .= ' and untreadStatus=2';
  4719. elseif ($status == 'PARTRECORD')
  4720. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  4721. elseif ($status == 'All') {
  4722. $con .= ' and ( untreadStatus=2 or untreadStatus=1 or untreadStatus=0 or untreadStatus=3 )';
  4723. }
  4724. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4725. if (! empty ( $MebSea )) {
  4726. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  4727. }
  4728. $pageinfo ['page'] = array (
  4729. 'previous' => ''
  4730. );
  4731. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAS", $get, "" );
  4732. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4733. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  4734. $this->data ['MebSeaEn'] = $MebSea;
  4735. $this->data ['MebSea'] = urlencode ( $MebSea );
  4736. $this->data ['date'] = $date;
  4737. $this->data ['page'] = $pageinfo;
  4738. $this->data ['get'] = $get;
  4739. $this->data ['list'] = $list;
  4740. $this->data ['status'] = $status;
  4741. $this->data ['memu'] = "invoice";
  4742. $this->data ['staff'] = $this->staff;
  4743. $this->data ['receiptMemu'] = 'invoiceReceivables';
  4744. $this->render ( "/admin/invoiceAS", $this->data );
  4745. }
  4746. /**
  4747. * 收款管理
  4748. */
  4749. function invoiceReceivablesAS() {
  4750. Doo::loadModel ( 'invoiceReceivables' );
  4751. $invoiceReceivables = new invoiceReceivables ();
  4752. Doo::loadModel ( 'L_category' );
  4753. $lCategory = new L_category ();
  4754. $category = $lCategory->getCategory ();
  4755. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4756. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  4757. $page_size = 10;
  4758. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4759. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4760. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4761. $dateArr = explode ( ':', $date );
  4762. $D1 = '';
  4763. $D2 = '';
  4764. if (! empty ( $date )) {
  4765. $D1 = $dateArr [0]; // ." 00:00:00 ";
  4766. if (isset ( $dateArr [1] ))
  4767. $D2 = $dateArr [1]; // ." 23:59:59 ";
  4768. else
  4769. $D2 = $dateArr [0]; // ." 23:59:59 ";//date ( "Y-m-d" );
  4770. }
  4771. $descField = 'a.receivablesDate';
  4772. if ($timeType == 'CREATE')
  4773. $descField = 'a.date';
  4774. $con = '1';
  4775. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4776. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4777. elseif (! empty ( $D1 ) && empty ( $D2 ))
  4778. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  4779. if ($status == 'Unclaimed')
  4780. $con .= ' and a.bindStatus=0';
  4781. elseif ($status == 'Credited')
  4782. $con .= ' and a.bindStatus=1';
  4783. elseif ($status == 'Claim')
  4784. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  4785. elseif ($status == 'BBN')
  4786. $con .= ' and a.bankBatchNumber!=""';
  4787. elseif ($status == 'REFUND')
  4788. $con .= ' and ( (a.bindStatus=0 and a.refundLog!="" ) or a.bindStatus=2)';
  4789. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4790. if (! empty ( $MebSea )) {
  4791. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" or a.receivablesSerial like "%' . $MebSea . '%" )';
  4792. }
  4793. $pageinfo ['page'] = array (
  4794. 'previous' => ''
  4795. );
  4796. $sql = 'select group_concat(b.invoiceSerial) as invoiceSerial ,group_concat(b.iid) as invoiceId
  4797. from CLD_invoiceReceivables as a left join CLD_invoice as b on
  4798. find_in_set(b.iid,a.iidExtend) or a.iid=b.iid
  4799. where ' . $con . ' group by a.irid ';
  4800. $pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceReceivablesAS", $get, "" );
  4801. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4802. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', $descField );
  4803. foreach ( $list as $key => $value ) {
  4804. $list [$key] ['category'] = '';
  4805. if ($value ['receivablesCategory'] != 'PUBLIC') {
  4806. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  4807. $list [$key] ['category'] = $receivablesCategory [1];
  4808. }
  4809. }
  4810. // print_r($list);
  4811. $this->data ['category'] = $category;
  4812. $this->data ['timeType'] = $timeType;
  4813. $this->data ['MebSeaEn'] = $MebSea;
  4814. $this->data ['MebSea'] = urlencode ( $MebSea );
  4815. $this->data ['date'] = $date;
  4816. $this->data ['page'] = $pageinfo;
  4817. $this->data ['get'] = $get;
  4818. $this->data ['list'] = $list;
  4819. $this->data ['status'] = $status;
  4820. $this->data ['memu'] = "invoice";
  4821. $this->data ['staff'] = $this->staff;
  4822. $this->data ['receiptMemu'] = 'invoiceReceivables';
  4823. $this->render ( "/admin/invoiceReceivablesAS", $this->data );
  4824. }
  4825. /**
  4826. * 删除一条收款
  4827. */
  4828. function delInvoiceReceivables() {
  4829. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  4830. if (empty ( $iridKey ))
  4831. die ( 'illegal request' );
  4832. Doo::loadClass ( 'XDeode' );
  4833. $XDeode = new XDeode ( 5 );
  4834. $irid = $XDeode->decode ( $iridKey );
  4835. Doo::loadModel ( 'invoiceReceivables' );
  4836. $invoiceReceivables = new invoiceReceivables ();
  4837. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4838. if (empty ( $detail ))
  4839. die ( 'illegal request' );
  4840. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  4841. // 扣除收款汇总信息 汇总
  4842. Doo::loadModel ( 'invoiceStatistics' );
  4843. $invoiceStatistics = new invoiceStatistics ();
  4844. $item = array (
  4845. 'date' => $detail ['receivablesDate'],
  4846. 'priceClass' => 2,
  4847. 'irid' => $detail ['irid'],
  4848. 'receivablesPrice' => - $detail ['receivablesPrice']
  4849. );
  4850. if ($detail ['receivablesCategory'] != 'PUBLIC') {
  4851. $receivablesCategory = explode ( ":", $detail ['receivablesCategory'] );
  4852. $item += array (
  4853. 'cid' => $receivablesCategory [0]
  4854. );
  4855. }
  4856. if ($detail ['receivablesStaff'] != 'PUBLIC') {
  4857. $receivablesStaff = explode ( "-", $detail ['receivablesStaff'] );
  4858. $item += array (
  4859. 'staff' => $receivablesStaff [0]
  4860. );
  4861. }
  4862. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4863. return '/invoiceReceivablesAS';
  4864. }
  4865. /**
  4866. * 添加退款信息
  4867. */
  4868. function setInvoiceReceivablesRefund() {
  4869. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  4870. $refundType = $this->get_args ( 'refundType' ) && is_numeric ( $this->get_args ( 'refundType' ) ) ? $this->get_args ( 'refundType' ) : '0';
  4871. $refundCompany = $this->get_args ( 'refundCompany' ) ? $this->get_args ( 'refundCompany' ) : "";
  4872. $refundNumber = $this->get_args ( 'refundNumber' ) ? $this->get_args ( 'refundNumber' ) : "";
  4873. $refundPrice = $this->get_args ( 'refundPrice' ) ? $this->get_args ( 'refundPrice' ) : "";
  4874. $refundRemarks = $this->get_args ( 'refundRemarks' ) ? $this->get_args ( 'refundRemarks' ) : "";
  4875. if ($refundPrice < 0)
  4876. die ( 'illegal request' );
  4877. if (! empty ( $iridKey ) && ! empty ( $refundCompany ) && ! empty ( $refundNumber ) && ! empty ( $refundPrice )) {
  4878. Doo::loadModel ( 'invoiceReceivables' );
  4879. $invoiceReceivables = new invoiceReceivables ();
  4880. Doo::loadModel ( 'invoiceRefund' );
  4881. $invoiceRefund = new invoiceRefund ();
  4882. $irid = $invoiceReceivables->authcode ( $iridKey );
  4883. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4884. if ($irDetail ['receivablesPrice'] < $refundPrice)
  4885. die ( 'illegal request' );
  4886. $invoiceReceivables = new invoiceReceivables ();
  4887. $refundLog = $this->staff [0] ['username'] . ' 退款 <b class="colRed">¥' . $refundPrice . '</b>
  4888. <br/><a href="#refunded" onclick="getRefundByDetail(\'' . $iridKey . '\')" data-toggle="modal">退款信息</a> <br/>' . date ( "Y-m-d H:i:s" ) . '
  4889. ';
  4890. $item = array (
  4891. 'irid' => $irid,
  4892. 'refundCompany' => $refundCompany,
  4893. 'refundNumber' => $refundNumber,
  4894. 'refundPrice' => $refundPrice,
  4895. 'refundRemarks' => $refundRemarks,
  4896. 'refundLog' => $refundLog
  4897. );
  4898. if ($refundType == 1) {
  4899. $item += array (
  4900. 'refundType' => $refundType,
  4901. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice,
  4902. 'bindStatus' => 2
  4903. );
  4904. } elseif ($refundType == 0 && $irDetail ['receivablesPrice'] <= $refundPrice) {
  4905. $item += array (
  4906. 'refundType' => 1,
  4907. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice,
  4908. 'bindStatus' => 2
  4909. );
  4910. } else {
  4911. $item += array (
  4912. 'refundType' => $refundType,
  4913. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice
  4914. );
  4915. }
  4916. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4917. // 添加退款记录
  4918. $item = array (
  4919. 'irid' => $irid,
  4920. 'refundType' => $refundType,
  4921. 'refundCompany' => $refundCompany,
  4922. 'refundNumber' => $refundNumber,
  4923. 'refundPrice' => $refundPrice,
  4924. 'refundLog' => $refundLog,
  4925. 'refundRemarks' => $refundRemarks,
  4926. 'date' => date ( "Y-m-d H:i:s" )
  4927. );
  4928. $invoiceRefund->addInvoiceRefund ( $item );
  4929. // 扣除收款汇总信息 汇总
  4930. Doo::loadModel ( 'invoiceStatistics' );
  4931. $invoiceStatistics = new invoiceStatistics ();
  4932. $item = array (
  4933. 'date' => $irDetail ['receivablesDate'],
  4934. 'priceClass' => 2,
  4935. 'irid' => $irDetail ['irid'],
  4936. 'receivablesPrice' => - $refundPrice
  4937. );
  4938. if ($irDetail ['receivablesCategory'] != 'PUBLIC') {
  4939. $receivablesCategory = explode ( ":", $irDetail ['receivablesCategory'] );
  4940. $item += array (
  4941. 'cid' => $receivablesCategory [0]
  4942. );
  4943. }
  4944. if ($irDetail ['receivablesStaff'] != 'PUBLIC') {
  4945. $receivablesStaff = explode ( "-", $irDetail ['receivablesStaff'] );
  4946. $item += array (
  4947. 'staff' => $receivablesStaff [0]
  4948. );
  4949. }
  4950. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4951. // 公司日常支出流水
  4952. Doo::loadModel ( 'wasteBook' );
  4953. $wasteBook = new wasteBook ();
  4954. $accountBank = '';
  4955. if ($irDetail ['receivablesBank'] == '纵横广发') {
  4956. $accountBank = 'CGBDeposit';
  4957. } elseif ($irDetail ['receivablesBank'] == '纵横工行') {
  4958. $accountBank = 'ICBCDeposit';
  4959. } elseif ($irDetail ['receivablesBank'] == '华润银行') {
  4960. $accountBank = 'HUADeposit';
  4961. } elseif ($irDetail ['receivablesBank'] == '个人广发') {
  4962. $accountBank = 'PersonalDeposit';
  4963. }
  4964. $itemWaste = array (
  4965. 'accountPrice' => - $refundPrice,
  4966. 'expensesType' => 2,
  4967. 'accountType' => 11,
  4968. 'accountPriceShow' => $refundPrice,
  4969. 'dataID' => $irid,
  4970. 'accountBank' => $accountBank,
  4971. 'category' => $this->staff [0] ['category'],
  4972. 'cid' => $this->staff [0] ['cid'],
  4973. 'name' => $this->staff [0] ['username'],
  4974. 'sid' => $this->staff [0] ['sid'],
  4975. 'inputDate' => date ( "Y-m-d H:i:s" )
  4976. );
  4977. $wasteBook->setAccountBookStatistics ( $itemWaste );
  4978. return '/invoiceReceivablesAS';
  4979. }
  4980. die ( 'illegal request' );
  4981. }
  4982. function ajaxCheckInvoiceReceivablesRefund() {
  4983. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  4984. $refundPrice = $this->get_args ( 'refundPrice' ) ? $this->get_args ( 'refundPrice' ) : "";
  4985. if ($refundPrice < 0) {
  4986. echo json_encode ( array (
  4987. 'error' => '金额不能为负'
  4988. ) );
  4989. die ();
  4990. }
  4991. if (! empty ( $refundPrice ) && ! empty ( $iridKey )) {
  4992. Doo::loadModel ( 'invoiceReceivables' );
  4993. $invoiceReceivables = new invoiceReceivables ();
  4994. $irid = $invoiceReceivables->authcode ( $iridKey );
  4995. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4996. if ($irDetail ['receivablesPrice'] < $refundPrice) {
  4997. echo json_encode ( array (
  4998. 'error' => '退款金额不能超过收款金额'
  4999. ) );
  5000. die ();
  5001. }
  5002. echo json_encode ( array (
  5003. 'ok' => '可以使用!'
  5004. ) );
  5005. die ();
  5006. }
  5007. }
  5008. /**
  5009. * 获得收款退款信息
  5010. */
  5011. function getRefundByDetail() {
  5012. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5013. Doo::loadModel ( 'invoiceReceivables' );
  5014. $invoiceReceivables = new invoiceReceivables ();
  5015. if (! empty ( $iridKey )) {
  5016. $irid = $invoiceReceivables->authcode ( $iridKey );
  5017. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5018. echo json_encode ( array (
  5019. 'status' => 1,
  5020. 'irDetail' => $irDetail
  5021. ) );
  5022. die ();
  5023. }
  5024. echo json_encode ( array (
  5025. 'status' => 2
  5026. ) );
  5027. }
  5028. /**
  5029. * 根据收款序列号获得收款退款信息
  5030. */
  5031. function ajaxGetInvoiceReceivablesBySerial() {
  5032. $receivablesSerial = $this->get_args ( 'receivablesSerial' ) ? $this->get_args ( 'receivablesSerial' ) : '';
  5033. if (! empty ( $receivablesSerial )) {
  5034. Doo::loadModel ( 'invoiceReceivables' );
  5035. $invoiceReceivables = new invoiceReceivables ();
  5036. // , ' and refundLog=""'
  5037. $irDetail = $invoiceReceivables->getInvoiceReceivablesBySerial ( $receivablesSerial );
  5038. $html = '';
  5039. if (! empty ( $irDetail ))
  5040. $html = '<td><b>¥' . $irDetail ['receivablesPrice'] . '</b></td>
  5041. <td>' . $irDetail ['receivablesMessage'] . '</td>
  5042. <td>' . $irDetail ['receivablesBank'] . '<br>' . $irDetail ['receivablesDate'] . '</td>
  5043. <td>' . $irDetail ['title'] . '-' . $irDetail ['username'] . '<br>' . $irDetail ['confirmTime'] . '</td>
  5044. <td>' . $irDetail ['recepitTitleMark'] . '
  5045. <input type="hidden" name="iridKey" id="iridKey" value="' . $irDetail ['iridKey'] . '">
  5046. </td>';
  5047. echo json_encode ( array (
  5048. 'status' => 1,
  5049. 'html' => $html,
  5050. 'irDetail' => $irDetail
  5051. ) );
  5052. die ();
  5053. }
  5054. echo json_encode ( array (
  5055. 'status' => 2
  5056. ) );
  5057. }
  5058. /**
  5059. * 绑定新收款
  5060. */
  5061. function relationNewInvoiceReceivables() {
  5062. $iridKeyOld = $this->get_args ( 'iridKeyOld' ) ? $this->get_args ( 'iridKeyOld' ) : '';
  5063. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5064. if (! empty ( $iridKeyOld ) && ! empty ( $iridKey )) {
  5065. Doo::loadModel ( 'invoiceReceivables' );
  5066. $invoiceReceivables = new invoiceReceivables ();
  5067. Doo::loadClass ( 'XDeode' );
  5068. $XDeode = new XDeode ( 5 );
  5069. $irid = $XDeode->decode ( $iridKey );
  5070. $iridOld = $invoiceReceivables->authcode ( $iridKeyOld );
  5071. echo $irid . 'bbb' . $iridOld;
  5072. $oldIrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $iridOld );
  5073. $IrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5074. if (empty ( $oldIrDetail ) || empty ( $IrDetail ))
  5075. die ( 'illegal request' );
  5076. $relationLog = $this->staff [0] ['username'] . ' 关联新款 <a href="#billing" onclick="invoiceReceivblesDivShow(\'' . $iridKey . '\',\'receivables\')" data-toggle="modal">' . $IrDetail ['receivablesSerial'] . '</a>
  5077. <br/>' . date ( "Y-m-d H:i:s" ) . '
  5078. ';
  5079. $invoiceReceivables = new invoiceReceivables ();
  5080. $item = array (
  5081. 'irid' => $iridOld,
  5082. 'relationIrid' => $irid,
  5083. 'relationLog' => $relationLog
  5084. );
  5085. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  5086. return '/invoiceReceivablesAS';
  5087. }
  5088. die ( 'illegal request' );
  5089. }
  5090. // function invoiceApprovalAchieve() {
  5091. // Doo::loadModel ( 'invoice' );
  5092. // $invoice = new invoice ();
  5093. // $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  5094. // $page_size = 12;
  5095. // $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5096. // $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  5097. // $get = "/" . $date;
  5098. // $con = '';
  5099. // if ($date == 'MONTHO')
  5100. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  5101. // elseif ($date == 'MONTHT')
  5102. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  5103. // elseif ($date == 'MONTHY')
  5104. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  5105. // if (! empty ( $MebSea )) {
  5106. // $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  5107. // $get .= "/" . $MebSea;
  5108. // }
  5109. // $pageinfo ['page'] = array (
  5110. // 'previous' => ''
  5111. // );
  5112. // $sql = '(status=1 or status=2 or status=3 or status=4) and processApprovals!=""' . $con; // echo $sql;
  5113. // $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", $get, "" );
  5114. // $limit = $pageinfo ['lower'] . ',' . $page_size;
  5115. // $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  5116. // // print_r($list);
  5117. // $this->data ['MebSeaEn'] = $MebSea;
  5118. // $this->data ['MebSea'] = urlencode ( $MebSea );
  5119. // $this->data ['get'] = $get;
  5120. // $this->data ['page'] = $pageinfo;
  5121. // $this->data ['list'] = $list;
  5122. // $this->data ['date'] = $date;
  5123. // $this->data ['memu'] = "invoice";
  5124. // $this->data ['staff'] = $this->staff;
  5125. // $this->data ['receiptMemu'] = 'invoiceApproval';
  5126. // $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  5127. // }
  5128. /**
  5129. * 获得审批发票的信息以及审批页面
  5130. */
  5131. function ajaxGetInvoiceApprovalDetail() {
  5132. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5133. if (empty ( $serial )) {
  5134. echo json_encode ( array (
  5135. 'status' => 2,
  5136. 'msg' => 'illegal request'
  5137. ) );
  5138. die ();
  5139. }
  5140. Doo::loadModel ( 'invoice' );
  5141. $invoice = new invoice ();
  5142. Doo::loadModel ( 'invoiceOperationLog' );
  5143. $invoiceOperationLog = new invoiceOperationLog ();
  5144. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5145. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5146. if (empty ( $detail ))
  5147. $html = '';
  5148. else {
  5149. $html = '
  5150. <form action="/invoiceApprovalDo" method="post" name="invoiceApproval" class="nice-validator n-yellow" novalidate="novalidate">
  5151. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  5152. <input type="hidden" name="status" value="">
  5153. <input type="hidden" name="divApproval" value="divApproval">
  5154. <div class="modal-dialog modal-lg">
  5155. <div class="modal-content"><div class="modal-header"><h3>发票审批详情</h3></div>
  5156. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  5157. <tr>
  5158. <th class="taC" width="150">发票审批</th><td><textarea name="opinion" style="width:98%" placeholder="在这写下您的审批意见,选填。"></textarea></td>
  5159. </tr>
  5160. <tr>
  5161. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5162. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5163. </tr>
  5164. <tr>
  5165. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5166. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5167. </tr>
  5168. <tr>
  5169. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5170. </td>
  5171. </tr>
  5172. <tr>
  5173. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5174. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5175. </tr>
  5176. <tr>
  5177. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5178. </tr></tbody></table>';
  5179. if ($detail ['invoiceType'] == 0)
  5180. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5181. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5182. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5183. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5184. </tr>';
  5185. else
  5186. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5187. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5188. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5189. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5190. ';
  5191. $html .= '<tr>
  5192. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5193. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5194. </tr>
  5195. <tr>
  5196. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5197. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5198. </tr></tbody></table>';
  5199. if ($detail ['doPost'] == 1) {
  5200. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5201. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5202. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5203. </tr><tr>
  5204. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5205. </tr><tr>
  5206. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5207. </tr>
  5208. ';
  5209. if ($detail ['expressCom'] == 'SF')
  5210. $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>';
  5211. else
  5212. $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>';
  5213. $html .= '</tbody></table>';
  5214. }
  5215. if (! empty ( $invoiceOperationLogList )) {
  5216. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  5217. foreach ( $invoiceOperationLogList as $key => $value ) {
  5218. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5219. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5220. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5221. if ($value ['status'] == 2) {
  5222. $html .= '<span class="colGreen">同意</span>';
  5223. } elseif ($value ['status'] == 3) {
  5224. $html .= '<span class="colOrange">退回</span>';
  5225. } elseif ($value ['status'] == 5) {
  5226. $html .= '<span class="colGreen">打印</span>';
  5227. } elseif ($value ['status'] == 4) {
  5228. $html .= '<span class="colRed">终止</span>';
  5229. }
  5230. $html .= $value ['operation'] . '</p></blockquote>';
  5231. }
  5232. }
  5233. $html .= '</td></tr></tbody></table>';
  5234. }
  5235. $html .= '</div><div class="modal-footer">
  5236. <a href="javascript:void(0)" node-approval="approval" diss-data="2" class="button btn-done" data-placement="top" data-toggle="ctooltip" >同意</a>
  5237. <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>
  5238. <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>
  5239. <a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>
  5240. </form>
  5241. <script type="text/javascript">
  5242. $("a[node-approval^=\'approval\']").click(function() {
  5243. $("input[name=\'status\']").val($(this).attr("diss-data"));
  5244. $("form[name=\'invoiceApproval\']").submit();
  5245. });
  5246. </script>
  5247. ';
  5248. }
  5249. echo json_encode ( array (
  5250. 'status' => 1,
  5251. 'html' => $html
  5252. ) );
  5253. die ();
  5254. }
  5255. /**
  5256. * 获得审批发票分页数据
  5257. */
  5258. function ajaxGetinvoiceApprovalAchieve() {
  5259. Doo::loadModel ( 'invoice' );
  5260. $invoice = new invoice ();
  5261. Doo::loadModel ( 'staff' );
  5262. $staff = new staff ();
  5263. Doo::loadClass ( 'XDeode' );
  5264. $XDeode = new XDeode ( 5 );
  5265. Doo::loadModel ( 'invoiceTraining' );
  5266. $invoiceTraining = new invoiceTraining ();
  5267. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  5268. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5269. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5270. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5271. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5272. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  5273. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  5274. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  5275. $MebSea = $this->get_args ( 'search' );
  5276. $MebSea = $MebSea ['value'];
  5277. $page_size = $length;
  5278. $con = '';
  5279. if ($status == 'ALL')
  5280. $con = ' (status=1 or status=2 or status=3 or status=4) and isDelete=0 ';
  5281. elseif ($status == 'PEND')
  5282. $con = ' isDelete=0 and status=1';
  5283. elseif ($status == 'APPROVED')
  5284. $con = ' isDelete=0 and status=2';
  5285. if ($invoiceType == 'ORDINARY')
  5286. $con .= ' and invoiceType=0 ';
  5287. elseif ($invoiceType == 'SPECIAL')
  5288. $con .= ' and invoiceType=1 ';
  5289. if ($invoiceTrain == 'ORDINARY')
  5290. $con .= ' and trainId=0 ';
  5291. elseif ($invoiceTrain == 'TRAIN')
  5292. $con .= ' and trainId!=0 ';
  5293. if ($invoiceTrainName != 'ALL') {
  5294. $trainId = $XDeode->decode ( $invoiceTrainName );
  5295. if (is_numeric ( $trainId ))
  5296. $con .= ' and trainId =' . $trainId;
  5297. }
  5298. $dateArr = explode ( ':', $date );
  5299. $D1 = $dateString = '';
  5300. $D2 = '';
  5301. if (! empty ( $date )) {
  5302. $D1 = $dateArr [0];
  5303. if (isset ( $dateArr [1] ))
  5304. $D2 = $dateArr [1];
  5305. else
  5306. $D2 = '';
  5307. $dateString = $D1 . " : " . $D2;
  5308. }
  5309. if (! empty ( $D1 ) && ! empty ( $D2 ))
  5310. $con .= ' and approvalTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  5311. elseif (! empty ( $D1 ) && empty ( $D2 ))
  5312. $con .= ' and approvalTime like "%' . $D1 . '%" ';
  5313. if (! empty ( $MebSea ))
  5314. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceSerial like "%' . $MebSea . '%" )';
  5315. // /
  5316. $pageinfo ['page'] = array (
  5317. 'previous' => ''
  5318. );
  5319. $sql = ' ' . $con;
  5320. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", '', "" );
  5321. $limit = $page . ',' . $page_size;
  5322. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  5323. $approvalList = array ();
  5324. $html = '<script type="text/javascript">
  5325. </script>';
  5326. // 结算结束不能修改方式
  5327. Doo::loadModel ( 'receipt' );
  5328. $receipt = new receipt ();
  5329. foreach ( $list as $key => $value ) {
  5330. $irDetail = array ();
  5331. // 结算方式
  5332. $receiptDetail = array ();
  5333. if ($value ['trainId'] != 0) {
  5334. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $value ['trainId'] );
  5335. }
  5336. if (! empty ( $receiptDetail )) {
  5337. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9) {
  5338. array_push ( $irDetail, '' );
  5339. } else {
  5340. if ($value ['status'] == 1 && $value ['pendingApprovals'] == $this->staff [0] ['sid']) {
  5341. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoiceApproval(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">审批发票</a>' );
  5342. } elseif ($value ['status'] == 2) {
  5343. array_push ( $irDetail, '<a href="#editPay" class="fnSettlementType" data-iidKey="' . $value ['iidKeyK'] . '" data-toggle="modal">结算方式</a>' );
  5344. } else
  5345. array_push ( $irDetail, '' );
  5346. }
  5347. } else {
  5348. if ($value ['status'] == 2) {
  5349. array_push ( $irDetail, '<a href="#editPay" class="fnSettlementType" data-iidKey="' . $value ['iidKeyK'] . '" data-toggle="modal">结算方式</a>' );
  5350. } else
  5351. array_push ( $irDetail, '' );
  5352. }
  5353. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  5354. if ($value ['invoiceType'] == 1)
  5355. array_push ( $irDetail, $value ['invoiceCompany'] );
  5356. else
  5357. array_push ( $irDetail, $value ['invoiceTitle'] );
  5358. array_push ( $irDetail, $value ['TIN'] );
  5359. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  5360. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  5361. array_push ( $irDetail, $value ['remark'] );
  5362. array_push ( $irDetail, $value ['invoiceElement'] );
  5363. array_push ( $irDetail, $value ['invoiceQuantity'] );
  5364. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  5365. if ($value ['invoiceType'] == 1) {
  5366. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  5367. } else {
  5368. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  5369. }
  5370. if ($value ['settlementType'] == 0) {
  5371. array_push ( $irDetail, '软件销售' );
  5372. } else {
  5373. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $value ['trainId'] );
  5374. array_push ( $irDetail, $itDetail ['trainName'] );
  5375. }
  5376. array_push ( $irDetail, $value ['recipients'] . $value ['recipientsPhone'] );
  5377. array_push ( $irDetail, $value ['recipientsAddress'] );
  5378. array_push ( $irDetail, $value ['mailItems'] );
  5379. array_push ( $irDetail, $value ['userName'] . '&nbsp;' . $value ['date'] );
  5380. $fchtml = $value ['OL'] ['operation'];
  5381. if (count ( $list ) == $page_size)
  5382. $fchtml = $value ['OL'] ['operation'] . $html;
  5383. // 最后的审批意见
  5384. array_push ( $irDetail, $fchtml );
  5385. if ($value ['status'] == 2)
  5386. array_push ( $irDetail, '<span class="colGreen">同意</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5387. elseif ($value ['status'] == 3)
  5388. array_push ( $irDetail, '<span class="colOrange">退回</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5389. elseif ($value ['status'] == 4)
  5390. array_push ( $irDetail, '<span class="colRed">终止</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5391. else
  5392. array_push ( $irDetail, '' );
  5393. array_push ( $approvalList, $irDetail );
  5394. }
  5395. // $approvalListJson = json_encode ( $approvalList );
  5396. $recordsFiltered = $pageinfo ['total_data'];
  5397. echo json_encode ( array (
  5398. "draw" => intval ( $draw ),
  5399. "recordsTotal" => intval ( $pageinfo ['total_data'] ),
  5400. "recordsFiltered" => intval ( $recordsFiltered ),
  5401. "data" => $approvalList
  5402. ), JSON_UNESCAPED_UNICODE );
  5403. }
  5404. /**
  5405. * 审批发票查看更多--重构
  5406. */
  5407. function invoiceApprovalAchieve() {
  5408. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'ALL';
  5409. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5410. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5411. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5412. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5413. Doo::loadModel ( 'invoiceTraining' );
  5414. $invoiceTraining = new invoiceTraining ();
  5415. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  5416. $this->data ['trainList'] = $trainList;
  5417. $this->data ['dateString'] = $date;
  5418. $this->data ['status'] = $status;
  5419. $this->data ['invoiceType'] = $invoiceType;
  5420. $this->data ['invoiceTrain'] = $invoiceTrain;
  5421. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  5422. $this->data ['memu'] = "invoice";
  5423. $this->data ['staff'] = $this->staff;
  5424. $this->data ['receiptMemu'] = 'invoiceApproval';
  5425. $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  5426. }
  5427. function invoiceTAchieve() {
  5428. Doo::loadModel ( 'invoice' );
  5429. $invoice = new invoice ();
  5430. Doo::loadClass ( 'XDeode' );
  5431. $XDeode = new XDeode ( 5 );
  5432. Doo::loadModel ( 'staff' );
  5433. $staff = new staff ();
  5434. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  5435. $page_size = 12;
  5436. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5437. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  5438. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5439. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5440. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5441. Doo::loadModel ( 'invoiceTraining' );
  5442. $invoiceTraining = new invoiceTraining ();
  5443. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  5444. $get = "/" . $date;
  5445. $con = '';
  5446. if ($date == 'MONTHO')
  5447. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  5448. elseif ($date == 'MONTHT')
  5449. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  5450. elseif ($date == 'MONTHY')
  5451. $con = ' and YEAR(updateTime) = YEAR(NOW())'; // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  5452. if ($invoiceType == 'ORDINARY')
  5453. $con .= ' and invoiceType=0 ';
  5454. elseif ($invoiceType == 'SPECIAL')
  5455. $con .= ' and invoiceType=1 ';
  5456. if ($invoiceTrain == 'ORDINARY')
  5457. $con .= ' and trainId=0 ';
  5458. elseif ($invoiceTrain == 'TRAIN')
  5459. $con .= ' and trainId!=0 ';
  5460. if ($invoiceTrainName != 'ALL') {
  5461. $trainId = $XDeode->decode ( $invoiceTrainName );
  5462. if (is_numeric ( $trainId ))
  5463. $con .= ' and trainId =' . $trainId;
  5464. }
  5465. if (! empty ( $MebSea )) {
  5466. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  5467. $get .= "/" . $MebSea;
  5468. }
  5469. $pageinfo ['page'] = array (
  5470. 'previous' => ''
  5471. );
  5472. $sql = "";
  5473. $action = "";
  5474. if ($this->ACTION == 'invoicePrintAchieve') {
  5475. $sql = "status=2 and printStatus=1 and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  5476. $action = "invoicePrintAchieve";
  5477. } elseif ($this->ACTION == 'invoicePostAchieve') {
  5478. // and untreadStatus=0
  5479. $sql = "postStatus=1 and doPost=1 and status=2 and isDelete=0" . $con;
  5480. $action = "invoicePostAchieve";
  5481. } elseif ($this->ACTION == 'invoiceUntreadAchieve') { // printStatus=1 and
  5482. $sql = " untreadStatus=2 and status=2 " . $con;
  5483. $action = "invoiceUntreadAchieve";
  5484. }
  5485. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  5486. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5487. $this->data ['MebSeaEn'] = $MebSea;
  5488. $this->data ['MebSea'] = urlencode ( $MebSea );
  5489. $this->data ['get'] = $get;
  5490. $this->data ['page'] = $pageinfo;
  5491. $this->data ['trainList'] = $trainList;
  5492. $this->data ['invoiceType'] = $invoiceType;
  5493. $this->data ['invoiceTrain'] = $invoiceTrain;
  5494. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  5495. $this->data ['date'] = $date;
  5496. $this->data ['memu'] = "invoice";
  5497. $this->data ['staff'] = $this->staff;
  5498. if ($this->ACTION == 'invoicePrintAchieve') {
  5499. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  5500. $this->data ['receiptMemu'] = 'invoicePrint';
  5501. $this->data ['list'] = $list;
  5502. $this->render ( "/admin/invoicePrintAchieve", $this->data );
  5503. } elseif ($this->ACTION == 'invoicePostAchieve') {
  5504. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  5505. Doo::loadModel ( 'express' );
  5506. $express = new express ();
  5507. $expressList = $express->getExpressByAll ();
  5508. $this->data ['expressList'] = $expressList;
  5509. $this->data ['receiptMemu'] = 'invoicePost';
  5510. $this->data ['list'] = $list;
  5511. $this->render ( "/admin/invoicePostAchieve", $this->data );
  5512. } elseif ($this->ACTION == 'invoiceUntreadAchieve') {
  5513. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  5514. $this->data ['receiptMemu'] = 'invoiceUntread';
  5515. $this->data ['list'] = $list;
  5516. $this->render ( "/admin/invoiceUntreadAchieve", $this->data );
  5517. }
  5518. }
  5519. /**
  5520. * 公司应收款
  5521. */
  5522. function invoiceAggregateCompanyDetail() {
  5523. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  5524. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  5525. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : 'ALL';
  5526. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  5527. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  5528. Doo::loadClass ( 'XDeode' );
  5529. $XDeode = new XDeode ( 5 );
  5530. Doo::loadModel ( 'invoice' );
  5531. $invoice = new invoice ();
  5532. Doo::loadModel ( 'staff' );
  5533. $staff = new staff ();
  5534. Doo::loadModel ( "invoiceCompanyManage" );
  5535. $invoiceCompanyManage = new invoiceCompanyManage ();
  5536. Doo::loadModel ( 'L_category' );
  5537. $category = new L_category ();
  5538. $sid = '';
  5539. if (! empty ( $sidKey )) {
  5540. $sid = $XDeode->decode ( $sidKey );
  5541. }
  5542. $staffDetail = $staff->getStaffBySid ( $sid );
  5543. $cid = '';
  5544. if (! empty ( $cidKey )) {
  5545. $cid = $XDeode->decode ( $cidKey );
  5546. }
  5547. $imcStaff = $invoiceCompanyManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  5548. $cidList = array ();
  5549. foreach ( $imcStaff as $key => $value ) {
  5550. array_push ( $cidList, $value ['cid'] );
  5551. }
  5552. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  5553. $cidString = implode ( ',', $cidList );
  5554. if (empty ( $cid ))
  5555. $staffList = $staff->getStaffInCid ( $cidString );
  5556. else
  5557. $staffList = $staff->getStaffByCidAll ( $cid ); //
  5558. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  5559. $page_size = 25;
  5560. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5561. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  5562. $con = ' status=2 and untreadStatus!=2 ';
  5563. $statisticsCon = '';
  5564. if (! empty ( $year ) && is_numeric ( $year ))
  5565. $con .= ' and Year(printTime)=' . $year . '';
  5566. if (! empty ( $month ) && is_numeric ( $month ))
  5567. $con .= ' and Month(printTime)="' . $month . '" ';
  5568. if ($status == 'UNRECORD')
  5569. $con .= ' and printStatus=1 and untreadStatus=0';
  5570. elseif ($status == 'RECORD')
  5571. $con .= ' and printStatus=1 and untreadStatus=3';
  5572. elseif ($status == 'BOUNCED')
  5573. $con .= ' and untreadStatus=2';
  5574. elseif ($status == 'PARTRECORD')
  5575. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  5576. elseif ($status == 'All') {
  5577. $con .= ' and printStatus=1 and ( untreadStatus=0 or untreadStatus=3 )';
  5578. }
  5579. if (! empty ( $sid ) && is_numeric ( $sid ))
  5580. $con .= ' and sid=' . $sid;
  5581. if (! empty ( $cid ) && is_numeric ( $cid ))
  5582. $con .= ' and cid=' . $cid;
  5583. else
  5584. $con .= ' and cid in (' . $cidString . ')';
  5585. // 开票内容筛选
  5586. if (! empty ( $invoiceElement ) && $invoiceElement != 'ALL') {
  5587. $con .= ' and invoiceElement="' . $invoiceElement . '"';
  5588. }
  5589. $get = "/" . $status . "?cidKey=" . $cidKey . "&sidKey=" . $sidKey . "&year=" . $year . "&month=" . $month . "&invoiceElement=" . $invoiceElement;
  5590. if (! empty ( $MebSea )) {
  5591. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  5592. }
  5593. $pageinfo ['page'] = array (
  5594. 'previous' => ''
  5595. );
  5596. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateCompanyDetail", $get, "" );
  5597. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5598. // 应收款合计
  5599. $ics = $invoice->getInvoiceCompanyStatistics ( $con );
  5600. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  5601. $monthHtml = "";
  5602. if ($year != "ALL") {
  5603. for($i = 1; $i <= 12; $i ++) {
  5604. if ($i == $month)
  5605. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  5606. else
  5607. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  5608. }
  5609. }
  5610. $this->data ['monthHtml'] = $monthHtml;
  5611. $this->data ['year'] = $year;
  5612. $this->data ['month'] = $month;
  5613. $this->data ['ics'] = $ics;
  5614. $this->data ['cidKey'] = $cidKey;
  5615. $this->data ['sid'] = $sid;
  5616. $this->data ['staffDetail'] = $staffDetail;
  5617. $this->data ['staffList'] = $staffList;
  5618. $this->data ['MebSeaEn'] = $MebSea;
  5619. $this->data ['MebSea'] = urlencode ( $MebSea );
  5620. $this->data ['invoiceDetail'] = array (
  5621. 'invoiceElement' => $invoiceElement
  5622. );
  5623. $this->data ['page'] = $pageinfo;
  5624. $this->data ['get'] = $get;
  5625. $this->data ['list'] = $list;
  5626. $this->data ['status'] = $status;
  5627. $this->data ['categoryList'] = $categoryList;
  5628. $this->data ['memu'] = "invoice";
  5629. $this->data ['staff'] = $this->staff;
  5630. $this->data ['receiptMemu'] = 'invoiceAggregateCompanyDetail';
  5631. $this->render ( "/admin/invoiceAggregateCompanyDetail", $this->data );
  5632. }
  5633. /**
  5634. * 获取一条收款信息
  5635. */
  5636. function ajaxGetInvoiceReceivables() {
  5637. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  5638. Doo::loadModel ( 'invoiceReceivables' );
  5639. $invoiceReceivables = new invoiceReceivables ();
  5640. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5641. echo json_encode ( array (
  5642. 'status' => 1,
  5643. 'detail' => $detail
  5644. ) );
  5645. }
  5646. /**
  5647. * 异步获取办事处用户
  5648. */
  5649. function ajaxGetStaffByCategory() {
  5650. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "";
  5651. Doo::loadModel ( 'staff' );
  5652. $staff = new staff ();
  5653. if ($cid == "PUBLIC") {
  5654. echo json_encode ( array (
  5655. 'status' => 1,
  5656. 'html' => '<option value="PUBLIC">办事处待认领款项</option>'
  5657. ) );
  5658. die ();
  5659. }
  5660. if (! is_numeric ( $cid )) {
  5661. echo json_encode ( array (
  5662. 'status' => 0,
  5663. 'msg' => 'illegal request'
  5664. ) );
  5665. die ();
  5666. }
  5667. $staffList = $staff->getStaffByCid ( $cid );
  5668. $html = '<option value="PUBLIC">办事处待认领款项</option>';
  5669. foreach ( $staffList as $key => $value ) {
  5670. $html .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  5671. }
  5672. echo json_encode ( array (
  5673. 'status' => 1,
  5674. 'html' => $html
  5675. ) );
  5676. }
  5677. /**
  5678. * 异步获取一条发票的邮寄信息
  5679. */
  5680. function ajaxGetInvoicePostDetail() {
  5681. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  5682. Doo::loadModel ( 'invoice' );
  5683. $invoice = new invoice ();
  5684. $iid = $invoice->authcode ( $iid );
  5685. Doo::loadModel ( 'express' );
  5686. $express = new express ();
  5687. $expressList = $express->getExpressByAll ();
  5688. if (! is_numeric ( $iid )) {
  5689. echo json_encode ( array (
  5690. 'status' => 0,
  5691. 'msg' => 'illegal request'
  5692. ) );
  5693. die ();
  5694. }
  5695. $select = "iid,recipients,recipientsPhone,recipientsAddress,mailItems,expressCompany,expressNumber,actualItems";
  5696. $invoiceDetail = $invoice->getInvoiceByIid ( $iid, $select );
  5697. $html = "";
  5698. foreach ( $expressList as $key => $value ) {
  5699. if ($value ['company'] == $invoiceDetail ['expressCompany'])
  5700. $html .= '<option selected value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  5701. else
  5702. $html .= '<option value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  5703. }
  5704. $invoiceDetail ['eaHtml'] = $html;
  5705. echo json_encode ( array (
  5706. 'status' => 1,
  5707. 'invoiceDetail' => $invoiceDetail
  5708. ) );
  5709. }
  5710. /**
  5711. *
  5712. * @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 ) ); }
  5713. */
  5714. /**
  5715. *
  5716. * @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 ) ); }
  5717. */
  5718. /**
  5719. * 我的收款中 选择哪个发票入账,进行金额判断
  5720. */
  5721. function ajaxCompareInvoicePrice() {
  5722. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  5723. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  5724. Doo::loadModel ( 'invoice' );
  5725. $invoice = new invoice ();
  5726. Doo::loadModel ( 'invoiceReceivables' );
  5727. $invoiceReceivables = new invoiceReceivables ();
  5728. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  5729. $keyList = explode ( ';', $claimKey );
  5730. $receivablesPrice = 0;
  5731. foreach ( $keyList as $key => $value ) {
  5732. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $value );
  5733. $receivablesPrice += $detailM ['receivablesPrice'];
  5734. }
  5735. if ($receivablesPrice > $detail ['invoicePrice']) {
  5736. $price = $receivablesPrice - $detail ['invoicePrice'];
  5737. echo json_encode ( array (
  5738. 'status' => 1,
  5739. 'price' => $price
  5740. ) );
  5741. } else
  5742. echo json_encode ( array (
  5743. 'status' => 2
  5744. ) );
  5745. }
  5746. /**
  5747. * 获得打印发票
  5748. */
  5749. function ajaxGetInvoiceInfoByPrint() {
  5750. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5751. if (empty ( $serial )) {
  5752. echo json_encode ( array (
  5753. 'status' => 2,
  5754. 'msg' => 'illegal request'
  5755. ) );
  5756. die ();
  5757. }
  5758. Doo::loadModel ( 'invoice' );
  5759. $invoice = new invoice ();
  5760. Doo::loadModel ( 'invoiceOperationLog' );
  5761. $invoiceOperationLog = new invoiceOperationLog ();
  5762. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5763. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5764. Doo::loadModel ( 'invoicePaper' );
  5765. $invoicePaper = new invoicePaper ();
  5766. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $detail ['invoiceType'] );
  5767. if (empty ( $detail ))
  5768. $html = '';
  5769. else {
  5770. $html = '
  5771. <form action="/invoicePrintDo" method="post" name="invoicePrint" class="nice-validator n-yellow" onSubmit="return checkPrintForm()" novalidate="novalidate">
  5772. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  5773. <input type="hidden" name="invoicePrintType" value="invoicePrintType">
  5774. <div class="modal-dialog modal-lg">
  5775. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  5776. <div class="modal-body saeaList">
  5777. <table class="table table-bordered table-condensed"><tbody>
  5778. <tr>
  5779. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5780. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5781. </tr>
  5782. <tr>
  5783. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5784. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5785. </tr>
  5786. <tr>
  5787. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5788. </td>
  5789. </tr>
  5790. <tr>
  5791. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5792. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5793. </tr>
  5794. <tr>
  5795. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5796. </tr></tbody></table>';
  5797. if ($detail ['invoiceType'] == 0)
  5798. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5799. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5800. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5801. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5802. </tr>';
  5803. else
  5804. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5805. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5806. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5807. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5808. ';
  5809. $html .= '<tr>
  5810. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5811. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5812. </tr>
  5813. <tr>
  5814. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5815. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5816. </tr></tbody></table>';
  5817. if ($detail ['doPost'] == 1)
  5818. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5819. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5820. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5821. </tr><tr>
  5822. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5823. </tr><tr>
  5824. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5825. </tr></tbody></table>';
  5826. if (! empty ( $invoiceOperationLogList )) {
  5827. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th><th class="taC">发票打印</th></tr><tr><td>';
  5828. foreach ( $invoiceOperationLogList as $key => $value ) {
  5829. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5830. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5831. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5832. if ($value ['status'] == 2) {
  5833. $html .= '<span class="colGreen">同意</span>';
  5834. } elseif ($value ['status'] == 3) {
  5835. $html .= '<span class="colOrange">退回</span>';
  5836. } elseif ($value ['status'] == 5) {
  5837. $html .= '<span class="colGreen">打印</span>';
  5838. } elseif ($value ['status'] == 4) {
  5839. $html .= '<span class="colRed">终止</span>';
  5840. }
  5841. $html .= $value ['operation'] . '</p></blockquote>';
  5842. }
  5843. }
  5844. $html .= '</td>
  5845. <td><span class="colRed">*</span>
  5846. <select name="invoiceNo" id="invoiceNo" style="width:97%">';
  5847. foreach ( $invoicePaperList as $key => $value ) {
  5848. $html .= '<option value="' . $value ['ipidKey'] . '">No.' . $value ['invoiceNo'] . '</option>';
  5849. }
  5850. $html .= '</select>
  5851. <span class="red" id="p-msg"></span>
  5852. </td>
  5853. </tr></tbody></table>';
  5854. }
  5855. $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>
  5856. </div></div></form>
  5857. <link rel=stylesheet href="' . WEB_SITE_GLOBAL . 'css/jquery.validator.css">
  5858. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/jquery.validator.min.js"></script>
  5859. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/zh-CN.js"></script>
  5860. <script src="' . WEB_SITE_GLOBAL . 'js/invoice.validator.js"></script>
  5861. ';
  5862. }
  5863. echo json_encode ( array (
  5864. 'status' => 1,
  5865. 'html' => $html
  5866. ) );
  5867. die ();
  5868. }
  5869. /**
  5870. * @ 获得与我有关收款数据 --需求变更 废弃 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 ) ); }
  5871. */
  5872. function ajaxGetInvoiceInfoByType() {
  5873. $type = $this->get_args ( 'type' ) ? $this->get_args ( 'type' ) : "";
  5874. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5875. $loss = $this->get_args ( 'loss' ) ? $this->get_args ( 'loss' ) : false;
  5876. if (empty ( $serial )) {
  5877. echo json_encode ( array (
  5878. 'status' => 2,
  5879. 'msg' => 'illegal request'
  5880. ) );
  5881. die ();
  5882. }
  5883. if ($type == 'INVOICE') {
  5884. Doo::loadModel ( 'invoice' );
  5885. $invoice = new invoice ();
  5886. Doo::loadModel ( 'invoiceOperationLog' );
  5887. $invoiceOperationLog = new invoiceOperationLog ();
  5888. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5889. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5890. if (empty ( $detail ))
  5891. $html = '';
  5892. else {
  5893. $html = '
  5894. <div class="modal-dialog modal-lg">
  5895. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  5896. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  5897. <tr>
  5898. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5899. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5900. </tr>
  5901. <tr>
  5902. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5903. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5904. </tr>
  5905. <tr>
  5906. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5907. </td>
  5908. </tr>
  5909. <tr>
  5910. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5911. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5912. </tr>
  5913. <tr>
  5914. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5915. </tr>';
  5916. if ($detail ['settlementType'] == 1)
  5917. $html .= '<tr>
  5918. <th class="taC" width="150">结算方式</th><td colspan="3">培训班(<a href="/invoiceTrainingDetail/' . $detail ['invoiceTraining'] ['trainingKey'] . '.html" target="_blank">' . $detail ['invoiceTraining'] ['trainName'] . '</a>)</td>
  5919. </tr>';
  5920. else
  5921. $html .= '<tr>
  5922. <th class="taC" width="150">结算方式</th><td colspan="3">软件销售</td>
  5923. </tr>';
  5924. $html .= ' </tbody></table>';
  5925. if ($detail ['invoiceType'] == 0)
  5926. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5927. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5928. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5929. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5930. </tr>';
  5931. else
  5932. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5933. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5934. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5935. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5936. ';
  5937. $html .= '<tr>
  5938. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5939. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5940. </tr>
  5941. <tr>
  5942. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5943. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5944. </tr></tbody></table>';
  5945. if ($detail ['doPost'] == 1) {
  5946. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5947. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5948. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5949. </tr><tr>
  5950. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5951. </tr><tr>
  5952. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5953. </tr>
  5954. ';
  5955. if ($detail ['expressCom'] == 'SF')
  5956. $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>';
  5957. else
  5958. $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>';
  5959. $html .= '</tbody></table>';
  5960. }
  5961. if (! empty ( $invoiceOperationLogList )) {
  5962. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  5963. foreach ( $invoiceOperationLogList as $key => $value ) {
  5964. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5965. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5966. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5967. if ($value ['status'] == 2) {
  5968. $html .= '<span class="colGreen">同意</span>';
  5969. } elseif ($value ['status'] == 3) {
  5970. $html .= '<span class="colOrange">退回</span>';
  5971. } elseif ($value ['status'] == 5) {
  5972. $html .= '<span class="colGreen">打印</span>';
  5973. } elseif ($value ['status'] == 4) {
  5974. $html .= '<span class="colRed">终止</span>';
  5975. }
  5976. $html .= $value ['operation'] . '</p></blockquote>';
  5977. }
  5978. }
  5979. $html .= '</td></tr></tbody></table>';
  5980. }
  5981. $html .= '</div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  5982. }
  5983. echo json_encode ( array (
  5984. 'status' => 1,
  5985. 'html' => $html
  5986. ) );
  5987. die ();
  5988. } elseif ($type == 'RECEIVABLES') {
  5989. Doo::loadModel ( 'invoiceReceivables' );
  5990. $invoiceReceivables = new invoiceReceivables ();
  5991. Doo::loadModel ( 'invoiceRefund' );
  5992. $invoiceRefund = new invoiceRefund ();
  5993. $detail = $invoiceReceivables->getInvoiceReceivablesByIrsid ( $serial );
  5994. $ireList = $invoiceRefund->getInvoiceRefundIrid ( $detail ['irid'] );
  5995. if (empty ( $detail ))
  5996. $html = '';
  5997. else {
  5998. $html = '<div class="modal-dialog modal-lg"><div class="modal-content"><div class="modal-header"><h3>收款单详情</h3></div><div class="modal-body saeaList">
  5999. <table class="table table-bordered table-condensed">
  6000. <tbody><tr>
  6001. <th class="taC">收款流水号</th><td>' . $detail ['receivablesSerial'] . '</td>
  6002. <th class="taC">录入收款</th><td>' . $detail ['inputStaff'] . ' ' . $detail ['date'] . '</td>
  6003. </tr><tr>
  6004. <th class="taC">收款金额</th><td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  6005. <th class="taC">收款信息</th><td>' . $detail ['receivablesMessage'] . '</td>
  6006. </tr>
  6007. <tr>
  6008. <th class="taC">收款银行</th><td>' . $detail ['receivablesBank'] . '</td>
  6009. <th class="taC">银行到账</th><td>' . $detail ['receivablesDate'] . '</td>
  6010. </tr>
  6011. <tr>
  6012. <th class="taC">认领收款</th><td colspan="3">' . $detail ['inputStaff'] . ' 转入 ' . $detail ['username'] . ' ' . $detail ['confirmTime'] . '</td>
  6013. </tr>
  6014. </tbody></table>';
  6015. if (! empty ( $ireList )) {
  6016. $html .= '
  6017. <table class="table table-bordered table-condensed"><tbody><tr><th class="taC" colspan="5">退款记录</th></tr>
  6018. <tr>
  6019. <th class="taC">退款单位名称</th>
  6020. <th class="taC">退款的账号</th>
  6021. <th class="taC">退款金额</th>
  6022. <th class="taC">退款</th>
  6023. <th class="taC">备注</th>
  6024. </tr>
  6025. ';
  6026. foreach ( $ireList as $key => $value ) {
  6027. $refundLogList = explode ( "<br/>", $value ['refundLog'] );
  6028. $html .= '<tr>
  6029. <td>' . $value ['refundCompany'] . '</td>
  6030. <td>' . $value ['refundNumber'] . '</td>
  6031. <td><b class="colRed">¥' . $value ['refundPrice'] . '</b></td>
  6032. <td>' . $refundLogList [0] . $refundLogList [2] . '</td>
  6033. <td>' . $value ['refundRemarks'] . '</td>
  6034. </tr>
  6035. ';
  6036. }
  6037. }
  6038. $html .= '</tbody></table></div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  6039. }
  6040. echo json_encode ( array (
  6041. 'status' => 1,
  6042. 'html' => $html
  6043. ) );
  6044. die ();
  6045. } elseif ($type == 'IRTC') {
  6046. Doo::loadModel ( 'invoice' );
  6047. $invoice = new invoice ();
  6048. Doo::loadModel ( 'invoiceOperationLog' );
  6049. $invoiceOperationLog = new invoiceOperationLog ();
  6050. Doo::loadModel ( 'invoiceReceivables' );
  6051. $invoiceReceivables = new invoiceReceivables ();
  6052. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  6053. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  6054. if (empty ( $detail ))
  6055. $html = '';
  6056. else {
  6057. $receivablesPriceedHtml = '';
  6058. $receivablesPrice = $detail ['invoicePrice'];
  6059. if (! empty ( $detail ['irid'] )) {
  6060. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $detail ['irid'] );
  6061. if (empty ( $irList ))
  6062. $irList [0] ['sumPrice'] = 0;
  6063. $balance = $detail ['invoicePrice'] - $irList [0] ['sumPrice'];
  6064. $receivablesPriceedHtml = '<table class="table table-bordered table-condensed"><tbody><tr>
  6065. <th class="taC">已入账金额</th><td><b class="colGreen" style="font-size:18px">¥' . $irList [0] ['sumPrice'] . '</b></td>
  6066. <th class="taC">剩余入账金额</th><td><b class="colRed" style="font-size:18px">¥' . $balance . '</b></td>
  6067. </tr></tbody></table>';
  6068. $receivablesPrice = $balance;
  6069. }
  6070. if ($loss)
  6071. $detail ['invoicePrice'] = - $detail ['invoicePrice'];
  6072. $html = $receivablesPriceedHtml . '
  6073. <table class="table table-bordered table-condensed"><tbody>
  6074. <tr>
  6075. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  6076. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  6077. </tr>
  6078. <tr>
  6079. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  6080. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  6081. </tr>
  6082. <tr>
  6083. <th class="taC" width="150">发票备注</th><td colspan="3">' . $detail ['remark'] . '</td>
  6084. </tr>
  6085. <tr>
  6086. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  6087. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  6088. </tr>
  6089. <tr>
  6090. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  6091. </tr></tbody></table>';
  6092. if ($detail ['invoiceType'] == 0) {
  6093. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6094. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  6095. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  6096. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  6097. </tr>';
  6098. $receivablesMessage = $detail ['invoiceTitle'];
  6099. } else {
  6100. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6101. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  6102. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  6103. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  6104. ';
  6105. $receivablesMessage = $detail ['invoiceCompany'];
  6106. }
  6107. $html .= '<tr>
  6108. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  6109. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  6110. </tr>
  6111. <tr>
  6112. <th class="taC">开户银行</th><td>' . $detail ['bankAccount'] . '</td>
  6113. <th class="taC">银行账号</th><td>' . $detail ['bank'] . '</td>
  6114. </tr></tbody></table>';
  6115. if ($detail ['doPost'] == 1)
  6116. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  6117. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  6118. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  6119. </tr><tr>
  6120. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  6121. </tr><tr>
  6122. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  6123. </tr></tbody></table>';
  6124. if (! empty ( $invoiceOperationLogList )) {
  6125. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  6126. foreach ( $invoiceOperationLogList as $key => $value ) {
  6127. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  6128. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  6129. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  6130. if ($value ['status'] == 2) {
  6131. $html .= '<span class="colGreen">同意</span>';
  6132. } elseif ($value ['status'] == 3) {
  6133. $html .= '<span class="colOrange">退回</span>';
  6134. } elseif ($value ['status'] == 5) {
  6135. $html .= '<span class="colGreen">打印</span>';
  6136. }
  6137. $html .= $value ['operation'] . '</p></blockquote>';
  6138. }
  6139. }
  6140. $html .= '</td></tr></tbody></table>';
  6141. }
  6142. }
  6143. echo json_encode ( array (
  6144. 'status' => 1,
  6145. 'html' => $html,
  6146. 'receivablesPrice' => $receivablesPrice,
  6147. 'receivablesMessage' => $receivablesMessage,
  6148. 'receivablesDate' => date ( "Y-m-d" ),
  6149. 'iidKey' => $serial
  6150. ) );
  6151. die ();
  6152. }
  6153. }
  6154. function ajaxGetInvoiceReceivablesByStaff() {
  6155. $postData = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : "";
  6156. if (empty ( $postData )) {
  6157. echo json_encode ( array (
  6158. 'status' => 2,
  6159. 'msg' => 'illegal request'
  6160. ) );
  6161. die ();
  6162. }
  6163. Doo::loadModel ( 'invoiceReceivables' );
  6164. $invoiceReceivables = new invoiceReceivables ();
  6165. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $postData );
  6166. if (empty ( $detail )) {
  6167. echo json_encode ( array (
  6168. 'status' => 2,
  6169. 'msg' => 'illegal request'
  6170. ) );
  6171. die ();
  6172. }
  6173. Doo::loadModel ( 'L_category' );
  6174. $lCategory = new L_category ();
  6175. Doo::loadModel ( 'staff' );
  6176. $staff = new staff ();
  6177. $staffList = $staff->getStaffByCid ( $detail ['cid'] );
  6178. $category = $lCategory->getCategory ();
  6179. $categoryHtml = '<option post-data="PUBLIC" value="PUBLIC" >公共待认领款项</option>';
  6180. $staffHtml = '<option value="PUBLIC">办事处待认领款项</option>';
  6181. foreach ( $category as $key => $value ) {
  6182. $categoryHtml .= '<option post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  6183. if ($value ['cid'] == $detail ['cid'])
  6184. $categoryHtml .= '<option selected post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  6185. }
  6186. foreach ( $staffList as $key => $value ) {
  6187. $staffHtml .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  6188. if ($value ['sid'] == $detail ['sid'])
  6189. $staffHtml .= '<option selected value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  6190. }
  6191. $rbankHtml = '<option value="广发银行珠海分行柠溪支行">广发银行珠海分行柠溪支行</option>';
  6192. echo json_encode ( array (
  6193. 'status' => 1,
  6194. 'categoryHtml' => $categoryHtml,
  6195. 'staffHtml' => $staffHtml,
  6196. 'rbankHtml' => $rbankHtml,
  6197. 'detail' => $detail
  6198. ) );
  6199. }
  6200. function ajaxGetInvoiceReceivablesByIrid() {
  6201. $irid = $this->get_args ( 'irid' ) ? $this->get_args ( 'irid' ) : "";
  6202. if (empty ( $irid )) {
  6203. echo json_encode ( array (
  6204. 'status' => 2,
  6205. 'msg' => 'illegal request'
  6206. ) );
  6207. die ();
  6208. }
  6209. Doo::loadModel ( 'invoiceReceivables' );
  6210. $invoiceReceivables = new invoiceReceivables ();
  6211. Doo::loadModel ( 'invoice' );
  6212. $invoice = new invoice ();
  6213. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid ); // 入账完成 待定 and postStatus=1
  6214. $flag = true;
  6215. $invoiceDetail = $invoice->getInvoiceByTitle ( $detail ['recepitTitleMark'], 'EXACTLY', " and status=2 and printStatus=1 and untreadStatus=0 ", $flag ); //
  6216. $bakDetail = array ();
  6217. if ($flag === false) {
  6218. array_push ( $bakDetail, $invoiceDetail );
  6219. $invoiceDetail = $bakDetail;
  6220. }
  6221. $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>
  6222. <tr>
  6223. <td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  6224. <td>' . $detail ['receivablesMessage'] . '</td>
  6225. <td>' . $detail ['receivablesBank'] . '<br>' . $detail ['receivablesDate'] . '</td>
  6226. <td>' . $detail ['title'] . '-' . $detail ['username'] . '<br>' . $detail ['confirmTime'] . '</td>
  6227. <td>' . $detail ['recepitTitleMark'] . '</td>
  6228. </tr></tbody></table>';
  6229. $isInvoice = false;
  6230. $invoiceHtml = '';
  6231. if (empty ( $invoiceDetail )) {
  6232. $isInvoice = true;
  6233. } else {
  6234. $invoiceHtml = '<table class="table table-bordered table-condensed">
  6235. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody>';
  6236. foreach ( $invoiceDetail as $key => $value ) {
  6237. $invoiceHtml .= '<tr>';
  6238. if (! empty ( $value ['invoiceType'] )) {
  6239. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  6240. } else {
  6241. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  6242. }
  6243. if (! empty ( $value ['invoiceType'] )) {
  6244. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  6245. } else {
  6246. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  6247. }
  6248. $invoiceHtml .= '
  6249. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  6250. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  6251. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir" data-ikey="' . $value ['iidKey'] . '" href="javascript:void(0)">入账</a></td>
  6252. </tr>
  6253. ';
  6254. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  6255. if (empty ( $irList ))
  6256. $irList [0] ['sumPrice'] = 0;
  6257. $balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  6258. $priceString = '';
  6259. if ($balance < $detail ['receivablesPrice']) {
  6260. $priceString = '收款金额超过开票金额,';
  6261. }
  6262. if ($balance > $detail ['receivablesPrice']) {
  6263. $priceString = '收款金额低于开票金额,';
  6264. }
  6265. }
  6266. $invoiceHtml .= '
  6267. <script>
  6268. $(\'a[bind-receivables^="ir"]\').click(function() {
  6269. var data = $(this).attr("data-ikey");
  6270. $("input[name=\'invoiceKey\']").val(data);
  6271. var invoiceKey=data;
  6272. if(invoiceKey==""){
  6273. alert("入账错误,请重新刷新页面");
  6274. return false;
  6275. }
  6276. if(window.confirm("' . $priceString . '确定入账吗?")){
  6277. $("#IBR").submit();
  6278. }else{
  6279. return false;
  6280. }
  6281. });
  6282. </script>
  6283. ';
  6284. $invoiceHtml .= '</tbody></table>';
  6285. }
  6286. echo json_encode ( array (
  6287. 'status' => 1,
  6288. 'irkey' => $detail ['iridEn'],
  6289. 'receivablesHtml' => $receivablesHtml,
  6290. 'isInvoice' => $isInvoice,
  6291. 'invoiceHtml' => $invoiceHtml
  6292. ) );
  6293. }
  6294. function ajaxGetInvoiceReceivablesByTitle() {
  6295. $title = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  6296. if (empty ( $title )) {
  6297. echo json_encode ( array (
  6298. 'status' => 2,
  6299. 'msg' => 'illegal request'
  6300. ) );
  6301. die ();
  6302. }
  6303. Doo::loadModel ( 'invoice' );
  6304. $invoice = new invoice ();
  6305. $invoiceDetail = $invoice->getInvoiceByTitle ( $title, 'FUZZY', " and status=2 and printStatus=1 and untreadStatus=0 and irid='' ", true );
  6306. $invoiceHtml = '';
  6307. if (! empty ( $invoiceDetail )) {
  6308. $invoiceHtml = '<table class="table table-bordered table-condensed">
  6309. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody><tr>';
  6310. foreach ( $invoiceDetail as $key => $value ) {
  6311. if (! empty ( $value ['invoiceType'] )) {
  6312. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  6313. } else {
  6314. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  6315. }
  6316. if (! empty ( $value ['invoiceType'] )) {
  6317. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  6318. } else {
  6319. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  6320. }
  6321. $invoiceHtml .= '
  6322. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  6323. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  6324. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir' . $value ['iidKeyXD'] . '" data-ikey="' . $value ['iidKey'] . '" href="#">入账</a></td>
  6325. </tr>
  6326. ';
  6327. }
  6328. $invoiceHtml .= '</tbody></table>
  6329. <script>
  6330. $(\'a[bind-receivables^="ir"]\').click(function() {
  6331. var data = $(this).attr("data-ikey");
  6332. $("input[name=\'invoiceKey\']").val(data);
  6333. var invoiceKey=$("input[name=\'invoiceKey\']").val();
  6334. if(invoiceKey==""){
  6335. alert("入账错误,请重新刷新页面");
  6336. return false;
  6337. }
  6338. if(window.confirm("确定入账吗?")){
  6339. $("#IBR").submit();
  6340. }else{
  6341. return false;
  6342. }
  6343. });
  6344. </script>
  6345. ';
  6346. }
  6347. echo json_encode ( array (
  6348. 'status' => 1,
  6349. 'invoiceHtml' => $invoiceHtml
  6350. ) );
  6351. }
  6352. function ajaxInvoicePushNotice() {
  6353. Doo::loadModel ( 'invoice' );
  6354. $invoice = new invoice ();
  6355. $approval = $invoice->getOne ( array (
  6356. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  6357. 'desc' => 'iid',
  6358. 'asArray' => true
  6359. ) );
  6360. $isNotice = false;
  6361. if (! empty ( $approval ))
  6362. $isNotice = true;
  6363. $response = array (
  6364. 'error' => 0,
  6365. 'isNotice' => $isNotice
  6366. );
  6367. echo json_encode ( $response );
  6368. exit ();
  6369. }
  6370. public function ajaxCheckInvoiceNoUniqueness() {
  6371. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  6372. Doo::loadModel ( 'invoice' );
  6373. $invoice = new invoice ();
  6374. if (! empty ( $invoiceNo )) {
  6375. Doo::loadModel ( 'invoicePaper' );
  6376. $invoicePaper = new invoicePaper ();
  6377. Doo::loadClass ( 'XDeode' );
  6378. $XDeode = new XDeode ( 5 );
  6379. $ipid = $XDeode->decode ( $invoiceNo );
  6380. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  6381. $info = $invoice->getOne ( array (
  6382. 'where' => "invoiceNo = '" . $paperDetail ['invoiceNo'] . "'",
  6383. 'asArray' => TRUE
  6384. ) );
  6385. if (! empty ( $info )) {
  6386. echo json_encode ( array (
  6387. 'error' => '发票号已存在'
  6388. ) );
  6389. die ();
  6390. } else
  6391. echo json_encode ( array (
  6392. 'ok' => '可以使用!'
  6393. ) );
  6394. die ();
  6395. }
  6396. }
  6397. function ajaxCheckInvoicePrice() {
  6398. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) && is_numeric ( $this->get_args ( 'receivablesPrice' ) ) ? $this->get_args ( 'receivablesPrice' ) : "";
  6399. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  6400. Doo::loadModel ( 'invoice' );
  6401. $invoice = new invoice ();
  6402. Doo::loadModel ( 'invoiceReceivables' );
  6403. $invoiceReceivables = new invoiceReceivables ();
  6404. Doo::loadClass ( 'XDeode' );
  6405. $XDeode = new XDeode ( 5 );
  6406. if (! empty ( $receivablesPrice ) && ! empty ( $iidKey )) {
  6407. $iidKey = $XDeode->decode ( $iidKey );
  6408. $info = $invoice->getInvoiceByIid ( $iidKey );
  6409. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $info ['irid'] );
  6410. if (empty ( $irList ))
  6411. $irList [0] ['sumPrice'] = 0;
  6412. $balance = $info ['invoicePrice'] - $irList [0] ['sumPrice'];
  6413. if ($balance < $receivablesPrice) {
  6414. echo json_encode ( array (
  6415. 'error' => '收款金额超过开票金额。'
  6416. ) );
  6417. die ();
  6418. }
  6419. if ($balance > $receivablesPrice) {
  6420. echo json_encode ( array (
  6421. 'error' => '收款金额低于开票金额。'
  6422. ) );
  6423. die ();
  6424. }
  6425. }
  6426. }
  6427. function ajaxGetInvoiceByNew() {
  6428. Doo::loadModel ( 'invoice' );
  6429. $invoice = new invoice ();
  6430. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );
  6431. echo json_encode ( array (
  6432. 'status' => 1,
  6433. 'detail' => $detail
  6434. ) );
  6435. }
  6436. /**
  6437. * 旧输入导入
  6438. */
  6439. function importInvoice() {
  6440. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  6441. $data ['emsg'] = "";
  6442. if ($emsg != "")
  6443. $data ['emsg'] = "请填写完整的数据";
  6444. $data ['time'] = time ();
  6445. $this->render ( "/admin/invoiceImport", $data );
  6446. }
  6447. function uploadInvoice() {
  6448. // move_uploaded_file($_FILES['Filedata']['tmp_name'], "/upload/".$_FILES['Filedata']['name']);
  6449. if (isset ( $_FILES ['Filedata'] ['name'] )) {
  6450. $file = $_FILES ['Filedata'] ['tmp_name'];
  6451. $error = false;
  6452. if (! is_uploaded_file ( $file )) {
  6453. $error = '400 Bad Request';
  6454. }
  6455. if ($error) {
  6456. header ( 'HTTP/1.0 ' . $error );
  6457. die ( 'Error ' . $error );
  6458. } else {
  6459. include (DOO::conf ()->SITE_PATH . 'protected/plugin/io.han.php');
  6460. $this->IoHandler = new IoHandler ();
  6461. $pics = explode ( '.', $_FILES ['Filedata'] ['name'] );
  6462. // $filedir=$_POST['time'];
  6463. // 调用定义物理路径
  6464. $t = DOO::conf ()->SITE_PATH . "upload/invoice/";
  6465. $this->IoHandler->MakeDir ( $t );
  6466. $filename = $this->_GetFileEXT ( $_FILES ['Filedata'] ['name'] );
  6467. if ($filename != 'xlsx')
  6468. return "";
  6469. // $upload_dir = $t."/".time().rand(10,100).".".$filename;
  6470. $upload_file = iconv ( "UTF-8", "GB2312", $_FILES ["Filedata"] ["name"] );
  6471. $upload_dir = $t . "/" . $upload_file;
  6472. $k = move_uploaded_file ( $file, $upload_dir );
  6473. if ($k) {
  6474. $m = round ( $_FILES ['Filedata'] ['size'] / 1024 / 1024, 2 );
  6475. echo $pics [0] . "." . $filename . "#" . $m . "#" . $_FILES ['Filedata'] ['size'];
  6476. }
  6477. }
  6478. }
  6479. }
  6480. function importInvoiceDo() {
  6481. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  6482. if ($path != "") {
  6483. Doo::loadModel ( 'invoice' );
  6484. Doo::loadModel ( 'staff' );
  6485. $staff = new staff ();
  6486. Doo::loadModel ( 'invoiceStatistics' );
  6487. Doo::loadModel ( 'invoiceOperationLog' );
  6488. echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  6489. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . $path );
  6490. // print_r ( $exlArray );
  6491. // die ();
  6492. // echo json_encode($exlArray);die;
  6493. foreach ( $exlArray as $key => $value ) {
  6494. // 开票
  6495. $invoice = new invoice ();
  6496. $invoice->invoiceNo = $value ['invoiceNo'];
  6497. $invoice->invoiceType = 0;
  6498. if ($value ['invoiceType'] == '专')
  6499. $invoice->invoiceType = 1;
  6500. $invoice->invoicePrice = $value ['invoicePrice'];
  6501. $invoice->invoiceQuantity = 1;
  6502. $invoice->invoiceUnitPrice = $value ['invoicePrice'];
  6503. $invoice->invoiceTitle = $value ['invoiceTitle'];
  6504. if ($value ['invoiceType'] == '专')
  6505. $invoice->invoiceCompany = $value ['invoiceTitle'];
  6506. $invoice->userName = $value ['userName'];
  6507. $sDetail = $staff->getStaffByName ( $value ['userName'] );
  6508. $invoice->sid = $sDetail ['sid'];
  6509. $invoice->cid = $sDetail ['cid'];
  6510. $invoice->categoryName = $sDetail ['category'];
  6511. $invoice->invoiceElement = $value ['invoiceElement'];
  6512. $invoice->remark = $value ['remark'];
  6513. $invoice->date = $value ['date'];
  6514. $invoice->printTime = $value ['date'];
  6515. $invoice->ipSource = 1;
  6516. $invoice->printStatus = 1;
  6517. $invoice->status = 2;
  6518. $invoice->postStatus = 1;
  6519. $invoice->untreadStatus = 0;
  6520. $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  6521. $iid = $invoice->insert ();
  6522. // 汇总
  6523. $invoiceStatistics = new invoiceStatistics ();
  6524. //
  6525. $item = array (
  6526. 'date' => $value ['date'],
  6527. 'priceClass' => 1,
  6528. 'cid' => $sDetail ['cid'],
  6529. 'staff' => $sDetail ['sid'],
  6530. 'invoicePrice' => $value ['invoicePrice']
  6531. );
  6532. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  6533. $invoiceOperationLog = new invoiceOperationLog ();
  6534. $item = array (
  6535. 'date' => date ( "Y-m-d H:i:s" ),
  6536. 'operation' => date ( "Y-m-d" ) . " 导入",
  6537. 'status' => 1,
  6538. 'img' => $sDetail ['avatar'],
  6539. 'username' => $sDetail ['username'],
  6540. 'uid' => $sDetail ['sid'],
  6541. 'category' => $sDetail ['category'],
  6542. 'iid' => $iid
  6543. );
  6544. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  6545. }
  6546. return '/importInvoice?count=' . count ( $exlArray );
  6547. // return "/keyonline";
  6548. }
  6549. echo 'no file';
  6550. }
  6551. function importInvoiceReceivables() {
  6552. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  6553. $data ['emsg'] = "";
  6554. if ($emsg != "")
  6555. $data ['emsg'] = "请填写完整的数据";
  6556. $data ['time'] = time ();
  6557. $this->render ( "/admin/invoiceReceivablesImport", $data );
  6558. }
  6559. // 导入入账数据
  6560. function importInvoiceReceivablesDo() {
  6561. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  6562. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  6563. if ($path != "") {
  6564. Doo::loadModel ( 'invoiceReceivables' );
  6565. Doo::loadModel ( 'invoice' );
  6566. Doo::loadModel ( 'staff' );
  6567. $staff = new staff ();
  6568. Doo::loadModel ( 'invoiceStatistics' );
  6569. // echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  6570. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path ), 'invoiceReceivables' );
  6571. // print_r ( $exlArray );
  6572. // die ();
  6573. // echo json_encode($exlArray);die;
  6574. foreach ( $exlArray as $key => $value ) {
  6575. // 收款
  6576. $invoiceReceivables = new invoiceReceivables ();
  6577. $invoice = new invoice ();
  6578. $invoiceReceivables->bindStatus = 1;
  6579. $invoiceReceivables->receivablesPrice = $value ['receivablesPrice'];
  6580. $invoiceReceivables->receivablesMessage = $value ['receivablesMessage'];
  6581. $invoiceReceivables->receivablesBank = $value ['receivablesBank'];
  6582. $invoiceReceivables->receivablesDate = $value ['receivablesDate'];
  6583. $sDetail = $staff->getStaffByName ( $value ['receivablesStaff'] );
  6584. $invoiceReceivables->receivablesCategory = $sDetail ['cid'] . ':' . $sDetail ['category'];
  6585. $invoiceReceivables->receivablesStaff = $sDetail ['sid'] . '-' . $sDetail ['username'];
  6586. $invoiceReceivables->receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  6587. $invoiceReceivables->sourcePrice = $value ['sourcePrice'];
  6588. $iDetail = $invoice->getInvoiceByInvoiceNo ( $value ['invoiceNo'] );
  6589. $invoiceReceivables->iid = $iDetail ['iid'];
  6590. $irid = $invoiceReceivables->insert ();
  6591. // 发票绑定收款
  6592. $detail = $iDetail;
  6593. $iridString = "";
  6594. if (empty ( $detail ['irid'] ))
  6595. $iridString = $irid;
  6596. else
  6597. $iridString = $detail ['irid'] . ',' . $irid;
  6598. $item = array (
  6599. 'irid' => $iridString,
  6600. 'iid' => $detail ['iid']
  6601. );
  6602. $invoice->setInvoiceByCondition ( $item );
  6603. // 汇总
  6604. $invoiceStatistics = new invoiceStatistics ();
  6605. // 扣除入账统计金额
  6606. $item = array (
  6607. 'date' => $value ['receivablesDate'],
  6608. 'priceClass' => 3,
  6609. 'cid' => $sDetail ['cid'],
  6610. 'staff' => $sDetail ['sid'],
  6611. // 'irid' => $irid,
  6612. 'accountPrice' => $value ['receivablesPrice']
  6613. );
  6614. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  6615. }
  6616. return '/importInvoiceReceivables?count=' . count ( $exlArray );
  6617. echo 'data count ' . count ( $exlArray );
  6618. die ();
  6619. // return "/keyonline";
  6620. }
  6621. echo 'no file';
  6622. }
  6623. function formatExcelToArrayTrain($file_url = "") {
  6624. if (! file_exists ( $file_url )) {
  6625. return array ();
  6626. }
  6627. // Doo::loadClass ( 'PHPExcel' );
  6628. Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  6629. $PHPExcel = new PHPExcel ();
  6630. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  6631. if (! $PHPReader->canRead ( $file_url )) {
  6632. $PHPReader = new PHPExcel_Reader_Excel5 ();
  6633. if (! $PHPReader->canRead ( $file_url )) {
  6634. echo 'no Excel';
  6635. return;
  6636. }
  6637. }
  6638. $PHPExcel = $PHPReader->load ( $file_url );
  6639. /* * 读取excel文件中的第一个工作表 */
  6640. $currentSheet = $PHPExcel->getSheet ( 0 );
  6641. /* * 取得最大的列号 */
  6642. $allColumn = $currentSheet->getHighestColumn ();
  6643. /* * 取得一共有多少行 */
  6644. $allRow = $currentSheet->getHighestRow ();
  6645. $excel_array = array ();
  6646. // die($file_url);
  6647. $conk = 2;
  6648. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  6649. $excel_column = array ();
  6650. // 后期改进
  6651. if ($allColumn == 'AM')
  6652. $allColumn = 'Z';
  6653. /* * 从第A列开始输出 */
  6654. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  6655. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  6656. if ($val instanceof PHPExcel_RichText)
  6657. $val = $val->__toString ();
  6658. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  6659. // $val = "'" . addslashes ( $val ) . "'";
  6660. if ($currentColumn == 'A') {
  6661. $excel_column ['invoiceTitle'] = $val;
  6662. } elseif ($currentColumn == 'B')
  6663. $excel_column ['invoiceType'] = $val;
  6664. elseif ($currentColumn == 'C') {
  6665. $excel_column ['TIN'] = $val;
  6666. } elseif ($currentColumn == 'D') {
  6667. $excel_column ['address'] = $val;
  6668. } elseif ($currentColumn == 'E') {
  6669. $excel_column ['phone'] = $val;
  6670. } elseif ($currentColumn == 'F') {
  6671. $excel_column ['bank'] = $val;
  6672. } elseif ($currentColumn == 'G') {
  6673. $excel_column ['bankAccount'] = $val;
  6674. } elseif ($currentColumn == 'H') {
  6675. $excel_column ['invoiceElement'] = $val;
  6676. } elseif ($currentColumn == 'I') {
  6677. $excel_column ['invoiceQuantity'] = $val;
  6678. } elseif ($currentColumn == 'J') {
  6679. $excel_column ['invoiceUnitPrice'] = $val;
  6680. } elseif ($currentColumn == 'K') {
  6681. $excel_column ['remark'] = $val;
  6682. } elseif ($currentColumn == 'L') {
  6683. $excel_column ['recipientsAddress'] = $val;
  6684. } elseif ($currentColumn == 'M') {
  6685. $excel_column ['recipients'] = $val;
  6686. } elseif ($currentColumn == 'N') {
  6687. $excel_column ['recipientsPhone'] = $val;
  6688. }
  6689. }
  6690. if (! empty ( $excel_column ['invoiceTitle'] ) && ! empty ( $excel_column ['invoiceQuantity'] ) && ! empty ( $excel_column ['invoiceUnitPrice'] ))
  6691. array_push ( $excel_array, $excel_column );
  6692. }
  6693. return $excel_array;
  6694. }
  6695. /**
  6696. * 格式化excel文件为数组
  6697. * @param unknown_type $file_url
  6698. * @param unknown_type $mcid
  6699. */
  6700. function _format_excel_to_array($file_url = "", $sType = "") {
  6701. if (! file_exists ( $file_url )) {
  6702. return array ();
  6703. }
  6704. Doo::loadClass ( 'PHPExcel' );
  6705. // Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  6706. $PHPExcel = new PHPExcel ();
  6707. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  6708. if (! $PHPReader->canRead ( $file_url )) {
  6709. $PHPReader = new PHPExcel_Reader_Excel5 ();
  6710. if (! $PHPReader->canRead ( $file_url )) {
  6711. echo 'no Excel';
  6712. return;
  6713. }
  6714. }
  6715. $PHPExcel = $PHPReader->load ( $file_url );
  6716. /* * 读取excel文件中的第一个工作表 */
  6717. $currentSheet = $PHPExcel->getSheet ( 0 );
  6718. /* * 取得最大的列号 */
  6719. $allColumn = $currentSheet->getHighestColumn ();
  6720. /* * 取得一共有多少行 */
  6721. $allRow = $currentSheet->getHighestRow ();
  6722. $excel_array = array ();
  6723. // die($file_url);
  6724. $conk = 2;
  6725. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  6726. $excel_column = array ();
  6727. // 后期改进
  6728. if ($allColumn == 'AM')
  6729. $allColumn = 'Z';
  6730. /* * 从第A列开始输出 */
  6731. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  6732. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  6733. if ($val instanceof PHPExcel_RichText)
  6734. $val = $val->__toString ();
  6735. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  6736. // $val = "'" . addslashes ( $val ) . "'";
  6737. if ($sType == 'invoiceReceivables') {
  6738. if ($currentColumn == 'A')
  6739. $excel_column ['invoiceNo'] = $val;
  6740. elseif ($currentColumn == 'B')
  6741. $excel_column ['receivablesPrice'] = $val;
  6742. elseif ($currentColumn == 'C') {
  6743. $excel_column ['receivablesMessage'] = $val;
  6744. } elseif ($currentColumn == 'D') {
  6745. $excel_column ['receivablesBank'] = $val;
  6746. } elseif ($currentColumn == 'E') {
  6747. $excel_column ['receivablesDate'] = $this->excelTime ( $val );
  6748. } elseif ($currentColumn == 'F') {
  6749. $excel_column ['receivablesStaff'] = $val;
  6750. } elseif ($currentColumn == 'G') {
  6751. $excel_column ['sourcePrice'] = $val;
  6752. }
  6753. } elseif ($sType == "invoiceTrain") {
  6754. if ($currentColumn == 'A') {
  6755. $excel_column ['invoiceTitle'] = $val;
  6756. } elseif ($currentColumn == 'B')
  6757. $excel_column ['invoiceType'] = $val;
  6758. elseif ($currentColumn == 'C') {
  6759. $excel_column ['TIN'] = $val;
  6760. } elseif ($currentColumn == 'D') {
  6761. $excel_column ['address'] = $val;
  6762. } elseif ($currentColumn == 'E') {
  6763. $excel_column ['phone'] = $val;
  6764. } elseif ($currentColumn == 'F') {
  6765. $excel_column ['bank'] = $val;
  6766. } elseif ($currentColumn == 'G') {
  6767. $excel_column ['bankAccount'] = $val;
  6768. } elseif ($currentColumn == 'H') {
  6769. $excel_column ['invoiceElement'] = $val;
  6770. } elseif ($currentColumn == 'I') {
  6771. $excel_column ['invoiceQuantity'] = $val;
  6772. } elseif ($currentColumn == 'J') {
  6773. $excel_column ['invoiceUnitPrice'] = $val;
  6774. } elseif ($currentColumn == 'K') {
  6775. $excel_column ['remark'] = $val;
  6776. } elseif ($currentColumn == 'L') {
  6777. $excel_column ['recipientsAddress'] = $val;
  6778. } elseif ($currentColumn == 'M') {
  6779. $excel_column ['recipients'] = $val;
  6780. } elseif ($currentColumn == 'N') {
  6781. $excel_column ['recipientsPhone'] = $val;
  6782. }
  6783. } else {
  6784. if ($currentColumn == 'A')
  6785. $excel_column ['invoiceNo'] = $val;
  6786. elseif ($currentColumn == 'B')
  6787. $excel_column ['invoiceType'] = $val;
  6788. elseif ($currentColumn == 'C') {
  6789. $excel_column ['invoicePrice'] = $val;
  6790. } elseif ($currentColumn == 'D') {
  6791. $excel_column ['invoiceTitle'] = $val;
  6792. } elseif ($currentColumn == 'E') {
  6793. $excel_column ['userName'] = $val;
  6794. } elseif ($currentColumn == 'F') {
  6795. $excel_column ['categoryName'] = $val;
  6796. } elseif ($currentColumn == 'G') {
  6797. $excel_column ['invoiceElement'] = $val;
  6798. } elseif ($currentColumn == 'H') {
  6799. $excel_column ['remark'] = $val;
  6800. } elseif ($currentColumn == 'I') {
  6801. $excel_column ['date'] = $this->excelTime ( $val );
  6802. }
  6803. }
  6804. }
  6805. array_push ( $excel_array, $excel_column );
  6806. }
  6807. return $excel_array;
  6808. }
  6809. function excelTime($date, $time = false) {
  6810. if (function_exists ( 'GregorianToJD' )) {
  6811. if (is_numeric ( $date )) {
  6812. $jd = GregorianToJD ( 1, 1, 1970 );
  6813. $gregorian = JDToGregorian ( $jd + intval ( $date ) - 25569 );
  6814. $date = explode ( '/', $gregorian );
  6815. $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" : '');
  6816. return $date_str;
  6817. }
  6818. } else {
  6819. $date = $date > 25568 ? $date + 1 : 25569;
  6820. /* There was a bug if Converting date before 1-1-1970 (tstamp 0) */
  6821. $ofs = (70 * 365 + 17 + 2) * 86400;
  6822. $date = date ( "Y-m-d", ($date * 86400) - $ofs ) . ($time ? " 00:00:00" : '');
  6823. }
  6824. return $date;
  6825. }
  6826. /**
  6827. * 旧输入导入
  6828. */
  6829. function _GetFileEXT($filename) {
  6830. $pics = explode ( '.', $filename );
  6831. $num = count ( $pics );
  6832. return $pics [$num - 1];
  6833. }
  6834. function showCache($path = "", $sid = 0) {
  6835. // if (file_exists ( $path )) {
  6836. // $htm = file_get_contents ( $path );
  6837. // } else {
  6838. Doo::loadModel ( 'invoiceStatistics' );
  6839. $invoiceStatistics = new invoiceStatistics ();
  6840. $isBriefly = $invoiceStatistics->getBrieflyStatistics ( $sid );
  6841. $htm = '<tr><th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计开票</th>
  6842. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['invoicePrice'] . '</td>
  6843. <th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计入账</th>
  6844. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['accountPrice'] . '</td></tr>';
  6845. /*
  6846. * '<tr><th class="taC">今年累计开票</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['invoicePrice'] . '</td> <th class="taC">今年累计入账</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['accountPrice'] . '</td></tr>';
  6847. */
  6848. file_put_contents ( $path, $htm );
  6849. // }
  6850. return $htm;
  6851. }
  6852. /**
  6853. * 生成token
  6854. * @return string
  6855. */
  6856. function set_token() {
  6857. $str = md5 ( uniqid ( md5 ( microtime ( true ) ), true ) ); // 生成一个不会重复的字符串
  6858. $str = sha1 ( $str ); // 加密
  6859. return $str;
  6860. }
  6861. /**
  6862. * 获取get或者POST值
  6863. *
  6864. * @param string $name 属性名称
  6865. * @return fixed 值
  6866. */
  6867. function get_args($name) {
  6868. if (isset ( $_GET [$name] )) {
  6869. if (is_array ( $_GET [$name] ))
  6870. return $_GET [$name];
  6871. else
  6872. return addslashes ( $_GET [$name] );
  6873. } elseif (isset ( $_POST [$name] )) {
  6874. if (is_array ( $_POST [$name] ))
  6875. return $_POST [$name];
  6876. else
  6877. return addslashes ( $_POST [$name] );
  6878. } else
  6879. return false;
  6880. }
  6881. function SafeFilter(&$arr) {
  6882. $ra = Array (
  6883. '/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/',
  6884. '/script/',
  6885. '/javascript/',
  6886. '/vbscript/',
  6887. '/expression/',
  6888. '/applet/',
  6889. '/meta/',
  6890. '/xml/',
  6891. '/blink/',
  6892. '/link/',
  6893. '/style/',
  6894. '/embed/',
  6895. '/object/',
  6896. '/frame/',
  6897. '/layer/',
  6898. '/title/',
  6899. '/bgsound/',
  6900. '/base/',
  6901. '/onload/',
  6902. '/onunload/',
  6903. '/onchange/',
  6904. '/onsubmit/',
  6905. '/onreset/',
  6906. '/onselect/',
  6907. '/onblur/',
  6908. '/onfocus/',
  6909. '/onabort/',
  6910. '/onkeydown/',
  6911. '/onkeypress/',
  6912. '/onkeyup/',
  6913. '/onclick/',
  6914. '/ondblclick/',
  6915. '/onmousedown/',
  6916. '/onmousemove/',
  6917. '/onmouseout/',
  6918. '/onmouseover/',
  6919. '/onmouseup/',
  6920. '/onunload/'
  6921. );
  6922. if (is_array ( $arr )) {
  6923. foreach ( $arr as $key => $value ) {
  6924. if (! is_array ( $value )) {
  6925. if (! get_magic_quotes_gpc ()) // 不对magic_quotes_gpc转义过的字符使用addslashes(),避免双重转义。
  6926. {
  6927. $value = addslashes ( $value ); // 给单引号(')、双引号(")、反斜线(\)与 NUL(NULL 字符)加上反斜线转义
  6928. }
  6929. $value = preg_replace ( $ra, '', $value ); // 删除非打印字符,粗暴式过滤xss可疑字符串
  6930. $arr [$key] = htmlentities ( strip_tags ( $value ) ); // 去除 HTML 和 PHP 标记并转换为 HTML 实体
  6931. } else {
  6932. SafeFilter ( $arr [$key] );
  6933. }
  6934. }
  6935. }
  6936. }
  6937. /**
  6938. * Escape String
  6939. *
  6940. * @access public
  6941. * @param string
  6942. * @param bool whether or not the string will be used in a LIKE condition
  6943. * @return string
  6944. */
  6945. function escape_str($str, $like = FALSE) {
  6946. if (is_array ( $str )) {
  6947. foreach ( $str as $key => $val ) {
  6948. $str [$key] = $this->escape_str ( $val, $like );
  6949. }
  6950. return $str;
  6951. }
  6952. var_dump ( Doo::db ()->getDbObject () );
  6953. die ();
  6954. if (function_exists ( 'mysql_real_escape_string' ) and is_resource ( Doo::db ()->getDbObject () )) { // Doo::db ()->getDbObject()
  6955. $str = mysql_real_escape_string ( $str, Doo::db ()->getDbObject () );
  6956. } elseif (function_exists ( 'mysql_escape_string' )) {
  6957. $str = mysql_escape_string ( $str );
  6958. } else {
  6959. $str = addslashes ( $str );
  6960. }
  6961. // escape LIKE condition wildcards
  6962. if ($like === TRUE) {
  6963. $str = str_replace ( array (
  6964. '%',
  6965. '_'
  6966. ), array (
  6967. '\\%',
  6968. '\\_'
  6969. ), $str );
  6970. }
  6971. return $str;
  6972. }
  6973. /**
  6974. * 获得分页数据
  6975. * @param unknown_type $table
  6976. * @param unknown_type $condition
  6977. * @param unknown_type $on_page
  6978. * @param unknown_type $page_size
  6979. */
  6980. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  6981. $page_c = "";
  6982. $page ['previous'] = $this->get_previous ( $on_page );
  6983. $page ['on_page'] = $on_page;
  6984. $total_count = $this->get_table_count ( $table, $condition );
  6985. $total = intval ( $total_count / $page_size );
  6986. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  6987. $page ['total_data'] = $total_count;
  6988. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  6989. $i = 1;
  6990. $page_max = 1;
  6991. $page_width = 3;
  6992. if ($on_page >= $page_width) {
  6993. $page_max = intval ( $on_page / $page_width ) + 1;
  6994. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  6995. }
  6996. for(; $i <= $page ['total_page']; $i ++) {
  6997. if ($i == $on_page)
  6998. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  6999. else
  7000. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  7001. if ($i == ($page_width * $page_max))
  7002. break;
  7003. }
  7004. $page ['page'] = $page_c;
  7005. $page ['lower'] = (-- $on_page) * $page_size;
  7006. return $page;
  7007. }
  7008. /**
  7009. * 获取上一页
  7010. * @param unknown_type $on_page
  7011. */
  7012. function get_previous($on_page = 1) {
  7013. return $on_page != 0 ? $on_page - 1 : $on_page;
  7014. }
  7015. /**
  7016. * 获取总页数
  7017. * @param unknown_type $table
  7018. * @param unknown_type $condition
  7019. */
  7020. public function get_table_count($table = "", $condition = "") {
  7021. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  7022. $sql = "select count(*) as count from " . $table . " where " . $condition;
  7023. // echo $sql;die;
  7024. $query = Doo::db ()->query ( $sql );
  7025. $result = $query->fetch ();
  7026. return $result ['count'];
  7027. }
  7028. /**
  7029. * 获得分页数据
  7030. * @param unknown_type $table
  7031. * @param unknown_type $condition
  7032. * @param unknown_type $on_page
  7033. * @param unknown_type $page_size
  7034. */
  7035. function getPageBySql($sql = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  7036. $page_c = "";
  7037. $page ['previous'] = $this->get_previous ( $on_page );
  7038. $page ['on_page'] = $on_page;
  7039. $total_count = $this->getTableCountBySql ( $sql );
  7040. $total = intval ( $total_count / $page_size );
  7041. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  7042. $page ['total_data'] = $total_count;
  7043. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  7044. $i = 1;
  7045. $page_max = 1;
  7046. $page_width = 3;
  7047. if ($on_page >= $page_width) {
  7048. $page_max = intval ( $on_page / $page_width ) + 1;
  7049. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  7050. }
  7051. for(; $i <= $page ['total_page']; $i ++) {
  7052. if ($i == $on_page)
  7053. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  7054. else
  7055. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  7056. if ($i == ($page_width * $page_max))
  7057. break;
  7058. }
  7059. $page ['page'] = $page_c;
  7060. $page ['lower'] = (-- $on_page) * $page_size;
  7061. return $page;
  7062. }
  7063. /**
  7064. * 获得总页数 sql
  7065. * @param string $type
  7066. * @return boolean[]
  7067. */
  7068. public function getTableCountBySql($sql = "") {
  7069. $query = Doo::db ()->query ( $sql );
  7070. $result = $query->fetchAll ();
  7071. return count ( $result );
  7072. }
  7073. function isInvoiceNew($type = "GLOBAL") {
  7074. Doo::loadModel ( 'invoice' );
  7075. $invoice = new invoice ();
  7076. Doo::loadModel ( 'invoiceReceivables' );
  7077. $invoiceReceivables = new invoiceReceivables ();
  7078. Doo::loadModel ( 'staff' );
  7079. $staff = new staff ();
  7080. $st = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  7081. // 我的发票待处理
  7082. $pendingInvoice = $invoice->getOne ( array ( // or (status=2 and printStatus=1 and untreadStatus=0 ) or (status=2 and printStatus=1 and untreadStatus=2 )
  7083. 'where' => "(status=3 or status=4) and isDelete=0 and sid=" . $st [0] ['sid'],
  7084. 'desc' => 'iid',
  7085. 'asArray' => TRUE
  7086. ) );
  7087. // 我的收款待入账
  7088. /*
  7089. * $myClaim = $invoiceReceivables->getOne ( array ( 'where' => " receivablesStaff like '" . $st [0] ['sid'] . "-%' and receivablesCategory like '" . $st [0] ['cid'] . ":%' and bindStatus=0", 'desc' => 'irid', 'asArray' => TRUE ) );
  7090. */
  7091. // 发票审批
  7092. $approval = $invoice->getOne ( array (
  7093. 'where' => 'status=1 and pendingApprovals=' . $st [0] ['sid'],
  7094. 'desc' => 'iid',
  7095. 'asArray' => true
  7096. ) );
  7097. // 发票邮寄
  7098. $post = $invoice->getOne ( array (
  7099. 'where' => "postStatus=0 and printStatus=1 and isDelete=0 and doPost=1 and status=2",
  7100. 'asArray' => TRUE
  7101. ) );
  7102. // 发票打印
  7103. $print = $invoice->getOne ( array (
  7104. 'where' => "status=2 and printStatus=0 and untreadStatus=0 and moldManage like '%[\"" . $st [0] ['sid'] . "\",%'",
  7105. 'desc' => 'iid',
  7106. 'asArray' => TRUE
  7107. ) );
  7108. // 发票退票 printStatus=1 and
  7109. $untread = $invoice->getOne ( array (
  7110. 'where' => " untreadStatus=1 and status=2 ",
  7111. 'asArray' => TRUE
  7112. ) );
  7113. $new = array (
  7114. 'GLOBAL' => FALSE,
  7115. 'pendingInvoice' => FALSE,
  7116. // 'myClaim' => FALSE,
  7117. 'approval' => FALSE,
  7118. 'post' => FALSE,
  7119. 'print' => FALSE,
  7120. 'untread' => FALSE
  7121. );
  7122. // || ! empty ( $myClaim )
  7123. if (! empty ( $pendingInvoice ) || ! empty ( $approval ) || ! empty ( $post ) || ! empty ( $print ) || ! empty ( $untread ))
  7124. $new ['GLOBAL'] = TRUE;
  7125. if (! empty ( $pendingInvoice ))
  7126. $new ['pendingInvoice'] = TRUE;
  7127. // if (! empty ( $myClaim ))
  7128. // $new ['myClaim'] = TRUE;
  7129. if (! empty ( $approval ))
  7130. $new ['approval'] = TRUE;
  7131. if (! empty ( $post ))
  7132. $new ['post'] = TRUE;
  7133. if (! empty ( $print ))
  7134. $new ['print'] = TRUE;
  7135. if (! empty ( $untread ))
  7136. $new ['untread'] = TRUE;
  7137. return $new;
  7138. }
  7139. function setWXMsg($rid, $typeMsg = '') {
  7140. Doo::loadModel ( 'invoice' );
  7141. $invoice = new invoice ();
  7142. $invoiceDetail = $invoice->getOne ( array (
  7143. 'where' => 'iid=' . $rid,
  7144. 'asArray' => true
  7145. ) );
  7146. if (! empty ( $invoiceDetail )) {
  7147. Doo::loadModel ( 'staff' );
  7148. $staff = new staff ();
  7149. $staffmsg = $staff->getOne ( array (
  7150. 'where' => "sid='" . $invoiceDetail ['sid'] . "'",
  7151. 'asArray' => TRUE
  7152. ) );
  7153. if (! empty ( $staffmsg ['wxid'] )) {
  7154. require_once (SITE_PATH . '/protected/class/client.php');
  7155. $client = new client ( 'http://m.cld.smartcost.com.cn/' );
  7156. $user = $staffmsg ['wxid'];
  7157. $expCom = explode ( ":", $invoiceDetail ['expressCompany'] );
  7158. if (empty ( $expCom ))
  7159. $expCom [0] = '';
  7160. $msg = "";
  7161. if (empty ( $typeMsg ))
  7162. $msg = '太好了,您的发票' . $invoiceDetail ['invoiceSerial'] . ' 已邮寄 ' . $expCom [0] . ' ,快递号: <a href="https://m.kuaidi100.com/result.jsp?nu=' . $invoiceDetail ['expressNumber'] . '" >' . $invoiceDetail ['expressNumber'] . '</a>';
  7163. elseif ($typeMsg == "PRINT")
  7164. $msg = '太好了,您的发票已打印完成。';
  7165. $result = $client->SendMsg ( $user, $msg, 'text' );
  7166. }
  7167. }
  7168. }
  7169. /**
  7170. * 获取微信部门
  7171. * @param string $category
  7172. * @return number|mixed
  7173. */
  7174. function getToparty($category = '') {
  7175. $token = $this->getAccessToken (); //
  7176. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token={$token}&id=5" ), true );
  7177. $toparty = 0;
  7178. foreach ( $result ['department'] as $key => $value ) {
  7179. if ($value ['name'] == $category)
  7180. $toparty = $value ['id'];
  7181. }
  7182. return $toparty;
  7183. }
  7184. /**
  7185. * 获得某部门下的用户
  7186. * @param string $toparty
  7187. */
  7188. function getUserByToparty($toparty = '') {
  7189. $token = $this->getAccessToken (); //
  7190. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token={$token}&department_id={$toparty}" ), true );
  7191. $userList = array ();
  7192. foreach ( $result ['userlist'] as $key => $value ) {
  7193. array_push ( $userList, "'" . $value ['userid'] . "'" );
  7194. }
  7195. return $userList;
  7196. }
  7197. function msgSendToparty($msg, $title, $url, $toparty, $text = '') {
  7198. $token = $this->getAccessToken ();
  7199. if ($text == 'text') {
  7200. $data = '{
  7201. "touser": "' . $toparty . '",
  7202. "toparty": "",
  7203. "totag": "",
  7204. "msgtype": "text",
  7205. "agentid": 1000002,
  7206. "text": {
  7207. "content": "' . $msg . '"
  7208. },
  7209. "safe":0
  7210. }';
  7211. }
  7212. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  7213. if ($result->errmsg != 'ok') {
  7214. return 0;
  7215. } else {
  7216. return 1;
  7217. }
  7218. }
  7219. /**
  7220. * 获得可以发送微信用户列表
  7221. * @param string $category
  7222. * @return string
  7223. */
  7224. function getWxidByCategory($category = "") {
  7225. if (empty ( $category ))
  7226. return "";
  7227. Doo::loadModel ( 'staff' );
  7228. $staff = new staff ();
  7229. $toparty = $this->getToparty ( $category );
  7230. $wxList = array ();
  7231. $wxString = "";
  7232. if (! empty ( $toparty )) {
  7233. $userList = $this->getUserByToparty ( $toparty );
  7234. $userCon = implode ( ',', $userList );
  7235. // echo $userCon;
  7236. $sidList = $staff->getStaffByWxid ( $userCon );
  7237. foreach ( $sidList as $key => $value ) {
  7238. $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  7239. if ($falg) {
  7240. array_push ( $wxList, $value ['wxid'] );
  7241. }
  7242. }
  7243. $wxString = implode ( '|', $wxList );
  7244. }
  7245. return $wxString;
  7246. }
  7247. /**
  7248. * 读取发送信息规则判断是否需要发送
  7249. * @param number $sid
  7250. * @param string $sendType
  7251. * @return boolean
  7252. */
  7253. function isSendNotification($sid = 0, $sendType = '') {
  7254. Doo::loadModel ( "notificationConf" );
  7255. $notificationConf = new notificationConf ();
  7256. $detail = $notificationConf->getNotificationConfBySid ( $sid );
  7257. $conf = array ();
  7258. $sendFlag = true;
  7259. if (! empty ( $detail )) {
  7260. $conf = json_decode ( $detail ['conf'], true );
  7261. if (! empty ( $sendType )) {
  7262. if (isset ( $conf [$sendType] )) {
  7263. if ($conf [$sendType] == "CLOSE")
  7264. $sendFlag = false;
  7265. elseif ($conf [$sendType] == "Weekend") {
  7266. $day = date ( "w" );
  7267. if (1 <= $day && 5 >= $day)
  7268. $sendFlag = false;
  7269. } elseif ($conf [$sendType] == "OneToFriday") {
  7270. $day = date ( "w" );
  7271. if (0 == $day || 6 == $day)
  7272. $sendFlag = false;
  7273. }
  7274. }
  7275. } else
  7276. $sendFlag = false;
  7277. }
  7278. return $sendFlag;
  7279. }
  7280. /**
  7281. * 根据规则发送信息
  7282. * @param unknown $msg
  7283. * @param unknown $title
  7284. * @param unknown $url
  7285. * @param unknown $user
  7286. * @param string $text
  7287. * @return number
  7288. */
  7289. private function msgSend($msg, $title, $url, $user, $sid = 0, $sendType = '') {
  7290. $token = $this->getAccessToken ();
  7291. $falg = $this->isSendNotification ( $sid, $sendType );
  7292. // if ($text == 'text') {
  7293. // $data = '{
  7294. // "touser": "' . $user . '",
  7295. // "toparty": "",
  7296. // "totag": "",
  7297. // "msgtype": "text",
  7298. // "agentid": 1000002,
  7299. // "text": {
  7300. // "content": "' . $msg . '"
  7301. // },
  7302. // "safe":0
  7303. // }';
  7304. // } else {
  7305. $data = '{
  7306. "touser": "' . $user . '",
  7307. "toparty": "",
  7308. "totag": "",
  7309. "msgtype": "news",
  7310. "agentid": 1000002,
  7311. "news": {
  7312. "articles":[
  7313. {
  7314. "title": "' . $title . '",
  7315. "description": "' . $msg . '",
  7316. "url": "' . $url . '",
  7317. "picurl": ""
  7318. }
  7319. ]
  7320. }
  7321. }';
  7322. // }
  7323. if ($falg) {
  7324. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  7325. if ($result->errmsg != 'ok') {
  7326. return 0;
  7327. } else {
  7328. return 1;
  7329. }
  7330. } else
  7331. return 0;
  7332. }
  7333. private function getAccessToken() {
  7334. // access_token 应该全局存储与更新,以下代码以写入到文件中做示例
  7335. // $file = './access_token.txt';
  7336. // $data = json_decode ( file_get_contents ( $file ) );
  7337. // if ($data->expire_time < time () or ! $data->expire_time) {
  7338. // 如果是企业号用以下URL获取access_token
  7339. $url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$this->appId&corpsecret=$this->appSecret";
  7340. // $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$this->appId&secret=$this->appSecret";
  7341. $res = json_decode ( $this->httpGet ( $url ) );
  7342. $access_token = $res->access_token;
  7343. // echo $access_token;
  7344. // if ($access_token) {
  7345. // $data->expire_time = time () + 7000;
  7346. // $data->access_token = $access_token;
  7347. // $fp = fopen ( $file, "w" );
  7348. // fwrite ( $fp, json_encode ( $data ) );
  7349. // fclose ( $fp );
  7350. // }
  7351. // } else {
  7352. // $access_token = $data->access_token;
  7353. // }
  7354. return $access_token;
  7355. }
  7356. private function httpGet($url) {
  7357. $curl = curl_init ();
  7358. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  7359. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  7360. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  7361. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  7362. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  7363. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  7364. curl_setopt ( $curl, CURLOPT_URL, $url );
  7365. $res = curl_exec ( $curl );
  7366. curl_close ( $curl );
  7367. return $res;
  7368. }
  7369. private function httpPost($url, $data) {
  7370. $curl = curl_init ();
  7371. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  7372. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  7373. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  7374. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  7375. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  7376. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  7377. curl_setopt ( $curl, CURLOPT_URL, $url );
  7378. curl_setopt ( $curl, CURLOPT_POST, 1 );
  7379. curl_setopt ( $curl, CURLOPT_POSTFIELDS, $data );
  7380. $res = curl_exec ( $curl );
  7381. curl_close ( $curl );
  7382. return $res;
  7383. }
  7384. }
  7385. ?>