InvoiceController.php 314 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562
  1. <?php
  2. /**
  3. * 开票功能控制器
  4. * @author CP
  5. * @version 1.0
  6. * @namespace invoice
  7. * @package invoiceController
  8. */
  9. class InvoiceController extends DooController {
  10. public $staff;
  11. public $NEW;
  12. public $data;
  13. private $INVOICEKEY = "APPROVAL";
  14. private $INVOICECOLLECTPATH = "protected/cache/invoiceCollect/";
  15. private $ACTION = '';
  16. private $appId = 'wx3ee46531947a1384';
  17. private $appSecret = 'awGWzy3J5q_96VXKBLA2BQ9RpiT0LiPXnkMF-xV6h5o'; // awGWzy3J5q_96VXKBLA2BXU6mVCGynPGD-sxUCsdNDE //'PeiQVH8tbQE7pM9pVO4AIPlX9FFNpwu7O6Iy6VFcAVtpjTA3Qn42dbNmktBFkUHo';
  18. public function beforeRun($resource, $action) {
  19. Doo::loadModel ( "invoiceManage" );
  20. $invoiceManage = new invoiceManage ();
  21. Doo::loadClass ( 'XDeode' );
  22. $XDeode = new XDeode ( 5 );
  23. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  24. header ( 'Content-Type:text/html;charset=utf-8' );
  25. $moldList = $invoiceManage->getInvoiceByStaff ( $sid );
  26. if (empty ( $moldList )) {
  27. $flag = false;
  28. $uGroups = 'ordinary';
  29. if (Doo::acl ()->isAllowed ( $uGroups, $resource, $action )) {
  30. $flag = true;
  31. }
  32. } else {
  33. $flag = false;
  34. array_push ( $moldList, array (
  35. 'mold' => 'ordinary'
  36. ) );
  37. // 删除审批人后-加入权限问题-暂时关闭
  38. $fileInvoice = file_get_contents ( "protected/config/invoice/invoice.ini" );
  39. $fiML = json_decode ( $fileInvoice, true );
  40. if (empty ( $fiML ))
  41. $fiML = array ();
  42. foreach ( $fiML as $key => $value ) {
  43. $sidList = explode ( ',', $value );
  44. foreach ( $sidList as $k => $v ) {
  45. if ($v == $sid) {
  46. array_push ( $moldList, array (
  47. 'mold' => $key
  48. ) );
  49. break;
  50. }
  51. }
  52. }
  53. foreach ( $moldList as $value ) {
  54. if (Doo::acl ()->isAllowed ( $value ['mold'], $resource, $action )) {
  55. $flag = true;
  56. break;
  57. }
  58. }
  59. }
  60. /*
  61. * Doo::acl()->isAllowed($uGroups['groups'], $resource, $action);
  62. */
  63. // 单独判断办事处汇总的访问权限 invoiceAggregateCategoryDetail,invoiceAggregateStaffDetail
  64. if ($action == 'invoiceAggregateCategoryDetail' || $action == 'invoiceAggregateStaffDetail') {
  65. Doo::loadModel ( "invoiceCategoryManage" );
  66. $invoiceCategoryManage = new invoiceCategoryManage ();
  67. $icm = $invoiceCategoryManage->getInvoiceCMByStaff ( $sid );
  68. if (empty ( $icm ))
  69. die ( 'illegal request-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. $_SESSION ['token_' . $this->staff [0] ['sidKey']] = $token;
  250. $this->data ['token'] = $token;
  251. $this->data ['memu'] = "invoice";
  252. $this->data ['staff'] = $this->staff;
  253. $this->data ['receiptMemu'] = 'invoice';
  254. $this->render ( "/admin/invoiceAdd", $this->data );
  255. }
  256. /**
  257. * 自更新发票信息库
  258. * @param unknown $invoicePrintDetail
  259. */
  260. function autoUpdateInvoiceInfoBase($invoicePrintDetail) {
  261. // 发票信息库
  262. Doo::loadModel ( 'invoiceInfoBase' );
  263. $invoiceInfoBase = new invoiceInfoBase ();
  264. $updateDate = strtotime ( $invoicePrintDetail ['date'] );
  265. $TIN = $invoicePrintDetail ['TIN'];
  266. $invoiceTitle = $invoicePrintDetail ['invoiceTitle'];
  267. if (empty ( $invoiceTitle ))
  268. $invoiceTitle = $invoicePrintDetail ['invoiceCompany'];
  269. $IIBList = $invoiceInfoBase->getInvoiceInfoByTT ( $TIN, $invoiceTitle );
  270. // 确认有该条发票信息
  271. $invoiceInfoBase = new invoiceInfoBase ();
  272. if (! empty ( $IIBList )) {
  273. // 发票库里的信息数量
  274. $IIBListCount = count ( $IIBList );
  275. if ($IIBListCount == 1) { // 更新发票--提交是最新的时间
  276. $item = array (
  277. 'iibID' => $IIBList [0] ['iibID'],
  278. 'invoiceTitle' => $invoiceTitle,
  279. 'TIN' => $TIN
  280. );
  281. if (! empty ( $invoicePrintDetail ['address'] )) {
  282. $item += array (
  283. 'address' => $invoicePrintDetail ['address']
  284. );
  285. }
  286. if (! empty ( $invoicePrintDetail ['phone'] )) {
  287. $item += array (
  288. 'phone' => $invoicePrintDetail ['phone']
  289. );
  290. }
  291. if (! empty ( $invoicePrintDetail ['bank'] )) {
  292. $item += array (
  293. 'bank' => $invoicePrintDetail ['bank']
  294. );
  295. }
  296. if (! empty ( $invoicePrintDetail ['bankAccount'] )) {
  297. $item += array (
  298. 'bankAccount' => $invoicePrintDetail ['bankAccount']
  299. );
  300. }
  301. if ($updateDate >= strtotime ($IIBList [0] ['updateDate'])) {
  302. $item += array (
  303. 'updateDate' => $invoicePrintDetail ['date']
  304. );
  305. $invoiceInfoBase->setInvoiceInfoBaseByCondition ( $item );
  306. }
  307. } else { // 删除多张发票,重新添加发票
  308. $iibIDStr = '';
  309. $iibID = array ();
  310. foreach ( $IIBList as $key => $value ) {
  311. array_push ( $iibID, $value ['iibID'] );
  312. }
  313. $iibIDStr = implode ( ",", $iibID ); // 删除
  314. $invoiceInfoBase->delInvoiceInfoBaseByIibStr ( $iibIDStr );
  315. $item = array (
  316. 'invoiceTitle' => $invoiceTitle,
  317. 'TIN' => $TIN,
  318. 'address' => $invoicePrintDetail ['address'],
  319. 'phone' => $invoicePrintDetail ['phone'],
  320. 'bank' => $invoicePrintDetail ['bank'],
  321. 'bankAccount' => $invoicePrintDetail ['bankAccount'],
  322. 'updateDate' => $invoicePrintDetail ['date']
  323. );
  324. $invoiceInfoBase->addInvoiceInfoBase ( $item );
  325. }
  326. } else { // 没有新增发票信息
  327. $item = array (
  328. 'invoiceTitle' => $invoiceTitle,
  329. 'TIN' => $TIN,
  330. 'address' => $invoicePrintDetail ['address'],
  331. 'phone' => $invoicePrintDetail ['phone'],
  332. 'bank' => $invoicePrintDetail ['bank'],
  333. 'bankAccount' => $invoicePrintDetail ['bankAccount'],
  334. 'updateDate' => $invoicePrintDetail ['date']
  335. );
  336. $invoiceInfoBase->addInvoiceInfoBase ( $item );
  337. }
  338. }
  339. function invoiceAddFill() {
  340. session_start ();
  341. Doo::loadModel ( 'invoice' );
  342. $invoice = new invoice ();
  343. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );
  344. Doo::loadModel ( 'L_category' );
  345. $lCategory = new L_category ();
  346. $category = $lCategory->find ( array (
  347. 'asArray' => true
  348. ) );
  349. $this->data ['category'] = $category;
  350. Doo::loadModel ( 'invoiceTraining' );
  351. $invoiceTraining = new invoiceTraining ();
  352. $itList = $invoiceTraining->getInvoiceTrainingByCid ( $this->staff [0] ['cid'] );
  353. $this->data ['itList'] = $itList;
  354. Doo::loadModel ( 'invoice' );
  355. $invoice = new invoice ();
  356. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );
  357. $detail ['mailItemsArray'] = json_decode ( $detail ['mailItemsJson'], true );
  358. $token = $this->set_token ();
  359. $_SESSION ['token_' . $this->staff [0] ['sidKey']] = $token;
  360. $this->data ['token'] = $token;
  361. $this->data ['invoiceDetail'] = $detail;
  362. $this->data ['memu'] = "invoice";
  363. $this->data ['staff'] = $this->staff;
  364. $this->data ['receiptMemu'] = 'invoice';
  365. $this->render ( "/admin/invoiceAddFill", $this->data );
  366. }
  367. /**
  368. * 提交一份开票申请,并记录下操作日志
  369. *
  370. * @since 1.0.0
  371. * @var integer cid 办事处ID
  372. * @var integer invoiceType 发票类型
  373. * @var integer doPost 是否邮寄
  374. * @var integer invoicePrice 开票金额
  375. * @var string invoiceElement 开票内容
  376. * @var string invoiceTitle 发票抬头
  377. * @var string invoiceCompany 单位名称
  378. * @var string TIN 纳税人识别码
  379. * @var string address 注册地址
  380. * @var string phone 注册电话
  381. * @var string bank 开户银行
  382. * @var string bankAccount 银行账户
  383. * @var string recipients 收件人
  384. * @var string recipientsPhone 收件人手机/电话
  385. * @var string recipientsAddress 收件地址
  386. * @var string mailItems 邮寄物品
  387. * @var string remark 备注
  388. * @return string 返回跳转开票主页路径
  389. */
  390. function invoiceAddDo() {
  391. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  392. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  393. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  394. // $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  395. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  396. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  397. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  398. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  399. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  400. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  401. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  402. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  403. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  404. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  405. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  406. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  407. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  408. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  409. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  410. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  411. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  412. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  413. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  414. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  415. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  416. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  417. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  418. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  419. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  420. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  421. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  422. $trainId = $this->get_args ( 'trainId' ) ? $this->get_args ( 'trainId' ) : 0;
  423. $settlementType = $this->get_args ( 'settlementType' ) ? $this->get_args ( 'settlementType' ) : "";
  424. /*
  425. * $mailList=array(); array_push($mailList, array('invoice'=>1)); array_push($mailList, array('mailItems'=>$mailItems)); if (!empty($softLock)) array_push($mailList, array('softLock'=>$softLockNum)); if (!empty($contract)) array_push($mailList, array('contract'=>$contractNum)); if (!empty($instructions)) array_push($mailList, array('instructions'=>$instructionsNum)); if (!empty($remittance)) array_push($mailList, array('remittance'=>$remittance)); echo json_encode($mailList) ; print_r($mailList); die;
  426. */
  427. $token = $this->get_args ( 'token' ) ? $this->get_args ( 'token' ) : "";
  428. if (empty ( $token )) {
  429. die ( 'illegal request-token' );
  430. } else {
  431. session_start ();
  432. if ($_SESSION ['token_' . $this->staff [0] ['sidKey']] != $token) {
  433. header ( 'Content-Type:text/html;charset=utf-8' );
  434. die ( '请勿重复申请发票' );
  435. } else {
  436. $_SESSION ['token_' . $this->staff [0] ['sidKey']] = '';
  437. }
  438. }
  439. if ($invoiceType == 1) {
  440. $temporary = $invoiceQuantity * $invoiceUnitPrice;
  441. if ($temporary > 10000) {
  442. header ( 'Content-Type:text/html;charset=utf-8' );
  443. die ( '专用发票总金额暂时不能超过10000.00(一万)元。' );
  444. // die ( 'illegal request-Please priceError' );
  445. }
  446. }
  447. if (empty ( $this->staff [0] ))
  448. die ( 'illegal request-Please login' );
  449. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $settlementType )) {
  450. Doo::loadModel ( 'invoice' );
  451. $invoice = new invoice ();
  452. Doo::loadModel ( 'L_category' );
  453. $lCategory = new L_category ();
  454. Doo::loadModel ( 'invoiceManage' );
  455. $invoiceManage = new invoiceManage ();
  456. Doo::loadModel ( 'invoiceOperationLog' );
  457. $invoiceOperationLog = new invoiceOperationLog ();
  458. Doo::loadClass ( 'XDeode' );
  459. $XDeode = new XDeode ( 5 );
  460. $trainId = $XDeode->decode ( $trainId );
  461. $categoryDetil = $lCategory->getOne ( array (
  462. 'SELECT' => 'title',
  463. 'where' => 'cid=' . $cid,
  464. 'asArray' => true
  465. ) );
  466. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  467. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  468. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  469. // print_r(current($invoiceManageDetail ['staffList']));
  470. // die;
  471. $moldManage = array ();
  472. foreach ( $invoiceManageList as $key => $value ) {
  473. if ($value ['mold'] == '发票打印')
  474. $moldManage [$value ['mold']] = $value ['staffList'];
  475. elseif ($value ['mold'] == '发票邮寄')
  476. $moldManage [$value ['mold']] = $value ['staffList'];
  477. elseif ($value ['mold'] == '发票退票')
  478. $moldManage [$value ['mold']] = $value ['staffList'];
  479. }
  480. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  481. $st = '';
  482. if ($settlementType == 'SOFTWARE') {
  483. $st = 0;
  484. $trainId = 0;
  485. } elseif ($settlementType == 'TRAINING') {
  486. $st = 1;
  487. if (empty ( $trainId ) && ! is_numeric ( $trainId )) {
  488. die ( 'illegal request-trainingIdError' );
  489. }
  490. } else {
  491. die ( 'illegal request-settlementError' );
  492. }
  493. $item = array (
  494. 'cid' => $cid,
  495. 'categoryName' => $categoryDetil ['title'],
  496. 'invoiceElement' => $invoiceElement,
  497. 'invoiceQuantity' => $invoiceQuantity,
  498. 'invoiceUnitPrice' => $invoiceUnitPrice,
  499. 'invoicePrice' => $invoicePrice,
  500. 'invoiceType' => $invoiceType,
  501. 'settlementType' => $st,
  502. 'doPost' => $doPost,
  503. 'status' => 1,
  504. 'invoiceSerial' => "#F" . date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT),
  505. 'date' => date ( "Y-m-d H:i:s" ),
  506. 'updateTime' => date ( "Y-m-d H:i:s" ),
  507. 'sid' => $this->staff [0] ['sid'],
  508. 'userName' => $this->staff [0] ['username'],
  509. 'invoiceManage' => $invoiceManageDetail ['staff'],
  510. 'pendingApprovals' => $pendingApprovalsSid,
  511. 'moldManage' => json_encode ( $moldManage ),
  512. 'remark' => $remark,
  513. 'trainId' => $trainId
  514. );
  515. if ($invoiceType == 0)
  516. $item += array (
  517. 'invoiceTitle' => $invoiceTitle,
  518. 'TIN' => $TINT,
  519. 'address' => $addressT,
  520. 'phone' => $phoneT,
  521. 'bank' => $bankT,
  522. 'bankAccount' => $bankAccountT
  523. );
  524. else {
  525. $item += array (
  526. 'invoiceCompany' => $invoiceCompany,
  527. 'TIN' => $TIN,
  528. 'address' => $address,
  529. 'phone' => $phone,
  530. 'bank' => $bank,
  531. 'bankAccount' => $bankAccount
  532. );
  533. }
  534. if ($doPost == 1) {
  535. $mailList = array (
  536. 'invoice' => 1,
  537. 'mailItems' => $mailItems
  538. );
  539. if (! empty ( $softLock ))
  540. $mailList += array (
  541. 'softLock' => $softLockNum
  542. );
  543. else
  544. $mailList += array (
  545. 'softLock' => 0
  546. );
  547. if (! empty ( $contract ))
  548. $mailList += array (
  549. 'contract' => $contractNum
  550. );
  551. else
  552. $mailList += array (
  553. 'contract' => 0
  554. );
  555. if (! empty ( $instructions ))
  556. $mailList += array (
  557. 'instructions' => $instructionsNum
  558. );
  559. else
  560. $mailList += array (
  561. 'instructions' => 0
  562. );
  563. if (! empty ( $remittance ))
  564. $mailList += array (
  565. 'remittance' => $remittance
  566. );
  567. else
  568. $mailList += array (
  569. 'remittance' => ''
  570. );
  571. $mailString = '发票x1张,备注:' . $mailItems;
  572. if (! empty ( $softLock ))
  573. $mailString .= ',软件锁x' . $softLockNum . '个';
  574. if (! empty ( $contract ))
  575. $mailString .= ',合同x' . $contractNum . '份';
  576. if (! empty ( $instructions ))
  577. $mailString .= ',说明书x' . $instructionsNum . '本';
  578. if (! empty ( $remittance ))
  579. $mailString .= ',汇款账号单(张)';
  580. $item += array (
  581. 'recipients' => $recipients,
  582. 'recipientsPhone' => $recipientsPhone,
  583. 'recipientsAddress' => $recipientsAddress,
  584. 'mailItems' => $mailString,
  585. 'mailItemsJson' => json_encode ( $mailList )
  586. );
  587. }
  588. $iid = $invoice->addInvoice ( $item );
  589. // 如果是培训班结算 创建培训班发票到培训班备份中
  590. if (! empty ( $st ) && $st == 1) {
  591. Doo::loadModel ( 'invoiceStore' );
  592. $invoiceStore = new invoiceStore ();
  593. Doo::loadModel ( 'invoiceTraining' );
  594. $invoiceTraining = new invoiceTraining ();
  595. $isid = $invoiceStore->setInvoiceToInvoiceStore ( $iid );
  596. $itemIS = array (
  597. 'isid' => $isid,
  598. 'ipSource' => 1,
  599. 'apStatus' => 1,
  600. 'iid' => $iid
  601. );
  602. $invoiceStore->setInvoiceStoreByCondition ( $itemIS );
  603. // 更新培训班总数量
  604. $detailIT = $invoiceTraining->getInvoiceTrainingByItid ( $trainId );
  605. $item = array (
  606. 'itid' => $trainId,
  607. 'invoiceTotal' => $detailIT ['invoiceTotal'] + 1,
  608. 'submitStatus' => 1
  609. );
  610. $itid = $invoiceTraining->setInvoiceTrainByCondition ( $item );
  611. }
  612. // 操作日志
  613. $item = array (
  614. 'date' => date ( "Y-m-d H:i:s" ),
  615. 'operation' => "创建",
  616. 'status' => 1,
  617. 'img' => $this->staff [0] ['avatar'],
  618. 'username' => $this->staff [0] ['username'],
  619. 'uid' => $this->staff [0] ['sid'],
  620. 'category' => $this->staff [0] ['category'],
  621. 'iid' => $iid
  622. );
  623. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  624. $item = array (
  625. 'date' => date ( "Y-m-d H:i:s" ),
  626. 'operation' => "提交审批",
  627. 'status' => 1,
  628. 'img' => $this->staff [0] ['avatar'],
  629. 'username' => $this->staff [0] ['username'],
  630. 'uid' => $this->staff [0] ['sid'],
  631. 'category' => $this->staff [0] ['category'],
  632. 'iid' => $iid
  633. );
  634. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  635. Doo::loadModel ( 'staff' );
  636. $staff = new staff ();
  637. $username2 = $staff->getOne ( array (
  638. 'select' => 'wxid',
  639. 'where' => 'sid=' . $pendingApprovalsSid,
  640. 'asArray' => TRUE
  641. ) );
  642. // 发送微信审批通知
  643. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  644. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  645. }
  646. return "/invoice";
  647. }
  648. function invoiceEdit() {
  649. Doo::loadClass ( 'XDeode' );
  650. $XDeode = new XDeode ( 5 );
  651. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  652. $iid = $XDeode->decode ( $iid );
  653. if (! is_numeric ( $iid ))
  654. die ( 'illegal request' );
  655. Doo::loadModel ( 'invoice' );
  656. $invoice = new invoice ();
  657. Doo::loadModel ( 'invoiceOperationLog' );
  658. $invoiceOperationLog = new invoiceOperationLog ();
  659. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  660. $operation = $invoiceOperationLog->getInvoiceOperationByDropped ( $iid );
  661. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  662. $this->data ['operation'] = $operation;
  663. $this->data ['invoiceDetail'] = $invoiceDetail;
  664. $this->data ['memu'] = "invoice";
  665. $this->data ['staff'] = $this->staff;
  666. $this->data ['receiptMemu'] = 'invoice';
  667. $this->render ( "/admin/invoiceEdit", $this->data );
  668. }
  669. /**
  670. * 重新编辑退回的发票
  671. * @return string
  672. */
  673. function invoiceEditDo() {
  674. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  675. Doo::loadModel ( 'invoice' );
  676. $invoice = new invoice ();
  677. $iid = $invoice->authcode ( $iidKey );
  678. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  679. die ( 'illegal request' );
  680. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  681. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  682. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  683. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  684. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  685. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  686. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  687. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  688. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  689. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  690. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  691. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  692. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  693. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  694. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  695. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  696. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  697. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  698. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  699. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  700. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  701. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  702. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  703. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  704. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  705. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  706. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  707. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  708. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  709. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  710. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  711. if ($invoiceType == 1) {
  712. $temporary = $invoiceQuantity * $invoiceUnitPrice;
  713. if ($temporary > 10000)
  714. die ( 'illegal request-Please priceError' );
  715. }
  716. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  717. Doo::loadModel ( 'invoiceManage' );
  718. $invoiceManage = new invoiceManage ();
  719. Doo::loadModel ( 'invoiceOperationLog' );
  720. $invoiceOperationLog = new invoiceOperationLog ();
  721. Doo::loadModel ( 'invoiceStore' );
  722. $invoiceStore = new invoiceStore ();
  723. $cid = explode ( ':', $cid );
  724. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  725. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  726. $moldManage = array ();
  727. foreach ( $invoiceManageList as $key => $value ) {
  728. if ($value ['mold'] == '发票打印')
  729. $moldManage [$value ['mold']] = $value ['staffList'];
  730. elseif ($value ['mold'] == '发票邮寄')
  731. $moldManage [$value ['mold']] = $value ['staffList'];
  732. elseif ($value ['mold'] == '发票打印')
  733. $moldManage [$value ['mold']] = $value ['staffList'];
  734. }
  735. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  736. $item = array (
  737. 'iid' => $iid,
  738. 'cid' => $cid [0],
  739. 'categoryName' => $cid [1],
  740. 'invoiceElement' => $invoiceElement,
  741. 'invoiceQuantity' => $invoiceQuantity,
  742. 'invoiceUnitPrice' => $invoiceUnitPrice,
  743. 'invoicePrice' => $invoicePrice,
  744. 'invoiceType' => $invoiceType,
  745. 'doPost' => $doPost,
  746. 'status' => 1,
  747. 'updateTime' => date ( "Y-m-d H:i:s" ),
  748. 'remark' => $remark
  749. );
  750. if ($invoiceType == 0)
  751. $item += array (
  752. 'invoiceTitle' => $invoiceTitle,
  753. 'TIN' => $TINT,
  754. 'address' => $addressT,
  755. 'phone' => $phoneT,
  756. 'bank' => $bankT,
  757. 'bankAccount' => $bankAccountT
  758. );
  759. else {
  760. $item += array (
  761. 'invoiceCompany' => $invoiceCompany,
  762. 'TIN' => $TIN,
  763. 'address' => $address,
  764. 'phone' => $phone,
  765. 'bank' => $bank,
  766. 'bankAccount' => $bankAccount
  767. );
  768. }
  769. if ($doPost == 1) {
  770. $mailList = array (
  771. 'invoice' => 1,
  772. 'mailItems' => $mailItems
  773. );
  774. if (! empty ( $softLock ))
  775. $mailList += array (
  776. 'softLock' => $softLockNum
  777. );
  778. else
  779. $mailList += array (
  780. 'softLock' => '0'
  781. );
  782. if (! empty ( $contract ))
  783. $mailList += array (
  784. 'contract' => $contractNum
  785. );
  786. else
  787. $mailList += array (
  788. 'contract' => '0'
  789. );
  790. if (! empty ( $instructions ))
  791. $mailList += array (
  792. 'instructions' => $instructionsNum
  793. );
  794. else
  795. $mailList += array (
  796. 'instructions' => '0'
  797. );
  798. if (! empty ( $remittance ))
  799. $mailList += array (
  800. 'remittance' => $remittance
  801. );
  802. else
  803. $mailList += array (
  804. 'remittance' => ''
  805. );
  806. $mailString = '发票x1,备注:' . $mailItems;
  807. if (! empty ( $softLock ))
  808. $mailString .= ',软件锁x' . $softLockNum;
  809. if (! empty ( $contract ))
  810. $mailString .= ',合同x' . $contractNum;
  811. if (! empty ( $instructions ))
  812. $mailString .= ',说明书x' . $instructionsNum;
  813. if (! empty ( $remittance ))
  814. $mailString .= ',汇款账号单';
  815. $item += array (
  816. 'recipients' => $recipients,
  817. 'recipientsPhone' => $recipientsPhone,
  818. 'recipientsAddress' => $recipientsAddress,
  819. 'mailItems' => $mailString,
  820. 'mailItemsJson' => json_encode ( $mailList )
  821. );
  822. }
  823. $invoice->setInvoiceByCondition ( $item );
  824. // 更新培训班仓库里的发票
  825. $detail = $invoice->getInvoiceByIid ( $iid );
  826. if (! empty ( $detail ['isid'] )) {
  827. $invoiceStore->isid = $detail ['isid'];
  828. $invoiceStore->invoiceQuantity = $invoiceQuantity;
  829. $invoiceStore->invoiceUnitPrice = $invoiceUnitPrice;
  830. $invoiceStore->invoicePrice = $invoicePrice;
  831. $invoiceStore->update ();
  832. }
  833. $item = array (
  834. 'date' => date ( "Y-m-d H:i:s" ),
  835. 'operation' => "重新提交审批",
  836. 'status' => 1,
  837. 'img' => $this->staff [0] ['avatar'],
  838. 'username' => $this->staff [0] ['username'],
  839. 'uid' => $this->staff [0] ['sid'],
  840. 'category' => $this->staff [0] ['category'],
  841. 'iid' => $iid
  842. );
  843. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  844. }
  845. return "/invoice";
  846. }
  847. /**
  848. * 培训班
  849. */
  850. function invoiceTraining() {
  851. Doo::loadModel ( 'L_category' );
  852. $lCategory = new L_category ();
  853. Doo::loadModel ( 'invoiceTraining' );
  854. $invoiceTraining = new invoiceTraining ();
  855. Doo::loadModel ( 'invoiceTrainManage' );
  856. $invoiceTrainManage = new invoiceTrainManage ();
  857. $imcStaff = $invoiceTrainManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  858. $cidList = array ();
  859. foreach ( $imcStaff as $key => $value ) {
  860. array_push ( $cidList, $value ['cid'] );
  861. }
  862. if (empty ( $cidList )) {
  863. $cidString = $this->staff [0] ['cid'];
  864. } else {
  865. $cidString = implode ( ',', $cidList );
  866. $cidString .= $cidString . ',' . $this->staff [0] ['cid'];
  867. }
  868. $itTodoList = $invoiceTraining->getInvoiceTrainingByTodo ( '', $cidString, $this->staff [0] ['sid'] );
  869. $itedList = $invoiceTraining->getInvoiceTrainingByStatus ( 2, '', $cidString, $this->staff [0] ['sid'] );
  870. $category = $lCategory->getCategory ();
  871. $itid = array ();
  872. foreach ( $itTodoList as $key => $value ) {
  873. array_push ( $itid, $value ['itid'] );
  874. // 如果入账100%更新为已完成
  875. if ($itTodoList [$key] ['arriveSchedule'] >= 100) {
  876. $invoiceTraining = new invoiceTraining ();
  877. $invoiceTraining->itid = $value ['itid'];
  878. $invoiceTraining->status = 2;
  879. $invoiceTraining->update ();
  880. }
  881. }
  882. foreach ( $itedList as $value ) {
  883. array_push ( $itid, $value ['itid'] );
  884. }
  885. $itid = implode ( ',', $itid );
  886. $this->data ['itStatist'] = $invoiceTraining->getInvoiceTrainStatistics ( $itid );
  887. // print_r($itTodoList);
  888. $this->data ['trainCount'] = count ( $itTodoList ) + count ( $itedList );
  889. $this->data ['itTodoList'] = $itTodoList;
  890. $this->data ['itedList'] = $itedList;
  891. $this->data ['category'] = $category;
  892. $this->data ['memu'] = "invoice";
  893. $this->data ['staff'] = $this->staff;
  894. $this->data ['receiptMemu'] = 'invoiceTraining';
  895. $this->render ( "/admin/invoiceTraining", $this->data );
  896. }
  897. /**
  898. * 创建培训班
  899. */
  900. function invoiceTrainingAdd() {
  901. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  902. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  903. $trainDate = $this->get_args ( 'trainDate' ) ? $this->get_args ( 'trainDate' ) : "";
  904. if (empty ( $this->staff [0] ))
  905. die ( 'illegal request' );
  906. if (! empty ( $cid ) && ! empty ( $trainName ) && ! empty ( $trainDate )) {
  907. Doo::loadModel ( 'invoiceTraining' );
  908. $invoiceTraining = new invoiceTraining ();
  909. Doo::loadModel ( 'invoice' );
  910. $invoice = new invoice ();
  911. Doo::loadModel ( 'L_category' );
  912. $lCategory = new L_category ();
  913. Doo::loadModel ( 'invoiceManage' );
  914. $invoiceManage = new invoiceManage ();
  915. Doo::loadModel ( 'invoiceOperationLog' );
  916. $invoiceOperationLog = new invoiceOperationLog ();
  917. $item = array (
  918. 'cid' => $cid,
  919. 'trainName' => $trainName,
  920. 'trainDate' => $trainDate,
  921. 'creator' => $this->staff [0] ['sid'],
  922. 'creatorDate' => date ( "Y-m-d H:i:s" )
  923. );
  924. $itid = $invoiceTraining->addInvoiceTraining ( $item );
  925. }
  926. return "/invoiceTraining";
  927. }
  928. /**
  929. * 删除培训班
  930. */
  931. function invoiceTrainingDelDo() {
  932. $itid = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  933. if (! empty ( $itid )) {
  934. Doo::loadModel ( 'invoiceTraining' );
  935. $invoiceTraining = new invoiceTraining ();
  936. $invoiceTraining->delInvoiceTrainingByItid ( $itid );
  937. }
  938. return "/invoiceTraining";
  939. }
  940. /**
  941. * 培训班详情
  942. */
  943. function invoiceTrainingDetail() {
  944. $trainStatus = $this->get_args ( 'trainStatus' ) ? $this->get_args ( 'trainStatus' ) : "ALL";
  945. $itid = isset ( $this->params ['trainingKey'] ) ? $this->params ['trainingKey'] : "";
  946. Doo::loadModel ( 'invoiceTraining' );
  947. $invoiceTraining = new invoiceTraining ();
  948. Doo::loadModel ( 'invoiceStore' );
  949. $invoiceStore = new invoiceStore ();
  950. if (empty ( $itid ))
  951. die ( 'illegal request' );
  952. $con = ' (b.untreadStatus is null or b.untreadStatus!=2) and ';
  953. if ($trainStatus == "SUBED")
  954. $con = ' (b.untreadStatus is null ) and ';
  955. elseif ($trainStatus == "APPROVAL")
  956. $con = ' ( b.status=1 and b.untreadStatus!=2 ) and ';
  957. elseif ($trainStatus == "TICKET")
  958. $con = ' (b.printStatus=1 and b.status=2 and b.untreadStatus!=2) and ';
  959. elseif ($trainStatus == "TICKETING") {
  960. $con = ' (b.status=2 and b.untreadStatus=1) and ';
  961. }
  962. $detail = $invoiceTraining->getInvoiceTrainingByItid ( $itid );
  963. $isList = $invoiceStore->getinvoiceStoreByItid ( $itid, $con );
  964. //print_r($isList);
  965. $trainlist = array ();
  966. foreach ( $isList as $key => $value ) {
  967. $irDetail = array ();
  968. if ($value ['apStatus'] == 1) {
  969. // array_push ( $irDetail, '' );
  970. array_push ( $irDetail, '<input disabled type="checkbox" style="display:none" >' );
  971. } else {
  972. array_push ( $irDetail, '<input type="checkbox" class="hide" id="' . $value ['storeKey'] . '" name="isBox" value="' . $value ['storeKey'] . '" > <a href="/invoiceStoreEdit/' . $value ['storeKey'] . '.html">编辑</a>
  973. <a href="#confirm" onclick="invoiceStoreApproval(\'' . $value ['storeKey'] . '\')" data-toggle="modal">提交审批</a>
  974. <a href="#del" node-iStore="del" data-key="' . $value ['storeKey'] . '" onclick="invoiceStoreDel(\'' . $value ['storeKey'] . '\')" data-toggle="modal" class="colRed">移除</a>' );
  975. }
  976. array_push ( $irDetail, $value ['invoiceSerial'] );
  977. if ($value ['invoiceType'] == 1)
  978. array_push ( $irDetail, $value ['invoiceCompany'] );
  979. else
  980. array_push ( $irDetail, $value ['invoiceTitle'] );
  981. array_push ( $irDetail, $value ['TIN'] );
  982. array_push ( $irDetail, $value ['userName'] );
  983. if (empty ( $value ['mailItems'] ) && $value ['apStatus'] != 1) {
  984. array_push ( $irDetail, '<a href="#confirm-erro" onclick="invoiceStoreMail(\'' . $value ['storeKey'] . '\')" data-toggle="modal">设置邮寄物品</a>' );
  985. } else
  986. array_push ( $irDetail, $value ['mailItems'] );
  987. array_push ( $irDetail, $value ['recipientsAddress'] . $value ['recipients'] . $value ['recipientsPhone'] );
  988. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  989. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  990. array_push ( $irDetail, $value ['invoiceElement'] );
  991. array_push ( $irDetail, $value ['invoiceQuantity'] );
  992. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  993. if ($value ['invoiceType'] == 1)
  994. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  995. else
  996. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  997. array_push ( $irDetail, $value ['remark'] );
  998. if ($value ['status'] == 1)
  999. array_push ( $irDetail, '审批中' );
  1000. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1)
  1001. array_push ( $irDetail, '已出票' );
  1002. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1 && $value ['printStatus'] != 'irid' && ($value ['untreadStatus'] == 3 || $value ['untreadStatus'] == 0))
  1003. array_push ( $irDetail, '已入账' );
  1004. else
  1005. array_push ( $irDetail, '' );
  1006. array_push ( $irDetail, $value ['invoiceNo'] );
  1007. array_push ( $irDetail, $value ['printTime'] );
  1008. $html = '';
  1009. foreach ( $value ['invoiceReceivables'] as $value ) {
  1010. $html .= '&nbsp;<a href="#billing" node-invoice="INFO" data-type="receivables" data-iskey="' . $value [2] . '" data-toggle="modal">' . $value [1] . '</a>';
  1011. }
  1012. array_push ( $irDetail, $html );
  1013. array_push ( $trainlist, $irDetail );
  1014. }
  1015. $trainlistJson = json_encode ( $trainlist );
  1016. if (empty ( $detail ))
  1017. die ( 'illegal request' );
  1018. // 培训班结算是否有和是否已经结算完成
  1019. Doo::loadModel ( 'receipt' );
  1020. $receipt = new receipt ();
  1021. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $itid );
  1022. $this->data ['receiptDetail'] = $receiptDetail;
  1023. $this->data ['trainStatus'] = $trainStatus;
  1024. $this->data ['itid'] = $itid;
  1025. $this->data ['trainlistJson'] = $trainlistJson;
  1026. $this->data ['iTrainDetail'] = $detail;
  1027. $this->data ['memu'] = "invoice";
  1028. $this->data ['staff'] = $this->staff;
  1029. $this->data ['receiptMemu'] = 'invoiceTraining';
  1030. $this->render ( "/admin/invoiceTrainingDetail", $this->data );
  1031. }
  1032. /**
  1033. * 上传培训班发票
  1034. * @return string
  1035. */
  1036. function invoiceTrainingUpload() {
  1037. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  1038. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  1039. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  1040. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  1041. header ( "HTTP/1.1 500 Internal Server Error" );
  1042. echo "POST exceeded maximum allowed size.";
  1043. exit ( 0 );
  1044. }
  1045. // Settings
  1046. $save_path = DOO::conf ()->SITE_PATH . "upload/invoiceTraining/"; // The path were we will save the file (getcwd() may not be reliable and should be tested in your environment)
  1047. $upload_name = "Filedata";
  1048. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  1049. $extension_whitelist = array (
  1050. "doc",
  1051. "txt",
  1052. "jpg",
  1053. "gif",
  1054. "png"
  1055. ); // Allowed file extensions
  1056. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  1057. // Other variables
  1058. $MAX_FILENAME_LENGTH = 260;
  1059. $file_name = "";
  1060. $file_extension = "";
  1061. $uploadErrors = array (
  1062. 0 => "文件上传成功",
  1063. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  1064. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  1065. 3 => "上传的文件仅为部分文件",
  1066. 4 => "没有文件上传",
  1067. 6 => "缺少临时文件夹"
  1068. );
  1069. $nk = time ();
  1070. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  1071. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  1072. echo "文件无法保存.";
  1073. exit ( 0 );
  1074. }
  1075. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  1076. echo json_encode ( array (
  1077. 'filename' => $file_name,
  1078. 'id' => $nk
  1079. ) );
  1080. exit ( 0 );
  1081. }
  1082. /**
  1083. * 导入发票临时仓库
  1084. */
  1085. function invoiceStoreImport() {
  1086. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  1087. $trainingKey = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  1088. $path = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  1089. if ($path != "" && ! empty ( $trainingKey )) {
  1090. Doo::loadModel ( 'invoiceStore' );
  1091. Doo::loadModel ( 'staff' );
  1092. $staff = new staff ();
  1093. Doo::loadModel ( 'invoiceTraining' );
  1094. $invoiceTraining = new invoiceTraining ();
  1095. Doo::loadClass ( 'XDeode' );
  1096. $XDeode = new XDeode ( 5 );
  1097. $itid = $XDeode->decode ( $trainingKey );
  1098. // 培训班结算是否有和是否已经结算完成
  1099. Doo::loadModel ( 'receipt' );
  1100. $receipt = new receipt ();
  1101. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $itid );
  1102. if (! empty ( $receiptDetail )) {
  1103. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9)
  1104. die ( 'illegal request--status' );
  1105. }
  1106. $exlArray = $this->formatExcelToArrayTrain ( DOO::conf ()->SITE_PATH . "upload/invoiceTraining/" . $path );
  1107. $userName = $this->staff [0] ['username'];
  1108. $sDetail = $staff->getStaffByName ( $userName );
  1109. // die('sdd');
  1110. // 可以优化
  1111. foreach ( $exlArray as $key => $value ) {
  1112. // 开票
  1113. $invoice = new invoiceStore ();
  1114. $invoice->trainId = $itid;
  1115. $invoice->invoiceType = 0;
  1116. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  1117. $invoice->invoiceType = 1;
  1118. $invoice->invoiceQuantity = $value ['invoiceQuantity'];
  1119. $invoice->invoiceUnitPrice = $value ['invoiceUnitPrice'];
  1120. $invoice->invoicePrice = $value ['invoiceQuantity'] * $value ['invoiceUnitPrice'];
  1121. $invoice->invoiceTitle = $value ['invoiceTitle'];
  1122. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  1123. $invoice->invoiceCompany = $value ['invoiceTitle'];
  1124. $invoice->userName = $userName;
  1125. $invoice->sid = $sDetail ['sid'];
  1126. $invoice->cid = $sDetail ['cid'];
  1127. $invoice->categoryName = $sDetail ['category'];
  1128. $invoice->invoiceElement = $value ['invoiceElement'];
  1129. $invoice->remark = $value ['remark'];
  1130. // $invoice->date = $value ['date'];
  1131. // $invoice->printTime = $value ['date'];
  1132. $invoice->ipSource = 1;
  1133. $invoice->printStatus = 0;
  1134. $invoice->status = 0;
  1135. $invoice->postStatus = 1;
  1136. $invoice->untreadStatus = 0;
  1137. // $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1138. $invoice->TIN = $value ['TIN'];
  1139. $invoice->address = $value ['address'];
  1140. $invoice->phone = $value ['phone'];
  1141. $invoice->bank = $value ['bank'];
  1142. $invoice->bankAccount = $value ['bankAccount'];
  1143. $invoice->recipientsAddress = $value ['recipientsAddress'];
  1144. $invoice->recipients = $value ['recipients'];
  1145. $invoice->recipientsPhone = $value ['recipientsPhone'];
  1146. $iid = $invoice->insert ();
  1147. }
  1148. // 加入发票总数量
  1149. $item = array (
  1150. 'itid' => $itid,
  1151. 'invoiceTotal' => count ( $exlArray )
  1152. );
  1153. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1154. return '/invoiceTrainingDetail/' . $trainingKey . ".html";
  1155. }
  1156. echo 'no file';
  1157. }
  1158. /**
  1159. * 编辑仓库里的发票
  1160. */
  1161. function invoiceStoreEdit() {
  1162. Doo::loadClass ( 'XDeode' );
  1163. $XDeode = new XDeode ( 5 );
  1164. $iid = isset ( $this->params ['storeKey'] ) ? $this->params ['storeKey'] : "";
  1165. $iid = $XDeode->decode ( $iid );
  1166. if (! is_numeric ( $iid ))
  1167. die ( 'illegal request' );
  1168. Doo::loadModel ( 'invoiceStore' );
  1169. $invoiceStore = new invoiceStore ();
  1170. $invoiceDetail = $invoiceStore->getInvoiceStoreByIsid ( $iid );
  1171. // print_r($invoiceDetail);
  1172. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  1173. $this->data ['invoiceDetail'] = $invoiceDetail;
  1174. $this->data ['memu'] = "invoice";
  1175. $this->data ['staff'] = $this->staff;
  1176. $this->data ['receiptMemu'] = 'invoiceTraining';
  1177. $this->render ( "/admin/invoiceStoreEdit", $this->data );
  1178. }
  1179. function invoiceStoreEditDo() {
  1180. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1181. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1182. Doo::loadModel ( 'invoiceStore' );
  1183. $invoice = new invoiceStore ();
  1184. Doo::loadClass ( 'XDeode' );
  1185. $XDeode = new XDeode ( 5 );
  1186. $iid = $XDeode->decode ( $storeKey );
  1187. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1188. die ( 'illegal request' );
  1189. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  1190. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  1191. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  1192. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  1193. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  1194. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  1195. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  1196. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  1197. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  1198. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  1199. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  1200. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  1201. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  1202. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  1203. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1204. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1205. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1206. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1207. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  1208. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  1209. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  1210. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  1211. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  1212. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  1213. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1214. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1215. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1216. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1217. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1218. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1219. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1220. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  1221. $cid = explode ( ':', $cid );
  1222. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  1223. $item = array (
  1224. 'isid' => $iid,
  1225. 'cid' => $cid [0],
  1226. 'categoryName' => $cid [1],
  1227. 'invoiceElement' => $invoiceElement,
  1228. 'invoiceQuantity' => $invoiceQuantity,
  1229. 'invoiceUnitPrice' => $invoiceUnitPrice,
  1230. 'invoicePrice' => $invoicePrice,
  1231. 'invoiceType' => $invoiceType,
  1232. 'doPost' => $doPost,
  1233. 'status' => 1,
  1234. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1235. 'remark' => $remark
  1236. );
  1237. if ($invoiceType == 0)
  1238. $item += array (
  1239. 'invoiceTitle' => $invoiceTitle,
  1240. 'TIN' => $TINT,
  1241. 'address' => $addressT,
  1242. 'phone' => $phoneT,
  1243. 'bank' => $bankT,
  1244. 'bankAccount' => $bankAccountT
  1245. );
  1246. else {
  1247. $item += array (
  1248. 'invoiceCompany' => $invoiceCompany,
  1249. 'TIN' => $TIN,
  1250. 'address' => $address,
  1251. 'phone' => $phone,
  1252. 'bank' => $bank,
  1253. 'bankAccount' => $bankAccount
  1254. );
  1255. }
  1256. if ($doPost == 1) {
  1257. $mailList = array (
  1258. 'invoice' => 1,
  1259. 'mailItems' => $mailItems
  1260. );
  1261. if (! empty ( $softLock ))
  1262. $mailList += array (
  1263. 'softLock' => $softLockNum
  1264. );
  1265. else
  1266. $mailList += array (
  1267. 'softLock' => '0'
  1268. );
  1269. if (! empty ( $contract ))
  1270. $mailList += array (
  1271. 'contract' => $contractNum
  1272. );
  1273. else
  1274. $mailList += array (
  1275. 'contract' => '0'
  1276. );
  1277. if (! empty ( $instructions ))
  1278. $mailList += array (
  1279. 'instructions' => $instructionsNum
  1280. );
  1281. else
  1282. $mailList += array (
  1283. 'instructions' => '0'
  1284. );
  1285. if (! empty ( $remittance ))
  1286. $mailList += array (
  1287. 'remittance' => $remittance
  1288. );
  1289. else
  1290. $mailList += array (
  1291. 'remittance' => ''
  1292. );
  1293. $mailString = '发票x1,备注:' . $mailItems;
  1294. if (! empty ( $softLock ))
  1295. $mailString .= ',软件锁x' . $softLockNum;
  1296. if (! empty ( $contract ))
  1297. $mailString .= ',合同x' . $contractNum;
  1298. if (! empty ( $instructions ))
  1299. $mailString .= ',说明书x' . $instructionsNum;
  1300. if (! empty ( $remittance ))
  1301. $mailString .= ',汇款账号单';
  1302. $item += array (
  1303. 'recipients' => $recipients,
  1304. 'recipientsPhone' => $recipientsPhone,
  1305. 'recipientsAddress' => $recipientsAddress,
  1306. 'mailItems' => $mailString,
  1307. 'mailItemsJson' => json_encode ( $mailList )
  1308. );
  1309. }
  1310. $invoice->setInvoiceStoreByCondition ( $item );
  1311. }
  1312. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1313. }
  1314. /**
  1315. *
  1316. * @return string
  1317. */
  1318. function invoiceStoreDelete() {
  1319. Doo::loadClass ( 'XDeode' );
  1320. $XDeode = new XDeode ( 5 );
  1321. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1322. $iStoreKey = $this->get_args ( 'iStoreKey' ) ? $this->get_args ( 'iStoreKey' ) : 0;
  1323. $isid = $XDeode->decode ( $iStoreKey );
  1324. $itid = $XDeode->decode ( $trainKey );
  1325. if (! is_numeric ( $isid ))
  1326. die ( 'illegal request' );
  1327. Doo::loadModel ( 'invoiceStore' );
  1328. $invoiceStore = new invoiceStore ();
  1329. $invoiceStore->delete ( array (
  1330. 'where' => 'isid=' . $isid,
  1331. 'limit' => 1
  1332. ) );
  1333. Doo::loadModel ( 'invoiceTraining' );
  1334. $invoiceTraining = new invoiceTraining ();
  1335. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1336. $item = array (
  1337. 'itid' => $itid,
  1338. 'invoiceTotal' => $itDetail ['invoiceTotal'] - 1
  1339. );
  1340. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1341. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1342. }
  1343. /**
  1344. * 批量删除库里发票
  1345. */
  1346. function invoiceStoreBatchDelete() {
  1347. Doo::loadClass ( 'XDeode' );
  1348. $XDeode = new XDeode ( 5 );
  1349. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1350. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1351. if (empty ( $trainKey ) || empty ( $storeKey ))
  1352. die ( 'illegal request-IdKey' );
  1353. $tid = $XDeode->decode ( $trainKey );
  1354. if (! is_numeric ( $tid ) && ! empty ( $storeKey ))
  1355. die ( 'illegal request' );
  1356. Doo::loadModel ( 'invoiceStore' );
  1357. $isidKeyList = explode ( ',', $storeKey );
  1358. $isidList = array ();
  1359. foreach ( $isidKeyList as $value ) {
  1360. $isid = $XDeode->decode ( $value );
  1361. if (! empty ( $isid ) && is_numeric ( $isid ))
  1362. array_push ( $isidList, $isid );
  1363. }
  1364. $isidString = implode ( ',', $isidList );
  1365. $invoiceStore = new invoiceStore ();
  1366. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,apStatus' );
  1367. $isidList = array ();
  1368. foreach ( $isList as $key => $value ) {
  1369. if ($value ['apStatus'] == 0)
  1370. array_push ( $isidList, $value ['isid'] );
  1371. }
  1372. $isidString = implode ( ',', $isidList );
  1373. // print_r($isList);
  1374. // echo $isidString;
  1375. $invoiceStore = new invoiceStore ();
  1376. $invoiceStore->delete ( array (
  1377. 'where' => "isid in ( " . $isidString . ")",
  1378. 'asArray' => TRUE
  1379. ) );
  1380. Doo::loadModel ( 'invoiceTraining' );
  1381. $invoiceTraining = new invoiceTraining ();
  1382. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1383. $item = array (
  1384. 'itid' => $tid,
  1385. 'invoiceTotal' => $itDetail ['invoiceTotal'] - count ( $isidList )
  1386. );
  1387. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1388. // echo $tid;
  1389. // echo $storeKey;
  1390. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1391. }
  1392. /**
  1393. * 仓库发票提交审批
  1394. * @return string
  1395. */
  1396. function invoiceStoreApproval() {
  1397. Doo::loadClass ( 'XDeode' );
  1398. $XDeode = new XDeode ( 5 );
  1399. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1400. $iStoreKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1401. $isid = $XDeode->decode ( $iStoreKey );
  1402. $trainId = $XDeode->decode ( $trainKey );
  1403. if (! is_numeric ( $isid ))
  1404. die ( 'illegal request' );
  1405. Doo::loadModel ( 'invoiceStore' );
  1406. Doo::loadModel ( 'invoice' );
  1407. $invoice = new invoice ();
  1408. // 加入限制必须填写入开票内容和邮寄物品
  1409. $invoiceStore = new invoiceStore ();
  1410. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid, 'isid,trainId ,invoiceElement,mailItemsJson' );
  1411. if (empty ( $isDetail ['invoiceElement'] ) || empty ( $isDetail ['mailItemsJson'] )) {
  1412. header ( 'Content-Type:text/html;charset=utf-8' );
  1413. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1414. }
  1415. // 拷贝插入一条发票数据
  1416. $invoiceStore = new invoiceStore ();
  1417. $iid = $invoiceStore->setInvoiceStoreToApproval ( $isid );
  1418. $invoiceStore = new invoiceStore ();
  1419. $item = array (
  1420. 'isid' => $isid,
  1421. 'iid' => $iid,
  1422. 'apStatus' => 1
  1423. );
  1424. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1425. Doo::loadModel ( 'invoiceManage' );
  1426. $invoiceManage = new invoiceManage ();
  1427. Doo::loadModel ( 'invoiceOperationLog' );
  1428. $invoiceOperationLog = new invoiceOperationLog ();
  1429. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1430. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1431. $moldManage = array ();
  1432. foreach ( $invoiceManageList as $key => $value ) {
  1433. if ($value ['mold'] == '发票打印')
  1434. $moldManage [$value ['mold']] = $value ['staffList'];
  1435. elseif ($value ['mold'] == '发票邮寄')
  1436. $moldManage [$value ['mold']] = $value ['staffList'];
  1437. elseif ($value ['mold'] == '发票退票')
  1438. $moldManage [$value ['mold']] = $value ['staffList'];
  1439. }
  1440. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1441. $item = array (
  1442. 'iid' => $iid,
  1443. 'isid' => $isid,
  1444. 'invoiceSerial' => "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  1445. 'date' => date ( "Y-m-d H:i:s" ),
  1446. 'status' => 1,
  1447. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1448. 'trainId' => $trainId,
  1449. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1450. 'moldManage' => json_encode ( $moldManage ),
  1451. 'settlementType' => 1,
  1452. 'pendingApprovals' => $pendingApprovalsSid
  1453. );
  1454. $invoice->setInvoiceByCondition ( $item );
  1455. Doo::loadModel ( 'invoiceTraining' );
  1456. $invoiceTraining = new invoiceTraining ();
  1457. $item = array (
  1458. 'itid' => $trainId,
  1459. 'submitStatus' => 1
  1460. );
  1461. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1462. $item = array (
  1463. 'date' => date ( "Y-m-d H:i:s" ),
  1464. 'operation' => "创建",
  1465. 'status' => 1,
  1466. 'img' => $this->staff [0] ['avatar'],
  1467. 'username' => $this->staff [0] ['username'],
  1468. 'uid' => $this->staff [0] ['sid'],
  1469. 'category' => $this->staff [0] ['category'],
  1470. 'iid' => $iid
  1471. );
  1472. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1473. $item = array (
  1474. 'date' => date ( "Y-m-d H:i:s" ),
  1475. 'operation' => "提交审批",
  1476. 'status' => 1,
  1477. 'img' => $this->staff [0] ['avatar'],
  1478. 'username' => $this->staff [0] ['username'],
  1479. 'uid' => $this->staff [0] ['sid'],
  1480. 'category' => $this->staff [0] ['category'],
  1481. 'iid' => $iid
  1482. );
  1483. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1484. Doo::loadModel ( 'staff' );
  1485. $staff = new staff ();
  1486. $username2 = $staff->getOne ( array (
  1487. 'select' => 'wxid',
  1488. 'where' => 'sid=' . $pendingApprovalsSid,
  1489. 'asArray' => TRUE
  1490. ) );
  1491. // 发送微信审批通知
  1492. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1493. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1494. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1495. }
  1496. /**
  1497. * 批量提交发票
  1498. * @return string
  1499. */
  1500. function invoiceStoreBatchApproval() {
  1501. Doo::loadClass ( 'XDeode' );
  1502. $XDeode = new XDeode ( 5 );
  1503. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1504. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1505. if (empty ( $trainKey ) || empty ( $storeKey ))
  1506. die ( 'illegal request-IdKey' );
  1507. $trainId = $XDeode->decode ( $trainKey );
  1508. $isidKeyList = explode ( ',', $storeKey );
  1509. $isidList = array ();
  1510. foreach ( $isidKeyList as $value ) {
  1511. $isid = $XDeode->decode ( $value );
  1512. if (! empty ( $isid ) && is_numeric ( $isid ))
  1513. array_push ( $isidList, $isid );
  1514. }
  1515. $isidString = implode ( ',', $isidList );
  1516. if (! is_numeric ( $trainId ))
  1517. die ( 'illegal request' );
  1518. Doo::loadModel ( 'invoiceStore' );
  1519. Doo::loadModel ( 'invoice' );
  1520. // 判断哪些已经加入审批过
  1521. // 加入限制必须填写入开票内容和邮寄物品
  1522. $invoiceStore = new invoiceStore ();
  1523. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,trainId ,invoiceElement,mailItemsJson' );
  1524. foreach ( $isList as $key => $value ) {
  1525. if (empty ( $value ['invoiceElement'] ) || empty ( $value ['mailItemsJson'] )) {
  1526. header ( 'Content-Type:text/html;charset=utf-8' );
  1527. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1528. }
  1529. }
  1530. // 拷贝插入一条发票数据
  1531. $invoiceStore = new invoiceStore ();
  1532. $invoiceStore->setInvoiceStoreBatchToApproval ( $isidString );
  1533. $invoiceStore = new invoiceStore ();
  1534. $item = array (
  1535. 'apStatus' => 1
  1536. );
  1537. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1538. // 获得正式发票ID
  1539. $invoice = new invoice ();
  1540. $iidList = $invoice->getInvoiceByIstoreid ( $isidString, 'iid,isid' );
  1541. $sqlList = array ();
  1542. $iidString = '';
  1543. $iida = array ();
  1544. foreach ( $iidList as $key => $value ) {
  1545. $sqlList [$value ['isid']] = $value ['iid'];
  1546. array_push ( $iida, $value ['iid'] );
  1547. }
  1548. $iidString = implode ( ',', $iida );
  1549. $ids = implode ( ',', array_keys ( $sqlList ) );
  1550. $sql = "UPDATE CLD_invoiceStore SET iid = CASE isid ";
  1551. foreach ( $sqlList as $id => $ordinal ) {
  1552. $sql .= sprintf ( "WHEN %d THEN %d ", $id, $ordinal );
  1553. }
  1554. $sql .= "END WHERE isid IN ($ids)";
  1555. $invoiceStore = new invoiceStore ();
  1556. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1557. Doo::loadModel ( 'invoiceManage' );
  1558. $invoiceManage = new invoiceManage ();
  1559. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1560. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1561. $moldManage = array ();
  1562. foreach ( $invoiceManageList as $key => $value ) {
  1563. if ($value ['mold'] == '发票打印')
  1564. $moldManage [$value ['mold']] = $value ['staffList'];
  1565. elseif ($value ['mold'] == '发票邮寄')
  1566. $moldManage [$value ['mold']] = $value ['staffList'];
  1567. elseif ($value ['mold'] == '发票退票')
  1568. $moldManage [$value ['mold']] = $value ['staffList'];
  1569. }
  1570. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1571. // 批量更新发票信息
  1572. $item = array (
  1573. 'date' => date ( "Y-m-d H:i:s" ),
  1574. 'status' => 1,
  1575. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1576. 'trainId' => $trainId,
  1577. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1578. 'moldManage' => json_encode ( $moldManage ),
  1579. 'settlementType' => 1,
  1580. 'pendingApprovals' => $pendingApprovalsSid
  1581. );
  1582. $invoice = new invoice ();
  1583. $invoice->BatchInvoiceByCondition ( $item, $iidString );
  1584. // 批量更新发票中仓库isid
  1585. $sql = "UPDATE CLD_invoiceStore SET isid = CASE iid ";
  1586. foreach ( $sqlList as $isid => $iid ) {
  1587. $sql .= sprintf ( "WHEN %d THEN %d ", $iid, $isid );
  1588. }
  1589. $sql .= "END WHERE iid IN ($iidString)";
  1590. $invoice = new invoice ();
  1591. $invoice->UpdateBatchInvoice ( $sql );
  1592. // 批量更新发票序列号
  1593. $sqlList = array ();
  1594. foreach ( $iida as $value ) {
  1595. $sqlList [$value] = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1596. }
  1597. $ids = implode ( ',', array_keys ( $sqlList ) );
  1598. $sql = "UPDATE CLD_invoice SET invoiceSerial = CASE iid ";
  1599. foreach ( $sqlList as $id => $ordinal ) {
  1600. $sql .= sprintf ( "WHEN %d THEN '%s' ", $id, $ordinal );
  1601. }
  1602. $sql .= "END WHERE iid IN ($ids)";
  1603. $invoiceStore = new invoiceStore ();
  1604. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1605. // 批量生产操作日志
  1606. Doo::loadModel ( 'invoiceOperationLog' );
  1607. $sqlList = array ();
  1608. foreach ( $iida as $key => $value ) {
  1609. $sql = '("' . date ( "Y-m-d H:i:s" ) . '","创建","1","' . $this->staff [0] ['avatar'] . '","' . $this->staff [0] ['username'] . '","' . $this->staff [0] ['sid'] . '","' . $this->staff [0] ['category'] . '","' . $value . '"),
  1610. ("' . date ( "Y-m-d H:i:s" ) . '","提交审批","1","' . $this->staff [0] ['avatar'] . '","' . $this->staff [0] ['username'] . '","' . $this->staff [0] ['sid'] . '","' . $this->staff [0] ['category'] . '","' . $value . '") ';
  1611. array_push ( $sqlList, $sql );
  1612. }
  1613. $iolSql = implode ( ',', $sqlList );
  1614. $sql = "INSERT INTO `CLD_invoiceOperationLog` (`date`, `operation`, `status`, `img`, `username`, `uid`, `category`, `iid`) VALUES " . $iolSql;
  1615. $invoiceOperationLog = new invoiceOperationLog ();
  1616. $invoiceOperationLog->setInvoiceOperationLogBySql ( $sql );
  1617. Doo::loadModel ( 'invoiceTraining' );
  1618. $invoiceTraining = new invoiceTraining ();
  1619. $item = array (
  1620. 'itid' => $trainId,
  1621. 'submitStatus' => 1
  1622. );
  1623. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1624. Doo::loadModel ( 'staff' );
  1625. $staff = new staff ();
  1626. $username2 = $staff->getOne ( array (
  1627. 'select' => 'wxid',
  1628. 'where' => 'sid=' . $pendingApprovalsSid,
  1629. 'asArray' => TRUE
  1630. ) );
  1631. // 发送微信审批通知
  1632. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1633. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1634. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1635. }
  1636. /**
  1637. */
  1638. function invoiceStoreMailItemSet() {
  1639. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1640. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1641. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1642. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1643. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1644. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1645. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1646. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1647. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1648. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1649. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1650. Doo::loadClass ( 'XDeode' );
  1651. $XDeode = new XDeode ( 5 );
  1652. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1653. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1654. $isid = $XDeode->decode ( $storeKey );
  1655. $trainId = $XDeode->decode ( $trainKey );
  1656. if (! is_numeric ( $isid ))
  1657. die ( 'illegal request' );
  1658. Doo::loadModel ( 'invoiceStore' );
  1659. $invoiceStore = new invoiceStore ();
  1660. $mailList = array (
  1661. 'invoice' => 1,
  1662. 'mailItems' => $mailItems
  1663. );
  1664. if (! empty ( $softLock ))
  1665. $mailList += array (
  1666. 'softLock' => $softLockNum
  1667. );
  1668. else
  1669. $mailList += array (
  1670. 'softLock' => 0
  1671. );
  1672. if (! empty ( $contract ))
  1673. $mailList += array (
  1674. 'contract' => $contractNum
  1675. );
  1676. else
  1677. $mailList += array (
  1678. 'contract' => 0
  1679. );
  1680. if (! empty ( $instructions ))
  1681. $mailList += array (
  1682. 'instructions' => $instructionsNum
  1683. );
  1684. else
  1685. $mailList += array (
  1686. 'instructions' => 0
  1687. );
  1688. if (! empty ( $remittance ))
  1689. $mailList += array (
  1690. 'remittance' => $remittance
  1691. );
  1692. else
  1693. $mailList += array (
  1694. 'remittance' => ''
  1695. );
  1696. $mailString = '发票x1,备注:' . $mailItems;
  1697. if (! empty ( $softLock ))
  1698. $mailString .= ',软件锁x' . $softLockNum;
  1699. if (! empty ( $contract ))
  1700. $mailString .= ',合同x' . $contractNum;
  1701. if (! empty ( $instructions ))
  1702. $mailString .= ',说明书x' . $instructionsNum;
  1703. if (! empty ( $remittance ))
  1704. $mailString .= ',汇款账号单';
  1705. $item = array (
  1706. 'isid' => $isid,
  1707. 'doPost' => 1,
  1708. 'mailItems' => $mailString,
  1709. 'mailItemsJson' => json_encode ( $mailList )
  1710. );
  1711. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1712. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1713. }
  1714. /**
  1715. * 批量设置邮寄物品
  1716. */
  1717. function invoiceStoreBatchMailItemSet() {
  1718. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1719. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1720. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1721. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1722. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1723. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1724. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1725. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1726. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1727. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1728. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1729. Doo::loadClass ( 'XDeode' );
  1730. $XDeode = new XDeode ( 5 );
  1731. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1732. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1733. if (empty ( $trainKey ) || empty ( $storeKey ))
  1734. die ( 'illegal request-IdKey' );
  1735. $isidKeyList = explode ( ',', $storeKey );
  1736. $isidList = array ();
  1737. foreach ( $isidKeyList as $value ) {
  1738. $isid = $XDeode->decode ( $value );
  1739. if (! empty ( $isid ) && is_numeric ( $isid ))
  1740. array_push ( $isidList, $isid );
  1741. }
  1742. $isidString = implode ( ',', $isidList );
  1743. $trainId = $XDeode->decode ( $trainKey );
  1744. if (! is_numeric ( $isid ))
  1745. die ( 'illegal request' );
  1746. Doo::loadModel ( 'invoiceStore' );
  1747. $invoiceStore = new invoiceStore ();
  1748. $mailList = array (
  1749. 'invoice' => 1,
  1750. 'mailItems' => $mailItems
  1751. );
  1752. if (! empty ( $softLock ))
  1753. $mailList += array (
  1754. 'softLock' => $softLockNum
  1755. );
  1756. else
  1757. $mailList += array (
  1758. 'softLock' => 0
  1759. );
  1760. if (! empty ( $contract ))
  1761. $mailList += array (
  1762. 'contract' => $contractNum
  1763. );
  1764. else
  1765. $mailList += array (
  1766. 'contract' => 0
  1767. );
  1768. if (! empty ( $instructions ))
  1769. $mailList += array (
  1770. 'instructions' => $instructionsNum
  1771. );
  1772. else
  1773. $mailList += array (
  1774. 'instructions' => 0
  1775. );
  1776. if (! empty ( $remittance ))
  1777. $mailList += array (
  1778. 'remittance' => $remittance
  1779. );
  1780. else
  1781. $mailList += array (
  1782. 'remittance' => ''
  1783. );
  1784. $mailString = '发票x1,备注:' . $mailItems;
  1785. if (! empty ( $softLock ))
  1786. $mailString .= ',软件锁x' . $softLockNum;
  1787. if (! empty ( $contract ))
  1788. $mailString .= ',合同x' . $contractNum;
  1789. if (! empty ( $instructions ))
  1790. $mailString .= ',说明书x' . $instructionsNum;
  1791. if (! empty ( $remittance ))
  1792. $mailString .= ',汇款账号单';
  1793. $item = array (
  1794. 'doPost' => 1,
  1795. 'mailItems' => $mailString,
  1796. 'mailItemsJson' => json_encode ( $mailList )
  1797. );
  1798. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1799. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1800. }
  1801. /**
  1802. * 废弃
  1803. */
  1804. function ajaxGetMailItemByIstore() {
  1805. Doo::loadClass ( 'XDeode' );
  1806. $XDeode = new XDeode ( 5 );
  1807. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1808. $isid = $XDeode->decode ( $storeKey );
  1809. if (! is_numeric ( $isid ))
  1810. die ( 'illegal request' );
  1811. Doo::loadModel ( 'invoiceStore' );
  1812. $invoiceStore = new invoiceStore ();
  1813. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid );
  1814. $isDetail ['mailItemsJson'] = json_decode ( $isDetail ['mailItemsJson'], true );
  1815. echo json_encode ( $isDetail ['mailItemsJson'] );
  1816. exit ();
  1817. }
  1818. /**
  1819. * 终止开票
  1820. */
  1821. function invoiceDroppedDo() {
  1822. $droppedIidKey = $this->get_args ( 'droppedIidKey' ) ? $this->get_args ( 'droppedIidKey' ) : '';
  1823. Doo::loadModel ( 'invoice' );
  1824. $invoice = new invoice ();
  1825. Doo::loadModel ( 'invoiceOperationLog' );
  1826. $invoiceOperationLog = new invoiceOperationLog ();
  1827. $iid = $invoice->authcode ( $droppedIidKey );
  1828. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1829. die ( 'illegal request' );
  1830. $item = array (
  1831. 'iid' => $iid,
  1832. 'status' => 4,
  1833. 'updateTime' => date ( "Y-m-d H:i:s" )
  1834. );
  1835. $invoice->setInvoiceByCondition ( $item );
  1836. $item = array (
  1837. 'date' => date ( "Y-m-d H:i:s" ),
  1838. 'operation' => '终止了开票',
  1839. 'status' => 4,
  1840. 'img' => $this->staff [0] ['avatar'],
  1841. 'username' => $this->staff [0] ['username'],
  1842. 'uid' => $this->staff [0] ['sid'],
  1843. 'category' => $this->staff [0] ['category'],
  1844. 'iid' => $iid
  1845. );
  1846. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1847. return "/invoice";
  1848. }
  1849. /**
  1850. * 更新退票的邮寄信息
  1851. */
  1852. function invoiceUntreadMailDo() {
  1853. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  1854. $untreadCompany = $this->get_args ( 'untreadCompany' ) ? $this->get_args ( 'untreadCompany' ) : "";
  1855. $untreadNumber = $this->get_args ( 'untreadNumber' ) ? $this->get_args ( 'untreadNumber' ) : "";
  1856. $untreadItems = $this->get_args ( 'untreadItems' ) ? $this->get_args ( 'untreadItems' ) : "";
  1857. Doo::loadModel ( 'invoice' );
  1858. $invoice = new invoice ();
  1859. $iid = $invoice->authcode ( $untreadIidKey );
  1860. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1861. die ( 'illegal request' );
  1862. $item = array (
  1863. 'iid' => $iid,
  1864. 'untreadCompany' => $untreadCompany,
  1865. 'untreadNumber' => $untreadNumber,
  1866. 'untreadItems' => $untreadItems
  1867. );
  1868. $invoice->setInvoiceByCondition ( $item );
  1869. return "/invoice";
  1870. }
  1871. /**
  1872. * 申请退票 --
  1873. */
  1874. function invoiceUntreadDo() {
  1875. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  1876. $untreadReason = $this->get_args ( 'untreadReason' ) ? $this->get_args ( 'untreadReason' ) : "";
  1877. $untreadPost = $this->get_args ( 'untreadPost' ) ? $this->get_args ( 'untreadPost' ) : "";
  1878. Doo::loadModel ( 'invoice' );
  1879. $invoice = new invoice ();
  1880. Doo::loadModel ( 'invoiceOperationLog' );
  1881. $invoiceOperationLog = new invoiceOperationLog ();
  1882. Doo::loadModel ( 'invoiceReceivables' );
  1883. $invoiceReceivables = new invoiceReceivables ();
  1884. $iid = $invoice->authcode ( $untreadIidKey );
  1885. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1886. die ( 'illegal request' );
  1887. /*
  1888. * 需求变革 有绑定收款也可以退票 $lt = $invoiceReceivables->getInvoiceReceivablesByIid ( $untreadIidKey ); if (! empty ( $lt )) { header ( 'Content-Type:text/html;charset=utf-8' ); die ( '该发票有收款绑定,请先移除!' ); }
  1889. */
  1890. $item = array (
  1891. 'iid' => $iid,
  1892. 'untreadStatus' => 1,
  1893. 'untreadReason' => $untreadReason,
  1894. 'untreadPost' => $untreadPost,
  1895. 'updateTime' => date ( "Y-m-d H:i:s" )
  1896. );
  1897. $invoice->setInvoiceByCondition ( $item );
  1898. $item = array (
  1899. 'date' => date ( "Y-m-d H:i:s" ),
  1900. 'operation' => '申请退票',
  1901. 'status' => 7,
  1902. 'img' => $this->staff [0] ['avatar'],
  1903. 'username' => $this->staff [0] ['username'],
  1904. 'uid' => $this->staff [0] ['sid'],
  1905. 'category' => $this->staff [0] ['category'],
  1906. 'iid' => $iid
  1907. );
  1908. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1909. return "/invoice";
  1910. }
  1911. /**
  1912. * 删除已终止的开票
  1913. */
  1914. function invoiceDelDo() {
  1915. Doo::loadModel ( 'invoice' );
  1916. $invoice = new invoice ();
  1917. Doo::loadModel ( 'invoiceOperationLog' );
  1918. $invoiceOperationLog = new invoiceOperationLog ();
  1919. Doo::loadClass ( 'XDeode' );
  1920. $XDeode = new XDeode ( 5 );
  1921. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  1922. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  1923. $iid = $XDeode->decode ( $iid );
  1924. Doo::loadModel ( 'invoiceStore' );
  1925. $invoiceStore = new invoiceStore ();
  1926. if (! is_numeric ( $iid ))
  1927. die ( 'illegal request' );
  1928. $invoiceDetail = $invoice->getMyInvoice ( $sid, $iid );
  1929. if (empty ( $invoiceDetail ))
  1930. die ( 'illegal request' );
  1931. $item = array (
  1932. 'iid' => $iid,
  1933. 'isDelete' => 1,
  1934. 'updateTime' => date ( "Y-m-d H:i:s" )
  1935. );
  1936. $invoice->setInvoiceByCondition ( $item );
  1937. $item = array (
  1938. 'date' => date ( "Y-m-d H:i:s" ),
  1939. 'operation' => '删除了已终止的发票',
  1940. 'status' => 4,
  1941. 'img' => $this->staff [0] ['avatar'],
  1942. 'username' => $this->staff [0] ['username'],
  1943. 'uid' => $this->staff [0] ['sid'],
  1944. 'category' => $this->staff [0] ['category'],
  1945. 'iid' => $iid
  1946. );
  1947. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1948. // 删除培训班发票仓库里的发票
  1949. $invoiceStore->delInvoiceStoreByIsid ( $invoiceDetail ['isid'] );
  1950. return "/invoice";
  1951. }
  1952. /**
  1953. */
  1954. function invoiceApproval() {
  1955. Doo::loadModel ( 'invoice' );
  1956. $invoice = new invoice ();
  1957. Doo::loadClass ( 'XDeode' );
  1958. $XDeode = new XDeode ( 5 );
  1959. Doo::loadModel ( 'staff' );
  1960. $staff = new staff ();
  1961. $invoiceList = $invoice->find ( array (
  1962. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  1963. 'desc' => 'iid',
  1964. 'limit' => 10,
  1965. 'asArray' => true
  1966. ) );
  1967. foreach ( $invoiceList as $key => $value ) {
  1968. $invoiceList [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1969. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1970. if (! empty ( $lastApprover )) {
  1971. $lastApproverKey = array_keys ( $lastApprover );
  1972. $lastApprover = end ( $lastApprover );
  1973. $staffDetail = $staff->getOne ( array (
  1974. 'where' => 'sid=' . end ( $lastApproverKey ),
  1975. 'asArray' => true
  1976. ) );
  1977. $lastApprover ['username'] = $staffDetail ['username'];
  1978. }
  1979. $invoiceList [$key] ['lastApprover'] = $lastApprover;
  1980. }
  1981. $ilist = $invoice->getInvoiceByProcessStatus ();
  1982. foreach ( $ilist as $key => $value ) {
  1983. $ilist [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1984. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1985. if (! empty ( $lastApprover )) {
  1986. $lastApproverKey = array_keys ( $lastApprover );
  1987. $lastApprover = end ( $lastApprover );
  1988. $staffDetail = $staff->getOne ( array (
  1989. 'where' => 'sid=' . end ( $lastApproverKey ),
  1990. 'asArray' => true
  1991. ) );
  1992. $lastApprover ['username'] = $staffDetail ['username'];
  1993. }
  1994. $ilist [$key] ['lastApprover'] = $lastApprover;
  1995. }
  1996. // print_r($ilist);
  1997. $this->data ['invoiceList'] = $invoiceList;
  1998. $this->data ['ilist'] = $ilist;
  1999. $this->data ['memu'] = "invoice";
  2000. $this->data ['staff'] = $this->staff;
  2001. $this->data ['receiptMemu'] = 'invoiceApproval';
  2002. $this->render ( "/admin/invoiceApproval", $this->data );
  2003. }
  2004. function invoiceDetail() {
  2005. Doo::loadClass ( 'XDeode' );
  2006. $XDeode = new XDeode ( 5 );
  2007. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  2008. $iid = $XDeode->decode ( $iid );
  2009. if (! is_numeric ( $iid ))
  2010. die ( 'illegal request' );
  2011. Doo::loadModel ( 'invoice' );
  2012. $invoice = new invoice ();
  2013. Doo::loadModel ( 'invoiceOperationLog' );
  2014. $invoiceOperationLog = new invoiceOperationLog ();
  2015. $invoiceDetail = $invoice->getOne ( array (
  2016. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'] . ' and iid=' . $iid,
  2017. 'asArray' => true
  2018. ) );
  2019. if (empty ( $invoiceDetail ))
  2020. die ( 'illegal request' );
  2021. if ($invoiceDetail ['settlementType'] == 1) {
  2022. Doo::loadModel ( 'invoiceTraining' );
  2023. $invoiceTraining = new invoiceTraining ();
  2024. $invoiceDetail ['invoiceTraining'] = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceDetail ['trainId'] );
  2025. }
  2026. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  2027. $this->data ['invoiceDetail'] = $invoiceDetail;
  2028. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  2029. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  2030. $this->data ['memu'] = "invoice";
  2031. $this->data ['staff'] = $this->staff;
  2032. $this->data ['receiptMemu'] = 'invoiceApproval';
  2033. $this->render ( "/admin/invoiceApprovalDetail", $this->data );
  2034. }
  2035. /**
  2036. * 对发票进行审批,其中操作有终止,退回,同意动作。操作成功并记录下操作日志
  2037. *
  2038. * @since 1.0.0
  2039. * @var integer iid 开票ID 已加密
  2040. * @var integer status 发票审批状态
  2041. * @var integer opintion 审批发票的意见
  2042. * @return string 如操作成功返回审批首页
  2043. */
  2044. function invoiceApprovalDo() {
  2045. Doo::loadModel ( 'invoice' );
  2046. $invoice = new invoice ();
  2047. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2048. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  2049. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  2050. $divApproval = $this->get_args ( 'divApproval' ) ? $this->get_args ( 'divApproval' ) : "";
  2051. $iid = $invoice->authcode ( $iid );
  2052. if (! is_numeric ( $iid ))
  2053. die ( 'illegal request' );
  2054. // && ! empty ( $opinion )
  2055. if (! empty ( $iid ) && ! empty ( $status )) {
  2056. if (! ($status == 2 || $status == 3 || $status == 4))
  2057. die ( 'illegal request' );
  2058. Doo::loadModel ( 'invoiceOperationLog' );
  2059. $invoiceOperationLog = new invoiceOperationLog ();
  2060. $invoiceDetail = $invoice->getOne ( array (
  2061. 'where' => 'status=1 and iid=' . $iid . ' and pendingApprovals=' . $this->staff [0] ['sid'],
  2062. 'asArray' => true
  2063. ) );
  2064. if (empty ( $invoiceDetail ))
  2065. die ( 'illegal request' );
  2066. $processApprovals = json_decode ( $invoiceDetail ['processApprovals'], true );
  2067. $invoiceManage = json_decode ( $invoiceDetail ['invoiceManage'], true );
  2068. if ($status == 3) {
  2069. $invoice->status = $status;
  2070. $item = array (
  2071. 'operation' => $opinion
  2072. );
  2073. } else {
  2074. if (empty ( $processApprovals )) {
  2075. $processApprovals = array (
  2076. $this->staff [0] ['sid'] => array (
  2077. 'date' => date ( "Y-m-d H:i:s" ),
  2078. 'opinion' => $opinion,
  2079. 'status' => $status
  2080. )
  2081. );
  2082. // var_dump(next($invoiceManage));
  2083. $nextInvoiceManage = next ( $invoiceManage );
  2084. // print_r($nextInvoiceManage);
  2085. if ($status != 4 && $nextInvoiceManage !== false)
  2086. $invoice->pendingApprovals = $nextInvoiceManage [0];
  2087. $invoice->processApprovals = json_encode ( $processApprovals );
  2088. // var_dump($invoice);
  2089. // print_r($invoiceManage);
  2090. } else {
  2091. $processApprovals [$this->staff [0] ['sid']] = array (
  2092. 'date' => date ( "Y-m-d H:i:s" ),
  2093. 'opinion' => $opinion,
  2094. 'status' => $status
  2095. );
  2096. $pendingApprovals = 0;
  2097. foreach ( $invoiceManage as $key => $value ) {
  2098. if ($value [0] == $this->staff [0] ['sid']) {
  2099. if (isset ( $invoiceManage [$key + 1] ))
  2100. $pendingApprovals = $invoiceManage [$key + 1] [0];
  2101. break;
  2102. }
  2103. }
  2104. if ($status != 4 && ! empty ( $pendingApprovals ))
  2105. $invoice->pendingApprovals = $pendingApprovals;
  2106. $invoice->processApprovals = json_encode ( $processApprovals );
  2107. }
  2108. $item = array (
  2109. 'operation' => $opinion
  2110. );
  2111. if (count ( $processApprovals ) == count ( $invoiceManage ) && $status != 4) {
  2112. $invoice->status = $status;
  2113. $invoice->pendingApprovals = 0;
  2114. $invoice->approvalTime = date ( "Y-m-d H:i:s" );
  2115. } elseif ($status == 4) {
  2116. $invoice->status = $status;
  2117. $item = array (
  2118. 'operation' => $opinion
  2119. );
  2120. }
  2121. }
  2122. $invoice->updateTime = date ( "Y-m-d H:i:s" );
  2123. $invoice->update ( array (
  2124. 'where' => 'iid=' . $iid
  2125. ) );
  2126. $item += array (
  2127. 'date' => date ( "Y-m-d H:i:s" ),
  2128. 'img' => $this->staff [0] ['avatar'],
  2129. 'username' => $this->staff [0] ['username'],
  2130. 'uid' => $this->staff [0] ['sid'],
  2131. 'category' => $this->staff [0] ['category'],
  2132. 'status' => $status,
  2133. 'iid' => $iid
  2134. );
  2135. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2136. if (empty ( $divApproval ))
  2137. return '/invoiceApproval';
  2138. else
  2139. return '/invoiceApprovalAchieve/PEND';
  2140. }
  2141. die ( 'illegal request' );
  2142. }
  2143. /**
  2144. * 展示需要打印的发票数据
  2145. *
  2146. * @since 1.0.0
  2147. */
  2148. function invoicePrint() {
  2149. Doo::loadModel ( 'invoice' );
  2150. $invoice = new invoice ();
  2151. Doo::loadClass ( 'XDeode' );
  2152. $XDeode = new XDeode ( 5 );
  2153. Doo::loadModel ( 'staff' );
  2154. $staff = new staff ();
  2155. $toPrint = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0 );
  2156. $printed = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 1 );
  2157. foreach ( $toPrint as $key => $value ) {
  2158. $toPrint [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2159. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2160. if (! empty ( $lastApprover )) {
  2161. $lastApproverKey = array_keys ( $lastApprover );
  2162. $lastApprover = end ( $lastApprover );
  2163. $staffDetail = $staff->getOne ( array (
  2164. 'where' => 'sid=' . end ( $lastApproverKey ),
  2165. 'asArray' => true
  2166. ) );
  2167. $lastApprover ['username'] = $staffDetail ['username'];
  2168. }
  2169. $toPrint [$key] ['lastApprover'] = $lastApprover;
  2170. }
  2171. foreach ( $printed as $key => $value ) {
  2172. $printed [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2173. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2174. if (! empty ( $lastApprover )) {
  2175. $lastApproverKey = array_keys ( $lastApprover );
  2176. $lastApprover = end ( $lastApprover );
  2177. $staffDetail = $staff->getOne ( array (
  2178. 'where' => 'sid=' . end ( $lastApproverKey ),
  2179. 'asArray' => true
  2180. ) );
  2181. $lastApprover ['username'] = $staffDetail ['username'];
  2182. }
  2183. $printed [$key] ['lastApprover'] = $lastApprover;
  2184. }
  2185. $this->data ['printed'] = $printed;
  2186. $this->data ['toPrint'] = $toPrint;
  2187. $this->data ['memu'] = "invoice";
  2188. $this->data ['staff'] = $this->staff;
  2189. $this->data ['receiptMemu'] = 'invoicePrint';
  2190. $this->render ( "/admin/invoicePrint", $this->data );
  2191. }
  2192. /**
  2193. * 展示发票打印的详情页面
  2194. *
  2195. * @since 1.0.0
  2196. */
  2197. function invoicePrintDetail() {
  2198. Doo::loadClass ( 'XDeode' );
  2199. $XDeode = new XDeode ( 5 );
  2200. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  2201. $iid = $XDeode->decode ( $iid );
  2202. if (! is_numeric ( $iid ))
  2203. die ( 'illegal request' );
  2204. Doo::loadModel ( 'invoice' );
  2205. $invoice = new invoice ();
  2206. Doo::loadModel ( 'invoiceOperationLog' );
  2207. $invoiceOperationLog = new invoiceOperationLog ();
  2208. Doo::loadModel ( 'invoicePaper' );
  2209. $invoicePaper = new invoicePaper ();
  2210. $invoiceDetail = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0, $iid );
  2211. if (empty ( $invoiceDetail ))
  2212. die ( 'illegal request' );
  2213. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $invoiceDetail ['invoiceType'] );
  2214. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  2215. if ($invoiceDetail ['settlementType'] == 1) {
  2216. Doo::loadModel ( 'invoiceTraining' );
  2217. $invoiceTraining = new invoiceTraining ();
  2218. $invoiceDetail ['invoiceTraining'] = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceDetail ['trainId'] );
  2219. }
  2220. $this->data ['invoicePaperList'] = $invoicePaperList;
  2221. $this->data ['invoiceDetail'] = $invoiceDetail;
  2222. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  2223. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  2224. $this->data ['memu'] = "invoice";
  2225. $this->data ['staff'] = $this->staff;
  2226. $this->data ['receiptMemu'] = 'invoicePrint';
  2227. $this->render ( "/admin/invoicePrintDetail", $this->data );
  2228. }
  2229. /**
  2230. * 所有待打印 发票
  2231. */
  2232. function invoicePrintStayAchieve() {
  2233. Doo::loadModel ( 'invoice' );
  2234. $invoice = new invoice ();
  2235. Doo::loadClass ( 'XDeode' );
  2236. $XDeode = new XDeode ( 5 );
  2237. Doo::loadModel ( 'staff' );
  2238. $staff = new staff ();
  2239. $MebSea = $this->get_args ( 'MebSea' ) ? urldecode ( $this->get_args ( 'MebSea' ) ) : "";
  2240. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  2241. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  2242. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  2243. Doo::loadModel ( 'invoiceTraining' );
  2244. $invoiceTraining = new invoiceTraining ();
  2245. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  2246. $page_size = 12;
  2247. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2248. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : "ALL";
  2249. // $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : "ALL";
  2250. $get = "/" . $status;
  2251. $con = ' and status=2 ';
  2252. if ($status == 'TOPRINT')
  2253. $con = ' and status=2 and printStatus=0 ';
  2254. elseif ($status == 'PRINTED')
  2255. $con = ' and status=2 and printStatus=1';
  2256. if ($invoiceType == 'ORDINARY')
  2257. $con .= ' and invoiceType=0 ';
  2258. elseif ($invoiceType == 'SPECIAL')
  2259. $con .= ' and invoiceType=1 ';
  2260. if ($invoiceTrain == 'ORDINARY')
  2261. $con .= ' and trainId=0 ';
  2262. elseif ($invoiceTrain == 'TRAIN')
  2263. $con .= ' and trainId!=0 ';
  2264. if ($invoiceTrainName != 'ALL') {
  2265. $trainId = $XDeode->decode ( $invoiceTrainName );
  2266. if (is_numeric ( $trainId ))
  2267. $con .= ' and trainId =' . $trainId;
  2268. }
  2269. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2270. $dateArr = explode ( ':', $date );
  2271. $D1 = '';
  2272. $D2 = '';
  2273. if (! empty ( $date )) {
  2274. $D1 = $dateArr [0];
  2275. $D2 = $dateArr [1];
  2276. }
  2277. if (! empty ( $D1 ) && ! empty ( $D2 ) && ! empty ( $date ))
  2278. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2279. if (! empty ( $MebSea )) {
  2280. $con .= ' and ( invoiceNo like "%' . $MebSea . '%" or invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  2281. }
  2282. $pageinfo ['page'] = array (
  2283. 'previous' => ''
  2284. );
  2285. $get .= "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&invoiceType=" . urlencode ( $invoiceType ) . "&invoiceTrain=" . urlencode ( $invoiceTrain ) . "";
  2286. $sql = " (untreadStatus=0 or untreadStatus=3) and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  2287. $action = "invoicePrintStayAchieve";
  2288. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2289. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2290. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  2291. $this->data ['trainList'] = $trainList;
  2292. $this->data ['invoiceType'] = $invoiceType;
  2293. $this->data ['invoiceTrain'] = $invoiceTrain;
  2294. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  2295. $this->data ['MebSeaEn'] = $MebSea;
  2296. $this->data ['MebSea'] = urlencode ( $MebSea );
  2297. $this->data ['get'] = $get;
  2298. $this->data ['page'] = $pageinfo;
  2299. $this->data ['date'] = $date;
  2300. $this->data ['status'] = $status;
  2301. $this->data ['invoiceType'] = $invoiceType;
  2302. $this->data ['memu'] = "invoice";
  2303. $this->data ['staff'] = $this->staff;
  2304. foreach ( $list as $key => $value ) {
  2305. $list [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2306. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2307. if (! empty ( $lastApprover )) {
  2308. $lastApproverKey = array_keys ( $lastApprover );
  2309. $lastApprover = end ( $lastApprover );
  2310. $staffDetail = $staff->getOne ( array (
  2311. 'where' => 'sid=' . end ( $lastApproverKey ),
  2312. 'asArray' => true
  2313. ) );
  2314. $lastApprover ['username'] = $staffDetail ['username'];
  2315. }
  2316. $list [$key] ['lastApprover'] = $lastApprover;
  2317. }
  2318. $this->data ['receiptMemu'] = 'invoicePrint';
  2319. $this->data ['list'] = $list;
  2320. $this->render ( "/admin/invoicePrintStayAchieve", $this->data );
  2321. }
  2322. /**
  2323. * 填写票号并完成打印
  2324. * @since 1.0.0
  2325. */
  2326. function invoicePrintDo() {
  2327. Doo::loadModel ( 'invoice' );
  2328. $invoice = new invoice ();
  2329. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2330. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  2331. $invoicePrintType = $this->get_args ( 'invoicePrintType' ) ? $this->get_args ( 'invoicePrintType' ) : "";
  2332. $iid = $invoice->authcode ( $iid );
  2333. if (! is_numeric ( $iid ))
  2334. die ( 'illegal request' );
  2335. if (! empty ( $iid ) && ! empty ( $invoiceNo )) {
  2336. Doo::loadModel ( 'invoiceOperationLog' );
  2337. $invoiceOperationLog = new invoiceOperationLog ();
  2338. Doo::loadModel ( 'invoiceStatistics' );
  2339. $invoiceStatistics = new invoiceStatistics ();
  2340. $XDeode = new XDeode ( 5 );
  2341. Doo::loadModel ( 'invoicePaper' );
  2342. $invoicePaper = new invoicePaper ();
  2343. $invoicePrintDetail = $invoice->getInvoiceByPrint ( $iid );
  2344. if (empty ( $invoicePrintDetail ))
  2345. die ( 'illegal request' );
  2346. //
  2347. $ipid = $XDeode->decode ( $invoiceNo );
  2348. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  2349. if (empty ( $paperDetail ))
  2350. die ( 'illegal request' );
  2351. $invoicePaper = new invoicePaper ();
  2352. $item = array (
  2353. 'iid' => $iid,
  2354. 'ipid' => $ipid
  2355. );
  2356. $invoicePaper->setInvoicePaperByCondition ( $item );
  2357. $item = array (
  2358. 'iid' => $iid,
  2359. 'printStatus' => 1,
  2360. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2361. 'printer' => $this->staff [0] ['username'],
  2362. 'printTime' => date ( "Y-m-d H:i:s" ),
  2363. 'invoiceNo' => $paperDetail ['invoiceNo']
  2364. );
  2365. $invoice->setInvoiceByCondition ( $item );
  2366. $item = array (
  2367. 'date' => date ( "Y-m-d H:i:s" ),
  2368. 'operation' => '打印发票号:' . $paperDetail ['invoiceNo'],
  2369. 'status' => 5,
  2370. 'img' => $this->staff [0] ['avatar'],
  2371. 'username' => $this->staff [0] ['username'],
  2372. 'uid' => $this->staff [0] ['sid'],
  2373. 'category' => $this->staff [0] ['category'],
  2374. 'iid' => $iid
  2375. );
  2376. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2377. // 去统计--负票不汇总
  2378. if ($invoicePrintDetail ['untreadStatus'] != 4) {
  2379. $item = array (
  2380. 'date' => date ( "Y-m-d H:i:s" ),
  2381. 'priceClass' => 1,
  2382. 'cid' => $invoicePrintDetail ['cid'],
  2383. 'staff' => $invoicePrintDetail ['sid'],
  2384. 'invoicePrice' => $invoicePrintDetail ['invoicePrice']
  2385. );
  2386. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2387. }
  2388. // 发送通知信息到微信-去除
  2389. // $this->setWXMsg($iid,'PRINT');
  2390. // 发票信息库
  2391. $this->autoUpdateInvoiceInfoBase ( $invoicePrintDetail );
  2392. // 申请人获取微信通知
  2393. Doo::loadModel ( 'staff' );
  2394. $staff = new staff ();
  2395. Doo::loadClass ( 'XDeode' );
  2396. $XDeode = new XDeode ( 5 );
  2397. $username2 = $staff->getOne ( array (
  2398. 'select' => 'wxid',
  2399. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2400. 'asArray' => TRUE
  2401. ) );
  2402. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '完成打印';
  2403. $msg = '';
  2404. $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/' . $XDeode->encode ( $invoicePrintDetail ['iid'] ) . '.html';
  2405. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2406. if (empty ( $invoicePrintType ))
  2407. return "/invoicePrint";
  2408. else
  2409. return "/invoicePrintStayAchieve";
  2410. }
  2411. }
  2412. /**
  2413. * 需要邮寄的发票
  2414. * @since 1.0.0
  2415. */
  2416. function invoicePost() {
  2417. Doo::loadModel ( 'invoice' );
  2418. $invoice = new invoice ();
  2419. Doo::loadModel ( 'express' );
  2420. $express = new express ();
  2421. $invoicePost = $invoice->getPostByInvoice ();
  2422. $invoicePosted = $invoice->getPostByInvoice ( 1 );
  2423. $expressList = $express->getExpressByAll ();
  2424. $invoicePostExpress = "";
  2425. if (isset ( $_COOKIE ["invoicePostExpress"] ))
  2426. $invoicePostExpress = $_COOKIE ["invoicePostExpress"];
  2427. $this->data ['invoicePostExpress'] = $invoicePostExpress;
  2428. $this->data ['expressList'] = $expressList;
  2429. $this->data ['invoicePost'] = $invoicePost;
  2430. $this->data ['invoicePosted'] = $invoicePosted;
  2431. $this->data ['memu'] = "invoice";
  2432. $this->data ['staff'] = $this->staff;
  2433. $this->data ['receiptMemu'] = 'invoicePost';
  2434. $this->render ( "/admin/invoicePost", $this->data );
  2435. }
  2436. /**
  2437. * 添加发票邮寄信息
  2438. */
  2439. function invoiceExpressAddDo() {
  2440. Doo::loadModel ( 'invoice' );
  2441. $invoice = new invoice ();
  2442. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2443. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2444. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2445. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2446. $iid = $iid = $invoice->authcode ( $iid );
  2447. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2448. die ( 'illegal request' );
  2449. $invoicePrintDetail = $invoice->getInvoiceByIid ( $iid );
  2450. setcookie ( 'invoicePostExpress', $expressNumber );
  2451. $item = array (
  2452. 'iid' => $iid,
  2453. 'postStatus' => 1,
  2454. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2455. 'postTime' => date ( "Y-m-d H:i:s" ),
  2456. 'expressCompany' => $expressCompany,
  2457. 'expressNumber' => $expressNumber,
  2458. 'actualItems' => $actualItems,
  2459. 'poster' => $this->staff [0] ['username']
  2460. );
  2461. $invoice->setInvoiceByCondition ( $item );
  2462. // 微信通知-去掉
  2463. // $this->setWXMsg ( $iid );
  2464. Doo::loadModel ( 'staff' );
  2465. $staff = new staff ();
  2466. Doo::loadClass ( 'XDeode' );
  2467. $XDeode = new XDeode ( 5 );
  2468. $username2 = $staff->getOne ( array (
  2469. 'select' => 'wxid',
  2470. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2471. 'asArray' => TRUE
  2472. ) );
  2473. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '已邮寄';
  2474. $expCom = explode ( ":", $invoicePrintDetail ['expressCompany'] );
  2475. if (empty ( $expCom ))
  2476. $expCom [0] = '';
  2477. $msg = $expCom [0] . ':' . $invoicePrintDetail ['expressNumber'] . '';
  2478. $url = 'https://m.kuaidi100.com/result.jsp?nu=' . $invoicePrintDetail ['expressNumber'];
  2479. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2480. return '/invoicePost';
  2481. }
  2482. function invoiceExpressUpdateDo() {
  2483. Doo::loadModel ( 'invoice' );
  2484. $invoice = new invoice ();
  2485. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  2486. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2487. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2488. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2489. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2490. $iid = $invoice->authcode ( $iid );
  2491. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2492. die ( 'illegal request' );
  2493. $item = array (
  2494. 'iid' => $iid,
  2495. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2496. 'expressCompany' => $expressCompany,
  2497. 'expressNumber' => $expressNumber,
  2498. 'actualItems' => $actualItems,
  2499. 'poster' => $this->staff [0] ['username']
  2500. );
  2501. $invoice->setInvoiceByCondition ( $item );
  2502. return $action;
  2503. }
  2504. /**
  2505. * 可退票管理
  2506. */
  2507. function invoiceUntreadIsAchieve() {
  2508. Doo::loadModel ( 'invoice' );
  2509. $invoice = new invoice ();
  2510. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2511. /*
  2512. * Doo::loadClass ( 'XDeode' ); $XDeode = new XDeode ( 5 ); $page_size = 18; $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1; $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : ""; $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ); $dateArr = explode ( ':', $date ); $D1 = ''; $D2 = ''; if (! empty ( $date )) { $D1 = $dateArr [0]; $D2 = $dateArr [1]; } $con = ''; if (! empty ( $D1 ) && ! empty ( $D2 )) $con = ' and bindTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" '; // if ($date == 'MONTHO') // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)'; // elseif ($date == 'MONTHT') // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)'; // elseif ($date == 'MONTHY') // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)'; if (! empty ( $MebSea )) { $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )'; } $pageinfo ['page'] = array ( 'previous' => '' );
  2513. */
  2514. if (empty ( $MebSea )) {//
  2515. $con = ' and invoiceNo like "NULL" ';
  2516. } else {
  2517. $con = ' and (invoiceNo like "%' . $MebSea . '%" or invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  2518. }
  2519. // printStatus=1 and
  2520. $sql = " (untreadStatus=0 or untreadStatus=3) and status=2 and sid=" . $this->staff [0] ['sid'] . $con;
  2521. /*
  2522. * $action = "invoiceUntreadIsAchieve"; $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" ); $limit = $pageinfo ['lower'] . ',' . $page_size;
  2523. */
  2524. $limit = '0,20';
  2525. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2526. // print_r($list);
  2527. $this->data ['MebSeaEn'] = $MebSea;
  2528. /*
  2529. * $this->data ['get'] = $get; $this->data ['page'] = $pageinfo; $this->data ['date'] = $date;
  2530. */
  2531. $this->data ['list'] = $list;
  2532. $this->data ['memu'] = "invoice";
  2533. $this->data ['staff'] = $this->staff;
  2534. $this->data ['receiptMemu'] = 'invoice';
  2535. $this->render ( "/admin/invoiceUntreadIsAchieve", $this->data );
  2536. }
  2537. // 已经退票的发票
  2538. function invoiceUntreadED() {
  2539. Doo::loadModel ( 'invoice' );
  2540. $invoice = new invoice ();
  2541. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2542. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "";
  2543. Doo::loadClass ( 'XDeode' );
  2544. $XDeode = new XDeode ( 5 );
  2545. $page_size = 18;
  2546. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2547. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2548. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  2549. $dateArr = explode ( ':', $date );
  2550. $D1 = '';
  2551. $D2 = '';
  2552. if (! empty ( $date )) {
  2553. $D1 = $dateArr [0];
  2554. $D2 = $dateArr [1];
  2555. }
  2556. $con = '';
  2557. if (! empty ( $D1 ) && ! empty ( $D2 )) {
  2558. $con = ' and bindTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2559. }
  2560. // if ($date == 'MONTHO')
  2561. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  2562. // elseif ($date == 'MONTHT')
  2563. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  2564. // elseif ($date == 'MONTHY')
  2565. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  2566. if (! empty ( $MebSea )) {
  2567. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  2568. }
  2569. if ($invoiceType == 'ORDINARY') {
  2570. $con .= ' and invoiceType=0 ';
  2571. } elseif ($invoiceType == 'SPECIAL') {
  2572. $con .= ' and invoiceType=1 ';
  2573. }
  2574. $pageinfo ['page'] = array (
  2575. 'previous' => ''
  2576. );
  2577. // printStatus=1 and
  2578. $sql = " (untreadStatus=2 ) and status=2 and sid=" . $this->staff [0] ['sid'] . $con;
  2579. $action = "invoiceUntreadED";
  2580. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2581. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2582. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2583. // print_r($list);
  2584. $this->data ['MebSeaEn'] = $MebSea;
  2585. $this->data ['get'] = $get;
  2586. $this->data ['page'] = $pageinfo;
  2587. $this->data ['date'] = $date;
  2588. $this->data ['invoiceType'] = $invoiceType;
  2589. $this->data ['list'] = $list;
  2590. $this->data ['memu'] = "invoice";
  2591. $this->data ['staff'] = $this->staff;
  2592. $this->data ['receiptMemu'] = 'invoice';
  2593. $this->render ( "/admin/invoiceUntreadED", $this->data );
  2594. }
  2595. /**
  2596. * 退票处理页面
  2597. */
  2598. function invoiceUntread() {
  2599. Doo::loadModel ( 'invoice' );
  2600. $invoice = new invoice ();
  2601. $untreadInvoice = $invoice->getInvoiceByUntreadStatus ( 1, 0, 50 );
  2602. $establishedInvoice = $invoice->getInvoiceByUntreadStatus ( 2 );
  2603. foreach ( $establishedInvoice as $key => $value ) {
  2604. // months
  2605. $lossDate = strtotime ( "+1 month", strtotime ( $value ['OperationLog'] ['date'] ) );
  2606. $nowDate = strtotime ( 'now' );
  2607. $establishedInvoice [$key] ['lossShow'] = false;
  2608. if ($lossDate < $nowDate)
  2609. $establishedInvoice [$key] ['lossShow'] = true;
  2610. }
  2611. $this->data ['untreadInvoice'] = $untreadInvoice;
  2612. $this->data ['establishedInvoice'] = $establishedInvoice;
  2613. $this->data ['memu'] = "invoice";
  2614. $this->data ['staff'] = $this->staff;
  2615. $this->data ['receiptMemu'] = 'invoiceUntread';
  2616. $this->render ( "/admin/invoiceUntread", $this->data );
  2617. }
  2618. /**
  2619. * 确认收到退回的发票,开票状态为退回 //收款状态解绑,公司统计扣除入账额度
  2620. */
  2621. function invoiceUntreadEstablishedDo() {
  2622. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  2623. Doo::loadModel ( 'invoice' );
  2624. $invoice = new invoice ();
  2625. Doo::loadModel ( 'invoiceOperationLog' );
  2626. $invoiceOperationLog = new invoiceOperationLog ();
  2627. Doo::loadModel ( 'invoiceReceivables' );
  2628. Doo::loadModel ( 'invoiceStatistics' );
  2629. $iid = $invoice->authcode ( $untreadIidKey );
  2630. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2631. die ( 'illegal request' );
  2632. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  2633. if ($invoiceDetails ['untreadStatus'] != 1)
  2634. die ( 'illegal request' );
  2635. $item = array (
  2636. 'iid' => $iid,
  2637. // 'irid'=>'',
  2638. 'untreadStatus' => 2,
  2639. 'updateTime' => date ( "Y-m-d H:i:s" )
  2640. );
  2641. $invoice->setInvoiceByCondition ( $item );
  2642. $item = array (
  2643. 'date' => date ( "Y-m-d H:i:s" ),
  2644. 'operation' => '已确认退票',
  2645. 'status' => 6,
  2646. 'img' => $this->staff [0] ['avatar'],
  2647. 'username' => $this->staff [0] ['username'],
  2648. 'uid' => $this->staff [0] ['sid'],
  2649. 'category' => $this->staff [0] ['category'],
  2650. 'iid' => $iid
  2651. );
  2652. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2653. // 收款解绑以及入账扣除 收款扣除
  2654. if (! empty ( $invoiceDetails ['irid'] )) {
  2655. $iridList = explode ( ',', $invoiceDetails ['irid'] );
  2656. foreach ( $iridList as $value ) {
  2657. $invoiceReceivables = new invoiceReceivables ();
  2658. $irDetails = $invoiceReceivables->getOne ( array (
  2659. 'where' => " irid=" . $value . ' and bindStatus=1',
  2660. 'asArray' => TRUE
  2661. ) );
  2662. $item = array (
  2663. 'irid' => $value,
  2664. 'bindStatus' => 0,
  2665. 'untreadStatus' => 1,
  2666. 'untreadStaff' => $invoiceDetails ['userName'],
  2667. 'unbundlingTime' => date ( "Y-m-d H:i:s" ),
  2668. 'iid' => 0
  2669. );
  2670. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2671. if (! empty ( $irDetails )) {
  2672. // 扣除入账
  2673. $invoiceStatistics = new invoiceStatistics ();
  2674. $item = array (
  2675. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2676. 'priceClass' => 3,
  2677. 'cid' => $invoiceDetails ['cid'],
  2678. 'staff' => $invoiceDetails ['sid'],
  2679. 'accountPrice' => - $irDetails ['receivablesPrice']
  2680. );
  2681. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2682. // 扣除收款
  2683. $invoiceStatistics = new invoiceStatistics ();
  2684. $item = array (
  2685. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2686. 'priceClass' => 2,
  2687. 'cid' => $invoiceDetails ['cid'],
  2688. 'staff' => $invoiceDetails ['sid'],
  2689. 'irid' => $irDetails ['irid'],
  2690. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  2691. );
  2692. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2693. }
  2694. // 解绑时删除收入流水
  2695. Doo::loadModel ( 'wasteBook' );
  2696. $wasteBook = new wasteBook ();
  2697. $wasteBook->delete ( array (
  2698. 'where' => 'dataID=' . $value . ' and accountType=7',
  2699. 'limit' => 1
  2700. ) );
  2701. }
  2702. }
  2703. return "/invoiceUntread";
  2704. }
  2705. function invoiceUntreadRecallDo() {
  2706. $iidKey = isset ( $this->params ['iidKey'] ) ? $this->params ['iidKey'] : "";
  2707. Doo::loadModel ( 'invoice' );
  2708. $invoice = new invoice ();
  2709. Doo::loadClass ( 'XDeode' );
  2710. $XDeode = new XDeode ( 5 );
  2711. Doo::loadModel ( 'invoiceOperationLog' );
  2712. $invoiceOperationLog = new invoiceOperationLog ();
  2713. $iid = $XDeode->decode ( $iidKey );
  2714. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  2715. if (empty ( $invoiceDetail )) {
  2716. die ( 'illegal request-DATANULL' );
  2717. }
  2718. $item = array (
  2719. 'iid' => $iid,
  2720. 'untreadStatus' => 0
  2721. );
  2722. $invoice->setInvoiceByCondition ( $item );
  2723. $item = array (
  2724. 'date' => date ( "Y-m-d H:i:s" ),
  2725. 'operation' => '撤回申请退票',
  2726. 'status' => 13,
  2727. 'img' => $this->staff [0] ['avatar'],
  2728. 'username' => $this->staff [0] ['username'],
  2729. 'uid' => $this->staff [0] ['sid'],
  2730. 'category' => $this->staff [0] ['category'],
  2731. 'iid' => $iid
  2732. );
  2733. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2734. return "/invoiceUntread";
  2735. }
  2736. /**
  2737. * 建立负票,关联原来发票
  2738. */
  2739. function invoiceLossDo() {
  2740. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2741. if (! empty ( $iidKey )) {
  2742. Doo::loadClass ( 'XDeode' );
  2743. $XDeode = new XDeode ( 5 );
  2744. Doo::loadModel ( 'invoice' );
  2745. $invoice = new invoice ();
  2746. Doo::loadModel ( 'invoiceOperationLog' );
  2747. $invoiceOperationLog = new invoiceOperationLog ();
  2748. $iidKey = $XDeode->decode ( $iidKey );
  2749. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  2750. // 拷贝插入一条发票数据
  2751. $iid = $invoice->setInvoiceLoss ( $iidKey );
  2752. // 更新负票
  2753. $invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  2754. $invoice = new invoice ();
  2755. $item = array (
  2756. 'iid' => $iid,
  2757. 'sid' => $this->staff [0] ['sid'],
  2758. 'userName' => $this->staff [0] ['username'],
  2759. 'cid' => $this->staff [0] ['cid'],
  2760. 'categoryName' => $this->staff [0] ['category'],
  2761. 'invoiceQuantity' => - $invoiceDetail ['invoiceQuantity'],
  2762. 'invoicePrice' => - $invoiceDetail ['invoicePrice'],
  2763. 'invoiceSerial' => $invoiceSerial,
  2764. 'invoiceNo' => '',
  2765. 'printStatus' => 0,
  2766. 'untreadStatus' => 4,
  2767. // 关联发票号
  2768. 'lossIid' => $invoiceDetail ['iid']
  2769. );
  2770. $invoice->setInvoiceByCondition ( $item );
  2771. // 更新原发票
  2772. $invoice = new invoice ();
  2773. $item = array (
  2774. 'iid' => $invoiceDetail ['iid'],
  2775. 'lossIid' => $iid
  2776. );
  2777. $invoice->setInvoiceByCondition ( $item );
  2778. // 操作日志
  2779. $item = array (
  2780. 'date' => date ( "Y-m-d H:i:s" ),
  2781. 'operation' => "创建负票" . $invoiceSerial,
  2782. 'status' => 12,
  2783. 'img' => $this->staff [0] ['avatar'],
  2784. 'username' => $this->staff [0] ['username'],
  2785. 'uid' => $this->staff [0] ['sid'],
  2786. 'category' => $this->staff [0] ['category'],
  2787. 'iid' => $iid
  2788. );
  2789. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2790. // print_r($invoiceDetail);
  2791. // echo $iid;die;
  2792. }
  2793. return '/invoiceUntread';
  2794. }
  2795. /**
  2796. * 上传银行到账 收款文件
  2797. */
  2798. function invoiceReceivablesBankUpload() {
  2799. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  2800. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  2801. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  2802. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  2803. header ( "HTTP/1.1 500 Internal Server Error" );
  2804. echo "POST exceeded maximum allowed size.";
  2805. exit ( 0 );
  2806. }
  2807. // Settings
  2808. $save_path = DOO::conf ()->SITE_PATH . "upload/invoiceReceivablesBank/"; // The path were we will save the file (getcwd() may not be reliable and should be tested in your environment)
  2809. $upload_name = "Filedata";
  2810. $file_name = "";
  2811. $nk = time ();
  2812. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  2813. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  2814. echo "文件无法保存.";
  2815. exit ( 0 );
  2816. }
  2817. echo json_encode ( array (
  2818. 'filename' => $file_name,
  2819. 'id' => $nk
  2820. ) );
  2821. exit ( 0 );
  2822. }
  2823. /**
  2824. * 解析银行到账收款execl并导入库中
  2825. */
  2826. function invoiceReceivablesImport() {
  2827. $path = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  2828. if ($path != "") {
  2829. Doo::loadModel ( 'invoiceReceivables' );
  2830. $invoiceReceivables = new invoiceReceivables ();
  2831. Doo::loadClass ( 'invoice.func' );
  2832. Doo::loadModel ( 'invoiceROLog' );
  2833. $invoiceROLog = new invoiceROLog ();
  2834. Doo::loadModel ( 'invoiceStatistics' );
  2835. $invoiceStatistics = new invoiceStatistics ();
  2836. $exlArray = formatExcelToArrayBank ( DOO::conf ()->SITE_PATH . "upload/invoiceReceivablesBank/" . $path );
  2837. $bankBatchNumber = 'BBN_' . time ();
  2838. Doo::db ()->beginTransaction ();
  2839. // 批量存储收款--由于必须获得收款ID,
  2840. $sql = 'INSERT INTO CLD_invoiceReceivables (OriginalPrice,receivablesPrice, receivablesMessage,receivablesSerial,receivablesBank,receivablesDate,inputStaff,date,receivablesCategory,receivablesStaff,bankBatchNumber,recepitTitleMark)
  2841. VALUES ';
  2842. $date = date ( "Y-m-d" );
  2843. $receivablesList = array ();
  2844. foreach ( $exlArray as $key => $value ) {
  2845. $receivablesSql = '(' . $value ["receivablesPrice"] . ',' . $value ["receivablesPrice"] . ',"' . $value ["receivablesMessage"] . '",' . '"#SK' . date ( "Ymd" ) . mt_rand ( 1000, 9999 ) . '","' . $value ["receivablesBank"] . '","' . $value ["receivablesDate"] . '","' . $this->staff [0] ['username'] . '","' . $date . '","PUBLIC","PUBLIC","' . $bankBatchNumber . '","' . $value ["receivablesMessage"] . '")';
  2846. array_push ( $receivablesList, $receivablesSql );
  2847. }
  2848. $sql = $sql . implode ( ',', $receivablesList );
  2849. // echo $sql;
  2850. Doo::db ()->query ( $sql );
  2851. // 批量存储收款统计
  2852. // 获得刚刚导入数据的irid组-缺少办事处和人员
  2853. $iridList = $invoiceReceivables->getInvoiceReceivablesByBBN ( $bankBatchNumber );
  2854. // 没有irid 回滚所有操作
  2855. if (empty ( $iridList )) {
  2856. Doo::db ()->rollBack ();
  2857. header ( 'Content-Type:text/html;charset=utf-8' );
  2858. die ( '文档或数据不正确,请重新<a href="/invoiceReceivables">上传</a>.' );
  2859. }
  2860. $sql = 'INSERT INTO CLD_invoiceStatistics (date, priceClass,irid,receivablesPrice)
  2861. VALUES ';
  2862. $statisticsList = array ();
  2863. foreach ( $iridList as $value ) {
  2864. $statisticsSql = '("' . $date . '",2,' . $value ['irid'] . ',' . $value ["receivablesPrice"] . ')';
  2865. array_push ( $statisticsList, $statisticsSql );
  2866. }
  2867. $sql = $sql . implode ( ',', $statisticsList );
  2868. Doo::db ()->query ( $sql );
  2869. // 批量存储操作日志
  2870. $sql = 'INSERT INTO CLD_invoiceROLog (operation, date,status,img, username,uid,category,irid)
  2871. VALUES ';
  2872. $ROLogList = array ();
  2873. foreach ( $iridList as $value ) {
  2874. $ROLogSql = '("' . $this->staff [0] ['username'] . ' 转入 公共待认领款项","' . $date . '",1,"' . $this->staff [0] ['avatar'] . '","' . $this->staff [0] ['username'] . '","' . $this->staff [0] ['sid'] . '","' . $this->staff [0] ['category'] . '","' . $value ['irid'] . '")';
  2875. array_push ( $ROLogList, $ROLogSql );
  2876. }
  2877. $sql = $sql . implode ( ',', $ROLogList );
  2878. Doo::db ()->query ( $sql );
  2879. // 批量写入流水
  2880. $sql = 'INSERT INTO CLD_wasteBook (dataID, expensesType,accountType,accountPriceShow, accountPrice,accountBank,category,cid,name,sid,inputDate)
  2881. VALUES ';
  2882. $wasteBookList = array ();
  2883. foreach ( $iridList as $value ) {
  2884. $accountBank = '';
  2885. if ($value ['receivablesBank'] == '纵横广发') {
  2886. $accountBank = 'CGBDeposit';
  2887. } elseif ($value ['receivablesBank'] == '纵横工行') {
  2888. $accountBank = 'ICBCDeposit';
  2889. } elseif ($value ['receivablesBank'] == '华润银行') {
  2890. $accountBank = 'HUADeposit';
  2891. } elseif ($value ['receivablesBank'] == '个人广发') {
  2892. $accountBank = 'PersonalDeposit';
  2893. }
  2894. $wasteBookSql = '("' . $value ['irid'] . ' ",1,7,"' . $value ['receivablesPrice'] . '","' . $value ['receivablesPrice'] . '","' . $accountBank . '",
  2895. "' . $this->staff [0] ['category'] . '","' . $this->staff [0] ['cid'] . '","' . $this->staff [0] ['username'] . '","' . $this->staff [0] ['sid'] . '","' . date ( "Y-m-d H:i:s" ) . '")';
  2896. array_push ( $wasteBookList, $wasteBookSql );
  2897. }
  2898. $sql = $sql . implode ( ',', $wasteBookList );
  2899. Doo::db ()->query ( $sql );
  2900. Doo::db ()->commit ();
  2901. return "/invoiceReceivables";
  2902. }
  2903. echo 'no file';
  2904. }
  2905. function invoiceReceivables() {
  2906. $invoiceTC = $this->get_args ( 'invoiceTC' ) ? $this->get_args ( 'invoiceTC' ) : '';
  2907. Doo::loadModel ( 'L_category' );
  2908. $lCategory = new L_category ();
  2909. Doo::loadModel ( 'staff' );
  2910. $staff = new staff ();
  2911. Doo::loadModel ( 'invoiceReceivables' );
  2912. $invoiceReceivables = new invoiceReceivables ();
  2913. Doo::loadModel ( 'invoice' );
  2914. $invoice = new invoice ();
  2915. Doo::loadClass ( 'XDeode' );
  2916. $XDeode = new XDeode ( 5 );
  2917. $category = $lCategory->getCategory ();
  2918. $staffList = $staff->getStaffByCid ( $this->staff [0] ['cid'] );
  2919. $sql = 'bindStatus=1 and iid!=0';
  2920. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByNew ( 4, $sql );
  2921. // 获取未入账发票
  2922. $invoiceUnAccount = $invoice->getInvoiceByUnAccount ( $invoiceTC );
  2923. $invoiceExistAccount = $invoice->getInvoiceByUnAccount ( '', true );
  2924. foreach ( $invoiceUnAccount as $key => $value ) {
  2925. $invoiceUnAccount [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2926. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2927. if (! empty ( $lastApprover )) {
  2928. $lastApproverKey = array_keys ( $lastApprover );
  2929. $lastApprover = end ( $lastApprover );
  2930. $staffDetail = $staff->getOne ( array (
  2931. 'where' => 'sid=' . end ( $lastApproverKey ),
  2932. 'asArray' => true
  2933. ) );
  2934. $lastApprover ['username'] = $staffDetail ['username'];
  2935. }
  2936. $invoiceUnAccount [$key] ['lastApprover'] = $lastApprover;
  2937. }
  2938. foreach ( $invoiceExistAccount as $key => $value ) {
  2939. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  2940. if (empty ( $irList ))
  2941. $irList [0] ['sumPrice'] = 0;
  2942. $balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  2943. $invoiceExistAccount [$key] ['existAccount'] = $irList [0] ['sumPrice'];
  2944. $invoiceExistAccount [$key] ['balance'] = $balance;
  2945. }
  2946. $receivablesInput = $invoiceReceivables->getInvoiceReceivablesByInput ();
  2947. $halfList = $invoiceReceivables->getInvoiceReceivablesByHalf ();
  2948. $this->data ['halfList'] = $halfList;
  2949. $this->data ['halfCount'] = count ( $halfList );
  2950. // print_r($receivablesList);
  2951. $this->data ['receivablesDate'] = date ( "Y-m-d" );
  2952. $this->data ['ieaCount'] = count ( $invoiceExistAccount );
  2953. $this->data ['invoiceExistAccount'] = $invoiceExistAccount;
  2954. $this->data ['receivablesInput'] = $receivablesInput;
  2955. $this->data ['year'] = date ( 'Y' );
  2956. $this->data ['invoiceUnAccount'] = $invoiceUnAccount;
  2957. $this->data ['receivablesList'] = $receivablesList;
  2958. $this->data ['staffList'] = $staffList;
  2959. $this->data ['category'] = $category;
  2960. $this->data ['memu'] = "invoice";
  2961. $this->data ['staff'] = $this->staff;
  2962. $this->data ['receiptMemu'] = 'invoiceReceivables';
  2963. $this->render ( "/admin/invoiceReceivables", $this->data );
  2964. }
  2965. /**
  2966. * 设置收款认领地区
  2967. */
  2968. function setInvoiceReceivablesClaim() {
  2969. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  2970. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  2971. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  2972. if (! empty ( $iridKey ) && ! empty ( $receivablesCategory )) {
  2973. Doo::loadModel ( 'invoiceReceivables' );
  2974. $invoiceReceivables = new invoiceReceivables ();
  2975. Doo::loadClass ( 'XDeode' );
  2976. $XDeode = new XDeode ( 5 );
  2977. Doo::loadModel ( 'invoiceROLog' );
  2978. $invoiceROLog = new invoiceROLog ();
  2979. $irid = $XDeode->decode ( $iridKey );
  2980. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  2981. if (empty ( $irDetail ))
  2982. die ( 'illegal request' );
  2983. $item = array (
  2984. 'irid' => $irid,
  2985. 'receivablesCategory' => $receivablesCategory
  2986. );
  2987. if ($receivablesCategory != 'PUBLIC') {
  2988. $item += array (
  2989. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  2990. 'inputType' => 1
  2991. );
  2992. }
  2993. $invoiceReceivables = new invoiceReceivables ();
  2994. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2995. // 收款操作日志
  2996. $item = array (
  2997. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 ",
  2998. 'date' => date ( "Y-m-d" ),
  2999. 'status' => 1,
  3000. 'img' => $this->staff [0] ['avatar'],
  3001. 'username' => $this->staff [0] ['username'],
  3002. 'uid' => $this->staff [0] ['sid'],
  3003. 'category' => $this->staff [0] ['category'],
  3004. 'irid' => $irid
  3005. );
  3006. $invoiceROLog->setInvoiceROLog ( $item );
  3007. if (empty ( $action ))
  3008. return '/invoiceReceivables';
  3009. else
  3010. return "/invoiceReceivablesAS";
  3011. }
  3012. die ( 'illegal request' );
  3013. }
  3014. /**
  3015. * 新添加收款直接入账发票
  3016. */
  3017. function invoiceCompareClaimPrice() {
  3018. // 收款录入
  3019. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  3020. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3021. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3022. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3023. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3024. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $iidKey )) {
  3025. Doo::loadModel ( 'invoiceReceivables' );
  3026. $invoiceReceivables = new invoiceReceivables ();
  3027. Doo::loadModel ( 'invoiceROLog' );
  3028. $invoiceROLog = new invoiceROLog ();
  3029. Doo::loadModel ( 'invoiceStatistics' );
  3030. Doo::loadModel ( 'invoice' );
  3031. $invoice = new invoice ();
  3032. Doo::loadClass ( 'XDeode' );
  3033. $XDeode = new XDeode ( 5 );
  3034. Doo::loadModel ( 'invoiceOperationLog' );
  3035. $invoiceOperationLog = new invoiceOperationLog ();
  3036. $iidKey = $XDeode->decode ( $iidKey );
  3037. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  3038. if (! ($invoiceDetail ['status'] == 2 && $invoiceDetail ['printStatus'] == 1 && $invoiceDetail ['untreadStatus'] == 0))
  3039. die ( 'illegal request' );
  3040. $receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  3041. // 收款录入 并绑定发票
  3042. Doo::db ()->beginTransaction ();
  3043. $bindStatus = 0;
  3044. if ($receivablesPrice <= $invoiceDetail ['invoicePrice']){
  3045. $bindStatus = 1;
  3046. }
  3047. $titleMark = $invoiceDetail ['invoiceTitle'];
  3048. if (! empty ( $invoiceDetail ['invoiceCompany'] ))
  3049. $titleMark = $invoiceDetail ['invoiceCompany'];
  3050. $item = array (
  3051. 'recepitTitleMark' => $titleMark,
  3052. 'bindStatus' => $bindStatus,
  3053. 'iid' => $invoiceDetail ['iid'],
  3054. 'bindPrice' => $invoiceDetail ['invoicePrice'],
  3055. 'bindDate' => date ( "Y-m-d H:i:s" ),
  3056. 'receivablesPrice' => $receivablesPrice,
  3057. 'OriginalPrice' => $receivablesPrice,
  3058. 'receivablesMessage' => $receivablesMessage,
  3059. 'receivablesSerial' => $receivablesSerial,
  3060. 'receivablesBank' => $receivablesBank,
  3061. 'receivablesDate' => $receivablesDate,
  3062. 'inputStaff' => $this->staff [0] ['username'],
  3063. 'accountClerk' => $this->staff [0] ['username'],
  3064. 'date' => date ( "Y-m-d" ),
  3065. 'receivablesCategory' => $invoiceDetail ['cid'] . ':' . $invoiceDetail ['categoryName'],
  3066. 'receivablesStaff' => $invoiceDetail ['sid'] . '-' . $invoiceDetail ['userName'],
  3067. 'confirmTime' => date ( "Y-m-d H:i:s" )
  3068. );
  3069. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  3070. $item = array ();
  3071. // 收款操作日志
  3072. $item = array (
  3073. 'operation' => $this->staff [0] ['username'] . " 转入 " . $invoiceDetail ['userName']
  3074. );
  3075. $item += array (
  3076. 'date' => date ( "Y-m-d" ),
  3077. 'status' => 1,
  3078. 'img' => $this->staff [0] ['avatar'],
  3079. 'username' => $this->staff [0] ['username'],
  3080. 'uid' => $this->staff [0] ['sid'],
  3081. 'category' => $this->staff [0] ['category'],
  3082. 'irid' => $irid
  3083. );
  3084. $invoiceROLog->setInvoiceROLog ( $item );
  3085. // 收款统计
  3086. $invoiceStatistics = new invoiceStatistics ();
  3087. $item = array (
  3088. 'date' => $receivablesDate,
  3089. 'priceClass' => 2,
  3090. 'irid' => $irid,
  3091. 'cid' => $invoiceDetail ['cid'],
  3092. 'staff' => $invoiceDetail ['sid'],
  3093. 'receivablesPrice' => $receivablesPrice
  3094. );
  3095. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3096. // 收款 入 发票
  3097. $detail = $invoiceDetail;
  3098. $iridString = "";
  3099. if (empty ( $detail ['irid'] ))
  3100. $iridString = $irid;
  3101. else
  3102. $iridString = $detail ['irid'] . ',' . $irid;
  3103. $item = array (
  3104. 'irid' => $iridString,
  3105. 'bindTime' => date ( "Y-m-d H:i:s" ),
  3106. 'updateTime' => date ( "Y-m-d H:i:s" ),
  3107. 'iid' => $detail ['iid']
  3108. );
  3109. $invoiceReceivables = new invoiceReceivables ();
  3110. $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  3111. if ($detail ['invoicePrice'] <= $sum)
  3112. $item += array (
  3113. 'untreadStatus' => 3
  3114. );
  3115. $invoice->setInvoiceByCondition ( $item );
  3116. // 操作日志
  3117. $item = array (
  3118. 'date' => date ( "Y-m-d H:i:s" ),
  3119. 'operation' => "收款入账" . $receivablesSerial . "到发票" . $detail ['invoiceSerial'],
  3120. 'status' => 8,
  3121. 'img' => $this->staff [0] ['avatar'],
  3122. 'username' => $this->staff [0] ['username'],
  3123. 'uid' => $this->staff [0] ['sid'],
  3124. 'category' => $this->staff [0] ['category'],
  3125. 'iid' => $detail ['iid']
  3126. );
  3127. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3128. // 入账汇总
  3129. $invoiceStatistics = new invoiceStatistics ();
  3130. // $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $iridString );
  3131. // $accountPrice = 0;
  3132. // foreach ( $list as $key => $value ) {
  3133. // $accountPrice += $value ['receivablesPrice'];
  3134. // }
  3135. $item = array (
  3136. 'date' => $receivablesDate,
  3137. 'priceClass' => 3,
  3138. 'cid' => $invoiceDetail ['cid'],
  3139. 'staff' => $invoiceDetail ['sid'],
  3140. 'accountPrice' => $receivablesPrice
  3141. );
  3142. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3143. // 公司流水记录
  3144. Doo::loadModel ( 'wasteBook' );
  3145. $wasteBook = new wasteBook ();
  3146. $abDetail = $wasteBook->getAccountBookByAid ( 2, 7, $irid );
  3147. $accountBank = '';
  3148. if ($receivablesBank == '纵横广发') {
  3149. $accountBank = 'CGBDeposit';
  3150. } elseif ($receivablesBank == '纵横工行') {
  3151. $accountBank = 'ICBCDeposit';
  3152. } elseif ($receivablesBank == '华润银行') {
  3153. $accountBank = 'HUADeposit';
  3154. } elseif ($receivablesBank == '个人广发') {
  3155. $accountBank = 'PersonalDeposit';
  3156. }
  3157. if (empty ( $abDetail )) {
  3158. $item = array (
  3159. 'dataID' => $irid,
  3160. 'expensesType' => 1,
  3161. 'accountType' => 7,
  3162. 'accountPrice' => $receivablesPrice,
  3163. 'accountPriceShow' => $receivablesPrice,
  3164. 'accountBank' => $accountBank,
  3165. 'category' => $this->staff [0] ['category'],
  3166. 'cid' => $this->staff [0] ['cid'],
  3167. 'name' => $this->staff [0] ['username'],
  3168. 'sid' => $this->staff [0] ['sid'],
  3169. 'inputDate' => date ( "Y-m-d H:i:s" )
  3170. );
  3171. $wasteBook->setAccountBookStatistics ( $item );
  3172. }
  3173. Doo::db ()->commit ();
  3174. }
  3175. return '/invoiceReceivables';
  3176. }
  3177. /**
  3178. * 录入收款数据
  3179. * @return string
  3180. */
  3181. function invoiceReceivablesDo() {
  3182. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3183. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3184. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3185. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3186. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3187. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  3188. Doo::loadModel ( 'invoiceReceivables' );
  3189. $invoiceReceivables = new invoiceReceivables ();
  3190. Doo::loadModel ( 'invoiceROLog' );
  3191. $invoiceROLog = new invoiceROLog ();
  3192. Doo::loadModel ( 'invoiceStatistics' );
  3193. $invoiceStatistics = new invoiceStatistics ();
  3194. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $receivablesCategory ) && ! empty ( $receivablesStaff )) {
  3195. $item = array (
  3196. 'receivablesPrice' => $receivablesPrice,
  3197. 'OriginalPrice' => $receivablesPrice,
  3198. 'receivablesMessage' => $receivablesMessage,
  3199. 'receivablesSerial' => "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  3200. 'receivablesBank' => $receivablesBank,
  3201. 'receivablesDate' => $receivablesDate,
  3202. 'inputStaff' => $this->staff [0] ['username'],
  3203. 'date' => date ( "Y-m-d" ),
  3204. 'receivablesCategory' => $receivablesCategory,
  3205. 'receivablesStaff' => $receivablesStaff
  3206. );
  3207. if ($receivablesCategory != 'PUBLIC') {
  3208. $item += array (
  3209. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3210. 'inputType' => 1
  3211. );
  3212. }
  3213. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  3214. $item = array ();
  3215. // 收款操作日志
  3216. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3217. $item = array (
  3218. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  3219. );
  3220. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3221. $item = array (
  3222. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  3223. );
  3224. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3225. $receivablesStaff = explode ( '-', $receivablesStaff );
  3226. $item = array (
  3227. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  3228. );
  3229. }
  3230. $item += array (
  3231. 'date' => date ( "Y-m-d" ),
  3232. 'status' => 1,
  3233. 'img' => $this->staff [0] ['avatar'],
  3234. 'username' => $this->staff [0] ['username'],
  3235. 'uid' => $this->staff [0] ['sid'],
  3236. 'category' => $this->staff [0] ['category'],
  3237. 'irid' => $irid
  3238. );
  3239. $invoiceROLog->setInvoiceROLog ( $item );
  3240. $item = array (
  3241. 'date' => $receivablesDate,
  3242. 'priceClass' => 2,
  3243. 'irid' => $irid,
  3244. 'receivablesPrice' => $receivablesPrice
  3245. );
  3246. if ($receivablesCategory != 'PUBLIC') {
  3247. $receivablesCategory = explode ( ":", $receivablesCategory );
  3248. $item += array (
  3249. 'cid' => $receivablesCategory [0]
  3250. );
  3251. }
  3252. if ($receivablesStaff2 != 'PUBLIC') {
  3253. $receivablesStaff = explode ( "-", $receivablesStaff2 );
  3254. $item += array (
  3255. 'staff' => $receivablesStaff [0]
  3256. );
  3257. }
  3258. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3259. $toparty = $this->getWxidByCategory ( $receivablesCategory [1] );
  3260. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  3261. $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  3262. if ($toparty != 0)
  3263. $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  3264. // 公司流水记录
  3265. Doo::loadModel ( 'wasteBook' );
  3266. $wasteBook = new wasteBook ();
  3267. $abDetail = $wasteBook->getAccountBookByAid ( 1, 7, $irid );
  3268. $accountBank = '';
  3269. if ($receivablesBank == '纵横广发') {
  3270. $accountBank = 'CGBDeposit';
  3271. } elseif ($receivablesBank == '纵横工行') {
  3272. $accountBank = 'ICBCDeposit';
  3273. } elseif ($receivablesBank == '华润银行') {
  3274. $accountBank = 'HUADeposit';
  3275. } elseif ($receivablesBank == '个人广发') {
  3276. $accountBank = 'PersonalDeposit';
  3277. }
  3278. $item = array (
  3279. 'dataID' => $irid,
  3280. 'expensesType' => 1,
  3281. 'accountType' => 7,
  3282. 'accountPriceShow' => $receivablesPrice,
  3283. 'accountPrice' => $receivablesPrice,
  3284. 'accountBank' => $accountBank,
  3285. 'category' => $this->staff [0] ['category'],
  3286. 'cid' => $this->staff [0] ['cid'],
  3287. 'name' => $this->staff [0] ['username'],
  3288. 'sid' => $this->staff [0] ['sid'],
  3289. 'inputDate' => date ( "Y-m-d H:i:s" )
  3290. );
  3291. $wasteBook->setAccountBookStatistics ( $item );
  3292. }
  3293. return "/invoiceReceivables";
  3294. }
  3295. /**
  3296. * 收款认领页面-包括公共认领 办事处认领 最近已认领数据
  3297. */
  3298. function invoiceReceivablesClaim() {
  3299. Doo::loadModel ( 'invoiceReceivables' );
  3300. $invoiceReceivables = new invoiceReceivables ();
  3301. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  3302. $this->data ['receivablesList'] = $receivablesList;
  3303. $this->data ['memu'] = "invoice";
  3304. $this->data ['staff'] = $this->staff;
  3305. $this->data ['receiptMemu'] = 'invoiceReceivablesClaim';
  3306. $this->render ( "/admin/invoiceReceivablesClaim", $this->data );
  3307. }
  3308. function invoiceReceivablesTitleMarkSet() {
  3309. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  3310. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  3311. if (empty ( $iridKey ) || empty ( $recepitTitleMark ))
  3312. die ( 'illegal request' );
  3313. Doo::loadModel ( 'invoiceReceivables' );
  3314. $invoiceReceivables = new invoiceReceivables ();
  3315. Doo::loadClass ( 'XDeode' );
  3316. $XDeode = new XDeode ( 5 );
  3317. $irid = $XDeode->decode ( $iridKey );
  3318. if (! is_numeric ( $irid ))
  3319. die ( 'illegal request' );
  3320. $invoiceReceivables->recepitTitleMark = $recepitTitleMark;
  3321. $invoiceReceivables->update ( array (
  3322. 'where' => 'irid = ' . $irid
  3323. ) );
  3324. return '/invoiceReceivablesClaim';
  3325. }
  3326. /**
  3327. * 更新收款相关数据
  3328. */
  3329. function invoiceReceivablesUpdateClaim() {
  3330. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3331. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3332. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3333. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3334. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3335. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  3336. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  3337. if (empty ( $claimKey ))
  3338. die ( 'illegal request' );
  3339. Doo::loadModel ( 'invoiceReceivables' );
  3340. $invoiceReceivables = new invoiceReceivables ();
  3341. Doo::loadModel ( 'invoiceROLog' );
  3342. $invoiceROLog = new invoiceROLog ();
  3343. $con = ' and iid=0 and bindStatus=0'; // and receivablesCategory!="PUBLIC" and receivablesStaff!="PUBLIC"
  3344. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  3345. if (empty ( $detail ))
  3346. die ( 'illegal request' );
  3347. $invoiceReceivables = new invoiceReceivables ();
  3348. $item = array (
  3349. 'irid' => $detail ['irid']
  3350. );
  3351. if ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3352. $item += array (
  3353. 'confirmTime' => date ( "Y-m-d H:i:s" )
  3354. );
  3355. }
  3356. if (! empty ( $receivablesCategory ))
  3357. $item += array (
  3358. 'receivablesCategory' => $receivablesCategory
  3359. );
  3360. if (! empty ( $receivablesStaff ))
  3361. $item += array (
  3362. 'receivablesStaff' => $receivablesStaff
  3363. );
  3364. if (! empty ( $receivablesPrice ))
  3365. $item += array (
  3366. 'receivablesPrice' => $receivablesPrice
  3367. );
  3368. if (! empty ( $receivablesMessage ))
  3369. $item += array (
  3370. 'receivablesMessage' => $receivablesMessage
  3371. );
  3372. if (! empty ( $receivablesBank ))
  3373. $item += array (
  3374. 'receivablesBank' => $receivablesBank
  3375. );
  3376. if (! empty ( $receivablesDate ))
  3377. $item += array (
  3378. 'receivablesDate' => $receivablesDate
  3379. );
  3380. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3381. // 收款操作日志
  3382. $item = array ();
  3383. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3384. $item = array (
  3385. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  3386. );
  3387. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3388. $item = array (
  3389. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  3390. );
  3391. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3392. $receivablesStaff = explode ( '-', $receivablesStaff );
  3393. $item = array (
  3394. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  3395. );
  3396. }
  3397. $item += array (
  3398. 'date' => date ( "Y-m-d" ),
  3399. 'status' => 1,
  3400. 'img' => $this->staff [0] ['avatar'],
  3401. 'username' => $this->staff [0] ['username'],
  3402. 'uid' => $this->staff [0] ['sid'],
  3403. 'category' => $this->staff [0] ['category'],
  3404. 'irid' => $detail ['irid']
  3405. );
  3406. $invoiceROLog->setInvoiceROLog ( $item );
  3407. return '/invoiceReceivablesAS';
  3408. }
  3409. function invoiceReceivablesDelete() {
  3410. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  3411. $skll = $this->get_args ( 'skll' ) ? $this->get_args ( 'skll' ) : "";
  3412. if ($skll != '删除到款')
  3413. die ( 'illegal request' );
  3414. if (empty ( $claimKey ))
  3415. die ( 'illegal request' );
  3416. Doo::loadModel ( 'invoiceReceivables' );
  3417. $invoiceReceivables = new invoiceReceivables ();
  3418. $con = ' and bindStatus=0 ';
  3419. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  3420. if (empty ( $detail ))
  3421. die ( 'illegal request' );
  3422. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  3423. // 扣除收款汇总信息 汇总
  3424. Doo::loadModel ( 'invoiceStatistics' );
  3425. $invoiceStatistics = new invoiceStatistics ();
  3426. $item = array (
  3427. 'date' => $detail ['receivablesDate'],
  3428. 'priceClass' => 2,
  3429. 'irid' => $detail ['irid'],
  3430. 'receivablesPrice' => - $detail ['receivablesPrice']
  3431. );
  3432. if ($detail ['receivablesCategory'] != 'PUBLIC') {
  3433. $receivablesCategory = explode ( ":", $detail ['receivablesCategory'] );
  3434. $item += array (
  3435. 'cid' => $receivablesCategory [0]
  3436. );
  3437. }
  3438. if ($detail ['receivablesStaff'] != 'PUBLIC') {
  3439. $receivablesStaff = explode ( "-", $detail ['receivablesStaff'] );
  3440. $item += array (
  3441. 'staff' => $receivablesStaff [0]
  3442. );
  3443. }
  3444. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3445. // 公司流水-删除时删除流水
  3446. Doo::loadModel ( 'wasteBook' );
  3447. $wasteBook = new wasteBook ();
  3448. $wasteBook->delete ( array (
  3449. 'where' => 'dataID=' . $detail ['irid'] . ' and accountType=7',
  3450. 'limit' => 1
  3451. ) );
  3452. return '/invoiceReceivablesAS';
  3453. }
  3454. /**
  3455. * 管理员录入的收款 ,确认认领到谁的名下.统计收款金额
  3456. */
  3457. function invoiceReceivablesAscription() {
  3458. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  3459. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  3460. Doo::loadModel ( 'invoiceReceivables' );
  3461. $invoiceReceivables = new invoiceReceivables ();
  3462. Doo::loadModel ( 'invoiceROLog' );
  3463. $invoiceROLog = new invoiceROLog ();
  3464. Doo::loadModel ( 'invoiceStatistics' );
  3465. $invoiceStatistics = new invoiceStatistics ();
  3466. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  3467. if (! empty ( $detail ) && $detail ['receivablesStaff'] == 'PUBLIC' && ! empty ( $recepitTitleMark )) {
  3468. $item = array (
  3469. 'irid' => $detail ['irid'],
  3470. 'receivablesCategory' => $this->staff [0] ['cid'] . ":" . $this->staff [0] ['category'],
  3471. 'receivablesStaff' => $this->staff [0] ['sid'] . "-" . $this->staff [0] ['username'],
  3472. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3473. 'recepitTitleMark' => $recepitTitleMark,
  3474. 'source' => 1
  3475. );
  3476. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3477. $item = array (
  3478. 'date' => date ( "Y-m-d" ),
  3479. 'operation' => $this->staff [0] ['username'] . " 认领 ",
  3480. 'status' => 2,
  3481. 'img' => $this->staff [0] ['avatar'],
  3482. 'username' => $this->staff [0] ['username'],
  3483. 'uid' => $this->staff [0] ['sid'],
  3484. 'category' => $this->staff [0] ['category'],
  3485. 'irid' => $irid
  3486. );
  3487. $invoiceROLog->setInvoiceROLog ( $item );
  3488. $item = array (
  3489. 'cid' => $this->staff [0] ['cid'],
  3490. 'staff' => $this->staff [0] ['sid']
  3491. );
  3492. $invoiceStatistics->updateInvoiceStatisticsByIrid ( $item, $detail ['irid'], 2 );
  3493. }
  3494. return "/invoiceReceivablesClaim";
  3495. }
  3496. /**
  3497. */
  3498. function invoiceMyReceivables() {
  3499. Doo::loadModel ( 'invoiceReceivables' );
  3500. $invoiceReceivables = new invoiceReceivables ();
  3501. Doo::loadModel ( 'invoiceStatistics' );
  3502. $invoiceStatistics = new invoiceStatistics ();
  3503. $isMonth = $invoiceStatistics->getStatisticsByMonth ( $this->staff [0] ['sid'] );
  3504. $year = date ( "Y" );
  3505. $tmp_date = date ( "Ym" );
  3506. $tmp_year = substr ( $tmp_date, 0, 4 );
  3507. $tmp_mon = substr ( $tmp_date, 4, 2 );
  3508. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  3509. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  3510. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . ".htm";
  3511. $htm = $this->showCache ( $path );
  3512. $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  3513. $this->data ['isMonth'] = $isMonth;
  3514. $this->data ['htm'] = $htm;
  3515. $this->data ['list'] = $list;
  3516. $this->data ['memu'] = "invoice";
  3517. $this->data ['staff'] = $this->staff;
  3518. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  3519. $this->render ( "/admin/invoiceMyReceivables", $this->data );
  3520. }
  3521. /**
  3522. * 纸票管理
  3523. */
  3524. function invoicePaper() {
  3525. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3526. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3527. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3528. $this->data ['dateString'] = $date;
  3529. $this->data ['status'] = $status;
  3530. $this->data ['invoiceType'] = $invoiceType;
  3531. $this->data ['memu'] = "invoice";
  3532. $this->data ['staff'] = $this->staff;
  3533. $this->data ['receiptMemu'] = 'invoicePaper';
  3534. $this->render ( "/admin/invoicePaper", $this->data );
  3535. }
  3536. /**
  3537. * 获得纸票分页数据
  3538. */
  3539. function ajaxGetinvoicePaperAchieve() {
  3540. Doo::loadModel ( 'invoicePaper' );
  3541. $invoicePaper = new invoicePaper ();
  3542. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3543. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3544. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ORDINARY";
  3545. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3546. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  3547. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  3548. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  3549. $MebSea = $this->get_args ( 'search' );
  3550. $MebSea = $MebSea ['value'];
  3551. $page_size = $length;
  3552. $con = '';
  3553. if ($status == 'ALL')
  3554. $con = ' where 1 ';
  3555. elseif ($status == 'PRINTED')
  3556. $con = ' where a.iid!=0 '; // $con = ' where b.isDelete=0 and a.iid!=0 and b.status=2 and b.untreadStatus=0 ';
  3557. elseif ($status == 'UNPRINT')
  3558. $con = ' where a.iid=0 '; // $con = ' where b.isDelete=0 and a.iid=0 and b.status=2 and b.untreadStatus=0 ';
  3559. elseif ($status == 'TICKET')
  3560. $con = ' where b.isDelete=0 and b.untreadStatus=2';
  3561. if ($invoiceType == 'ORDINARY')
  3562. $con .= ' and a.invoiceType=0 ';
  3563. elseif ($invoiceType == 'SPECIAL')
  3564. $con .= ' and a.invoiceType=1 ';
  3565. $dateArr = explode ( ':', $date );
  3566. $D1 = $dateString = '';
  3567. $D2 = '';
  3568. if (! empty ( $date )) {
  3569. $D1 = $dateArr [0];
  3570. if (isset ( $dateArr [1] ))
  3571. $D2 = $dateArr [1];
  3572. else
  3573. $D2 = '';
  3574. $dateString = $D1 . " : " . $D2;
  3575. }
  3576. if (! empty ( $D1 ) && ! empty ( $D2 ))
  3577. $con .= ' and b.printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  3578. elseif (! empty ( $D1 ) && empty ( $D2 ))
  3579. $con .= ' and b.printTime like "%' . $D1 . '%" ';
  3580. if (! empty ( $MebSea ))
  3581. $con .= ' and ( b.invoiceTitle like "%' . $MebSea . '%" or b.invoiceCompany like "%' . $MebSea . '%" or a.invoiceNo like "%' . $MebSea . '%" )';
  3582. $invoiceTotal = $invoicePaper->getInvoicePaperCount ();
  3583. $sql = ' ' . $con;
  3584. $limit = $page . ',' . $page_size;
  3585. $list = $invoicePaper->getInvoicePaper ( $limit, $sql, 'desc' );
  3586. $paperList = array ();
  3587. foreach ( $list as $key => $value ) {
  3588. $irDetail = array ();
  3589. if ($value ['iid'] == 0)
  3590. array_push ( $irDetail, '<a href="javascript:if(window.confirm(\'确认删除?\'))window.location=\'/invoicePaperDel/' . $value ['ipidKey'] . '\'" >删除</a>' );
  3591. else
  3592. array_push ( $irDetail, '' );
  3593. array_push ( $irDetail, $value ['invoiceCode'] );
  3594. array_push ( $irDetail, $value ['invoiceNo'] );
  3595. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKey'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  3596. if ($value ['invoiceType'] == 1)
  3597. array_push ( $irDetail, $value ['invoiceCompany'] );
  3598. else
  3599. array_push ( $irDetail, $value ['invoiceTitle'] );
  3600. if ($value ['invoiceType'] == 1)
  3601. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  3602. else
  3603. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  3604. array_push ( $irDetail, $value ['invoiceElement'] );
  3605. array_push ( $irDetail, $value ['categoryName'] . '-' . $value ['userName'] );
  3606. array_push ( $irDetail, $value ['printTime'] );
  3607. array_push ( $paperList, $irDetail );
  3608. }
  3609. // $approvalListJson = json_encode ( $approvalList );
  3610. $recordsFiltered = $invoiceTotal;
  3611. echo json_encode ( array (
  3612. "draw" => intval ( $draw ),
  3613. "recordsTotal" => intval ( $invoiceTotal ),
  3614. "recordsFiltered" => intval ( $recordsFiltered ),
  3615. "data" => $paperList
  3616. ), JSON_UNESCAPED_UNICODE );
  3617. }
  3618. function invoicePaperDel() {
  3619. $ipidKey = isset ( $this->params ['ipidKey'] ) ? $this->params ['ipidKey'] : "";
  3620. $XDeode = new XDeode ( 5 );
  3621. $ipid = $XDeode->decode ( $ipidKey );
  3622. if (empty ( $ipid ))
  3623. die ( 'illegal request' );
  3624. Doo::loadModel ( 'invoicePaper' );
  3625. $invoicePaper = new invoicePaper ();
  3626. $invoicePaper->delete ( array (
  3627. 'where' => 'ipid=' . $ipid . ' and iid=0',
  3628. 'limit' => 1
  3629. ) );
  3630. return '/invoicePaper';
  3631. }
  3632. /**
  3633. * 添加纸质发票号
  3634. */
  3635. function invoicePaperAdd() {
  3636. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : '0';
  3637. $invoiceCode = $this->get_args ( 'invoiceCode' ) ? $this->get_args ( 'invoiceCode' ) : "";
  3638. $invoiceNoStart = $this->get_args ( 'invoiceNoStart' ) && is_numeric ( $this->get_args ( 'invoiceNoStart' ) ) ? $this->get_args ( 'invoiceNoStart' ) : 0;
  3639. $invoiceNoTotal = $this->get_args ( 'invoiceNoTotal' ) && is_numeric ( $this->get_args ( 'invoiceNoTotal' ) ) ? $this->get_args ( 'invoiceNoTotal' ) : 0;
  3640. if ($invoiceType != '' && ! empty ( $invoiceCode ) && ! empty ( $invoiceNoStart ) && ! empty ( $invoiceNoTotal )) {
  3641. $sum = $invoiceNoStart + $invoiceNoTotal;
  3642. if (empty ( $sum ))
  3643. die ( 'illegal request' );
  3644. // echo $invoiceNoStart;
  3645. // echo $sum;
  3646. // echo strlen((int)$invoiceNoStart);
  3647. $sumLenght = strlen ( $invoiceNoStart ) - strlen ( ( int ) $invoiceNoStart );
  3648. Doo::db ()->beginTransaction ();
  3649. // 批量存储纸质发票
  3650. $date = date ( "Y-m-d H:i:s" );
  3651. $sql = 'INSERT INTO CLD_invoicePaper (invoiceType, invoiceCode,invoiceNo,date)
  3652. VALUES ';
  3653. $paperList = array ();
  3654. for($invoiceNoStart; $invoiceNoStart <= $sum - 1; $invoiceNoStart ++) {
  3655. // 数字前面自加0
  3656. $INLENGHT = strlen ( ( int ) $invoiceNoStart ) + $sumLenght;
  3657. $var = sprintf ( "%0" . $INLENGHT . "d", $invoiceNoStart );
  3658. $paperSql = '(' . $invoiceType . ',"' . $invoiceCode . '","' . $var . '","' . $date . '")';
  3659. array_push ( $paperList, $paperSql );
  3660. }
  3661. if (empty ( $paperList ))
  3662. die ( 'illegal request' );
  3663. $sql = $sql . implode ( ',', $paperList );
  3664. Doo::db ()->query ( $sql );
  3665. Doo::db ()->commit ();
  3666. return 'invoicePaper';
  3667. }
  3668. die ( 'illegal request' );
  3669. }
  3670. /**
  3671. * 收款绑定发票 ,//一个收款只能绑定一个发票
  3672. */
  3673. function invoiceBindReceivables() {
  3674. $claimKey = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  3675. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  3676. Doo::loadModel ( 'invoice' );
  3677. $invoice = new invoice ();
  3678. Doo::loadModel ( 'invoiceReceivables' );
  3679. $invoiceReceivables = new invoiceReceivables ();
  3680. Doo::loadModel ( 'invoiceOperationLog' );
  3681. $invoiceOperationLog = new invoiceOperationLog ();
  3682. if (empty ( $invoiceKey ) || empty ( $claimKey ))
  3683. die ( 'illegal request' );
  3684. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  3685. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey );
  3686. if (empty ( $detail ) && empty ( $detailM ))
  3687. die ( 'illegal request' );
  3688. if ($detail ['untreadStatus'] == 3)
  3689. die ( 'illegal request' );
  3690. // 修改 绑定状态改为 金额
  3691. $invoiceReceivables = new invoiceReceivables ();
  3692. $invoicePrice = $detail ['invoicePrice'] + $detailM ['bindPrice'];
  3693. if ($detailM ['receivablesPrice'] > $invoicePrice) {
  3694. $item = array (
  3695. 'bindPrice' => $invoicePrice
  3696. );
  3697. } elseif ($detailM ['receivablesPrice'] <= $invoicePrice) {
  3698. $item = array (
  3699. 'bindPrice' => $invoicePrice,
  3700. 'bindStatus' => 1,
  3701. 'bindDate' => date ( "Y-m-d H:i:s" )
  3702. );
  3703. } else {
  3704. die ( 'illegal request' );
  3705. }
  3706. if ($detailM ['iid'] == 0) {
  3707. $item += array (
  3708. 'iid' => $detail ['iid']
  3709. );
  3710. } else {
  3711. $iidExtend = explode ( ',', $detailM ['iidExtend'] );
  3712. array_push ( $iidExtend, $detail ['iid'] );
  3713. $item += array (
  3714. 'iidExtend' => implode ( ',', $iidExtend )
  3715. );
  3716. }
  3717. $titleMark = $detail ['invoiceTitle'];
  3718. if (! empty ( $detail ['invoiceCompany'] ))
  3719. $titleMark = $detail ['invoiceCompany'];
  3720. $item += array (
  3721. 'irid' => $detailM ['irid'],
  3722. 'recepitTitleMark' => $titleMark,
  3723. 'accountClerk' => $this->staff [0] ['username']
  3724. );
  3725. // 如何没有人收款 则自动绑定收款
  3726. if ($detailM ['receivablesCategory'] == 'PUBLIC' || $detailM ['receivablesStaff'] == 'PUBLIC') {
  3727. $item += array (
  3728. 'receivablesCategory' => $detail ['cid'] . ':' . $detail ['categoryName'],
  3729. 'receivablesStaff' => $detail ['sid'] . '-' . $detail ['userName']
  3730. );
  3731. }
  3732. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3733. $iridString = "";
  3734. if (empty ( $detail ['irid'] ))
  3735. $iridString = $detailM ['irid'];
  3736. else
  3737. $iridString = $detail ['irid'] . ',' . $detailM ['irid'];
  3738. $item = array (
  3739. 'iid' => $detail ['iid'],
  3740. 'irid' => $iridString
  3741. );
  3742. $invoiceReceivables = new invoiceReceivables ();
  3743. $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  3744. if ($detail ['invoicePrice'] <= $sum)
  3745. $item += array (
  3746. 'untreadStatus' => 3,
  3747. 'bindTime' => date ( "Y-m-d H:i:s" )
  3748. );
  3749. // print_r($item);
  3750. // echo $sum;die;
  3751. $invoice->setInvoiceByCondition ( $item );
  3752. // 操作日志
  3753. $item = array (
  3754. 'date' => date ( "Y-m-d H:i:s" ),
  3755. 'operation' => "收款" . $detailM ['receivablesSerial'] . "入账到发票" . $detail ['invoiceSerial'],
  3756. 'status' => 8,
  3757. 'img' => $this->staff [0] ['avatar'],
  3758. 'username' => $this->staff [0] ['username'],
  3759. 'uid' => $this->staff [0] ['sid'],
  3760. 'category' => $this->staff [0] ['category'],
  3761. 'iid' => $detail ['iid']
  3762. );
  3763. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3764. Doo::loadModel ( 'invoiceStatistics' );
  3765. $invoiceStatistics = new invoiceStatistics ();
  3766. $item = array (
  3767. 'date' => $detailM ['receivablesDate'],
  3768. 'priceClass' => 3,
  3769. 'cid' => $detail ['cid'],
  3770. 'staff' => $detail ['sid'],
  3771. 'accountPrice' => $detailM ['receivablesPrice']
  3772. );
  3773. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3774. // 公司流水记录
  3775. // Doo::loadModel ( 'wasteBook' );
  3776. // $wasteBook = new wasteBook ();
  3777. // $abDetail = $wasteBook->getAccountBookByAid (1,8,$detail ['iid'] );
  3778. // $accountBank='';
  3779. // if ($detailM ['receivablesBank']=='纵横广发'){
  3780. // $accountBank='CGBDeposit';
  3781. // }elseif($detailM ['receivablesBank']=='纵横工行'){
  3782. // $accountBank='ICBCDeposit';
  3783. // }elseif($detailM ['receivablesBank']=='华润银行'){
  3784. // $accountBank='HUADeposit';
  3785. // }elseif($detailM ['receivablesBank']=='个人广发'){
  3786. // $accountBank='PersonalDeposit';
  3787. // }
  3788. // if (empty($abDetail)){
  3789. // $item = array (
  3790. // 'dataID' => $detail ['iid'],
  3791. // 'expensesType' => 1,
  3792. // 'accountType' => 8,
  3793. // 'accountPriceShow'=>$detail ['invoicePrice'],
  3794. // 'accountPrice'=>$detail ['invoicePrice'],
  3795. // 'accountBank'=>$accountBank,
  3796. // 'category'=>$this->staff[0]['category'],
  3797. // 'cid'=>$this->staff[0]['cid'],
  3798. // 'name'=>$this->staff[0]['username'],
  3799. // 'sid'=>$this->staff[0]['sid'],
  3800. // 'inputDate'=>date ( "Y-m-d H:i:s" )
  3801. // );
  3802. // $wasteBook->setAccountBookStatistics($item);
  3803. // }
  3804. return "/invoiceReceivables";
  3805. }
  3806. /**
  3807. * 核销 动作,确认入账统计 发票收款完成--需求更变 废弃 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"; }
  3808. */
  3809. function invoiceAggregate() {
  3810. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3811. Doo::loadModel ( 'invoiceStatistics' );
  3812. $invoiceStatistics = new invoiceStatistics ();
  3813. Doo::loadModel ( 'L_category' );
  3814. $Lcategory = new L_category ();
  3815. $isList = $invoiceStatistics->getInvoiceStatisticsByYear ( $year );
  3816. $LcategoryList = $Lcategory->getCategory ();
  3817. // print_r($isList);
  3818. $html = ""; // $invoicePriceCategory=0;$receivablesPriceCategory=0;$accountPriceCategory=0;
  3819. foreach ( $LcategoryList as $key => $value ) {
  3820. $html .= '<tr><th><a href="/invoiceAggregateCategory/' . $value ['cidKey'] . '">' . $value ['title'] . '</a></th>';
  3821. $month = 1;
  3822. $invoicePriceYear = 0;
  3823. $receivablesPriceYear = 0;
  3824. $accountPriceYear = 0;
  3825. for(; $month <= 12; $month ++) {
  3826. $flag = true;
  3827. foreach ( $isList ['statisticsMonthCid'] as $k => $v ) {
  3828. if ($value ['cid'] == $v ['cid'] && $month == $v ['month']) {
  3829. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  3830. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  3831. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  3832. ';
  3833. $invoicePriceYear += $v ['invoicePrice'];
  3834. $receivablesPriceYear += $v ['receivablesPrice'];
  3835. $accountPriceYear += $v ['accountPrice'];
  3836. $flag = false;
  3837. break;
  3838. }
  3839. }
  3840. if ($flag)
  3841. $html .= '<td class="taR"></td>
  3842. <td class="taR"></td>
  3843. <td class="taR"><b></b></td>
  3844. ';
  3845. }
  3846. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  3847. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  3848. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  3849. ';
  3850. $html .= '</tr>';
  3851. }
  3852. $html .= '<tr><th><b class="colGreen">月合计</b></th>';
  3853. $invoicePriceYear = 0;
  3854. $receivablesPriceYear = 0;
  3855. $accountPriceYear = 0;
  3856. for($month = 1; $month <= 12; $month ++) {
  3857. $flag = true;
  3858. foreach ( $isList ['statisticsMonth'] as $k => $v ) {
  3859. if ($month == $v ['month']) {
  3860. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  3861. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  3862. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  3863. ';
  3864. $invoicePriceYear += $v ['invoicePrice'];
  3865. $receivablesPriceYear += $v ['receivablesPrice'];
  3866. $accountPriceYear += $v ['accountPrice'];
  3867. $flag = false;
  3868. break;
  3869. }
  3870. }
  3871. if ($flag) {
  3872. $html .= '<td class="taR"></td>
  3873. <td class="taR"></td>
  3874. <td class="taR"><b></b></td>
  3875. ';
  3876. }
  3877. }
  3878. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  3879. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  3880. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  3881. ';
  3882. $html .= '</tr>';
  3883. // print_r($isList);
  3884. $this->data ['html'] = $html;
  3885. $this->data ['LcategoryList'] = $LcategoryList;
  3886. $this->data ['isList'] = $isList;
  3887. $this->data ['year'] = $year;
  3888. $this->data ['memu'] = "invoice";
  3889. $this->data ['staff'] = $this->staff;
  3890. $this->data ['receiptMemu'] = 'invoiceAggregate';
  3891. $this->render ( "/admin/invoiceAggregate", $this->data );
  3892. }
  3893. function invoiceAggregateStaff() {
  3894. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3895. Doo::loadModel ( 'invoiceStatistics' );
  3896. $invoiceStatistics = new invoiceStatistics ();
  3897. Doo::loadModel ( 'L_category' );
  3898. $Lcategory = new L_category ();
  3899. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year );
  3900. $staffList = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year );
  3901. $cStaff = $Lcategory->getCategoryStaff ();
  3902. $html = '';
  3903. foreach ( $cStaff as $key => $value ) {
  3904. $categoryFir = true;
  3905. foreach ( $value ['staff'] as $k => $v ) {
  3906. if ($categoryFir) {
  3907. $width = count ( $value ['staff'] ) + 1;
  3908. $html .= '<tr><th rowspan="' . $width . '">' . $value ['title'] . ' </th>';
  3909. $categoryFir = false;
  3910. } else
  3911. $html .= '<tr>';
  3912. $html .= '<th>' . $v ['username'] . '</th>';
  3913. $invoicePriceStaffYear = 0;
  3914. $receivablesPriceStaffYear = 0;
  3915. $accountPriceStaffYear = 0;
  3916. for($month = 1; $month <= 12; $month ++) {
  3917. $flag = true;
  3918. foreach ( $staffList ['statisticsMonthStaff'] as $sl => $slv ) {
  3919. if ($v ['sid'] == $slv ['staff'] && $month == $slv ['month']) {
  3920. $html .= '<td class="taR">¥' . $slv ['invoicePrice'] . '</td>
  3921. <td class="taR">¥' . $slv ['receivablesPrice'] . '</td>
  3922. <td class="taR"><b>¥' . $slv ['accountPrice'] . '</b></td>
  3923. ';
  3924. $invoicePriceStaffYear += $slv ['invoicePrice'];
  3925. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  3926. $accountPriceStaffYear += $slv ['accountPrice'];
  3927. $flag = false;
  3928. break;
  3929. }
  3930. }
  3931. if ($flag)
  3932. $html .= '<td class="taR"></td>
  3933. <td class="taR"></td>
  3934. <td class="taR"><b></b></td>
  3935. ';
  3936. }
  3937. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  3938. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  3939. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  3940. ';
  3941. }
  3942. $html .= '</tr>';
  3943. // 小计
  3944. if (! empty ( $value ['staff'] )) {
  3945. $html .= '<tr><th class="taR">小计</th>';
  3946. $invoicePriceStaffYear = 0;
  3947. $receivablesPriceStaffYear = 0;
  3948. $accountPriceStaffYear = 0;
  3949. for($month = 1; $month <= 12; $month ++) {
  3950. $flag = true;
  3951. foreach ( $staffList ['statisticsMonthCid'] as $smc => $smcv ) {
  3952. if ($value ['cid'] == $smcv ['cid'] && $month == $slv ['month']) {
  3953. $html .= '<td class="taR">¥' . $smcv ['invoicePrice'] . '</td>
  3954. <td class="taR">¥' . $smcv ['receivablesPrice'] . '</td>
  3955. <td class="taR"><b>¥' . $smcv ['accountPrice'] . '</b></td>
  3956. ';
  3957. $invoicePriceStaffYear += $slv ['invoicePrice'];
  3958. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  3959. $accountPriceStaffYear += $slv ['accountPrice'];
  3960. $flag = false;
  3961. break;
  3962. }
  3963. }
  3964. if ($flag)
  3965. $html .= '<td class="taR"></td>
  3966. <td class="taR"></td>
  3967. <td class="taR"><b></b></td>
  3968. ';
  3969. }
  3970. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  3971. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  3972. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  3973. ';
  3974. $html .= '</tr>';
  3975. }
  3976. }
  3977. $html .= '<tr class="warning"><th colspan="2"><b class="colGreen" >月合计</b></th>';
  3978. $invoicePriceYear = 0;
  3979. $receivablesPriceYear = 0;
  3980. $accountPriceYear = 0;
  3981. for($month = 1; $month <= 12; $month ++) {
  3982. $flag = true;
  3983. foreach ( $staffList ['statisticsMonth'] as $k => $v ) {
  3984. if ($month == $v ['month']) {
  3985. $html .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>
  3986. <td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>
  3987. <td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>
  3988. ';
  3989. $invoicePriceYear += $v ['invoicePrice'];
  3990. $receivablesPriceYear += $v ['receivablesPrice'];
  3991. $accountPriceYear += $v ['accountPrice'];
  3992. $flag = false;
  3993. break;
  3994. }
  3995. }
  3996. if ($flag)
  3997. $html .= '<td class="taR"></td>
  3998. <td class="taR"></td>
  3999. <td class="taR"><b></b></td>
  4000. ';
  4001. }
  4002. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  4003. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  4004. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  4005. ';
  4006. $html .= '</tr>';
  4007. $this->data ['html'] = $html;
  4008. $this->data ['isList'] = $toteList;
  4009. $this->data ['year'] = $year;
  4010. $this->data ['memu'] = "invoice";
  4011. $this->data ['staff'] = $this->staff;
  4012. $this->data ['receiptMemu'] = 'invoiceAggregate';
  4013. $this->render ( "/admin/invoiceAggregateStaff", $this->data );
  4014. }
  4015. function invoiceAggregateCategory() {
  4016. Doo::loadClass ( 'XDeode' );
  4017. $XDeode = new XDeode ( 5 );
  4018. $cid = $cidKey = isset ( $this->params ['cid'] ) ? $this->params ['cid'] : "";
  4019. $cid = $XDeode->decode ( $cid );
  4020. if (! is_numeric ( $cid ))
  4021. die ( 'illegal request' );
  4022. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  4023. Doo::loadModel ( 'invoiceStatistics' );
  4024. $invoiceStatistics = new invoiceStatistics ();
  4025. Doo::loadModel ( 'staff' );
  4026. $staff = new staff ();
  4027. $list = $staff->getStaffByCid ( $cid );
  4028. $isCategory = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year, $cid );
  4029. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year, $cid );
  4030. if (empty ( $list ))
  4031. die ( '该办事处没有成员' );
  4032. $htmlA = $htmlB = $htmlC = $html = '';
  4033. foreach ( $list as $key => $value ) {
  4034. $htmlA = '<tr><th rowspan="3">' . $value ['username'] . '</th><th class="taC">开票</th>';
  4035. $htmlB = '<tr><th class="taC">收款</th>';
  4036. $htmlC = '<tr><th class="taC">入账</th>';
  4037. $invoicePriceStaffYear = 0;
  4038. $receivablesPriceStaffYear = 0;
  4039. $accountPriceStaffYear = 0;
  4040. for($month = 1; $month <= 12; $month ++) {
  4041. $flag = true;
  4042. foreach ( $isCategory ['statisticsMonthStaff'] as $k => $v ) {
  4043. if ($value ['sid'] == $v ['staff'] && $month == $v ['month']) {
  4044. $htmlA .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>';
  4045. $htmlB .= '<td class="taR">¥' . $v ['receivablesPrice'] . '</td>';
  4046. $htmlC .= '<td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>';
  4047. $invoicePriceStaffYear += $v ['invoicePrice'];
  4048. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  4049. $accountPriceStaffYear += $v ['accountPrice'];
  4050. $flag = false;
  4051. break;
  4052. }
  4053. }
  4054. if ($flag) {
  4055. $htmlA .= '<td class="taR">-</td>';
  4056. $htmlB .= '<td class="taR">-</td>';
  4057. $htmlC .= '<td class="taR"><b>-</b></td>';
  4058. }
  4059. }
  4060. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  4061. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  4062. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  4063. $htmlA .= '</tr>';
  4064. $htmlB .= '</tr>';
  4065. $htmlC .= '</tr>';
  4066. $html .= $htmlA . $htmlB . $htmlC;
  4067. }
  4068. $htmlA = $htmlB = $htmlC = "";
  4069. $htmlA = '<tr><th rowspan="3">月合计</th><th class="taC">开票</th>';
  4070. $htmlB = '<tr><th class="taC">收款</th>';
  4071. $htmlC = '<tr><th class="taC">入账</th>';
  4072. $invoicePriceStaffYear = 0;
  4073. $receivablesPriceStaffYear = 0;
  4074. $accountPriceStaffYear = 0;
  4075. for($month = 1; $month <= 12; $month ++) {
  4076. $flag = true;
  4077. foreach ( $isCategory ['statisticsMonth'] as $k => $v ) {
  4078. if ($month == $v ['month']) {
  4079. $htmlA .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>';
  4080. $htmlB .= '<td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>';
  4081. $htmlC .= '<td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>';
  4082. $invoicePriceStaffYear += $v ['invoicePrice'];
  4083. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  4084. $accountPriceStaffYear += $v ['accountPrice'];
  4085. $flag = false;
  4086. break;
  4087. }
  4088. }
  4089. if ($flag) {
  4090. $htmlA .= '<td class="taR">-</td>';
  4091. $htmlB .= '<td class="taR">-</td>';
  4092. $htmlC .= '<td class="taR"><b>-</b></td>';
  4093. }
  4094. }
  4095. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  4096. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  4097. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  4098. $htmlA .= '</tr>';
  4099. $htmlB .= '</tr>';
  4100. $htmlC .= '</tr>';
  4101. $html .= $htmlA . $htmlB . $htmlC;
  4102. $this->data ['html'] = $html;
  4103. $this->data ['cidKey'] = $cidKey;
  4104. $this->data ['slist'] = $list;
  4105. $this->data ['isList'] = $toteList;
  4106. $this->data ['year'] = $year;
  4107. $this->data ['memu'] = "invoice";
  4108. $this->data ['staff'] = $this->staff;
  4109. $this->data ['receiptMemu'] = 'invoiceAggregate';
  4110. $this->render ( "/admin/invoiceAggregateCategory", $this->data );
  4111. }
  4112. /**
  4113. * 办事处汇总信息
  4114. */
  4115. function invoiceAggregateCategoryDetail() {
  4116. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  4117. Doo::loadClass ( 'XDeode' );
  4118. $XDeode = new XDeode ( 5 );
  4119. Doo::loadModel ( 'invoiceStatistics' );
  4120. $invoiceStatistics = new invoiceStatistics ();
  4121. Doo::loadModel ( 'L_category' );
  4122. $category = new L_category ();
  4123. Doo::loadModel ( 'invoice' );
  4124. $invoice = new invoice ();
  4125. Doo::loadModel ( 'staff' );
  4126. $staff = new staff ();
  4127. Doo::loadModel ( "invoiceCategoryManage" );
  4128. $invoiceCategoryManage = new invoiceCategoryManage ();
  4129. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4130. $cidList = array ();
  4131. foreach ( $imcStaff as $key => $value ) {
  4132. array_push ( $cidList, $value ['cid'] );
  4133. if (empty ( $cidKey ))
  4134. $cidKey = $XDeode->encode ( $value ['cid'] );
  4135. }
  4136. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  4137. $cid = $XDeode->decode ( $cidKey );
  4138. $month = date ( "m", strtotime ( "-1 month" ) );
  4139. $YearMonth = date ( "Y-m", strtotime ( "-1 month" ) );
  4140. $redis = new Redis ();
  4141. $redis->connect ( '127.0.0.1', '6379' );
  4142. $redisKey = ''; // date('Y-m-d').'_iacd_'.$cid;
  4143. $redisValue = ''; // $redis->lrange($redisKey, 0, -1);
  4144. if (empty ( $redisValue )) {
  4145. $isMC = $invoiceStatistics->getInvoiceStatistiscsMothByCategory ( $cid );
  4146. $schedule = $invoice->getInvoiceScheduleByCid ( $cid );
  4147. // 获得办事处人员下的汇总
  4148. $slist = $staff->getStaffByCid ( $cid );
  4149. $ismsbMonth = $invoiceStatistics->getISMSByCategoryByMonth ( $cid, $YearMonth ); // 上一个月的汇总
  4150. $ismsb = $invoiceStatistics->getISMSByCategory ( $cid ); // 当月汇总
  4151. $ISAS = $invoiceStatistics->getISASByCategory ( $cid ); // 全部汇总
  4152. $scheduleStaff = $invoice->getInvoiceScheduleByCidGroupSid ( $cid ); // 完成度
  4153. foreach ( $slist as $key => $value ) {
  4154. $slist [$key] ['invoicePrice'] = 0;
  4155. $slist [$key] ['receivablesPrice'] = 0;
  4156. $slist [$key] ['accountPrice'] = 0;
  4157. $slist [$key] ['invoiceAllPrice'] = 0;
  4158. $slist [$key] ['receivablesAllPrice'] = 0;
  4159. $slist [$key] ['accountAllPrice'] = 0;
  4160. $slist [$key] ['schedule'] = 0;
  4161. $slist [$key] ['invoiceMonthPrice'] = 0;
  4162. $slist [$key] ['receivablesMonthPrice'] = 0;
  4163. $slist [$key] ['accountMonthPrice'] = 0;
  4164. foreach ( $ismsbMonth as $y => $l ) {
  4165. if ($value ['sid'] == $l ['staff']) {
  4166. $slist [$key] ['invoiceMonthPrice'] = $l ['invoicePrice'];
  4167. $slist [$key] ['receivablesMonthPrice'] = $l ['receivablesPrice'];
  4168. $slist [$key] ['accountMonthPrice'] = $l ['accountPrice'];
  4169. }
  4170. }
  4171. foreach ( $ismsb as $k => $v ) {
  4172. if ($value ['sid'] == $v ['staff']) {
  4173. $slist [$key] ['invoicePrice'] = $v ['invoicePrice'];
  4174. $slist [$key] ['receivablesPrice'] = $v ['receivablesPrice'];
  4175. $slist [$key] ['accountPrice'] = $v ['accountPrice'];
  4176. }
  4177. }
  4178. foreach ( $ISAS as $e => $a ) {
  4179. if ($value ['sid'] == $a ['staff']) {
  4180. $slist [$key] ['invoiceAllPrice'] = $a ['invoicePrice'];
  4181. $slist [$key] ['receivablesAllPrice'] = $a ['receivablesPrice'];
  4182. $slist [$key] ['accountAllPrice'] = $a ['accountPrice'];
  4183. }
  4184. }
  4185. if (isset ( $scheduleStaff [$value ['sid']] ))
  4186. $slist [$key] ['schedule'] = $scheduleStaff [$value ['sid']];
  4187. }
  4188. $this->data ['cidKey'] = $cidKey;
  4189. $schedule = ( int ) ($schedule * 100);
  4190. $this->data ['slist'] = $slist;
  4191. $this->data ['isMC'] = $isMC;
  4192. $this->data ['schedule'] = $schedule;
  4193. $slist = json_encode ( $slist );
  4194. $isMC = json_encode ( $isMC );
  4195. $schedule = json_encode ( $schedule );
  4196. $redis->lpush ( $redisKey, $slist );
  4197. $redis->lpush ( $redisKey, $isMC );
  4198. $redis->lpush ( $redisKey, $schedule );
  4199. } else {
  4200. $this->data ['cidKey'] = $cidKey;
  4201. $this->data ['slist'] = json_decode ( $redisValue [2], true );
  4202. $this->data ['isMC'] = json_decode ( $redisValue [1], true );
  4203. $this->data ['schedule'] = json_decode ( $redisValue [0], true );
  4204. }
  4205. $this->data ['month'] = $month;
  4206. $this->data ['categoryList'] = $categoryList;
  4207. $this->data ['memu'] = "invoice";
  4208. $this->data ['staff'] = $this->staff;
  4209. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4210. $this->render ( "/admin/invoiceAggregateCategoryDetail", $this->data );
  4211. }
  4212. /**
  4213. * 办事处人员汇总详情
  4214. */
  4215. function invoiceAggregateStaffDetail() {
  4216. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  4217. // $sidKey = isset ( $this->params ['sidKey'] ) ? $this->params ['sidKey'] : '';
  4218. Doo::loadClass ( 'XDeode' );
  4219. $XDeode = new XDeode ( 5 );
  4220. Doo::loadModel ( 'invoice' );
  4221. $invoice = new invoice ();
  4222. Doo::loadModel ( 'staff' );
  4223. $staff = new staff ();
  4224. Doo::loadModel ( "invoiceCategoryManage" );
  4225. $invoiceCategoryManage = new invoiceCategoryManage ();
  4226. $sid = $XDeode->decode ( $sidKey );
  4227. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4228. $cidList = array ();
  4229. foreach ( $imcStaff as $key => $value ) {
  4230. array_push ( $cidList, $value ['cid'] );
  4231. if (empty ( $cidKey ))
  4232. $cidKey = $XDeode->encode ( $value ['cid'] );
  4233. }
  4234. $cidString = implode ( ',', $cidList );
  4235. $staffList = $staff->getStaffInCid ( $cidString );
  4236. $staffDetail = $staff->getStaffBySid ( $sid );
  4237. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4238. $page_size = 18;
  4239. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4240. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4241. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  4242. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  4243. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  4244. $dateArr = explode ( ':', $date );
  4245. $D1 = '';
  4246. $D2 = '';
  4247. if (! empty ( $date )) {
  4248. $D1 = $dateArr [0] . " 00:00:00 ";
  4249. if (isset ( $dateArr [1] ))
  4250. $D2 = $dateArr [1] . " 23:59:59 ";
  4251. else
  4252. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4253. // $D2 = $dateArr [1];
  4254. }
  4255. $con = ' status=2 ';
  4256. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4257. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4258. if ($status == 'UNRECORD')
  4259. $con .= ' and printStatus=1 and untreadStatus=0';
  4260. elseif ($status == 'RECORD')
  4261. $con .= ' and printStatus=1 and untreadStatus=3';
  4262. elseif ($status == 'BOUNCED')
  4263. $con .= ' and untreadStatus=2';
  4264. elseif ($status == 'PARTRECORD')
  4265. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  4266. elseif ($status == 'All') {
  4267. $con .= ' and ( untreadStatus=2 or untreadStatus=0 or untreadStatus=3 )';
  4268. }
  4269. $con .= ' and sid=' . $sid;
  4270. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  4271. if (! empty ( $MebSea )) {
  4272. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  4273. }
  4274. $pageinfo ['page'] = array (
  4275. 'previous' => ''
  4276. );
  4277. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateStaffDetail", $get, "" );
  4278. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4279. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  4280. $this->data ['staffDetail'] = $staffDetail;
  4281. $this->data ['staffList'] = $staffList;
  4282. $this->data ['MebSeaEn'] = $MebSea;
  4283. $this->data ['MebSea'] = urlencode ( $MebSea );
  4284. $this->data ['date'] = $date;
  4285. $this->data ['page'] = $pageinfo;
  4286. $this->data ['get'] = $get;
  4287. $this->data ['list'] = $list;
  4288. $this->data ['status'] = $status;
  4289. $this->data ['sidKey'] = $sidKey;
  4290. $this->data ['memu'] = "invoice";
  4291. $this->data ['staff'] = $this->staff;
  4292. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4293. $this->render ( "/admin/invoiceAggregateStaffDetail", $this->data );
  4294. }
  4295. /**
  4296. * 办事处人员汇总收款情
  4297. */
  4298. function invoiceAggregateStaffReceivablesDetail() {
  4299. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  4300. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  4301. Doo::loadModel ( 'invoiceReceivables' );
  4302. $invoiceReceivables = new invoiceReceivables ();
  4303. Doo::loadModel ( 'staff' );
  4304. $staff = new staff ();
  4305. Doo::loadModel ( "invoiceCategoryManage" );
  4306. $invoiceCategoryManage = new invoiceCategoryManage ();
  4307. Doo::loadClass ( 'XDeode' );
  4308. $XDeode = new XDeode ( 5 );
  4309. $sid = $XDeode->decode ( $sidKey );
  4310. $staffDetail = $staff->getStaffBySid ( $sid );
  4311. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4312. $cidList = array ();
  4313. foreach ( $imcStaff as $key => $value ) {
  4314. array_push ( $cidList, $value ['cid'] );
  4315. if (empty ( $cidKey ))
  4316. $cidKey = $XDeode->encode ( $value ['cid'] );
  4317. }
  4318. $cidString = implode ( ',', $cidList );
  4319. $staffList = $staff->getStaffInCid ( $cidString );
  4320. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4321. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  4322. $page_size = 10;
  4323. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4324. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4325. if ($timeType == "BINDOTP") {
  4326. $status = 'Credited';
  4327. }
  4328. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  4329. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  4330. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  4331. $dateArr = explode ( ':', $date );
  4332. $D1 = '';
  4333. $D2 = '';
  4334. if (! empty ( $date )) {
  4335. $D1 = $dateArr [0] . " 00:00:00 ";
  4336. if (isset ( $dateArr [1] ))
  4337. $D2 = $dateArr [1] . " 23:59:59 ";
  4338. else
  4339. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4340. }
  4341. $con = ' a.receivablesStaff like "%' . $staffDetail ['username'] . '%" ';
  4342. $descField = 'a.bindDate';
  4343. if ($timeType == 'CREATE')
  4344. $descField = 'a.date';
  4345. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4346. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4347. elseif (! empty ( $D1 ) && empty ( $D2 ))
  4348. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  4349. if ($status == 'Unclaimed')
  4350. $con .= ' and a.bindStatus=0';
  4351. elseif ($status == 'Credited')
  4352. $con .= ' and a.bindStatus=1';
  4353. elseif ($status == 'Claim')
  4354. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  4355. elseif ($status == 'BBN')
  4356. $con .= ' and a.bindPrice>a.receivablesPrice';
  4357. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  4358. if (! empty ( $MebSea )) {
  4359. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" )';
  4360. }
  4361. $pageinfo ['page'] = array (
  4362. 'previous' => ''
  4363. );
  4364. $sql = 'select group_concat(b.invoiceSerial) as invoiceSerial ,group_concat(b.iid) as invoiceId
  4365. from CLD_invoiceReceivables as a left join CLD_invoice as b on
  4366. find_in_set(b.iid,a.iidExtend) or a.iid=b.iid
  4367. where ' . $con . ' group by a.irid ';
  4368. $pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceAggregateStaffReceivablesDetail", $get, "" );
  4369. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4370. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', 'printTime' );
  4371. foreach ( $list as $key => $value ) {
  4372. $list [$key] ['category'] = '';
  4373. if ($value ['receivablesCategory'] != 'PUBLIC') {
  4374. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  4375. $list [$key] ['category'] = $receivablesCategory [1];
  4376. }
  4377. }
  4378. // print_r($list);
  4379. $this->data ['staffDetail'] = $staffDetail;
  4380. $this->data ['sidKey'] = $sidKey;
  4381. $this->data ['staffList'] = $staffList;
  4382. $this->data ['timeType'] = $timeType;
  4383. $this->data ['MebSeaEn'] = $MebSea;
  4384. $this->data ['MebSea'] = urlencode ( $MebSea );
  4385. $this->data ['date'] = $date;
  4386. $this->data ['page'] = $pageinfo;
  4387. $this->data ['get'] = $get;
  4388. $this->data ['list'] = $list;
  4389. $this->data ['status'] = $status;
  4390. $this->data ['memu'] = "invoice";
  4391. $this->data ['staff'] = $this->staff;
  4392. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4393. $this->render ( "/admin/invoiceAggregateStaffReceivablesDetail", $this->data );
  4394. }
  4395. function invoiceAchieve() {
  4396. Doo::loadModel ( 'invoice' );
  4397. $invoice = new invoice ();
  4398. Doo::loadClass ( 'XDeode' );
  4399. $XDeode = new XDeode ( 5 );
  4400. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4401. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4402. $page_size = 18;
  4403. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4404. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4405. $get = "/" . $date;
  4406. $con = '';
  4407. if ($date == 'MONTHO')
  4408. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4409. elseif ($date == 'MONTHT')
  4410. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4411. elseif ($date == 'MONTHY')
  4412. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4413. if (! empty ( $MebSea )) {
  4414. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4415. $get .= "/" . $MebSea;
  4416. }
  4417. $pageinfo ['page'] = array (
  4418. 'previous' => ''
  4419. );
  4420. $sql = 'status=2 and printStatus=1 and irid!="" and ( untreadStatus=3 or untreadStatus=0 ) and sid=' . $sid . $con;
  4421. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceAchieve", $get, "" );
  4422. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4423. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  4424. // print_r($pageinfo);
  4425. $this->data ['MebSeaEn'] = $MebSea;
  4426. $this->data ['MebSea'] = urlencode ( $MebSea );
  4427. $this->data ['get'] = $get;
  4428. $this->data ['page'] = $pageinfo;
  4429. $this->data ['list'] = $list;
  4430. $this->data ['date'] = $date;
  4431. $this->data ['memu'] = "invoice";
  4432. $this->data ['staff'] = $this->staff;
  4433. $this->data ['receiptMemu'] = 'invoice';
  4434. $this->render ( "/admin/invoiceAchieve", $this->data );
  4435. }
  4436. /**
  4437. */
  4438. function invoiceMyUnAccountAchieve() {
  4439. Doo::loadModel ( 'invoice' );
  4440. $invoice = new invoice ();
  4441. Doo::loadClass ( 'XDeode' );
  4442. $XDeode = new XDeode ( 5 );
  4443. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4444. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4445. $page_size = 18;
  4446. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4447. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4448. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4449. $dateArr = explode ( ':', $date );
  4450. $D1 = '';
  4451. $D2 = '';
  4452. if (! empty ( $date )) {
  4453. $D1 = $dateArr [0];
  4454. $D2 = $dateArr [1];
  4455. }
  4456. $con = '';
  4457. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4458. $con = ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4459. if (! empty ( $MebSea )) {
  4460. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4461. }
  4462. $pageinfo ['page'] = array (
  4463. 'previous' => ''
  4464. );
  4465. // and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  4466. $sql = " status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid= " . $sid . $con;
  4467. $action = "invoiceMyUnAccountAchieve";
  4468. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  4469. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4470. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 'desc', 'printTime' );
  4471. Doo::loadModel ( 'express' );
  4472. $express = new express ();
  4473. $expressList = $express->getExpressByAll ();
  4474. $this->data ['expressList'] = $expressList;
  4475. // print_r($list);
  4476. $this->data ['MebSeaEn'] = $MebSea;
  4477. $this->data ['get'] = $get;
  4478. $this->data ['page'] = $pageinfo;
  4479. $this->data ['date'] = $date;
  4480. $this->data ['list'] = $list;
  4481. $this->data ['memu'] = "invoice";
  4482. $this->data ['staff'] = $this->staff;
  4483. $this->data ['receiptMemu'] = 'invoice';
  4484. $this->render ( "/admin/invoiceMyUnAccountAchieve", $this->data );
  4485. }
  4486. function invoiceReceivablesAchieve() {
  4487. Doo::loadModel ( 'invoiceReceivables' );
  4488. $invoiceReceivables = new invoiceReceivables ();
  4489. Doo::loadClass ( 'XDeode' );
  4490. $XDeode = new XDeode ( 5 );
  4491. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4492. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  4493. $page_size = 12;
  4494. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4495. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4496. $get = "/" . $date;
  4497. $con = '';
  4498. if ($date == 'MONTHO')
  4499. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4500. elseif ($date == 'MONTHT')
  4501. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4502. elseif ($date == 'MONTHY')
  4503. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4504. if (! empty ( $MebSea )) {
  4505. $con .= ' and ( receivablesMessage like "%' . $MebSea . '%" or receivablesPrice like "%' . $MebSea . '%" )';
  4506. $get .= "/" . $MebSea;
  4507. }
  4508. $pageinfo ['page'] = array (
  4509. 'previous' => ''
  4510. );
  4511. $sql = " bindStatus=1 and receivablesStaff like '" . $sid . "-%' " . $con;
  4512. $pageinfo = $this->get_page ( "CLD_invoiceReceivables", $sql, $page, $page_size, "invoiceReceivablesAchieve", $get, "" );
  4513. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4514. $list = $invoiceReceivables->getReceivablesByUntreadStatusPage ( $limit, $sql );
  4515. // print_r($pageinfo);
  4516. $this->data ['MebSeaEn'] = $MebSea;
  4517. $this->data ['MebSea'] = urlencode ( $MebSea );
  4518. $this->data ['get'] = $get;
  4519. $this->data ['page'] = $pageinfo;
  4520. $this->data ['list'] = $list;
  4521. $this->data ['date'] = $date;
  4522. $this->data ['memu'] = "invoice";
  4523. $this->data ['staff'] = $this->staff;
  4524. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  4525. $this->render ( "/admin/invoiceReceivablesAchieve", $this->data );
  4526. }
  4527. /**
  4528. * 收款解绑
  4529. */
  4530. function invoiceUnBundLing() {
  4531. $unBundKey = $this->get_args ( 'unBundKey' ) ? $this->get_args ( 'unBundKey' ) : '';
  4532. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  4533. Doo::loadModel ( 'invoice' );
  4534. $invoice = new invoice ();
  4535. Doo::loadModel ( 'invoiceReceivables' );
  4536. $invoiceReceivables = new invoiceReceivables ();
  4537. Doo::loadModel ( 'invoiceOperationLog' );
  4538. $invoiceOperationLog = new invoiceOperationLog ();
  4539. Doo::loadModel ( 'invoiceROLog' );
  4540. $invoiceROLog = new invoiceROLog ();
  4541. Doo::loadModel ( 'invoiceStatistics' );
  4542. Doo::loadClass ( 'XDeode' );
  4543. $XDeode = new XDeode ( 5 );
  4544. if (empty ( $iidKey ) || empty ( $unBundKey ))
  4545. die ( 'illegal request' );
  4546. $iid = $XDeode->decode ( $iidKey );
  4547. $irid = $invoice->authcode ( $unBundKey );
  4548. if ((! empty ( $irid ) && ! is_numeric ( $irid )) || (! empty ( $iid ) && ! is_numeric ( $iid )))
  4549. die ( 'illegal request' );
  4550. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4551. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  4552. if (empty ( $irDetails ) || empty ( $invoiceDetails ) || (empty ( $irDetails ['iid'] ) && empty ( $irDetails ['iidExtend'] )) || $invoiceDetails ['untreadStatus'] == 2)
  4553. die ( 'illegal request' );
  4554. // 收款
  4555. $item = array (
  4556. 'irid' => $irDetails ['irid'],
  4557. 'bindPrice' => $irDetails ['bindPrice'] - $invoiceDetails ['invoicePrice'],
  4558. 'bindStatus' => 0
  4559. );
  4560. if ($irDetails ['iid'] == $iid)
  4561. $item += array (
  4562. 'iid' => 0
  4563. );
  4564. else {
  4565. $iidExtend = explode ( ',', $irDetails ['iidExtend'] );
  4566. foreach ( $iidExtend as $key => $value ) {
  4567. if ($value == $iid)
  4568. unset ( $iidExtend [$key] );
  4569. }
  4570. $iidExtend = implode ( ',', $iidExtend );
  4571. $item += array (
  4572. 'iidExtend' => $iidExtend
  4573. );
  4574. }
  4575. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4576. // 收款操作日志
  4577. $item = array (
  4578. 'operation' => $this->staff [0] ['username'] . " 解绑 " . $irDetails ['receivablesSerial'],
  4579. 'date' => date ( "Y-m-d" ),
  4580. 'status' => 3,
  4581. 'img' => $this->staff [0] ['avatar'],
  4582. 'username' => $this->staff [0] ['username'],
  4583. 'uid' => $this->staff [0] ['sid'],
  4584. 'category' => $this->staff [0] ['category'],
  4585. 'irid' => $irid
  4586. );
  4587. $invoiceROLog->setInvoiceROLog ( $item );
  4588. // 扣除入账统计金额
  4589. $invoiceStatistics = new invoiceStatistics ();
  4590. $item = array (
  4591. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  4592. 'priceClass' => 3,
  4593. 'cid' => $invoiceDetails ['cid'],
  4594. 'staff' => $invoiceDetails ['sid'],
  4595. 'accountPrice' => - $irDetails ['receivablesPrice']
  4596. );
  4597. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4598. // 扣除收款统计金额
  4599. $invoiceStatistics = new invoiceStatistics ();
  4600. $item = array (
  4601. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  4602. 'priceClass' => 2,
  4603. 'cid' => $invoiceDetails ['cid'],
  4604. 'staff' => $invoiceDetails ['sid'],
  4605. 'irid' => $irDetails ['irid'],
  4606. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  4607. );
  4608. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4609. // 发票解绑去收款ID
  4610. $iridString = $invoiceDetails ['irid'];
  4611. if (! empty ( $invoiceDetails ['irid'] )) {
  4612. $list = explode ( ',', $invoiceDetails ['irid'] );
  4613. foreach ( $list as $key => $value ) {
  4614. if ($value == $irDetails ['irid']) {
  4615. unset ( $list [$key] );
  4616. break;
  4617. }
  4618. }
  4619. $iridString = implode ( ",", $list );
  4620. }
  4621. $item = array (
  4622. 'iid' => $invoiceDetails ['iid'],
  4623. 'irid' => $iridString,
  4624. 'updateTime' => date ( "Y-m-d H:i:s" )
  4625. );
  4626. if ($invoiceDetails ['untreadStatus'] == 3)
  4627. $item += array (
  4628. 'untreadStatus' => 0
  4629. );
  4630. $invoice->setInvoiceByCondition ( $item );
  4631. $item = array (
  4632. 'date' => date ( "Y-m-d H:i:s" ),
  4633. 'operation' => '解绑 收款 ' . $irDetails ['receivablesSerial'],
  4634. 'status' => 11,
  4635. 'img' => $this->staff [0] ['avatar'],
  4636. 'username' => $this->staff [0] ['username'],
  4637. 'uid' => $this->staff [0] ['sid'],
  4638. 'category' => $this->staff [0] ['category'],
  4639. 'iid' => $invoiceDetails ['iid']
  4640. );
  4641. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  4642. // 公司流水-解绑时删除流水
  4643. Doo::loadModel ( 'wasteBook' );
  4644. $wasteBook = new wasteBook ();
  4645. // $wasteBook->delete ( array (
  4646. // 'where' => 'dataID=' . $irDetails ['irid'] . ' and accountType=7',
  4647. // 'limit' => 1
  4648. // ) );
  4649. // 银行
  4650. /*
  4651. * $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); }
  4652. */
  4653. return "/invoiceReceivablesAS";
  4654. }
  4655. /**
  4656. * 或者该收款下的所以发票
  4657. */
  4658. function ajaxGetInvoiceReceivablesByInvoice() {
  4659. $irid = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : '';
  4660. Doo::loadModel ( 'invoice' );
  4661. $invoice = new invoice ();
  4662. Doo::loadModel ( 'invoiceReceivables' );
  4663. $invoiceReceivables = new invoiceReceivables ();
  4664. $irid = $invoice->authcode ( $irid );
  4665. if (! empty ( $irid ) && ! is_numeric ( $irid ))
  4666. die ( 'illegal request' );
  4667. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4668. $iidString = $irDetails ['iid'];
  4669. $iidExtend = array_filter ( explode ( ',', $irDetails ['iidExtend'] ) );
  4670. if (! empty ( $irDetails ['iidExtend'] ))
  4671. $iidString .= ',' . implode ( ',', $iidExtend );
  4672. $invoiceList = $invoice->getInvoiceInIid ( $iidString, 'iid,invoiceSerial,invoicePrice,invoiceTitle,invoiceCompany,invoiceElement' );
  4673. $html = "";
  4674. foreach ( $invoiceList as $key => $value ) {
  4675. $title = $value ['invoiceTitle'];
  4676. if (! empty ( $value ['invoiceCompany'] ))
  4677. $title = $value ['invoiceCompany'];
  4678. $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>';
  4679. }
  4680. echo json_encode ( array (
  4681. 'status' => 1,
  4682. 'html' => $html
  4683. ) );
  4684. }
  4685. /**
  4686. * 发票管理
  4687. */
  4688. function invoiceAS() {
  4689. Doo::loadModel ( 'invoice' );
  4690. $invoice = new invoice ();
  4691. Doo::loadModel ( 'invoiceReceivables' );
  4692. $invoiceReceivables = new invoiceReceivables ();
  4693. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4694. $page_size = 18;
  4695. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4696. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4697. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4698. $dateArr = explode ( ':', $date );
  4699. $D1 = '';
  4700. $D2 = '';
  4701. if (! empty ( $date )) {
  4702. $D1 = $dateArr [0] . " 00:00:00 ";
  4703. if (isset ( $dateArr [1] ))
  4704. $D2 = $dateArr [1] . " 23:59:59 ";
  4705. else
  4706. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4707. // $D2 = $dateArr [1];
  4708. }
  4709. $con = ' status=2 ';
  4710. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4711. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4712. if ($status == 'UNRECORD')
  4713. $con .= ' and printStatus=1 and untreadStatus=0';
  4714. elseif ($status == 'RECORD')
  4715. $con .= ' and printStatus=1 and untreadStatus=3';
  4716. elseif ($status == 'BOUNCED')
  4717. $con .= ' and untreadStatus=2';
  4718. elseif ($status == 'PARTRECORD')
  4719. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  4720. elseif ($status == 'All') {
  4721. $con .= ' and ( untreadStatus=2 or untreadStatus=1 or untreadStatus=0 or untreadStatus=3 )';
  4722. }
  4723. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4724. if (! empty ( $MebSea )) {
  4725. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  4726. }
  4727. $pageinfo ['page'] = array (
  4728. 'previous' => ''
  4729. );
  4730. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAS", $get, "" );
  4731. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4732. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  4733. $this->data ['MebSeaEn'] = $MebSea;
  4734. $this->data ['MebSea'] = urlencode ( $MebSea );
  4735. $this->data ['date'] = $date;
  4736. $this->data ['page'] = $pageinfo;
  4737. $this->data ['get'] = $get;
  4738. $this->data ['list'] = $list;
  4739. $this->data ['status'] = $status;
  4740. $this->data ['memu'] = "invoice";
  4741. $this->data ['staff'] = $this->staff;
  4742. $this->data ['receiptMemu'] = 'invoiceReceivables';
  4743. $this->render ( "/admin/invoiceAS", $this->data );
  4744. }
  4745. /**
  4746. * 收款管理
  4747. */
  4748. function invoiceReceivablesAS() {
  4749. Doo::loadModel ( 'invoiceReceivables' );
  4750. $invoiceReceivables = new invoiceReceivables ();
  4751. Doo::loadModel ( 'L_category' );
  4752. $lCategory = new L_category ();
  4753. $category = $lCategory->getCategory ();
  4754. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4755. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  4756. $page_size = 10;
  4757. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4758. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4759. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4760. $dateArr = explode ( ':', $date );
  4761. $D1 = '';
  4762. $D2 = '';
  4763. if (! empty ( $date )) {
  4764. $D1 = $dateArr [0]; // ." 00:00:00 ";
  4765. if (isset ( $dateArr [1] ))
  4766. $D2 = $dateArr [1]; // ." 23:59:59 ";
  4767. else
  4768. $D2 = $dateArr [0]; // ." 23:59:59 ";//date ( "Y-m-d" );
  4769. }
  4770. $descField = 'a.receivablesDate';
  4771. if ($timeType == 'CREATE')
  4772. $descField = 'a.date';
  4773. $con = '1';
  4774. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4775. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4776. elseif (! empty ( $D1 ) && empty ( $D2 ))
  4777. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  4778. if ($status == 'Unclaimed')
  4779. $con .= ' and a.bindStatus=0';
  4780. elseif ($status == 'Credited')
  4781. $con .= ' and a.bindStatus=1';
  4782. elseif ($status == 'Claim')
  4783. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  4784. elseif ($status == 'BBN')
  4785. $con .= ' and a.bankBatchNumber!=""';
  4786. elseif ($status == 'REFUND')
  4787. $con .= ' and ( (a.bindStatus=0 and a.refundLog!="" ) or a.bindStatus=2)';
  4788. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4789. if (! empty ( $MebSea )) {
  4790. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" or a.receivablesSerial like "%' . $MebSea . '%" )';
  4791. }
  4792. $pageinfo ['page'] = array (
  4793. 'previous' => ''
  4794. );
  4795. $sql = 'select group_concat(b.invoiceSerial) as invoiceSerial ,group_concat(b.iid) as invoiceId
  4796. from CLD_invoiceReceivables as a left join CLD_invoice as b on
  4797. find_in_set(b.iid,a.iidExtend) or a.iid=b.iid
  4798. where ' . $con . ' group by a.irid ';
  4799. $pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceReceivablesAS", $get, "" );
  4800. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4801. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', $descField );
  4802. foreach ( $list as $key => $value ) {
  4803. $list [$key] ['category'] = '';
  4804. if ($value ['receivablesCategory'] != 'PUBLIC') {
  4805. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  4806. $list [$key] ['category'] = $receivablesCategory [1];
  4807. }
  4808. }
  4809. // print_r($list);
  4810. $this->data ['category'] = $category;
  4811. $this->data ['timeType'] = $timeType;
  4812. $this->data ['MebSeaEn'] = $MebSea;
  4813. $this->data ['MebSea'] = urlencode ( $MebSea );
  4814. $this->data ['date'] = $date;
  4815. $this->data ['page'] = $pageinfo;
  4816. $this->data ['get'] = $get;
  4817. $this->data ['list'] = $list;
  4818. $this->data ['status'] = $status;
  4819. $this->data ['memu'] = "invoice";
  4820. $this->data ['staff'] = $this->staff;
  4821. $this->data ['receiptMemu'] = 'invoiceReceivables';
  4822. $this->render ( "/admin/invoiceReceivablesAS", $this->data );
  4823. }
  4824. /**
  4825. * 删除一条收款
  4826. */
  4827. function delInvoiceReceivables() {
  4828. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  4829. if (empty ( $iridKey ))
  4830. die ( 'illegal request' );
  4831. Doo::loadClass ( 'XDeode' );
  4832. $XDeode = new XDeode ( 5 );
  4833. $irid = $XDeode->decode ( $iridKey );
  4834. Doo::loadModel ( 'invoiceReceivables' );
  4835. $invoiceReceivables = new invoiceReceivables ();
  4836. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4837. if (empty ( $detail ))
  4838. die ( 'illegal request' );
  4839. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  4840. // 扣除收款汇总信息 汇总
  4841. Doo::loadModel ( 'invoiceStatistics' );
  4842. $invoiceStatistics = new invoiceStatistics ();
  4843. $item = array (
  4844. 'date' => $detail ['receivablesDate'],
  4845. 'priceClass' => 2,
  4846. 'irid' => $detail ['irid'],
  4847. 'receivablesPrice' => - $detail ['receivablesPrice']
  4848. );
  4849. if ($detail ['receivablesCategory'] != 'PUBLIC') {
  4850. $receivablesCategory = explode ( ":", $detail ['receivablesCategory'] );
  4851. $item += array (
  4852. 'cid' => $receivablesCategory [0]
  4853. );
  4854. }
  4855. if ($detail ['receivablesStaff'] != 'PUBLIC') {
  4856. $receivablesStaff = explode ( "-", $detail ['receivablesStaff'] );
  4857. $item += array (
  4858. 'staff' => $receivablesStaff [0]
  4859. );
  4860. }
  4861. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4862. return '/invoiceReceivablesAS';
  4863. }
  4864. /**
  4865. * 添加退款信息
  4866. */
  4867. function setInvoiceReceivablesRefund() {
  4868. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  4869. $refundType = $this->get_args ( 'refundType' ) && is_numeric ( $this->get_args ( 'refundType' ) ) ? $this->get_args ( 'refundType' ) : '0';
  4870. $refundCompany = $this->get_args ( 'refundCompany' ) ? $this->get_args ( 'refundCompany' ) : "";
  4871. $refundNumber = $this->get_args ( 'refundNumber' ) ? $this->get_args ( 'refundNumber' ) : "";
  4872. $refundPrice = $this->get_args ( 'refundPrice' ) ? $this->get_args ( 'refundPrice' ) : "";
  4873. $refundRemarks = $this->get_args ( 'refundRemarks' ) ? $this->get_args ( 'refundRemarks' ) : "";
  4874. if ($refundPrice < 0)
  4875. die ( 'illegal request' );
  4876. if (! empty ( $iridKey ) && ! empty ( $refundCompany ) && ! empty ( $refundNumber ) && ! empty ( $refundPrice )) {
  4877. Doo::loadModel ( 'invoiceReceivables' );
  4878. $invoiceReceivables = new invoiceReceivables ();
  4879. Doo::loadModel ( 'invoiceRefund' );
  4880. $invoiceRefund = new invoiceRefund ();
  4881. $irid = $invoiceReceivables->authcode ( $iridKey );
  4882. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4883. if ($irDetail ['receivablesPrice'] < $refundPrice)
  4884. die ( 'illegal request' );
  4885. $invoiceReceivables = new invoiceReceivables ();
  4886. $refundLog = $this->staff [0] ['username'] . ' 退款 <b class="colRed">¥' . $refundPrice . '</b>
  4887. <br/><a href="#refunded" onclick="getRefundByDetail(\'' . $iridKey . '\')" data-toggle="modal">退款信息</a> <br/>' . date ( "Y-m-d H:i:s" ) . '
  4888. ';
  4889. $item = array (
  4890. 'irid' => $irid,
  4891. 'refundCompany' => $refundCompany,
  4892. 'refundNumber' => $refundNumber,
  4893. 'refundPrice' => $refundPrice,
  4894. 'refundRemarks' => $refundRemarks,
  4895. 'refundLog' => $refundLog
  4896. );
  4897. if ($refundType == 1) {
  4898. $item += array (
  4899. 'refundType' => $refundType,
  4900. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice,
  4901. 'bindStatus' => 2
  4902. );
  4903. } elseif ($refundType == 0 && $irDetail ['receivablesPrice'] <= $refundPrice) {
  4904. $item += array (
  4905. 'refundType' => 1,
  4906. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice,
  4907. 'bindStatus' => 2
  4908. );
  4909. } else {
  4910. $item += array (
  4911. 'refundType' => $refundType,
  4912. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice
  4913. );
  4914. }
  4915. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4916. // 添加退款记录
  4917. $item = array (
  4918. 'irid' => $irid,
  4919. 'refundType' => $refundType,
  4920. 'refundCompany' => $refundCompany,
  4921. 'refundNumber' => $refundNumber,
  4922. 'refundPrice' => $refundPrice,
  4923. 'refundLog' => $refundLog,
  4924. 'refundRemarks' => $refundRemarks,
  4925. 'date' => date ( "Y-m-d H:i:s" )
  4926. );
  4927. $invoiceRefund->addInvoiceRefund ( $item );
  4928. // 扣除收款汇总信息 汇总
  4929. Doo::loadModel ( 'invoiceStatistics' );
  4930. $invoiceStatistics = new invoiceStatistics ();
  4931. $item = array (
  4932. 'date' => $irDetail ['receivablesDate'],
  4933. 'priceClass' => 2,
  4934. 'irid' => $irDetail ['irid'],
  4935. 'receivablesPrice' => - $refundPrice
  4936. );
  4937. if ($irDetail ['receivablesCategory'] != 'PUBLIC') {
  4938. $receivablesCategory = explode ( ":", $irDetail ['receivablesCategory'] );
  4939. $item += array (
  4940. 'cid' => $receivablesCategory [0]
  4941. );
  4942. }
  4943. if ($irDetail ['receivablesStaff'] != 'PUBLIC') {
  4944. $receivablesStaff = explode ( "-", $irDetail ['receivablesStaff'] );
  4945. $item += array (
  4946. 'staff' => $receivablesStaff [0]
  4947. );
  4948. }
  4949. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4950. // 公司日常支出流水
  4951. Doo::loadModel ( 'wasteBook' );
  4952. $wasteBook = new wasteBook ();
  4953. $accountBank = '';
  4954. if ($irDetail ['receivablesBank'] == '纵横广发') {
  4955. $accountBank = 'CGBDeposit';
  4956. } elseif ($irDetail ['receivablesBank'] == '纵横工行') {
  4957. $accountBank = 'ICBCDeposit';
  4958. } elseif ($irDetail ['receivablesBank'] == '华润银行') {
  4959. $accountBank = 'HUADeposit';
  4960. } elseif ($irDetail ['receivablesBank'] == '个人广发') {
  4961. $accountBank = 'PersonalDeposit';
  4962. }
  4963. $itemWaste = array (
  4964. 'accountPrice' => - $refundPrice,
  4965. 'expensesType' => 2,
  4966. 'accountType' => 11,
  4967. 'accountPriceShow' => $refundPrice,
  4968. 'dataID' => $irid,
  4969. 'accountBank' => $accountBank,
  4970. 'category' => $this->staff [0] ['category'],
  4971. 'cid' => $this->staff [0] ['cid'],
  4972. 'name' => $this->staff [0] ['username'],
  4973. 'sid' => $this->staff [0] ['sid'],
  4974. 'inputDate' => date ( "Y-m-d H:i:s" )
  4975. );
  4976. $wasteBook->setAccountBookStatistics ( $itemWaste );
  4977. return '/invoiceReceivablesAS';
  4978. }
  4979. die ( 'illegal request' );
  4980. }
  4981. function ajaxCheckInvoiceReceivablesRefund() {
  4982. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  4983. $refundPrice = $this->get_args ( 'refundPrice' ) ? $this->get_args ( 'refundPrice' ) : "";
  4984. if ($refundPrice < 0) {
  4985. echo json_encode ( array (
  4986. 'error' => '金额不能为负'
  4987. ) );
  4988. die ();
  4989. }
  4990. if (! empty ( $refundPrice ) && ! empty ( $iridKey )) {
  4991. Doo::loadModel ( 'invoiceReceivables' );
  4992. $invoiceReceivables = new invoiceReceivables ();
  4993. $irid = $invoiceReceivables->authcode ( $iridKey );
  4994. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4995. if ($irDetail ['receivablesPrice'] < $refundPrice) {
  4996. echo json_encode ( array (
  4997. 'error' => '退款金额不能超过收款金额'
  4998. ) );
  4999. die ();
  5000. }
  5001. echo json_encode ( array (
  5002. 'ok' => '可以使用!'
  5003. ) );
  5004. die ();
  5005. }
  5006. }
  5007. /**
  5008. * 获得收款退款信息
  5009. */
  5010. function getRefundByDetail() {
  5011. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5012. Doo::loadModel ( 'invoiceReceivables' );
  5013. $invoiceReceivables = new invoiceReceivables ();
  5014. if (! empty ( $iridKey )) {
  5015. $irid = $invoiceReceivables->authcode ( $iridKey );
  5016. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5017. echo json_encode ( array (
  5018. 'status' => 1,
  5019. 'irDetail' => $irDetail
  5020. ) );
  5021. die ();
  5022. }
  5023. echo json_encode ( array (
  5024. 'status' => 2
  5025. ) );
  5026. }
  5027. /**
  5028. * 根据收款序列号获得收款退款信息
  5029. */
  5030. function ajaxGetInvoiceReceivablesBySerial() {
  5031. $receivablesSerial = $this->get_args ( 'receivablesSerial' ) ? $this->get_args ( 'receivablesSerial' ) : '';
  5032. if (! empty ( $receivablesSerial )) {
  5033. Doo::loadModel ( 'invoiceReceivables' );
  5034. $invoiceReceivables = new invoiceReceivables ();
  5035. // , ' and refundLog=""'
  5036. $irDetail = $invoiceReceivables->getInvoiceReceivablesBySerial ( $receivablesSerial );
  5037. $html = '';
  5038. if (! empty ( $irDetail ))
  5039. $html = '<td><b>¥' . $irDetail ['receivablesPrice'] . '</b></td>
  5040. <td>' . $irDetail ['receivablesMessage'] . '</td>
  5041. <td>' . $irDetail ['receivablesBank'] . '<br>' . $irDetail ['receivablesDate'] . '</td>
  5042. <td>' . $irDetail ['title'] . '-' . $irDetail ['username'] . '<br>' . $irDetail ['confirmTime'] . '</td>
  5043. <td>' . $irDetail ['recepitTitleMark'] . '
  5044. <input type="hidden" name="iridKey" id="iridKey" value="' . $irDetail ['iridKey'] . '">
  5045. </td>';
  5046. echo json_encode ( array (
  5047. 'status' => 1,
  5048. 'html' => $html,
  5049. 'irDetail' => $irDetail
  5050. ) );
  5051. die ();
  5052. }
  5053. echo json_encode ( array (
  5054. 'status' => 2
  5055. ) );
  5056. }
  5057. /**
  5058. * 绑定新收款
  5059. */
  5060. function relationNewInvoiceReceivables() {
  5061. $iridKeyOld = $this->get_args ( 'iridKeyOld' ) ? $this->get_args ( 'iridKeyOld' ) : '';
  5062. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5063. if (! empty ( $iridKeyOld ) && ! empty ( $iridKey )) {
  5064. Doo::loadModel ( 'invoiceReceivables' );
  5065. $invoiceReceivables = new invoiceReceivables ();
  5066. Doo::loadClass ( 'XDeode' );
  5067. $XDeode = new XDeode ( 5 );
  5068. $irid = $XDeode->decode ( $iridKey );
  5069. $iridOld = $invoiceReceivables->authcode ( $iridKeyOld );
  5070. echo $irid . 'bbb' . $iridOld;
  5071. $oldIrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $iridOld );
  5072. $IrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5073. if (empty ( $oldIrDetail ) || empty ( $IrDetail ))
  5074. die ( 'illegal request' );
  5075. $relationLog = $this->staff [0] ['username'] . ' 关联新款 <a href="#billing" onclick="invoiceReceivblesDivShow(\'' . $iridKey . '\',\'receivables\')" data-toggle="modal">' . $IrDetail ['receivablesSerial'] . '</a>
  5076. <br/>' . date ( "Y-m-d H:i:s" ) . '
  5077. ';
  5078. $invoiceReceivables = new invoiceReceivables ();
  5079. $item = array (
  5080. 'irid' => $iridOld,
  5081. 'relationIrid' => $irid,
  5082. 'relationLog' => $relationLog
  5083. );
  5084. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  5085. return '/invoiceReceivablesAS';
  5086. }
  5087. die ( 'illegal request' );
  5088. }
  5089. // function invoiceApprovalAchieve() {
  5090. // Doo::loadModel ( 'invoice' );
  5091. // $invoice = new invoice ();
  5092. // $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  5093. // $page_size = 12;
  5094. // $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5095. // $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  5096. // $get = "/" . $date;
  5097. // $con = '';
  5098. // if ($date == 'MONTHO')
  5099. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  5100. // elseif ($date == 'MONTHT')
  5101. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  5102. // elseif ($date == 'MONTHY')
  5103. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  5104. // if (! empty ( $MebSea )) {
  5105. // $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  5106. // $get .= "/" . $MebSea;
  5107. // }
  5108. // $pageinfo ['page'] = array (
  5109. // 'previous' => ''
  5110. // );
  5111. // $sql = '(status=1 or status=2 or status=3 or status=4) and processApprovals!=""' . $con; // echo $sql;
  5112. // $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", $get, "" );
  5113. // $limit = $pageinfo ['lower'] . ',' . $page_size;
  5114. // $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  5115. // // print_r($list);
  5116. // $this->data ['MebSeaEn'] = $MebSea;
  5117. // $this->data ['MebSea'] = urlencode ( $MebSea );
  5118. // $this->data ['get'] = $get;
  5119. // $this->data ['page'] = $pageinfo;
  5120. // $this->data ['list'] = $list;
  5121. // $this->data ['date'] = $date;
  5122. // $this->data ['memu'] = "invoice";
  5123. // $this->data ['staff'] = $this->staff;
  5124. // $this->data ['receiptMemu'] = 'invoiceApproval';
  5125. // $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  5126. // }
  5127. /**
  5128. * 获得审批发票的信息以及审批页面
  5129. */
  5130. function ajaxGetInvoiceApprovalDetail() {
  5131. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5132. if (empty ( $serial )) {
  5133. echo json_encode ( array (
  5134. 'status' => 2,
  5135. 'msg' => 'illegal request'
  5136. ) );
  5137. die ();
  5138. }
  5139. Doo::loadModel ( 'invoice' );
  5140. $invoice = new invoice ();
  5141. Doo::loadModel ( 'invoiceOperationLog' );
  5142. $invoiceOperationLog = new invoiceOperationLog ();
  5143. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5144. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5145. if (empty ( $detail ))
  5146. $html = '';
  5147. else {
  5148. $html = '
  5149. <form action="/invoiceApprovalDo" method="post" name="invoiceApproval" class="nice-validator n-yellow" novalidate="novalidate">
  5150. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  5151. <input type="hidden" name="status" value="">
  5152. <input type="hidden" name="divApproval" value="divApproval">
  5153. <div class="modal-dialog modal-lg">
  5154. <div class="modal-content"><div class="modal-header"><h3>发票审批详情</h3></div>
  5155. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  5156. <tr>
  5157. <th class="taC" width="150">发票审批</th><td><textarea name="opinion" style="width:98%" placeholder="在这写下您的审批意见,选填。"></textarea></td>
  5158. </tr>
  5159. <tr>
  5160. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5161. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5162. </tr>
  5163. <tr>
  5164. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5165. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5166. </tr>
  5167. <tr>
  5168. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5169. </td>
  5170. </tr>
  5171. <tr>
  5172. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5173. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5174. </tr>
  5175. <tr>
  5176. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5177. </tr></tbody></table>';
  5178. if ($detail ['invoiceType'] == 0)
  5179. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5180. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5181. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5182. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5183. </tr>';
  5184. else
  5185. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5186. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5187. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5188. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5189. ';
  5190. $html .= '<tr>
  5191. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5192. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5193. </tr>
  5194. <tr>
  5195. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5196. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5197. </tr></tbody></table>';
  5198. if ($detail ['doPost'] == 1) {
  5199. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5200. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5201. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5202. </tr><tr>
  5203. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5204. </tr><tr>
  5205. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5206. </tr>
  5207. ';
  5208. if ($detail ['expressCom'] == 'SF')
  5209. $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>';
  5210. else
  5211. $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>';
  5212. $html .= '</tbody></table>';
  5213. }
  5214. if (! empty ( $invoiceOperationLogList )) {
  5215. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  5216. foreach ( $invoiceOperationLogList as $key => $value ) {
  5217. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5218. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5219. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5220. if ($value ['status'] == 2) {
  5221. $html .= '<span class="colGreen">同意</span>';
  5222. } elseif ($value ['status'] == 3) {
  5223. $html .= '<span class="colOrange">退回</span>';
  5224. } elseif ($value ['status'] == 5) {
  5225. $html .= '<span class="colGreen">打印</span>';
  5226. } elseif ($value ['status'] == 4) {
  5227. $html .= '<span class="colRed">终止</span>';
  5228. }
  5229. $html .= $value ['operation'] . '</p></blockquote>';
  5230. }
  5231. }
  5232. $html .= '</td></tr></tbody></table>';
  5233. }
  5234. $html .= '</div><div class="modal-footer">
  5235. <a href="javascript:void(0)" node-approval="approval" diss-data="2" class="button btn-done" data-placement="top" data-toggle="ctooltip" >同意</a>
  5236. <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>
  5237. <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>
  5238. <a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>
  5239. </form>
  5240. <script type="text/javascript">
  5241. $("a[node-approval^=\'approval\']").click(function() {
  5242. $("input[name=\'status\']").val($(this).attr("diss-data"));
  5243. $("form[name=\'invoiceApproval\']").submit();
  5244. });
  5245. </script>
  5246. ';
  5247. }
  5248. echo json_encode ( array (
  5249. 'status' => 1,
  5250. 'html' => $html
  5251. ) );
  5252. die ();
  5253. }
  5254. /**
  5255. * 获得审批发票分页数据
  5256. */
  5257. function ajaxGetinvoiceApprovalAchieve() {
  5258. Doo::loadModel ( 'invoice' );
  5259. $invoice = new invoice ();
  5260. Doo::loadModel ( 'staff' );
  5261. $staff = new staff ();
  5262. Doo::loadClass ( 'XDeode' );
  5263. $XDeode = new XDeode ( 5 );
  5264. Doo::loadModel ( 'invoiceTraining' );
  5265. $invoiceTraining = new invoiceTraining ();
  5266. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  5267. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5268. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5269. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5270. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5271. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  5272. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  5273. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  5274. $MebSea = $this->get_args ( 'search' );
  5275. $MebSea = $MebSea ['value'];
  5276. $page_size = $length;
  5277. $con = '';
  5278. if ($status == 'ALL')
  5279. $con = ' (status=1 or status=2 or status=3 or status=4) and isDelete=0 ';
  5280. elseif ($status == 'PEND')
  5281. $con = ' isDelete=0 and status=1';
  5282. elseif ($status == 'APPROVED')
  5283. $con = ' isDelete=0 and status=2';
  5284. if ($invoiceType == 'ORDINARY')
  5285. $con .= ' and invoiceType=0 ';
  5286. elseif ($invoiceType == 'SPECIAL')
  5287. $con .= ' and invoiceType=1 ';
  5288. if ($invoiceTrain == 'ORDINARY')
  5289. $con .= ' and trainId=0 ';
  5290. elseif ($invoiceTrain == 'TRAIN')
  5291. $con .= ' and trainId!=0 ';
  5292. if ($invoiceTrainName != 'ALL') {
  5293. $trainId = $XDeode->decode ( $invoiceTrainName );
  5294. if (is_numeric ( $trainId ))
  5295. $con .= ' and trainId =' . $trainId;
  5296. }
  5297. $dateArr = explode ( ':', $date );
  5298. $D1 = $dateString = '';
  5299. $D2 = '';
  5300. if (! empty ( $date )) {
  5301. $D1 = $dateArr [0];
  5302. if (isset ( $dateArr [1] ))
  5303. $D2 = $dateArr [1];
  5304. else
  5305. $D2 = '';
  5306. $dateString = $D1 . " : " . $D2;
  5307. }
  5308. if (! empty ( $D1 ) && ! empty ( $D2 ))
  5309. $con .= ' and approvalTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  5310. elseif (! empty ( $D1 ) && empty ( $D2 ))
  5311. $con .= ' and approvalTime like "%' . $D1 . '%" ';
  5312. if (! empty ( $MebSea ))
  5313. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceSerial like "%' . $MebSea . '%" )';
  5314. // /
  5315. $pageinfo ['page'] = array (
  5316. 'previous' => ''
  5317. );
  5318. $sql = ' ' . $con;
  5319. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", '', "" );
  5320. $limit = $page . ',' . $page_size;
  5321. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  5322. $approvalList = array ();
  5323. $html = '<script type="text/javascript">
  5324. </script>';
  5325. // 结算结束不能修改方式
  5326. Doo::loadModel ( 'receipt' );
  5327. $receipt = new receipt ();
  5328. foreach ( $list as $key => $value ) {
  5329. $irDetail = array ();
  5330. // 结算方式
  5331. $receiptDetail = array ();
  5332. if ($value ['trainId'] != 0) {
  5333. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $value ['trainId'] );
  5334. }
  5335. if (! empty ( $receiptDetail )) {
  5336. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9) {
  5337. array_push ( $irDetail, '' );
  5338. } else {
  5339. if ($value ['status'] == 1 && $value ['pendingApprovals'] == $this->staff [0] ['sid']) {
  5340. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoiceApproval(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">审批发票</a>' );
  5341. } elseif ($value ['status'] == 2) {
  5342. array_push ( $irDetail, '<a href="#editPay" class="fnSettlementType" data-iidKey="' . $value ['iidKeyK'] . '" data-toggle="modal">结算方式</a>' );
  5343. } else
  5344. array_push ( $irDetail, '' );
  5345. }
  5346. } else {
  5347. if ($value ['status'] == 2) {
  5348. array_push ( $irDetail, '<a href="#editPay" class="fnSettlementType" data-iidKey="' . $value ['iidKeyK'] . '" data-toggle="modal">结算方式</a>' );
  5349. } else
  5350. array_push ( $irDetail, '' );
  5351. }
  5352. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  5353. if ($value ['invoiceType'] == 1)
  5354. array_push ( $irDetail, $value ['invoiceCompany'] );
  5355. else
  5356. array_push ( $irDetail, $value ['invoiceTitle'] );
  5357. array_push ( $irDetail, $value ['TIN'] );
  5358. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  5359. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  5360. array_push ( $irDetail, $value ['remark'] );
  5361. array_push ( $irDetail, $value ['invoiceElement'] );
  5362. array_push ( $irDetail, $value ['invoiceQuantity'] );
  5363. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  5364. if ($value ['invoiceType'] == 1) {
  5365. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  5366. } else {
  5367. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  5368. }
  5369. if ($value ['settlementType'] == 0) {
  5370. array_push ( $irDetail, '软件销售' );
  5371. } else {
  5372. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $value ['trainId'] );
  5373. array_push ( $irDetail, $itDetail ['trainName'] );
  5374. }
  5375. array_push ( $irDetail, $value ['recipients'] . $value ['recipientsPhone'] );
  5376. array_push ( $irDetail, $value ['recipientsAddress'] );
  5377. array_push ( $irDetail, $value ['mailItems'] );
  5378. array_push ( $irDetail, $value ['userName'] . '&nbsp;' . $value ['date'] );
  5379. $fchtml = $value ['OL'] ['operation'];
  5380. if (count ( $list ) == $page_size)
  5381. $fchtml = $value ['OL'] ['operation'] . $html;
  5382. // 最后的审批意见
  5383. array_push ( $irDetail, $fchtml );
  5384. if ($value ['status'] == 2)
  5385. array_push ( $irDetail, '<span class="colGreen">同意</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5386. elseif ($value ['status'] == 3)
  5387. array_push ( $irDetail, '<span class="colOrange">退回</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5388. elseif ($value ['status'] == 4)
  5389. array_push ( $irDetail, '<span class="colRed">终止</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5390. else
  5391. array_push ( $irDetail, '' );
  5392. array_push ( $approvalList, $irDetail );
  5393. }
  5394. // $approvalListJson = json_encode ( $approvalList );
  5395. $recordsFiltered = $pageinfo ['total_data'];
  5396. echo json_encode ( array (
  5397. "draw" => intval ( $draw ),
  5398. "recordsTotal" => intval ( $pageinfo ['total_data'] ),
  5399. "recordsFiltered" => intval ( $recordsFiltered ),
  5400. "data" => $approvalList
  5401. ), JSON_UNESCAPED_UNICODE );
  5402. }
  5403. /**
  5404. * 审批发票查看更多--重构
  5405. */
  5406. function invoiceApprovalAchieve() {
  5407. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'ALL';
  5408. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5409. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5410. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5411. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5412. Doo::loadModel ( 'invoiceTraining' );
  5413. $invoiceTraining = new invoiceTraining ();
  5414. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  5415. $this->data ['trainList'] = $trainList;
  5416. $this->data ['dateString'] = $date;
  5417. $this->data ['status'] = $status;
  5418. $this->data ['invoiceType'] = $invoiceType;
  5419. $this->data ['invoiceTrain'] = $invoiceTrain;
  5420. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  5421. $this->data ['memu'] = "invoice";
  5422. $this->data ['staff'] = $this->staff;
  5423. $this->data ['receiptMemu'] = 'invoiceApproval';
  5424. $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  5425. }
  5426. function invoiceTAchieve() {
  5427. Doo::loadModel ( 'invoice' );
  5428. $invoice = new invoice ();
  5429. Doo::loadClass ( 'XDeode' );
  5430. $XDeode = new XDeode ( 5 );
  5431. Doo::loadModel ( 'staff' );
  5432. $staff = new staff ();
  5433. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  5434. $page_size = 12;
  5435. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5436. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  5437. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5438. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5439. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5440. Doo::loadModel ( 'invoiceTraining' );
  5441. $invoiceTraining = new invoiceTraining ();
  5442. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  5443. $get = "/" . $date;
  5444. $con = '';
  5445. if ($date == 'MONTHO')
  5446. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  5447. elseif ($date == 'MONTHT')
  5448. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  5449. elseif ($date == 'MONTHY')
  5450. $con = ' and YEAR(updateTime) = YEAR(NOW())'; // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  5451. if ($invoiceType == 'ORDINARY')
  5452. $con .= ' and invoiceType=0 ';
  5453. elseif ($invoiceType == 'SPECIAL')
  5454. $con .= ' and invoiceType=1 ';
  5455. if ($invoiceTrain == 'ORDINARY')
  5456. $con .= ' and trainId=0 ';
  5457. elseif ($invoiceTrain == 'TRAIN')
  5458. $con .= ' and trainId!=0 ';
  5459. if ($invoiceTrainName != 'ALL') {
  5460. $trainId = $XDeode->decode ( $invoiceTrainName );
  5461. if (is_numeric ( $trainId ))
  5462. $con .= ' and trainId =' . $trainId;
  5463. }
  5464. if (! empty ( $MebSea )) {
  5465. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  5466. $get .= "/" . $MebSea;
  5467. }
  5468. $pageinfo ['page'] = array (
  5469. 'previous' => ''
  5470. );
  5471. $sql = "";
  5472. $action = "";
  5473. if ($this->ACTION == 'invoicePrintAchieve') {
  5474. $sql = "status=2 and printStatus=1 and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  5475. $action = "invoicePrintAchieve";
  5476. } elseif ($this->ACTION == 'invoicePostAchieve') {
  5477. // and untreadStatus=0
  5478. $sql = "postStatus=1 and doPost=1 and status=2 and isDelete=0" . $con;
  5479. $action = "invoicePostAchieve";
  5480. } elseif ($this->ACTION == 'invoiceUntreadAchieve') { // printStatus=1 and
  5481. $sql = " untreadStatus=2 and status=2 " . $con;
  5482. $action = "invoiceUntreadAchieve";
  5483. }
  5484. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  5485. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5486. $this->data ['MebSeaEn'] = $MebSea;
  5487. $this->data ['MebSea'] = urlencode ( $MebSea );
  5488. $this->data ['get'] = $get;
  5489. $this->data ['page'] = $pageinfo;
  5490. $this->data ['trainList'] = $trainList;
  5491. $this->data ['invoiceType'] = $invoiceType;
  5492. $this->data ['invoiceTrain'] = $invoiceTrain;
  5493. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  5494. $this->data ['date'] = $date;
  5495. $this->data ['memu'] = "invoice";
  5496. $this->data ['staff'] = $this->staff;
  5497. if ($this->ACTION == 'invoicePrintAchieve') {
  5498. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  5499. $this->data ['receiptMemu'] = 'invoicePrint';
  5500. $this->data ['list'] = $list;
  5501. $this->render ( "/admin/invoicePrintAchieve", $this->data );
  5502. } elseif ($this->ACTION == 'invoicePostAchieve') {
  5503. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  5504. Doo::loadModel ( 'express' );
  5505. $express = new express ();
  5506. $expressList = $express->getExpressByAll ();
  5507. $this->data ['expressList'] = $expressList;
  5508. $this->data ['receiptMemu'] = 'invoicePost';
  5509. $this->data ['list'] = $list;
  5510. $this->render ( "/admin/invoicePostAchieve", $this->data );
  5511. } elseif ($this->ACTION == 'invoiceUntreadAchieve') {
  5512. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  5513. $this->data ['receiptMemu'] = 'invoiceUntread';
  5514. $this->data ['list'] = $list;
  5515. $this->render ( "/admin/invoiceUntreadAchieve", $this->data );
  5516. }
  5517. }
  5518. /**
  5519. * 公司应收款
  5520. */
  5521. function invoiceAggregateCompanyDetail() {
  5522. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  5523. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  5524. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : 'ALL';
  5525. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  5526. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  5527. Doo::loadClass ( 'XDeode' );
  5528. $XDeode = new XDeode ( 5 );
  5529. Doo::loadModel ( 'invoice' );
  5530. $invoice = new invoice ();
  5531. Doo::loadModel ( 'staff' );
  5532. $staff = new staff ();
  5533. Doo::loadModel ( "invoiceCompanyManage" );
  5534. $invoiceCompanyManage = new invoiceCompanyManage ();
  5535. Doo::loadModel ( 'L_category' );
  5536. $category = new L_category ();
  5537. $sid = '';
  5538. if (! empty ( $sidKey )) {
  5539. $sid = $XDeode->decode ( $sidKey );
  5540. }
  5541. $staffDetail = $staff->getStaffBySid ( $sid );
  5542. $cid = '';
  5543. if (! empty ( $cidKey )) {
  5544. $cid = $XDeode->decode ( $cidKey );
  5545. }
  5546. $imcStaff = $invoiceCompanyManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  5547. $cidList = array ();
  5548. foreach ( $imcStaff as $key => $value ) {
  5549. array_push ( $cidList, $value ['cid'] );
  5550. }
  5551. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  5552. $cidString = implode ( ',', $cidList );
  5553. if (empty ( $cid ))
  5554. $staffList = $staff->getStaffInCid ( $cidString );
  5555. else
  5556. $staffList = $staff->getStaffByCidAll ( $cid ); //
  5557. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  5558. $page_size = 25;
  5559. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5560. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  5561. $con = ' status=2 and untreadStatus!=2 ';
  5562. $statisticsCon = '';
  5563. if (! empty ( $year ) && is_numeric ( $year ))
  5564. $con .= ' and Year(printTime)=' . $year . '';
  5565. if (! empty ( $month ) && is_numeric ( $month ))
  5566. $con .= ' and Month(printTime)="' . $month . '" ';
  5567. if ($status == 'UNRECORD')
  5568. $con .= ' and printStatus=1 and untreadStatus=0';
  5569. elseif ($status == 'RECORD')
  5570. $con .= ' and printStatus=1 and untreadStatus=3';
  5571. elseif ($status == 'BOUNCED')
  5572. $con .= ' and untreadStatus=2';
  5573. elseif ($status == 'PARTRECORD')
  5574. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  5575. elseif ($status == 'All') {
  5576. $con .= ' and printStatus=1 and ( untreadStatus=0 or untreadStatus=3 )';
  5577. }
  5578. if (! empty ( $sid ) && is_numeric ( $sid ))
  5579. $con .= ' and sid=' . $sid;
  5580. if (! empty ( $cid ) && is_numeric ( $cid ))
  5581. $con .= ' and cid=' . $cid;
  5582. else
  5583. $con .= ' and cid in (' . $cidString . ')';
  5584. // 开票内容筛选
  5585. if (! empty ( $invoiceElement ) && $invoiceElement != 'ALL') {
  5586. $con .= ' and invoiceElement="' . $invoiceElement . '"';
  5587. }
  5588. $get = "/" . $status . "?cidKey=" . $cidKey . "&sidKey=" . $sidKey . "&year=" . $year . "&month=" . $month . "&invoiceElement=" . $invoiceElement;
  5589. if (! empty ( $MebSea )) {
  5590. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  5591. }
  5592. $pageinfo ['page'] = array (
  5593. 'previous' => ''
  5594. );
  5595. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateCompanyDetail", $get, "" );
  5596. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5597. // 应收款合计
  5598. $ics = $invoice->getInvoiceCompanyStatistics ( $con );
  5599. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  5600. $monthHtml = "";
  5601. if ($year != "ALL") {
  5602. for($i = 1; $i <= 12; $i ++) {
  5603. if ($i == $month)
  5604. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  5605. else
  5606. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  5607. }
  5608. }
  5609. $this->data ['monthHtml'] = $monthHtml;
  5610. $this->data ['year'] = $year;
  5611. $this->data ['month'] = $month;
  5612. $this->data ['ics'] = $ics;
  5613. $this->data ['cidKey'] = $cidKey;
  5614. $this->data ['sid'] = $sid;
  5615. $this->data ['staffDetail'] = $staffDetail;
  5616. $this->data ['staffList'] = $staffList;
  5617. $this->data ['MebSeaEn'] = $MebSea;
  5618. $this->data ['MebSea'] = urlencode ( $MebSea );
  5619. $this->data ['invoiceDetail'] = array (
  5620. 'invoiceElement' => $invoiceElement
  5621. );
  5622. $this->data ['page'] = $pageinfo;
  5623. $this->data ['get'] = $get;
  5624. $this->data ['list'] = $list;
  5625. $this->data ['status'] = $status;
  5626. $this->data ['categoryList'] = $categoryList;
  5627. $this->data ['memu'] = "invoice";
  5628. $this->data ['staff'] = $this->staff;
  5629. $this->data ['receiptMemu'] = 'invoiceAggregateCompanyDetail';
  5630. $this->render ( "/admin/invoiceAggregateCompanyDetail", $this->data );
  5631. }
  5632. /**
  5633. * 获取一条收款信息
  5634. */
  5635. function ajaxGetInvoiceReceivables() {
  5636. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  5637. Doo::loadModel ( 'invoiceReceivables' );
  5638. $invoiceReceivables = new invoiceReceivables ();
  5639. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5640. echo json_encode ( array (
  5641. 'status' => 1,
  5642. 'detail' => $detail
  5643. ) );
  5644. }
  5645. /**
  5646. * 异步获取办事处用户
  5647. */
  5648. function ajaxGetStaffByCategory() {
  5649. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "";
  5650. Doo::loadModel ( 'staff' );
  5651. $staff = new staff ();
  5652. if ($cid == "PUBLIC") {
  5653. echo json_encode ( array (
  5654. 'status' => 1,
  5655. 'html' => '<option value="PUBLIC">办事处待认领款项</option>'
  5656. ) );
  5657. die ();
  5658. }
  5659. if (! is_numeric ( $cid )) {
  5660. echo json_encode ( array (
  5661. 'status' => 0,
  5662. 'msg' => 'illegal request'
  5663. ) );
  5664. die ();
  5665. }
  5666. $staffList = $staff->getStaffByCid ( $cid );
  5667. $html = '<option value="PUBLIC">办事处待认领款项</option>';
  5668. foreach ( $staffList as $key => $value ) {
  5669. $html .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  5670. }
  5671. echo json_encode ( array (
  5672. 'status' => 1,
  5673. 'html' => $html
  5674. ) );
  5675. }
  5676. /**
  5677. * 异步获取一条发票的邮寄信息
  5678. */
  5679. function ajaxGetInvoicePostDetail() {
  5680. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  5681. Doo::loadModel ( 'invoice' );
  5682. $invoice = new invoice ();
  5683. $iid = $invoice->authcode ( $iid );
  5684. Doo::loadModel ( 'express' );
  5685. $express = new express ();
  5686. $expressList = $express->getExpressByAll ();
  5687. if (! is_numeric ( $iid )) {
  5688. echo json_encode ( array (
  5689. 'status' => 0,
  5690. 'msg' => 'illegal request'
  5691. ) );
  5692. die ();
  5693. }
  5694. $select = "iid,recipients,recipientsPhone,recipientsAddress,mailItems,expressCompany,expressNumber,actualItems";
  5695. $invoiceDetail = $invoice->getInvoiceByIid ( $iid, $select );
  5696. $html = "";
  5697. foreach ( $expressList as $key => $value ) {
  5698. if ($value ['company'] == $invoiceDetail ['expressCompany'])
  5699. $html .= '<option selected value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  5700. else
  5701. $html .= '<option value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  5702. }
  5703. $invoiceDetail ['eaHtml'] = $html;
  5704. echo json_encode ( array (
  5705. 'status' => 1,
  5706. 'invoiceDetail' => $invoiceDetail
  5707. ) );
  5708. }
  5709. /**
  5710. *
  5711. * @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 ) ); }
  5712. */
  5713. /**
  5714. *
  5715. * @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 ) ); }
  5716. */
  5717. /**
  5718. * 我的收款中 选择哪个发票入账,进行金额判断
  5719. */
  5720. function ajaxCompareInvoicePrice() {
  5721. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  5722. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  5723. Doo::loadModel ( 'invoice' );
  5724. $invoice = new invoice ();
  5725. Doo::loadModel ( 'invoiceReceivables' );
  5726. $invoiceReceivables = new invoiceReceivables ();
  5727. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  5728. $keyList = explode ( ';', $claimKey );
  5729. $receivablesPrice = 0;
  5730. foreach ( $keyList as $key => $value ) {
  5731. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $value );
  5732. $receivablesPrice += $detailM ['receivablesPrice'];
  5733. }
  5734. if ($receivablesPrice > $detail ['invoicePrice']) {
  5735. $price = $receivablesPrice - $detail ['invoicePrice'];
  5736. echo json_encode ( array (
  5737. 'status' => 1,
  5738. 'price' => $price
  5739. ) );
  5740. } else
  5741. echo json_encode ( array (
  5742. 'status' => 2
  5743. ) );
  5744. }
  5745. /**
  5746. * 获得打印发票
  5747. */
  5748. function ajaxGetInvoiceInfoByPrint() {
  5749. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5750. if (empty ( $serial )) {
  5751. echo json_encode ( array (
  5752. 'status' => 2,
  5753. 'msg' => 'illegal request'
  5754. ) );
  5755. die ();
  5756. }
  5757. Doo::loadModel ( 'invoice' );
  5758. $invoice = new invoice ();
  5759. Doo::loadModel ( 'invoiceOperationLog' );
  5760. $invoiceOperationLog = new invoiceOperationLog ();
  5761. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5762. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5763. Doo::loadModel ( 'invoicePaper' );
  5764. $invoicePaper = new invoicePaper ();
  5765. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $detail ['invoiceType'] );
  5766. if (empty ( $detail ))
  5767. $html = '';
  5768. else {
  5769. $html = '
  5770. <form action="/invoicePrintDo" method="post" name="invoicePrint" class="nice-validator n-yellow" onSubmit="return checkPrintForm()" novalidate="novalidate">
  5771. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  5772. <input type="hidden" name="invoicePrintType" value="invoicePrintType">
  5773. <div class="modal-dialog modal-lg">
  5774. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  5775. <div class="modal-body saeaList">
  5776. <table class="table table-bordered table-condensed"><tbody>
  5777. <tr>
  5778. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5779. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5780. </tr>
  5781. <tr>
  5782. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5783. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5784. </tr>
  5785. <tr>
  5786. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5787. </td>
  5788. </tr>
  5789. <tr>
  5790. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5791. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5792. </tr>
  5793. <tr>
  5794. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5795. </tr></tbody></table>';
  5796. if ($detail ['invoiceType'] == 0)
  5797. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5798. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5799. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5800. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5801. </tr>';
  5802. else
  5803. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5804. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5805. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5806. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5807. ';
  5808. $html .= '<tr>
  5809. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5810. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5811. </tr>
  5812. <tr>
  5813. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5814. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5815. </tr></tbody></table>';
  5816. if ($detail ['doPost'] == 1)
  5817. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5818. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5819. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5820. </tr><tr>
  5821. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5822. </tr><tr>
  5823. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5824. </tr></tbody></table>';
  5825. if (! empty ( $invoiceOperationLogList )) {
  5826. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th><th class="taC">发票打印</th></tr><tr><td>';
  5827. foreach ( $invoiceOperationLogList as $key => $value ) {
  5828. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5829. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5830. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5831. if ($value ['status'] == 2) {
  5832. $html .= '<span class="colGreen">同意</span>';
  5833. } elseif ($value ['status'] == 3) {
  5834. $html .= '<span class="colOrange">退回</span>';
  5835. } elseif ($value ['status'] == 5) {
  5836. $html .= '<span class="colGreen">打印</span>';
  5837. } elseif ($value ['status'] == 4) {
  5838. $html .= '<span class="colRed">终止</span>';
  5839. }
  5840. $html .= $value ['operation'] . '</p></blockquote>';
  5841. }
  5842. }
  5843. $html .= '</td>
  5844. <td><span class="colRed">*</span>
  5845. <select name="invoiceNo" id="invoiceNo" style="width:97%">';
  5846. foreach ( $invoicePaperList as $key => $value ) {
  5847. $html .= '<option value="' . $value ['ipidKey'] . '">No.' . $value ['invoiceNo'] . '</option>';
  5848. }
  5849. $html .= '</select>
  5850. <span class="red" id="p-msg"></span>
  5851. </td>
  5852. </tr></tbody></table>';
  5853. }
  5854. $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>
  5855. </div></div></form>
  5856. <link rel=stylesheet href="' . WEB_SITE_GLOBAL . 'css/jquery.validator.css">
  5857. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/jquery.validator.min.js"></script>
  5858. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/zh-CN.js"></script>
  5859. <script src="' . WEB_SITE_GLOBAL . 'js/invoice.validator.js"></script>
  5860. ';
  5861. }
  5862. echo json_encode ( array (
  5863. 'status' => 1,
  5864. 'html' => $html
  5865. ) );
  5866. die ();
  5867. }
  5868. /**
  5869. * @ 获得与我有关收款数据 --需求变更 废弃 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 ) ); }
  5870. */
  5871. function ajaxGetInvoiceInfoByType() {
  5872. $type = $this->get_args ( 'type' ) ? $this->get_args ( 'type' ) : "";
  5873. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5874. $loss = $this->get_args ( 'loss' ) ? $this->get_args ( 'loss' ) : false;
  5875. if (empty ( $serial )) {
  5876. echo json_encode ( array (
  5877. 'status' => 2,
  5878. 'msg' => 'illegal request'
  5879. ) );
  5880. die ();
  5881. }
  5882. if ($type == 'INVOICE') {
  5883. Doo::loadModel ( 'invoice' );
  5884. $invoice = new invoice ();
  5885. Doo::loadModel ( 'invoiceOperationLog' );
  5886. $invoiceOperationLog = new invoiceOperationLog ();
  5887. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5888. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5889. if (empty ( $detail ))
  5890. $html = '';
  5891. else {
  5892. $html = '
  5893. <div class="modal-dialog modal-lg">
  5894. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  5895. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  5896. <tr>
  5897. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5898. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5899. </tr>
  5900. <tr>
  5901. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5902. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5903. </tr>
  5904. <tr>
  5905. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5906. </td>
  5907. </tr>
  5908. <tr>
  5909. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5910. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5911. </tr>
  5912. <tr>
  5913. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5914. </tr>';
  5915. if ($detail ['settlementType'] == 1)
  5916. $html .= '<tr>
  5917. <th class="taC" width="150">结算方式</th><td colspan="3">培训班(<a href="/invoiceTrainingDetail/' . $detail ['invoiceTraining'] ['trainingKey'] . '.html" target="_blank">' . $detail ['invoiceTraining'] ['trainName'] . '</a>)</td>
  5918. </tr>';
  5919. else
  5920. $html .= '<tr>
  5921. <th class="taC" width="150">结算方式</th><td colspan="3">软件销售</td>
  5922. </tr>';
  5923. $html .= ' </tbody></table>';
  5924. if ($detail ['invoiceType'] == 0)
  5925. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5926. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5927. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5928. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5929. </tr>';
  5930. else
  5931. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5932. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5933. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5934. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5935. ';
  5936. $html .= '<tr>
  5937. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5938. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5939. </tr>
  5940. <tr>
  5941. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5942. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5943. </tr></tbody></table>';
  5944. if ($detail ['doPost'] == 1) {
  5945. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5946. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5947. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5948. </tr><tr>
  5949. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5950. </tr><tr>
  5951. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5952. </tr>
  5953. ';
  5954. if ($detail ['expressCom'] == 'SF')
  5955. $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>';
  5956. else
  5957. $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>';
  5958. $html .= '</tbody></table>';
  5959. }
  5960. if (! empty ( $invoiceOperationLogList )) {
  5961. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  5962. foreach ( $invoiceOperationLogList as $key => $value ) {
  5963. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5964. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5965. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5966. if ($value ['status'] == 2) {
  5967. $html .= '<span class="colGreen">同意</span>';
  5968. } elseif ($value ['status'] == 3) {
  5969. $html .= '<span class="colOrange">退回</span>';
  5970. } elseif ($value ['status'] == 5) {
  5971. $html .= '<span class="colGreen">打印</span>';
  5972. } elseif ($value ['status'] == 4) {
  5973. $html .= '<span class="colRed">终止</span>';
  5974. }
  5975. $html .= $value ['operation'] . '</p></blockquote>';
  5976. }
  5977. }
  5978. $html .= '</td></tr></tbody></table>';
  5979. }
  5980. $html .= '</div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  5981. }
  5982. echo json_encode ( array (
  5983. 'status' => 1,
  5984. 'html' => $html
  5985. ) );
  5986. die ();
  5987. } elseif ($type == 'RECEIVABLES') {
  5988. Doo::loadModel ( 'invoiceReceivables' );
  5989. $invoiceReceivables = new invoiceReceivables ();
  5990. Doo::loadModel ( 'invoiceRefund' );
  5991. $invoiceRefund = new invoiceRefund ();
  5992. $detail = $invoiceReceivables->getInvoiceReceivablesByIrsid ( $serial );
  5993. $ireList = $invoiceRefund->getInvoiceRefundIrid ( $detail ['irid'] );
  5994. if (empty ( $detail ))
  5995. $html = '';
  5996. else {
  5997. $html = '<div class="modal-dialog modal-lg"><div class="modal-content"><div class="modal-header"><h3>收款单详情</h3></div><div class="modal-body saeaList">
  5998. <table class="table table-bordered table-condensed">
  5999. <tbody><tr>
  6000. <th class="taC">收款流水号</th><td>' . $detail ['receivablesSerial'] . '</td>
  6001. <th class="taC">录入收款</th><td>' . $detail ['inputStaff'] . ' ' . $detail ['date'] . '</td>
  6002. </tr><tr>
  6003. <th class="taC">收款金额</th><td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  6004. <th class="taC">收款信息</th><td>' . $detail ['receivablesMessage'] . '</td>
  6005. </tr>
  6006. <tr>
  6007. <th class="taC">收款银行</th><td>' . $detail ['receivablesBank'] . '</td>
  6008. <th class="taC">银行到账</th><td>' . $detail ['receivablesDate'] . '</td>
  6009. </tr>
  6010. <tr>
  6011. <th class="taC">认领收款</th><td colspan="3">' . $detail ['inputStaff'] . ' 转入 ' . $detail ['username'] . ' ' . $detail ['confirmTime'] . '</td>
  6012. </tr>
  6013. </tbody></table>';
  6014. if (! empty ( $ireList )) {
  6015. $html .= '
  6016. <table class="table table-bordered table-condensed"><tbody><tr><th class="taC" colspan="5">退款记录</th></tr>
  6017. <tr>
  6018. <th class="taC">退款单位名称</th>
  6019. <th class="taC">退款的账号</th>
  6020. <th class="taC">退款金额</th>
  6021. <th class="taC">退款</th>
  6022. <th class="taC">备注</th>
  6023. </tr>
  6024. ';
  6025. foreach ( $ireList as $key => $value ) {
  6026. $refundLogList = explode ( "<br/>", $value ['refundLog'] );
  6027. $html .= '<tr>
  6028. <td>' . $value ['refundCompany'] . '</td>
  6029. <td>' . $value ['refundNumber'] . '</td>
  6030. <td><b class="colRed">¥' . $value ['refundPrice'] . '</b></td>
  6031. <td>' . $refundLogList [0] . $refundLogList [2] . '</td>
  6032. <td>' . $value ['refundRemarks'] . '</td>
  6033. </tr>
  6034. ';
  6035. }
  6036. }
  6037. $html .= '</tbody></table></div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  6038. }
  6039. echo json_encode ( array (
  6040. 'status' => 1,
  6041. 'html' => $html
  6042. ) );
  6043. die ();
  6044. } elseif ($type == 'IRTC') {
  6045. Doo::loadModel ( 'invoice' );
  6046. $invoice = new invoice ();
  6047. Doo::loadModel ( 'invoiceOperationLog' );
  6048. $invoiceOperationLog = new invoiceOperationLog ();
  6049. Doo::loadModel ( 'invoiceReceivables' );
  6050. $invoiceReceivables = new invoiceReceivables ();
  6051. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  6052. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  6053. if (empty ( $detail ))
  6054. $html = '';
  6055. else {
  6056. $receivablesPriceedHtml = '';
  6057. $receivablesPrice = $detail ['invoicePrice'];
  6058. if (! empty ( $detail ['irid'] )) {
  6059. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $detail ['irid'] );
  6060. if (empty ( $irList ))
  6061. $irList [0] ['sumPrice'] = 0;
  6062. $balance = $detail ['invoicePrice'] - $irList [0] ['sumPrice'];
  6063. $receivablesPriceedHtml = '<table class="table table-bordered table-condensed"><tbody><tr>
  6064. <th class="taC">已入账金额</th><td><b class="colGreen" style="font-size:18px">¥' . $irList [0] ['sumPrice'] . '</b></td>
  6065. <th class="taC">剩余入账金额</th><td><b class="colRed" style="font-size:18px">¥' . $balance . '</b></td>
  6066. </tr></tbody></table>';
  6067. $receivablesPrice = $balance;
  6068. }
  6069. if ($loss)
  6070. $detail ['invoicePrice'] = - $detail ['invoicePrice'];
  6071. $html = $receivablesPriceedHtml . '
  6072. <table class="table table-bordered table-condensed"><tbody>
  6073. <tr>
  6074. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  6075. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  6076. </tr>
  6077. <tr>
  6078. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  6079. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  6080. </tr>
  6081. <tr>
  6082. <th class="taC" width="150">发票备注</th><td colspan="3">' . $detail ['remark'] . '</td>
  6083. </tr>
  6084. <tr>
  6085. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  6086. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  6087. </tr>
  6088. <tr>
  6089. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  6090. </tr></tbody></table>';
  6091. if ($detail ['invoiceType'] == 0) {
  6092. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6093. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  6094. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  6095. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  6096. </tr>';
  6097. $receivablesMessage = $detail ['invoiceTitle'];
  6098. } else {
  6099. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6100. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  6101. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  6102. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  6103. ';
  6104. $receivablesMessage = $detail ['invoiceCompany'];
  6105. }
  6106. $html .= '<tr>
  6107. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  6108. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  6109. </tr>
  6110. <tr>
  6111. <th class="taC">开户银行</th><td>' . $detail ['bankAccount'] . '</td>
  6112. <th class="taC">银行账号</th><td>' . $detail ['bank'] . '</td>
  6113. </tr></tbody></table>';
  6114. if ($detail ['doPost'] == 1)
  6115. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  6116. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  6117. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  6118. </tr><tr>
  6119. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  6120. </tr><tr>
  6121. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  6122. </tr></tbody></table>';
  6123. if (! empty ( $invoiceOperationLogList )) {
  6124. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  6125. foreach ( $invoiceOperationLogList as $key => $value ) {
  6126. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  6127. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  6128. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  6129. if ($value ['status'] == 2) {
  6130. $html .= '<span class="colGreen">同意</span>';
  6131. } elseif ($value ['status'] == 3) {
  6132. $html .= '<span class="colOrange">退回</span>';
  6133. } elseif ($value ['status'] == 5) {
  6134. $html .= '<span class="colGreen">打印</span>';
  6135. }
  6136. $html .= $value ['operation'] . '</p></blockquote>';
  6137. }
  6138. }
  6139. $html .= '</td></tr></tbody></table>';
  6140. }
  6141. }
  6142. echo json_encode ( array (
  6143. 'status' => 1,
  6144. 'html' => $html,
  6145. 'receivablesPrice' => $receivablesPrice,
  6146. 'receivablesMessage' => $receivablesMessage,
  6147. 'receivablesDate' => date ( "Y-m-d" ),
  6148. 'iidKey' => $serial
  6149. ) );
  6150. die ();
  6151. }
  6152. }
  6153. function ajaxGetInvoiceReceivablesByStaff() {
  6154. $postData = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : "";
  6155. if (empty ( $postData )) {
  6156. echo json_encode ( array (
  6157. 'status' => 2,
  6158. 'msg' => 'illegal request'
  6159. ) );
  6160. die ();
  6161. }
  6162. Doo::loadModel ( 'invoiceReceivables' );
  6163. $invoiceReceivables = new invoiceReceivables ();
  6164. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $postData );
  6165. if (empty ( $detail )) {
  6166. echo json_encode ( array (
  6167. 'status' => 2,
  6168. 'msg' => 'illegal request'
  6169. ) );
  6170. die ();
  6171. }
  6172. Doo::loadModel ( 'L_category' );
  6173. $lCategory = new L_category ();
  6174. Doo::loadModel ( 'staff' );
  6175. $staff = new staff ();
  6176. $staffList = $staff->getStaffByCid ( $detail ['cid'] );
  6177. $category = $lCategory->getCategory ();
  6178. $categoryHtml = '<option post-data="PUBLIC" value="PUBLIC" >公共待认领款项</option>';
  6179. $staffHtml = '<option value="PUBLIC">办事处待认领款项</option>';
  6180. foreach ( $category as $key => $value ) {
  6181. $categoryHtml .= '<option post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  6182. if ($value ['cid'] == $detail ['cid'])
  6183. $categoryHtml .= '<option selected post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  6184. }
  6185. foreach ( $staffList as $key => $value ) {
  6186. $staffHtml .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  6187. if ($value ['sid'] == $detail ['sid'])
  6188. $staffHtml .= '<option selected value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  6189. }
  6190. $rbankHtml = '<option value="广发银行珠海分行柠溪支行">广发银行珠海分行柠溪支行</option>';
  6191. echo json_encode ( array (
  6192. 'status' => 1,
  6193. 'categoryHtml' => $categoryHtml,
  6194. 'staffHtml' => $staffHtml,
  6195. 'rbankHtml' => $rbankHtml,
  6196. 'detail' => $detail
  6197. ) );
  6198. }
  6199. function ajaxGetInvoiceReceivablesByIrid() {
  6200. $irid = $this->get_args ( 'irid' ) ? $this->get_args ( 'irid' ) : "";
  6201. if (empty ( $irid )) {
  6202. echo json_encode ( array (
  6203. 'status' => 2,
  6204. 'msg' => 'illegal request'
  6205. ) );
  6206. die ();
  6207. }
  6208. Doo::loadModel ( 'invoiceReceivables' );
  6209. $invoiceReceivables = new invoiceReceivables ();
  6210. Doo::loadModel ( 'invoice' );
  6211. $invoice = new invoice ();
  6212. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid ); // 入账完成 待定 and postStatus=1
  6213. $flag = true;
  6214. $invoiceDetail = $invoice->getInvoiceByTitle ( $detail ['recepitTitleMark'], 'EXACTLY', " and status=2 and printStatus=1 and untreadStatus=0 ", $flag ); //
  6215. $bakDetail = array ();
  6216. if ($flag === false) {
  6217. array_push ( $bakDetail, $invoiceDetail );
  6218. $invoiceDetail = $bakDetail;
  6219. }
  6220. $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>
  6221. <tr>
  6222. <td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  6223. <td>' . $detail ['receivablesMessage'] . '</td>
  6224. <td>' . $detail ['receivablesBank'] . '<br>' . $detail ['receivablesDate'] . '</td>
  6225. <td>' . $detail ['title'] . '-' . $detail ['username'] . '<br>' . $detail ['confirmTime'] . '</td>
  6226. <td>' . $detail ['recepitTitleMark'] . '</td>
  6227. </tr></tbody></table>';
  6228. $isInvoice = false;
  6229. $invoiceHtml = '';
  6230. if (empty ( $invoiceDetail )) {
  6231. $isInvoice = true;
  6232. } else {
  6233. $invoiceHtml = '<table class="table table-bordered table-condensed">
  6234. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody>';
  6235. foreach ( $invoiceDetail as $key => $value ) {
  6236. $invoiceHtml .= '<tr>';
  6237. if (! empty ( $value ['invoiceType'] )) {
  6238. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  6239. } else {
  6240. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  6241. }
  6242. if (! empty ( $value ['invoiceType'] )) {
  6243. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  6244. } else {
  6245. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  6246. }
  6247. $invoiceHtml .= '
  6248. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  6249. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  6250. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir" data-ikey="' . $value ['iidKey'] . '" href="javascript:void(0)">入账</a></td>
  6251. </tr>
  6252. ';
  6253. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  6254. if (empty ( $irList ))
  6255. $irList [0] ['sumPrice'] = 0;
  6256. $balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  6257. $priceString = '';
  6258. if ($balance < $detail ['receivablesPrice']) {
  6259. $priceString = '收款金额超过开票金额,';
  6260. }
  6261. if ($balance > $detail ['receivablesPrice']) {
  6262. $priceString = '收款金额低于开票金额,';
  6263. }
  6264. }
  6265. $invoiceHtml .= '
  6266. <script>
  6267. $(\'a[bind-receivables^="ir"]\').click(function() {
  6268. var data = $(this).attr("data-ikey");
  6269. $("input[name=\'invoiceKey\']").val(data);
  6270. var invoiceKey=data;
  6271. if(invoiceKey==""){
  6272. alert("入账错误,请重新刷新页面");
  6273. return false;
  6274. }
  6275. if(window.confirm("' . $priceString . '确定入账吗?")){
  6276. $("#IBR").submit();
  6277. }else{
  6278. return false;
  6279. }
  6280. });
  6281. </script>
  6282. ';
  6283. $invoiceHtml .= '</tbody></table>';
  6284. }
  6285. echo json_encode ( array (
  6286. 'status' => 1,
  6287. 'irkey' => $detail ['iridEn'],
  6288. 'receivablesHtml' => $receivablesHtml,
  6289. 'isInvoice' => $isInvoice,
  6290. 'invoiceHtml' => $invoiceHtml
  6291. ) );
  6292. }
  6293. function ajaxGetInvoiceReceivablesByTitle() {
  6294. $title = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  6295. if (empty ( $title )) {
  6296. echo json_encode ( array (
  6297. 'status' => 2,
  6298. 'msg' => 'illegal request'
  6299. ) );
  6300. die ();
  6301. }
  6302. Doo::loadModel ( 'invoice' );
  6303. $invoice = new invoice ();
  6304. $invoiceDetail = $invoice->getInvoiceByTitle ( $title, 'FUZZY', " and status=2 and printStatus=1 and untreadStatus=0 and irid='' ", true );
  6305. $invoiceHtml = '';
  6306. if (! empty ( $invoiceDetail )) {
  6307. $invoiceHtml = '<table class="table table-bordered table-condensed">
  6308. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody><tr>';
  6309. foreach ( $invoiceDetail as $key => $value ) {
  6310. if (! empty ( $value ['invoiceType'] )) {
  6311. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  6312. } else {
  6313. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  6314. }
  6315. if (! empty ( $value ['invoiceType'] )) {
  6316. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  6317. } else {
  6318. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  6319. }
  6320. $invoiceHtml .= '
  6321. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  6322. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  6323. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir' . $value ['iidKeyXD'] . '" data-ikey="' . $value ['iidKey'] . '" href="#">入账</a></td>
  6324. </tr>
  6325. ';
  6326. }
  6327. $invoiceHtml .= '</tbody></table>
  6328. <script>
  6329. $(\'a[bind-receivables^="ir"]\').click(function() {
  6330. var data = $(this).attr("data-ikey");
  6331. $("input[name=\'invoiceKey\']").val(data);
  6332. var invoiceKey=$("input[name=\'invoiceKey\']").val();
  6333. if(invoiceKey==""){
  6334. alert("入账错误,请重新刷新页面");
  6335. return false;
  6336. }
  6337. if(window.confirm("确定入账吗?")){
  6338. $("#IBR").submit();
  6339. }else{
  6340. return false;
  6341. }
  6342. });
  6343. </script>
  6344. ';
  6345. }
  6346. echo json_encode ( array (
  6347. 'status' => 1,
  6348. 'invoiceHtml' => $invoiceHtml
  6349. ) );
  6350. }
  6351. function ajaxInvoicePushNotice() {
  6352. Doo::loadModel ( 'invoice' );
  6353. $invoice = new invoice ();
  6354. $approval = $invoice->getOne ( array (
  6355. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  6356. 'desc' => 'iid',
  6357. 'asArray' => true
  6358. ) );
  6359. $isNotice = false;
  6360. if (! empty ( $approval ))
  6361. $isNotice = true;
  6362. $response = array (
  6363. 'error' => 0,
  6364. 'isNotice' => $isNotice
  6365. );
  6366. echo json_encode ( $response );
  6367. exit ();
  6368. }
  6369. public function ajaxCheckInvoiceNoUniqueness() {
  6370. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  6371. Doo::loadModel ( 'invoice' );
  6372. $invoice = new invoice ();
  6373. if (! empty ( $invoiceNo )) {
  6374. Doo::loadModel ( 'invoicePaper' );
  6375. $invoicePaper = new invoicePaper ();
  6376. Doo::loadClass ( 'XDeode' );
  6377. $XDeode = new XDeode ( 5 );
  6378. $ipid = $XDeode->decode ( $invoiceNo );
  6379. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  6380. $info = $invoice->getOne ( array (
  6381. 'where' => "invoiceNo = '" . $paperDetail ['invoiceNo'] . "'",
  6382. 'asArray' => TRUE
  6383. ) );
  6384. if (! empty ( $info )) {
  6385. echo json_encode ( array (
  6386. 'error' => '发票号已存在'
  6387. ) );
  6388. die ();
  6389. } else
  6390. echo json_encode ( array (
  6391. 'ok' => '可以使用!'
  6392. ) );
  6393. die ();
  6394. }
  6395. }
  6396. function ajaxCheckInvoicePrice() {
  6397. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) && is_numeric ( $this->get_args ( 'receivablesPrice' ) ) ? $this->get_args ( 'receivablesPrice' ) : "";
  6398. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  6399. Doo::loadModel ( 'invoice' );
  6400. $invoice = new invoice ();
  6401. Doo::loadModel ( 'invoiceReceivables' );
  6402. $invoiceReceivables = new invoiceReceivables ();
  6403. Doo::loadClass ( 'XDeode' );
  6404. $XDeode = new XDeode ( 5 );
  6405. if (! empty ( $receivablesPrice ) && ! empty ( $iidKey )) {
  6406. $iidKey = $XDeode->decode ( $iidKey );
  6407. $info = $invoice->getInvoiceByIid ( $iidKey );
  6408. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $info ['irid'] );
  6409. if (empty ( $irList ))
  6410. $irList [0] ['sumPrice'] = 0;
  6411. $balance = $info ['invoicePrice'] - $irList [0] ['sumPrice'];
  6412. if ($balance < $receivablesPrice) {
  6413. echo json_encode ( array (
  6414. 'error' => '收款金额超过开票金额。'
  6415. ) );
  6416. die ();
  6417. }
  6418. if ($balance > $receivablesPrice) {
  6419. echo json_encode ( array (
  6420. 'error' => '收款金额低于开票金额。'
  6421. ) );
  6422. die ();
  6423. }
  6424. }
  6425. }
  6426. function ajaxGetInvoiceByNew() {
  6427. Doo::loadModel ( 'invoice' );
  6428. $invoice = new invoice ();
  6429. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );
  6430. echo json_encode ( array (
  6431. 'status' => 1,
  6432. 'detail' => $detail
  6433. ) );
  6434. }
  6435. /**
  6436. * 旧输入导入
  6437. */
  6438. function importInvoice() {
  6439. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  6440. $data ['emsg'] = "";
  6441. if ($emsg != "")
  6442. $data ['emsg'] = "请填写完整的数据";
  6443. $data ['time'] = time ();
  6444. $this->render ( "/admin/invoiceImport", $data );
  6445. }
  6446. function uploadInvoice() {
  6447. // move_uploaded_file($_FILES['Filedata']['tmp_name'], "/upload/".$_FILES['Filedata']['name']);
  6448. if (isset ( $_FILES ['Filedata'] ['name'] )) {
  6449. $file = $_FILES ['Filedata'] ['tmp_name'];
  6450. $error = false;
  6451. if (! is_uploaded_file ( $file )) {
  6452. $error = '400 Bad Request';
  6453. }
  6454. if ($error) {
  6455. header ( 'HTTP/1.0 ' . $error );
  6456. die ( 'Error ' . $error );
  6457. } else {
  6458. include (DOO::conf ()->SITE_PATH . 'protected/plugin/io.han.php');
  6459. $this->IoHandler = new IoHandler ();
  6460. $pics = explode ( '.', $_FILES ['Filedata'] ['name'] );
  6461. // $filedir=$_POST['time'];
  6462. // 调用定义物理路径
  6463. $t = DOO::conf ()->SITE_PATH . "upload/invoice/";
  6464. $this->IoHandler->MakeDir ( $t );
  6465. $filename = $this->_GetFileEXT ( $_FILES ['Filedata'] ['name'] );
  6466. if ($filename != 'xlsx')
  6467. return "";
  6468. // $upload_dir = $t."/".time().rand(10,100).".".$filename;
  6469. $upload_file = iconv ( "UTF-8", "GB2312", $_FILES ["Filedata"] ["name"] );
  6470. $upload_dir = $t . "/" . $upload_file;
  6471. $k = move_uploaded_file ( $file, $upload_dir );
  6472. if ($k) {
  6473. $m = round ( $_FILES ['Filedata'] ['size'] / 1024 / 1024, 2 );
  6474. echo $pics [0] . "." . $filename . "#" . $m . "#" . $_FILES ['Filedata'] ['size'];
  6475. }
  6476. }
  6477. }
  6478. }
  6479. function importInvoiceDo() {
  6480. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  6481. if ($path != "") {
  6482. Doo::loadModel ( 'invoice' );
  6483. Doo::loadModel ( 'staff' );
  6484. $staff = new staff ();
  6485. Doo::loadModel ( 'invoiceStatistics' );
  6486. Doo::loadModel ( 'invoiceOperationLog' );
  6487. echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  6488. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . $path );
  6489. // print_r ( $exlArray );
  6490. // die ();
  6491. // echo json_encode($exlArray);die;
  6492. foreach ( $exlArray as $key => $value ) {
  6493. // 开票
  6494. $invoice = new invoice ();
  6495. $invoice->invoiceNo = $value ['invoiceNo'];
  6496. $invoice->invoiceType = 0;
  6497. if ($value ['invoiceType'] == '专')
  6498. $invoice->invoiceType = 1;
  6499. $invoice->invoicePrice = $value ['invoicePrice'];
  6500. $invoice->invoiceQuantity = 1;
  6501. $invoice->invoiceUnitPrice = $value ['invoicePrice'];
  6502. $invoice->invoiceTitle = $value ['invoiceTitle'];
  6503. if ($value ['invoiceType'] == '专')
  6504. $invoice->invoiceCompany = $value ['invoiceTitle'];
  6505. $invoice->userName = $value ['userName'];
  6506. $sDetail = $staff->getStaffByName ( $value ['userName'] );
  6507. $invoice->sid = $sDetail ['sid'];
  6508. $invoice->cid = $sDetail ['cid'];
  6509. $invoice->categoryName = $sDetail ['category'];
  6510. $invoice->invoiceElement = $value ['invoiceElement'];
  6511. $invoice->remark = $value ['remark'];
  6512. $invoice->date = $value ['date'];
  6513. $invoice->printTime = $value ['date'];
  6514. $invoice->ipSource = 1;
  6515. $invoice->printStatus = 1;
  6516. $invoice->status = 2;
  6517. $invoice->postStatus = 1;
  6518. $invoice->untreadStatus = 0;
  6519. $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  6520. $iid = $invoice->insert ();
  6521. // 汇总
  6522. $invoiceStatistics = new invoiceStatistics ();
  6523. //
  6524. $item = array (
  6525. 'date' => $value ['date'],
  6526. 'priceClass' => 1,
  6527. 'cid' => $sDetail ['cid'],
  6528. 'staff' => $sDetail ['sid'],
  6529. 'invoicePrice' => $value ['invoicePrice']
  6530. );
  6531. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  6532. $invoiceOperationLog = new invoiceOperationLog ();
  6533. $item = array (
  6534. 'date' => date ( "Y-m-d H:i:s" ),
  6535. 'operation' => date ( "Y-m-d" ) . " 导入",
  6536. 'status' => 1,
  6537. 'img' => $sDetail ['avatar'],
  6538. 'username' => $sDetail ['username'],
  6539. 'uid' => $sDetail ['sid'],
  6540. 'category' => $sDetail ['category'],
  6541. 'iid' => $iid
  6542. );
  6543. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  6544. }
  6545. return '/importInvoice?count=' . count ( $exlArray );
  6546. // return "/keyonline";
  6547. }
  6548. echo 'no file';
  6549. }
  6550. function importInvoiceReceivables() {
  6551. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  6552. $data ['emsg'] = "";
  6553. if ($emsg != "")
  6554. $data ['emsg'] = "请填写完整的数据";
  6555. $data ['time'] = time ();
  6556. $this->render ( "/admin/invoiceReceivablesImport", $data );
  6557. }
  6558. // 导入入账数据
  6559. function importInvoiceReceivablesDo() {
  6560. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  6561. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  6562. if ($path != "") {
  6563. Doo::loadModel ( 'invoiceReceivables' );
  6564. Doo::loadModel ( 'invoice' );
  6565. Doo::loadModel ( 'staff' );
  6566. $staff = new staff ();
  6567. Doo::loadModel ( 'invoiceStatistics' );
  6568. // echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  6569. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path ), 'invoiceReceivables' );
  6570. // print_r ( $exlArray );
  6571. // die ();
  6572. // echo json_encode($exlArray);die;
  6573. foreach ( $exlArray as $key => $value ) {
  6574. // 收款
  6575. $invoiceReceivables = new invoiceReceivables ();
  6576. $invoice = new invoice ();
  6577. $invoiceReceivables->bindStatus = 1;
  6578. $invoiceReceivables->receivablesPrice = $value ['receivablesPrice'];
  6579. $invoiceReceivables->receivablesMessage = $value ['receivablesMessage'];
  6580. $invoiceReceivables->receivablesBank = $value ['receivablesBank'];
  6581. $invoiceReceivables->receivablesDate = $value ['receivablesDate'];
  6582. $sDetail = $staff->getStaffByName ( $value ['receivablesStaff'] );
  6583. $invoiceReceivables->receivablesCategory = $sDetail ['cid'] . ':' . $sDetail ['category'];
  6584. $invoiceReceivables->receivablesStaff = $sDetail ['sid'] . '-' . $sDetail ['username'];
  6585. $invoiceReceivables->receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  6586. $invoiceReceivables->sourcePrice = $value ['sourcePrice'];
  6587. $iDetail = $invoice->getInvoiceByInvoiceNo ( $value ['invoiceNo'] );
  6588. $invoiceReceivables->iid = $iDetail ['iid'];
  6589. $irid = $invoiceReceivables->insert ();
  6590. // 发票绑定收款
  6591. $detail = $iDetail;
  6592. $iridString = "";
  6593. if (empty ( $detail ['irid'] ))
  6594. $iridString = $irid;
  6595. else
  6596. $iridString = $detail ['irid'] . ',' . $irid;
  6597. $item = array (
  6598. 'irid' => $iridString,
  6599. 'iid' => $detail ['iid']
  6600. );
  6601. $invoice->setInvoiceByCondition ( $item );
  6602. // 汇总
  6603. $invoiceStatistics = new invoiceStatistics ();
  6604. // 扣除入账统计金额
  6605. $item = array (
  6606. 'date' => $value ['receivablesDate'],
  6607. 'priceClass' => 3,
  6608. 'cid' => $sDetail ['cid'],
  6609. 'staff' => $sDetail ['sid'],
  6610. // 'irid' => $irid,
  6611. 'accountPrice' => $value ['receivablesPrice']
  6612. );
  6613. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  6614. }
  6615. return '/importInvoiceReceivables?count=' . count ( $exlArray );
  6616. echo 'data count ' . count ( $exlArray );
  6617. die ();
  6618. // return "/keyonline";
  6619. }
  6620. echo 'no file';
  6621. }
  6622. function formatExcelToArrayTrain($file_url = "") {
  6623. if (! file_exists ( $file_url )) {
  6624. return array ();
  6625. }
  6626. // Doo::loadClass ( 'PHPExcel' );
  6627. Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  6628. $PHPExcel = new PHPExcel ();
  6629. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  6630. if (! $PHPReader->canRead ( $file_url )) {
  6631. $PHPReader = new PHPExcel_Reader_Excel5 ();
  6632. if (! $PHPReader->canRead ( $file_url )) {
  6633. echo 'no Excel';
  6634. return;
  6635. }
  6636. }
  6637. $PHPExcel = $PHPReader->load ( $file_url );
  6638. /* * 读取excel文件中的第一个工作表 */
  6639. $currentSheet = $PHPExcel->getSheet ( 0 );
  6640. /* * 取得最大的列号 */
  6641. $allColumn = $currentSheet->getHighestColumn ();
  6642. /* * 取得一共有多少行 */
  6643. $allRow = $currentSheet->getHighestRow ();
  6644. $excel_array = array ();
  6645. // die($file_url);
  6646. $conk = 2;
  6647. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  6648. $excel_column = array ();
  6649. // 后期改进
  6650. if ($allColumn == 'AM')
  6651. $allColumn = 'Z';
  6652. /* * 从第A列开始输出 */
  6653. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  6654. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  6655. if ($val instanceof PHPExcel_RichText)
  6656. $val = $val->__toString ();
  6657. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  6658. // $val = "'" . addslashes ( $val ) . "'";
  6659. if ($currentColumn == 'A') {
  6660. $excel_column ['invoiceTitle'] = $val;
  6661. } elseif ($currentColumn == 'B')
  6662. $excel_column ['invoiceType'] = $val;
  6663. elseif ($currentColumn == 'C') {
  6664. $excel_column ['TIN'] = $val;
  6665. } elseif ($currentColumn == 'D') {
  6666. $excel_column ['address'] = $val;
  6667. } elseif ($currentColumn == 'E') {
  6668. $excel_column ['phone'] = $val;
  6669. } elseif ($currentColumn == 'F') {
  6670. $excel_column ['bank'] = $val;
  6671. } elseif ($currentColumn == 'G') {
  6672. $excel_column ['bankAccount'] = $val;
  6673. } elseif ($currentColumn == 'H') {
  6674. $excel_column ['invoiceElement'] = $val;
  6675. } elseif ($currentColumn == 'I') {
  6676. $excel_column ['invoiceQuantity'] = $val;
  6677. } elseif ($currentColumn == 'J') {
  6678. $excel_column ['invoiceUnitPrice'] = $val;
  6679. } elseif ($currentColumn == 'K') {
  6680. $excel_column ['remark'] = $val;
  6681. } elseif ($currentColumn == 'L') {
  6682. $excel_column ['recipientsAddress'] = $val;
  6683. } elseif ($currentColumn == 'M') {
  6684. $excel_column ['recipients'] = $val;
  6685. } elseif ($currentColumn == 'N') {
  6686. $excel_column ['recipientsPhone'] = $val;
  6687. }
  6688. }
  6689. if (! empty ( $excel_column ['invoiceTitle'] ) && ! empty ( $excel_column ['invoiceQuantity'] ) && ! empty ( $excel_column ['invoiceUnitPrice'] ))
  6690. array_push ( $excel_array, $excel_column );
  6691. }
  6692. return $excel_array;
  6693. }
  6694. /**
  6695. * 格式化excel文件为数组
  6696. * @param unknown_type $file_url
  6697. * @param unknown_type $mcid
  6698. */
  6699. function _format_excel_to_array($file_url = "", $sType = "") {
  6700. if (! file_exists ( $file_url )) {
  6701. return array ();
  6702. }
  6703. Doo::loadClass ( 'PHPExcel' );
  6704. // Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  6705. $PHPExcel = new PHPExcel ();
  6706. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  6707. if (! $PHPReader->canRead ( $file_url )) {
  6708. $PHPReader = new PHPExcel_Reader_Excel5 ();
  6709. if (! $PHPReader->canRead ( $file_url )) {
  6710. echo 'no Excel';
  6711. return;
  6712. }
  6713. }
  6714. $PHPExcel = $PHPReader->load ( $file_url );
  6715. /* * 读取excel文件中的第一个工作表 */
  6716. $currentSheet = $PHPExcel->getSheet ( 0 );
  6717. /* * 取得最大的列号 */
  6718. $allColumn = $currentSheet->getHighestColumn ();
  6719. /* * 取得一共有多少行 */
  6720. $allRow = $currentSheet->getHighestRow ();
  6721. $excel_array = array ();
  6722. // die($file_url);
  6723. $conk = 2;
  6724. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  6725. $excel_column = array ();
  6726. // 后期改进
  6727. if ($allColumn == 'AM')
  6728. $allColumn = 'Z';
  6729. /* * 从第A列开始输出 */
  6730. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  6731. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  6732. if ($val instanceof PHPExcel_RichText)
  6733. $val = $val->__toString ();
  6734. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  6735. // $val = "'" . addslashes ( $val ) . "'";
  6736. if ($sType == 'invoiceReceivables') {
  6737. if ($currentColumn == 'A')
  6738. $excel_column ['invoiceNo'] = $val;
  6739. elseif ($currentColumn == 'B')
  6740. $excel_column ['receivablesPrice'] = $val;
  6741. elseif ($currentColumn == 'C') {
  6742. $excel_column ['receivablesMessage'] = $val;
  6743. } elseif ($currentColumn == 'D') {
  6744. $excel_column ['receivablesBank'] = $val;
  6745. } elseif ($currentColumn == 'E') {
  6746. $excel_column ['receivablesDate'] = $this->excelTime ( $val );
  6747. } elseif ($currentColumn == 'F') {
  6748. $excel_column ['receivablesStaff'] = $val;
  6749. } elseif ($currentColumn == 'G') {
  6750. $excel_column ['sourcePrice'] = $val;
  6751. }
  6752. } elseif ($sType == "invoiceTrain") {
  6753. if ($currentColumn == 'A') {
  6754. $excel_column ['invoiceTitle'] = $val;
  6755. } elseif ($currentColumn == 'B')
  6756. $excel_column ['invoiceType'] = $val;
  6757. elseif ($currentColumn == 'C') {
  6758. $excel_column ['TIN'] = $val;
  6759. } elseif ($currentColumn == 'D') {
  6760. $excel_column ['address'] = $val;
  6761. } elseif ($currentColumn == 'E') {
  6762. $excel_column ['phone'] = $val;
  6763. } elseif ($currentColumn == 'F') {
  6764. $excel_column ['bank'] = $val;
  6765. } elseif ($currentColumn == 'G') {
  6766. $excel_column ['bankAccount'] = $val;
  6767. } elseif ($currentColumn == 'H') {
  6768. $excel_column ['invoiceElement'] = $val;
  6769. } elseif ($currentColumn == 'I') {
  6770. $excel_column ['invoiceQuantity'] = $val;
  6771. } elseif ($currentColumn == 'J') {
  6772. $excel_column ['invoiceUnitPrice'] = $val;
  6773. } elseif ($currentColumn == 'K') {
  6774. $excel_column ['remark'] = $val;
  6775. } elseif ($currentColumn == 'L') {
  6776. $excel_column ['recipientsAddress'] = $val;
  6777. } elseif ($currentColumn == 'M') {
  6778. $excel_column ['recipients'] = $val;
  6779. } elseif ($currentColumn == 'N') {
  6780. $excel_column ['recipientsPhone'] = $val;
  6781. }
  6782. } else {
  6783. if ($currentColumn == 'A')
  6784. $excel_column ['invoiceNo'] = $val;
  6785. elseif ($currentColumn == 'B')
  6786. $excel_column ['invoiceType'] = $val;
  6787. elseif ($currentColumn == 'C') {
  6788. $excel_column ['invoicePrice'] = $val;
  6789. } elseif ($currentColumn == 'D') {
  6790. $excel_column ['invoiceTitle'] = $val;
  6791. } elseif ($currentColumn == 'E') {
  6792. $excel_column ['userName'] = $val;
  6793. } elseif ($currentColumn == 'F') {
  6794. $excel_column ['categoryName'] = $val;
  6795. } elseif ($currentColumn == 'G') {
  6796. $excel_column ['invoiceElement'] = $val;
  6797. } elseif ($currentColumn == 'H') {
  6798. $excel_column ['remark'] = $val;
  6799. } elseif ($currentColumn == 'I') {
  6800. $excel_column ['date'] = $this->excelTime ( $val );
  6801. }
  6802. }
  6803. }
  6804. array_push ( $excel_array, $excel_column );
  6805. }
  6806. return $excel_array;
  6807. }
  6808. function excelTime($date, $time = false) {
  6809. if (function_exists ( 'GregorianToJD' )) {
  6810. if (is_numeric ( $date )) {
  6811. $jd = GregorianToJD ( 1, 1, 1970 );
  6812. $gregorian = JDToGregorian ( $jd + intval ( $date ) - 25569 );
  6813. $date = explode ( '/', $gregorian );
  6814. $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" : '');
  6815. return $date_str;
  6816. }
  6817. } else {
  6818. $date = $date > 25568 ? $date + 1 : 25569;
  6819. /* There was a bug if Converting date before 1-1-1970 (tstamp 0) */
  6820. $ofs = (70 * 365 + 17 + 2) * 86400;
  6821. $date = date ( "Y-m-d", ($date * 86400) - $ofs ) . ($time ? " 00:00:00" : '');
  6822. }
  6823. return $date;
  6824. }
  6825. /**
  6826. * 旧输入导入
  6827. */
  6828. function _GetFileEXT($filename) {
  6829. $pics = explode ( '.', $filename );
  6830. $num = count ( $pics );
  6831. return $pics [$num - 1];
  6832. }
  6833. function showCache($path = "", $sid = 0) {
  6834. // if (file_exists ( $path )) {
  6835. // $htm = file_get_contents ( $path );
  6836. // } else {
  6837. Doo::loadModel ( 'invoiceStatistics' );
  6838. $invoiceStatistics = new invoiceStatistics ();
  6839. $isBriefly = $invoiceStatistics->getBrieflyStatistics ( $sid );
  6840. $htm = '<tr><th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计开票</th>
  6841. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['invoicePrice'] . '</td>
  6842. <th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计入账</th>
  6843. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['accountPrice'] . '</td></tr>';
  6844. /*
  6845. * '<tr><th class="taC">今年累计开票</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['invoicePrice'] . '</td> <th class="taC">今年累计入账</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['accountPrice'] . '</td></tr>';
  6846. */
  6847. file_put_contents ( $path, $htm );
  6848. // }
  6849. return $htm;
  6850. }
  6851. /**
  6852. * 生成token
  6853. * @return string
  6854. */
  6855. function set_token() {
  6856. $str = md5 ( uniqid ( md5 ( microtime ( true ) ), true ) ); // 生成一个不会重复的字符串
  6857. $str = sha1 ( $str ); // 加密
  6858. return $str;
  6859. }
  6860. /**
  6861. * 获取get或者POST值
  6862. *
  6863. * @param string $name 属性名称
  6864. * @return fixed 值
  6865. */
  6866. function get_args($name) {
  6867. if (isset ( $_GET [$name] )) {
  6868. if (is_array ( $_GET [$name] ))
  6869. return $_GET [$name];
  6870. else
  6871. return addslashes ( $_GET [$name] );
  6872. } elseif (isset ( $_POST [$name] )) {
  6873. if (is_array ( $_POST [$name] ))
  6874. return $_POST [$name];
  6875. else
  6876. return addslashes ( $_POST [$name] );
  6877. } else
  6878. return false;
  6879. }
  6880. function SafeFilter(&$arr) {
  6881. $ra = Array (
  6882. '/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/',
  6883. '/script/',
  6884. '/javascript/',
  6885. '/vbscript/',
  6886. '/expression/',
  6887. '/applet/',
  6888. '/meta/',
  6889. '/xml/',
  6890. '/blink/',
  6891. '/link/',
  6892. '/style/',
  6893. '/embed/',
  6894. '/object/',
  6895. '/frame/',
  6896. '/layer/',
  6897. '/title/',
  6898. '/bgsound/',
  6899. '/base/',
  6900. '/onload/',
  6901. '/onunload/',
  6902. '/onchange/',
  6903. '/onsubmit/',
  6904. '/onreset/',
  6905. '/onselect/',
  6906. '/onblur/',
  6907. '/onfocus/',
  6908. '/onabort/',
  6909. '/onkeydown/',
  6910. '/onkeypress/',
  6911. '/onkeyup/',
  6912. '/onclick/',
  6913. '/ondblclick/',
  6914. '/onmousedown/',
  6915. '/onmousemove/',
  6916. '/onmouseout/',
  6917. '/onmouseover/',
  6918. '/onmouseup/',
  6919. '/onunload/'
  6920. );
  6921. if (is_array ( $arr )) {
  6922. foreach ( $arr as $key => $value ) {
  6923. if (! is_array ( $value )) {
  6924. if (! get_magic_quotes_gpc ()) // 不对magic_quotes_gpc转义过的字符使用addslashes(),避免双重转义。
  6925. {
  6926. $value = addslashes ( $value ); // 给单引号(')、双引号(")、反斜线(\)与 NUL(NULL 字符)加上反斜线转义
  6927. }
  6928. $value = preg_replace ( $ra, '', $value ); // 删除非打印字符,粗暴式过滤xss可疑字符串
  6929. $arr [$key] = htmlentities ( strip_tags ( $value ) ); // 去除 HTML 和 PHP 标记并转换为 HTML 实体
  6930. } else {
  6931. SafeFilter ( $arr [$key] );
  6932. }
  6933. }
  6934. }
  6935. }
  6936. /**
  6937. * Escape String
  6938. *
  6939. * @access public
  6940. * @param string
  6941. * @param bool whether or not the string will be used in a LIKE condition
  6942. * @return string
  6943. */
  6944. function escape_str($str, $like = FALSE) {
  6945. if (is_array ( $str )) {
  6946. foreach ( $str as $key => $val ) {
  6947. $str [$key] = $this->escape_str ( $val, $like );
  6948. }
  6949. return $str;
  6950. }
  6951. var_dump ( Doo::db ()->getDbObject () );
  6952. die ();
  6953. if (function_exists ( 'mysql_real_escape_string' ) and is_resource ( Doo::db ()->getDbObject () )) { // Doo::db ()->getDbObject()
  6954. $str = mysql_real_escape_string ( $str, Doo::db ()->getDbObject () );
  6955. } elseif (function_exists ( 'mysql_escape_string' )) {
  6956. $str = mysql_escape_string ( $str );
  6957. } else {
  6958. $str = addslashes ( $str );
  6959. }
  6960. // escape LIKE condition wildcards
  6961. if ($like === TRUE) {
  6962. $str = str_replace ( array (
  6963. '%',
  6964. '_'
  6965. ), array (
  6966. '\\%',
  6967. '\\_'
  6968. ), $str );
  6969. }
  6970. return $str;
  6971. }
  6972. /**
  6973. * 获得分页数据
  6974. * @param unknown_type $table
  6975. * @param unknown_type $condition
  6976. * @param unknown_type $on_page
  6977. * @param unknown_type $page_size
  6978. */
  6979. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  6980. $page_c = "";
  6981. $page ['previous'] = $this->get_previous ( $on_page );
  6982. $page ['on_page'] = $on_page;
  6983. $total_count = $this->get_table_count ( $table, $condition );
  6984. $total = intval ( $total_count / $page_size );
  6985. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  6986. $page ['total_data'] = $total_count;
  6987. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  6988. $i = 1;
  6989. $page_max = 1;
  6990. $page_width = 3;
  6991. if ($on_page >= $page_width) {
  6992. $page_max = intval ( $on_page / $page_width ) + 1;
  6993. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  6994. }
  6995. for(; $i <= $page ['total_page']; $i ++) {
  6996. if ($i == $on_page)
  6997. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  6998. else
  6999. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  7000. if ($i == ($page_width * $page_max))
  7001. break;
  7002. }
  7003. $page ['page'] = $page_c;
  7004. $page ['lower'] = (-- $on_page) * $page_size;
  7005. return $page;
  7006. }
  7007. /**
  7008. * 获取上一页
  7009. * @param unknown_type $on_page
  7010. */
  7011. function get_previous($on_page = 1) {
  7012. return $on_page != 0 ? $on_page - 1 : $on_page;
  7013. }
  7014. /**
  7015. * 获取总页数
  7016. * @param unknown_type $table
  7017. * @param unknown_type $condition
  7018. */
  7019. public function get_table_count($table = "", $condition = "") {
  7020. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  7021. $sql = "select count(*) as count from " . $table . " where " . $condition;
  7022. // echo $sql;die;
  7023. $query = Doo::db ()->query ( $sql );
  7024. $result = $query->fetch ();
  7025. return $result ['count'];
  7026. }
  7027. /**
  7028. * 获得分页数据
  7029. * @param unknown_type $table
  7030. * @param unknown_type $condition
  7031. * @param unknown_type $on_page
  7032. * @param unknown_type $page_size
  7033. */
  7034. function getPageBySql($sql = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  7035. $page_c = "";
  7036. $page ['previous'] = $this->get_previous ( $on_page );
  7037. $page ['on_page'] = $on_page;
  7038. $total_count = $this->getTableCountBySql ( $sql );
  7039. $total = intval ( $total_count / $page_size );
  7040. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  7041. $page ['total_data'] = $total_count;
  7042. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  7043. $i = 1;
  7044. $page_max = 1;
  7045. $page_width = 3;
  7046. if ($on_page >= $page_width) {
  7047. $page_max = intval ( $on_page / $page_width ) + 1;
  7048. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  7049. }
  7050. for(; $i <= $page ['total_page']; $i ++) {
  7051. if ($i == $on_page)
  7052. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  7053. else
  7054. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  7055. if ($i == ($page_width * $page_max))
  7056. break;
  7057. }
  7058. $page ['page'] = $page_c;
  7059. $page ['lower'] = (-- $on_page) * $page_size;
  7060. return $page;
  7061. }
  7062. /**
  7063. * 获得总页数 sql
  7064. * @param string $type
  7065. * @return boolean[]
  7066. */
  7067. public function getTableCountBySql($sql = "") {
  7068. $query = Doo::db ()->query ( $sql );
  7069. $result = $query->fetchAll ();
  7070. return count ( $result );
  7071. }
  7072. function isInvoiceNew($type = "GLOBAL") {
  7073. Doo::loadModel ( 'invoice' );
  7074. $invoice = new invoice ();
  7075. Doo::loadModel ( 'invoiceReceivables' );
  7076. $invoiceReceivables = new invoiceReceivables ();
  7077. Doo::loadModel ( 'staff' );
  7078. $staff = new staff ();
  7079. $st = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  7080. // 我的发票待处理
  7081. $pendingInvoice = $invoice->getOne ( array ( // or (status=2 and printStatus=1 and untreadStatus=0 ) or (status=2 and printStatus=1 and untreadStatus=2 )
  7082. 'where' => "(status=3 or status=4) and isDelete=0 and sid=" . $st [0] ['sid'],
  7083. 'desc' => 'iid',
  7084. 'asArray' => TRUE
  7085. ) );
  7086. // 我的收款待入账
  7087. /*
  7088. * $myClaim = $invoiceReceivables->getOne ( array ( 'where' => " receivablesStaff like '" . $st [0] ['sid'] . "-%' and receivablesCategory like '" . $st [0] ['cid'] . ":%' and bindStatus=0", 'desc' => 'irid', 'asArray' => TRUE ) );
  7089. */
  7090. // 发票审批
  7091. $approval = $invoice->getOne ( array (
  7092. 'where' => 'status=1 and pendingApprovals=' . $st [0] ['sid'],
  7093. 'desc' => 'iid',
  7094. 'asArray' => true
  7095. ) );
  7096. // 发票邮寄
  7097. $post = $invoice->getOne ( array (
  7098. 'where' => "postStatus=0 and printStatus=1 and isDelete=0 and doPost=1 and status=2",
  7099. 'asArray' => TRUE
  7100. ) );
  7101. // 发票打印
  7102. $print = $invoice->getOne ( array (
  7103. 'where' => "status=2 and printStatus=0 and untreadStatus=0 and moldManage like '%[\"" . $st [0] ['sid'] . "\",%'",
  7104. 'desc' => 'iid',
  7105. 'asArray' => TRUE
  7106. ) );
  7107. // 发票退票 printStatus=1 and
  7108. $untread = $invoice->getOne ( array (
  7109. 'where' => " untreadStatus=1 and status=2 ",
  7110. 'asArray' => TRUE
  7111. ) );
  7112. $new = array (
  7113. 'GLOBAL' => FALSE,
  7114. 'pendingInvoice' => FALSE,
  7115. // 'myClaim' => FALSE,
  7116. 'approval' => FALSE,
  7117. 'post' => FALSE,
  7118. 'print' => FALSE,
  7119. 'untread' => FALSE
  7120. );
  7121. // || ! empty ( $myClaim )
  7122. if (! empty ( $pendingInvoice ) || ! empty ( $approval ) || ! empty ( $post ) || ! empty ( $print ) || ! empty ( $untread ))
  7123. $new ['GLOBAL'] = TRUE;
  7124. if (! empty ( $pendingInvoice ))
  7125. $new ['pendingInvoice'] = TRUE;
  7126. // if (! empty ( $myClaim ))
  7127. // $new ['myClaim'] = TRUE;
  7128. if (! empty ( $approval ))
  7129. $new ['approval'] = TRUE;
  7130. if (! empty ( $post ))
  7131. $new ['post'] = TRUE;
  7132. if (! empty ( $print ))
  7133. $new ['print'] = TRUE;
  7134. if (! empty ( $untread ))
  7135. $new ['untread'] = TRUE;
  7136. return $new;
  7137. }
  7138. function setWXMsg($rid, $typeMsg = '') {
  7139. Doo::loadModel ( 'invoice' );
  7140. $invoice = new invoice ();
  7141. $invoiceDetail = $invoice->getOne ( array (
  7142. 'where' => 'iid=' . $rid,
  7143. 'asArray' => true
  7144. ) );
  7145. if (! empty ( $invoiceDetail )) {
  7146. Doo::loadModel ( 'staff' );
  7147. $staff = new staff ();
  7148. $staffmsg = $staff->getOne ( array (
  7149. 'where' => "sid='" . $invoiceDetail ['sid'] . "'",
  7150. 'asArray' => TRUE
  7151. ) );
  7152. if (! empty ( $staffmsg ['wxid'] )) {
  7153. require_once (SITE_PATH . '/protected/class/client.php');
  7154. $client = new client ( 'http://m.cld.smartcost.com.cn/' );
  7155. $user = $staffmsg ['wxid'];
  7156. $expCom = explode ( ":", $invoiceDetail ['expressCompany'] );
  7157. if (empty ( $expCom ))
  7158. $expCom [0] = '';
  7159. $msg = "";
  7160. if (empty ( $typeMsg ))
  7161. $msg = '太好了,您的发票' . $invoiceDetail ['invoiceSerial'] . ' 已邮寄 ' . $expCom [0] . ' ,快递号: <a href="https://m.kuaidi100.com/result.jsp?nu=' . $invoiceDetail ['expressNumber'] . '" >' . $invoiceDetail ['expressNumber'] . '</a>';
  7162. elseif ($typeMsg == "PRINT")
  7163. $msg = '太好了,您的发票已打印完成。';
  7164. $result = $client->SendMsg ( $user, $msg, 'text' );
  7165. }
  7166. }
  7167. }
  7168. /**
  7169. * 获取微信部门
  7170. * @param string $category
  7171. * @return number|mixed
  7172. */
  7173. function getToparty($category = '') {
  7174. $token = $this->getAccessToken (); //
  7175. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token={$token}&id=5" ), true );
  7176. $toparty = 0;
  7177. foreach ( $result ['department'] as $key => $value ) {
  7178. if ($value ['name'] == $category)
  7179. $toparty = $value ['id'];
  7180. }
  7181. return $toparty;
  7182. }
  7183. /**
  7184. * 获得某部门下的用户
  7185. * @param string $toparty
  7186. */
  7187. function getUserByToparty($toparty = '') {
  7188. $token = $this->getAccessToken (); //
  7189. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token={$token}&department_id={$toparty}" ), true );
  7190. $userList = array ();
  7191. foreach ( $result ['userlist'] as $key => $value ) {
  7192. array_push ( $userList, "'" . $value ['userid'] . "'" );
  7193. }
  7194. return $userList;
  7195. }
  7196. function msgSendToparty($msg, $title, $url, $toparty, $text = '') {
  7197. $token = $this->getAccessToken ();
  7198. if ($text == 'text') {
  7199. $data = '{
  7200. "touser": "' . $toparty . '",
  7201. "toparty": "",
  7202. "totag": "",
  7203. "msgtype": "text",
  7204. "agentid": 1000002,
  7205. "text": {
  7206. "content": "' . $msg . '"
  7207. },
  7208. "safe":0
  7209. }';
  7210. }
  7211. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  7212. if ($result->errmsg != 'ok') {
  7213. return 0;
  7214. } else {
  7215. return 1;
  7216. }
  7217. }
  7218. /**
  7219. * 获得可以发送微信用户列表
  7220. * @param string $category
  7221. * @return string
  7222. */
  7223. function getWxidByCategory($category = "") {
  7224. if (empty ( $category ))
  7225. return "";
  7226. Doo::loadModel ( 'staff' );
  7227. $staff = new staff ();
  7228. $toparty = $this->getToparty ( $category );
  7229. $wxList = array ();
  7230. $wxString = "";
  7231. if (! empty ( $toparty )) {
  7232. $userList = $this->getUserByToparty ( $toparty );
  7233. $userCon = implode ( ',', $userList );
  7234. // echo $userCon;
  7235. $sidList = $staff->getStaffByWxid ( $userCon );
  7236. foreach ( $sidList as $key => $value ) {
  7237. $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  7238. if ($falg) {
  7239. array_push ( $wxList, $value ['wxid'] );
  7240. }
  7241. }
  7242. $wxString = implode ( '|', $wxList );
  7243. }
  7244. return $wxString;
  7245. }
  7246. /**
  7247. * 读取发送信息规则判断是否需要发送
  7248. * @param number $sid
  7249. * @param string $sendType
  7250. * @return boolean
  7251. */
  7252. function isSendNotification($sid = 0, $sendType = '') {
  7253. Doo::loadModel ( "notificationConf" );
  7254. $notificationConf = new notificationConf ();
  7255. $detail = $notificationConf->getNotificationConfBySid ( $sid );
  7256. $conf = array ();
  7257. $sendFlag = true;
  7258. if (! empty ( $detail )) {
  7259. $conf = json_decode ( $detail ['conf'], true );
  7260. if (! empty ( $sendType )) {
  7261. if (isset ( $conf [$sendType] )) {
  7262. if ($conf [$sendType] == "CLOSE")
  7263. $sendFlag = false;
  7264. elseif ($conf [$sendType] == "Weekend") {
  7265. $day = date ( "w" );
  7266. if (1 <= $day && 5 >= $day)
  7267. $sendFlag = false;
  7268. } elseif ($conf [$sendType] == "OneToFriday") {
  7269. $day = date ( "w" );
  7270. if (0 == $day || 6 == $day)
  7271. $sendFlag = false;
  7272. }
  7273. }
  7274. } else
  7275. $sendFlag = false;
  7276. }
  7277. return $sendFlag;
  7278. }
  7279. /**
  7280. * 根据规则发送信息
  7281. * @param unknown $msg
  7282. * @param unknown $title
  7283. * @param unknown $url
  7284. * @param unknown $user
  7285. * @param string $text
  7286. * @return number
  7287. */
  7288. private function msgSend($msg, $title, $url, $user, $sid = 0, $sendType = '') {
  7289. $token = $this->getAccessToken ();
  7290. $falg = $this->isSendNotification ( $sid, $sendType );
  7291. // if ($text == 'text') {
  7292. // $data = '{
  7293. // "touser": "' . $user . '",
  7294. // "toparty": "",
  7295. // "totag": "",
  7296. // "msgtype": "text",
  7297. // "agentid": 1000002,
  7298. // "text": {
  7299. // "content": "' . $msg . '"
  7300. // },
  7301. // "safe":0
  7302. // }';
  7303. // } else {
  7304. $data = '{
  7305. "touser": "' . $user . '",
  7306. "toparty": "",
  7307. "totag": "",
  7308. "msgtype": "news",
  7309. "agentid": 1000002,
  7310. "news": {
  7311. "articles":[
  7312. {
  7313. "title": "' . $title . '",
  7314. "description": "' . $msg . '",
  7315. "url": "' . $url . '",
  7316. "picurl": ""
  7317. }
  7318. ]
  7319. }
  7320. }';
  7321. // }
  7322. if ($falg) {
  7323. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  7324. if ($result->errmsg != 'ok') {
  7325. return 0;
  7326. } else {
  7327. return 1;
  7328. }
  7329. } else
  7330. return 0;
  7331. }
  7332. private function getAccessToken() {
  7333. // access_token 应该全局存储与更新,以下代码以写入到文件中做示例
  7334. // $file = './access_token.txt';
  7335. // $data = json_decode ( file_get_contents ( $file ) );
  7336. // if ($data->expire_time < time () or ! $data->expire_time) {
  7337. // 如果是企业号用以下URL获取access_token
  7338. $url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$this->appId&corpsecret=$this->appSecret";
  7339. // $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$this->appId&secret=$this->appSecret";
  7340. $res = json_decode ( $this->httpGet ( $url ) );
  7341. $access_token = $res->access_token;
  7342. // echo $access_token;
  7343. // if ($access_token) {
  7344. // $data->expire_time = time () + 7000;
  7345. // $data->access_token = $access_token;
  7346. // $fp = fopen ( $file, "w" );
  7347. // fwrite ( $fp, json_encode ( $data ) );
  7348. // fclose ( $fp );
  7349. // }
  7350. // } else {
  7351. // $access_token = $data->access_token;
  7352. // }
  7353. return $access_token;
  7354. }
  7355. private function httpGet($url) {
  7356. $curl = curl_init ();
  7357. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  7358. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  7359. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  7360. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  7361. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  7362. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  7363. curl_setopt ( $curl, CURLOPT_URL, $url );
  7364. $res = curl_exec ( $curl );
  7365. curl_close ( $curl );
  7366. return $res;
  7367. }
  7368. private function httpPost($url, $data) {
  7369. $curl = curl_init ();
  7370. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  7371. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  7372. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  7373. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  7374. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  7375. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  7376. curl_setopt ( $curl, CURLOPT_URL, $url );
  7377. curl_setopt ( $curl, CURLOPT_POST, 1 );
  7378. curl_setopt ( $curl, CURLOPT_POSTFIELDS, $data );
  7379. $res = curl_exec ( $curl );
  7380. curl_close ( $curl );
  7381. return $res;
  7382. }
  7383. }
  7384. ?>