InvoiceController.php 315 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577
  1. <?php
  2. /**
  3. * 开票功能控制器
  4. * @author CP
  5. * @version 1.0
  6. * @namespace invoice
  7. * @package invoiceController
  8. */
  9. class InvoiceController extends DooController {
  10. public $staff;
  11. public $NEW;
  12. public $data;
  13. private $INVOICEKEY = "APPROVAL";
  14. private $INVOICECOLLECTPATH = "protected/cache/invoiceCollect/";
  15. private $ACTION = '';
  16. private $appId = 'wx3ee46531947a1384';
  17. private $appSecret = 'awGWzy3J5q_96VXKBLA2BQ9RpiT0LiPXnkMF-xV6h5o'; // awGWzy3J5q_96VXKBLA2BXU6mVCGynPGD-sxUCsdNDE //'PeiQVH8tbQE7pM9pVO4AIPlX9FFNpwu7O6Iy6VFcAVtpjTA3Qn42dbNmktBFkUHo';
  18. public function beforeRun($resource, $action) {
  19. Doo::loadModel ( "invoiceManage" );
  20. $invoiceManage = new invoiceManage ();
  21. Doo::loadClass ( 'XDeode' );
  22. $XDeode = new XDeode ( 5 );
  23. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  24. header ( 'Content-Type:text/html;charset=utf-8' );
  25. $moldList = $invoiceManage->getInvoiceByStaff ( $sid );
  26. if (empty ( $moldList )) {
  27. $flag = false;
  28. $uGroups = 'ordinary';
  29. if (Doo::acl ()->isAllowed ( $uGroups, $resource, $action )) {
  30. $flag = true;
  31. }
  32. } else {
  33. $flag = false;
  34. array_push ( $moldList, array (
  35. 'mold' => 'ordinary'
  36. ) );
  37. // 删除审批人后-加入权限问题-暂时关闭
  38. $fileInvoice = file_get_contents ( "protected/config/invoice/invoice.ini" );
  39. $fiML = json_decode ( $fileInvoice, true );
  40. if (empty ( $fiML ))
  41. $fiML = array ();
  42. foreach ( $fiML as $key => $value ) {
  43. $sidList = explode ( ',', $value );
  44. foreach ( $sidList as $k => $v ) {
  45. if ($v == $sid) {
  46. array_push ( $moldList, array (
  47. 'mold' => $key
  48. ) );
  49. break;
  50. }
  51. }
  52. }
  53. foreach ( $moldList as $value ) {
  54. if (Doo::acl ()->isAllowed ( $value ['mold'], $resource, $action )) {
  55. $flag = true;
  56. break;
  57. }
  58. }
  59. }
  60. /*
  61. * Doo::acl()->isAllowed($uGroups['groups'], $resource, $action);
  62. */
  63. // 单独判断办事处汇总的访问权限 invoiceAggregateCategoryDetail,invoiceAggregateStaffDetail
  64. if ($action == 'invoiceAggregateCategoryDetail' || $action == 'invoiceAggregateStaffDetail') {
  65. Doo::loadModel ( "invoiceCategoryManage" );
  66. $invoiceCategoryManage = new invoiceCategoryManage ();
  67. $icm = $invoiceCategoryManage->getInvoiceCMByStaff ( $sid );
  68. if (empty ( $icm ))
  69. die ( 'illegal request-iacd' );
  70. }
  71. // 单独判断应收款访问权限
  72. if ($action == 'invoiceAggregateCompanyDetail') {
  73. Doo::loadModel ( "invoiceCompanyManage" );
  74. $invoiceCompanyManage = new invoiceCompanyManage ();
  75. $icm = $invoiceCompanyManage->getInvoiceCMByStaff ( $sid );
  76. if (empty ( $icm ))
  77. die ( 'illegal request' );
  78. }
  79. // 主权限获得与判断
  80. Doo::loadModel ( 'staff' );
  81. $staff = new staff ();
  82. $detail = $staff->getStaffBySid ( $_COOKIE ["staff"] );
  83. $accessModular = 'INVOICE';
  84. if (empty ( $detail ['cldAccessArray'] ))
  85. die ( 'illegal request' );
  86. else {
  87. if (in_array ( $accessModular, $detail ['cldAccessArray'] )) {
  88. if (Doo::acl ()->isAllowed ( $accessModular, $resource, $action )) {
  89. $flag = true;
  90. } else {
  91. $flag = false;
  92. }
  93. } else {
  94. die ( 'illegal request' );
  95. }
  96. }
  97. if (! $flag)
  98. die ( 'illegal request' );
  99. }
  100. function __construct() {
  101. if (isset ( $_COOKIE ["staff"] )) {
  102. if (! empty ( $_COOKIE ["staff"] )) {
  103. Doo::loadModel ( 'staff' );
  104. $staff = new staff ();
  105. $uriPartsOrig = explode ( '/', $_SERVER ['REQUEST_URI'] );
  106. $this->ACTION = $uriPartsOrig [1];
  107. $this->data ['new'] = $this->isInvoiceNew ();
  108. $this->staff = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  109. $this->data ['isStaffCompleteMsg'] = false;
  110. $detail = $staff->checkStaffInfoIsComplete ( $_COOKIE ["staff"] );
  111. if (! empty ( $detail ))
  112. $this->data ['isStaffCompleteMsg'] = true;
  113. return "/";
  114. }
  115. }
  116. Doo::loadCore ( 'uri/DooUriRouter' );
  117. $router = new DooUriRouter ();
  118. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  119. if ($routeRs ['1'] != "login") {
  120. header ( 'Content-Type:text/html;charset=utf-8' );
  121. @header ( "Location: /login" );
  122. }
  123. }
  124. function testSend() {
  125. // 测试根据规则发送信息 普通发送
  126. // $pendingApprovalsSid = 41;
  127. // Doo::loadModel ( 'staff' );
  128. // $staff = new staff ();
  129. // $username2 = $staff->getOne ( array ( 'select' => 'wxid', 'where' => 'sid=' . $pendingApprovalsSid, 'asArray' => TRUE ) );
  130. // // 发送微信审批通知
  131. // $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  132. // $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  133. // Doo::loadModel ( 'staff' );
  134. // $staff = new staff ();
  135. // $toparty = $this->getToparty ( '广东办' );
  136. // $wxList = array ();
  137. // if (! empty ( $toparty )) {
  138. // $userList = $this->getUserByToparty ( $toparty );
  139. // $userCon = implode ( ',', $userList );
  140. // // echo $userCon;
  141. // $sidList = $staff->getStaffByWxid ( $userCon );
  142. // foreach ( $sidList as $key => $value ) {
  143. // $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  144. // if ($falg) {
  145. // array_push ( $wxList, $value ['wxid'] );
  146. // }
  147. // }
  148. // $wxString = implode ( '|', $wxList );
  149. // print_r ( $wxList );
  150. // echo $wxString;
  151. // }
  152. // 测试发送
  153. /*
  154. * //$toparty = $this->getWxidByCategory( $receivablesCategory [1] ); $toparty = $this->getToparty ( $receivablesCategory [1] ); $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。'; if ($toparty != 0) $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  155. */
  156. // print_r ( $userList );
  157. // $msTouser='caipin|outaozhen';
  158. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  159. // $title2 = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  160. // $hfreult = $this->msgSend ( '', $title2, '', 'outaozhen' );
  161. // $toparty= $this->getToparty('广东办');
  162. // $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  163. // $toparty = 26;
  164. // $msg = '';
  165. // $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/1.html';
  166. // $hfreult = $this->msgSendToparty ( $msg, '', '', $toparty,'text' );
  167. }
  168. function invoice() {
  169. Doo::loadModel ( 'invoice' );
  170. $invoice = new invoice ();
  171. Doo::loadModel ( 'express' );
  172. $express = new express ();
  173. $expressList = $express->getExpressByAll ();
  174. $this->data ['expressList'] = $expressList;
  175. // Doo::loadModel ( 'invoiceReceivables' );
  176. // $invoiceReceivables = new invoiceReceivables ();
  177. // $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  178. Doo::loadClass ( 'XDeode' );
  179. $XDeode = new XDeode ( 5 );
  180. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  181. Doo::loadModel ( 'invoiceStatistics' );
  182. $invoiceStatistics = new invoiceStatistics ();
  183. $isMonth = $invoiceStatistics->getStatisticsByMonth ( $sid );
  184. // 缓存统计结果
  185. $year = date ( "Y" );
  186. $tmp_date = date ( "Ym" );
  187. $tmp_year = substr ( $tmp_date, 0, 4 );
  188. $tmp_mon = substr ( $tmp_date, 4, 2 );
  189. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  190. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  191. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . "_" . $sid . ".htm";
  192. if (is_file ( $path ))
  193. $htm = file_get_contents ( $path );
  194. else
  195. $htm = $this->showCache ( $path, $sid );
  196. $invoiceList = $invoice->getMyInvoice ( $sid );
  197. $sql = 'status=2 and printStatus=1 and irid!="" and sid=' . $sid;
  198. $list = $invoice->getInvoiceByUntreadStatusPage ( 4, $sql );
  199. // 我的待入账发票 and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  200. $sql = "status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid=" . $sid;
  201. $myInvoiceUnAccount = $invoice->getInvoiceByUntreadStatusPage ( 4, $sql );
  202. // 获得已退票功能
  203. $untreadStatusList = $invoice->getMyInvoiceByUntreadStatus ( 2, 0, 5, $sid );
  204. $this->data ['untreadStatusList'] = $untreadStatusList;
  205. // print_r($untreadStatusList);
  206. $this->data ['isMonth'] = $isMonth;
  207. $this->data ['htm'] = $htm;
  208. $this->data ['invoiceList'] = $invoiceList;
  209. $this->data ['receivablesList'] = $list;
  210. $this->data ['myInvoiceUnAccount'] = $myInvoiceUnAccount;
  211. $this->data ['memu'] = "invoice";
  212. $this->data ['staff'] = $this->staff;
  213. $this->data ['receiptMemu'] = 'invoice';
  214. $this->render ( "/admin/invoice", $this->data );
  215. }
  216. function invoiceExpress() {
  217. $expressCom = isset ( $this->params ['expressCom'] ) ? $this->params ['expressCom'] : "";
  218. $expressNumber = isset ( $this->params ['expressNumber'] ) ? $this->params ['expressNumber'] : "";
  219. $this->data ['expressCom'] = $expressCom;
  220. $this->data ['expressNumber'] = $expressNumber;
  221. $this->render ( "/admin/invoiceExpress", $this->data );
  222. }
  223. function invoiceAdd() {
  224. session_start ();
  225. /*Doo::loadModel ( 'invoice' );
  226. $invoice = new invoice ();
  227. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );*/
  228. Doo::loadModel ( 'L_category' );
  229. $lCategory = new L_category ();
  230. $category = $lCategory->find ( array (
  231. 'asArray' => true
  232. ) );
  233. $this->data ['category'] = $category;
  234. Doo::loadModel ( 'invoiceTraining' );
  235. $invoiceTraining = new invoiceTraining ();
  236. $itList = $invoiceTraining->getInvoiceTrainingByCid ( $this->staff [0] ['cid'] );
  237. Doo::loadModel ( 'receipt' );
  238. $receipt = new receipt ();
  239. foreach ( $itList as $key => $value ) { // 不展示已结算完结的培训班
  240. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $value ['itid'] );
  241. if (! empty ( $receiptDetail )) {
  242. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9) {
  243. unset ( $itList [$key] );
  244. }
  245. }
  246. }
  247. $this->data ['itList'] = $itList;
  248. $token = $this->set_token ();
  249. $tokenTime=time().rand(5, 15);
  250. $_SESSION ['token_' . $this->staff [0] ['sidKey'].'_'.$tokenTime] = $token;
  251. $this->data ['token'] = $token;
  252. $this->data['tokenTime']=$tokenTime;
  253. $this->data ['memu'] = "invoice";
  254. $this->data ['staff'] = $this->staff;
  255. $this->data ['receiptMemu'] = 'invoice';
  256. $this->render ( "/admin/invoiceAdd", $this->data );
  257. }
  258. /**
  259. * 自更新发票信息库
  260. * @param unknown $invoicePrintDetail
  261. */
  262. function autoUpdateInvoiceInfoBase($invoicePrintDetail) {
  263. // 发票信息库
  264. Doo::loadModel ( 'invoiceInfoBase' );
  265. $invoiceInfoBase = new invoiceInfoBase ();
  266. $updateDate = strtotime ( $invoicePrintDetail ['date'] );
  267. $TIN = $invoicePrintDetail ['TIN'];
  268. $invoiceTitle = $invoicePrintDetail ['invoiceTitle'];
  269. if (empty ( $invoiceTitle ))
  270. $invoiceTitle = $invoicePrintDetail ['invoiceCompany'];
  271. $IIBList = $invoiceInfoBase->getInvoiceInfoByTT ( $TIN, $invoiceTitle );
  272. // 确认有该条发票信息
  273. $invoiceInfoBase = new invoiceInfoBase ();
  274. if (! empty ( $IIBList )) {
  275. // 发票库里的信息数量
  276. $IIBListCount = count ( $IIBList );
  277. if ($IIBListCount == 1) { // 更新发票--提交是最新的时间
  278. $item = array (
  279. 'iibID' => $IIBList [0] ['iibID'],
  280. 'invoiceTitle' => $invoiceTitle,
  281. 'TIN' => $TIN
  282. );
  283. if (! empty ( $invoicePrintDetail ['address'] )) {
  284. $item += array (
  285. 'address' => $invoicePrintDetail ['address']
  286. );
  287. }
  288. if (! empty ( $invoicePrintDetail ['phone'] )) {
  289. $item += array (
  290. 'phone' => $invoicePrintDetail ['phone']
  291. );
  292. }
  293. if (! empty ( $invoicePrintDetail ['bank'] )) {
  294. $item += array (
  295. 'bank' => $invoicePrintDetail ['bank']
  296. );
  297. }
  298. if (! empty ( $invoicePrintDetail ['bankAccount'] )) {
  299. $item += array (
  300. 'bankAccount' => $invoicePrintDetail ['bankAccount']
  301. );
  302. }
  303. if ($updateDate >= strtotime ($IIBList [0] ['updateDate'])) {
  304. $item += array (
  305. 'updateDate' => $invoicePrintDetail ['date']
  306. );
  307. $invoiceInfoBase->setInvoiceInfoBaseByCondition ( $item );
  308. }
  309. } else { // 删除多张发票,重新添加发票
  310. $iibIDStr = '';
  311. $iibID = array ();
  312. foreach ( $IIBList as $key => $value ) {
  313. array_push ( $iibID, $value ['iibID'] );
  314. }
  315. $iibIDStr = implode ( ",", $iibID ); // 删除
  316. $invoiceInfoBase->delInvoiceInfoBaseByIibStr ( $iibIDStr );
  317. $item = array (
  318. 'invoiceTitle' => $invoiceTitle,
  319. 'TIN' => $TIN,
  320. 'address' => $invoicePrintDetail ['address'],
  321. 'phone' => $invoicePrintDetail ['phone'],
  322. 'bank' => $invoicePrintDetail ['bank'],
  323. 'bankAccount' => $invoicePrintDetail ['bankAccount'],
  324. 'updateDate' => $invoicePrintDetail ['date']
  325. );
  326. $invoiceInfoBase->addInvoiceInfoBase ( $item );
  327. }
  328. } else { // 没有新增发票信息
  329. $item = array (
  330. 'invoiceTitle' => $invoiceTitle,
  331. 'TIN' => $TIN,
  332. 'address' => $invoicePrintDetail ['address'],
  333. 'phone' => $invoicePrintDetail ['phone'],
  334. 'bank' => $invoicePrintDetail ['bank'],
  335. 'bankAccount' => $invoicePrintDetail ['bankAccount'],
  336. 'updateDate' => $invoicePrintDetail ['date']
  337. );
  338. $invoiceInfoBase->addInvoiceInfoBase ( $item );
  339. }
  340. }
  341. function invoiceAddFill() {
  342. session_start ();
  343. Doo::loadModel ( 'L_category' );
  344. $lCategory = new L_category ();
  345. $category = $lCategory->find ( array (
  346. 'asArray' => true
  347. ) );
  348. $this->data ['category'] = $category;
  349. Doo::loadModel ( 'invoiceTraining' );
  350. $invoiceTraining = new invoiceTraining ();
  351. $itList = $invoiceTraining->getInvoiceTrainingByCid ( $this->staff [0] ['cid'] );
  352. $this->data ['itList'] = $itList;
  353. Doo::loadModel ( 'invoice' );
  354. $invoice = new invoice ();
  355. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );
  356. $detail ['mailItemsArray'] = json_decode ( $detail ['mailItemsJson'], true );
  357. $token = $this->set_token ();
  358. $tokenTime=time().rand(5, 15);
  359. $_SESSION ['token_' . $this->staff [0] ['sidKey'].'_'.$tokenTime] = $token;
  360. $this->data ['token'] = $token;
  361. $this->data['tokenTime']=$tokenTime;
  362. $this->data ['invoiceDetail'] = $detail;
  363. $this->data ['memu'] = "invoice";
  364. $this->data ['staff'] = $this->staff;
  365. $this->data ['receiptMemu'] = 'invoice';
  366. $this->render ( "/admin/invoiceAddFill", $this->data );
  367. }
  368. /**
  369. * 提交一份开票申请,并记录下操作日志
  370. *
  371. * @since 1.0.0
  372. * @var integer cid 办事处ID
  373. * @var integer invoiceType 发票类型
  374. * @var integer doPost 是否邮寄
  375. * @var integer invoicePrice 开票金额
  376. * @var string invoiceElement 开票内容
  377. * @var string invoiceTitle 发票抬头
  378. * @var string invoiceCompany 单位名称
  379. * @var string TIN 纳税人识别码
  380. * @var string address 注册地址
  381. * @var string phone 注册电话
  382. * @var string bank 开户银行
  383. * @var string bankAccount 银行账户
  384. * @var string recipients 收件人
  385. * @var string recipientsPhone 收件人手机/电话
  386. * @var string recipientsAddress 收件地址
  387. * @var string mailItems 邮寄物品
  388. * @var string remark 备注
  389. * @return string 返回跳转开票主页路径
  390. */
  391. function invoiceAddDo() {
  392. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  393. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  394. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  395. // $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  396. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  397. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  398. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  399. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  400. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  401. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  402. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  403. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  404. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  405. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  406. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  407. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  408. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  409. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  410. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  411. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  412. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  413. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  414. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  415. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  416. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  417. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  418. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  419. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  420. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  421. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  422. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  423. $trainId = $this->get_args ( 'trainId' ) ? $this->get_args ( 'trainId' ) : 0;
  424. $settlementType = $this->get_args ( 'settlementType' ) ? $this->get_args ( 'settlementType' ) : "";
  425. /*
  426. * $mailList=array(); array_push($mailList, array('invoice'=>1)); array_push($mailList, array('mailItems'=>$mailItems)); if (!empty($softLock)) array_push($mailList, array('softLock'=>$softLockNum)); if (!empty($contract)) array_push($mailList, array('contract'=>$contractNum)); if (!empty($instructions)) array_push($mailList, array('instructions'=>$instructionsNum)); if (!empty($remittance)) array_push($mailList, array('remittance'=>$remittance)); echo json_encode($mailList) ; print_r($mailList); die;
  427. */
  428. $token = $this->get_args ( 'token' ) ? $this->get_args ( 'token' ) : "";
  429. $tokenTime = $this->get_args ( 'tokenTime' ) ? $this->get_args ( 'tokenTime' ) : "";
  430. if (empty ( $token )) {
  431. die ( 'illegal request-token' );
  432. } else {
  433. session_start ();
  434. $sessionKey='token_' . $this->staff [0] ['sidKey'].'_'.$tokenTime;
  435. header ( 'Content-Type:text/html;charset=utf-8' );
  436. if (!isset($_SESSION [$sessionKey])||empty($_SESSION [$sessionKey])) {
  437. die ( '请重新刷新发票申请页面' );
  438. }elseif($_SESSION [$sessionKey]=='repeat'){
  439. die ( '请勿重复申请发票' );
  440. } else {
  441. if ($_SESSION [$sessionKey] != $token){
  442. die ( '请勿重复申请发票' );
  443. }else{
  444. $_SESSION [$sessionKey] = 'repeat';
  445. }
  446. }
  447. }
  448. if ($invoiceType == 1) {
  449. $temporary = $invoiceQuantity * $invoiceUnitPrice;
  450. if ($temporary > 100001) {
  451. header ( 'Content-Type:text/html;charset=utf-8' );
  452. die ( '专用发票总金额暂时不能超过100000.00(一万)元。' );
  453. // die ( 'illegal request-Please priceError' );
  454. }
  455. }
  456. if (empty ( $this->staff [0] ))
  457. die ( 'illegal request-Please login' );
  458. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $settlementType )) {
  459. Doo::loadModel ( 'invoice' );
  460. $invoice = new invoice ();
  461. Doo::loadModel ( 'L_category' );
  462. $lCategory = new L_category ();
  463. Doo::loadModel ( 'invoiceManage' );
  464. $invoiceManage = new invoiceManage ();
  465. Doo::loadModel ( 'invoiceOperationLog' );
  466. $invoiceOperationLog = new invoiceOperationLog ();
  467. Doo::loadClass ( 'XDeode' );
  468. $XDeode = new XDeode ( 5 );
  469. $trainId = $XDeode->decode ( $trainId );
  470. $categoryDetil = $lCategory->getOne ( array (
  471. 'SELECT' => 'title',
  472. 'where' => 'cid=' . $cid,
  473. 'asArray' => true
  474. ) );
  475. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  476. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  477. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  478. // print_r(current($invoiceManageDetail ['staffList']));
  479. // die;
  480. $moldManage = array ();
  481. foreach ( $invoiceManageList as $key => $value ) {
  482. if ($value ['mold'] == '发票打印')
  483. $moldManage [$value ['mold']] = $value ['staffList'];
  484. elseif ($value ['mold'] == '发票邮寄')
  485. $moldManage [$value ['mold']] = $value ['staffList'];
  486. elseif ($value ['mold'] == '发票退票')
  487. $moldManage [$value ['mold']] = $value ['staffList'];
  488. }
  489. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  490. $st = '';
  491. if ($settlementType == 'SOFTWARE') {
  492. $st = 0;
  493. $trainId = 0;
  494. } elseif ($settlementType == 'TRAINING') {
  495. $st = 1;
  496. if (empty ( $trainId ) && ! is_numeric ( $trainId )) {
  497. die ( 'illegal request-trainingIdError' );
  498. }
  499. } else {
  500. die ( 'illegal request-settlementError' );
  501. }
  502. $item = array (
  503. 'cid' => $cid,
  504. 'categoryName' => $categoryDetil ['title'],
  505. 'invoiceElement' => $invoiceElement,
  506. 'invoiceQuantity' => $invoiceQuantity,
  507. 'invoiceUnitPrice' => $invoiceUnitPrice,
  508. 'invoicePrice' => $invoicePrice,
  509. 'invoiceType' => $invoiceType,
  510. 'settlementType' => $st,
  511. 'doPost' => $doPost,
  512. 'status' => 1,
  513. 'invoiceSerial' => "#F" . date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT),
  514. 'date' => date ( "Y-m-d H:i:s" ),
  515. 'updateTime' => date ( "Y-m-d H:i:s" ),
  516. 'sid' => $this->staff [0] ['sid'],
  517. 'userName' => $this->staff [0] ['username'],
  518. 'invoiceManage' => $invoiceManageDetail ['staff'],
  519. 'pendingApprovals' => $pendingApprovalsSid,
  520. 'moldManage' => json_encode ( $moldManage ),
  521. 'remark' => $remark,
  522. 'trainId' => $trainId
  523. );
  524. if ($invoiceType == 0)
  525. $item += array (
  526. 'invoiceTitle' => $invoiceTitle,
  527. 'TIN' => $TINT,
  528. 'address' => $addressT,
  529. 'phone' => $phoneT,
  530. 'bank' => $bankT,
  531. 'bankAccount' => $bankAccountT
  532. );
  533. else {
  534. $item += array (
  535. 'invoiceCompany' => $invoiceCompany,
  536. 'TIN' => $TIN,
  537. 'address' => $address,
  538. 'phone' => $phone,
  539. 'bank' => $bank,
  540. 'bankAccount' => $bankAccount
  541. );
  542. }
  543. if ($doPost == 1) {
  544. $mailList = array (
  545. 'invoice' => 1,
  546. 'mailItems' => $mailItems
  547. );
  548. if (! empty ( $softLock ))
  549. $mailList += array (
  550. 'softLock' => $softLockNum
  551. );
  552. else
  553. $mailList += array (
  554. 'softLock' => 0
  555. );
  556. if (! empty ( $contract ))
  557. $mailList += array (
  558. 'contract' => $contractNum
  559. );
  560. else
  561. $mailList += array (
  562. 'contract' => 0
  563. );
  564. if (! empty ( $instructions ))
  565. $mailList += array (
  566. 'instructions' => $instructionsNum
  567. );
  568. else
  569. $mailList += array (
  570. 'instructions' => 0
  571. );
  572. if (! empty ( $remittance ))
  573. $mailList += array (
  574. 'remittance' => $remittance
  575. );
  576. else
  577. $mailList += array (
  578. 'remittance' => ''
  579. );
  580. $mailString = '发票x1张,备注:' . $mailItems;
  581. if (! empty ( $softLock ))
  582. $mailString .= ',软件锁x' . $softLockNum . '个';
  583. if (! empty ( $contract ))
  584. $mailString .= ',合同x' . $contractNum . '份';
  585. if (! empty ( $instructions ))
  586. $mailString .= ',说明书x' . $instructionsNum . '本';
  587. if (! empty ( $remittance ))
  588. $mailString .= ',汇款账号单(张)';
  589. $item += array (
  590. 'recipients' => $recipients,
  591. 'recipientsPhone' => $recipientsPhone,
  592. 'recipientsAddress' => $recipientsAddress,
  593. 'mailItems' => $mailString,
  594. 'mailItemsJson' => json_encode ( $mailList )
  595. );
  596. }
  597. $iid = $invoice->addInvoice ( $item );
  598. // 如果是培训班结算 创建培训班发票到培训班备份中
  599. if (! empty ( $st ) && $st == 1) {
  600. Doo::loadModel ( 'invoiceStore' );
  601. $invoiceStore = new invoiceStore ();
  602. Doo::loadModel ( 'invoiceTraining' );
  603. $invoiceTraining = new invoiceTraining ();
  604. $isid = $invoiceStore->setInvoiceToInvoiceStore ( $iid );
  605. $itemIS = array (
  606. 'isid' => $isid,
  607. 'ipSource' => 1,
  608. 'apStatus' => 1,
  609. 'iid' => $iid
  610. );
  611. $invoiceStore->setInvoiceStoreByCondition ( $itemIS );
  612. // 更新培训班总数量
  613. $detailIT = $invoiceTraining->getInvoiceTrainingByItid ( $trainId );
  614. $item = array (
  615. 'itid' => $trainId,
  616. 'invoiceTotal' => $detailIT ['invoiceTotal'] + 1,
  617. 'submitStatus' => 1
  618. );
  619. $itid = $invoiceTraining->setInvoiceTrainByCondition ( $item );
  620. }
  621. // 操作日志
  622. $item = array (
  623. 'date' => date ( "Y-m-d H:i:s" ),
  624. 'operation' => "创建",
  625. 'status' => 1,
  626. 'img' => $this->staff [0] ['avatar'],
  627. 'username' => $this->staff [0] ['username'],
  628. 'uid' => $this->staff [0] ['sid'],
  629. 'category' => $this->staff [0] ['category'],
  630. 'iid' => $iid
  631. );
  632. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  633. $item = array (
  634. 'date' => date ( "Y-m-d H:i:s" ),
  635. 'operation' => "提交审批",
  636. 'status' => 1,
  637. 'img' => $this->staff [0] ['avatar'],
  638. 'username' => $this->staff [0] ['username'],
  639. 'uid' => $this->staff [0] ['sid'],
  640. 'category' => $this->staff [0] ['category'],
  641. 'iid' => $iid
  642. );
  643. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  644. Doo::loadModel ( 'staff' );
  645. $staff = new staff ();
  646. $username2 = $staff->getOne ( array (
  647. 'select' => 'wxid',
  648. 'where' => 'sid=' . $pendingApprovalsSid,
  649. 'asArray' => TRUE
  650. ) );
  651. // 发送微信审批通知
  652. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  653. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  654. }
  655. return "/invoice";
  656. }
  657. function invoiceEdit() {
  658. Doo::loadClass ( 'XDeode' );
  659. $XDeode = new XDeode ( 5 );
  660. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  661. $iid = $XDeode->decode ( $iid );
  662. if (! is_numeric ( $iid ))
  663. die ( 'illegal request' );
  664. Doo::loadModel ( 'invoice' );
  665. $invoice = new invoice ();
  666. Doo::loadModel ( 'invoiceOperationLog' );
  667. $invoiceOperationLog = new invoiceOperationLog ();
  668. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  669. $operation = $invoiceOperationLog->getInvoiceOperationByDropped ( $iid );
  670. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  671. $this->data ['operation'] = $operation;
  672. $this->data ['invoiceDetail'] = $invoiceDetail;
  673. $this->data ['memu'] = "invoice";
  674. $this->data ['staff'] = $this->staff;
  675. $this->data ['receiptMemu'] = 'invoice';
  676. $this->render ( "/admin/invoiceEdit", $this->data );
  677. }
  678. /**
  679. * 重新编辑退回的发票
  680. * @return string
  681. */
  682. function invoiceEditDo() {
  683. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  684. Doo::loadModel ( 'invoice' );
  685. $invoice = new invoice ();
  686. $iid = $invoice->authcode ( $iidKey );
  687. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  688. die ( 'illegal request' );
  689. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  690. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  691. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  692. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  693. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  694. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  695. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  696. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  697. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  698. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  699. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  700. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  701. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  702. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  703. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  704. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  705. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  706. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  707. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  708. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  709. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  710. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  711. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  712. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  713. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  714. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  715. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  716. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  717. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  718. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  719. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  720. if ($invoiceType == 1) {
  721. $temporary = $invoiceQuantity * $invoiceUnitPrice;
  722. if ($temporary > 100001)
  723. die ( 'illegal request-Please priceError' );
  724. }
  725. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  726. Doo::loadModel ( 'invoiceManage' );
  727. $invoiceManage = new invoiceManage ();
  728. Doo::loadModel ( 'invoiceOperationLog' );
  729. $invoiceOperationLog = new invoiceOperationLog ();
  730. Doo::loadModel ( 'invoiceStore' );
  731. $invoiceStore = new invoiceStore ();
  732. $cid = explode ( ':', $cid );
  733. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  734. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  735. $moldManage = array ();
  736. foreach ( $invoiceManageList as $key => $value ) {
  737. if ($value ['mold'] == '发票打印')
  738. $moldManage [$value ['mold']] = $value ['staffList'];
  739. elseif ($value ['mold'] == '发票邮寄')
  740. $moldManage [$value ['mold']] = $value ['staffList'];
  741. elseif ($value ['mold'] == '发票打印')
  742. $moldManage [$value ['mold']] = $value ['staffList'];
  743. }
  744. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  745. $item = array (
  746. 'iid' => $iid,
  747. 'cid' => $cid [0],
  748. 'categoryName' => $cid [1],
  749. 'invoiceElement' => $invoiceElement,
  750. 'invoiceQuantity' => $invoiceQuantity,
  751. 'invoiceUnitPrice' => $invoiceUnitPrice,
  752. 'invoicePrice' => $invoicePrice,
  753. 'invoiceType' => $invoiceType,
  754. 'doPost' => $doPost,
  755. 'status' => 1,
  756. 'updateTime' => date ( "Y-m-d H:i:s" ),
  757. 'remark' => $remark
  758. );
  759. if ($invoiceType == 0)
  760. $item += array (
  761. 'invoiceTitle' => $invoiceTitle,
  762. 'TIN' => $TINT,
  763. 'address' => $addressT,
  764. 'phone' => $phoneT,
  765. 'bank' => $bankT,
  766. 'bankAccount' => $bankAccountT
  767. );
  768. else {
  769. $item += array (
  770. 'invoiceCompany' => $invoiceCompany,
  771. 'TIN' => $TIN,
  772. 'address' => $address,
  773. 'phone' => $phone,
  774. 'bank' => $bank,
  775. 'bankAccount' => $bankAccount
  776. );
  777. }
  778. if ($doPost == 1) {
  779. $mailList = array (
  780. 'invoice' => 1,
  781. 'mailItems' => $mailItems
  782. );
  783. if (! empty ( $softLock ))
  784. $mailList += array (
  785. 'softLock' => $softLockNum
  786. );
  787. else
  788. $mailList += array (
  789. 'softLock' => '0'
  790. );
  791. if (! empty ( $contract ))
  792. $mailList += array (
  793. 'contract' => $contractNum
  794. );
  795. else
  796. $mailList += array (
  797. 'contract' => '0'
  798. );
  799. if (! empty ( $instructions ))
  800. $mailList += array (
  801. 'instructions' => $instructionsNum
  802. );
  803. else
  804. $mailList += array (
  805. 'instructions' => '0'
  806. );
  807. if (! empty ( $remittance ))
  808. $mailList += array (
  809. 'remittance' => $remittance
  810. );
  811. else
  812. $mailList += array (
  813. 'remittance' => ''
  814. );
  815. $mailString = '发票x1,备注:' . $mailItems;
  816. if (! empty ( $softLock ))
  817. $mailString .= ',软件锁x' . $softLockNum;
  818. if (! empty ( $contract ))
  819. $mailString .= ',合同x' . $contractNum;
  820. if (! empty ( $instructions ))
  821. $mailString .= ',说明书x' . $instructionsNum;
  822. if (! empty ( $remittance ))
  823. $mailString .= ',汇款账号单';
  824. $item += array (
  825. 'recipients' => $recipients,
  826. 'recipientsPhone' => $recipientsPhone,
  827. 'recipientsAddress' => $recipientsAddress,
  828. 'mailItems' => $mailString,
  829. 'mailItemsJson' => json_encode ( $mailList )
  830. );
  831. }
  832. $invoice->setInvoiceByCondition ( $item );
  833. // 更新培训班仓库里的发票
  834. $detail = $invoice->getInvoiceByIid ( $iid );
  835. if (! empty ( $detail ['isid'] )) {
  836. $invoiceStore->isid = $detail ['isid'];
  837. $invoiceStore->invoiceQuantity = $invoiceQuantity;
  838. $invoiceStore->invoiceUnitPrice = $invoiceUnitPrice;
  839. $invoiceStore->invoicePrice = $invoicePrice;
  840. $invoiceStore->update ();
  841. }
  842. $item = array (
  843. 'date' => date ( "Y-m-d H:i:s" ),
  844. 'operation' => "重新提交审批",
  845. 'status' => 1,
  846. 'img' => $this->staff [0] ['avatar'],
  847. 'username' => $this->staff [0] ['username'],
  848. 'uid' => $this->staff [0] ['sid'],
  849. 'category' => $this->staff [0] ['category'],
  850. 'iid' => $iid
  851. );
  852. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  853. }
  854. return "/invoice";
  855. }
  856. /**
  857. * 培训班
  858. */
  859. function invoiceTraining() {
  860. Doo::loadModel ( 'L_category' );
  861. $lCategory = new L_category ();
  862. Doo::loadModel ( 'invoiceTraining' );
  863. $invoiceTraining = new invoiceTraining ();
  864. Doo::loadModel ( 'invoiceTrainManage' );
  865. $invoiceTrainManage = new invoiceTrainManage ();
  866. $imcStaff = $invoiceTrainManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  867. $cidList = array ();
  868. foreach ( $imcStaff as $key => $value ) {
  869. array_push ( $cidList, $value ['cid'] );
  870. }
  871. if (empty ( $cidList )) {
  872. $cidString = $this->staff [0] ['cid'];
  873. } else {
  874. $cidString = implode ( ',', $cidList );
  875. $cidString .= $cidString . ',' . $this->staff [0] ['cid'];
  876. }
  877. $itTodoList = $invoiceTraining->getInvoiceTrainingByTodo ( '', $cidString, $this->staff [0] ['sid'] );
  878. $itedList = $invoiceTraining->getInvoiceTrainingByStatus ( 2, '', $cidString, $this->staff [0] ['sid'] );
  879. $category = $lCategory->getCategory ();
  880. $itid = array ();
  881. foreach ( $itTodoList as $key => $value ) {
  882. array_push ( $itid, $value ['itid'] );
  883. // 如果入账100%更新为已完成
  884. if ($itTodoList [$key] ['arriveSchedule'] >= 100) {
  885. $invoiceTraining = new invoiceTraining ();
  886. $invoiceTraining->itid = $value ['itid'];
  887. $invoiceTraining->status = 2;
  888. $invoiceTraining->update ();
  889. }
  890. }
  891. foreach ( $itedList as $value ) {
  892. array_push ( $itid, $value ['itid'] );
  893. }
  894. $itid = implode ( ',', $itid );
  895. $this->data ['itStatist'] = $invoiceTraining->getInvoiceTrainStatistics ( $itid );
  896. // print_r($itTodoList);
  897. $this->data ['trainCount'] = count ( $itTodoList ) + count ( $itedList );
  898. $this->data ['itTodoList'] = $itTodoList;
  899. $this->data ['itedList'] = $itedList;
  900. $this->data ['category'] = $category;
  901. $this->data ['memu'] = "invoice";
  902. $this->data ['staff'] = $this->staff;
  903. $this->data ['receiptMemu'] = 'invoiceTraining';
  904. $this->render ( "/admin/invoiceTraining", $this->data );
  905. }
  906. /**
  907. * 创建培训班
  908. */
  909. function invoiceTrainingAdd() {
  910. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  911. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  912. $trainDate = $this->get_args ( 'trainDate' ) ? $this->get_args ( 'trainDate' ) : "";
  913. if (empty ( $this->staff [0] ))
  914. die ( 'illegal request' );
  915. if (! empty ( $cid ) && ! empty ( $trainName ) && ! empty ( $trainDate )) {
  916. Doo::loadModel ( 'invoiceTraining' );
  917. $invoiceTraining = new invoiceTraining ();
  918. Doo::loadModel ( 'invoice' );
  919. $invoice = new invoice ();
  920. Doo::loadModel ( 'L_category' );
  921. $lCategory = new L_category ();
  922. Doo::loadModel ( 'invoiceManage' );
  923. $invoiceManage = new invoiceManage ();
  924. Doo::loadModel ( 'invoiceOperationLog' );
  925. $invoiceOperationLog = new invoiceOperationLog ();
  926. $item = array (
  927. 'cid' => $cid,
  928. 'trainName' => $trainName,
  929. 'trainDate' => $trainDate,
  930. 'creator' => $this->staff [0] ['sid'],
  931. 'creatorDate' => date ( "Y-m-d H:i:s" )
  932. );
  933. $itid = $invoiceTraining->addInvoiceTraining ( $item );
  934. }
  935. return "/invoiceTraining";
  936. }
  937. /**
  938. * 删除培训班
  939. */
  940. function invoiceTrainingDelDo() {
  941. $itid = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  942. if (! empty ( $itid )) {
  943. Doo::loadModel ( 'invoiceTraining' );
  944. $invoiceTraining = new invoiceTraining ();
  945. $invoiceTraining->delInvoiceTrainingByItid ( $itid );
  946. }
  947. return "/invoiceTraining";
  948. }
  949. /**
  950. * 培训班详情
  951. */
  952. function invoiceTrainingDetail() {
  953. $trainStatus = $this->get_args ( 'trainStatus' ) ? $this->get_args ( 'trainStatus' ) : "ALL";
  954. $itid = isset ( $this->params ['trainingKey'] ) ? $this->params ['trainingKey'] : "";
  955. Doo::loadModel ( 'invoiceTraining' );
  956. $invoiceTraining = new invoiceTraining ();
  957. Doo::loadModel ( 'invoiceStore' );
  958. $invoiceStore = new invoiceStore ();
  959. if (empty ( $itid ))
  960. die ( 'illegal request' );
  961. $con = ' (b.untreadStatus is null or b.untreadStatus!=2) and ';
  962. if ($trainStatus == "SUBED")
  963. $con = ' (b.untreadStatus is null ) and ';
  964. elseif ($trainStatus == "APPROVAL")
  965. $con = ' ( b.status=1 and b.untreadStatus!=2 ) and ';
  966. elseif ($trainStatus == "TICKET")
  967. $con = ' (b.printStatus=1 and b.status=2 and b.untreadStatus!=2) and ';
  968. elseif ($trainStatus == "TICKETING") {
  969. $con = ' (b.status=2 and b.untreadStatus=1) and ';
  970. }
  971. $detail = $invoiceTraining->getInvoiceTrainingByItid ( $itid );
  972. $isList = $invoiceStore->getinvoiceStoreByItid ( $itid, $con );
  973. //print_r($isList);
  974. $trainlist = array ();
  975. foreach ( $isList as $key => $value ) {
  976. $irDetail = array ();
  977. if ($value ['apStatus'] == 1) {
  978. // array_push ( $irDetail, '' );
  979. array_push ( $irDetail, '<input disabled type="checkbox" style="display:none" >' );
  980. } else {
  981. array_push ( $irDetail, '<input type="checkbox" class="hide" id="' . $value ['storeKey'] . '" name="isBox" value="' . $value ['storeKey'] . '" > <a href="/invoiceStoreEdit/' . $value ['storeKey'] . '.html">编辑</a>
  982. <a href="#confirm" onclick="invoiceStoreApproval(\'' . $value ['storeKey'] . '\')" data-toggle="modal">提交审批</a>
  983. <a href="#del" node-iStore="del" data-key="' . $value ['storeKey'] . '" onclick="invoiceStoreDel(\'' . $value ['storeKey'] . '\')" data-toggle="modal" class="colRed">移除</a>' );
  984. }
  985. array_push ( $irDetail, $value ['invoiceSerial'] );
  986. if ($value ['invoiceType'] == 1)
  987. array_push ( $irDetail, $value ['invoiceCompany'] );
  988. else
  989. array_push ( $irDetail, $value ['invoiceTitle'] );
  990. array_push ( $irDetail, $value ['TIN'] );
  991. array_push ( $irDetail, $value ['userName'] );
  992. if (empty ( $value ['mailItems'] ) && $value ['apStatus'] != 1) {
  993. array_push ( $irDetail, '<a href="#confirm-erro" onclick="invoiceStoreMail(\'' . $value ['storeKey'] . '\')" data-toggle="modal">设置邮寄物品</a>' );
  994. } else
  995. array_push ( $irDetail, $value ['mailItems'] );
  996. array_push ( $irDetail, $value ['recipientsAddress'] . $value ['recipients'] . $value ['recipientsPhone'] );
  997. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  998. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  999. array_push ( $irDetail, $value ['invoiceElement'] );
  1000. array_push ( $irDetail, $value ['invoiceQuantity'] );
  1001. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  1002. if ($value ['invoiceType'] == 1)
  1003. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  1004. else
  1005. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  1006. array_push ( $irDetail, $value ['remark'] );
  1007. if ($value ['status'] == 1)
  1008. array_push ( $irDetail, '审批中' );
  1009. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1)
  1010. array_push ( $irDetail, '已出票' );
  1011. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1 && $value ['printStatus'] != 'irid' && ($value ['untreadStatus'] == 3 || $value ['untreadStatus'] == 0))
  1012. array_push ( $irDetail, '已入账' );
  1013. else
  1014. array_push ( $irDetail, '' );
  1015. array_push ( $irDetail, $value ['invoiceNo'] );
  1016. array_push ( $irDetail, $value ['printTime'] );
  1017. $html = '';
  1018. foreach ( $value ['invoiceReceivables'] as $value ) {
  1019. $html .= '&nbsp;<a href="#billing" node-invoice="INFO" data-type="receivables" data-iskey="' . $value [2] . '" data-toggle="modal">' . $value [1] . '</a>';
  1020. }
  1021. array_push ( $irDetail, $html );
  1022. array_push ( $trainlist, $irDetail );
  1023. }
  1024. $trainlistJson = json_encode ( $trainlist );
  1025. if (empty ( $detail ))
  1026. die ( 'illegal request' );
  1027. // 培训班结算是否有和是否已经结算完成
  1028. Doo::loadModel ( 'receipt' );
  1029. $receipt = new receipt ();
  1030. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $itid );
  1031. $this->data ['receiptDetail'] = $receiptDetail;
  1032. $this->data ['trainStatus'] = $trainStatus;
  1033. $this->data ['itid'] = $itid;
  1034. $this->data ['trainlistJson'] = $trainlistJson;
  1035. $this->data ['iTrainDetail'] = $detail;
  1036. $this->data ['memu'] = "invoice";
  1037. $this->data ['staff'] = $this->staff;
  1038. $this->data ['receiptMemu'] = 'invoiceTraining';
  1039. $this->render ( "/admin/invoiceTrainingDetail", $this->data );
  1040. }
  1041. /**
  1042. * 上传培训班发票
  1043. * @return string
  1044. */
  1045. function invoiceTrainingUpload() {
  1046. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  1047. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  1048. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  1049. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  1050. header ( "HTTP/1.1 500 Internal Server Error" );
  1051. echo "POST exceeded maximum allowed size.";
  1052. exit ( 0 );
  1053. }
  1054. // Settings
  1055. $save_path = DOO::conf ()->SITE_PATH . "upload/invoiceTraining/"; // The path were we will save the file (getcwd() may not be reliable and should be tested in your environment)
  1056. $upload_name = "Filedata";
  1057. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  1058. $extension_whitelist = array (
  1059. "doc",
  1060. "txt",
  1061. "jpg",
  1062. "gif",
  1063. "png"
  1064. ); // Allowed file extensions
  1065. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  1066. // Other variables
  1067. $MAX_FILENAME_LENGTH = 260;
  1068. $file_name = "";
  1069. $file_extension = "";
  1070. $uploadErrors = array (
  1071. 0 => "文件上传成功",
  1072. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  1073. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  1074. 3 => "上传的文件仅为部分文件",
  1075. 4 => "没有文件上传",
  1076. 6 => "缺少临时文件夹"
  1077. );
  1078. $nk = time ();
  1079. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  1080. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  1081. echo "文件无法保存.";
  1082. exit ( 0 );
  1083. }
  1084. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  1085. echo json_encode ( array (
  1086. 'filename' => $file_name,
  1087. 'id' => $nk
  1088. ) );
  1089. exit ( 0 );
  1090. }
  1091. /**
  1092. * 导入发票临时仓库
  1093. */
  1094. function invoiceStoreImport() {
  1095. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  1096. $trainingKey = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  1097. $path = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  1098. if ($path != "" && ! empty ( $trainingKey )) {
  1099. Doo::loadModel ( 'invoiceStore' );
  1100. Doo::loadModel ( 'staff' );
  1101. $staff = new staff ();
  1102. Doo::loadModel ( 'invoiceTraining' );
  1103. $invoiceTraining = new invoiceTraining ();
  1104. Doo::loadClass ( 'XDeode' );
  1105. $XDeode = new XDeode ( 5 );
  1106. $itid = $XDeode->decode ( $trainingKey );
  1107. // 培训班结算是否有和是否已经结算完成
  1108. Doo::loadModel ( 'receipt' );
  1109. $receipt = new receipt ();
  1110. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $itid );
  1111. if (! empty ( $receiptDetail )) {
  1112. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9)
  1113. die ( 'illegal request--status' );
  1114. }
  1115. $exlArray = $this->formatExcelToArrayTrain ( DOO::conf ()->SITE_PATH . "upload/invoiceTraining/" . $path );
  1116. $userName = $this->staff [0] ['username'];
  1117. $sDetail = $staff->getStaffByName ( $userName );
  1118. // die('sdd');
  1119. // 可以优化
  1120. foreach ( $exlArray as $key => $value ) {
  1121. // 开票
  1122. $invoice = new invoiceStore ();
  1123. $invoice->trainId = $itid;
  1124. $invoice->invoiceType = 0;
  1125. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  1126. $invoice->invoiceType = 1;
  1127. $invoice->invoiceQuantity = $value ['invoiceQuantity'];
  1128. $invoice->invoiceUnitPrice = $value ['invoiceUnitPrice'];
  1129. $invoice->invoicePrice = $value ['invoiceQuantity'] * $value ['invoiceUnitPrice'];
  1130. $invoice->invoiceTitle = $value ['invoiceTitle'];
  1131. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  1132. $invoice->invoiceCompany = $value ['invoiceTitle'];
  1133. $invoice->userName = $userName;
  1134. $invoice->sid = $sDetail ['sid'];
  1135. $invoice->cid = $sDetail ['cid'];
  1136. $invoice->categoryName = $sDetail ['category'];
  1137. $invoice->invoiceElement = $value ['invoiceElement'];
  1138. $invoice->remark = $value ['remark'];
  1139. // $invoice->date = $value ['date'];
  1140. // $invoice->printTime = $value ['date'];
  1141. $invoice->ipSource = 1;
  1142. $invoice->printStatus = 0;
  1143. $invoice->status = 0;
  1144. $invoice->postStatus = 1;
  1145. $invoice->untreadStatus = 0;
  1146. // $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1147. $invoice->TIN = $value ['TIN'];
  1148. $invoice->address = $value ['address'];
  1149. $invoice->phone = $value ['phone'];
  1150. $invoice->bank = $value ['bank'];
  1151. $invoice->bankAccount = $value ['bankAccount'];
  1152. $invoice->recipientsAddress = $value ['recipientsAddress'];
  1153. $invoice->recipients = $value ['recipients'];
  1154. $invoice->recipientsPhone = $value ['recipientsPhone'];
  1155. $iid = $invoice->insert ();
  1156. }
  1157. // 加入发票总数量
  1158. $item = array (
  1159. 'itid' => $itid,
  1160. 'invoiceTotal' => count ( $exlArray )
  1161. );
  1162. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1163. return '/invoiceTrainingDetail/' . $trainingKey . ".html";
  1164. }
  1165. echo 'no file';
  1166. }
  1167. /**
  1168. * 编辑仓库里的发票
  1169. */
  1170. function invoiceStoreEdit() {
  1171. Doo::loadClass ( 'XDeode' );
  1172. $XDeode = new XDeode ( 5 );
  1173. $iid = isset ( $this->params ['storeKey'] ) ? $this->params ['storeKey'] : "";
  1174. $iid = $XDeode->decode ( $iid );
  1175. if (! is_numeric ( $iid ))
  1176. die ( 'illegal request' );
  1177. Doo::loadModel ( 'invoiceStore' );
  1178. $invoiceStore = new invoiceStore ();
  1179. $invoiceDetail = $invoiceStore->getInvoiceStoreByIsid ( $iid );
  1180. // print_r($invoiceDetail);
  1181. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  1182. $this->data ['invoiceDetail'] = $invoiceDetail;
  1183. $this->data ['memu'] = "invoice";
  1184. $this->data ['staff'] = $this->staff;
  1185. $this->data ['receiptMemu'] = 'invoiceTraining';
  1186. $this->render ( "/admin/invoiceStoreEdit", $this->data );
  1187. }
  1188. function invoiceStoreEditDo() {
  1189. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1190. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1191. Doo::loadModel ( 'invoiceStore' );
  1192. $invoice = new invoiceStore ();
  1193. Doo::loadClass ( 'XDeode' );
  1194. $XDeode = new XDeode ( 5 );
  1195. $iid = $XDeode->decode ( $storeKey );
  1196. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1197. die ( 'illegal request' );
  1198. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  1199. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  1200. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  1201. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  1202. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  1203. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  1204. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  1205. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  1206. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  1207. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  1208. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  1209. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  1210. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  1211. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  1212. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1213. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1214. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1215. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1216. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  1217. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  1218. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  1219. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  1220. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  1221. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  1222. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1223. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1224. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1225. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1226. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1227. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1228. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1229. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  1230. $cid = explode ( ':', $cid );
  1231. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  1232. $item = array (
  1233. 'isid' => $iid,
  1234. 'cid' => $cid [0],
  1235. 'categoryName' => $cid [1],
  1236. 'invoiceElement' => $invoiceElement,
  1237. 'invoiceQuantity' => $invoiceQuantity,
  1238. 'invoiceUnitPrice' => $invoiceUnitPrice,
  1239. 'invoicePrice' => $invoicePrice,
  1240. 'invoiceType' => $invoiceType,
  1241. 'doPost' => $doPost,
  1242. 'status' => 1,
  1243. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1244. 'remark' => $remark
  1245. );
  1246. if ($invoiceType == 0)
  1247. $item += array (
  1248. 'invoiceTitle' => $invoiceTitle,
  1249. 'TIN' => $TINT,
  1250. 'address' => $addressT,
  1251. 'phone' => $phoneT,
  1252. 'bank' => $bankT,
  1253. 'bankAccount' => $bankAccountT
  1254. );
  1255. else {
  1256. $item += array (
  1257. 'invoiceCompany' => $invoiceCompany,
  1258. 'TIN' => $TIN,
  1259. 'address' => $address,
  1260. 'phone' => $phone,
  1261. 'bank' => $bank,
  1262. 'bankAccount' => $bankAccount
  1263. );
  1264. }
  1265. if ($doPost == 1) {
  1266. $mailList = array (
  1267. 'invoice' => 1,
  1268. 'mailItems' => $mailItems
  1269. );
  1270. if (! empty ( $softLock ))
  1271. $mailList += array (
  1272. 'softLock' => $softLockNum
  1273. );
  1274. else
  1275. $mailList += array (
  1276. 'softLock' => '0'
  1277. );
  1278. if (! empty ( $contract ))
  1279. $mailList += array (
  1280. 'contract' => $contractNum
  1281. );
  1282. else
  1283. $mailList += array (
  1284. 'contract' => '0'
  1285. );
  1286. if (! empty ( $instructions ))
  1287. $mailList += array (
  1288. 'instructions' => $instructionsNum
  1289. );
  1290. else
  1291. $mailList += array (
  1292. 'instructions' => '0'
  1293. );
  1294. if (! empty ( $remittance ))
  1295. $mailList += array (
  1296. 'remittance' => $remittance
  1297. );
  1298. else
  1299. $mailList += array (
  1300. 'remittance' => ''
  1301. );
  1302. $mailString = '发票x1,备注:' . $mailItems;
  1303. if (! empty ( $softLock ))
  1304. $mailString .= ',软件锁x' . $softLockNum;
  1305. if (! empty ( $contract ))
  1306. $mailString .= ',合同x' . $contractNum;
  1307. if (! empty ( $instructions ))
  1308. $mailString .= ',说明书x' . $instructionsNum;
  1309. if (! empty ( $remittance ))
  1310. $mailString .= ',汇款账号单';
  1311. $item += array (
  1312. 'recipients' => $recipients,
  1313. 'recipientsPhone' => $recipientsPhone,
  1314. 'recipientsAddress' => $recipientsAddress,
  1315. 'mailItems' => $mailString,
  1316. 'mailItemsJson' => json_encode ( $mailList )
  1317. );
  1318. }
  1319. $invoice->setInvoiceStoreByCondition ( $item );
  1320. }
  1321. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1322. }
  1323. /**
  1324. *
  1325. * @return string
  1326. */
  1327. function invoiceStoreDelete() {
  1328. Doo::loadClass ( 'XDeode' );
  1329. $XDeode = new XDeode ( 5 );
  1330. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1331. $iStoreKey = $this->get_args ( 'iStoreKey' ) ? $this->get_args ( 'iStoreKey' ) : 0;
  1332. $isid = $XDeode->decode ( $iStoreKey );
  1333. $itid = $XDeode->decode ( $trainKey );
  1334. if (! is_numeric ( $isid ))
  1335. die ( 'illegal request' );
  1336. Doo::loadModel ( 'invoiceStore' );
  1337. $invoiceStore = new invoiceStore ();
  1338. $invoiceStore->delete ( array (
  1339. 'where' => 'isid=' . $isid,
  1340. 'limit' => 1
  1341. ) );
  1342. Doo::loadModel ( 'invoiceTraining' );
  1343. $invoiceTraining = new invoiceTraining ();
  1344. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1345. $item = array (
  1346. 'itid' => $itid,
  1347. 'invoiceTotal' => $itDetail ['invoiceTotal'] - 1
  1348. );
  1349. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1350. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1351. }
  1352. /**
  1353. * 批量删除库里发票
  1354. */
  1355. function invoiceStoreBatchDelete() {
  1356. Doo::loadClass ( 'XDeode' );
  1357. $XDeode = new XDeode ( 5 );
  1358. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1359. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1360. if (empty ( $trainKey ) || empty ( $storeKey ))
  1361. die ( 'illegal request-IdKey' );
  1362. $tid = $XDeode->decode ( $trainKey );
  1363. if (! is_numeric ( $tid ) && ! empty ( $storeKey ))
  1364. die ( 'illegal request' );
  1365. Doo::loadModel ( 'invoiceStore' );
  1366. $isidKeyList = explode ( ',', $storeKey );
  1367. $isidList = array ();
  1368. foreach ( $isidKeyList as $value ) {
  1369. $isid = $XDeode->decode ( $value );
  1370. if (! empty ( $isid ) && is_numeric ( $isid ))
  1371. array_push ( $isidList, $isid );
  1372. }
  1373. $isidString = implode ( ',', $isidList );
  1374. $invoiceStore = new invoiceStore ();
  1375. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,apStatus' );
  1376. $isidList = array ();
  1377. foreach ( $isList as $key => $value ) {
  1378. if ($value ['apStatus'] == 0)
  1379. array_push ( $isidList, $value ['isid'] );
  1380. }
  1381. $isidString = implode ( ',', $isidList );
  1382. // print_r($isList);
  1383. // echo $isidString;
  1384. $invoiceStore = new invoiceStore ();
  1385. $invoiceStore->delete ( array (
  1386. 'where' => "isid in ( " . $isidString . ")",
  1387. 'asArray' => TRUE
  1388. ) );
  1389. Doo::loadModel ( 'invoiceTraining' );
  1390. $invoiceTraining = new invoiceTraining ();
  1391. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1392. $item = array (
  1393. 'itid' => $tid,
  1394. 'invoiceTotal' => $itDetail ['invoiceTotal'] - count ( $isidList )
  1395. );
  1396. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1397. // echo $tid;
  1398. // echo $storeKey;
  1399. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1400. }
  1401. /**
  1402. * 仓库发票提交审批
  1403. * @return string
  1404. */
  1405. function invoiceStoreApproval() {
  1406. Doo::loadClass ( 'XDeode' );
  1407. $XDeode = new XDeode ( 5 );
  1408. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1409. $iStoreKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1410. $isid = $XDeode->decode ( $iStoreKey );
  1411. $trainId = $XDeode->decode ( $trainKey );
  1412. if (! is_numeric ( $isid ))
  1413. die ( 'illegal request' );
  1414. Doo::loadModel ( 'invoiceStore' );
  1415. Doo::loadModel ( 'invoice' );
  1416. $invoice = new invoice ();
  1417. // 加入限制必须填写入开票内容和邮寄物品
  1418. $invoiceStore = new invoiceStore ();
  1419. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid, 'isid,trainId ,invoiceElement,mailItemsJson' );
  1420. if (empty ( $isDetail ['invoiceElement'] ) || empty ( $isDetail ['mailItemsJson'] )) {
  1421. header ( 'Content-Type:text/html;charset=utf-8' );
  1422. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1423. }
  1424. // 拷贝插入一条发票数据
  1425. $invoiceStore = new invoiceStore ();
  1426. $iid = $invoiceStore->setInvoiceStoreToApproval ( $isid );
  1427. $invoiceStore = new invoiceStore ();
  1428. $item = array (
  1429. 'isid' => $isid,
  1430. 'iid' => $iid,
  1431. 'apStatus' => 1
  1432. );
  1433. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1434. Doo::loadModel ( 'invoiceManage' );
  1435. $invoiceManage = new invoiceManage ();
  1436. Doo::loadModel ( 'invoiceOperationLog' );
  1437. $invoiceOperationLog = new invoiceOperationLog ();
  1438. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1439. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1440. $moldManage = array ();
  1441. foreach ( $invoiceManageList as $key => $value ) {
  1442. if ($value ['mold'] == '发票打印')
  1443. $moldManage [$value ['mold']] = $value ['staffList'];
  1444. elseif ($value ['mold'] == '发票邮寄')
  1445. $moldManage [$value ['mold']] = $value ['staffList'];
  1446. elseif ($value ['mold'] == '发票退票')
  1447. $moldManage [$value ['mold']] = $value ['staffList'];
  1448. }
  1449. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1450. $item = array (
  1451. 'iid' => $iid,
  1452. 'isid' => $isid,
  1453. 'invoiceSerial' => "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  1454. 'date' => date ( "Y-m-d H:i:s" ),
  1455. 'status' => 1,
  1456. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1457. 'trainId' => $trainId,
  1458. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1459. 'moldManage' => json_encode ( $moldManage ),
  1460. 'settlementType' => 1,
  1461. 'pendingApprovals' => $pendingApprovalsSid
  1462. );
  1463. $invoice->setInvoiceByCondition ( $item );
  1464. Doo::loadModel ( 'invoiceTraining' );
  1465. $invoiceTraining = new invoiceTraining ();
  1466. $item = array (
  1467. 'itid' => $trainId,
  1468. 'submitStatus' => 1
  1469. );
  1470. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1471. $item = array (
  1472. 'date' => date ( "Y-m-d H:i:s" ),
  1473. 'operation' => "创建",
  1474. 'status' => 1,
  1475. 'img' => $this->staff [0] ['avatar'],
  1476. 'username' => $this->staff [0] ['username'],
  1477. 'uid' => $this->staff [0] ['sid'],
  1478. 'category' => $this->staff [0] ['category'],
  1479. 'iid' => $iid
  1480. );
  1481. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1482. $item = array (
  1483. 'date' => date ( "Y-m-d H:i:s" ),
  1484. 'operation' => "提交审批",
  1485. 'status' => 1,
  1486. 'img' => $this->staff [0] ['avatar'],
  1487. 'username' => $this->staff [0] ['username'],
  1488. 'uid' => $this->staff [0] ['sid'],
  1489. 'category' => $this->staff [0] ['category'],
  1490. 'iid' => $iid
  1491. );
  1492. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1493. Doo::loadModel ( 'staff' );
  1494. $staff = new staff ();
  1495. $username2 = $staff->getOne ( array (
  1496. 'select' => 'wxid',
  1497. 'where' => 'sid=' . $pendingApprovalsSid,
  1498. 'asArray' => TRUE
  1499. ) );
  1500. // 发送微信审批通知
  1501. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1502. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1503. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1504. }
  1505. /**
  1506. * 批量提交发票
  1507. * @return string
  1508. */
  1509. function invoiceStoreBatchApproval() {
  1510. Doo::loadClass ( 'XDeode' );
  1511. $XDeode = new XDeode ( 5 );
  1512. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1513. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1514. if (empty ( $trainKey ) || empty ( $storeKey ))
  1515. die ( 'illegal request-IdKey' );
  1516. $trainId = $XDeode->decode ( $trainKey );
  1517. $isidKeyList = explode ( ',', $storeKey );
  1518. $isidList = array ();
  1519. foreach ( $isidKeyList as $value ) {
  1520. $isid = $XDeode->decode ( $value );
  1521. if (! empty ( $isid ) && is_numeric ( $isid ))
  1522. array_push ( $isidList, $isid );
  1523. }
  1524. $isidString = implode ( ',', $isidList );
  1525. if (! is_numeric ( $trainId ))
  1526. die ( 'illegal request' );
  1527. Doo::loadModel ( 'invoiceStore' );
  1528. Doo::loadModel ( 'invoice' );
  1529. // 判断哪些已经加入审批过
  1530. // 加入限制必须填写入开票内容和邮寄物品
  1531. $invoiceStore = new invoiceStore ();
  1532. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,trainId ,invoiceElement,mailItemsJson' );
  1533. foreach ( $isList as $key => $value ) {
  1534. if (empty ( $value ['invoiceElement'] ) || empty ( $value ['mailItemsJson'] )) {
  1535. header ( 'Content-Type:text/html;charset=utf-8' );
  1536. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1537. }
  1538. }
  1539. // 拷贝插入一条发票数据
  1540. $invoiceStore = new invoiceStore ();
  1541. $invoiceStore->setInvoiceStoreBatchToApproval ( $isidString );
  1542. $invoiceStore = new invoiceStore ();
  1543. $item = array (
  1544. 'apStatus' => 1
  1545. );
  1546. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1547. // 获得正式发票ID
  1548. $invoice = new invoice ();
  1549. $iidList = $invoice->getInvoiceByIstoreid ( $isidString, 'iid,isid' );
  1550. $sqlList = array ();
  1551. $iidString = '';
  1552. $iida = array ();
  1553. foreach ( $iidList as $key => $value ) {
  1554. $sqlList [$value ['isid']] = $value ['iid'];
  1555. array_push ( $iida, $value ['iid'] );
  1556. }
  1557. $iidString = implode ( ',', $iida );
  1558. $ids = implode ( ',', array_keys ( $sqlList ) );
  1559. $sql = "UPDATE CLD_invoiceStore SET iid = CASE isid ";
  1560. foreach ( $sqlList as $id => $ordinal ) {
  1561. $sql .= sprintf ( "WHEN %d THEN %d ", $id, $ordinal );
  1562. }
  1563. $sql .= "END WHERE isid IN ($ids)";
  1564. $invoiceStore = new invoiceStore ();
  1565. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1566. Doo::loadModel ( 'invoiceManage' );
  1567. $invoiceManage = new invoiceManage ();
  1568. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1569. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1570. $moldManage = array ();
  1571. foreach ( $invoiceManageList as $key => $value ) {
  1572. if ($value ['mold'] == '发票打印')
  1573. $moldManage [$value ['mold']] = $value ['staffList'];
  1574. elseif ($value ['mold'] == '发票邮寄')
  1575. $moldManage [$value ['mold']] = $value ['staffList'];
  1576. elseif ($value ['mold'] == '发票退票')
  1577. $moldManage [$value ['mold']] = $value ['staffList'];
  1578. }
  1579. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1580. // 批量更新发票信息
  1581. $item = array (
  1582. 'date' => date ( "Y-m-d H:i:s" ),
  1583. 'status' => 1,
  1584. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1585. 'trainId' => $trainId,
  1586. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1587. 'moldManage' => json_encode ( $moldManage ),
  1588. 'settlementType' => 1,
  1589. 'pendingApprovals' => $pendingApprovalsSid
  1590. );
  1591. $invoice = new invoice ();
  1592. $invoice->BatchInvoiceByCondition ( $item, $iidString );
  1593. // 批量更新发票中仓库isid
  1594. $sql = "UPDATE CLD_invoiceStore SET isid = CASE iid ";
  1595. foreach ( $sqlList as $isid => $iid ) {
  1596. $sql .= sprintf ( "WHEN %d THEN %d ", $iid, $isid );
  1597. }
  1598. $sql .= "END WHERE iid IN ($iidString)";
  1599. $invoice = new invoice ();
  1600. $invoice->UpdateBatchInvoice ( $sql );
  1601. // 批量更新发票序列号
  1602. $sqlList = array ();
  1603. foreach ( $iida as $value ) {
  1604. $sqlList [$value] = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1605. }
  1606. $ids = implode ( ',', array_keys ( $sqlList ) );
  1607. $sql = "UPDATE CLD_invoice SET invoiceSerial = CASE iid ";
  1608. foreach ( $sqlList as $id => $ordinal ) {
  1609. $sql .= sprintf ( "WHEN %d THEN '%s' ", $id, $ordinal );
  1610. }
  1611. $sql .= "END WHERE iid IN ($ids)";
  1612. $invoiceStore = new invoiceStore ();
  1613. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1614. // 批量生产操作日志
  1615. Doo::loadModel ( 'invoiceOperationLog' );
  1616. $sqlList = array ();
  1617. foreach ( $iida as $key => $value ) {
  1618. $sql = '("' . date ( "Y-m-d H:i:s" ) . '","创建","1","' . $this->staff [0] ['avatar'] . '","' . $this->staff [0] ['username'] . '","' . $this->staff [0] ['sid'] . '","' . $this->staff [0] ['category'] . '","' . $value . '"),
  1619. ("' . date ( "Y-m-d H:i:s" ) . '","提交审批","1","' . $this->staff [0] ['avatar'] . '","' . $this->staff [0] ['username'] . '","' . $this->staff [0] ['sid'] . '","' . $this->staff [0] ['category'] . '","' . $value . '") ';
  1620. array_push ( $sqlList, $sql );
  1621. }
  1622. $iolSql = implode ( ',', $sqlList );
  1623. $sql = "INSERT INTO `CLD_invoiceOperationLog` (`date`, `operation`, `status`, `img`, `username`, `uid`, `category`, `iid`) VALUES " . $iolSql;
  1624. $invoiceOperationLog = new invoiceOperationLog ();
  1625. $invoiceOperationLog->setInvoiceOperationLogBySql ( $sql );
  1626. Doo::loadModel ( 'invoiceTraining' );
  1627. $invoiceTraining = new invoiceTraining ();
  1628. $item = array (
  1629. 'itid' => $trainId,
  1630. 'submitStatus' => 1
  1631. );
  1632. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1633. Doo::loadModel ( 'staff' );
  1634. $staff = new staff ();
  1635. $username2 = $staff->getOne ( array (
  1636. 'select' => 'wxid',
  1637. 'where' => 'sid=' . $pendingApprovalsSid,
  1638. 'asArray' => TRUE
  1639. ) );
  1640. // 发送微信审批通知
  1641. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1642. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1643. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1644. }
  1645. /**
  1646. */
  1647. function invoiceStoreMailItemSet() {
  1648. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1649. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1650. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1651. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1652. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1653. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1654. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1655. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1656. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1657. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1658. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1659. Doo::loadClass ( 'XDeode' );
  1660. $XDeode = new XDeode ( 5 );
  1661. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1662. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1663. $isid = $XDeode->decode ( $storeKey );
  1664. $trainId = $XDeode->decode ( $trainKey );
  1665. if (! is_numeric ( $isid ))
  1666. die ( 'illegal request' );
  1667. Doo::loadModel ( 'invoiceStore' );
  1668. $invoiceStore = new invoiceStore ();
  1669. $mailList = array (
  1670. 'invoice' => 1,
  1671. 'mailItems' => $mailItems
  1672. );
  1673. if (! empty ( $softLock ))
  1674. $mailList += array (
  1675. 'softLock' => $softLockNum
  1676. );
  1677. else
  1678. $mailList += array (
  1679. 'softLock' => 0
  1680. );
  1681. if (! empty ( $contract ))
  1682. $mailList += array (
  1683. 'contract' => $contractNum
  1684. );
  1685. else
  1686. $mailList += array (
  1687. 'contract' => 0
  1688. );
  1689. if (! empty ( $instructions ))
  1690. $mailList += array (
  1691. 'instructions' => $instructionsNum
  1692. );
  1693. else
  1694. $mailList += array (
  1695. 'instructions' => 0
  1696. );
  1697. if (! empty ( $remittance ))
  1698. $mailList += array (
  1699. 'remittance' => $remittance
  1700. );
  1701. else
  1702. $mailList += array (
  1703. 'remittance' => ''
  1704. );
  1705. $mailString = '发票x1,备注:' . $mailItems;
  1706. if (! empty ( $softLock ))
  1707. $mailString .= ',软件锁x' . $softLockNum;
  1708. if (! empty ( $contract ))
  1709. $mailString .= ',合同x' . $contractNum;
  1710. if (! empty ( $instructions ))
  1711. $mailString .= ',说明书x' . $instructionsNum;
  1712. if (! empty ( $remittance ))
  1713. $mailString .= ',汇款账号单';
  1714. $item = array (
  1715. 'isid' => $isid,
  1716. 'doPost' => 1,
  1717. 'mailItems' => $mailString,
  1718. 'mailItemsJson' => json_encode ( $mailList )
  1719. );
  1720. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1721. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1722. }
  1723. /**
  1724. * 批量设置邮寄物品
  1725. */
  1726. function invoiceStoreBatchMailItemSet() {
  1727. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1728. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1729. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1730. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1731. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1732. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1733. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1734. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1735. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1736. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1737. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1738. Doo::loadClass ( 'XDeode' );
  1739. $XDeode = new XDeode ( 5 );
  1740. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1741. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1742. if (empty ( $trainKey ) || empty ( $storeKey ))
  1743. die ( 'illegal request-IdKey' );
  1744. $isidKeyList = explode ( ',', $storeKey );
  1745. $isidList = array ();
  1746. foreach ( $isidKeyList as $value ) {
  1747. $isid = $XDeode->decode ( $value );
  1748. if (! empty ( $isid ) && is_numeric ( $isid ))
  1749. array_push ( $isidList, $isid );
  1750. }
  1751. $isidString = implode ( ',', $isidList );
  1752. $trainId = $XDeode->decode ( $trainKey );
  1753. if (! is_numeric ( $isid ))
  1754. die ( 'illegal request' );
  1755. Doo::loadModel ( 'invoiceStore' );
  1756. $invoiceStore = new invoiceStore ();
  1757. $mailList = array (
  1758. 'invoice' => 1,
  1759. 'mailItems' => $mailItems
  1760. );
  1761. if (! empty ( $softLock ))
  1762. $mailList += array (
  1763. 'softLock' => $softLockNum
  1764. );
  1765. else
  1766. $mailList += array (
  1767. 'softLock' => 0
  1768. );
  1769. if (! empty ( $contract ))
  1770. $mailList += array (
  1771. 'contract' => $contractNum
  1772. );
  1773. else
  1774. $mailList += array (
  1775. 'contract' => 0
  1776. );
  1777. if (! empty ( $instructions ))
  1778. $mailList += array (
  1779. 'instructions' => $instructionsNum
  1780. );
  1781. else
  1782. $mailList += array (
  1783. 'instructions' => 0
  1784. );
  1785. if (! empty ( $remittance ))
  1786. $mailList += array (
  1787. 'remittance' => $remittance
  1788. );
  1789. else
  1790. $mailList += array (
  1791. 'remittance' => ''
  1792. );
  1793. $mailString = '发票x1,备注:' . $mailItems;
  1794. if (! empty ( $softLock ))
  1795. $mailString .= ',软件锁x' . $softLockNum;
  1796. if (! empty ( $contract ))
  1797. $mailString .= ',合同x' . $contractNum;
  1798. if (! empty ( $instructions ))
  1799. $mailString .= ',说明书x' . $instructionsNum;
  1800. if (! empty ( $remittance ))
  1801. $mailString .= ',汇款账号单';
  1802. $item = array (
  1803. 'doPost' => 1,
  1804. 'mailItems' => $mailString,
  1805. 'mailItemsJson' => json_encode ( $mailList )
  1806. );
  1807. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1808. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1809. }
  1810. /**
  1811. * 废弃
  1812. */
  1813. function ajaxGetMailItemByIstore() {
  1814. Doo::loadClass ( 'XDeode' );
  1815. $XDeode = new XDeode ( 5 );
  1816. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1817. $isid = $XDeode->decode ( $storeKey );
  1818. if (! is_numeric ( $isid ))
  1819. die ( 'illegal request' );
  1820. Doo::loadModel ( 'invoiceStore' );
  1821. $invoiceStore = new invoiceStore ();
  1822. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid );
  1823. $isDetail ['mailItemsJson'] = json_decode ( $isDetail ['mailItemsJson'], true );
  1824. echo json_encode ( $isDetail ['mailItemsJson'] );
  1825. exit ();
  1826. }
  1827. /**
  1828. * 终止开票
  1829. */
  1830. function invoiceDroppedDo() {
  1831. $droppedIidKey = $this->get_args ( 'droppedIidKey' ) ? $this->get_args ( 'droppedIidKey' ) : '';
  1832. Doo::loadModel ( 'invoice' );
  1833. $invoice = new invoice ();
  1834. Doo::loadModel ( 'invoiceOperationLog' );
  1835. $invoiceOperationLog = new invoiceOperationLog ();
  1836. $iid = $invoice->authcode ( $droppedIidKey );
  1837. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1838. die ( 'illegal request' );
  1839. $item = array (
  1840. 'iid' => $iid,
  1841. 'status' => 4,
  1842. 'updateTime' => date ( "Y-m-d H:i:s" )
  1843. );
  1844. $invoice->setInvoiceByCondition ( $item );
  1845. $item = array (
  1846. 'date' => date ( "Y-m-d H:i:s" ),
  1847. 'operation' => '终止了开票',
  1848. 'status' => 4,
  1849. 'img' => $this->staff [0] ['avatar'],
  1850. 'username' => $this->staff [0] ['username'],
  1851. 'uid' => $this->staff [0] ['sid'],
  1852. 'category' => $this->staff [0] ['category'],
  1853. 'iid' => $iid
  1854. );
  1855. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1856. return "/invoice";
  1857. }
  1858. /**
  1859. * 更新退票的邮寄信息
  1860. */
  1861. function invoiceUntreadMailDo() {
  1862. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  1863. $untreadCompany = $this->get_args ( 'untreadCompany' ) ? $this->get_args ( 'untreadCompany' ) : "";
  1864. $untreadNumber = $this->get_args ( 'untreadNumber' ) ? $this->get_args ( 'untreadNumber' ) : "";
  1865. $untreadItems = $this->get_args ( 'untreadItems' ) ? $this->get_args ( 'untreadItems' ) : "";
  1866. Doo::loadModel ( 'invoice' );
  1867. $invoice = new invoice ();
  1868. $iid = $invoice->authcode ( $untreadIidKey );
  1869. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1870. die ( 'illegal request' );
  1871. $item = array (
  1872. 'iid' => $iid,
  1873. 'untreadCompany' => $untreadCompany,
  1874. 'untreadNumber' => $untreadNumber,
  1875. 'untreadItems' => $untreadItems
  1876. );
  1877. $invoice->setInvoiceByCondition ( $item );
  1878. return "/invoice";
  1879. }
  1880. /**
  1881. * 申请退票 --
  1882. */
  1883. function invoiceUntreadDo() {
  1884. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  1885. $untreadReason = $this->get_args ( 'untreadReason' ) ? $this->get_args ( 'untreadReason' ) : "";
  1886. $untreadPost = $this->get_args ( 'untreadPost' ) ? $this->get_args ( 'untreadPost' ) : "";
  1887. Doo::loadModel ( 'invoice' );
  1888. $invoice = new invoice ();
  1889. Doo::loadModel ( 'invoiceOperationLog' );
  1890. $invoiceOperationLog = new invoiceOperationLog ();
  1891. Doo::loadModel ( 'invoiceReceivables' );
  1892. $invoiceReceivables = new invoiceReceivables ();
  1893. $iid = $invoice->authcode ( $untreadIidKey );
  1894. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1895. die ( 'illegal request' );
  1896. /*
  1897. * 需求变革 有绑定收款也可以退票 $lt = $invoiceReceivables->getInvoiceReceivablesByIid ( $untreadIidKey ); if (! empty ( $lt )) { header ( 'Content-Type:text/html;charset=utf-8' ); die ( '该发票有收款绑定,请先移除!' ); }
  1898. */
  1899. $item = array (
  1900. 'iid' => $iid,
  1901. 'untreadStatus' => 1,
  1902. 'untreadReason' => $untreadReason,
  1903. 'untreadPost' => $untreadPost,
  1904. 'updateTime' => date ( "Y-m-d H:i:s" )
  1905. );
  1906. $invoice->setInvoiceByCondition ( $item );
  1907. $item = array (
  1908. 'date' => date ( "Y-m-d H:i:s" ),
  1909. 'operation' => '申请退票',
  1910. 'status' => 7,
  1911. 'img' => $this->staff [0] ['avatar'],
  1912. 'username' => $this->staff [0] ['username'],
  1913. 'uid' => $this->staff [0] ['sid'],
  1914. 'category' => $this->staff [0] ['category'],
  1915. 'iid' => $iid
  1916. );
  1917. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1918. return "/invoice";
  1919. }
  1920. /**
  1921. * 删除已终止的开票
  1922. */
  1923. function invoiceDelDo() {
  1924. Doo::loadModel ( 'invoice' );
  1925. $invoice = new invoice ();
  1926. Doo::loadModel ( 'invoiceOperationLog' );
  1927. $invoiceOperationLog = new invoiceOperationLog ();
  1928. Doo::loadClass ( 'XDeode' );
  1929. $XDeode = new XDeode ( 5 );
  1930. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  1931. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  1932. $iid = $XDeode->decode ( $iid );
  1933. Doo::loadModel ( 'invoiceStore' );
  1934. $invoiceStore = new invoiceStore ();
  1935. if (! is_numeric ( $iid ))
  1936. die ( 'illegal request' );
  1937. $invoiceDetail = $invoice->getMyInvoice ( $sid, $iid );
  1938. if (empty ( $invoiceDetail ))
  1939. die ( 'illegal request' );
  1940. $item = array (
  1941. 'iid' => $iid,
  1942. 'isDelete' => 1,
  1943. 'updateTime' => date ( "Y-m-d H:i:s" )
  1944. );
  1945. $invoice->setInvoiceByCondition ( $item );
  1946. $item = array (
  1947. 'date' => date ( "Y-m-d H:i:s" ),
  1948. 'operation' => '删除了已终止的发票',
  1949. 'status' => 4,
  1950. 'img' => $this->staff [0] ['avatar'],
  1951. 'username' => $this->staff [0] ['username'],
  1952. 'uid' => $this->staff [0] ['sid'],
  1953. 'category' => $this->staff [0] ['category'],
  1954. 'iid' => $iid
  1955. );
  1956. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1957. // 删除培训班发票仓库里的发票
  1958. $invoiceStore->delInvoiceStoreByIsid ( $invoiceDetail ['isid'] );
  1959. return "/invoice";
  1960. }
  1961. /**
  1962. */
  1963. function invoiceApproval() {
  1964. Doo::loadModel ( 'invoice' );
  1965. $invoice = new invoice ();
  1966. Doo::loadClass ( 'XDeode' );
  1967. $XDeode = new XDeode ( 5 );
  1968. Doo::loadModel ( 'staff' );
  1969. $staff = new staff ();
  1970. $invoiceList = $invoice->find ( array (
  1971. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  1972. 'desc' => 'iid',
  1973. 'limit' => 10,
  1974. 'asArray' => true
  1975. ) );
  1976. foreach ( $invoiceList as $key => $value ) {
  1977. $invoiceList [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1978. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1979. if (! empty ( $lastApprover )) {
  1980. $lastApproverKey = array_keys ( $lastApprover );
  1981. $lastApprover = end ( $lastApprover );
  1982. $staffDetail = $staff->getOne ( array (
  1983. 'where' => 'sid=' . end ( $lastApproverKey ),
  1984. 'asArray' => true
  1985. ) );
  1986. $lastApprover ['username'] = $staffDetail ['username'];
  1987. }
  1988. $invoiceList [$key] ['lastApprover'] = $lastApprover;
  1989. }
  1990. $ilist = $invoice->getInvoiceByProcessStatus ();
  1991. foreach ( $ilist as $key => $value ) {
  1992. $ilist [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1993. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1994. if (! empty ( $lastApprover )) {
  1995. $lastApproverKey = array_keys ( $lastApprover );
  1996. $lastApprover = end ( $lastApprover );
  1997. $staffDetail = $staff->getOne ( array (
  1998. 'where' => 'sid=' . end ( $lastApproverKey ),
  1999. 'asArray' => true
  2000. ) );
  2001. $lastApprover ['username'] = $staffDetail ['username'];
  2002. }
  2003. $ilist [$key] ['lastApprover'] = $lastApprover;
  2004. }
  2005. // print_r($ilist);
  2006. $this->data ['invoiceList'] = $invoiceList;
  2007. $this->data ['ilist'] = $ilist;
  2008. $this->data ['memu'] = "invoice";
  2009. $this->data ['staff'] = $this->staff;
  2010. $this->data ['receiptMemu'] = 'invoiceApproval';
  2011. $this->render ( "/admin/invoiceApproval", $this->data );
  2012. }
  2013. function invoiceDetail() {
  2014. Doo::loadClass ( 'XDeode' );
  2015. $XDeode = new XDeode ( 5 );
  2016. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  2017. $iid = $XDeode->decode ( $iid );
  2018. if (! is_numeric ( $iid ))
  2019. die ( 'illegal request' );
  2020. Doo::loadModel ( 'invoice' );
  2021. $invoice = new invoice ();
  2022. Doo::loadModel ( 'invoiceOperationLog' );
  2023. $invoiceOperationLog = new invoiceOperationLog ();
  2024. $invoiceDetail = $invoice->getOne ( array (
  2025. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'] . ' and iid=' . $iid,
  2026. 'asArray' => true
  2027. ) );
  2028. if (empty ( $invoiceDetail ))
  2029. die ( 'illegal request' );
  2030. if ($invoiceDetail ['settlementType'] == 1) {
  2031. Doo::loadModel ( 'invoiceTraining' );
  2032. $invoiceTraining = new invoiceTraining ();
  2033. $invoiceDetail ['invoiceTraining'] = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceDetail ['trainId'] );
  2034. }
  2035. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  2036. $this->data ['invoiceDetail'] = $invoiceDetail;
  2037. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  2038. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  2039. $this->data ['memu'] = "invoice";
  2040. $this->data ['staff'] = $this->staff;
  2041. $this->data ['receiptMemu'] = 'invoiceApproval';
  2042. $this->render ( "/admin/invoiceApprovalDetail", $this->data );
  2043. }
  2044. /**
  2045. * 对发票进行审批,其中操作有终止,退回,同意动作。操作成功并记录下操作日志
  2046. *
  2047. * @since 1.0.0
  2048. * @var integer iid 开票ID 已加密
  2049. * @var integer status 发票审批状态
  2050. * @var integer opintion 审批发票的意见
  2051. * @return string 如操作成功返回审批首页
  2052. */
  2053. function invoiceApprovalDo() {
  2054. Doo::loadModel ( 'invoice' );
  2055. $invoice = new invoice ();
  2056. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2057. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  2058. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  2059. $divApproval = $this->get_args ( 'divApproval' ) ? $this->get_args ( 'divApproval' ) : "";
  2060. $iid = $invoice->authcode ( $iid );
  2061. if (! is_numeric ( $iid ))
  2062. die ( 'illegal request' );
  2063. // && ! empty ( $opinion )
  2064. if (! empty ( $iid ) && ! empty ( $status )) {
  2065. if (! ($status == 2 || $status == 3 || $status == 4))
  2066. die ( 'illegal request' );
  2067. Doo::loadModel ( 'invoiceOperationLog' );
  2068. $invoiceOperationLog = new invoiceOperationLog ();
  2069. $invoiceDetail = $invoice->getOne ( array (
  2070. 'where' => 'status=1 and iid=' . $iid . ' and pendingApprovals=' . $this->staff [0] ['sid'],
  2071. 'asArray' => true
  2072. ) );
  2073. if (empty ( $invoiceDetail ))
  2074. die ( 'illegal request' );
  2075. $processApprovals = json_decode ( $invoiceDetail ['processApprovals'], true );
  2076. $invoiceManage = json_decode ( $invoiceDetail ['invoiceManage'], true );
  2077. if ($status == 3) {
  2078. $invoice->status = $status;
  2079. $item = array (
  2080. 'operation' => $opinion
  2081. );
  2082. } else {
  2083. if (empty ( $processApprovals )) {
  2084. $processApprovals = array (
  2085. $this->staff [0] ['sid'] => array (
  2086. 'date' => date ( "Y-m-d H:i:s" ),
  2087. 'opinion' => $opinion,
  2088. 'status' => $status
  2089. )
  2090. );
  2091. // var_dump(next($invoiceManage));
  2092. $nextInvoiceManage = next ( $invoiceManage );
  2093. // print_r($nextInvoiceManage);
  2094. if ($status != 4 && $nextInvoiceManage !== false)
  2095. $invoice->pendingApprovals = $nextInvoiceManage [0];
  2096. $invoice->processApprovals = json_encode ( $processApprovals );
  2097. // var_dump($invoice);
  2098. // print_r($invoiceManage);
  2099. } else {
  2100. $processApprovals [$this->staff [0] ['sid']] = array (
  2101. 'date' => date ( "Y-m-d H:i:s" ),
  2102. 'opinion' => $opinion,
  2103. 'status' => $status
  2104. );
  2105. $pendingApprovals = 0;
  2106. foreach ( $invoiceManage as $key => $value ) {
  2107. if ($value [0] == $this->staff [0] ['sid']) {
  2108. if (isset ( $invoiceManage [$key + 1] ))
  2109. $pendingApprovals = $invoiceManage [$key + 1] [0];
  2110. break;
  2111. }
  2112. }
  2113. if ($status != 4 && ! empty ( $pendingApprovals ))
  2114. $invoice->pendingApprovals = $pendingApprovals;
  2115. $invoice->processApprovals = json_encode ( $processApprovals );
  2116. }
  2117. $item = array (
  2118. 'operation' => $opinion
  2119. );
  2120. if (count ( $processApprovals ) == count ( $invoiceManage ) && $status != 4) {
  2121. $invoice->status = $status;
  2122. $invoice->pendingApprovals = 0;
  2123. $invoice->approvalTime = date ( "Y-m-d H:i:s" );
  2124. } elseif ($status == 4) {
  2125. $invoice->status = $status;
  2126. $item = array (
  2127. 'operation' => $opinion
  2128. );
  2129. }
  2130. }
  2131. $invoice->updateTime = date ( "Y-m-d H:i:s" );
  2132. $invoice->update ( array (
  2133. 'where' => 'iid=' . $iid
  2134. ) );
  2135. $item += array (
  2136. 'date' => date ( "Y-m-d H:i:s" ),
  2137. 'img' => $this->staff [0] ['avatar'],
  2138. 'username' => $this->staff [0] ['username'],
  2139. 'uid' => $this->staff [0] ['sid'],
  2140. 'category' => $this->staff [0] ['category'],
  2141. 'status' => $status,
  2142. 'iid' => $iid
  2143. );
  2144. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2145. if (empty ( $divApproval ))
  2146. return '/invoiceApproval';
  2147. else
  2148. return '/invoiceApprovalAchieve/PEND';
  2149. }
  2150. die ( 'illegal request' );
  2151. }
  2152. /**
  2153. * 展示需要打印的发票数据
  2154. *
  2155. * @since 1.0.0
  2156. */
  2157. function invoicePrint() {
  2158. Doo::loadModel ( 'invoice' );
  2159. $invoice = new invoice ();
  2160. Doo::loadClass ( 'XDeode' );
  2161. $XDeode = new XDeode ( 5 );
  2162. Doo::loadModel ( 'staff' );
  2163. $staff = new staff ();
  2164. $toPrint = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0 );
  2165. $printed = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 1 );
  2166. foreach ( $toPrint as $key => $value ) {
  2167. $toPrint [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2168. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2169. if (! empty ( $lastApprover )) {
  2170. $lastApproverKey = array_keys ( $lastApprover );
  2171. $lastApprover = end ( $lastApprover );
  2172. $staffDetail = $staff->getOne ( array (
  2173. 'where' => 'sid=' . end ( $lastApproverKey ),
  2174. 'asArray' => true
  2175. ) );
  2176. $lastApprover ['username'] = $staffDetail ['username'];
  2177. }
  2178. $toPrint [$key] ['lastApprover'] = $lastApprover;
  2179. }
  2180. foreach ( $printed as $key => $value ) {
  2181. $printed [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2182. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2183. if (! empty ( $lastApprover )) {
  2184. $lastApproverKey = array_keys ( $lastApprover );
  2185. $lastApprover = end ( $lastApprover );
  2186. $staffDetail = $staff->getOne ( array (
  2187. 'where' => 'sid=' . end ( $lastApproverKey ),
  2188. 'asArray' => true
  2189. ) );
  2190. $lastApprover ['username'] = $staffDetail ['username'];
  2191. }
  2192. $printed [$key] ['lastApprover'] = $lastApprover;
  2193. }
  2194. $this->data ['printed'] = $printed;
  2195. $this->data ['toPrint'] = $toPrint;
  2196. $this->data ['memu'] = "invoice";
  2197. $this->data ['staff'] = $this->staff;
  2198. $this->data ['receiptMemu'] = 'invoicePrint';
  2199. $this->render ( "/admin/invoicePrint", $this->data );
  2200. }
  2201. /**
  2202. * 展示发票打印的详情页面
  2203. *
  2204. * @since 1.0.0
  2205. */
  2206. function invoicePrintDetail() {
  2207. Doo::loadClass ( 'XDeode' );
  2208. $XDeode = new XDeode ( 5 );
  2209. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  2210. $iid = $XDeode->decode ( $iid );
  2211. if (! is_numeric ( $iid ))
  2212. die ( 'illegal request' );
  2213. Doo::loadModel ( 'invoice' );
  2214. $invoice = new invoice ();
  2215. Doo::loadModel ( 'invoiceOperationLog' );
  2216. $invoiceOperationLog = new invoiceOperationLog ();
  2217. Doo::loadModel ( 'invoicePaper' );
  2218. $invoicePaper = new invoicePaper ();
  2219. $invoiceDetail = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0, $iid );
  2220. if (empty ( $invoiceDetail ))
  2221. die ( 'illegal request' );
  2222. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $invoiceDetail ['invoiceType'] );
  2223. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  2224. if ($invoiceDetail ['settlementType'] == 1) {
  2225. Doo::loadModel ( 'invoiceTraining' );
  2226. $invoiceTraining = new invoiceTraining ();
  2227. $invoiceDetail ['invoiceTraining'] = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceDetail ['trainId'] );
  2228. }
  2229. $this->data ['invoicePaperList'] = $invoicePaperList;
  2230. $this->data ['invoiceDetail'] = $invoiceDetail;
  2231. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  2232. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  2233. $this->data ['memu'] = "invoice";
  2234. $this->data ['staff'] = $this->staff;
  2235. $this->data ['receiptMemu'] = 'invoicePrint';
  2236. $this->render ( "/admin/invoicePrintDetail", $this->data );
  2237. }
  2238. /**
  2239. * 所有待打印 发票
  2240. */
  2241. function invoicePrintStayAchieve() {
  2242. Doo::loadModel ( 'invoice' );
  2243. $invoice = new invoice ();
  2244. Doo::loadClass ( 'XDeode' );
  2245. $XDeode = new XDeode ( 5 );
  2246. Doo::loadModel ( 'staff' );
  2247. $staff = new staff ();
  2248. $MebSea = $this->get_args ( 'MebSea' ) ? urldecode ( $this->get_args ( 'MebSea' ) ) : "";
  2249. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  2250. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  2251. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  2252. Doo::loadModel ( 'invoiceTraining' );
  2253. $invoiceTraining = new invoiceTraining ();
  2254. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  2255. $page_size = 12;
  2256. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2257. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : "ALL";
  2258. // $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : "ALL";
  2259. $get = "/" . $status;
  2260. $con = ' and status=2 ';
  2261. if ($status == 'TOPRINT')
  2262. $con = ' and status=2 and printStatus=0 ';
  2263. elseif ($status == 'PRINTED')
  2264. $con = ' and status=2 and printStatus=1';
  2265. if ($invoiceType == 'ORDINARY')
  2266. $con .= ' and invoiceType=0 ';
  2267. elseif ($invoiceType == 'SPECIAL')
  2268. $con .= ' and invoiceType=1 ';
  2269. if ($invoiceTrain == 'ORDINARY')
  2270. $con .= ' and trainId=0 ';
  2271. elseif ($invoiceTrain == 'TRAIN')
  2272. $con .= ' and trainId!=0 ';
  2273. if ($invoiceTrainName != 'ALL') {
  2274. $trainId = $XDeode->decode ( $invoiceTrainName );
  2275. if (is_numeric ( $trainId ))
  2276. $con .= ' and trainId =' . $trainId;
  2277. }
  2278. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2279. $dateArr = explode ( ':', $date );
  2280. $D1 = '';
  2281. $D2 = '';
  2282. if (! empty ( $date )) {
  2283. $D1 = $dateArr [0];
  2284. $D2 = $dateArr [1];
  2285. }
  2286. if (! empty ( $D1 ) && ! empty ( $D2 ) && ! empty ( $date ))
  2287. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2288. if (! empty ( $MebSea )) {
  2289. $con .= ' and ( invoiceNo like "%' . $MebSea . '%" or invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  2290. }
  2291. $pageinfo ['page'] = array (
  2292. 'previous' => ''
  2293. );
  2294. $get .= "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&invoiceType=" . urlencode ( $invoiceType ) . "&invoiceTrain=" . urlencode ( $invoiceTrain ) . "";
  2295. $sql = " (untreadStatus=0 or untreadStatus=3) and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  2296. $action = "invoicePrintStayAchieve";
  2297. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2298. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2299. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  2300. $this->data ['trainList'] = $trainList;
  2301. $this->data ['invoiceType'] = $invoiceType;
  2302. $this->data ['invoiceTrain'] = $invoiceTrain;
  2303. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  2304. $this->data ['MebSeaEn'] = $MebSea;
  2305. $this->data ['MebSea'] = urlencode ( $MebSea );
  2306. $this->data ['get'] = $get;
  2307. $this->data ['page'] = $pageinfo;
  2308. $this->data ['date'] = $date;
  2309. $this->data ['status'] = $status;
  2310. $this->data ['invoiceType'] = $invoiceType;
  2311. $this->data ['memu'] = "invoice";
  2312. $this->data ['staff'] = $this->staff;
  2313. foreach ( $list as $key => $value ) {
  2314. $list [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2315. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2316. if (! empty ( $lastApprover )) {
  2317. $lastApproverKey = array_keys ( $lastApprover );
  2318. $lastApprover = end ( $lastApprover );
  2319. $staffDetail = $staff->getOne ( array (
  2320. 'where' => 'sid=' . end ( $lastApproverKey ),
  2321. 'asArray' => true
  2322. ) );
  2323. $lastApprover ['username'] = $staffDetail ['username'];
  2324. }
  2325. $list [$key] ['lastApprover'] = $lastApprover;
  2326. }
  2327. $this->data ['receiptMemu'] = 'invoicePrint';
  2328. $this->data ['list'] = $list;
  2329. $this->render ( "/admin/invoicePrintStayAchieve", $this->data );
  2330. }
  2331. /**
  2332. * 填写票号并完成打印
  2333. * @since 1.0.0
  2334. */
  2335. function invoicePrintDo() {
  2336. Doo::loadModel ( 'invoice' );
  2337. $invoice = new invoice ();
  2338. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2339. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  2340. $invoicePrintType = $this->get_args ( 'invoicePrintType' ) ? $this->get_args ( 'invoicePrintType' ) : "";
  2341. $iid = $invoice->authcode ( $iid );
  2342. if (! is_numeric ( $iid ))
  2343. die ( 'illegal request' );
  2344. if (! empty ( $iid ) && ! empty ( $invoiceNo )) {
  2345. Doo::loadModel ( 'invoiceOperationLog' );
  2346. $invoiceOperationLog = new invoiceOperationLog ();
  2347. Doo::loadModel ( 'invoiceStatistics' );
  2348. $invoiceStatistics = new invoiceStatistics ();
  2349. $XDeode = new XDeode ( 5 );
  2350. Doo::loadModel ( 'invoicePaper' );
  2351. $invoicePaper = new invoicePaper ();
  2352. $invoicePrintDetail = $invoice->getInvoiceByPrint ( $iid );
  2353. if (empty ( $invoicePrintDetail ))
  2354. die ( 'illegal request' );
  2355. //
  2356. $ipid = $XDeode->decode ( $invoiceNo );
  2357. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  2358. if (empty ( $paperDetail ))
  2359. die ( 'illegal request' );
  2360. $invoicePaper = new invoicePaper ();
  2361. $item = array (
  2362. 'iid' => $iid,
  2363. 'ipid' => $ipid
  2364. );
  2365. $invoicePaper->setInvoicePaperByCondition ( $item );
  2366. $item = array (
  2367. 'iid' => $iid,
  2368. 'printStatus' => 1,
  2369. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2370. 'printer' => $this->staff [0] ['username'],
  2371. 'printTime' => date ( "Y-m-d H:i:s" ),
  2372. 'invoiceNo' => $paperDetail ['invoiceNo']
  2373. );
  2374. $invoice->setInvoiceByCondition ( $item );
  2375. $item = array (
  2376. 'date' => date ( "Y-m-d H:i:s" ),
  2377. 'operation' => '打印发票号:' . $paperDetail ['invoiceNo'],
  2378. 'status' => 5,
  2379. 'img' => $this->staff [0] ['avatar'],
  2380. 'username' => $this->staff [0] ['username'],
  2381. 'uid' => $this->staff [0] ['sid'],
  2382. 'category' => $this->staff [0] ['category'],
  2383. 'iid' => $iid
  2384. );
  2385. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2386. // 去统计--负票不汇总
  2387. if ($invoicePrintDetail ['untreadStatus'] != 4) {
  2388. $item = array (
  2389. 'date' => date ( "Y-m-d H:i:s" ),
  2390. 'priceClass' => 1,
  2391. 'cid' => $invoicePrintDetail ['cid'],
  2392. 'staff' => $invoicePrintDetail ['sid'],
  2393. 'invoicePrice' => $invoicePrintDetail ['invoicePrice']
  2394. );
  2395. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2396. }
  2397. // 发送通知信息到微信-去除
  2398. // $this->setWXMsg($iid,'PRINT');
  2399. // 发票信息库
  2400. $this->autoUpdateInvoiceInfoBase ( $invoicePrintDetail );
  2401. // 申请人获取微信通知
  2402. Doo::loadModel ( 'staff' );
  2403. $staff = new staff ();
  2404. Doo::loadClass ( 'XDeode' );
  2405. $XDeode = new XDeode ( 5 );
  2406. $username2 = $staff->getOne ( array (
  2407. 'select' => 'wxid',
  2408. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2409. 'asArray' => TRUE
  2410. ) );
  2411. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '完成打印';
  2412. $msg = '';
  2413. $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/' . $XDeode->encode ( $invoicePrintDetail ['iid'] ) . '.html';
  2414. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2415. if (empty ( $invoicePrintType ))
  2416. return "/invoicePrint";
  2417. else
  2418. return "/invoicePrintStayAchieve";
  2419. }
  2420. }
  2421. /**
  2422. * 需要邮寄的发票
  2423. * @since 1.0.0
  2424. */
  2425. function invoicePost() {
  2426. Doo::loadModel ( 'invoice' );
  2427. $invoice = new invoice ();
  2428. Doo::loadModel ( 'express' );
  2429. $express = new express ();
  2430. $invoicePost = $invoice->getPostByInvoice ();
  2431. $invoicePosted = $invoice->getPostByInvoice ( 1 );
  2432. $expressList = $express->getExpressByAll ();
  2433. $invoicePostExpress = "";
  2434. if (isset ( $_COOKIE ["invoicePostExpress"] ))
  2435. $invoicePostExpress = $_COOKIE ["invoicePostExpress"];
  2436. $this->data ['invoicePostExpress'] = $invoicePostExpress;
  2437. $this->data ['expressList'] = $expressList;
  2438. $this->data ['invoicePost'] = $invoicePost;
  2439. $this->data ['invoicePosted'] = $invoicePosted;
  2440. $this->data ['memu'] = "invoice";
  2441. $this->data ['staff'] = $this->staff;
  2442. $this->data ['receiptMemu'] = 'invoicePost';
  2443. $this->render ( "/admin/invoicePost", $this->data );
  2444. }
  2445. /**
  2446. * 添加发票邮寄信息
  2447. */
  2448. function invoiceExpressAddDo() {
  2449. Doo::loadModel ( 'invoice' );
  2450. $invoice = new invoice ();
  2451. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2452. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2453. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2454. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2455. $iid = $iid = $invoice->authcode ( $iid );
  2456. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2457. die ( 'illegal request' );
  2458. $invoicePrintDetail = $invoice->getInvoiceByIid ( $iid );
  2459. setcookie ( 'invoicePostExpress', $expressNumber );
  2460. $item = array (
  2461. 'iid' => $iid,
  2462. 'postStatus' => 1,
  2463. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2464. 'postTime' => date ( "Y-m-d H:i:s" ),
  2465. 'expressCompany' => $expressCompany,
  2466. 'expressNumber' => $expressNumber,
  2467. 'actualItems' => $actualItems,
  2468. 'poster' => $this->staff [0] ['username']
  2469. );
  2470. $invoice->setInvoiceByCondition ( $item );
  2471. // 微信通知-去掉
  2472. // $this->setWXMsg ( $iid );
  2473. Doo::loadModel ( 'staff' );
  2474. $staff = new staff ();
  2475. Doo::loadClass ( 'XDeode' );
  2476. $XDeode = new XDeode ( 5 );
  2477. $username2 = $staff->getOne ( array (
  2478. 'select' => 'wxid',
  2479. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2480. 'asArray' => TRUE
  2481. ) );
  2482. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '已邮寄';
  2483. $expCom = explode ( ":", $invoicePrintDetail ['expressCompany'] );
  2484. if (empty ( $expCom ))
  2485. $expCom [0] = '';
  2486. $msg = $expCom [0] . ':' . $invoicePrintDetail ['expressNumber'] . '';
  2487. $url = 'https://m.kuaidi100.com/result.jsp?nu=' . $invoicePrintDetail ['expressNumber'];
  2488. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2489. return '/invoicePost';
  2490. }
  2491. function invoiceExpressUpdateDo() {
  2492. Doo::loadModel ( 'invoice' );
  2493. $invoice = new invoice ();
  2494. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  2495. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2496. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2497. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2498. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2499. $iid = $invoice->authcode ( $iid );
  2500. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2501. die ( 'illegal request' );
  2502. $item = array (
  2503. 'iid' => $iid,
  2504. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2505. 'expressCompany' => $expressCompany,
  2506. 'expressNumber' => $expressNumber,
  2507. 'actualItems' => $actualItems,
  2508. 'poster' => $this->staff [0] ['username']
  2509. );
  2510. $invoice->setInvoiceByCondition ( $item );
  2511. return $action;
  2512. }
  2513. /**
  2514. * 可退票管理
  2515. */
  2516. function invoiceUntreadIsAchieve() {
  2517. Doo::loadModel ( 'invoice' );
  2518. $invoice = new invoice ();
  2519. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2520. /*
  2521. * Doo::loadClass ( 'XDeode' ); $XDeode = new XDeode ( 5 ); $page_size = 18; $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1; $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : ""; $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ); $dateArr = explode ( ':', $date ); $D1 = ''; $D2 = ''; if (! empty ( $date )) { $D1 = $dateArr [0]; $D2 = $dateArr [1]; } $con = ''; if (! empty ( $D1 ) && ! empty ( $D2 )) $con = ' and bindTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" '; // if ($date == 'MONTHO') // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)'; // elseif ($date == 'MONTHT') // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)'; // elseif ($date == 'MONTHY') // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)'; if (! empty ( $MebSea )) { $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )'; } $pageinfo ['page'] = array ( 'previous' => '' );
  2522. */
  2523. if (empty ( $MebSea )) {//
  2524. $con = ' and invoiceNo like "NULL" ';
  2525. } else {
  2526. $con = ' and (invoiceNo like "%' . $MebSea . '%" or invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  2527. }
  2528. // printStatus=1 and
  2529. $sql = " (untreadStatus=0 or untreadStatus=3) and status=2 and sid=" . $this->staff [0] ['sid'] . $con;
  2530. /*
  2531. * $action = "invoiceUntreadIsAchieve"; $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" ); $limit = $pageinfo ['lower'] . ',' . $page_size;
  2532. */
  2533. $limit = '0,20';
  2534. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2535. // print_r($list);
  2536. $this->data ['MebSeaEn'] = $MebSea;
  2537. /*
  2538. * $this->data ['get'] = $get; $this->data ['page'] = $pageinfo; $this->data ['date'] = $date;
  2539. */
  2540. $this->data ['list'] = $list;
  2541. $this->data ['memu'] = "invoice";
  2542. $this->data ['staff'] = $this->staff;
  2543. $this->data ['receiptMemu'] = 'invoice';
  2544. $this->render ( "/admin/invoiceUntreadIsAchieve", $this->data );
  2545. }
  2546. // 已经退票的发票
  2547. function invoiceUntreadED() {
  2548. Doo::loadModel ( 'invoice' );
  2549. $invoice = new invoice ();
  2550. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2551. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "";
  2552. Doo::loadClass ( 'XDeode' );
  2553. $XDeode = new XDeode ( 5 );
  2554. $page_size = 18;
  2555. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2556. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2557. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  2558. $dateArr = explode ( ':', $date );
  2559. $D1 = '';
  2560. $D2 = '';
  2561. if (! empty ( $date )) {
  2562. $D1 = $dateArr [0];
  2563. $D2 = $dateArr [1];
  2564. }
  2565. $con = '';
  2566. if (! empty ( $D1 ) && ! empty ( $D2 )) {
  2567. $con = ' and bindTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2568. }
  2569. // if ($date == 'MONTHO')
  2570. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  2571. // elseif ($date == 'MONTHT')
  2572. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  2573. // elseif ($date == 'MONTHY')
  2574. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  2575. if (! empty ( $MebSea )) {
  2576. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  2577. }
  2578. if ($invoiceType == 'ORDINARY') {
  2579. $con .= ' and invoiceType=0 ';
  2580. } elseif ($invoiceType == 'SPECIAL') {
  2581. $con .= ' and invoiceType=1 ';
  2582. }
  2583. $pageinfo ['page'] = array (
  2584. 'previous' => ''
  2585. );
  2586. // printStatus=1 and
  2587. $sql = " (untreadStatus=2 ) and status=2 and sid=" . $this->staff [0] ['sid'] . $con;
  2588. $action = "invoiceUntreadED";
  2589. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2590. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2591. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2592. // print_r($list);
  2593. $this->data ['MebSeaEn'] = $MebSea;
  2594. $this->data ['get'] = $get;
  2595. $this->data ['page'] = $pageinfo;
  2596. $this->data ['date'] = $date;
  2597. $this->data ['invoiceType'] = $invoiceType;
  2598. $this->data ['list'] = $list;
  2599. $this->data ['memu'] = "invoice";
  2600. $this->data ['staff'] = $this->staff;
  2601. $this->data ['receiptMemu'] = 'invoice';
  2602. $this->render ( "/admin/invoiceUntreadED", $this->data );
  2603. }
  2604. /**
  2605. * 退票处理页面
  2606. */
  2607. function invoiceUntread() {
  2608. Doo::loadModel ( 'invoice' );
  2609. $invoice = new invoice ();
  2610. $untreadInvoice = $invoice->getInvoiceByUntreadStatus ( 1, 0, 50 );
  2611. $establishedInvoice = $invoice->getInvoiceByUntreadStatus ( 2 );
  2612. foreach ( $establishedInvoice as $key => $value ) {
  2613. // months
  2614. $lossDate = strtotime ( "+1 month", strtotime ( $value ['OperationLog'] ['date'] ) );
  2615. $nowDate = strtotime ( 'now' );
  2616. $establishedInvoice [$key] ['lossShow'] = false;
  2617. if ($lossDate < $nowDate)
  2618. $establishedInvoice [$key] ['lossShow'] = true;
  2619. }
  2620. $this->data ['untreadInvoice'] = $untreadInvoice;
  2621. $this->data ['establishedInvoice'] = $establishedInvoice;
  2622. $this->data ['memu'] = "invoice";
  2623. $this->data ['staff'] = $this->staff;
  2624. $this->data ['receiptMemu'] = 'invoiceUntread';
  2625. $this->render ( "/admin/invoiceUntread", $this->data );
  2626. }
  2627. /**
  2628. * 确认收到退回的发票,开票状态为退回 //收款状态解绑,公司统计扣除入账额度
  2629. */
  2630. function invoiceUntreadEstablishedDo() {
  2631. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  2632. Doo::loadModel ( 'invoice' );
  2633. $invoice = new invoice ();
  2634. Doo::loadModel ( 'invoiceOperationLog' );
  2635. $invoiceOperationLog = new invoiceOperationLog ();
  2636. Doo::loadModel ( 'invoiceReceivables' );
  2637. Doo::loadModel ( 'invoiceStatistics' );
  2638. $iid = $invoice->authcode ( $untreadIidKey );
  2639. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2640. die ( 'illegal request' );
  2641. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  2642. if ($invoiceDetails ['untreadStatus'] != 1)
  2643. die ( 'illegal request untreadStatus error !=1' );
  2644. $item = array (
  2645. 'iid' => $iid,
  2646. // 'irid'=>'',
  2647. 'untreadStatus' => 2,
  2648. 'updateTime' => date ( "Y-m-d H:i:s" )
  2649. );
  2650. $invoice->setInvoiceByCondition ( $item );
  2651. $item = array (
  2652. 'date' => date ( "Y-m-d H:i:s" ),
  2653. 'operation' => '已确认退票',
  2654. 'status' => 6,
  2655. 'img' => $this->staff [0] ['avatar'],
  2656. 'username' => $this->staff [0] ['username'],
  2657. 'uid' => $this->staff [0] ['sid'],
  2658. 'category' => $this->staff [0] ['category'],
  2659. 'iid' => $iid
  2660. );
  2661. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2662. // 收款解绑以及入账扣除 收款扣除
  2663. if (! empty ( $invoiceDetails ['irid'] )) {
  2664. $iridList = explode ( ',', $invoiceDetails ['irid'] );
  2665. foreach ( $iridList as $value ) {
  2666. $invoiceReceivables = new invoiceReceivables ();
  2667. $irDetails = $invoiceReceivables->getOne ( array (
  2668. 'where' => " irid=" . $value . ' and bindStatus=1',
  2669. 'asArray' => TRUE
  2670. ) );
  2671. $item = array (
  2672. 'irid' => $value,
  2673. 'bindStatus' => 0,
  2674. 'untreadStatus' => 1,
  2675. 'untreadStaff' => $invoiceDetails ['userName'],
  2676. 'unbundlingTime' => date ( "Y-m-d H:i:s" ),
  2677. 'iid' => 0
  2678. );
  2679. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2680. if (! empty ( $irDetails )) {
  2681. // 扣除入账
  2682. $invoiceStatistics = new invoiceStatistics ();
  2683. $item = array (
  2684. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2685. 'priceClass' => 3,
  2686. 'cid' => $invoiceDetails ['cid'],
  2687. 'staff' => $invoiceDetails ['sid'],
  2688. 'accountPrice' => - $irDetails ['receivablesPrice']
  2689. );
  2690. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2691. // 扣除收款
  2692. $invoiceStatistics = new invoiceStatistics ();
  2693. $item = array (
  2694. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2695. 'priceClass' => 2,
  2696. 'cid' => $invoiceDetails ['cid'],
  2697. 'staff' => $invoiceDetails ['sid'],
  2698. 'irid' => $irDetails ['irid'],
  2699. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  2700. );
  2701. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2702. }
  2703. // 解绑时删除收入流水
  2704. Doo::loadModel ( 'wasteBook' );
  2705. $wasteBook = new wasteBook ();
  2706. $wasteBook->delete ( array (
  2707. 'where' => 'dataID=' . $value . ' and accountType=7',
  2708. 'limit' => 1
  2709. ) );
  2710. }
  2711. }
  2712. return "/invoiceUntread";
  2713. }
  2714. function invoiceUntreadRecallDo() {
  2715. $iidKey = isset ( $this->params ['iidKey'] ) ? $this->params ['iidKey'] : "";
  2716. Doo::loadModel ( 'invoice' );
  2717. $invoice = new invoice ();
  2718. Doo::loadClass ( 'XDeode' );
  2719. $XDeode = new XDeode ( 5 );
  2720. Doo::loadModel ( 'invoiceOperationLog' );
  2721. $invoiceOperationLog = new invoiceOperationLog ();
  2722. $iid = $XDeode->decode ( $iidKey );
  2723. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  2724. if (empty ( $invoiceDetail )) {
  2725. die ( 'illegal request-DATANULL' );
  2726. }
  2727. $item = array (
  2728. 'iid' => $iid,
  2729. 'untreadStatus' => 0
  2730. );
  2731. $invoice->setInvoiceByCondition ( $item );
  2732. $item = array (
  2733. 'date' => date ( "Y-m-d H:i:s" ),
  2734. 'operation' => '撤回申请退票',
  2735. 'status' => 13,
  2736. 'img' => $this->staff [0] ['avatar'],
  2737. 'username' => $this->staff [0] ['username'],
  2738. 'uid' => $this->staff [0] ['sid'],
  2739. 'category' => $this->staff [0] ['category'],
  2740. 'iid' => $iid
  2741. );
  2742. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2743. return "/invoiceUntread";
  2744. }
  2745. /**
  2746. * 建立负票,关联原来发票
  2747. */
  2748. function invoiceLossDo() {
  2749. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2750. if (! empty ( $iidKey )) {
  2751. Doo::loadClass ( 'XDeode' );
  2752. $XDeode = new XDeode ( 5 );
  2753. Doo::loadModel ( 'invoice' );
  2754. $invoice = new invoice ();
  2755. Doo::loadModel ( 'invoiceOperationLog' );
  2756. $invoiceOperationLog = new invoiceOperationLog ();
  2757. $iidKey = $XDeode->decode ( $iidKey );
  2758. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  2759. // 拷贝插入一条发票数据
  2760. $iid = $invoice->setInvoiceLoss ( $iidKey );
  2761. // 更新负票
  2762. $invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  2763. $invoice = new invoice ();
  2764. $item = array (
  2765. 'iid' => $iid,
  2766. 'sid' => $this->staff [0] ['sid'],
  2767. 'userName' => $this->staff [0] ['username'],
  2768. 'cid' => $this->staff [0] ['cid'],
  2769. 'categoryName' => $this->staff [0] ['category'],
  2770. 'invoiceQuantity' => - $invoiceDetail ['invoiceQuantity'],
  2771. 'invoicePrice' => - $invoiceDetail ['invoicePrice'],
  2772. 'invoiceSerial' => $invoiceSerial,
  2773. 'invoiceNo' => '',
  2774. 'printStatus' => 0,
  2775. 'untreadStatus' => 4,
  2776. // 关联发票号
  2777. 'lossIid' => $invoiceDetail ['iid']
  2778. );
  2779. $invoice->setInvoiceByCondition ( $item );
  2780. // 更新原发票
  2781. $invoice = new invoice ();
  2782. $item = array (
  2783. 'iid' => $invoiceDetail ['iid'],
  2784. 'lossIid' => $iid
  2785. );
  2786. $invoice->setInvoiceByCondition ( $item );
  2787. // 操作日志
  2788. $item = array (
  2789. 'date' => date ( "Y-m-d H:i:s" ),
  2790. 'operation' => "创建负票" . $invoiceSerial,
  2791. 'status' => 12,
  2792. 'img' => $this->staff [0] ['avatar'],
  2793. 'username' => $this->staff [0] ['username'],
  2794. 'uid' => $this->staff [0] ['sid'],
  2795. 'category' => $this->staff [0] ['category'],
  2796. 'iid' => $iid
  2797. );
  2798. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2799. // print_r($invoiceDetail);
  2800. // echo $iid;die;
  2801. }
  2802. return '/invoiceUntread';
  2803. }
  2804. /**
  2805. * 上传银行到账 收款文件
  2806. */
  2807. function invoiceReceivablesBankUpload() {
  2808. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  2809. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  2810. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  2811. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  2812. header ( "HTTP/1.1 500 Internal Server Error" );
  2813. echo "POST exceeded maximum allowed size.";
  2814. exit ( 0 );
  2815. }
  2816. // Settings
  2817. $save_path = DOO::conf ()->SITE_PATH . "upload/invoiceReceivablesBank/"; // The path were we will save the file (getcwd() may not be reliable and should be tested in your environment)
  2818. $upload_name = "Filedata";
  2819. $file_name = "";
  2820. $nk = time ();
  2821. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  2822. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  2823. echo "文件无法保存.";
  2824. exit ( 0 );
  2825. }
  2826. echo json_encode ( array (
  2827. 'filename' => $file_name,
  2828. 'id' => $nk
  2829. ) );
  2830. exit ( 0 );
  2831. }
  2832. /**
  2833. * 解析银行到账收款execl并导入库中
  2834. */
  2835. function invoiceReceivablesImport() {
  2836. $path = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  2837. if ($path != "") {
  2838. Doo::loadModel ( 'invoiceReceivables' );
  2839. $invoiceReceivables = new invoiceReceivables ();
  2840. Doo::loadClass ( 'invoice.func' );
  2841. Doo::loadModel ( 'invoiceROLog' );
  2842. $invoiceROLog = new invoiceROLog ();
  2843. Doo::loadModel ( 'invoiceStatistics' );
  2844. $invoiceStatistics = new invoiceStatistics ();
  2845. $exlArray = formatExcelToArrayBank ( DOO::conf ()->SITE_PATH . "upload/invoiceReceivablesBank/" . $path );
  2846. $bankBatchNumber = 'BBN_' . time ();
  2847. Doo::db ()->beginTransaction ();
  2848. // 批量存储收款--由于必须获得收款ID,
  2849. $sql = 'INSERT INTO CLD_invoiceReceivables (OriginalPrice,receivablesPrice, receivablesMessage,receivablesSerial,receivablesBank,receivablesDate,inputStaff,date,receivablesCategory,receivablesStaff,bankBatchNumber,recepitTitleMark)
  2850. VALUES ';
  2851. $date = date ( "Y-m-d" );
  2852. $receivablesList = array ();
  2853. foreach ( $exlArray as $key => $value ) {
  2854. $receivablesSql = '(' . $value ["receivablesPrice"] . ',' . $value ["receivablesPrice"] . ',"' . $value ["receivablesMessage"] . '",' . '"#SK' . date ( "Ymd" ) . mt_rand ( 1000, 9999 ) . '","' . $value ["receivablesBank"] . '","' . $value ["receivablesDate"] . '","' . $this->staff [0] ['username'] . '","' . $date . '","PUBLIC","PUBLIC","' . $bankBatchNumber . '","' . $value ["receivablesMessage"] . '")';
  2855. array_push ( $receivablesList, $receivablesSql );
  2856. }
  2857. $sql = $sql . implode ( ',', $receivablesList );
  2858. // echo $sql;
  2859. Doo::db ()->query ( $sql );
  2860. // 批量存储收款统计
  2861. // 获得刚刚导入数据的irid组-缺少办事处和人员
  2862. $iridList = $invoiceReceivables->getInvoiceReceivablesByBBN ( $bankBatchNumber );
  2863. // 没有irid 回滚所有操作
  2864. if (empty ( $iridList )) {
  2865. Doo::db ()->rollBack ();
  2866. header ( 'Content-Type:text/html;charset=utf-8' );
  2867. die ( '文档或数据不正确,请重新<a href="/invoiceReceivables">上传</a>.' );
  2868. }
  2869. $sql = 'INSERT INTO CLD_invoiceStatistics (date, priceClass,irid,receivablesPrice)
  2870. VALUES ';
  2871. $statisticsList = array ();
  2872. foreach ( $iridList as $value ) {
  2873. $statisticsSql = '("' . $date . '",2,' . $value ['irid'] . ',' . $value ["receivablesPrice"] . ')';
  2874. array_push ( $statisticsList, $statisticsSql );
  2875. }
  2876. $sql = $sql . implode ( ',', $statisticsList );
  2877. Doo::db ()->query ( $sql );
  2878. // 批量存储操作日志
  2879. $sql = 'INSERT INTO CLD_invoiceROLog (operation, date,status,img, username,uid,category,irid)
  2880. VALUES ';
  2881. $ROLogList = array ();
  2882. foreach ( $iridList as $value ) {
  2883. $ROLogSql = '("' . $this->staff [0] ['username'] . ' 转入 公共待认领款项","' . $date . '",1,"' . $this->staff [0] ['avatar'] . '","' . $this->staff [0] ['username'] . '","' . $this->staff [0] ['sid'] . '","' . $this->staff [0] ['category'] . '","' . $value ['irid'] . '")';
  2884. array_push ( $ROLogList, $ROLogSql );
  2885. }
  2886. $sql = $sql . implode ( ',', $ROLogList );
  2887. Doo::db ()->query ( $sql );
  2888. // 批量写入流水
  2889. $sql = 'INSERT INTO CLD_wasteBook (dataID, expensesType,accountType,accountPriceShow, accountPrice,accountBank,category,cid,name,sid,inputDate)
  2890. VALUES ';
  2891. $wasteBookList = array ();
  2892. foreach ( $iridList as $value ) {
  2893. $accountBank = '';
  2894. if ($value ['receivablesBank'] == '纵横广发') {
  2895. $accountBank = 'CGBDeposit';
  2896. } elseif ($value ['receivablesBank'] == '纵横工行') {
  2897. $accountBank = 'ICBCDeposit';
  2898. } elseif ($value ['receivablesBank'] == '华润银行') {
  2899. $accountBank = 'HUADeposit';
  2900. } elseif ($value ['receivablesBank'] == '个人广发') {
  2901. $accountBank = 'PersonalDeposit';
  2902. }
  2903. $wasteBookSql = '("' . $value ['irid'] . ' ",1,7,"' . $value ['receivablesPrice'] . '","' . $value ['receivablesPrice'] . '","' . $accountBank . '",
  2904. "' . $this->staff [0] ['category'] . '","' . $this->staff [0] ['cid'] . '","' . $this->staff [0] ['username'] . '","' . $this->staff [0] ['sid'] . '","' . date ( "Y-m-d H:i:s" ) . '")';
  2905. array_push ( $wasteBookList, $wasteBookSql );
  2906. }
  2907. $sql = $sql . implode ( ',', $wasteBookList );
  2908. Doo::db ()->query ( $sql );
  2909. Doo::db ()->commit ();
  2910. return "/invoiceReceivables";
  2911. }
  2912. echo 'no file';
  2913. }
  2914. function invoiceReceivables() {
  2915. $invoiceTC = $this->get_args ( 'invoiceTC' ) ? $this->get_args ( 'invoiceTC' ) : '';
  2916. Doo::loadModel ( 'L_category' );
  2917. $lCategory = new L_category ();
  2918. Doo::loadModel ( 'staff' );
  2919. $staff = new staff ();
  2920. Doo::loadModel ( 'invoiceReceivables' );
  2921. $invoiceReceivables = new invoiceReceivables ();
  2922. Doo::loadModel ( 'invoice' );
  2923. $invoice = new invoice ();
  2924. Doo::loadClass ( 'XDeode' );
  2925. $XDeode = new XDeode ( 5 );
  2926. $category = $lCategory->getCategory ();
  2927. $staffList = $staff->getStaffByCid ( $this->staff [0] ['cid'] );
  2928. $sql = 'bindStatus=1 and iid!=0';
  2929. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByNew ( 4, $sql );
  2930. // 获取未入账发票
  2931. $invoiceUnAccount = $invoice->getInvoiceByUnAccount ( $invoiceTC );
  2932. $invoiceExistAccount = $invoice->getInvoiceByUnAccount ( '', true );
  2933. foreach ( $invoiceUnAccount as $key => $value ) {
  2934. $invoiceUnAccount [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2935. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2936. if (! empty ( $lastApprover )) {
  2937. $lastApproverKey = array_keys ( $lastApprover );
  2938. $lastApprover = end ( $lastApprover );
  2939. $staffDetail = $staff->getOne ( array (
  2940. 'where' => 'sid=' . end ( $lastApproverKey ),
  2941. 'asArray' => true
  2942. ) );
  2943. $lastApprover ['username'] = $staffDetail ['username'];
  2944. }
  2945. $invoiceUnAccount [$key] ['lastApprover'] = $lastApprover;
  2946. }
  2947. foreach ( $invoiceExistAccount as $key => $value ) {
  2948. // $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  2949. // if (empty ( $irList ))
  2950. // $irList [0] ['sumPrice'] = 0;
  2951. //$balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  2952. $invoiceExistAccount [$key] ['existAccount'] = $value ['invoicePrice']-$value ['invoiceBalance'];
  2953. //$invoiceExistAccount [$key] ['balance'] = $balance;
  2954. }
  2955. $receivablesInput = $invoiceReceivables->getInvoiceReceivablesByInput ();
  2956. $halfList = $invoiceReceivables->getInvoiceReceivablesByHalf ();
  2957. $this->data ['halfList'] = $halfList;
  2958. $this->data ['halfCount'] = count ( $halfList );
  2959. // print_r($receivablesList);
  2960. $this->data ['receivablesDate'] = date ( "Y-m-d" );
  2961. $this->data ['ieaCount'] = count ( $invoiceExistAccount );
  2962. $this->data ['invoiceExistAccount'] = $invoiceExistAccount;
  2963. $this->data ['receivablesInput'] = $receivablesInput;
  2964. $this->data ['year'] = date ( 'Y' );
  2965. $this->data ['invoiceUnAccount'] = $invoiceUnAccount;
  2966. $this->data ['receivablesList'] = $receivablesList;
  2967. $this->data ['staffList'] = $staffList;
  2968. $this->data ['category'] = $category;
  2969. $this->data ['memu'] = "invoice";
  2970. $this->data ['staff'] = $this->staff;
  2971. $this->data ['receiptMemu'] = 'invoiceReceivables';
  2972. $this->render ( "/admin/invoiceReceivables", $this->data );
  2973. }
  2974. /**
  2975. * 设置收款认领地区
  2976. */
  2977. function setInvoiceReceivablesClaim() {
  2978. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  2979. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  2980. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  2981. if (! empty ( $iridKey ) && ! empty ( $receivablesCategory )) {
  2982. Doo::loadModel ( 'invoiceReceivables' );
  2983. $invoiceReceivables = new invoiceReceivables ();
  2984. Doo::loadClass ( 'XDeode' );
  2985. $XDeode = new XDeode ( 5 );
  2986. Doo::loadModel ( 'invoiceROLog' );
  2987. $invoiceROLog = new invoiceROLog ();
  2988. $irid = $XDeode->decode ( $iridKey );
  2989. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  2990. if (empty ( $irDetail ))
  2991. die ( 'illegal request' );
  2992. $item = array (
  2993. 'irid' => $irid,
  2994. 'receivablesCategory' => $receivablesCategory
  2995. );
  2996. if ($receivablesCategory != 'PUBLIC') {
  2997. $item += array (
  2998. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  2999. 'inputType' => 1
  3000. );
  3001. }
  3002. $invoiceReceivables = new invoiceReceivables ();
  3003. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3004. // 收款操作日志
  3005. $item = array (
  3006. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 ",
  3007. 'date' => date ( "Y-m-d" ),
  3008. 'status' => 1,
  3009. 'img' => $this->staff [0] ['avatar'],
  3010. 'username' => $this->staff [0] ['username'],
  3011. 'uid' => $this->staff [0] ['sid'],
  3012. 'category' => $this->staff [0] ['category'],
  3013. 'irid' => $irid
  3014. );
  3015. $invoiceROLog->setInvoiceROLog ( $item );
  3016. if (empty ( $action ))
  3017. return '/invoiceReceivables';
  3018. else
  3019. return "/invoiceReceivablesAS";
  3020. }
  3021. die ( 'illegal request' );
  3022. }
  3023. /**
  3024. * 新添加收款直接入账发票
  3025. */
  3026. function invoiceCompareClaimPrice() {
  3027. // 收款录入
  3028. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  3029. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3030. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3031. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3032. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3033. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $iidKey )) {
  3034. Doo::loadModel ( 'invoiceReceivables' );
  3035. $invoiceReceivables = new invoiceReceivables ();
  3036. Doo::loadModel ( 'invoiceROLog' );
  3037. $invoiceROLog = new invoiceROLog ();
  3038. Doo::loadModel ( 'invoiceStatistics' );
  3039. Doo::loadModel ( 'invoice' );
  3040. $invoice = new invoice ();
  3041. Doo::loadClass ( 'XDeode' );
  3042. $XDeode = new XDeode ( 5 );
  3043. Doo::loadModel ( 'invoiceOperationLog' );
  3044. $invoiceOperationLog = new invoiceOperationLog ();
  3045. $iidKey = $XDeode->decode ( $iidKey );
  3046. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  3047. if (! ($invoiceDetail ['status'] == 2 && $invoiceDetail ['printStatus'] == 1 && $invoiceDetail ['untreadStatus'] == 0))
  3048. die ( 'illegal request' );
  3049. $receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  3050. // 收款录入 并绑定发票
  3051. Doo::db ()->beginTransaction ();
  3052. //获得发票入账余额
  3053. //$bindInvicePrice=$invoiceReceivables->getSumOfReceivablesPrice ( $invoiceDetail['irid'] );
  3054. //$bindPrice=$invoiceDetail ['invoiceBalance']-$bindInvicePrice;
  3055. $bindStatus = 0;
  3056. $invoiceBalance=$invoiceDetail ['invoicePrice'];
  3057. if($invoiceDetail ['invoiceBalance']!=0){
  3058. $invoiceBalance=$invoiceDetail ['invoiceBalance'];
  3059. }
  3060. if ($receivablesPrice <= $invoiceBalance){
  3061. $bindStatus = 1;
  3062. //$bindPrice=$receivablesPrice;
  3063. }
  3064. $titleMark = $invoiceDetail ['invoiceTitle'];
  3065. if (! empty ( $invoiceDetail ['invoiceCompany'] ))
  3066. $titleMark = $invoiceDetail ['invoiceCompany'];
  3067. $item = array (
  3068. 'recepitTitleMark' => $titleMark,
  3069. 'bindStatus' => $bindStatus,
  3070. 'iid' => $invoiceDetail ['iid'],
  3071. 'bindPrice' => $receivablesPrice,
  3072. 'bindDate' => date ( "Y-m-d H:i:s" ),
  3073. 'receivablesPrice' => $receivablesPrice,
  3074. 'OriginalPrice' => $receivablesPrice,
  3075. 'receivablesMessage' => $receivablesMessage,
  3076. 'receivablesSerial' => $receivablesSerial,
  3077. 'receivablesBank' => $receivablesBank,
  3078. 'receivablesDate' => $receivablesDate,
  3079. 'inputStaff' => $this->staff [0] ['username'],
  3080. 'accountClerk' => $this->staff [0] ['username'],
  3081. 'date' => date ( "Y-m-d" ),
  3082. 'receivablesCategory' => $invoiceDetail ['cid'] . ':' . $invoiceDetail ['categoryName'],
  3083. 'receivablesStaff' => $invoiceDetail ['sid'] . '-' . $invoiceDetail ['userName'],
  3084. 'confirmTime' => date ( "Y-m-d H:i:s" )
  3085. );
  3086. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  3087. $item = array ();
  3088. // 收款操作日志
  3089. $item = array (
  3090. 'operation' => $this->staff [0] ['username'] . " 转入 " . $invoiceDetail ['userName']
  3091. );
  3092. $item += array (
  3093. 'date' => date ( "Y-m-d" ),
  3094. 'status' => 1,
  3095. 'img' => $this->staff [0] ['avatar'],
  3096. 'username' => $this->staff [0] ['username'],
  3097. 'uid' => $this->staff [0] ['sid'],
  3098. 'category' => $this->staff [0] ['category'],
  3099. 'irid' => $irid
  3100. );
  3101. $invoiceROLog->setInvoiceROLog ( $item );
  3102. // 收款统计
  3103. $invoiceStatistics = new invoiceStatistics ();
  3104. $item = array (
  3105. 'date' => $receivablesDate,
  3106. 'priceClass' => 2,
  3107. 'irid' => $irid,
  3108. 'cid' => $invoiceDetail ['cid'],
  3109. 'staff' => $invoiceDetail ['sid'],
  3110. 'receivablesPrice' => $receivablesPrice
  3111. );
  3112. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3113. // 收款 入 发票
  3114. $detail = $invoiceDetail;
  3115. $iridString = "";
  3116. if (empty ( $detail ['irid'] ))
  3117. $iridString = $irid;
  3118. else
  3119. $iridString = $detail ['irid'] . ',' . $irid;
  3120. $item = array (
  3121. 'irid' => $iridString,
  3122. 'bindTime' => date ( "Y-m-d H:i:s" ),
  3123. 'updateTime' => date ( "Y-m-d H:i:s" ),
  3124. 'iid' => $detail ['iid']
  3125. );
  3126. // $invoiceReceivables = new invoiceReceivables ();
  3127. // $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  3128. // $sumBind = $bindInvicePrice;
  3129. // $sumBalance=$invoiceReceivables->balanceOfReceivablesPrice($irid);
  3130. // $sum=$sumBind+$sumBalance;
  3131. // ;
  3132. if ($receivablesPrice>=$invoiceBalance){
  3133. $item += array (
  3134. 'invoiceBalance'=>0,
  3135. 'untreadStatus' => 3
  3136. );
  3137. }else{
  3138. $item += array (
  3139. 'invoiceBalance'=>$invoiceBalance-$receivablesPrice
  3140. );
  3141. }
  3142. $invoice->setInvoiceByCondition ( $item );
  3143. // 操作日志
  3144. $item = array (
  3145. 'date' => date ( "Y-m-d H:i:s" ),
  3146. 'operation' => "收款入账" . $receivablesSerial . "到发票" . $detail ['invoiceSerial'],
  3147. 'status' => 8,
  3148. 'img' => $this->staff [0] ['avatar'],
  3149. 'username' => $this->staff [0] ['username'],
  3150. 'uid' => $this->staff [0] ['sid'],
  3151. 'category' => $this->staff [0] ['category'],
  3152. 'iid' => $detail ['iid']
  3153. );
  3154. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3155. // 入账汇总
  3156. $invoiceStatistics = new invoiceStatistics ();
  3157. // $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $iridString );
  3158. // $accountPrice = 0;
  3159. // foreach ( $list as $key => $value ) {
  3160. // $accountPrice += $value ['receivablesPrice'];
  3161. // }
  3162. $item = array (
  3163. 'date' => $receivablesDate,
  3164. 'priceClass' => 3,
  3165. 'cid' => $invoiceDetail ['cid'],
  3166. 'staff' => $invoiceDetail ['sid'],
  3167. 'accountPrice' => $receivablesPrice
  3168. );
  3169. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3170. // 公司流水记录
  3171. Doo::loadModel ( 'wasteBook' );
  3172. $wasteBook = new wasteBook ();
  3173. $abDetail = $wasteBook->getAccountBookByAid ( 2, 7, $irid );
  3174. $accountBank = '';
  3175. if ($receivablesBank == '纵横广发') {
  3176. $accountBank = 'CGBDeposit';
  3177. } elseif ($receivablesBank == '纵横工行') {
  3178. $accountBank = 'ICBCDeposit';
  3179. } elseif ($receivablesBank == '华润银行') {
  3180. $accountBank = 'HUADeposit';
  3181. } elseif ($receivablesBank == '个人广发') {
  3182. $accountBank = 'PersonalDeposit';
  3183. }
  3184. if (empty ( $abDetail )) {
  3185. $item = array (
  3186. 'dataID' => $irid,
  3187. 'expensesType' => 1,
  3188. 'accountType' => 7,
  3189. 'accountPrice' => $receivablesPrice,
  3190. 'accountPriceShow' => $receivablesPrice,
  3191. 'accountBank' => $accountBank,
  3192. 'category' => $this->staff [0] ['category'],
  3193. 'cid' => $this->staff [0] ['cid'],
  3194. 'name' => $this->staff [0] ['username'],
  3195. 'sid' => $this->staff [0] ['sid'],
  3196. 'inputDate' => date ( "Y-m-d H:i:s" )
  3197. );
  3198. $wasteBook->setAccountBookStatistics ( $item );
  3199. }
  3200. Doo::db ()->commit ();
  3201. }
  3202. return '/invoiceReceivables';
  3203. }
  3204. /**
  3205. * 录入收款数据
  3206. * @return string
  3207. */
  3208. function invoiceReceivablesDo() {
  3209. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3210. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3211. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3212. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3213. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3214. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  3215. Doo::loadModel ( 'invoiceReceivables' );
  3216. $invoiceReceivables = new invoiceReceivables ();
  3217. Doo::loadModel ( 'invoiceROLog' );
  3218. $invoiceROLog = new invoiceROLog ();
  3219. Doo::loadModel ( 'invoiceStatistics' );
  3220. $invoiceStatistics = new invoiceStatistics ();
  3221. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $receivablesCategory ) && ! empty ( $receivablesStaff )) {
  3222. $item = array (
  3223. 'receivablesPrice' => $receivablesPrice,
  3224. 'OriginalPrice' => $receivablesPrice,
  3225. 'receivablesMessage' => $receivablesMessage,
  3226. 'receivablesSerial' => "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  3227. 'receivablesBank' => $receivablesBank,
  3228. 'receivablesDate' => $receivablesDate,
  3229. 'inputStaff' => $this->staff [0] ['username'],
  3230. 'date' => date ( "Y-m-d" ),
  3231. 'receivablesCategory' => $receivablesCategory,
  3232. 'receivablesStaff' => $receivablesStaff
  3233. );
  3234. if ($receivablesCategory != 'PUBLIC') {
  3235. $item += array (
  3236. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3237. 'inputType' => 1
  3238. );
  3239. }
  3240. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  3241. $item = array ();
  3242. // 收款操作日志
  3243. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3244. $item = array (
  3245. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  3246. );
  3247. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3248. $item = array (
  3249. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  3250. );
  3251. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3252. $receivablesStaff = explode ( '-', $receivablesStaff );
  3253. $item = array (
  3254. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  3255. );
  3256. }
  3257. $item += array (
  3258. 'date' => date ( "Y-m-d" ),
  3259. 'status' => 1,
  3260. 'img' => $this->staff [0] ['avatar'],
  3261. 'username' => $this->staff [0] ['username'],
  3262. 'uid' => $this->staff [0] ['sid'],
  3263. 'category' => $this->staff [0] ['category'],
  3264. 'irid' => $irid
  3265. );
  3266. $invoiceROLog->setInvoiceROLog ( $item );
  3267. $item = array (
  3268. 'date' => $receivablesDate,
  3269. 'priceClass' => 2,
  3270. 'irid' => $irid,
  3271. 'receivablesPrice' => $receivablesPrice
  3272. );
  3273. if ($receivablesCategory != 'PUBLIC') {
  3274. $receivablesCategory = explode ( ":", $receivablesCategory );
  3275. $item += array (
  3276. 'cid' => $receivablesCategory [0]
  3277. );
  3278. }
  3279. if ($receivablesStaff2 != 'PUBLIC') {
  3280. $receivablesStaff = explode ( "-", $receivablesStaff2 );
  3281. $item += array (
  3282. 'staff' => $receivablesStaff [0]
  3283. );
  3284. }
  3285. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3286. $toparty = $this->getWxidByCategory ( $receivablesCategory [1] );
  3287. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  3288. $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  3289. if ($toparty != 0)
  3290. $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  3291. // 公司流水记录
  3292. Doo::loadModel ( 'wasteBook' );
  3293. $wasteBook = new wasteBook ();
  3294. $abDetail = $wasteBook->getAccountBookByAid ( 1, 7, $irid );
  3295. $accountBank = '';
  3296. if ($receivablesBank == '纵横广发') {
  3297. $accountBank = 'CGBDeposit';
  3298. } elseif ($receivablesBank == '纵横工行') {
  3299. $accountBank = 'ICBCDeposit';
  3300. } elseif ($receivablesBank == '华润银行') {
  3301. $accountBank = 'HUADeposit';
  3302. } elseif ($receivablesBank == '个人广发') {
  3303. $accountBank = 'PersonalDeposit';
  3304. }
  3305. $item = array (
  3306. 'dataID' => $irid,
  3307. 'expensesType' => 1,
  3308. 'accountType' => 7,
  3309. 'accountPriceShow' => $receivablesPrice,
  3310. 'accountPrice' => $receivablesPrice,
  3311. 'accountBank' => $accountBank,
  3312. 'category' => $this->staff [0] ['category'],
  3313. 'cid' => $this->staff [0] ['cid'],
  3314. 'name' => $this->staff [0] ['username'],
  3315. 'sid' => $this->staff [0] ['sid'],
  3316. 'inputDate' => date ( "Y-m-d H:i:s" )
  3317. );
  3318. $wasteBook->setAccountBookStatistics ( $item );
  3319. }
  3320. return "/invoiceReceivables";
  3321. }
  3322. /**
  3323. * 收款认领页面-包括公共认领 办事处认领 最近已认领数据
  3324. */
  3325. function invoiceReceivablesClaim() {
  3326. Doo::loadModel ( 'invoiceReceivables' );
  3327. $invoiceReceivables = new invoiceReceivables ();
  3328. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  3329. $this->data ['receivablesList'] = $receivablesList;
  3330. $this->data ['memu'] = "invoice";
  3331. $this->data ['staff'] = $this->staff;
  3332. $this->data ['receiptMemu'] = 'invoiceReceivablesClaim';
  3333. $this->render ( "/admin/invoiceReceivablesClaim", $this->data );
  3334. }
  3335. function invoiceReceivablesTitleMarkSet() {
  3336. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  3337. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  3338. if (empty ( $iridKey ) || empty ( $recepitTitleMark ))
  3339. die ( 'illegal request' );
  3340. Doo::loadModel ( 'invoiceReceivables' );
  3341. $invoiceReceivables = new invoiceReceivables ();
  3342. Doo::loadClass ( 'XDeode' );
  3343. $XDeode = new XDeode ( 5 );
  3344. $irid = $XDeode->decode ( $iridKey );
  3345. if (! is_numeric ( $irid ))
  3346. die ( 'illegal request' );
  3347. $invoiceReceivables->recepitTitleMark = $recepitTitleMark;
  3348. $invoiceReceivables->update ( array (
  3349. 'where' => 'irid = ' . $irid
  3350. ) );
  3351. return '/invoiceReceivablesClaim';
  3352. }
  3353. /**
  3354. * 更新收款相关数据
  3355. */
  3356. function invoiceReceivablesUpdateClaim() {
  3357. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3358. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3359. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3360. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3361. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3362. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  3363. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  3364. if (empty ( $claimKey ))
  3365. die ( 'illegal request' );
  3366. Doo::loadModel ( 'invoiceReceivables' );
  3367. $invoiceReceivables = new invoiceReceivables ();
  3368. Doo::loadModel ( 'invoiceROLog' );
  3369. $invoiceROLog = new invoiceROLog ();
  3370. $con = ' and iid=0 and bindStatus=0'; // and receivablesCategory!="PUBLIC" and receivablesStaff!="PUBLIC"
  3371. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  3372. if (empty ( $detail ))
  3373. die ( 'illegal request' );
  3374. $invoiceReceivables = new invoiceReceivables ();
  3375. $item = array (
  3376. 'irid' => $detail ['irid']
  3377. );
  3378. if ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3379. $item += array (
  3380. 'confirmTime' => date ( "Y-m-d H:i:s" )
  3381. );
  3382. }
  3383. if (! empty ( $receivablesCategory ))
  3384. $item += array (
  3385. 'receivablesCategory' => $receivablesCategory
  3386. );
  3387. if (! empty ( $receivablesStaff ))
  3388. $item += array (
  3389. 'receivablesStaff' => $receivablesStaff
  3390. );
  3391. if (! empty ( $receivablesPrice ))
  3392. $item += array (
  3393. 'receivablesPrice' => $receivablesPrice
  3394. );
  3395. if (! empty ( $receivablesMessage ))
  3396. $item += array (
  3397. 'receivablesMessage' => $receivablesMessage
  3398. );
  3399. if (! empty ( $receivablesBank ))
  3400. $item += array (
  3401. 'receivablesBank' => $receivablesBank
  3402. );
  3403. if (! empty ( $receivablesDate ))
  3404. $item += array (
  3405. 'receivablesDate' => $receivablesDate
  3406. );
  3407. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3408. // 收款操作日志
  3409. $item = array ();
  3410. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3411. $item = array (
  3412. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  3413. );
  3414. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3415. $item = array (
  3416. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  3417. );
  3418. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3419. $receivablesStaff = explode ( '-', $receivablesStaff );
  3420. $item = array (
  3421. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  3422. );
  3423. }
  3424. $item += array (
  3425. 'date' => date ( "Y-m-d" ),
  3426. 'status' => 1,
  3427. 'img' => $this->staff [0] ['avatar'],
  3428. 'username' => $this->staff [0] ['username'],
  3429. 'uid' => $this->staff [0] ['sid'],
  3430. 'category' => $this->staff [0] ['category'],
  3431. 'irid' => $detail ['irid']
  3432. );
  3433. $invoiceROLog->setInvoiceROLog ( $item );
  3434. return '/invoiceReceivablesAS';
  3435. }
  3436. function invoiceReceivablesDelete() {
  3437. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  3438. $skll = $this->get_args ( 'skll' ) ? $this->get_args ( 'skll' ) : "";
  3439. if ($skll != '删除到款')
  3440. die ( 'illegal request' );
  3441. if (empty ( $claimKey ))
  3442. die ( 'illegal request' );
  3443. Doo::loadModel ( 'invoiceReceivables' );
  3444. $invoiceReceivables = new invoiceReceivables ();
  3445. $con = ' and bindStatus=0 ';
  3446. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  3447. if (empty ( $detail ))
  3448. die ( 'illegal request' );
  3449. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  3450. // 扣除收款汇总信息 汇总
  3451. Doo::loadModel ( 'invoiceStatistics' );
  3452. $invoiceStatistics = new invoiceStatistics ();
  3453. $item = array (
  3454. 'date' => $detail ['receivablesDate'],
  3455. 'priceClass' => 2,
  3456. 'irid' => $detail ['irid'],
  3457. 'receivablesPrice' => - $detail ['receivablesPrice']
  3458. );
  3459. if ($detail ['receivablesCategory'] != 'PUBLIC') {
  3460. $receivablesCategory = explode ( ":", $detail ['receivablesCategory'] );
  3461. $item += array (
  3462. 'cid' => $receivablesCategory [0]
  3463. );
  3464. }
  3465. if ($detail ['receivablesStaff'] != 'PUBLIC') {
  3466. $receivablesStaff = explode ( "-", $detail ['receivablesStaff'] );
  3467. $item += array (
  3468. 'staff' => $receivablesStaff [0]
  3469. );
  3470. }
  3471. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3472. // 公司流水-删除时删除流水
  3473. Doo::loadModel ( 'wasteBook' );
  3474. $wasteBook = new wasteBook ();
  3475. $wasteBook->delete ( array (
  3476. 'where' => 'dataID=' . $detail ['irid'] . ' and accountType=7',
  3477. 'limit' => 1
  3478. ) );
  3479. return '/invoiceReceivablesAS';
  3480. }
  3481. /**
  3482. * 管理员录入的收款 ,确认认领到谁的名下.统计收款金额
  3483. */
  3484. function invoiceReceivablesAscription() {
  3485. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  3486. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  3487. Doo::loadModel ( 'invoiceReceivables' );
  3488. $invoiceReceivables = new invoiceReceivables ();
  3489. Doo::loadModel ( 'invoiceROLog' );
  3490. $invoiceROLog = new invoiceROLog ();
  3491. Doo::loadModel ( 'invoiceStatistics' );
  3492. $invoiceStatistics = new invoiceStatistics ();
  3493. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  3494. if (! empty ( $detail ) && $detail ['receivablesStaff'] == 'PUBLIC' && ! empty ( $recepitTitleMark )) {
  3495. $item = array (
  3496. 'irid' => $detail ['irid'],
  3497. 'receivablesCategory' => $this->staff [0] ['cid'] . ":" . $this->staff [0] ['category'],
  3498. 'receivablesStaff' => $this->staff [0] ['sid'] . "-" . $this->staff [0] ['username'],
  3499. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3500. 'recepitTitleMark' => $recepitTitleMark,
  3501. 'source' => 1
  3502. );
  3503. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3504. $item = array (
  3505. 'date' => date ( "Y-m-d" ),
  3506. 'operation' => $this->staff [0] ['username'] . " 认领 ",
  3507. 'status' => 2,
  3508. 'img' => $this->staff [0] ['avatar'],
  3509. 'username' => $this->staff [0] ['username'],
  3510. 'uid' => $this->staff [0] ['sid'],
  3511. 'category' => $this->staff [0] ['category'],
  3512. 'irid' => $irid
  3513. );
  3514. $invoiceROLog->setInvoiceROLog ( $item );
  3515. $item = array (
  3516. 'cid' => $this->staff [0] ['cid'],
  3517. 'staff' => $this->staff [0] ['sid']
  3518. );
  3519. $invoiceStatistics->updateInvoiceStatisticsByIrid ( $item, $detail ['irid'], 2 );
  3520. }
  3521. return "/invoiceReceivablesClaim";
  3522. }
  3523. /**
  3524. */
  3525. function invoiceMyReceivables() {
  3526. Doo::loadModel ( 'invoiceReceivables' );
  3527. $invoiceReceivables = new invoiceReceivables ();
  3528. Doo::loadModel ( 'invoiceStatistics' );
  3529. $invoiceStatistics = new invoiceStatistics ();
  3530. $isMonth = $invoiceStatistics->getStatisticsByMonth ( $this->staff [0] ['sid'] );
  3531. $year = date ( "Y" );
  3532. $tmp_date = date ( "Ym" );
  3533. $tmp_year = substr ( $tmp_date, 0, 4 );
  3534. $tmp_mon = substr ( $tmp_date, 4, 2 );
  3535. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  3536. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  3537. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . ".htm";
  3538. $htm = $this->showCache ( $path );
  3539. $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  3540. $this->data ['isMonth'] = $isMonth;
  3541. $this->data ['htm'] = $htm;
  3542. $this->data ['list'] = $list;
  3543. $this->data ['memu'] = "invoice";
  3544. $this->data ['staff'] = $this->staff;
  3545. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  3546. $this->render ( "/admin/invoiceMyReceivables", $this->data );
  3547. }
  3548. /**
  3549. * 纸票管理
  3550. */
  3551. function invoicePaper() {
  3552. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3553. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3554. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3555. $this->data ['dateString'] = $date;
  3556. $this->data ['status'] = $status;
  3557. $this->data ['invoiceType'] = $invoiceType;
  3558. $this->data ['memu'] = "invoice";
  3559. $this->data ['staff'] = $this->staff;
  3560. $this->data ['receiptMemu'] = 'invoicePaper';
  3561. $this->render ( "/admin/invoicePaper", $this->data );
  3562. }
  3563. /**
  3564. * 获得纸票分页数据
  3565. */
  3566. function ajaxGetinvoicePaperAchieve() {
  3567. Doo::loadModel ( 'invoicePaper' );
  3568. $invoicePaper = new invoicePaper ();
  3569. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3570. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3571. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ORDINARY";
  3572. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3573. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  3574. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  3575. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  3576. $MebSea = $this->get_args ( 'search' );
  3577. $MebSea = $MebSea ['value'];
  3578. $page_size = $length;
  3579. $con = '';
  3580. if ($status == 'ALL')
  3581. $con = ' where 1 ';
  3582. elseif ($status == 'PRINTED')
  3583. $con = ' where a.iid!=0 '; // $con = ' where b.isDelete=0 and a.iid!=0 and b.status=2 and b.untreadStatus=0 ';
  3584. elseif ($status == 'UNPRINT')
  3585. $con = ' where a.iid=0 '; // $con = ' where b.isDelete=0 and a.iid=0 and b.status=2 and b.untreadStatus=0 ';
  3586. elseif ($status == 'TICKET')
  3587. $con = ' where b.isDelete=0 and b.untreadStatus=2';
  3588. if ($invoiceType == 'ORDINARY')
  3589. $con .= ' and a.invoiceType=0 ';
  3590. elseif ($invoiceType == 'SPECIAL')
  3591. $con .= ' and a.invoiceType=1 ';
  3592. $dateArr = explode ( ':', $date );
  3593. $D1 = $dateString = '';
  3594. $D2 = '';
  3595. if (! empty ( $date )) {
  3596. $D1 = $dateArr [0];
  3597. if (isset ( $dateArr [1] ))
  3598. $D2 = $dateArr [1];
  3599. else
  3600. $D2 = '';
  3601. $dateString = $D1 . " : " . $D2;
  3602. }
  3603. if (! empty ( $D1 ) && ! empty ( $D2 ))
  3604. $con .= ' and b.printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  3605. elseif (! empty ( $D1 ) && empty ( $D2 ))
  3606. $con .= ' and b.printTime like "%' . $D1 . '%" ';
  3607. if (! empty ( $MebSea ))
  3608. $con .= ' and ( b.invoiceTitle like "%' . $MebSea . '%" or b.invoiceCompany like "%' . $MebSea . '%" or a.invoiceNo like "%' . $MebSea . '%" )';
  3609. $invoiceTotal = $invoicePaper->getInvoicePaperCount ();
  3610. $sql = ' ' . $con;
  3611. $limit = $page . ',' . $page_size;
  3612. $list = $invoicePaper->getInvoicePaper ( $limit, $sql, 'desc' );
  3613. $paperList = array ();
  3614. foreach ( $list as $key => $value ) {
  3615. $irDetail = array ();
  3616. if ($value ['iid'] == 0)
  3617. array_push ( $irDetail, '<a href="javascript:if(window.confirm(\'确认删除?\'))window.location=\'/invoicePaperDel/' . $value ['ipidKey'] . '\'" >删除</a>' );
  3618. else
  3619. array_push ( $irDetail, '' );
  3620. array_push ( $irDetail, $value ['invoiceCode'] );
  3621. array_push ( $irDetail, $value ['invoiceNo'] );
  3622. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKey'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  3623. if ($value ['invoiceType'] == 1)
  3624. array_push ( $irDetail, $value ['invoiceCompany'] );
  3625. else
  3626. array_push ( $irDetail, $value ['invoiceTitle'] );
  3627. if ($value ['invoiceType'] == 1)
  3628. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  3629. else
  3630. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  3631. array_push ( $irDetail, $value ['invoiceElement'] );
  3632. array_push ( $irDetail, $value ['categoryName'] . '-' . $value ['userName'] );
  3633. array_push ( $irDetail, $value ['printTime'] );
  3634. array_push ( $paperList, $irDetail );
  3635. }
  3636. // $approvalListJson = json_encode ( $approvalList );
  3637. $recordsFiltered = $invoiceTotal;
  3638. echo json_encode ( array (
  3639. "draw" => intval ( $draw ),
  3640. "recordsTotal" => intval ( $invoiceTotal ),
  3641. "recordsFiltered" => intval ( $recordsFiltered ),
  3642. "data" => $paperList
  3643. ), JSON_UNESCAPED_UNICODE );
  3644. }
  3645. function invoicePaperDel() {
  3646. $ipidKey = isset ( $this->params ['ipidKey'] ) ? $this->params ['ipidKey'] : "";
  3647. $XDeode = new XDeode ( 5 );
  3648. $ipid = $XDeode->decode ( $ipidKey );
  3649. if (empty ( $ipid ))
  3650. die ( 'illegal request' );
  3651. Doo::loadModel ( 'invoicePaper' );
  3652. $invoicePaper = new invoicePaper ();
  3653. $invoicePaper->delete ( array (
  3654. 'where' => 'ipid=' . $ipid . ' and iid=0',
  3655. 'limit' => 1
  3656. ) );
  3657. return '/invoicePaper';
  3658. }
  3659. /**
  3660. * 添加纸质发票号
  3661. */
  3662. function invoicePaperAdd() {
  3663. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : '0';
  3664. $invoiceCode = $this->get_args ( 'invoiceCode' ) ? $this->get_args ( 'invoiceCode' ) : "";
  3665. $invoiceNoStart = $this->get_args ( 'invoiceNoStart' ) && is_numeric ( $this->get_args ( 'invoiceNoStart' ) ) ? $this->get_args ( 'invoiceNoStart' ) : 0;
  3666. $invoiceNoTotal = $this->get_args ( 'invoiceNoTotal' ) && is_numeric ( $this->get_args ( 'invoiceNoTotal' ) ) ? $this->get_args ( 'invoiceNoTotal' ) : 0;
  3667. if ($invoiceType != '' && ! empty ( $invoiceCode ) && ! empty ( $invoiceNoStart ) && ! empty ( $invoiceNoTotal )) {
  3668. $sum = $invoiceNoStart + $invoiceNoTotal;
  3669. if (empty ( $sum ))
  3670. die ( 'illegal request' );
  3671. // echo $invoiceNoStart;
  3672. // echo $sum;
  3673. // echo strlen((int)$invoiceNoStart);
  3674. $sumLenght = strlen ( $invoiceNoStart ) - strlen ( ( int ) $invoiceNoStart );
  3675. Doo::db ()->beginTransaction ();
  3676. // 批量存储纸质发票
  3677. $date = date ( "Y-m-d H:i:s" );
  3678. $sql = 'INSERT INTO CLD_invoicePaper (invoiceType, invoiceCode,invoiceNo,date)
  3679. VALUES ';
  3680. $paperList = array ();
  3681. for($invoiceNoStart; $invoiceNoStart <= $sum - 1; $invoiceNoStart ++) {
  3682. // 数字前面自加0
  3683. $INLENGHT = strlen ( ( int ) $invoiceNoStart ) + $sumLenght;
  3684. $var = sprintf ( "%0" . $INLENGHT . "d", $invoiceNoStart );
  3685. $paperSql = '(' . $invoiceType . ',"' . $invoiceCode . '","' . $var . '","' . $date . '")';
  3686. array_push ( $paperList, $paperSql );
  3687. }
  3688. if (empty ( $paperList ))
  3689. die ( 'illegal request' );
  3690. $sql = $sql . implode ( ',', $paperList );
  3691. Doo::db ()->query ( $sql );
  3692. Doo::db ()->commit ();
  3693. return 'invoicePaper';
  3694. }
  3695. die ( 'illegal request' );
  3696. }
  3697. /**
  3698. * 收款绑定发票 ,//一个收款只能绑定一个发票
  3699. */
  3700. function invoiceBindReceivables() {
  3701. $claimKey = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  3702. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  3703. Doo::loadModel ( 'invoice' );
  3704. $invoice = new invoice ();
  3705. Doo::loadModel ( 'invoiceReceivables' );
  3706. $invoiceReceivables = new invoiceReceivables ();
  3707. Doo::loadModel ( 'invoiceOperationLog' );
  3708. $invoiceOperationLog = new invoiceOperationLog ();
  3709. if (empty ( $invoiceKey ) || empty ( $claimKey ))
  3710. die ( 'illegal request' );
  3711. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  3712. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey );
  3713. if (empty ( $detail ) && empty ( $detailM ))
  3714. die ( 'illegal request' );
  3715. if ($detail ['untreadStatus'] == 3)
  3716. die ( 'illegal request' );
  3717. // 修改 绑定状态改为 金额
  3718. $invoiceReceivables = new invoiceReceivables ();
  3719. //有BUG-需修改
  3720. $invoicePrice = $detail ['invoicePrice'] + $detailM ['bindPrice'];
  3721. if ($detailM ['receivablesPrice'] > $invoicePrice) {
  3722. $item = array (
  3723. 'bindPrice' => $invoicePrice
  3724. );
  3725. } elseif ($detailM ['receivablesPrice'] <= $invoicePrice) {//发票金额大于收款金额,绑定金额为收款金额
  3726. $item = array (
  3727. 'bindPrice' => $detailM ['receivablesPrice'],
  3728. 'bindStatus' => 1,
  3729. 'bindDate' => date ( "Y-m-d H:i:s" )
  3730. );
  3731. } else {
  3732. die ( 'illegal request' );
  3733. }
  3734. if ($detailM ['iid'] == 0) {
  3735. $item += array (
  3736. 'iid' => $detail ['iid']
  3737. );
  3738. } else {
  3739. $iidExtend = explode ( ',', $detailM ['iidExtend'] );
  3740. array_push ( $iidExtend, $detail ['iid'] );
  3741. $item += array (
  3742. 'iidExtend' => implode ( ',', $iidExtend )
  3743. );
  3744. }
  3745. $titleMark = $detail ['invoiceTitle'];
  3746. if (! empty ( $detail ['invoiceCompany'] ))
  3747. $titleMark = $detail ['invoiceCompany'];
  3748. $item += array (
  3749. 'irid' => $detailM ['irid'],
  3750. 'recepitTitleMark' => $titleMark,
  3751. 'accountClerk' => $this->staff [0] ['username']
  3752. );
  3753. // 如何没有人收款 则自动绑定收款
  3754. if ($detailM ['receivablesCategory'] == 'PUBLIC' || $detailM ['receivablesStaff'] == 'PUBLIC') {
  3755. $item += array (
  3756. 'receivablesCategory' => $detail ['cid'] . ':' . $detail ['categoryName'],
  3757. 'receivablesStaff' => $detail ['sid'] . '-' . $detail ['userName']
  3758. );
  3759. }
  3760. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3761. $iridString = "";
  3762. if (empty ( $detail ['irid'] ))
  3763. $iridString = $detailM ['irid'];
  3764. else
  3765. $iridString = $detail ['irid'] . ',' . $detailM ['irid'];
  3766. // $invoiceReceivables = new invoiceReceivables ();
  3767. // $sumBind = $invoiceReceivables->getSumOfReceivablesPrice ( $detail ['irid'] );
  3768. // //这个收款余额
  3769. // $sumBalance=$invoiceReceivables->balanceOfReceivablesPrice($detailM ['irid']);
  3770. // $sum=$sumBind+$sumBalance;
  3771. //这个收款余额
  3772. $sumBalance=$detailM ['receivablesPrice']-$detailM ['bindPrice'];
  3773. // echo $detailM ['irid'].'/'.$sumBalance.'/'.$detail ['invoicePrice'];
  3774. // die;
  3775. $item = array (
  3776. 'iid' => $detail ['iid'],
  3777. 'irid' => $iridString
  3778. );
  3779. if ($detail ['invoicePrice'] <= $sumBalance){
  3780. $item += array (
  3781. 'invoiceBalance'=>0,
  3782. 'untreadStatus' => 3,
  3783. 'bindTime' => date ( "Y-m-d H:i:s" )
  3784. );
  3785. }else{
  3786. $item += array (
  3787. 'invoiceBalance'=>$detail ['invoicePrice']-$sumBalance,
  3788. );
  3789. }
  3790. // print_r($item);
  3791. // echo $sum;die;
  3792. $invoice->setInvoiceByCondition ( $item );
  3793. // 操作日志
  3794. $item = array (
  3795. 'date' => date ( "Y-m-d H:i:s" ),
  3796. 'operation' => "收款" . $detailM ['receivablesSerial'] . "入账到发票" . $detail ['invoiceSerial'],
  3797. 'status' => 8,
  3798. 'img' => $this->staff [0] ['avatar'],
  3799. 'username' => $this->staff [0] ['username'],
  3800. 'uid' => $this->staff [0] ['sid'],
  3801. 'category' => $this->staff [0] ['category'],
  3802. 'iid' => $detail ['iid']
  3803. );
  3804. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3805. Doo::loadModel ( 'invoiceStatistics' );
  3806. $invoiceStatistics = new invoiceStatistics ();
  3807. $item = array (
  3808. 'date' => $detailM ['receivablesDate'],
  3809. 'priceClass' => 3,
  3810. 'cid' => $detail ['cid'],
  3811. 'staff' => $detail ['sid'],
  3812. 'accountPrice' => $detailM ['receivablesPrice']
  3813. );
  3814. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3815. // 公司流水记录
  3816. // Doo::loadModel ( 'wasteBook' );
  3817. // $wasteBook = new wasteBook ();
  3818. // $abDetail = $wasteBook->getAccountBookByAid (1,8,$detail ['iid'] );
  3819. // $accountBank='';
  3820. // if ($detailM ['receivablesBank']=='纵横广发'){
  3821. // $accountBank='CGBDeposit';
  3822. // }elseif($detailM ['receivablesBank']=='纵横工行'){
  3823. // $accountBank='ICBCDeposit';
  3824. // }elseif($detailM ['receivablesBank']=='华润银行'){
  3825. // $accountBank='HUADeposit';
  3826. // }elseif($detailM ['receivablesBank']=='个人广发'){
  3827. // $accountBank='PersonalDeposit';
  3828. // }
  3829. // if (empty($abDetail)){
  3830. // $item = array (
  3831. // 'dataID' => $detail ['iid'],
  3832. // 'expensesType' => 1,
  3833. // 'accountType' => 8,
  3834. // 'accountPriceShow'=>$detail ['invoicePrice'],
  3835. // 'accountPrice'=>$detail ['invoicePrice'],
  3836. // 'accountBank'=>$accountBank,
  3837. // 'category'=>$this->staff[0]['category'],
  3838. // 'cid'=>$this->staff[0]['cid'],
  3839. // 'name'=>$this->staff[0]['username'],
  3840. // 'sid'=>$this->staff[0]['sid'],
  3841. // 'inputDate'=>date ( "Y-m-d H:i:s" )
  3842. // );
  3843. // $wasteBook->setAccountBookStatistics($item);
  3844. // }
  3845. return "/invoiceReceivables";
  3846. }
  3847. /**
  3848. * 核销 动作,确认入账统计 发票收款完成--需求更变 废弃 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"; }
  3849. */
  3850. function invoiceAggregate() {
  3851. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3852. Doo::loadModel ( 'invoiceStatistics' );
  3853. $invoiceStatistics = new invoiceStatistics ();
  3854. Doo::loadModel ( 'L_category' );
  3855. $Lcategory = new L_category ();
  3856. $isList = $invoiceStatistics->getInvoiceStatisticsByYear ( $year );
  3857. $LcategoryList = $Lcategory->getCategory ();
  3858. // print_r($isList);
  3859. $html = ""; // $invoicePriceCategory=0;$receivablesPriceCategory=0;$accountPriceCategory=0;
  3860. foreach ( $LcategoryList as $key => $value ) {
  3861. $html .= '<tr><th><a href="/invoiceAggregateCategory/' . $value ['cidKey'] . '">' . $value ['title'] . '</a></th>';
  3862. $month = 1;
  3863. $invoicePriceYear = 0;
  3864. $receivablesPriceYear = 0;
  3865. $accountPriceYear = 0;
  3866. for(; $month <= 12; $month ++) {
  3867. $flag = true;
  3868. foreach ( $isList ['statisticsMonthCid'] as $k => $v ) {
  3869. if ($value ['cid'] == $v ['cid'] && $month == $v ['month']) {
  3870. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  3871. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  3872. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  3873. ';
  3874. $invoicePriceYear += $v ['invoicePrice'];
  3875. $receivablesPriceYear += $v ['receivablesPrice'];
  3876. $accountPriceYear += $v ['accountPrice'];
  3877. $flag = false;
  3878. break;
  3879. }
  3880. }
  3881. if ($flag)
  3882. $html .= '<td class="taR"></td>
  3883. <td class="taR"></td>
  3884. <td class="taR"><b></b></td>
  3885. ';
  3886. }
  3887. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  3888. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  3889. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  3890. ';
  3891. $html .= '</tr>';
  3892. }
  3893. $html .= '<tr><th><b class="colGreen">月合计</b></th>';
  3894. $invoicePriceYear = 0;
  3895. $receivablesPriceYear = 0;
  3896. $accountPriceYear = 0;
  3897. for($month = 1; $month <= 12; $month ++) {
  3898. $flag = true;
  3899. foreach ( $isList ['statisticsMonth'] as $k => $v ) {
  3900. if ($month == $v ['month']) {
  3901. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  3902. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  3903. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  3904. ';
  3905. $invoicePriceYear += $v ['invoicePrice'];
  3906. $receivablesPriceYear += $v ['receivablesPrice'];
  3907. $accountPriceYear += $v ['accountPrice'];
  3908. $flag = false;
  3909. break;
  3910. }
  3911. }
  3912. if ($flag) {
  3913. $html .= '<td class="taR"></td>
  3914. <td class="taR"></td>
  3915. <td class="taR"><b></b></td>
  3916. ';
  3917. }
  3918. }
  3919. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  3920. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  3921. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  3922. ';
  3923. $html .= '</tr>';
  3924. // print_r($isList);
  3925. $this->data ['html'] = $html;
  3926. $this->data ['LcategoryList'] = $LcategoryList;
  3927. $this->data ['isList'] = $isList;
  3928. $this->data ['year'] = $year;
  3929. $this->data ['memu'] = "invoice";
  3930. $this->data ['staff'] = $this->staff;
  3931. $this->data ['receiptMemu'] = 'invoiceAggregate';
  3932. $this->render ( "/admin/invoiceAggregate", $this->data );
  3933. }
  3934. function invoiceAggregateStaff() {
  3935. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3936. Doo::loadModel ( 'invoiceStatistics' );
  3937. $invoiceStatistics = new invoiceStatistics ();
  3938. Doo::loadModel ( 'L_category' );
  3939. $Lcategory = new L_category ();
  3940. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year );
  3941. $staffList = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year );
  3942. $cStaff = $Lcategory->getCategoryStaff ();
  3943. $html = '';
  3944. foreach ( $cStaff as $key => $value ) {
  3945. $categoryFir = true;
  3946. foreach ( $value ['staff'] as $k => $v ) {
  3947. if ($categoryFir) {
  3948. $width = count ( $value ['staff'] ) + 1;
  3949. $html .= '<tr><th rowspan="' . $width . '">' . $value ['title'] . ' </th>';
  3950. $categoryFir = false;
  3951. } else
  3952. $html .= '<tr>';
  3953. $html .= '<th>' . $v ['username'] . '</th>';
  3954. $invoicePriceStaffYear = 0;
  3955. $receivablesPriceStaffYear = 0;
  3956. $accountPriceStaffYear = 0;
  3957. for($month = 1; $month <= 12; $month ++) {
  3958. $flag = true;
  3959. foreach ( $staffList ['statisticsMonthStaff'] as $sl => $slv ) {
  3960. if ($v ['sid'] == $slv ['staff'] && $month == $slv ['month']) {
  3961. $html .= '<td class="taR">¥' . $slv ['invoicePrice'] . '</td>
  3962. <td class="taR">¥' . $slv ['receivablesPrice'] . '</td>
  3963. <td class="taR"><b>¥' . $slv ['accountPrice'] . '</b></td>
  3964. ';
  3965. $invoicePriceStaffYear += $slv ['invoicePrice'];
  3966. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  3967. $accountPriceStaffYear += $slv ['accountPrice'];
  3968. $flag = false;
  3969. break;
  3970. }
  3971. }
  3972. if ($flag)
  3973. $html .= '<td class="taR"></td>
  3974. <td class="taR"></td>
  3975. <td class="taR"><b></b></td>
  3976. ';
  3977. }
  3978. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  3979. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  3980. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  3981. ';
  3982. }
  3983. $html .= '</tr>';
  3984. // 小计
  3985. if (! empty ( $value ['staff'] )) {
  3986. $html .= '<tr><th class="taR">小计</th>';
  3987. $invoicePriceStaffYear = 0;
  3988. $receivablesPriceStaffYear = 0;
  3989. $accountPriceStaffYear = 0;
  3990. for($month = 1; $month <= 12; $month ++) {
  3991. $flag = true;
  3992. foreach ( $staffList ['statisticsMonthCid'] as $smc => $smcv ) {
  3993. if ($value ['cid'] == $smcv ['cid'] && $month == $slv ['month']) {
  3994. $html .= '<td class="taR">¥' . $smcv ['invoicePrice'] . '</td>
  3995. <td class="taR">¥' . $smcv ['receivablesPrice'] . '</td>
  3996. <td class="taR"><b>¥' . $smcv ['accountPrice'] . '</b></td>
  3997. ';
  3998. $invoicePriceStaffYear += $slv ['invoicePrice'];
  3999. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  4000. $accountPriceStaffYear += $slv ['accountPrice'];
  4001. $flag = false;
  4002. break;
  4003. }
  4004. }
  4005. if ($flag)
  4006. $html .= '<td class="taR"></td>
  4007. <td class="taR"></td>
  4008. <td class="taR"><b></b></td>
  4009. ';
  4010. }
  4011. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  4012. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  4013. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  4014. ';
  4015. $html .= '</tr>';
  4016. }
  4017. }
  4018. $html .= '<tr class="warning"><th colspan="2"><b class="colGreen" >月合计</b></th>';
  4019. $invoicePriceYear = 0;
  4020. $receivablesPriceYear = 0;
  4021. $accountPriceYear = 0;
  4022. for($month = 1; $month <= 12; $month ++) {
  4023. $flag = true;
  4024. foreach ( $staffList ['statisticsMonth'] as $k => $v ) {
  4025. if ($month == $v ['month']) {
  4026. $html .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>
  4027. <td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>
  4028. <td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>
  4029. ';
  4030. $invoicePriceYear += $v ['invoicePrice'];
  4031. $receivablesPriceYear += $v ['receivablesPrice'];
  4032. $accountPriceYear += $v ['accountPrice'];
  4033. $flag = false;
  4034. break;
  4035. }
  4036. }
  4037. if ($flag)
  4038. $html .= '<td class="taR"></td>
  4039. <td class="taR"></td>
  4040. <td class="taR"><b></b></td>
  4041. ';
  4042. }
  4043. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  4044. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  4045. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  4046. ';
  4047. $html .= '</tr>';
  4048. $this->data ['html'] = $html;
  4049. $this->data ['isList'] = $toteList;
  4050. $this->data ['year'] = $year;
  4051. $this->data ['memu'] = "invoice";
  4052. $this->data ['staff'] = $this->staff;
  4053. $this->data ['receiptMemu'] = 'invoiceAggregate';
  4054. $this->render ( "/admin/invoiceAggregateStaff", $this->data );
  4055. }
  4056. function invoiceAggregateCategory() {
  4057. Doo::loadClass ( 'XDeode' );
  4058. $XDeode = new XDeode ( 5 );
  4059. $cid = $cidKey = isset ( $this->params ['cid'] ) ? $this->params ['cid'] : "";
  4060. $cid = $XDeode->decode ( $cid );
  4061. if (! is_numeric ( $cid ))
  4062. die ( 'illegal request' );
  4063. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  4064. Doo::loadModel ( 'invoiceStatistics' );
  4065. $invoiceStatistics = new invoiceStatistics ();
  4066. Doo::loadModel ( 'staff' );
  4067. $staff = new staff ();
  4068. $list = $staff->getStaffByCid ( $cid );
  4069. $isCategory = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year, $cid );
  4070. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year, $cid );
  4071. if (empty ( $list ))
  4072. die ( '该办事处没有成员' );
  4073. $htmlA = $htmlB = $htmlC = $html = '';
  4074. foreach ( $list as $key => $value ) {
  4075. $htmlA = '<tr><th rowspan="3">' . $value ['username'] . '</th><th class="taC">开票</th>';
  4076. $htmlB = '<tr><th class="taC">收款</th>';
  4077. $htmlC = '<tr><th class="taC">入账</th>';
  4078. $invoicePriceStaffYear = 0;
  4079. $receivablesPriceStaffYear = 0;
  4080. $accountPriceStaffYear = 0;
  4081. for($month = 1; $month <= 12; $month ++) {
  4082. $flag = true;
  4083. foreach ( $isCategory ['statisticsMonthStaff'] as $k => $v ) {
  4084. if ($value ['sid'] == $v ['staff'] && $month == $v ['month']) {
  4085. $htmlA .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>';
  4086. $htmlB .= '<td class="taR">¥' . $v ['receivablesPrice'] . '</td>';
  4087. $htmlC .= '<td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>';
  4088. $invoicePriceStaffYear += $v ['invoicePrice'];
  4089. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  4090. $accountPriceStaffYear += $v ['accountPrice'];
  4091. $flag = false;
  4092. break;
  4093. }
  4094. }
  4095. if ($flag) {
  4096. $htmlA .= '<td class="taR">-</td>';
  4097. $htmlB .= '<td class="taR">-</td>';
  4098. $htmlC .= '<td class="taR"><b>-</b></td>';
  4099. }
  4100. }
  4101. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  4102. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  4103. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  4104. $htmlA .= '</tr>';
  4105. $htmlB .= '</tr>';
  4106. $htmlC .= '</tr>';
  4107. $html .= $htmlA . $htmlB . $htmlC;
  4108. }
  4109. $htmlA = $htmlB = $htmlC = "";
  4110. $htmlA = '<tr><th rowspan="3">月合计</th><th class="taC">开票</th>';
  4111. $htmlB = '<tr><th class="taC">收款</th>';
  4112. $htmlC = '<tr><th class="taC">入账</th>';
  4113. $invoicePriceStaffYear = 0;
  4114. $receivablesPriceStaffYear = 0;
  4115. $accountPriceStaffYear = 0;
  4116. for($month = 1; $month <= 12; $month ++) {
  4117. $flag = true;
  4118. foreach ( $isCategory ['statisticsMonth'] as $k => $v ) {
  4119. if ($month == $v ['month']) {
  4120. $htmlA .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>';
  4121. $htmlB .= '<td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>';
  4122. $htmlC .= '<td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>';
  4123. $invoicePriceStaffYear += $v ['invoicePrice'];
  4124. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  4125. $accountPriceStaffYear += $v ['accountPrice'];
  4126. $flag = false;
  4127. break;
  4128. }
  4129. }
  4130. if ($flag) {
  4131. $htmlA .= '<td class="taR">-</td>';
  4132. $htmlB .= '<td class="taR">-</td>';
  4133. $htmlC .= '<td class="taR"><b>-</b></td>';
  4134. }
  4135. }
  4136. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  4137. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  4138. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  4139. $htmlA .= '</tr>';
  4140. $htmlB .= '</tr>';
  4141. $htmlC .= '</tr>';
  4142. $html .= $htmlA . $htmlB . $htmlC;
  4143. $this->data ['html'] = $html;
  4144. $this->data ['cidKey'] = $cidKey;
  4145. $this->data ['slist'] = $list;
  4146. $this->data ['isList'] = $toteList;
  4147. $this->data ['year'] = $year;
  4148. $this->data ['memu'] = "invoice";
  4149. $this->data ['staff'] = $this->staff;
  4150. $this->data ['receiptMemu'] = 'invoiceAggregate';
  4151. $this->render ( "/admin/invoiceAggregateCategory", $this->data );
  4152. }
  4153. /**
  4154. * 办事处汇总信息
  4155. */
  4156. function invoiceAggregateCategoryDetail() {
  4157. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  4158. Doo::loadClass ( 'XDeode' );
  4159. $XDeode = new XDeode ( 5 );
  4160. Doo::loadModel ( 'invoiceStatistics' );
  4161. $invoiceStatistics = new invoiceStatistics ();
  4162. Doo::loadModel ( 'L_category' );
  4163. $category = new L_category ();
  4164. Doo::loadModel ( 'invoice' );
  4165. $invoice = new invoice ();
  4166. Doo::loadModel ( 'staff' );
  4167. $staff = new staff ();
  4168. Doo::loadModel ( "invoiceCategoryManage" );
  4169. $invoiceCategoryManage = new invoiceCategoryManage ();
  4170. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4171. $cidList = array ();
  4172. foreach ( $imcStaff as $key => $value ) {
  4173. array_push ( $cidList, $value ['cid'] );
  4174. if (empty ( $cidKey ))
  4175. $cidKey = $XDeode->encode ( $value ['cid'] );
  4176. }
  4177. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  4178. $cid = $XDeode->decode ( $cidKey );
  4179. $month = date ( "m", strtotime ( "-1 month" ) );
  4180. $YearMonth = date ( "Y-m", strtotime ( "-1 month" ) );
  4181. $redis = new Redis ();
  4182. $redis->connect ( '127.0.0.1', '6379' );
  4183. $redisKey = ''; // date('Y-m-d').'_iacd_'.$cid;
  4184. $redisValue = ''; // $redis->lrange($redisKey, 0, -1);
  4185. if (empty ( $redisValue )) {
  4186. $isMC = $invoiceStatistics->getInvoiceStatistiscsMothByCategory ( $cid );
  4187. $schedule = $invoice->getInvoiceScheduleByCid ( $cid );
  4188. // 获得办事处人员下的汇总
  4189. $slist = $staff->getStaffByCid ( $cid );
  4190. $ismsbMonth = $invoiceStatistics->getISMSByCategoryByMonth ( $cid, $YearMonth ); // 上一个月的汇总
  4191. $ismsb = $invoiceStatistics->getISMSByCategory ( $cid ); // 当月汇总
  4192. $ISAS = $invoiceStatistics->getISASByCategory ( $cid ); // 全部汇总
  4193. $scheduleStaff = $invoice->getInvoiceScheduleByCidGroupSid ( $cid ); // 完成度
  4194. foreach ( $slist as $key => $value ) {
  4195. $slist [$key] ['invoicePrice'] = 0;
  4196. $slist [$key] ['receivablesPrice'] = 0;
  4197. $slist [$key] ['accountPrice'] = 0;
  4198. $slist [$key] ['invoiceAllPrice'] = 0;
  4199. $slist [$key] ['receivablesAllPrice'] = 0;
  4200. $slist [$key] ['accountAllPrice'] = 0;
  4201. $slist [$key] ['schedule'] = 0;
  4202. $slist [$key] ['invoiceMonthPrice'] = 0;
  4203. $slist [$key] ['receivablesMonthPrice'] = 0;
  4204. $slist [$key] ['accountMonthPrice'] = 0;
  4205. foreach ( $ismsbMonth as $y => $l ) {
  4206. if ($value ['sid'] == $l ['staff']) {
  4207. $slist [$key] ['invoiceMonthPrice'] = $l ['invoicePrice'];
  4208. $slist [$key] ['receivablesMonthPrice'] = $l ['receivablesPrice'];
  4209. $slist [$key] ['accountMonthPrice'] = $l ['accountPrice'];
  4210. }
  4211. }
  4212. foreach ( $ismsb as $k => $v ) {
  4213. if ($value ['sid'] == $v ['staff']) {
  4214. $slist [$key] ['invoicePrice'] = $v ['invoicePrice'];
  4215. $slist [$key] ['receivablesPrice'] = $v ['receivablesPrice'];
  4216. $slist [$key] ['accountPrice'] = $v ['accountPrice'];
  4217. }
  4218. }
  4219. foreach ( $ISAS as $e => $a ) {
  4220. if ($value ['sid'] == $a ['staff']) {
  4221. $slist [$key] ['invoiceAllPrice'] = $a ['invoicePrice'];
  4222. $slist [$key] ['receivablesAllPrice'] = $a ['receivablesPrice'];
  4223. $slist [$key] ['accountAllPrice'] = $a ['accountPrice'];
  4224. }
  4225. }
  4226. if (isset ( $scheduleStaff [$value ['sid']] ))
  4227. $slist [$key] ['schedule'] = $scheduleStaff [$value ['sid']];
  4228. }
  4229. $this->data ['cidKey'] = $cidKey;
  4230. $schedule = ( int ) ($schedule * 100);
  4231. $this->data ['slist'] = $slist;
  4232. $this->data ['isMC'] = $isMC;
  4233. $this->data ['schedule'] = $schedule;
  4234. $slist = json_encode ( $slist );
  4235. $isMC = json_encode ( $isMC );
  4236. $schedule = json_encode ( $schedule );
  4237. $redis->lpush ( $redisKey, $slist );
  4238. $redis->lpush ( $redisKey, $isMC );
  4239. $redis->lpush ( $redisKey, $schedule );
  4240. } else {
  4241. $this->data ['cidKey'] = $cidKey;
  4242. $this->data ['slist'] = json_decode ( $redisValue [2], true );
  4243. $this->data ['isMC'] = json_decode ( $redisValue [1], true );
  4244. $this->data ['schedule'] = json_decode ( $redisValue [0], true );
  4245. }
  4246. $this->data ['month'] = $month;
  4247. $this->data ['categoryList'] = $categoryList;
  4248. $this->data ['memu'] = "invoice";
  4249. $this->data ['staff'] = $this->staff;
  4250. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4251. $this->render ( "/admin/invoiceAggregateCategoryDetail", $this->data );
  4252. }
  4253. /**
  4254. * 办事处人员汇总详情
  4255. */
  4256. function invoiceAggregateStaffDetail() {
  4257. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  4258. // $sidKey = isset ( $this->params ['sidKey'] ) ? $this->params ['sidKey'] : '';
  4259. Doo::loadClass ( 'XDeode' );
  4260. $XDeode = new XDeode ( 5 );
  4261. Doo::loadModel ( 'invoice' );
  4262. $invoice = new invoice ();
  4263. Doo::loadModel ( 'staff' );
  4264. $staff = new staff ();
  4265. Doo::loadModel ( "invoiceCategoryManage" );
  4266. $invoiceCategoryManage = new invoiceCategoryManage ();
  4267. $sid = $XDeode->decode ( $sidKey );
  4268. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4269. $cidList = array ();
  4270. foreach ( $imcStaff as $key => $value ) {
  4271. array_push ( $cidList, $value ['cid'] );
  4272. if (empty ( $cidKey ))
  4273. $cidKey = $XDeode->encode ( $value ['cid'] );
  4274. }
  4275. $cidString = implode ( ',', $cidList );
  4276. $staffList = $staff->getStaffInCid ( $cidString );
  4277. $staffDetail = $staff->getStaffBySid ( $sid );
  4278. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4279. $page_size = 18;
  4280. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4281. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4282. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  4283. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  4284. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  4285. $dateArr = explode ( ':', $date );
  4286. $D1 = '';
  4287. $D2 = '';
  4288. if (! empty ( $date )) {
  4289. $D1 = $dateArr [0] . " 00:00:00 ";
  4290. if (isset ( $dateArr [1] ))
  4291. $D2 = $dateArr [1] . " 23:59:59 ";
  4292. else
  4293. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4294. // $D2 = $dateArr [1];
  4295. }
  4296. $con = ' status=2 ';
  4297. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4298. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4299. if ($status == 'UNRECORD')
  4300. $con .= ' and printStatus=1 and untreadStatus=0';
  4301. elseif ($status == 'RECORD')
  4302. $con .= ' and printStatus=1 and untreadStatus=3';
  4303. elseif ($status == 'BOUNCED')
  4304. $con .= ' and untreadStatus=2';
  4305. elseif ($status == 'PARTRECORD')
  4306. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  4307. elseif ($status == 'All') {
  4308. $con .= ' and ( untreadStatus=2 or untreadStatus=0 or untreadStatus=3 )';
  4309. }
  4310. $con .= ' and sid=' . $sid;
  4311. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  4312. if (! empty ( $MebSea )) {
  4313. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  4314. }
  4315. $pageinfo ['page'] = array (
  4316. 'previous' => ''
  4317. );
  4318. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateStaffDetail", $get, "" );
  4319. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4320. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  4321. $this->data ['staffDetail'] = $staffDetail;
  4322. $this->data ['staffList'] = $staffList;
  4323. $this->data ['MebSeaEn'] = $MebSea;
  4324. $this->data ['MebSea'] = urlencode ( $MebSea );
  4325. $this->data ['date'] = $date;
  4326. $this->data ['page'] = $pageinfo;
  4327. $this->data ['get'] = $get;
  4328. $this->data ['list'] = $list;
  4329. $this->data ['status'] = $status;
  4330. $this->data ['sidKey'] = $sidKey;
  4331. $this->data ['memu'] = "invoice";
  4332. $this->data ['staff'] = $this->staff;
  4333. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4334. $this->render ( "/admin/invoiceAggregateStaffDetail", $this->data );
  4335. }
  4336. /**
  4337. * 办事处人员汇总收款情
  4338. */
  4339. function invoiceAggregateStaffReceivablesDetail() {
  4340. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  4341. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  4342. Doo::loadModel ( 'invoiceReceivables' );
  4343. $invoiceReceivables = new invoiceReceivables ();
  4344. Doo::loadModel ( 'staff' );
  4345. $staff = new staff ();
  4346. Doo::loadModel ( "invoiceCategoryManage" );
  4347. $invoiceCategoryManage = new invoiceCategoryManage ();
  4348. Doo::loadClass ( 'XDeode' );
  4349. $XDeode = new XDeode ( 5 );
  4350. $sid = $XDeode->decode ( $sidKey );
  4351. $staffDetail = $staff->getStaffBySid ( $sid );
  4352. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4353. $cidList = array ();
  4354. foreach ( $imcStaff as $key => $value ) {
  4355. array_push ( $cidList, $value ['cid'] );
  4356. if (empty ( $cidKey ))
  4357. $cidKey = $XDeode->encode ( $value ['cid'] );
  4358. }
  4359. $cidString = implode ( ',', $cidList );
  4360. $staffList = $staff->getStaffInCid ( $cidString );
  4361. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4362. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  4363. $page_size = 10;
  4364. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4365. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4366. if ($timeType == "BINDOTP") {
  4367. $status = 'Credited';
  4368. }
  4369. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  4370. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  4371. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  4372. $dateArr = explode ( ':', $date );
  4373. $D1 = '';
  4374. $D2 = '';
  4375. if (! empty ( $date )) {
  4376. $D1 = $dateArr [0] . " 00:00:00 ";
  4377. if (isset ( $dateArr [1] ))
  4378. $D2 = $dateArr [1] . " 23:59:59 ";
  4379. else
  4380. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4381. }
  4382. $con = ' a.receivablesStaff like "%' . $staffDetail ['username'] . '%" ';
  4383. $descField = 'a.bindDate';
  4384. if ($timeType == 'CREATE')
  4385. $descField = 'a.date';
  4386. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4387. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4388. elseif (! empty ( $D1 ) && empty ( $D2 ))
  4389. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  4390. if ($status == 'Unclaimed')
  4391. $con .= ' and a.bindStatus=0';
  4392. elseif ($status == 'Credited')
  4393. $con .= ' and a.bindStatus=1';
  4394. elseif ($status == 'Claim')
  4395. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  4396. elseif ($status == 'BBN')
  4397. $con .= ' and a.bindPrice>a.receivablesPrice';
  4398. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  4399. if (! empty ( $MebSea )) {
  4400. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" )';
  4401. }
  4402. $pageinfo ['page'] = array (
  4403. 'previous' => ''
  4404. );
  4405. // $sql = 'select group_concat(b.invoiceSerial) as invoiceSerial ,group_concat(b.iid) as invoiceId
  4406. // from CLD_invoiceReceivables as a left join CLD_invoice as b on
  4407. // find_in_set(b.iid,a.iidExtend) or a.iid=b.iid
  4408. // where ' . $con . ' group by a.irid ';
  4409. $pageinfo =$this->get_page ( "CLD_invoiceReceivables as a", $con, $page, $page_size, "invoiceAggregateStaffReceivablesDetail", $get, "" );
  4410. //$pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceAggregateStaffReceivablesDetail", $get, "" );
  4411. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4412. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', $descField);
  4413. foreach ( $list as $key => $value ) {
  4414. $list [$key] ['category'] = '';
  4415. if ($value ['receivablesCategory'] != 'PUBLIC') {
  4416. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  4417. $list [$key] ['category'] = $receivablesCategory [1];
  4418. }
  4419. }
  4420. // print_r($list);
  4421. $this->data ['staffDetail'] = $staffDetail;
  4422. $this->data ['sidKey'] = $sidKey;
  4423. $this->data ['staffList'] = $staffList;
  4424. $this->data ['timeType'] = $timeType;
  4425. $this->data ['MebSeaEn'] = $MebSea;
  4426. $this->data ['MebSea'] = urlencode ( $MebSea );
  4427. $this->data ['date'] = $date;
  4428. $this->data ['page'] = $pageinfo;
  4429. $this->data ['get'] = $get;
  4430. $this->data ['list'] = $list;
  4431. $this->data ['status'] = $status;
  4432. $this->data ['memu'] = "invoice";
  4433. $this->data ['staff'] = $this->staff;
  4434. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4435. $this->render ( "/admin/invoiceAggregateStaffReceivablesDetail", $this->data );
  4436. }
  4437. function invoiceAchieve() {
  4438. Doo::loadModel ( 'invoice' );
  4439. $invoice = new invoice ();
  4440. Doo::loadClass ( 'XDeode' );
  4441. $XDeode = new XDeode ( 5 );
  4442. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4443. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4444. $page_size = 18;
  4445. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4446. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4447. $get = "/" . $date;
  4448. $con = '';
  4449. if ($date == 'MONTHO')
  4450. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4451. elseif ($date == 'MONTHT')
  4452. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4453. elseif ($date == 'MONTHY')
  4454. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4455. if (! empty ( $MebSea )) {
  4456. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4457. $get .= "/" . $MebSea;
  4458. }
  4459. $pageinfo ['page'] = array (
  4460. 'previous' => ''
  4461. );
  4462. $sql = 'status=2 and printStatus=1 and irid!="" and ( untreadStatus=3 or untreadStatus=0 ) and sid=' . $sid . $con;
  4463. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceAchieve", $get, "" );
  4464. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4465. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  4466. // print_r($pageinfo);
  4467. $this->data ['MebSeaEn'] = $MebSea;
  4468. $this->data ['MebSea'] = urlencode ( $MebSea );
  4469. $this->data ['get'] = $get;
  4470. $this->data ['page'] = $pageinfo;
  4471. $this->data ['list'] = $list;
  4472. $this->data ['date'] = $date;
  4473. $this->data ['memu'] = "invoice";
  4474. $this->data ['staff'] = $this->staff;
  4475. $this->data ['receiptMemu'] = 'invoice';
  4476. $this->render ( "/admin/invoiceAchieve", $this->data );
  4477. }
  4478. /**
  4479. */
  4480. function invoiceMyUnAccountAchieve() {
  4481. Doo::loadModel ( 'invoice' );
  4482. $invoice = new invoice ();
  4483. Doo::loadClass ( 'XDeode' );
  4484. $XDeode = new XDeode ( 5 );
  4485. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4486. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4487. $page_size = 18;
  4488. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4489. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4490. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4491. $dateArr = explode ( ':', $date );
  4492. $D1 = '';
  4493. $D2 = '';
  4494. if (! empty ( $date )) {
  4495. $D1 = $dateArr [0];
  4496. $D2 = $dateArr [1];
  4497. }
  4498. $con = '';
  4499. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4500. $con = ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4501. if (! empty ( $MebSea )) {
  4502. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4503. }
  4504. $pageinfo ['page'] = array (
  4505. 'previous' => ''
  4506. );
  4507. // and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  4508. $sql = " status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid= " . $sid . $con;
  4509. $action = "invoiceMyUnAccountAchieve";
  4510. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  4511. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4512. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 'desc', 'printTime' );
  4513. Doo::loadModel ( 'express' );
  4514. $express = new express ();
  4515. $expressList = $express->getExpressByAll ();
  4516. $this->data ['expressList'] = $expressList;
  4517. // print_r($list);
  4518. $this->data ['MebSeaEn'] = $MebSea;
  4519. $this->data ['get'] = $get;
  4520. $this->data ['page'] = $pageinfo;
  4521. $this->data ['date'] = $date;
  4522. $this->data ['list'] = $list;
  4523. $this->data ['memu'] = "invoice";
  4524. $this->data ['staff'] = $this->staff;
  4525. $this->data ['receiptMemu'] = 'invoice';
  4526. $this->render ( "/admin/invoiceMyUnAccountAchieve", $this->data );
  4527. }
  4528. function invoiceReceivablesAchieve() {
  4529. Doo::loadModel ( 'invoiceReceivables' );
  4530. $invoiceReceivables = new invoiceReceivables ();
  4531. Doo::loadClass ( 'XDeode' );
  4532. $XDeode = new XDeode ( 5 );
  4533. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4534. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  4535. $page_size = 12;
  4536. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4537. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4538. $get = "/" . $date;
  4539. $con = '';
  4540. if ($date == 'MONTHO')
  4541. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4542. elseif ($date == 'MONTHT')
  4543. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4544. elseif ($date == 'MONTHY')
  4545. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4546. if (! empty ( $MebSea )) {
  4547. $con .= ' and ( receivablesMessage like "%' . $MebSea . '%" or receivablesPrice like "%' . $MebSea . '%" )';
  4548. $get .= "/" . $MebSea;
  4549. }
  4550. $pageinfo ['page'] = array (
  4551. 'previous' => ''
  4552. );
  4553. $sql = " bindStatus=1 and receivablesStaff like '" . $sid . "-%' " . $con;
  4554. $pageinfo = $this->get_page ( "CLD_invoiceReceivables", $sql, $page, $page_size, "invoiceReceivablesAchieve", $get, "" );
  4555. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4556. $list = $invoiceReceivables->getReceivablesByUntreadStatusPage ( $limit, $sql );
  4557. // print_r($pageinfo);
  4558. $this->data ['MebSeaEn'] = $MebSea;
  4559. $this->data ['MebSea'] = urlencode ( $MebSea );
  4560. $this->data ['get'] = $get;
  4561. $this->data ['page'] = $pageinfo;
  4562. $this->data ['list'] = $list;
  4563. $this->data ['date'] = $date;
  4564. $this->data ['memu'] = "invoice";
  4565. $this->data ['staff'] = $this->staff;
  4566. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  4567. $this->render ( "/admin/invoiceReceivablesAchieve", $this->data );
  4568. }
  4569. /**
  4570. * 收款解绑
  4571. */
  4572. function invoiceUnBundLing() {
  4573. $unBundKey = $this->get_args ( 'unBundKey' ) ? $this->get_args ( 'unBundKey' ) : '';
  4574. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  4575. Doo::loadModel ( 'invoice' );
  4576. $invoice = new invoice ();
  4577. Doo::loadModel ( 'invoiceReceivables' );
  4578. $invoiceReceivables = new invoiceReceivables ();
  4579. Doo::loadModel ( 'invoiceOperationLog' );
  4580. $invoiceOperationLog = new invoiceOperationLog ();
  4581. Doo::loadModel ( 'invoiceROLog' );
  4582. $invoiceROLog = new invoiceROLog ();
  4583. Doo::loadModel ( 'invoiceStatistics' );
  4584. Doo::loadClass ( 'XDeode' );
  4585. $XDeode = new XDeode ( 5 );
  4586. if (empty ( $iidKey ) || empty ( $unBundKey ))
  4587. die ( 'illegal request' );
  4588. $iid = $XDeode->decode ( $iidKey );
  4589. $irid = $invoice->authcode ( $unBundKey );
  4590. if ((! empty ( $irid ) && ! is_numeric ( $irid )) || (! empty ( $iid ) && ! is_numeric ( $iid )))
  4591. die ( 'illegal request' );
  4592. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4593. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  4594. if (empty ( $irDetails ) || empty ( $invoiceDetails ) || (empty ( $irDetails ['iid'] ) && empty ( $irDetails ['iidExtend'] )) || $invoiceDetails ['untreadStatus'] == 2)
  4595. die ( 'illegal request' );
  4596. // 收款
  4597. $item = array (
  4598. 'irid' => $irDetails ['irid'],
  4599. 'bindPrice' => $irDetails ['bindPrice'] - $invoiceDetails ['invoicePrice'],
  4600. 'bindStatus' => 0
  4601. );
  4602. if ($irDetails ['iid'] == $iid)
  4603. $item += array (
  4604. 'iid' => 0
  4605. );
  4606. else {
  4607. $iidExtend = explode ( ',', $irDetails ['iidExtend'] );
  4608. foreach ( $iidExtend as $key => $value ) {
  4609. if ($value == $iid)
  4610. unset ( $iidExtend [$key] );
  4611. }
  4612. $iidExtend = implode ( ',', $iidExtend );
  4613. $item += array (
  4614. 'iidExtend' => $iidExtend
  4615. );
  4616. }
  4617. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4618. // 收款操作日志
  4619. $item = array (
  4620. 'operation' => $this->staff [0] ['username'] . " 解绑 " . $irDetails ['receivablesSerial'],
  4621. 'date' => date ( "Y-m-d" ),
  4622. 'status' => 3,
  4623. 'img' => $this->staff [0] ['avatar'],
  4624. 'username' => $this->staff [0] ['username'],
  4625. 'uid' => $this->staff [0] ['sid'],
  4626. 'category' => $this->staff [0] ['category'],
  4627. 'irid' => $irid
  4628. );
  4629. $invoiceROLog->setInvoiceROLog ( $item );
  4630. // 扣除入账统计金额
  4631. $invoiceStatistics = new invoiceStatistics ();
  4632. $item = array (
  4633. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  4634. 'priceClass' => 3,
  4635. 'cid' => $invoiceDetails ['cid'],
  4636. 'staff' => $invoiceDetails ['sid'],
  4637. 'accountPrice' => - $irDetails ['receivablesPrice']
  4638. );
  4639. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4640. // 扣除收款统计金额
  4641. $invoiceStatistics = new invoiceStatistics ();
  4642. $item = array (
  4643. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  4644. 'priceClass' => 2,
  4645. 'cid' => $invoiceDetails ['cid'],
  4646. 'staff' => $invoiceDetails ['sid'],
  4647. 'irid' => $irDetails ['irid'],
  4648. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  4649. );
  4650. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4651. // 发票解绑去收款ID
  4652. $iridString = $invoiceDetails ['irid'];
  4653. if (! empty ( $invoiceDetails ['irid'] )) {
  4654. $list = explode ( ',', $invoiceDetails ['irid'] );
  4655. foreach ( $list as $key => $value ) {
  4656. if ($value == $irDetails ['irid']) {
  4657. unset ( $list [$key] );
  4658. break;
  4659. }
  4660. }
  4661. $iridString = implode ( ",", $list );
  4662. }
  4663. $item = array (
  4664. 'iid' => $invoiceDetails ['iid'],
  4665. 'irid' => $iridString,
  4666. 'updateTime' => date ( "Y-m-d H:i:s" )
  4667. );
  4668. if ($invoiceDetails ['untreadStatus'] == 3)
  4669. $item += array (
  4670. 'untreadStatus' => 0
  4671. );
  4672. $invoice->setInvoiceByCondition ( $item );
  4673. $item = array (
  4674. 'date' => date ( "Y-m-d H:i:s" ),
  4675. 'operation' => '解绑 收款 ' . $irDetails ['receivablesSerial'],
  4676. 'status' => 11,
  4677. 'img' => $this->staff [0] ['avatar'],
  4678. 'username' => $this->staff [0] ['username'],
  4679. 'uid' => $this->staff [0] ['sid'],
  4680. 'category' => $this->staff [0] ['category'],
  4681. 'iid' => $invoiceDetails ['iid']
  4682. );
  4683. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  4684. // 公司流水-解绑时删除流水
  4685. Doo::loadModel ( 'wasteBook' );
  4686. $wasteBook = new wasteBook ();
  4687. // $wasteBook->delete ( array (
  4688. // 'where' => 'dataID=' . $irDetails ['irid'] . ' and accountType=7',
  4689. // 'limit' => 1
  4690. // ) );
  4691. // 银行
  4692. /*
  4693. * $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); }
  4694. */
  4695. return "/invoiceReceivablesAS";
  4696. }
  4697. /**
  4698. * 或者该收款下的所以发票
  4699. */
  4700. function ajaxGetInvoiceReceivablesByInvoice() {
  4701. $irid = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : '';
  4702. Doo::loadModel ( 'invoice' );
  4703. $invoice = new invoice ();
  4704. Doo::loadModel ( 'invoiceReceivables' );
  4705. $invoiceReceivables = new invoiceReceivables ();
  4706. $irid = $invoice->authcode ( $irid );
  4707. if (! empty ( $irid ) && ! is_numeric ( $irid ))
  4708. die ( 'illegal request' );
  4709. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4710. $iidString = $irDetails ['iid'];
  4711. $iidExtend = array_filter ( explode ( ',', $irDetails ['iidExtend'] ) );
  4712. if (! empty ( $irDetails ['iidExtend'] ))
  4713. $iidString .= ',' . implode ( ',', $iidExtend );
  4714. $invoiceList = $invoice->getInvoiceInIid ( $iidString, 'iid,invoiceSerial,invoicePrice,invoiceTitle,invoiceCompany,invoiceElement' );
  4715. $html = "";
  4716. foreach ( $invoiceList as $key => $value ) {
  4717. $title = $value ['invoiceTitle'];
  4718. if (! empty ( $value ['invoiceCompany'] ))
  4719. $title = $value ['invoiceCompany'];
  4720. $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>';
  4721. }
  4722. echo json_encode ( array (
  4723. 'status' => 1,
  4724. 'html' => $html
  4725. ) );
  4726. }
  4727. /**
  4728. * 发票管理
  4729. */
  4730. function invoiceAS() {
  4731. Doo::loadModel ( 'invoice' );
  4732. $invoice = new invoice ();
  4733. Doo::loadModel ( 'invoiceReceivables' );
  4734. $invoiceReceivables = new invoiceReceivables ();
  4735. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4736. $page_size = 18;
  4737. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4738. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4739. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4740. $dateArr = explode ( ':', $date );
  4741. $D1 = '';
  4742. $D2 = '';
  4743. if (! empty ( $date )) {
  4744. $D1 = $dateArr [0] . " 00:00:00 ";
  4745. if (isset ( $dateArr [1] ))
  4746. $D2 = $dateArr [1] . " 23:59:59 ";
  4747. else
  4748. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4749. // $D2 = $dateArr [1];
  4750. }
  4751. $con = ' status=2 ';
  4752. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4753. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4754. if ($status == 'UNRECORD')
  4755. $con .= ' and printStatus=1 and untreadStatus=0';
  4756. elseif ($status == 'RECORD')
  4757. $con .= ' and printStatus=1 and untreadStatus=3';
  4758. elseif ($status == 'BOUNCED')
  4759. $con .= ' and untreadStatus=2';
  4760. elseif ($status == 'PARTRECORD')
  4761. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  4762. elseif ($status == 'All') {
  4763. $con .= ' and ( untreadStatus=2 or untreadStatus=1 or untreadStatus=0 or untreadStatus=3 )';
  4764. }
  4765. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4766. if (! empty ( $MebSea )) {
  4767. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  4768. }
  4769. $pageinfo ['page'] = array (
  4770. 'previous' => ''
  4771. );
  4772. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAS", $get, "" );
  4773. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4774. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  4775. $this->data ['MebSeaEn'] = $MebSea;
  4776. $this->data ['MebSea'] = urlencode ( $MebSea );
  4777. $this->data ['date'] = $date;
  4778. $this->data ['page'] = $pageinfo;
  4779. $this->data ['get'] = $get;
  4780. $this->data ['list'] = $list;
  4781. $this->data ['status'] = $status;
  4782. $this->data ['memu'] = "invoice";
  4783. $this->data ['staff'] = $this->staff;
  4784. $this->data ['receiptMemu'] = 'invoiceReceivables';
  4785. $this->render ( "/admin/invoiceAS", $this->data );
  4786. }
  4787. /**
  4788. * 收款管理
  4789. */
  4790. function invoiceReceivablesAS() {
  4791. Doo::loadModel ( 'invoiceReceivables' );
  4792. $invoiceReceivables = new invoiceReceivables ();
  4793. Doo::loadModel ( 'L_category' );
  4794. $lCategory = new L_category ();
  4795. $category = $lCategory->getCategory ();
  4796. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4797. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  4798. $page_size = 10;
  4799. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4800. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4801. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4802. $dateArr = explode ( ':', $date );
  4803. $D1 = '';
  4804. $D2 = '';
  4805. if (! empty ( $date )) {
  4806. $D1 = $dateArr [0]; // ." 00:00:00 ";
  4807. if (isset ( $dateArr [1] ))
  4808. $D2 = $dateArr [1]; // ." 23:59:59 ";
  4809. else
  4810. $D2 = $dateArr [0]; // ." 23:59:59 ";//date ( "Y-m-d" );
  4811. }
  4812. $descField = 'a.receivablesDate';
  4813. if ($timeType == 'CREATE')
  4814. $descField = 'a.date';
  4815. $con = ' 1 ';
  4816. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4817. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4818. elseif (! empty ( $D1 ) && empty ( $D2 ))
  4819. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  4820. if ($status == 'Unclaimed')
  4821. $con .= ' and a.bindStatus=0';
  4822. elseif ($status == 'Credited')
  4823. $con .= ' and a.bindStatus=1';
  4824. elseif ($status == 'Claim')
  4825. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  4826. elseif ($status == 'BBN')
  4827. $con .= ' and a.bankBatchNumber!=""';
  4828. elseif ($status == 'REFUND')
  4829. $con .= ' and ( (a.bindStatus=0 and a.refundLog!="" ) or a.bindStatus=2)';
  4830. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4831. if (! empty ( $MebSea )) {
  4832. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" or a.receivablesSerial like "%' . $MebSea . '%" )';
  4833. }
  4834. $pageinfo ['page'] = array (
  4835. 'previous' => ''
  4836. );
  4837. // if(!empty($con)){
  4838. // $con=' where 1 '.$con;
  4839. // }
  4840. // $sql = 'select a.iid from CLD_invoiceReceivables as a
  4841. // ' . $con ;
  4842. $pageinfo =$this->get_page ( "CLD_invoiceReceivables as a", $con, $page, $page_size, "invoiceReceivablesAS", $get, "" );
  4843. //echo $sql;
  4844. //$pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceReceivablesAS", $get, "" );
  4845. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4846. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', $descField );
  4847. foreach ( $list as $key => $value ) {
  4848. $list [$key] ['category'] = '';
  4849. if ($value ['receivablesCategory'] != 'PUBLIC') {
  4850. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  4851. $list [$key] ['category'] = $receivablesCategory [1];
  4852. }
  4853. }
  4854. // print_r($list);
  4855. $this->data ['category'] = $category;
  4856. $this->data ['timeType'] = $timeType;
  4857. $this->data ['MebSeaEn'] = $MebSea;
  4858. $this->data ['MebSea'] = urlencode ( $MebSea );
  4859. $this->data ['date'] = $date;
  4860. $this->data ['page'] = $pageinfo;
  4861. $this->data ['get'] = $get;
  4862. $this->data ['list'] = $list;
  4863. $this->data ['status'] = $status;
  4864. $this->data ['memu'] = "invoice";
  4865. $this->data ['staff'] = $this->staff;
  4866. $this->data ['receiptMemu'] = 'invoiceReceivables';
  4867. $this->render ( "/admin/invoiceReceivablesAS", $this->data );
  4868. }
  4869. /**
  4870. * 删除一条收款
  4871. */
  4872. function delInvoiceReceivables() {
  4873. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  4874. if (empty ( $iridKey ))
  4875. die ( 'illegal request' );
  4876. Doo::loadClass ( 'XDeode' );
  4877. $XDeode = new XDeode ( 5 );
  4878. $irid = $XDeode->decode ( $iridKey );
  4879. Doo::loadModel ( 'invoiceReceivables' );
  4880. $invoiceReceivables = new invoiceReceivables ();
  4881. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4882. if (empty ( $detail ))
  4883. die ( 'illegal request' );
  4884. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  4885. // 扣除收款汇总信息 汇总
  4886. Doo::loadModel ( 'invoiceStatistics' );
  4887. $invoiceStatistics = new invoiceStatistics ();
  4888. $item = array (
  4889. 'date' => $detail ['receivablesDate'],
  4890. 'priceClass' => 2,
  4891. 'irid' => $detail ['irid'],
  4892. 'receivablesPrice' => - $detail ['receivablesPrice']
  4893. );
  4894. if ($detail ['receivablesCategory'] != 'PUBLIC') {
  4895. $receivablesCategory = explode ( ":", $detail ['receivablesCategory'] );
  4896. $item += array (
  4897. 'cid' => $receivablesCategory [0]
  4898. );
  4899. }
  4900. if ($detail ['receivablesStaff'] != 'PUBLIC') {
  4901. $receivablesStaff = explode ( "-", $detail ['receivablesStaff'] );
  4902. $item += array (
  4903. 'staff' => $receivablesStaff [0]
  4904. );
  4905. }
  4906. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4907. return '/invoiceReceivablesAS';
  4908. }
  4909. /**
  4910. * 添加退款信息
  4911. */
  4912. function setInvoiceReceivablesRefund() {
  4913. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  4914. $refundType = $this->get_args ( 'refundType' ) && is_numeric ( $this->get_args ( 'refundType' ) ) ? $this->get_args ( 'refundType' ) : '0';
  4915. $refundCompany = $this->get_args ( 'refundCompany' ) ? $this->get_args ( 'refundCompany' ) : "";
  4916. $refundNumber = $this->get_args ( 'refundNumber' ) ? $this->get_args ( 'refundNumber' ) : "";
  4917. $refundPrice = $this->get_args ( 'refundPrice' ) ? $this->get_args ( 'refundPrice' ) : "";
  4918. $refundRemarks = $this->get_args ( 'refundRemarks' ) ? $this->get_args ( 'refundRemarks' ) : "";
  4919. if ($refundPrice < 0)
  4920. die ( 'illegal request' );
  4921. if (! empty ( $iridKey ) && ! empty ( $refundCompany ) && ! empty ( $refundNumber ) && ! empty ( $refundPrice )) {
  4922. Doo::loadModel ( 'invoiceReceivables' );
  4923. $invoiceReceivables = new invoiceReceivables ();
  4924. Doo::loadModel ( 'invoiceRefund' );
  4925. $invoiceRefund = new invoiceRefund ();
  4926. $irid = $invoiceReceivables->authcode ( $iridKey );
  4927. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4928. if ($irDetail ['receivablesPrice'] < $refundPrice)
  4929. die ( 'illegal request' );
  4930. $invoiceReceivables = new invoiceReceivables ();
  4931. $refundLog = $this->staff [0] ['username'] . ' 退款 <b class="colRed">¥' . $refundPrice . '</b>
  4932. <br/><a href="#refunded" onclick="getRefundByDetail(\'' . $iridKey . '\')" data-toggle="modal">退款信息</a> <br/>' . date ( "Y-m-d H:i:s" ) . '
  4933. ';
  4934. $item = array (
  4935. 'irid' => $irid,
  4936. 'refundCompany' => $refundCompany,
  4937. 'refundNumber' => $refundNumber,
  4938. 'refundPrice' => $refundPrice,
  4939. 'refundRemarks' => $refundRemarks,
  4940. 'refundLog' => $refundLog
  4941. );
  4942. if ($refundType == 1) {
  4943. $item += array (
  4944. 'refundType' => $refundType,
  4945. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice,
  4946. 'bindStatus' => 2
  4947. );
  4948. } elseif ($refundType == 0 && $irDetail ['receivablesPrice'] <= $refundPrice) {
  4949. $item += array (
  4950. 'refundType' => 1,
  4951. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice,
  4952. 'bindStatus' => 2
  4953. );
  4954. } else {
  4955. $item += array (
  4956. 'refundType' => $refundType,
  4957. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice
  4958. );
  4959. }
  4960. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4961. // 添加退款记录
  4962. $item = array (
  4963. 'irid' => $irid,
  4964. 'refundType' => $refundType,
  4965. 'refundCompany' => $refundCompany,
  4966. 'refundNumber' => $refundNumber,
  4967. 'refundPrice' => $refundPrice,
  4968. 'refundLog' => $refundLog,
  4969. 'refundRemarks' => $refundRemarks,
  4970. 'date' => date ( "Y-m-d H:i:s" )
  4971. );
  4972. $invoiceRefund->addInvoiceRefund ( $item );
  4973. // 扣除收款汇总信息 汇总
  4974. Doo::loadModel ( 'invoiceStatistics' );
  4975. $invoiceStatistics = new invoiceStatistics ();
  4976. $item = array (
  4977. 'date' => $irDetail ['receivablesDate'],
  4978. 'priceClass' => 2,
  4979. 'irid' => $irDetail ['irid'],
  4980. 'receivablesPrice' => - $refundPrice
  4981. );
  4982. if ($irDetail ['receivablesCategory'] != 'PUBLIC') {
  4983. $receivablesCategory = explode ( ":", $irDetail ['receivablesCategory'] );
  4984. $item += array (
  4985. 'cid' => $receivablesCategory [0]
  4986. );
  4987. }
  4988. if ($irDetail ['receivablesStaff'] != 'PUBLIC') {
  4989. $receivablesStaff = explode ( "-", $irDetail ['receivablesStaff'] );
  4990. $item += array (
  4991. 'staff' => $receivablesStaff [0]
  4992. );
  4993. }
  4994. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4995. // 公司日常支出流水
  4996. Doo::loadModel ( 'wasteBook' );
  4997. $wasteBook = new wasteBook ();
  4998. $accountBank = '';
  4999. if ($irDetail ['receivablesBank'] == '纵横广发') {
  5000. $accountBank = 'CGBDeposit';
  5001. } elseif ($irDetail ['receivablesBank'] == '纵横工行') {
  5002. $accountBank = 'ICBCDeposit';
  5003. } elseif ($irDetail ['receivablesBank'] == '华润银行') {
  5004. $accountBank = 'HUADeposit';
  5005. } elseif ($irDetail ['receivablesBank'] == '个人广发') {
  5006. $accountBank = 'PersonalDeposit';
  5007. }
  5008. $itemWaste = array (
  5009. 'accountPrice' => - $refundPrice,
  5010. 'expensesType' => 2,
  5011. 'accountType' => 11,
  5012. 'accountPriceShow' => $refundPrice,
  5013. 'dataID' => $irid,
  5014. 'accountBank' => $accountBank,
  5015. 'category' => $this->staff [0] ['category'],
  5016. 'cid' => $this->staff [0] ['cid'],
  5017. 'name' => $this->staff [0] ['username'],
  5018. 'sid' => $this->staff [0] ['sid'],
  5019. 'inputDate' => date ( "Y-m-d H:i:s" )
  5020. );
  5021. $wasteBook->setAccountBookStatistics ( $itemWaste );
  5022. return '/invoiceReceivablesAS';
  5023. }
  5024. die ( 'illegal request' );
  5025. }
  5026. function ajaxCheckInvoiceReceivablesRefund() {
  5027. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5028. $refundPrice = $this->get_args ( 'refundPrice' ) ? $this->get_args ( 'refundPrice' ) : "";
  5029. if ($refundPrice < 0) {
  5030. echo json_encode ( array (
  5031. 'error' => '金额不能为负'
  5032. ) );
  5033. die ();
  5034. }
  5035. if (! empty ( $refundPrice ) && ! empty ( $iridKey )) {
  5036. Doo::loadModel ( 'invoiceReceivables' );
  5037. $invoiceReceivables = new invoiceReceivables ();
  5038. $irid = $invoiceReceivables->authcode ( $iridKey );
  5039. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5040. if ($irDetail ['receivablesPrice'] < $refundPrice) {
  5041. echo json_encode ( array (
  5042. 'error' => '退款金额不能超过收款金额'
  5043. ) );
  5044. die ();
  5045. }
  5046. echo json_encode ( array (
  5047. 'ok' => '可以使用!'
  5048. ) );
  5049. die ();
  5050. }
  5051. }
  5052. /**
  5053. * 获得收款退款信息
  5054. */
  5055. function getRefundByDetail() {
  5056. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5057. Doo::loadModel ( 'invoiceReceivables' );
  5058. $invoiceReceivables = new invoiceReceivables ();
  5059. if (! empty ( $iridKey )) {
  5060. $irid = $invoiceReceivables->authcode ( $iridKey );
  5061. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5062. echo json_encode ( array (
  5063. 'status' => 1,
  5064. 'irDetail' => $irDetail
  5065. ) );
  5066. die ();
  5067. }
  5068. echo json_encode ( array (
  5069. 'status' => 2
  5070. ) );
  5071. }
  5072. /**
  5073. * 根据收款序列号获得收款退款信息
  5074. */
  5075. function ajaxGetInvoiceReceivablesBySerial() {
  5076. $receivablesSerial = $this->get_args ( 'receivablesSerial' ) ? $this->get_args ( 'receivablesSerial' ) : '';
  5077. if (! empty ( $receivablesSerial )) {
  5078. Doo::loadModel ( 'invoiceReceivables' );
  5079. $invoiceReceivables = new invoiceReceivables ();
  5080. // , ' and refundLog=""'
  5081. $irDetail = $invoiceReceivables->getInvoiceReceivablesBySerial ( $receivablesSerial );
  5082. $html = '';
  5083. if (! empty ( $irDetail ))
  5084. $html = '<td><b>¥' . $irDetail ['receivablesPrice'] . '</b></td>
  5085. <td>' . $irDetail ['receivablesMessage'] . '</td>
  5086. <td>' . $irDetail ['receivablesBank'] . '<br>' . $irDetail ['receivablesDate'] . '</td>
  5087. <td>' . $irDetail ['title'] . '-' . $irDetail ['username'] . '<br>' . $irDetail ['confirmTime'] . '</td>
  5088. <td>' . $irDetail ['recepitTitleMark'] . '
  5089. <input type="hidden" name="iridKey" id="iridKey" value="' . $irDetail ['iridKey'] . '">
  5090. </td>';
  5091. echo json_encode ( array (
  5092. 'status' => 1,
  5093. 'html' => $html,
  5094. 'irDetail' => $irDetail
  5095. ) );
  5096. die ();
  5097. }
  5098. echo json_encode ( array (
  5099. 'status' => 2
  5100. ) );
  5101. }
  5102. /**
  5103. * 绑定新收款
  5104. */
  5105. function relationNewInvoiceReceivables() {
  5106. $iridKeyOld = $this->get_args ( 'iridKeyOld' ) ? $this->get_args ( 'iridKeyOld' ) : '';
  5107. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5108. if (! empty ( $iridKeyOld ) && ! empty ( $iridKey )) {
  5109. Doo::loadModel ( 'invoiceReceivables' );
  5110. $invoiceReceivables = new invoiceReceivables ();
  5111. Doo::loadClass ( 'XDeode' );
  5112. $XDeode = new XDeode ( 5 );
  5113. $irid = $XDeode->decode ( $iridKey );
  5114. $iridOld = $invoiceReceivables->authcode ( $iridKeyOld );
  5115. echo $irid . 'bbb' . $iridOld;
  5116. $oldIrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $iridOld );
  5117. $IrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5118. if (empty ( $oldIrDetail ) || empty ( $IrDetail ))
  5119. die ( 'illegal request' );
  5120. $relationLog = $this->staff [0] ['username'] . ' 关联新款 <a href="#billing" onclick="invoiceReceivblesDivShow(\'' . $iridKey . '\',\'receivables\')" data-toggle="modal">' . $IrDetail ['receivablesSerial'] . '</a>
  5121. <br/>' . date ( "Y-m-d H:i:s" ) . '
  5122. ';
  5123. $invoiceReceivables = new invoiceReceivables ();
  5124. $item = array (
  5125. 'irid' => $iridOld,
  5126. 'relationIrid' => $irid,
  5127. 'relationLog' => $relationLog
  5128. );
  5129. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  5130. return '/invoiceReceivablesAS';
  5131. }
  5132. die ( 'illegal request' );
  5133. }
  5134. // function invoiceApprovalAchieve() {
  5135. // Doo::loadModel ( 'invoice' );
  5136. // $invoice = new invoice ();
  5137. // $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  5138. // $page_size = 12;
  5139. // $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5140. // $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  5141. // $get = "/" . $date;
  5142. // $con = '';
  5143. // if ($date == 'MONTHO')
  5144. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  5145. // elseif ($date == 'MONTHT')
  5146. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  5147. // elseif ($date == 'MONTHY')
  5148. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  5149. // if (! empty ( $MebSea )) {
  5150. // $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  5151. // $get .= "/" . $MebSea;
  5152. // }
  5153. // $pageinfo ['page'] = array (
  5154. // 'previous' => ''
  5155. // );
  5156. // $sql = '(status=1 or status=2 or status=3 or status=4) and processApprovals!=""' . $con; // echo $sql;
  5157. // $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", $get, "" );
  5158. // $limit = $pageinfo ['lower'] . ',' . $page_size;
  5159. // $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  5160. // // print_r($list);
  5161. // $this->data ['MebSeaEn'] = $MebSea;
  5162. // $this->data ['MebSea'] = urlencode ( $MebSea );
  5163. // $this->data ['get'] = $get;
  5164. // $this->data ['page'] = $pageinfo;
  5165. // $this->data ['list'] = $list;
  5166. // $this->data ['date'] = $date;
  5167. // $this->data ['memu'] = "invoice";
  5168. // $this->data ['staff'] = $this->staff;
  5169. // $this->data ['receiptMemu'] = 'invoiceApproval';
  5170. // $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  5171. // }
  5172. /**
  5173. * 获得审批发票的信息以及审批页面
  5174. */
  5175. function ajaxGetInvoiceApprovalDetail() {
  5176. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5177. if (empty ( $serial )) {
  5178. echo json_encode ( array (
  5179. 'status' => 2,
  5180. 'msg' => 'illegal request'
  5181. ) );
  5182. die ();
  5183. }
  5184. Doo::loadModel ( 'invoice' );
  5185. $invoice = new invoice ();
  5186. Doo::loadModel ( 'invoiceOperationLog' );
  5187. $invoiceOperationLog = new invoiceOperationLog ();
  5188. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5189. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5190. if (empty ( $detail ))
  5191. $html = '';
  5192. else {
  5193. $html = '
  5194. <form action="/invoiceApprovalDo" method="post" name="invoiceApproval" class="nice-validator n-yellow" novalidate="novalidate">
  5195. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  5196. <input type="hidden" name="status" value="">
  5197. <input type="hidden" name="divApproval" value="divApproval">
  5198. <div class="modal-dialog modal-lg">
  5199. <div class="modal-content"><div class="modal-header"><h3>发票审批详情</h3></div>
  5200. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  5201. <tr>
  5202. <th class="taC" width="150">发票审批</th><td><textarea name="opinion" style="width:98%" placeholder="在这写下您的审批意见,选填。"></textarea></td>
  5203. </tr>
  5204. <tr>
  5205. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5206. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5207. </tr>
  5208. <tr>
  5209. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5210. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5211. </tr>
  5212. <tr>
  5213. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5214. </td>
  5215. </tr>
  5216. <tr>
  5217. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5218. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5219. </tr>
  5220. <tr>
  5221. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5222. </tr></tbody></table>';
  5223. if ($detail ['invoiceType'] == 0)
  5224. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5225. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5226. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5227. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5228. </tr>';
  5229. else
  5230. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5231. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5232. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5233. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5234. ';
  5235. $html .= '<tr>
  5236. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5237. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5238. </tr>
  5239. <tr>
  5240. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5241. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5242. </tr></tbody></table>';
  5243. if ($detail ['doPost'] == 1) {
  5244. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5245. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5246. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5247. </tr><tr>
  5248. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5249. </tr><tr>
  5250. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5251. </tr>
  5252. ';
  5253. if ($detail ['expressCom'] == 'SF')
  5254. $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>';
  5255. else
  5256. $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>';
  5257. $html .= '</tbody></table>';
  5258. }
  5259. if (! empty ( $invoiceOperationLogList )) {
  5260. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  5261. foreach ( $invoiceOperationLogList as $key => $value ) {
  5262. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5263. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5264. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5265. if ($value ['status'] == 2) {
  5266. $html .= '<span class="colGreen">同意</span>';
  5267. } elseif ($value ['status'] == 3) {
  5268. $html .= '<span class="colOrange">退回</span>';
  5269. } elseif ($value ['status'] == 5) {
  5270. $html .= '<span class="colGreen">打印</span>';
  5271. } elseif ($value ['status'] == 4) {
  5272. $html .= '<span class="colRed">终止</span>';
  5273. }
  5274. $html .= $value ['operation'] . '</p></blockquote>';
  5275. }
  5276. }
  5277. $html .= '</td></tr></tbody></table>';
  5278. }
  5279. $html .= '</div><div class="modal-footer">
  5280. <a href="javascript:void(0)" node-approval="approval" diss-data="2" class="button btn-done" data-placement="top" data-toggle="ctooltip" >同意</a>
  5281. <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>
  5282. <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>
  5283. <a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>
  5284. </form>
  5285. <script type="text/javascript">
  5286. $("a[node-approval^=\'approval\']").click(function() {
  5287. $("input[name=\'status\']").val($(this).attr("diss-data"));
  5288. $("form[name=\'invoiceApproval\']").submit();
  5289. });
  5290. </script>
  5291. ';
  5292. }
  5293. echo json_encode ( array (
  5294. 'status' => 1,
  5295. 'html' => $html
  5296. ) );
  5297. die ();
  5298. }
  5299. /**
  5300. * 获得审批发票分页数据
  5301. */
  5302. function ajaxGetinvoiceApprovalAchieve() {
  5303. Doo::loadModel ( 'invoice' );
  5304. $invoice = new invoice ();
  5305. Doo::loadModel ( 'staff' );
  5306. $staff = new staff ();
  5307. Doo::loadClass ( 'XDeode' );
  5308. $XDeode = new XDeode ( 5 );
  5309. Doo::loadModel ( 'invoiceTraining' );
  5310. $invoiceTraining = new invoiceTraining ();
  5311. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  5312. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5313. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5314. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5315. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5316. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  5317. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  5318. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  5319. $MebSea = $this->get_args ( 'search' );
  5320. $MebSea = $MebSea ['value'];
  5321. $page_size = $length;
  5322. $con = '';
  5323. if ($status == 'ALL')
  5324. $con = ' (status=1 or status=2 or status=3 or status=4) and isDelete=0 ';
  5325. elseif ($status == 'PEND')
  5326. $con = ' isDelete=0 and status=1';
  5327. elseif ($status == 'APPROVED')
  5328. $con = ' isDelete=0 and status=2';
  5329. if ($invoiceType == 'ORDINARY')
  5330. $con .= ' and invoiceType=0 ';
  5331. elseif ($invoiceType == 'SPECIAL')
  5332. $con .= ' and invoiceType=1 ';
  5333. if ($invoiceTrain == 'ORDINARY')
  5334. $con .= ' and trainId=0 ';
  5335. elseif ($invoiceTrain == 'TRAIN')
  5336. $con .= ' and trainId!=0 ';
  5337. if ($invoiceTrainName != 'ALL') {
  5338. $trainId = $XDeode->decode ( $invoiceTrainName );
  5339. if (is_numeric ( $trainId ))
  5340. $con .= ' and trainId =' . $trainId;
  5341. }
  5342. $dateArr = explode ( ':', $date );
  5343. $D1 = $dateString = '';
  5344. $D2 = '';
  5345. if (! empty ( $date )) {
  5346. $D1 = $dateArr [0];
  5347. if (isset ( $dateArr [1] ))
  5348. $D2 = $dateArr [1];
  5349. else
  5350. $D2 = '';
  5351. $dateString = $D1 . " : " . $D2;
  5352. }
  5353. if (! empty ( $D1 ) && ! empty ( $D2 ))
  5354. $con .= ' and approvalTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  5355. elseif (! empty ( $D1 ) && empty ( $D2 ))
  5356. $con .= ' and approvalTime like "%' . $D1 . '%" ';
  5357. if (! empty ( $MebSea ))
  5358. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceSerial like "%' . $MebSea . '%" )';
  5359. // /
  5360. $pageinfo ['page'] = array (
  5361. 'previous' => ''
  5362. );
  5363. $sql = ' ' . $con;
  5364. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", '', "" );
  5365. $limit = $page . ',' . $page_size;
  5366. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  5367. $approvalList = array ();
  5368. $html = '<script type="text/javascript">
  5369. </script>';
  5370. // 结算结束不能修改方式
  5371. Doo::loadModel ( 'receipt' );
  5372. $receipt = new receipt ();
  5373. foreach ( $list as $key => $value ) {
  5374. $irDetail = array ();
  5375. // 结算方式
  5376. $receiptDetail = array ();
  5377. if ($value ['trainId'] != 0) {
  5378. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $value ['trainId'] );
  5379. }
  5380. if (! empty ( $receiptDetail )) {
  5381. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9) {
  5382. array_push ( $irDetail, '' );
  5383. } else {
  5384. if ($value ['status'] == 1 && $value ['pendingApprovals'] == $this->staff [0] ['sid']) {
  5385. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoiceApproval(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">审批发票</a>' );
  5386. } elseif ($value ['status'] == 2) {
  5387. array_push ( $irDetail, '<a href="#editPay" class="fnSettlementType" data-iidKey="' . $value ['iidKeyK'] . '" data-toggle="modal">结算方式</a>' );
  5388. } else
  5389. array_push ( $irDetail, '' );
  5390. }
  5391. } else {
  5392. if ($value ['status'] == 2) {
  5393. array_push ( $irDetail, '<a href="#editPay" class="fnSettlementType" data-iidKey="' . $value ['iidKeyK'] . '" data-toggle="modal">结算方式</a>' );
  5394. } else
  5395. array_push ( $irDetail, '' );
  5396. }
  5397. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  5398. if ($value ['invoiceType'] == 1)
  5399. array_push ( $irDetail, $value ['invoiceCompany'] );
  5400. else
  5401. array_push ( $irDetail, $value ['invoiceTitle'] );
  5402. array_push ( $irDetail, $value ['TIN'] );
  5403. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  5404. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  5405. array_push ( $irDetail, $value ['remark'] );
  5406. array_push ( $irDetail, $value ['invoiceElement'] );
  5407. array_push ( $irDetail, $value ['invoiceQuantity'] );
  5408. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  5409. if ($value ['invoiceType'] == 1) {
  5410. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  5411. } else {
  5412. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  5413. }
  5414. if ($value ['settlementType'] == 0) {
  5415. array_push ( $irDetail, '软件销售' );
  5416. } else {
  5417. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $value ['trainId'] );
  5418. array_push ( $irDetail, $itDetail ['trainName'] );
  5419. }
  5420. array_push ( $irDetail, $value ['recipients'] . $value ['recipientsPhone'] );
  5421. array_push ( $irDetail, $value ['recipientsAddress'] );
  5422. array_push ( $irDetail, $value ['mailItems'] );
  5423. array_push ( $irDetail, $value ['userName'] . '&nbsp;' . $value ['date'] );
  5424. $fchtml = $value ['OL'] ['operation'];
  5425. if (count ( $list ) == $page_size)
  5426. $fchtml = $value ['OL'] ['operation'] . $html;
  5427. // 最后的审批意见
  5428. array_push ( $irDetail, $fchtml );
  5429. if ($value ['status'] == 2)
  5430. array_push ( $irDetail, '<span class="colGreen">同意</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5431. elseif ($value ['status'] == 3)
  5432. array_push ( $irDetail, '<span class="colOrange">退回</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5433. elseif ($value ['status'] == 4)
  5434. array_push ( $irDetail, '<span class="colRed">终止</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5435. else
  5436. array_push ( $irDetail, '' );
  5437. array_push ( $approvalList, $irDetail );
  5438. }
  5439. // $approvalListJson = json_encode ( $approvalList );
  5440. $recordsFiltered = $pageinfo ['total_data'];
  5441. echo json_encode ( array (
  5442. "draw" => intval ( $draw ),
  5443. "recordsTotal" => intval ( $pageinfo ['total_data'] ),
  5444. "recordsFiltered" => intval ( $recordsFiltered ),
  5445. "data" => $approvalList
  5446. ), JSON_UNESCAPED_UNICODE );
  5447. }
  5448. /**
  5449. * 审批发票查看更多--重构
  5450. */
  5451. function invoiceApprovalAchieve() {
  5452. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'ALL';
  5453. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5454. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5455. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5456. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5457. Doo::loadModel ( 'invoiceTraining' );
  5458. $invoiceTraining = new invoiceTraining ();
  5459. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  5460. $this->data ['trainList'] = $trainList;
  5461. $this->data ['dateString'] = $date;
  5462. $this->data ['status'] = $status;
  5463. $this->data ['invoiceType'] = $invoiceType;
  5464. $this->data ['invoiceTrain'] = $invoiceTrain;
  5465. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  5466. $this->data ['memu'] = "invoice";
  5467. $this->data ['staff'] = $this->staff;
  5468. $this->data ['receiptMemu'] = 'invoiceApproval';
  5469. $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  5470. }
  5471. function invoiceTAchieve() {
  5472. Doo::loadModel ( 'invoice' );
  5473. $invoice = new invoice ();
  5474. Doo::loadClass ( 'XDeode' );
  5475. $XDeode = new XDeode ( 5 );
  5476. Doo::loadModel ( 'staff' );
  5477. $staff = new staff ();
  5478. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  5479. $page_size = 12;
  5480. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5481. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  5482. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5483. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5484. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5485. Doo::loadModel ( 'invoiceTraining' );
  5486. $invoiceTraining = new invoiceTraining ();
  5487. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  5488. $get = "/" . $date;
  5489. $con = '';
  5490. if ($date == 'MONTHO')
  5491. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  5492. elseif ($date == 'MONTHT')
  5493. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  5494. elseif ($date == 'MONTHY')
  5495. $con = ' and YEAR(updateTime) = YEAR(NOW())'; // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  5496. if ($invoiceType == 'ORDINARY')
  5497. $con .= ' and invoiceType=0 ';
  5498. elseif ($invoiceType == 'SPECIAL')
  5499. $con .= ' and invoiceType=1 ';
  5500. if ($invoiceTrain == 'ORDINARY')
  5501. $con .= ' and trainId=0 ';
  5502. elseif ($invoiceTrain == 'TRAIN')
  5503. $con .= ' and trainId!=0 ';
  5504. if ($invoiceTrainName != 'ALL') {
  5505. $trainId = $XDeode->decode ( $invoiceTrainName );
  5506. if (is_numeric ( $trainId ))
  5507. $con .= ' and trainId =' . $trainId;
  5508. }
  5509. if (! empty ( $MebSea )) {
  5510. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  5511. $get .= "/" . $MebSea;
  5512. }
  5513. $pageinfo ['page'] = array (
  5514. 'previous' => ''
  5515. );
  5516. $sql = "";
  5517. $action = "";
  5518. if ($this->ACTION == 'invoicePrintAchieve') {
  5519. $sql = "status=2 and printStatus=1 and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  5520. $action = "invoicePrintAchieve";
  5521. } elseif ($this->ACTION == 'invoicePostAchieve') {
  5522. // and untreadStatus=0
  5523. $sql = "postStatus=1 and doPost=1 and status=2 and isDelete=0" . $con;
  5524. $action = "invoicePostAchieve";
  5525. } elseif ($this->ACTION == 'invoiceUntreadAchieve') { // printStatus=1 and
  5526. $sql = " untreadStatus=2 and status=2 " . $con;
  5527. $action = "invoiceUntreadAchieve";
  5528. }
  5529. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  5530. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5531. $this->data ['MebSeaEn'] = $MebSea;
  5532. $this->data ['MebSea'] = urlencode ( $MebSea );
  5533. $this->data ['get'] = $get;
  5534. $this->data ['page'] = $pageinfo;
  5535. $this->data ['trainList'] = $trainList;
  5536. $this->data ['invoiceType'] = $invoiceType;
  5537. $this->data ['invoiceTrain'] = $invoiceTrain;
  5538. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  5539. $this->data ['date'] = $date;
  5540. $this->data ['memu'] = "invoice";
  5541. $this->data ['staff'] = $this->staff;
  5542. if ($this->ACTION == 'invoicePrintAchieve') {
  5543. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  5544. $this->data ['receiptMemu'] = 'invoicePrint';
  5545. $this->data ['list'] = $list;
  5546. $this->render ( "/admin/invoicePrintAchieve", $this->data );
  5547. } elseif ($this->ACTION == 'invoicePostAchieve') {
  5548. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  5549. Doo::loadModel ( 'express' );
  5550. $express = new express ();
  5551. $expressList = $express->getExpressByAll ();
  5552. $this->data ['expressList'] = $expressList;
  5553. $this->data ['receiptMemu'] = 'invoicePost';
  5554. $this->data ['list'] = $list;
  5555. $this->render ( "/admin/invoicePostAchieve", $this->data );
  5556. } elseif ($this->ACTION == 'invoiceUntreadAchieve') {
  5557. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  5558. $this->data ['receiptMemu'] = 'invoiceUntread';
  5559. $this->data ['list'] = $list;
  5560. $this->render ( "/admin/invoiceUntreadAchieve", $this->data );
  5561. }
  5562. }
  5563. /**
  5564. * 公司应收款
  5565. */
  5566. function invoiceAggregateCompanyDetail() {
  5567. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  5568. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  5569. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : 'ALL';
  5570. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  5571. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  5572. $titleORno = $this->get_args ( 'titleORno' ) ? $this->get_args ( 'titleORno' ) : "";
  5573. Doo::loadClass ( 'XDeode' );
  5574. $XDeode = new XDeode ( 5 );
  5575. Doo::loadModel ( 'invoice' );
  5576. $invoice = new invoice ();
  5577. Doo::loadModel ( 'staff' );
  5578. $staff = new staff ();
  5579. Doo::loadModel ( "invoiceCompanyManage" );
  5580. $invoiceCompanyManage = new invoiceCompanyManage ();
  5581. Doo::loadModel ( 'L_category' );
  5582. $category = new L_category ();
  5583. $sid = '';
  5584. if (! empty ( $sidKey )) {
  5585. $sid = $XDeode->decode ( $sidKey );
  5586. }
  5587. $staffDetail = $staff->getStaffBySid ( $sid );
  5588. $cid = '';
  5589. if (! empty ( $cidKey )) {
  5590. $cid = $XDeode->decode ( $cidKey );
  5591. }
  5592. $imcStaff = $invoiceCompanyManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  5593. $cidList = array ();
  5594. foreach ( $imcStaff as $key => $value ) {
  5595. array_push ( $cidList, $value ['cid'] );
  5596. }
  5597. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  5598. $cidString = implode ( ',', $cidList );
  5599. if (empty ( $cid ))
  5600. $staffList = $staff->getStaffInCid ( $cidString );
  5601. else
  5602. $staffList = $staff->getStaffByCidAll ( $cid ); //
  5603. //$MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  5604. $page_size = 25;
  5605. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5606. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  5607. $con = ' status=2 and untreadStatus!=2 ';
  5608. $statisticsCon = '';
  5609. if (! empty ( $year ) && is_numeric ( $year ))
  5610. $con .= ' and Year(printTime)=' . $year . '';
  5611. if (! empty ( $month ) && is_numeric ( $month ))
  5612. $con .= ' and Month(printTime)="' . $month . '" ';
  5613. if ($status == 'UNRECORD')
  5614. $con .= ' and printStatus=1 and untreadStatus=0';
  5615. elseif ($status == 'RECORD')
  5616. $con .= ' and printStatus=1 and untreadStatus=3';
  5617. elseif ($status == 'BOUNCED')
  5618. $con .= ' and untreadStatus=2';
  5619. elseif ($status == 'PARTRECORD')
  5620. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  5621. elseif ($status == 'All') {
  5622. $con .= ' and printStatus=1 and ( untreadStatus=0 or untreadStatus=3 )';
  5623. }
  5624. if (! empty ( $sid ) && is_numeric ( $sid ))
  5625. $con .= ' and sid=' . $sid;
  5626. if (! empty ( $cid ) && is_numeric ( $cid ))
  5627. $con .= ' and cid=' . $cid;
  5628. else
  5629. $con .= ' and cid in (' . $cidString . ')';
  5630. // 开票内容筛选
  5631. if (! empty ( $invoiceElement ) && $invoiceElement != 'ALL') {
  5632. $con .= ' and invoiceElement="' . $invoiceElement . '"';
  5633. }
  5634. $get = "/" . $status . "?cidKey=" . $cidKey . "&sidKey=" . $sidKey . "&year=" . $year . "&month=" . $month
  5635. . "&invoiceElement=" . $invoiceElement."&titleORno=".urlencode ( $titleORno );
  5636. if (! empty ( $titleORno )) {
  5637. $con .= ' and ( invoiceTitle like "%' . $titleORno . '%" or invoiceCompany like "%' . $titleORno . '%" or invoiceNo like "%'.$titleORno.'%" )';
  5638. }
  5639. $pageinfo ['page'] = array (
  5640. 'previous' => ''
  5641. );
  5642. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateCompanyDetail", $get, "" );
  5643. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5644. // 应收款合计
  5645. $ics = $invoice->getInvoiceCompanyStatistics ( $con );
  5646. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  5647. $monthHtml = "";
  5648. if ($year != "ALL") {
  5649. for($i = 1; $i <= 12; $i ++) {
  5650. if ($i == $month)
  5651. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  5652. else
  5653. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  5654. }
  5655. }
  5656. $this->data ['monthHtml'] = $monthHtml;
  5657. $this->data ['year'] = $year;
  5658. $this->data ['month'] = $month;
  5659. $this->data ['ics'] = $ics;
  5660. $this->data ['cidKey'] = $cidKey;
  5661. $this->data ['sid'] = $sid;
  5662. $this->data ['staffDetail'] = $staffDetail;
  5663. $this->data ['staffList'] = $staffList;
  5664. $this->data ['titleORnoEn'] = $titleORno;
  5665. $this->data ['titleORno'] = urlencode ( $titleORno );
  5666. $this->data ['invoiceDetail'] = array (
  5667. 'invoiceElement' => $invoiceElement
  5668. );
  5669. $this->data ['page'] = $pageinfo;
  5670. $this->data ['get'] = $get;
  5671. $this->data ['list'] = $list;
  5672. $this->data ['status'] = $status;
  5673. $this->data ['categoryList'] = $categoryList;
  5674. $this->data ['memu'] = "invoice";
  5675. $this->data ['staff'] = $this->staff;
  5676. $this->data ['receiptMemu'] = 'invoiceAggregateCompanyDetail';
  5677. $this->render ( "/admin/invoiceAggregateCompanyDetail", $this->data );
  5678. }
  5679. /**
  5680. * 获取一条收款信息
  5681. */
  5682. function ajaxGetInvoiceReceivables() {
  5683. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  5684. Doo::loadModel ( 'invoiceReceivables' );
  5685. $invoiceReceivables = new invoiceReceivables ();
  5686. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5687. echo json_encode ( array (
  5688. 'status' => 1,
  5689. 'detail' => $detail
  5690. ) );
  5691. }
  5692. /**
  5693. * 异步获取办事处用户
  5694. */
  5695. function ajaxGetStaffByCategory() {
  5696. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "";
  5697. Doo::loadModel ( 'staff' );
  5698. $staff = new staff ();
  5699. if ($cid == "PUBLIC") {
  5700. echo json_encode ( array (
  5701. 'status' => 1,
  5702. 'html' => '<option value="PUBLIC">办事处待认领款项</option>'
  5703. ) );
  5704. die ();
  5705. }
  5706. if (! is_numeric ( $cid )) {
  5707. echo json_encode ( array (
  5708. 'status' => 0,
  5709. 'msg' => 'illegal request'
  5710. ) );
  5711. die ();
  5712. }
  5713. $staffList = $staff->getStaffByCid ( $cid );
  5714. $html = '<option value="PUBLIC">办事处待认领款项</option>';
  5715. foreach ( $staffList as $key => $value ) {
  5716. $html .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  5717. }
  5718. echo json_encode ( array (
  5719. 'status' => 1,
  5720. 'html' => $html
  5721. ) );
  5722. }
  5723. /**
  5724. * 异步获取一条发票的邮寄信息
  5725. */
  5726. function ajaxGetInvoicePostDetail() {
  5727. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  5728. Doo::loadModel ( 'invoice' );
  5729. $invoice = new invoice ();
  5730. $iid = $invoice->authcode ( $iid );
  5731. Doo::loadModel ( 'express' );
  5732. $express = new express ();
  5733. $expressList = $express->getExpressByAll ();
  5734. if (! is_numeric ( $iid )) {
  5735. echo json_encode ( array (
  5736. 'status' => 0,
  5737. 'msg' => 'illegal request'
  5738. ) );
  5739. die ();
  5740. }
  5741. $select = "iid,recipients,recipientsPhone,recipientsAddress,mailItems,expressCompany,expressNumber,actualItems";
  5742. $invoiceDetail = $invoice->getInvoiceByIid ( $iid, $select );
  5743. $html = "";
  5744. foreach ( $expressList as $key => $value ) {
  5745. if ($value ['company'] == $invoiceDetail ['expressCompany'])
  5746. $html .= '<option selected value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  5747. else
  5748. $html .= '<option value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  5749. }
  5750. $invoiceDetail ['eaHtml'] = $html;
  5751. echo json_encode ( array (
  5752. 'status' => 1,
  5753. 'invoiceDetail' => $invoiceDetail
  5754. ) );
  5755. }
  5756. /**
  5757. *
  5758. * @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 ) ); }
  5759. */
  5760. /**
  5761. *
  5762. * @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 ) ); }
  5763. */
  5764. /**
  5765. * 我的收款中 选择哪个发票入账,进行金额判断
  5766. */
  5767. function ajaxCompareInvoicePrice() {
  5768. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  5769. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  5770. Doo::loadModel ( 'invoice' );
  5771. $invoice = new invoice ();
  5772. Doo::loadModel ( 'invoiceReceivables' );
  5773. $invoiceReceivables = new invoiceReceivables ();
  5774. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  5775. $keyList = explode ( ';', $claimKey );
  5776. $receivablesPrice = 0;
  5777. foreach ( $keyList as $key => $value ) {
  5778. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $value );
  5779. $receivablesPrice += $detailM ['receivablesPrice'];
  5780. }
  5781. if ($receivablesPrice > $detail ['invoicePrice']) {
  5782. $price = $receivablesPrice - $detail ['invoicePrice'];
  5783. echo json_encode ( array (
  5784. 'status' => 1,
  5785. 'price' => $price
  5786. ) );
  5787. } else
  5788. echo json_encode ( array (
  5789. 'status' => 2
  5790. ) );
  5791. }
  5792. /**
  5793. * 获得打印发票
  5794. */
  5795. function ajaxGetInvoiceInfoByPrint() {
  5796. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5797. if (empty ( $serial )) {
  5798. echo json_encode ( array (
  5799. 'status' => 2,
  5800. 'msg' => 'illegal request'
  5801. ) );
  5802. die ();
  5803. }
  5804. Doo::loadModel ( 'invoice' );
  5805. $invoice = new invoice ();
  5806. Doo::loadModel ( 'invoiceOperationLog' );
  5807. $invoiceOperationLog = new invoiceOperationLog ();
  5808. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5809. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5810. Doo::loadModel ( 'invoicePaper' );
  5811. $invoicePaper = new invoicePaper ();
  5812. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $detail ['invoiceType'] );
  5813. if (empty ( $detail ))
  5814. $html = '';
  5815. else {
  5816. $html = '
  5817. <form action="/invoicePrintDo" method="post" name="invoicePrint" class="nice-validator n-yellow" onSubmit="return checkPrintForm()" novalidate="novalidate">
  5818. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  5819. <input type="hidden" name="invoicePrintType" value="invoicePrintType">
  5820. <div class="modal-dialog modal-lg">
  5821. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  5822. <div class="modal-body saeaList">
  5823. <table class="table table-bordered table-condensed"><tbody>
  5824. <tr>
  5825. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5826. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5827. </tr>
  5828. <tr>
  5829. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5830. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5831. </tr>
  5832. <tr>
  5833. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5834. </td>
  5835. </tr>
  5836. <tr>
  5837. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5838. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5839. </tr>
  5840. <tr>
  5841. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5842. </tr></tbody></table>';
  5843. if ($detail ['invoiceType'] == 0)
  5844. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5845. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5846. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5847. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5848. </tr>';
  5849. else
  5850. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5851. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5852. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5853. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5854. ';
  5855. $html .= '<tr>
  5856. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5857. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5858. </tr>
  5859. <tr>
  5860. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5861. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5862. </tr></tbody></table>';
  5863. if ($detail ['doPost'] == 1)
  5864. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5865. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5866. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5867. </tr><tr>
  5868. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5869. </tr><tr>
  5870. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5871. </tr></tbody></table>';
  5872. if (! empty ( $invoiceOperationLogList )) {
  5873. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th><th class="taC">发票打印</th></tr><tr><td>';
  5874. foreach ( $invoiceOperationLogList as $key => $value ) {
  5875. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5876. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5877. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5878. if ($value ['status'] == 2) {
  5879. $html .= '<span class="colGreen">同意</span>';
  5880. } elseif ($value ['status'] == 3) {
  5881. $html .= '<span class="colOrange">退回</span>';
  5882. } elseif ($value ['status'] == 5) {
  5883. $html .= '<span class="colGreen">打印</span>';
  5884. } elseif ($value ['status'] == 4) {
  5885. $html .= '<span class="colRed">终止</span>';
  5886. }
  5887. $html .= $value ['operation'] . '</p></blockquote>';
  5888. }
  5889. }
  5890. $html .= '</td>
  5891. <td><span class="colRed">*</span>
  5892. <select name="invoiceNo" id="invoiceNo" style="width:97%">';
  5893. foreach ( $invoicePaperList as $key => $value ) {
  5894. $html .= '<option value="' . $value ['ipidKey'] . '">No.' . $value ['invoiceNo'] . '</option>';
  5895. }
  5896. $html .= '</select>
  5897. <span class="red" id="p-msg"></span>
  5898. </td>
  5899. </tr></tbody></table>';
  5900. }
  5901. $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>
  5902. </div></div></form>
  5903. <link rel=stylesheet href="' . WEB_SITE_GLOBAL . 'css/jquery.validator.css">
  5904. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/jquery.validator.min.js"></script>
  5905. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/zh-CN.js"></script>
  5906. <script src="' . WEB_SITE_GLOBAL . 'js/invoice.validator.js"></script>
  5907. ';
  5908. }
  5909. echo json_encode ( array (
  5910. 'status' => 1,
  5911. 'html' => $html
  5912. ) );
  5913. die ();
  5914. }
  5915. /**
  5916. * @ 获得与我有关收款数据 --需求变更 废弃 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 ) ); }
  5917. */
  5918. function ajaxGetInvoiceInfoByType() {
  5919. $type = $this->get_args ( 'type' ) ? $this->get_args ( 'type' ) : "";
  5920. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5921. $loss = $this->get_args ( 'loss' ) ? $this->get_args ( 'loss' ) : false;
  5922. if (empty ( $serial )) {
  5923. echo json_encode ( array (
  5924. 'status' => 2,
  5925. 'msg' => 'illegal request'
  5926. ) );
  5927. die ();
  5928. }
  5929. if ($type == 'INVOICE') {
  5930. Doo::loadModel ( 'invoice' );
  5931. $invoice = new invoice ();
  5932. Doo::loadModel ( 'invoiceOperationLog' );
  5933. $invoiceOperationLog = new invoiceOperationLog ();
  5934. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5935. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5936. if (empty ( $detail ))
  5937. $html = '';
  5938. else {
  5939. $html = '
  5940. <div class="modal-dialog modal-lg">
  5941. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  5942. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  5943. <tr>
  5944. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5945. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5946. </tr>
  5947. <tr>
  5948. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5949. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5950. </tr>
  5951. <tr>
  5952. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5953. </td>
  5954. </tr>
  5955. <tr>
  5956. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5957. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5958. </tr>
  5959. <tr>
  5960. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5961. </tr>';
  5962. if ($detail ['settlementType'] == 1)
  5963. $html .= '<tr>
  5964. <th class="taC" width="150">结算方式</th><td colspan="3">培训班(<a href="/invoiceTrainingDetail/' . $detail ['invoiceTraining'] ['trainingKey'] . '.html" target="_blank">' . $detail ['invoiceTraining'] ['trainName'] . '</a>)</td>
  5965. </tr>';
  5966. else
  5967. $html .= '<tr>
  5968. <th class="taC" width="150">结算方式</th><td colspan="3">软件销售</td>
  5969. </tr>';
  5970. $html .= ' </tbody></table>';
  5971. if ($detail ['invoiceType'] == 0)
  5972. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5973. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5974. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5975. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5976. </tr>';
  5977. else
  5978. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5979. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5980. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5981. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5982. ';
  5983. $html .= '<tr>
  5984. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5985. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5986. </tr>
  5987. <tr>
  5988. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5989. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5990. </tr></tbody></table>';
  5991. if ($detail ['doPost'] == 1) {
  5992. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5993. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5994. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5995. </tr><tr>
  5996. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5997. </tr><tr>
  5998. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5999. </tr>
  6000. ';
  6001. if ($detail ['expressCom'] == 'SF')
  6002. $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>';
  6003. else
  6004. $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>';
  6005. $html .= '</tbody></table>';
  6006. }
  6007. if (! empty ( $invoiceOperationLogList )) {
  6008. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  6009. foreach ( $invoiceOperationLogList as $key => $value ) {
  6010. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  6011. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  6012. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  6013. if ($value ['status'] == 2) {
  6014. $html .= '<span class="colGreen">同意</span>';
  6015. } elseif ($value ['status'] == 3) {
  6016. $html .= '<span class="colOrange">退回</span>';
  6017. } elseif ($value ['status'] == 5) {
  6018. $html .= '<span class="colGreen">打印</span>';
  6019. } elseif ($value ['status'] == 4) {
  6020. $html .= '<span class="colRed">终止</span>';
  6021. }
  6022. $html .= $value ['operation'] . '</p></blockquote>';
  6023. }
  6024. }
  6025. $html .= '</td></tr></tbody></table>';
  6026. }
  6027. $html .= '</div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  6028. }
  6029. echo json_encode ( array (
  6030. 'status' => 1,
  6031. 'html' => $html
  6032. ) );
  6033. die ();
  6034. } elseif ($type == 'RECEIVABLES') {
  6035. Doo::loadModel ( 'invoiceReceivables' );
  6036. $invoiceReceivables = new invoiceReceivables ();
  6037. Doo::loadModel ( 'invoiceRefund' );
  6038. $invoiceRefund = new invoiceRefund ();
  6039. $detail = $invoiceReceivables->getInvoiceReceivablesByIrsid ( $serial );
  6040. $ireList = $invoiceRefund->getInvoiceRefundIrid ( $detail ['irid'] );
  6041. if (empty ( $detail ))
  6042. $html = '';
  6043. else {
  6044. $html = '<div class="modal-dialog modal-lg"><div class="modal-content"><div class="modal-header"><h3>收款单详情</h3></div><div class="modal-body saeaList">
  6045. <table class="table table-bordered table-condensed">
  6046. <tbody><tr>
  6047. <th class="taC">收款流水号</th><td>' . $detail ['receivablesSerial'] . '</td>
  6048. <th class="taC">录入收款</th><td>' . $detail ['inputStaff'] . ' ' . $detail ['date'] . '</td>
  6049. </tr><tr>
  6050. <th class="taC">收款金额</th><td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  6051. <th class="taC">收款信息</th><td>' . $detail ['receivablesMessage'] . '</td>
  6052. </tr>
  6053. <tr>
  6054. <th class="taC">收款银行</th><td>' . $detail ['receivablesBank'] . '</td>
  6055. <th class="taC">银行到账</th><td>' . $detail ['receivablesDate'] . '</td>
  6056. </tr>
  6057. <tr>
  6058. <th class="taC">认领收款</th><td colspan="3">' . $detail ['inputStaff'] . ' 转入 ' . $detail ['username'] . ' ' . $detail ['confirmTime'] . '</td>
  6059. </tr>
  6060. </tbody></table>';
  6061. if (! empty ( $ireList )) {
  6062. $html .= '
  6063. <table class="table table-bordered table-condensed"><tbody><tr><th class="taC" colspan="5">退款记录</th></tr>
  6064. <tr>
  6065. <th class="taC">退款单位名称</th>
  6066. <th class="taC">退款的账号</th>
  6067. <th class="taC">退款金额</th>
  6068. <th class="taC">退款</th>
  6069. <th class="taC">备注</th>
  6070. </tr>
  6071. ';
  6072. foreach ( $ireList as $key => $value ) {
  6073. $refundLogList = explode ( "<br/>", $value ['refundLog'] );
  6074. $html .= '<tr>
  6075. <td>' . $value ['refundCompany'] . '</td>
  6076. <td>' . $value ['refundNumber'] . '</td>
  6077. <td><b class="colRed">¥' . $value ['refundPrice'] . '</b></td>
  6078. <td>' . $refundLogList [0] . $refundLogList [2] . '</td>
  6079. <td>' . $value ['refundRemarks'] . '</td>
  6080. </tr>
  6081. ';
  6082. }
  6083. }
  6084. $html .= '</tbody></table></div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  6085. }
  6086. echo json_encode ( array (
  6087. 'status' => 1,
  6088. 'html' => $html
  6089. ) );
  6090. die ();
  6091. } elseif ($type == 'IRTC') {
  6092. Doo::loadModel ( 'invoice' );
  6093. $invoice = new invoice ();
  6094. Doo::loadModel ( 'invoiceOperationLog' );
  6095. $invoiceOperationLog = new invoiceOperationLog ();
  6096. // Doo::loadModel ( 'invoiceReceivables' );
  6097. // $invoiceReceivables = new invoiceReceivables ();
  6098. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  6099. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  6100. if (empty ( $detail ))
  6101. $html = '';
  6102. else {
  6103. $receivablesPriceedHtml = '';
  6104. $receivablesPrice = $detail ['invoicePrice'];
  6105. if (! empty ( $detail ['irid'] )) {
  6106. // $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $detail ['irid'] );
  6107. // if (empty ( $irList ))
  6108. // $irList [0] ['sumPrice'] = 0;
  6109. // $balance = $detail ['invoicePrice'] - $irList [0] ['sumPrice'];
  6110. $enteredPrice=$detail ['invoicePrice']-$detail ['invoiceBalance'];
  6111. $receivablesPriceedHtml = '<table class="table table-bordered table-condensed"><tbody><tr>
  6112. <th class="taC">已入账金额</th><td><b class="colGreen" style="font-size:18px">¥' . $enteredPrice . '</b></td>
  6113. <th class="taC">剩余入账金额</th><td><b class="colRed" style="font-size:18px">¥' . $detail ['invoiceBalance'] . '</b></td>
  6114. </tr></tbody></table>';
  6115. $receivablesPrice = $detail ['invoiceBalance'];
  6116. }
  6117. if ($loss)
  6118. $detail ['invoicePrice'] = - $detail ['invoicePrice'];
  6119. $html = $receivablesPriceedHtml . '
  6120. <table class="table table-bordered table-condensed"><tbody>
  6121. <tr>
  6122. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  6123. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  6124. </tr>
  6125. <tr>
  6126. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  6127. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  6128. </tr>
  6129. <tr>
  6130. <th class="taC" width="150">发票备注</th><td colspan="3">' . $detail ['remark'] . '</td>
  6131. </tr>
  6132. <tr>
  6133. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  6134. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  6135. </tr>
  6136. <tr>
  6137. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  6138. </tr></tbody></table>';
  6139. if ($detail ['invoiceType'] == 0) {
  6140. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6141. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  6142. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  6143. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  6144. </tr>';
  6145. $receivablesMessage = $detail ['invoiceTitle'];
  6146. } else {
  6147. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6148. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  6149. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  6150. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  6151. ';
  6152. $receivablesMessage = $detail ['invoiceCompany'];
  6153. }
  6154. $html .= '<tr>
  6155. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  6156. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  6157. </tr>
  6158. <tr>
  6159. <th class="taC">开户银行</th><td>' . $detail ['bankAccount'] . '</td>
  6160. <th class="taC">银行账号</th><td>' . $detail ['bank'] . '</td>
  6161. </tr></tbody></table>';
  6162. if ($detail ['doPost'] == 1)
  6163. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  6164. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  6165. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  6166. </tr><tr>
  6167. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  6168. </tr><tr>
  6169. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  6170. </tr></tbody></table>';
  6171. if (! empty ( $invoiceOperationLogList )) {
  6172. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  6173. foreach ( $invoiceOperationLogList as $key => $value ) {
  6174. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  6175. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  6176. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  6177. if ($value ['status'] == 2) {
  6178. $html .= '<span class="colGreen">同意</span>';
  6179. } elseif ($value ['status'] == 3) {
  6180. $html .= '<span class="colOrange">退回</span>';
  6181. } elseif ($value ['status'] == 5) {
  6182. $html .= '<span class="colGreen">打印</span>';
  6183. }
  6184. $html .= $value ['operation'] . '</p></blockquote>';
  6185. }
  6186. }
  6187. $html .= '</td></tr></tbody></table>';
  6188. }
  6189. }
  6190. echo json_encode ( array (
  6191. 'status' => 1,
  6192. 'html' => $html,
  6193. 'receivablesPrice' => $receivablesPrice,
  6194. 'receivablesMessage' => $receivablesMessage,
  6195. 'receivablesDate' => date ( "Y-m-d" ),
  6196. 'iidKey' => $serial
  6197. ) );
  6198. die ();
  6199. }
  6200. }
  6201. function ajaxGetInvoiceReceivablesByStaff() {
  6202. $postData = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : "";
  6203. if (empty ( $postData )) {
  6204. echo json_encode ( array (
  6205. 'status' => 2,
  6206. 'msg' => 'illegal request'
  6207. ) );
  6208. die ();
  6209. }
  6210. Doo::loadModel ( 'invoiceReceivables' );
  6211. $invoiceReceivables = new invoiceReceivables ();
  6212. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $postData );
  6213. if (empty ( $detail )) {
  6214. echo json_encode ( array (
  6215. 'status' => 2,
  6216. 'msg' => 'illegal request'
  6217. ) );
  6218. die ();
  6219. }
  6220. Doo::loadModel ( 'L_category' );
  6221. $lCategory = new L_category ();
  6222. Doo::loadModel ( 'staff' );
  6223. $staff = new staff ();
  6224. $staffList = $staff->getStaffByCid ( $detail ['cid'] );
  6225. $category = $lCategory->getCategory ();
  6226. $categoryHtml = '<option post-data="PUBLIC" value="PUBLIC" >公共待认领款项</option>';
  6227. $staffHtml = '<option value="PUBLIC">办事处待认领款项</option>';
  6228. foreach ( $category as $key => $value ) {
  6229. $categoryHtml .= '<option post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  6230. if ($value ['cid'] == $detail ['cid'])
  6231. $categoryHtml .= '<option selected post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  6232. }
  6233. foreach ( $staffList as $key => $value ) {
  6234. $staffHtml .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  6235. if ($value ['sid'] == $detail ['sid'])
  6236. $staffHtml .= '<option selected value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  6237. }
  6238. $rbankHtml = '<option value="广发银行珠海分行柠溪支行">广发银行珠海分行柠溪支行</option>';
  6239. echo json_encode ( array (
  6240. 'status' => 1,
  6241. 'categoryHtml' => $categoryHtml,
  6242. 'staffHtml' => $staffHtml,
  6243. 'rbankHtml' => $rbankHtml,
  6244. 'detail' => $detail
  6245. ) );
  6246. }
  6247. function ajaxGetInvoiceReceivablesByIrid() {
  6248. $irid = $this->get_args ( 'irid' ) ? $this->get_args ( 'irid' ) : "";
  6249. if (empty ( $irid )) {
  6250. echo json_encode ( array (
  6251. 'status' => 2,
  6252. 'msg' => 'illegal request'
  6253. ) );
  6254. die ();
  6255. }
  6256. Doo::loadModel ( 'invoiceReceivables' );
  6257. $invoiceReceivables = new invoiceReceivables ();
  6258. Doo::loadModel ( 'invoice' );
  6259. $invoice = new invoice ();
  6260. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid ); // 入账完成 待定 and postStatus=1
  6261. $flag = true;
  6262. $invoiceDetail = $invoice->getInvoiceByTitle ( $detail ['recepitTitleMark'], 'EXACTLY', " and status=2 and printStatus=1 and untreadStatus=0 ", $flag ); //
  6263. $bakDetail = array ();
  6264. if ($flag === false) {
  6265. array_push ( $bakDetail, $invoiceDetail );
  6266. $invoiceDetail = $bakDetail;
  6267. }
  6268. $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>
  6269. <tr>
  6270. <td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  6271. <td>' . $detail ['receivablesMessage'] . '</td>
  6272. <td>' . $detail ['receivablesBank'] . '<br>' . $detail ['receivablesDate'] . '</td>
  6273. <td>' . $detail ['title'] . '-' . $detail ['username'] . '<br>' . $detail ['confirmTime'] . '</td>
  6274. <td>' . $detail ['recepitTitleMark'] . '</td>
  6275. </tr></tbody></table>';
  6276. $isInvoice = false;
  6277. $invoiceHtml = '';
  6278. if (empty ( $invoiceDetail )) {
  6279. $isInvoice = true;
  6280. } else {
  6281. $invoiceHtml = '<table class="table table-bordered table-condensed">
  6282. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody>';
  6283. foreach ( $invoiceDetail as $key => $value ) {
  6284. $invoiceHtml .= '<tr>';
  6285. if (! empty ( $value ['invoiceType'] )) {
  6286. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  6287. } else {
  6288. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  6289. }
  6290. if (! empty ( $value ['invoiceType'] )) {
  6291. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  6292. } else {
  6293. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  6294. }
  6295. $invoiceHtml .= '
  6296. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  6297. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  6298. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir" data-ikey="' . $value ['iidKey'] . '" href="javascript:void(0)">入账</a></td>
  6299. </tr>
  6300. ';
  6301. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  6302. if (empty ( $irList ))
  6303. $irList [0] ['sumPrice'] = 0;
  6304. $balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  6305. $priceString = '';
  6306. if ($balance < $detail ['receivablesPrice']) {
  6307. $priceString = '收款金额超过开票金额,';
  6308. }
  6309. if ($balance > $detail ['receivablesPrice']) {
  6310. $priceString = '收款金额低于开票金额,';
  6311. }
  6312. }
  6313. $invoiceHtml .= '
  6314. <script>
  6315. $(\'a[bind-receivables^="ir"]\').click(function() {
  6316. var data = $(this).attr("data-ikey");
  6317. $("input[name=\'invoiceKey\']").val(data);
  6318. var invoiceKey=data;
  6319. if(invoiceKey==""){
  6320. alert("入账错误,请重新刷新页面");
  6321. return false;
  6322. }
  6323. if(window.confirm("' . $priceString . '确定入账吗?")){
  6324. $("#IBR").submit();
  6325. }else{
  6326. return false;
  6327. }
  6328. });
  6329. </script>
  6330. ';
  6331. $invoiceHtml .= '</tbody></table>';
  6332. }
  6333. echo json_encode ( array (
  6334. 'status' => 1,
  6335. 'irkey' => $detail ['iridEn'],
  6336. 'receivablesHtml' => $receivablesHtml,
  6337. 'isInvoice' => $isInvoice,
  6338. 'invoiceHtml' => $invoiceHtml
  6339. ) );
  6340. }
  6341. function ajaxGetInvoiceReceivablesByTitle() {
  6342. $title = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  6343. if (empty ( $title )) {
  6344. echo json_encode ( array (
  6345. 'status' => 2,
  6346. 'msg' => 'illegal request'
  6347. ) );
  6348. die ();
  6349. }
  6350. Doo::loadModel ( 'invoice' );
  6351. $invoice = new invoice ();
  6352. $invoiceDetail = $invoice->getInvoiceByTitle ( $title, 'FUZZY', " and status=2 and printStatus=1 and untreadStatus=0 and irid='' ", true );
  6353. $invoiceHtml = '';
  6354. if (! empty ( $invoiceDetail )) {
  6355. $invoiceHtml = '<table class="table table-bordered table-condensed">
  6356. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody><tr>';
  6357. foreach ( $invoiceDetail as $key => $value ) {
  6358. if (! empty ( $value ['invoiceType'] )) {
  6359. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  6360. } else {
  6361. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  6362. }
  6363. if (! empty ( $value ['invoiceType'] )) {
  6364. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  6365. } else {
  6366. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  6367. }
  6368. $invoiceHtml .= '
  6369. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  6370. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  6371. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir' . $value ['iidKeyXD'] . '" data-ikey="' . $value ['iidKey'] . '" href="#">入账</a></td>
  6372. </tr>
  6373. ';
  6374. }
  6375. $invoiceHtml .= '</tbody></table>
  6376. <script>
  6377. $(\'a[bind-receivables^="ir"]\').click(function() {
  6378. var data = $(this).attr("data-ikey");
  6379. $("input[name=\'invoiceKey\']").val(data);
  6380. var invoiceKey=$("input[name=\'invoiceKey\']").val();
  6381. if(invoiceKey==""){
  6382. alert("入账错误,请重新刷新页面");
  6383. return false;
  6384. }
  6385. if(window.confirm("确定入账吗?")){
  6386. $("#IBR").submit();
  6387. }else{
  6388. return false;
  6389. }
  6390. });
  6391. </script>
  6392. ';
  6393. }
  6394. echo json_encode ( array (
  6395. 'status' => 1,
  6396. 'invoiceHtml' => $invoiceHtml
  6397. ) );
  6398. }
  6399. function ajaxInvoicePushNotice() {
  6400. Doo::loadModel ( 'invoice' );
  6401. $invoice = new invoice ();
  6402. $approval = $invoice->getOne ( array (
  6403. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  6404. 'desc' => 'iid',
  6405. 'asArray' => true
  6406. ) );
  6407. $isNotice = false;
  6408. if (! empty ( $approval ))
  6409. $isNotice = true;
  6410. $response = array (
  6411. 'error' => 0,
  6412. 'isNotice' => $isNotice
  6413. );
  6414. echo json_encode ( $response );
  6415. exit ();
  6416. }
  6417. public function ajaxCheckInvoiceNoUniqueness() {
  6418. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  6419. Doo::loadModel ( 'invoice' );
  6420. $invoice = new invoice ();
  6421. if (! empty ( $invoiceNo )) {
  6422. Doo::loadModel ( 'invoicePaper' );
  6423. $invoicePaper = new invoicePaper ();
  6424. Doo::loadClass ( 'XDeode' );
  6425. $XDeode = new XDeode ( 5 );
  6426. $ipid = $XDeode->decode ( $invoiceNo );
  6427. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  6428. $info = $invoice->getOne ( array (
  6429. 'where' => "invoiceNo = '" . $paperDetail ['invoiceNo'] . "'",
  6430. 'asArray' => TRUE
  6431. ) );
  6432. if (! empty ( $info )) {
  6433. echo json_encode ( array (
  6434. 'error' => '发票号已存在'
  6435. ) );
  6436. die ();
  6437. } else
  6438. echo json_encode ( array (
  6439. 'ok' => '可以使用!'
  6440. ) );
  6441. die ();
  6442. }
  6443. }
  6444. function ajaxCheckInvoicePrice() {
  6445. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) && is_numeric ( $this->get_args ( 'receivablesPrice' ) ) ? $this->get_args ( 'receivablesPrice' ) : "";
  6446. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  6447. Doo::loadModel ( 'invoice' );
  6448. $invoice = new invoice ();
  6449. Doo::loadModel ( 'invoiceReceivables' );
  6450. $invoiceReceivables = new invoiceReceivables ();
  6451. Doo::loadClass ( 'XDeode' );
  6452. $XDeode = new XDeode ( 5 );
  6453. if (! empty ( $receivablesPrice ) && ! empty ( $iidKey )) {
  6454. $iidKey = $XDeode->decode ( $iidKey );
  6455. $info = $invoice->getInvoiceByIid ( $iidKey );
  6456. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $info ['irid'] );
  6457. if (empty ( $irList ))
  6458. $irList [0] ['sumPrice'] = 0;
  6459. $balance = $info ['invoicePrice'] - $irList [0] ['sumPrice'];
  6460. if ($balance < $receivablesPrice) {
  6461. echo json_encode ( array (
  6462. 'error' => '收款金额超过开票金额。'
  6463. ) );
  6464. die ();
  6465. }
  6466. if ($balance > $receivablesPrice) {
  6467. echo json_encode ( array (
  6468. 'error' => '收款金额低于开票金额。'
  6469. ) );
  6470. die ();
  6471. }
  6472. }
  6473. }
  6474. function ajaxGetInvoiceByNew() {
  6475. Doo::loadModel ( 'invoice' );
  6476. $invoice = new invoice ();
  6477. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );
  6478. echo json_encode ( array (
  6479. 'status' => 1,
  6480. 'detail' => $detail
  6481. ) );
  6482. }
  6483. /**
  6484. * 旧输入导入
  6485. */
  6486. function importInvoice() {
  6487. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  6488. $data ['emsg'] = "";
  6489. if ($emsg != "")
  6490. $data ['emsg'] = "请填写完整的数据";
  6491. $data ['time'] = time ();
  6492. $this->render ( "/admin/invoiceImport", $data );
  6493. }
  6494. function uploadInvoice() {
  6495. // move_uploaded_file($_FILES['Filedata']['tmp_name'], "/upload/".$_FILES['Filedata']['name']);
  6496. if (isset ( $_FILES ['Filedata'] ['name'] )) {
  6497. $file = $_FILES ['Filedata'] ['tmp_name'];
  6498. $error = false;
  6499. if (! is_uploaded_file ( $file )) {
  6500. $error = '400 Bad Request';
  6501. }
  6502. if ($error) {
  6503. header ( 'HTTP/1.0 ' . $error );
  6504. die ( 'Error ' . $error );
  6505. } else {
  6506. include (DOO::conf ()->SITE_PATH . 'protected/plugin/io.han.php');
  6507. $this->IoHandler = new IoHandler ();
  6508. $pics = explode ( '.', $_FILES ['Filedata'] ['name'] );
  6509. // $filedir=$_POST['time'];
  6510. // 调用定义物理路径
  6511. $t = DOO::conf ()->SITE_PATH . "upload/invoice/";
  6512. $this->IoHandler->MakeDir ( $t );
  6513. $filename = $this->_GetFileEXT ( $_FILES ['Filedata'] ['name'] );
  6514. if ($filename != 'xlsx')
  6515. return "";
  6516. // $upload_dir = $t."/".time().rand(10,100).".".$filename;
  6517. $upload_file = iconv ( "UTF-8", "GB2312", $_FILES ["Filedata"] ["name"] );
  6518. $upload_dir = $t . "/" . $upload_file;
  6519. $k = move_uploaded_file ( $file, $upload_dir );
  6520. if ($k) {
  6521. $m = round ( $_FILES ['Filedata'] ['size'] / 1024 / 1024, 2 );
  6522. echo $pics [0] . "." . $filename . "#" . $m . "#" . $_FILES ['Filedata'] ['size'];
  6523. }
  6524. }
  6525. }
  6526. }
  6527. function importInvoiceDo() {
  6528. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  6529. if ($path != "") {
  6530. Doo::loadModel ( 'invoice' );
  6531. Doo::loadModel ( 'staff' );
  6532. $staff = new staff ();
  6533. Doo::loadModel ( 'invoiceStatistics' );
  6534. Doo::loadModel ( 'invoiceOperationLog' );
  6535. echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  6536. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . $path );
  6537. // print_r ( $exlArray );
  6538. // die ();
  6539. // echo json_encode($exlArray);die;
  6540. foreach ( $exlArray as $key => $value ) {
  6541. // 开票
  6542. $invoice = new invoice ();
  6543. $invoice->invoiceNo = $value ['invoiceNo'];
  6544. $invoice->invoiceType = 0;
  6545. if ($value ['invoiceType'] == '专')
  6546. $invoice->invoiceType = 1;
  6547. $invoice->invoicePrice = $value ['invoicePrice'];
  6548. $invoice->invoiceQuantity = 1;
  6549. $invoice->invoiceUnitPrice = $value ['invoicePrice'];
  6550. $invoice->invoiceTitle = $value ['invoiceTitle'];
  6551. if ($value ['invoiceType'] == '专')
  6552. $invoice->invoiceCompany = $value ['invoiceTitle'];
  6553. $invoice->userName = $value ['userName'];
  6554. $sDetail = $staff->getStaffByName ( $value ['userName'] );
  6555. $invoice->sid = $sDetail ['sid'];
  6556. $invoice->cid = $sDetail ['cid'];
  6557. $invoice->categoryName = $sDetail ['category'];
  6558. $invoice->invoiceElement = $value ['invoiceElement'];
  6559. $invoice->remark = $value ['remark'];
  6560. $invoice->date = $value ['date'];
  6561. $invoice->printTime = $value ['date'];
  6562. $invoice->ipSource = 1;
  6563. $invoice->printStatus = 1;
  6564. $invoice->status = 2;
  6565. $invoice->postStatus = 1;
  6566. $invoice->untreadStatus = 0;
  6567. $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  6568. $iid = $invoice->insert ();
  6569. // 汇总
  6570. $invoiceStatistics = new invoiceStatistics ();
  6571. //
  6572. $item = array (
  6573. 'date' => $value ['date'],
  6574. 'priceClass' => 1,
  6575. 'cid' => $sDetail ['cid'],
  6576. 'staff' => $sDetail ['sid'],
  6577. 'invoicePrice' => $value ['invoicePrice']
  6578. );
  6579. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  6580. $invoiceOperationLog = new invoiceOperationLog ();
  6581. $item = array (
  6582. 'date' => date ( "Y-m-d H:i:s" ),
  6583. 'operation' => date ( "Y-m-d" ) . " 导入",
  6584. 'status' => 1,
  6585. 'img' => $sDetail ['avatar'],
  6586. 'username' => $sDetail ['username'],
  6587. 'uid' => $sDetail ['sid'],
  6588. 'category' => $sDetail ['category'],
  6589. 'iid' => $iid
  6590. );
  6591. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  6592. }
  6593. return '/importInvoice?count=' . count ( $exlArray );
  6594. // return "/keyonline";
  6595. }
  6596. echo 'no file';
  6597. }
  6598. function importInvoiceReceivables() {
  6599. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  6600. $data ['emsg'] = "";
  6601. if ($emsg != "")
  6602. $data ['emsg'] = "请填写完整的数据";
  6603. $data ['time'] = time ();
  6604. $this->render ( "/admin/invoiceReceivablesImport", $data );
  6605. }
  6606. // 导入入账数据
  6607. function importInvoiceReceivablesDo() {
  6608. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  6609. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  6610. if ($path != "") {
  6611. Doo::loadModel ( 'invoiceReceivables' );
  6612. Doo::loadModel ( 'invoice' );
  6613. Doo::loadModel ( 'staff' );
  6614. $staff = new staff ();
  6615. Doo::loadModel ( 'invoiceStatistics' );
  6616. // echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  6617. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path ), 'invoiceReceivables' );
  6618. // print_r ( $exlArray );
  6619. // die ();
  6620. // echo json_encode($exlArray);die;
  6621. foreach ( $exlArray as $key => $value ) {
  6622. // 收款
  6623. $invoiceReceivables = new invoiceReceivables ();
  6624. $invoice = new invoice ();
  6625. $invoiceReceivables->bindStatus = 1;
  6626. $invoiceReceivables->receivablesPrice = $value ['receivablesPrice'];
  6627. $invoiceReceivables->receivablesMessage = $value ['receivablesMessage'];
  6628. $invoiceReceivables->receivablesBank = $value ['receivablesBank'];
  6629. $invoiceReceivables->receivablesDate = $value ['receivablesDate'];
  6630. $sDetail = $staff->getStaffByName ( $value ['receivablesStaff'] );
  6631. $invoiceReceivables->receivablesCategory = $sDetail ['cid'] . ':' . $sDetail ['category'];
  6632. $invoiceReceivables->receivablesStaff = $sDetail ['sid'] . '-' . $sDetail ['username'];
  6633. $invoiceReceivables->receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  6634. $invoiceReceivables->sourcePrice = $value ['sourcePrice'];
  6635. $iDetail = $invoice->getInvoiceByInvoiceNo ( $value ['invoiceNo'] );
  6636. $invoiceReceivables->iid = $iDetail ['iid'];
  6637. $irid = $invoiceReceivables->insert ();
  6638. // 发票绑定收款
  6639. $detail = $iDetail;
  6640. $iridString = "";
  6641. if (empty ( $detail ['irid'] ))
  6642. $iridString = $irid;
  6643. else
  6644. $iridString = $detail ['irid'] . ',' . $irid;
  6645. $item = array (
  6646. 'irid' => $iridString,
  6647. 'iid' => $detail ['iid']
  6648. );
  6649. $invoice->setInvoiceByCondition ( $item );
  6650. // 汇总
  6651. $invoiceStatistics = new invoiceStatistics ();
  6652. // 扣除入账统计金额
  6653. $item = array (
  6654. 'date' => $value ['receivablesDate'],
  6655. 'priceClass' => 3,
  6656. 'cid' => $sDetail ['cid'],
  6657. 'staff' => $sDetail ['sid'],
  6658. // 'irid' => $irid,
  6659. 'accountPrice' => $value ['receivablesPrice']
  6660. );
  6661. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  6662. }
  6663. return '/importInvoiceReceivables?count=' . count ( $exlArray );
  6664. echo 'data count ' . count ( $exlArray );
  6665. die ();
  6666. // return "/keyonline";
  6667. }
  6668. echo 'no file';
  6669. }
  6670. function formatExcelToArrayTrain($file_url = "") {
  6671. if (! file_exists ( $file_url )) {
  6672. return array ();
  6673. }
  6674. // Doo::loadClass ( 'PHPExcel' );
  6675. Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  6676. $PHPExcel = new PHPExcel ();
  6677. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  6678. if (! $PHPReader->canRead ( $file_url )) {
  6679. $PHPReader = new PHPExcel_Reader_Excel5 ();
  6680. if (! $PHPReader->canRead ( $file_url )) {
  6681. echo 'no Excel';
  6682. return;
  6683. }
  6684. }
  6685. $PHPExcel = $PHPReader->load ( $file_url );
  6686. /* * 读取excel文件中的第一个工作表 */
  6687. $currentSheet = $PHPExcel->getSheet ( 0 );
  6688. /* * 取得最大的列号 */
  6689. $allColumn = $currentSheet->getHighestColumn ();
  6690. /* * 取得一共有多少行 */
  6691. $allRow = $currentSheet->getHighestRow ();
  6692. $excel_array = array ();
  6693. // die($file_url);
  6694. $conk = 2;
  6695. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  6696. $excel_column = array ();
  6697. // 后期改进
  6698. if ($allColumn == 'AM')
  6699. $allColumn = 'Z';
  6700. /* * 从第A列开始输出 */
  6701. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  6702. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  6703. if ($val instanceof PHPExcel_RichText)
  6704. $val = $val->__toString ();
  6705. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  6706. // $val = "'" . addslashes ( $val ) . "'";
  6707. if ($currentColumn == 'A') {
  6708. $excel_column ['invoiceTitle'] = $val;
  6709. } elseif ($currentColumn == 'B')
  6710. $excel_column ['invoiceType'] = $val;
  6711. elseif ($currentColumn == 'C') {
  6712. $excel_column ['TIN'] = $val;
  6713. } elseif ($currentColumn == 'D') {
  6714. $excel_column ['address'] = $val;
  6715. } elseif ($currentColumn == 'E') {
  6716. $excel_column ['phone'] = $val;
  6717. } elseif ($currentColumn == 'F') {
  6718. $excel_column ['bank'] = $val;
  6719. } elseif ($currentColumn == 'G') {
  6720. $excel_column ['bankAccount'] = $val;
  6721. } elseif ($currentColumn == 'H') {
  6722. $excel_column ['invoiceElement'] = $val;
  6723. } elseif ($currentColumn == 'I') {
  6724. $excel_column ['invoiceQuantity'] = $val;
  6725. } elseif ($currentColumn == 'J') {
  6726. $excel_column ['invoiceUnitPrice'] = $val;
  6727. } elseif ($currentColumn == 'K') {
  6728. $excel_column ['remark'] = $val;
  6729. } elseif ($currentColumn == 'L') {
  6730. $excel_column ['recipientsAddress'] = $val;
  6731. } elseif ($currentColumn == 'M') {
  6732. $excel_column ['recipients'] = $val;
  6733. } elseif ($currentColumn == 'N') {
  6734. $excel_column ['recipientsPhone'] = $val;
  6735. }
  6736. }
  6737. if (! empty ( $excel_column ['invoiceTitle'] ) && ! empty ( $excel_column ['invoiceQuantity'] ) && ! empty ( $excel_column ['invoiceUnitPrice'] ))
  6738. array_push ( $excel_array, $excel_column );
  6739. }
  6740. return $excel_array;
  6741. }
  6742. /**
  6743. * 格式化excel文件为数组
  6744. * @param unknown_type $file_url
  6745. * @param unknown_type $mcid
  6746. */
  6747. function _format_excel_to_array($file_url = "", $sType = "") {
  6748. if (! file_exists ( $file_url )) {
  6749. return array ();
  6750. }
  6751. Doo::loadClass ( 'PHPExcel' );
  6752. // Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  6753. $PHPExcel = new PHPExcel ();
  6754. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  6755. if (! $PHPReader->canRead ( $file_url )) {
  6756. $PHPReader = new PHPExcel_Reader_Excel5 ();
  6757. if (! $PHPReader->canRead ( $file_url )) {
  6758. echo 'no Excel';
  6759. return;
  6760. }
  6761. }
  6762. $PHPExcel = $PHPReader->load ( $file_url );
  6763. /* * 读取excel文件中的第一个工作表 */
  6764. $currentSheet = $PHPExcel->getSheet ( 0 );
  6765. /* * 取得最大的列号 */
  6766. $allColumn = $currentSheet->getHighestColumn ();
  6767. /* * 取得一共有多少行 */
  6768. $allRow = $currentSheet->getHighestRow ();
  6769. $excel_array = array ();
  6770. // die($file_url);
  6771. $conk = 2;
  6772. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  6773. $excel_column = array ();
  6774. // 后期改进
  6775. if ($allColumn == 'AM')
  6776. $allColumn = 'Z';
  6777. /* * 从第A列开始输出 */
  6778. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  6779. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  6780. if ($val instanceof PHPExcel_RichText)
  6781. $val = $val->__toString ();
  6782. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  6783. // $val = "'" . addslashes ( $val ) . "'";
  6784. if ($sType == 'invoiceReceivables') {
  6785. if ($currentColumn == 'A')
  6786. $excel_column ['invoiceNo'] = $val;
  6787. elseif ($currentColumn == 'B')
  6788. $excel_column ['receivablesPrice'] = $val;
  6789. elseif ($currentColumn == 'C') {
  6790. $excel_column ['receivablesMessage'] = $val;
  6791. } elseif ($currentColumn == 'D') {
  6792. $excel_column ['receivablesBank'] = $val;
  6793. } elseif ($currentColumn == 'E') {
  6794. $excel_column ['receivablesDate'] = $this->excelTime ( $val );
  6795. } elseif ($currentColumn == 'F') {
  6796. $excel_column ['receivablesStaff'] = $val;
  6797. } elseif ($currentColumn == 'G') {
  6798. $excel_column ['sourcePrice'] = $val;
  6799. }
  6800. } elseif ($sType == "invoiceTrain") {
  6801. if ($currentColumn == 'A') {
  6802. $excel_column ['invoiceTitle'] = $val;
  6803. } elseif ($currentColumn == 'B')
  6804. $excel_column ['invoiceType'] = $val;
  6805. elseif ($currentColumn == 'C') {
  6806. $excel_column ['TIN'] = $val;
  6807. } elseif ($currentColumn == 'D') {
  6808. $excel_column ['address'] = $val;
  6809. } elseif ($currentColumn == 'E') {
  6810. $excel_column ['phone'] = $val;
  6811. } elseif ($currentColumn == 'F') {
  6812. $excel_column ['bank'] = $val;
  6813. } elseif ($currentColumn == 'G') {
  6814. $excel_column ['bankAccount'] = $val;
  6815. } elseif ($currentColumn == 'H') {
  6816. $excel_column ['invoiceElement'] = $val;
  6817. } elseif ($currentColumn == 'I') {
  6818. $excel_column ['invoiceQuantity'] = $val;
  6819. } elseif ($currentColumn == 'J') {
  6820. $excel_column ['invoiceUnitPrice'] = $val;
  6821. } elseif ($currentColumn == 'K') {
  6822. $excel_column ['remark'] = $val;
  6823. } elseif ($currentColumn == 'L') {
  6824. $excel_column ['recipientsAddress'] = $val;
  6825. } elseif ($currentColumn == 'M') {
  6826. $excel_column ['recipients'] = $val;
  6827. } elseif ($currentColumn == 'N') {
  6828. $excel_column ['recipientsPhone'] = $val;
  6829. }
  6830. } else {
  6831. if ($currentColumn == 'A')
  6832. $excel_column ['invoiceNo'] = $val;
  6833. elseif ($currentColumn == 'B')
  6834. $excel_column ['invoiceType'] = $val;
  6835. elseif ($currentColumn == 'C') {
  6836. $excel_column ['invoicePrice'] = $val;
  6837. } elseif ($currentColumn == 'D') {
  6838. $excel_column ['invoiceTitle'] = $val;
  6839. } elseif ($currentColumn == 'E') {
  6840. $excel_column ['userName'] = $val;
  6841. } elseif ($currentColumn == 'F') {
  6842. $excel_column ['categoryName'] = $val;
  6843. } elseif ($currentColumn == 'G') {
  6844. $excel_column ['invoiceElement'] = $val;
  6845. } elseif ($currentColumn == 'H') {
  6846. $excel_column ['remark'] = $val;
  6847. } elseif ($currentColumn == 'I') {
  6848. $excel_column ['date'] = $this->excelTime ( $val );
  6849. }
  6850. }
  6851. }
  6852. array_push ( $excel_array, $excel_column );
  6853. }
  6854. return $excel_array;
  6855. }
  6856. function excelTime($date, $time = false) {
  6857. if (function_exists ( 'GregorianToJD' )) {
  6858. if (is_numeric ( $date )) {
  6859. $jd = GregorianToJD ( 1, 1, 1970 );
  6860. $gregorian = JDToGregorian ( $jd + intval ( $date ) - 25569 );
  6861. $date = explode ( '/', $gregorian );
  6862. $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" : '');
  6863. return $date_str;
  6864. }
  6865. } else {
  6866. $date = $date > 25568 ? $date + 1 : 25569;
  6867. /* There was a bug if Converting date before 1-1-1970 (tstamp 0) */
  6868. $ofs = (70 * 365 + 17 + 2) * 86400;
  6869. $date = date ( "Y-m-d", ($date * 86400) - $ofs ) . ($time ? " 00:00:00" : '');
  6870. }
  6871. return $date;
  6872. }
  6873. /**
  6874. * 旧输入导入
  6875. */
  6876. function _GetFileEXT($filename) {
  6877. $pics = explode ( '.', $filename );
  6878. $num = count ( $pics );
  6879. return $pics [$num - 1];
  6880. }
  6881. function showCache($path = "", $sid = 0) {
  6882. // if (file_exists ( $path )) {
  6883. // $htm = file_get_contents ( $path );
  6884. // } else {
  6885. Doo::loadModel ( 'invoiceStatistics' );
  6886. $invoiceStatistics = new invoiceStatistics ();
  6887. $isBriefly = $invoiceStatistics->getBrieflyStatistics ( $sid );
  6888. $htm = '<tr><th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计开票</th>
  6889. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['invoicePrice'] . '</td>
  6890. <th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计入账</th>
  6891. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['accountPrice'] . '</td></tr>';
  6892. /*
  6893. * '<tr><th class="taC">今年累计开票</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['invoicePrice'] . '</td> <th class="taC">今年累计入账</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['accountPrice'] . '</td></tr>';
  6894. */
  6895. file_put_contents ( $path, $htm );
  6896. // }
  6897. return $htm;
  6898. }
  6899. /**
  6900. * 生成token
  6901. * @return string
  6902. */
  6903. function set_token() {
  6904. $str = md5 ( uniqid ( md5 ( microtime ( true ) ), true ) ); // 生成一个不会重复的字符串
  6905. $str = sha1 ( $str ); // 加密
  6906. return $str;
  6907. }
  6908. /**
  6909. * 获取get或者POST值
  6910. *
  6911. * @param string $name 属性名称
  6912. * @return fixed 值
  6913. */
  6914. function get_args($name) {
  6915. if (isset ( $_GET [$name] )) {
  6916. if (is_array ( $_GET [$name] ))
  6917. return $_GET [$name];
  6918. else
  6919. return addslashes ( $_GET [$name] );
  6920. } elseif (isset ( $_POST [$name] )) {
  6921. if (is_array ( $_POST [$name] ))
  6922. return $_POST [$name];
  6923. else
  6924. return addslashes ( $_POST [$name] );
  6925. } else
  6926. return false;
  6927. }
  6928. function SafeFilter(&$arr) {
  6929. $ra = Array (
  6930. '/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/',
  6931. '/script/',
  6932. '/javascript/',
  6933. '/vbscript/',
  6934. '/expression/',
  6935. '/applet/',
  6936. '/meta/',
  6937. '/xml/',
  6938. '/blink/',
  6939. '/link/',
  6940. '/style/',
  6941. '/embed/',
  6942. '/object/',
  6943. '/frame/',
  6944. '/layer/',
  6945. '/title/',
  6946. '/bgsound/',
  6947. '/base/',
  6948. '/onload/',
  6949. '/onunload/',
  6950. '/onchange/',
  6951. '/onsubmit/',
  6952. '/onreset/',
  6953. '/onselect/',
  6954. '/onblur/',
  6955. '/onfocus/',
  6956. '/onabort/',
  6957. '/onkeydown/',
  6958. '/onkeypress/',
  6959. '/onkeyup/',
  6960. '/onclick/',
  6961. '/ondblclick/',
  6962. '/onmousedown/',
  6963. '/onmousemove/',
  6964. '/onmouseout/',
  6965. '/onmouseover/',
  6966. '/onmouseup/',
  6967. '/onunload/'
  6968. );
  6969. if (is_array ( $arr )) {
  6970. foreach ( $arr as $key => $value ) {
  6971. if (! is_array ( $value )) {
  6972. if (! get_magic_quotes_gpc ()) // 不对magic_quotes_gpc转义过的字符使用addslashes(),避免双重转义。
  6973. {
  6974. $value = addslashes ( $value ); // 给单引号(')、双引号(")、反斜线(\)与 NUL(NULL 字符)加上反斜线转义
  6975. }
  6976. $value = preg_replace ( $ra, '', $value ); // 删除非打印字符,粗暴式过滤xss可疑字符串
  6977. $arr [$key] = htmlentities ( strip_tags ( $value ) ); // 去除 HTML 和 PHP 标记并转换为 HTML 实体
  6978. } else {
  6979. SafeFilter ( $arr [$key] );
  6980. }
  6981. }
  6982. }
  6983. }
  6984. /**
  6985. * Escape String
  6986. *
  6987. * @access public
  6988. * @param string
  6989. * @param bool whether or not the string will be used in a LIKE condition
  6990. * @return string
  6991. */
  6992. function escape_str($str, $like = FALSE) {
  6993. if (is_array ( $str )) {
  6994. foreach ( $str as $key => $val ) {
  6995. $str [$key] = $this->escape_str ( $val, $like );
  6996. }
  6997. return $str;
  6998. }
  6999. var_dump ( Doo::db ()->getDbObject () );
  7000. die ();
  7001. if (function_exists ( 'mysql_real_escape_string' ) and is_resource ( Doo::db ()->getDbObject () )) { // Doo::db ()->getDbObject()
  7002. $str = mysql_real_escape_string ( $str, Doo::db ()->getDbObject () );
  7003. } elseif (function_exists ( 'mysql_escape_string' )) {
  7004. $str = mysql_escape_string ( $str );
  7005. } else {
  7006. $str = addslashes ( $str );
  7007. }
  7008. // escape LIKE condition wildcards
  7009. if ($like === TRUE) {
  7010. $str = str_replace ( array (
  7011. '%',
  7012. '_'
  7013. ), array (
  7014. '\\%',
  7015. '\\_'
  7016. ), $str );
  7017. }
  7018. return $str;
  7019. }
  7020. /**
  7021. * 获得分页数据
  7022. * @param unknown_type $table
  7023. * @param unknown_type $condition
  7024. * @param unknown_type $on_page
  7025. * @param unknown_type $page_size
  7026. */
  7027. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  7028. $page_c = "";
  7029. $page ['previous'] = $this->get_previous ( $on_page );
  7030. $page ['on_page'] = $on_page;
  7031. $total_count = $this->get_table_count ( $table, $condition );
  7032. $total = intval ( $total_count / $page_size );
  7033. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  7034. $page ['total_data'] = $total_count;
  7035. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  7036. $i = 1;
  7037. $page_max = 1;
  7038. $page_width = 3;
  7039. if ($on_page >= $page_width) {
  7040. $page_max = intval ( $on_page / $page_width ) + 1;
  7041. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  7042. }
  7043. for(; $i <= $page ['total_page']; $i ++) {
  7044. if ($i == $on_page)
  7045. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  7046. else
  7047. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  7048. if ($i == ($page_width * $page_max))
  7049. break;
  7050. }
  7051. $page ['page'] = $page_c;
  7052. $page ['lower'] = (-- $on_page) * $page_size;
  7053. return $page;
  7054. }
  7055. /**
  7056. * 获取上一页
  7057. * @param unknown_type $on_page
  7058. */
  7059. function get_previous($on_page = 1) {
  7060. return $on_page != 0 ? $on_page - 1 : $on_page;
  7061. }
  7062. /**
  7063. * 获取总页数
  7064. * @param unknown_type $table
  7065. * @param unknown_type $condition
  7066. */
  7067. public function get_table_count($table = "", $condition = "") {
  7068. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  7069. $sql = "select count(*) as count from " . $table . " where " . $condition;
  7070. // echo $sql;die;
  7071. $query = Doo::db ()->query ( $sql );
  7072. $result = $query->fetch ();
  7073. return $result ['count'];
  7074. }
  7075. function isInvoiceNew($type = "GLOBAL") {
  7076. Doo::loadModel ( 'invoice' );
  7077. $invoice = new invoice ();
  7078. Doo::loadModel ( 'invoiceReceivables' );
  7079. $invoiceReceivables = new invoiceReceivables ();
  7080. Doo::loadModel ( 'staff' );
  7081. $staff = new staff ();
  7082. $st = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  7083. // 我的发票待处理
  7084. $pendingInvoice = $invoice->getOne ( array ( // or (status=2 and printStatus=1 and untreadStatus=0 ) or (status=2 and printStatus=1 and untreadStatus=2 )
  7085. 'where' => "(status=3 or status=4) and isDelete=0 and sid=" . $st [0] ['sid'],
  7086. 'desc' => 'iid',
  7087. 'asArray' => TRUE
  7088. ) );
  7089. // 我的收款待入账
  7090. /*
  7091. * $myClaim = $invoiceReceivables->getOne ( array ( 'where' => " receivablesStaff like '" . $st [0] ['sid'] . "-%' and receivablesCategory like '" . $st [0] ['cid'] . ":%' and bindStatus=0", 'desc' => 'irid', 'asArray' => TRUE ) );
  7092. */
  7093. // 发票审批
  7094. $approval = $invoice->getOne ( array (
  7095. 'where' => 'status=1 and pendingApprovals=' . $st [0] ['sid'],
  7096. 'desc' => 'iid',
  7097. 'asArray' => true
  7098. ) );
  7099. // 发票邮寄
  7100. $post = $invoice->getOne ( array (
  7101. 'where' => "postStatus=0 and printStatus=1 and isDelete=0 and doPost=1 and status=2",
  7102. 'asArray' => TRUE
  7103. ) );
  7104. // 发票打印
  7105. $print = $invoice->getOne ( array (
  7106. 'where' => "status=2 and printStatus=0 and untreadStatus=0 and moldManage like '%[\"" . $st [0] ['sid'] . "\",%'",
  7107. 'desc' => 'iid',
  7108. 'asArray' => TRUE
  7109. ) );
  7110. // 发票退票 printStatus=1 and
  7111. $untread = $invoice->getOne ( array (
  7112. 'where' => " untreadStatus=1 and status=2 ",
  7113. 'asArray' => TRUE
  7114. ) );
  7115. $new = array (
  7116. 'GLOBAL' => FALSE,
  7117. 'pendingInvoice' => FALSE,
  7118. // 'myClaim' => FALSE,
  7119. 'approval' => FALSE,
  7120. 'post' => FALSE,
  7121. 'print' => FALSE,
  7122. 'untread' => FALSE
  7123. );
  7124. // || ! empty ( $myClaim )
  7125. if (! empty ( $pendingInvoice ) || ! empty ( $approval ) || ! empty ( $post ) || ! empty ( $print ) || ! empty ( $untread ))
  7126. $new ['GLOBAL'] = TRUE;
  7127. if (! empty ( $pendingInvoice ))
  7128. $new ['pendingInvoice'] = TRUE;
  7129. // if (! empty ( $myClaim ))
  7130. // $new ['myClaim'] = TRUE;
  7131. if (! empty ( $approval ))
  7132. $new ['approval'] = TRUE;
  7133. if (! empty ( $post ))
  7134. $new ['post'] = TRUE;
  7135. if (! empty ( $print ))
  7136. $new ['print'] = TRUE;
  7137. if (! empty ( $untread ))
  7138. $new ['untread'] = TRUE;
  7139. return $new;
  7140. }
  7141. function setWXMsg($rid, $typeMsg = '') {
  7142. Doo::loadModel ( 'invoice' );
  7143. $invoice = new invoice ();
  7144. $invoiceDetail = $invoice->getOne ( array (
  7145. 'where' => 'iid=' . $rid,
  7146. 'asArray' => true
  7147. ) );
  7148. if (! empty ( $invoiceDetail )) {
  7149. Doo::loadModel ( 'staff' );
  7150. $staff = new staff ();
  7151. $staffmsg = $staff->getOne ( array (
  7152. 'where' => "sid='" . $invoiceDetail ['sid'] . "'",
  7153. 'asArray' => TRUE
  7154. ) );
  7155. if (! empty ( $staffmsg ['wxid'] )) {
  7156. require_once (SITE_PATH . '/protected/class/client.php');
  7157. $client = new client ( 'http://m.cld.smartcost.com.cn/' );
  7158. $user = $staffmsg ['wxid'];
  7159. $expCom = explode ( ":", $invoiceDetail ['expressCompany'] );
  7160. if (empty ( $expCom ))
  7161. $expCom [0] = '';
  7162. $msg = "";
  7163. if (empty ( $typeMsg ))
  7164. $msg = '太好了,您的发票' . $invoiceDetail ['invoiceSerial'] . ' 已邮寄 ' . $expCom [0] . ' ,快递号: <a href="https://m.kuaidi100.com/result.jsp?nu=' . $invoiceDetail ['expressNumber'] . '" >' . $invoiceDetail ['expressNumber'] . '</a>';
  7165. elseif ($typeMsg == "PRINT")
  7166. $msg = '太好了,您的发票已打印完成。';
  7167. $result = $client->SendMsg ( $user, $msg, 'text' );
  7168. }
  7169. }
  7170. }
  7171. /**
  7172. * 获取微信部门
  7173. * @param string $category
  7174. * @return number|mixed
  7175. */
  7176. function getToparty($category = '') {
  7177. $token = $this->getAccessToken (); //
  7178. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token={$token}&id=5" ), true );
  7179. $toparty = 0;
  7180. foreach ( $result ['department'] as $key => $value ) {
  7181. if ($value ['name'] == $category)
  7182. $toparty = $value ['id'];
  7183. }
  7184. return $toparty;
  7185. }
  7186. /**
  7187. * 获得某部门下的用户
  7188. * @param string $toparty
  7189. */
  7190. function getUserByToparty($toparty = '') {
  7191. $token = $this->getAccessToken (); //
  7192. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token={$token}&department_id={$toparty}" ), true );
  7193. $userList = array ();
  7194. foreach ( $result ['userlist'] as $key => $value ) {
  7195. array_push ( $userList, "'" . $value ['userid'] . "'" );
  7196. }
  7197. return $userList;
  7198. }
  7199. function msgSendToparty($msg, $title, $url, $toparty, $text = '') {
  7200. $token = $this->getAccessToken ();
  7201. if ($text == 'text') {
  7202. $data = '{
  7203. "touser": "' . $toparty . '",
  7204. "toparty": "",
  7205. "totag": "",
  7206. "msgtype": "text",
  7207. "agentid": 1000002,
  7208. "text": {
  7209. "content": "' . $msg . '"
  7210. },
  7211. "safe":0
  7212. }';
  7213. }
  7214. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  7215. if ($result->errmsg != 'ok') {
  7216. return 0;
  7217. } else {
  7218. return 1;
  7219. }
  7220. }
  7221. /**
  7222. * 获得可以发送微信用户列表
  7223. * @param string $category
  7224. * @return string
  7225. */
  7226. function getWxidByCategory($category = "") {
  7227. if (empty ( $category ))
  7228. return "";
  7229. Doo::loadModel ( 'staff' );
  7230. $staff = new staff ();
  7231. $toparty = $this->getToparty ( $category );
  7232. $wxList = array ();
  7233. $wxString = "";
  7234. if (! empty ( $toparty )) {
  7235. $userList = $this->getUserByToparty ( $toparty );
  7236. $userCon = implode ( ',', $userList );
  7237. // echo $userCon;
  7238. $sidList = $staff->getStaffByWxid ( $userCon );
  7239. foreach ( $sidList as $key => $value ) {
  7240. $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  7241. if ($falg) {
  7242. array_push ( $wxList, $value ['wxid'] );
  7243. }
  7244. }
  7245. $wxString = implode ( '|', $wxList );
  7246. }
  7247. return $wxString;
  7248. }
  7249. /**
  7250. * 读取发送信息规则判断是否需要发送
  7251. * @param number $sid
  7252. * @param string $sendType
  7253. * @return boolean
  7254. */
  7255. function isSendNotification($sid = 0, $sendType = '') {
  7256. Doo::loadModel ( "notificationConf" );
  7257. $notificationConf = new notificationConf ();
  7258. $detail = $notificationConf->getNotificationConfBySid ( $sid );
  7259. $conf = array ();
  7260. $sendFlag = true;
  7261. if (! empty ( $detail )) {
  7262. $conf = json_decode ( $detail ['conf'], true );
  7263. if (! empty ( $sendType )) {
  7264. if (isset ( $conf [$sendType] )) {
  7265. if ($conf [$sendType] == "CLOSE")
  7266. $sendFlag = false;
  7267. elseif ($conf [$sendType] == "Weekend") {
  7268. $day = date ( "w" );
  7269. if (1 <= $day && 5 >= $day)
  7270. $sendFlag = false;
  7271. } elseif ($conf [$sendType] == "OneToFriday") {
  7272. $day = date ( "w" );
  7273. if (0 == $day || 6 == $day)
  7274. $sendFlag = false;
  7275. }
  7276. }
  7277. } else
  7278. $sendFlag = false;
  7279. }
  7280. return $sendFlag;
  7281. }
  7282. /**
  7283. * 根据规则发送信息
  7284. * @param unknown $msg
  7285. * @param unknown $title
  7286. * @param unknown $url
  7287. * @param unknown $user
  7288. * @param string $text
  7289. * @return number
  7290. */
  7291. private function msgSend($msg, $title, $url, $user, $sid = 0, $sendType = '') {
  7292. $token = $this->getAccessToken ();
  7293. $falg = $this->isSendNotification ( $sid, $sendType );
  7294. // if ($text == 'text') {
  7295. // $data = '{
  7296. // "touser": "' . $user . '",
  7297. // "toparty": "",
  7298. // "totag": "",
  7299. // "msgtype": "text",
  7300. // "agentid": 1000002,
  7301. // "text": {
  7302. // "content": "' . $msg . '"
  7303. // },
  7304. // "safe":0
  7305. // }';
  7306. // } else {
  7307. $data = '{
  7308. "touser": "' . $user . '",
  7309. "toparty": "",
  7310. "totag": "",
  7311. "msgtype": "news",
  7312. "agentid": 1000002,
  7313. "news": {
  7314. "articles":[
  7315. {
  7316. "title": "' . $title . '",
  7317. "description": "' . $msg . '",
  7318. "url": "' . $url . '",
  7319. "picurl": ""
  7320. }
  7321. ]
  7322. }
  7323. }';
  7324. // }
  7325. if ($falg) {
  7326. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  7327. if ($result->errmsg != 'ok') {
  7328. return 0;
  7329. } else {
  7330. return 1;
  7331. }
  7332. } else
  7333. return 0;
  7334. }
  7335. private function getAccessToken() {
  7336. // access_token 应该全局存储与更新,以下代码以写入到文件中做示例
  7337. // $file = './access_token.txt';
  7338. // $data = json_decode ( file_get_contents ( $file ) );
  7339. // if ($data->expire_time < time () or ! $data->expire_time) {
  7340. // 如果是企业号用以下URL获取access_token
  7341. $url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$this->appId&corpsecret=$this->appSecret";
  7342. // $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$this->appId&secret=$this->appSecret";
  7343. $res = json_decode ( $this->httpGet ( $url ) );
  7344. $access_token = $res->access_token;
  7345. // echo $access_token;
  7346. // if ($access_token) {
  7347. // $data->expire_time = time () + 7000;
  7348. // $data->access_token = $access_token;
  7349. // $fp = fopen ( $file, "w" );
  7350. // fwrite ( $fp, json_encode ( $data ) );
  7351. // fclose ( $fp );
  7352. // }
  7353. // } else {
  7354. // $access_token = $data->access_token;
  7355. // }
  7356. return $access_token;
  7357. }
  7358. private function httpGet($url) {
  7359. $curl = curl_init ();
  7360. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  7361. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  7362. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  7363. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  7364. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  7365. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  7366. curl_setopt ( $curl, CURLOPT_URL, $url );
  7367. $res = curl_exec ( $curl );
  7368. curl_close ( $curl );
  7369. return $res;
  7370. }
  7371. private function httpPost($url, $data) {
  7372. $curl = curl_init ();
  7373. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  7374. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  7375. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  7376. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  7377. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  7378. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  7379. curl_setopt ( $curl, CURLOPT_URL, $url );
  7380. curl_setopt ( $curl, CURLOPT_POST, 1 );
  7381. curl_setopt ( $curl, CURLOPT_POSTFIELDS, $data );
  7382. $res = curl_exec ( $curl );
  7383. curl_close ( $curl );
  7384. return $res;
  7385. }
  7386. }
  7387. ?>