InvoiceController.php 315 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586
  1. <?php
  2. /**
  3. * 开票功能控制器
  4. * @author CP
  5. * @version 1.0
  6. * @namespace invoice
  7. * @package invoiceController
  8. */
  9. class InvoiceController extends DooController {
  10. public $staff;
  11. public $NEW;
  12. public $data;
  13. private $INVOICEKEY = "APPROVAL";
  14. private $INVOICECOLLECTPATH = "protected/cache/invoiceCollect/";
  15. private $ACTION = '';
  16. private $appId = 'wx3ee46531947a1384';
  17. private $appSecret = 'awGWzy3J5q_96VXKBLA2BQ9RpiT0LiPXnkMF-xV6h5o'; // awGWzy3J5q_96VXKBLA2BXU6mVCGynPGD-sxUCsdNDE //'PeiQVH8tbQE7pM9pVO4AIPlX9FFNpwu7O6Iy6VFcAVtpjTA3Qn42dbNmktBFkUHo';
  18. public function beforeRun($resource, $action) {
  19. Doo::loadModel ( "invoiceManage" );
  20. $invoiceManage = new invoiceManage ();
  21. Doo::loadClass ( 'XDeode' );
  22. $XDeode = new XDeode ( 5 );
  23. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  24. header ( 'Content-Type:text/html;charset=utf-8' );
  25. $moldList = $invoiceManage->getInvoiceByStaff ( $sid );
  26. if (empty ( $moldList )) {
  27. $flag = false;
  28. $uGroups = 'ordinary';
  29. if (Doo::acl ()->isAllowed ( $uGroups, $resource, $action )) {
  30. $flag = true;
  31. }
  32. } else {
  33. $flag = false;
  34. array_push ( $moldList, array (
  35. 'mold' => 'ordinary'
  36. ) );
  37. // 删除审批人后-加入权限问题-暂时关闭
  38. $fileInvoice = file_get_contents ( "protected/config/invoice/invoice.ini" );
  39. $fiML = json_decode ( $fileInvoice, true );
  40. if (empty ( $fiML ))
  41. $fiML = array ();
  42. foreach ( $fiML as $key => $value ) {
  43. $sidList = explode ( ',', $value );
  44. foreach ( $sidList as $k => $v ) {
  45. if ($v == $sid) {
  46. array_push ( $moldList, array (
  47. 'mold' => $key
  48. ) );
  49. break;
  50. }
  51. }
  52. }
  53. foreach ( $moldList as $value ) {
  54. if (Doo::acl ()->isAllowed ( $value ['mold'], $resource, $action )) {
  55. $flag = true;
  56. break;
  57. }
  58. }
  59. }
  60. /*
  61. * Doo::acl()->isAllowed($uGroups['groups'], $resource, $action);
  62. */
  63. // 单独判断办事处汇总的访问权限 invoiceAggregateCategoryDetail,invoiceAggregateStaffDetail
  64. if ($action == 'invoiceAggregateCategoryDetail' || $action == 'invoiceAggregateStaffDetail') {
  65. Doo::loadModel ( "invoiceCategoryManage" );
  66. $invoiceCategoryManage = new invoiceCategoryManage ();
  67. $icm = $invoiceCategoryManage->getInvoiceCMByStaff ( $sid );
  68. if (empty ( $icm ))
  69. die ( 'illegal request-iacd' );
  70. }
  71. // 单独判断应收款访问权限
  72. if ($action == 'invoiceAggregateCompanyDetail') {
  73. Doo::loadModel ( "invoiceCompanyManage" );
  74. $invoiceCompanyManage = new invoiceCompanyManage ();
  75. $icm = $invoiceCompanyManage->getInvoiceCMByStaff ( $sid );
  76. if (empty ( $icm ))
  77. die ( 'illegal request' );
  78. }
  79. // 主权限获得与判断
  80. Doo::loadModel ( 'staff' );
  81. $staff = new staff ();
  82. $detail = $staff->getStaffBySid ( $_COOKIE ["staff"] );
  83. $accessModular = 'INVOICE';
  84. if (empty ( $detail ['cldAccessArray'] ))
  85. die ( 'illegal request' );
  86. else {
  87. if (in_array ( $accessModular, $detail ['cldAccessArray'] )) {
  88. if (Doo::acl ()->isAllowed ( $accessModular, $resource, $action )) {
  89. $flag = true;
  90. } else {
  91. $flag = false;
  92. }
  93. } else {
  94. die ( 'illegal request' );
  95. }
  96. }
  97. if (! $flag)
  98. die ( 'illegal request' );
  99. }
  100. function __construct() {
  101. if (isset ( $_COOKIE ["staff"] )) {
  102. if (! empty ( $_COOKIE ["staff"] )) {
  103. Doo::loadModel ( 'staff' );
  104. $staff = new staff ();
  105. $uriPartsOrig = explode ( '/', $_SERVER ['REQUEST_URI'] );
  106. $this->ACTION = $uriPartsOrig [1];
  107. $this->data ['new'] = $this->isInvoiceNew ();
  108. $this->staff = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  109. $this->data ['isStaffCompleteMsg'] = false;
  110. $detail = $staff->checkStaffInfoIsComplete ( $_COOKIE ["staff"] );
  111. if (! empty ( $detail ))
  112. $this->data ['isStaffCompleteMsg'] = true;
  113. return "/";
  114. }
  115. }
  116. Doo::loadCore ( 'uri/DooUriRouter' );
  117. $router = new DooUriRouter ();
  118. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  119. if ($routeRs ['1'] != "login") {
  120. header ( 'Content-Type:text/html;charset=utf-8' );
  121. @header ( "Location: /login" );
  122. }
  123. }
  124. function testSend() {
  125. // 测试根据规则发送信息 普通发送
  126. // $pendingApprovalsSid = 41;
  127. // Doo::loadModel ( 'staff' );
  128. // $staff = new staff ();
  129. // $username2 = $staff->getOne ( array ( 'select' => 'wxid', 'where' => 'sid=' . $pendingApprovalsSid, 'asArray' => TRUE ) );
  130. // // 发送微信审批通知
  131. // $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  132. // $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  133. // Doo::loadModel ( 'staff' );
  134. // $staff = new staff ();
  135. // $toparty = $this->getToparty ( '广东办' );
  136. // $wxList = array ();
  137. // if (! empty ( $toparty )) {
  138. // $userList = $this->getUserByToparty ( $toparty );
  139. // $userCon = implode ( ',', $userList );
  140. // // echo $userCon;
  141. // $sidList = $staff->getStaffByWxid ( $userCon );
  142. // foreach ( $sidList as $key => $value ) {
  143. // $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  144. // if ($falg) {
  145. // array_push ( $wxList, $value ['wxid'] );
  146. // }
  147. // }
  148. // $wxString = implode ( '|', $wxList );
  149. // print_r ( $wxList );
  150. // echo $wxString;
  151. // }
  152. // 测试发送
  153. /*
  154. * //$toparty = $this->getWxidByCategory( $receivablesCategory [1] ); $toparty = $this->getToparty ( $receivablesCategory [1] ); $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。'; if ($toparty != 0) $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  155. */
  156. // print_r ( $userList );
  157. // $msTouser='caipin|outaozhen';
  158. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  159. // $title2 = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  160. // $hfreult = $this->msgSend ( '', $title2, '', 'outaozhen' );
  161. // $toparty= $this->getToparty('广东办');
  162. // $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  163. // $toparty = 26;
  164. // $msg = '';
  165. // $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/1.html';
  166. // $hfreult = $this->msgSendToparty ( $msg, '', '', $toparty,'text' );
  167. }
  168. function invoice() {
  169. Doo::loadModel ( 'invoice' );
  170. $invoice = new invoice ();
  171. Doo::loadModel ( 'express' );
  172. $express = new express ();
  173. $expressList = $express->getExpressByAll ();
  174. $this->data ['expressList'] = $expressList;
  175. // Doo::loadModel ( 'invoiceReceivables' );
  176. // $invoiceReceivables = new invoiceReceivables ();
  177. // $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  178. Doo::loadClass ( 'XDeode' );
  179. $XDeode = new XDeode ( 5 );
  180. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  181. Doo::loadModel ( 'invoiceStatistics' );
  182. $invoiceStatistics = new invoiceStatistics ();
  183. $isMonth = $invoiceStatistics->getStatisticsByMonth ( $sid );
  184. // 缓存统计结果
  185. $year = date ( "Y" );
  186. $tmp_date = date ( "Ym" );
  187. $tmp_year = substr ( $tmp_date, 0, 4 );
  188. $tmp_mon = substr ( $tmp_date, 4, 2 );
  189. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  190. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  191. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . "_" . $sid . ".htm";
  192. if (is_file ( $path ))
  193. $htm = file_get_contents ( $path );
  194. else
  195. $htm = $this->showCache ( $path, $sid );
  196. $invoiceList = $invoice->getMyInvoice ( $sid );
  197. $sql = 'status=2 and printStatus=1 and irid!="" and sid=' . $sid;
  198. $list = $invoice->getInvoiceByUntreadStatusPage ( 4, $sql );
  199. // 我的待入账发票 and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  200. $sql = "status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid=" . $sid;
  201. $myInvoiceUnAccount = $invoice->getInvoiceByUntreadStatusPage ( 4, $sql );
  202. // 获得已退票功能
  203. $untreadStatusList = $invoice->getMyInvoiceByUntreadStatus ( 2, 0, 5, $sid );
  204. $this->data ['untreadStatusList'] = $untreadStatusList;
  205. // print_r($untreadStatusList);
  206. $this->data ['isMonth'] = $isMonth;
  207. $this->data ['htm'] = $htm;
  208. $this->data ['invoiceList'] = $invoiceList;
  209. $this->data ['receivablesList'] = $list;
  210. $this->data ['myInvoiceUnAccount'] = $myInvoiceUnAccount;
  211. $this->data ['memu'] = "invoice";
  212. $this->data ['staff'] = $this->staff;
  213. $this->data ['receiptMemu'] = 'invoice';
  214. $this->render ( "/admin/invoice", $this->data );
  215. }
  216. function invoiceExpress() {
  217. $expressCom = isset ( $this->params ['expressCom'] ) ? $this->params ['expressCom'] : "";
  218. $expressNumber = isset ( $this->params ['expressNumber'] ) ? $this->params ['expressNumber'] : "";
  219. $this->data ['expressCom'] = $expressCom;
  220. $this->data ['expressNumber'] = $expressNumber;
  221. $this->render ( "/admin/invoiceExpress", $this->data );
  222. }
  223. function invoiceAdd() {
  224. session_start ();
  225. /*Doo::loadModel ( 'invoice' );
  226. $invoice = new invoice ();
  227. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );*/
  228. Doo::loadModel ( 'L_category' );
  229. $lCategory = new L_category ();
  230. $category = $lCategory->find ( array (
  231. 'asArray' => true
  232. ) );
  233. $this->data ['category'] = $category;
  234. Doo::loadModel ( 'invoiceTraining' );
  235. $invoiceTraining = new invoiceTraining ();
  236. $itList = $invoiceTraining->getInvoiceTrainingByCid ( $this->staff [0] ['cid'] );
  237. Doo::loadModel ( 'receipt' );
  238. $receipt = new receipt ();
  239. foreach ( $itList as $key => $value ) { // 不展示已结算完结的培训班
  240. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $value ['itid'] );
  241. if (! empty ( $receiptDetail )) {
  242. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9) {
  243. unset ( $itList [$key] );
  244. }
  245. }
  246. }
  247. $this->data ['itList'] = $itList;
  248. $token = $this->set_token ();
  249. $tokenTime=time().rand(5, 15);
  250. $_SESSION ['token_' . $this->staff [0] ['sidKey'].'_'.$tokenTime] = $token;
  251. $this->data ['token'] = $token;
  252. $this->data['tokenTime']=$tokenTime;
  253. $this->data ['memu'] = "invoice";
  254. $this->data ['staff'] = $this->staff;
  255. $this->data ['receiptMemu'] = 'invoice';
  256. $this->render ( "/admin/invoiceAdd", $this->data );
  257. }
  258. /**
  259. * 自更新发票信息库
  260. * @param unknown $invoicePrintDetail
  261. */
  262. function autoUpdateInvoiceInfoBase($invoicePrintDetail) {
  263. // 发票信息库
  264. Doo::loadModel ( 'invoiceInfoBase' );
  265. $invoiceInfoBase = new invoiceInfoBase ();
  266. $updateDate = strtotime ( $invoicePrintDetail ['date'] );
  267. $TIN = $invoicePrintDetail ['TIN'];
  268. $invoiceTitle = $invoicePrintDetail ['invoiceTitle'];
  269. if (empty ( $invoiceTitle ))
  270. $invoiceTitle = $invoicePrintDetail ['invoiceCompany'];
  271. $IIBList = $invoiceInfoBase->getInvoiceInfoByTT ( $TIN, $invoiceTitle );
  272. // 确认有该条发票信息
  273. $invoiceInfoBase = new invoiceInfoBase ();
  274. if (! empty ( $IIBList )) {
  275. // 发票库里的信息数量
  276. $IIBListCount = count ( $IIBList );
  277. if ($IIBListCount == 1) { // 更新发票--提交是最新的时间
  278. $item = array (
  279. 'iibID' => $IIBList [0] ['iibID'],
  280. 'invoiceTitle' => $invoiceTitle,
  281. 'TIN' => $TIN
  282. );
  283. if (! empty ( $invoicePrintDetail ['address'] )) {
  284. $item += array (
  285. 'address' => $invoicePrintDetail ['address']
  286. );
  287. }
  288. if (! empty ( $invoicePrintDetail ['phone'] )) {
  289. $item += array (
  290. 'phone' => $invoicePrintDetail ['phone']
  291. );
  292. }
  293. if (! empty ( $invoicePrintDetail ['bank'] )) {
  294. $item += array (
  295. 'bank' => $invoicePrintDetail ['bank']
  296. );
  297. }
  298. if (! empty ( $invoicePrintDetail ['bankAccount'] )) {
  299. $item += array (
  300. 'bankAccount' => $invoicePrintDetail ['bankAccount']
  301. );
  302. }
  303. if ($updateDate >= strtotime ($IIBList [0] ['updateDate'])) {
  304. $item += array (
  305. 'updateDate' => $invoicePrintDetail ['date']
  306. );
  307. $invoiceInfoBase->setInvoiceInfoBaseByCondition ( $item );
  308. }
  309. } else { // 删除多张发票,重新添加发票
  310. $iibIDStr = '';
  311. $iibID = array ();
  312. foreach ( $IIBList as $key => $value ) {
  313. array_push ( $iibID, $value ['iibID'] );
  314. }
  315. $iibIDStr = implode ( ",", $iibID ); // 删除
  316. $invoiceInfoBase->delInvoiceInfoBaseByIibStr ( $iibIDStr );
  317. $item = array (
  318. 'invoiceTitle' => $invoiceTitle,
  319. 'TIN' => $TIN,
  320. 'address' => $invoicePrintDetail ['address'],
  321. 'phone' => $invoicePrintDetail ['phone'],
  322. 'bank' => $invoicePrintDetail ['bank'],
  323. 'bankAccount' => $invoicePrintDetail ['bankAccount'],
  324. 'updateDate' => $invoicePrintDetail ['date']
  325. );
  326. $invoiceInfoBase->addInvoiceInfoBase ( $item );
  327. }
  328. } else { // 没有新增发票信息
  329. $item = array (
  330. 'invoiceTitle' => $invoiceTitle,
  331. 'TIN' => $TIN,
  332. 'address' => $invoicePrintDetail ['address'],
  333. 'phone' => $invoicePrintDetail ['phone'],
  334. 'bank' => $invoicePrintDetail ['bank'],
  335. 'bankAccount' => $invoicePrintDetail ['bankAccount'],
  336. 'updateDate' => $invoicePrintDetail ['date']
  337. );
  338. $invoiceInfoBase->addInvoiceInfoBase ( $item );
  339. }
  340. }
  341. function invoiceAddFill() {
  342. session_start ();
  343. Doo::loadModel ( 'L_category' );
  344. $lCategory = new L_category ();
  345. $category = $lCategory->find ( array (
  346. 'asArray' => true
  347. ) );
  348. $this->data ['category'] = $category;
  349. Doo::loadModel ( 'invoiceTraining' );
  350. $invoiceTraining = new invoiceTraining ();
  351. $itList = $invoiceTraining->getInvoiceTrainingByCid ( $this->staff [0] ['cid'] );
  352. $this->data ['itList'] = $itList;
  353. Doo::loadModel ( 'invoice' );
  354. $invoice = new invoice ();
  355. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );
  356. $detail ['mailItemsArray'] = json_decode ( $detail ['mailItemsJson'], true );
  357. $token = $this->set_token ();
  358. $tokenTime=time().rand(5, 15);
  359. $_SESSION ['token_' . $this->staff [0] ['sidKey'].'_'.$tokenTime] = $token;
  360. $this->data ['token'] = $token;
  361. $this->data['tokenTime']=$tokenTime;
  362. $this->data ['invoiceDetail'] = $detail;
  363. $this->data ['memu'] = "invoice";
  364. $this->data ['staff'] = $this->staff;
  365. $this->data ['receiptMemu'] = 'invoice';
  366. $this->render ( "/admin/invoiceAddFill", $this->data );
  367. }
  368. /**
  369. * 提交一份开票申请,并记录下操作日志
  370. *
  371. * @since 1.0.0
  372. * @var integer cid 办事处ID
  373. * @var integer invoiceType 发票类型
  374. * @var integer doPost 是否邮寄
  375. * @var integer invoicePrice 开票金额
  376. * @var string invoiceElement 开票内容
  377. * @var string invoiceTitle 发票抬头
  378. * @var string invoiceCompany 单位名称
  379. * @var string TIN 纳税人识别码
  380. * @var string address 注册地址
  381. * @var string phone 注册电话
  382. * @var string bank 开户银行
  383. * @var string bankAccount 银行账户
  384. * @var string recipients 收件人
  385. * @var string recipientsPhone 收件人手机/电话
  386. * @var string recipientsAddress 收件地址
  387. * @var string mailItems 邮寄物品
  388. * @var string remark 备注
  389. * @return string 返回跳转开票主页路径
  390. */
  391. function invoiceAddDo() {
  392. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  393. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  394. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  395. // $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  396. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  397. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  398. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  399. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  400. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  401. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  402. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  403. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  404. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  405. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  406. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  407. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  408. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  409. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  410. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  411. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  412. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  413. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  414. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  415. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  416. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  417. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  418. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  419. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  420. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  421. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  422. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  423. $trainId = $this->get_args ( 'trainId' ) ? $this->get_args ( 'trainId' ) : 0;
  424. $settlementType = $this->get_args ( 'settlementType' ) ? $this->get_args ( 'settlementType' ) : "";
  425. /*
  426. * $mailList=array(); array_push($mailList, array('invoice'=>1)); array_push($mailList, array('mailItems'=>$mailItems)); if (!empty($softLock)) array_push($mailList, array('softLock'=>$softLockNum)); if (!empty($contract)) array_push($mailList, array('contract'=>$contractNum)); if (!empty($instructions)) array_push($mailList, array('instructions'=>$instructionsNum)); if (!empty($remittance)) array_push($mailList, array('remittance'=>$remittance)); echo json_encode($mailList) ; print_r($mailList); die;
  427. */
  428. $token = $this->get_args ( 'token' ) ? $this->get_args ( 'token' ) : "";
  429. $tokenTime = $this->get_args ( 'tokenTime' ) ? $this->get_args ( 'tokenTime' ) : "";
  430. if (empty ( $token )) {
  431. die ( 'illegal request-token' );
  432. } else {
  433. session_start ();
  434. $sessionKey='token_' . $this->staff [0] ['sidKey'].'_'.$tokenTime;
  435. header ( 'Content-Type:text/html;charset=utf-8' );
  436. if (!isset($_SESSION [$sessionKey])||empty($_SESSION [$sessionKey])) {
  437. die ( '请重新刷新发票申请页面' );
  438. }elseif($_SESSION [$sessionKey]=='repeat'){
  439. die ( '请勿重复申请发票' );
  440. } else {
  441. if ($_SESSION [$sessionKey] != $token){
  442. die ( '请勿重复申请发票' );
  443. }else{
  444. $_SESSION [$sessionKey] = 'repeat';
  445. }
  446. }
  447. }
  448. if ($invoiceType == 1) {
  449. $temporary = $invoiceQuantity * $invoiceUnitPrice;
  450. if ($temporary > 100001) {
  451. header ( 'Content-Type:text/html;charset=utf-8' );
  452. die ( '专用发票总金额暂时不能超过100000.00(一万)元。' );
  453. // die ( 'illegal request-Please priceError' );
  454. }
  455. }
  456. if (empty ( $this->staff [0] ))
  457. die ( 'illegal request-Please login' );
  458. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $settlementType )) {
  459. Doo::loadModel ( 'invoice' );
  460. $invoice = new invoice ();
  461. Doo::loadModel ( 'L_category' );
  462. $lCategory = new L_category ();
  463. Doo::loadModel ( 'invoiceManage' );
  464. $invoiceManage = new invoiceManage ();
  465. Doo::loadModel ( 'invoiceOperationLog' );
  466. $invoiceOperationLog = new invoiceOperationLog ();
  467. Doo::loadClass ( 'XDeode' );
  468. $XDeode = new XDeode ( 5 );
  469. $trainId = $XDeode->decode ( $trainId );
  470. $categoryDetil = $lCategory->getOne ( array (
  471. 'SELECT' => 'title',
  472. 'where' => 'cid=' . $cid,
  473. 'asArray' => true
  474. ) );
  475. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  476. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  477. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  478. // print_r(current($invoiceManageDetail ['staffList']));
  479. // die;
  480. $moldManage = array ();
  481. foreach ( $invoiceManageList as $key => $value ) {
  482. if ($value ['mold'] == '发票打印')
  483. $moldManage [$value ['mold']] = $value ['staffList'];
  484. elseif ($value ['mold'] == '发票邮寄')
  485. $moldManage [$value ['mold']] = $value ['staffList'];
  486. elseif ($value ['mold'] == '发票退票')
  487. $moldManage [$value ['mold']] = $value ['staffList'];
  488. }
  489. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  490. $st = '';
  491. if ($settlementType == 'SOFTWARE') {
  492. $st = 0;
  493. $trainId = 0;
  494. } elseif ($settlementType == 'TRAINING') {
  495. $st = 1;
  496. if (empty ( $trainId ) && ! is_numeric ( $trainId )) {
  497. die ( 'illegal request-trainingIdError' );
  498. }
  499. } else {
  500. die ( 'illegal request-settlementError' );
  501. }
  502. $item = array (
  503. 'cid' => $cid,
  504. 'categoryName' => $categoryDetil ['title'],
  505. 'invoiceElement' => $invoiceElement,
  506. 'invoiceQuantity' => $invoiceQuantity,
  507. 'invoiceUnitPrice' => $invoiceUnitPrice,
  508. 'invoicePrice' => $invoicePrice,
  509. 'invoiceType' => $invoiceType,
  510. 'settlementType' => $st,
  511. 'doPost' => $doPost,
  512. 'status' => 1,
  513. 'invoiceSerial' => "#F" . date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT),
  514. 'date' => date ( "Y-m-d H:i:s" ),
  515. 'updateTime' => date ( "Y-m-d H:i:s" ),
  516. 'sid' => $this->staff [0] ['sid'],
  517. 'userName' => $this->staff [0] ['username'],
  518. 'invoiceManage' => $invoiceManageDetail ['staff'],
  519. 'pendingApprovals' => $pendingApprovalsSid,
  520. 'moldManage' => json_encode ( $moldManage ),
  521. 'remark' => $remark,
  522. 'trainId' => $trainId
  523. );
  524. if ($invoiceType == 0)
  525. $item += array (
  526. 'invoiceTitle' => $invoiceTitle,
  527. 'TIN' => $TINT,
  528. 'address' => $addressT,
  529. 'phone' => $phoneT,
  530. 'bank' => $bankT,
  531. 'bankAccount' => $bankAccountT
  532. );
  533. else {
  534. $item += array (
  535. 'invoiceCompany' => $invoiceCompany,
  536. 'TIN' => $TIN,
  537. 'address' => $address,
  538. 'phone' => $phone,
  539. 'bank' => $bank,
  540. 'bankAccount' => $bankAccount
  541. );
  542. }
  543. if ($doPost == 1) {
  544. $mailList = array (
  545. 'invoice' => 1,
  546. 'mailItems' => $mailItems
  547. );
  548. if (! empty ( $softLock ))
  549. $mailList += array (
  550. 'softLock' => $softLockNum
  551. );
  552. else
  553. $mailList += array (
  554. 'softLock' => 0
  555. );
  556. if (! empty ( $contract ))
  557. $mailList += array (
  558. 'contract' => $contractNum
  559. );
  560. else
  561. $mailList += array (
  562. 'contract' => 0
  563. );
  564. if (! empty ( $instructions ))
  565. $mailList += array (
  566. 'instructions' => $instructionsNum
  567. );
  568. else
  569. $mailList += array (
  570. 'instructions' => 0
  571. );
  572. if (! empty ( $remittance ))
  573. $mailList += array (
  574. 'remittance' => $remittance
  575. );
  576. else
  577. $mailList += array (
  578. 'remittance' => ''
  579. );
  580. $mailString = '发票x1张,备注:' . $mailItems;
  581. if (! empty ( $softLock ))
  582. $mailString .= ',软件锁x' . $softLockNum . '个';
  583. if (! empty ( $contract ))
  584. $mailString .= ',合同x' . $contractNum . '份';
  585. if (! empty ( $instructions ))
  586. $mailString .= ',说明书x' . $instructionsNum . '本';
  587. if (! empty ( $remittance ))
  588. $mailString .= ',汇款账号单(张)';
  589. $item += array (
  590. 'recipients' => $recipients,
  591. 'recipientsPhone' => $recipientsPhone,
  592. 'recipientsAddress' => $recipientsAddress,
  593. 'mailItems' => $mailString,
  594. 'mailItemsJson' => json_encode ( $mailList )
  595. );
  596. }
  597. $iid = $invoice->addInvoice ( $item );
  598. // 如果是培训班结算 创建培训班发票到培训班备份中
  599. if (! empty ( $st ) && $st == 1) {
  600. Doo::loadModel ( 'invoiceStore' );
  601. $invoiceStore = new invoiceStore ();
  602. Doo::loadModel ( 'invoiceTraining' );
  603. $invoiceTraining = new invoiceTraining ();
  604. $isid = $invoiceStore->setInvoiceToInvoiceStore ( $iid );
  605. $itemIS = array (
  606. 'isid' => $isid,
  607. 'ipSource' => 1,
  608. 'apStatus' => 1,
  609. 'iid' => $iid
  610. );
  611. $invoiceStore->setInvoiceStoreByCondition ( $itemIS );
  612. // 更新培训班总数量
  613. $detailIT = $invoiceTraining->getInvoiceTrainingByItid ( $trainId );
  614. $item = array (
  615. 'itid' => $trainId,
  616. 'invoiceTotal' => $detailIT ['invoiceTotal'] + 1,
  617. 'submitStatus' => 1
  618. );
  619. $itid = $invoiceTraining->setInvoiceTrainByCondition ( $item );
  620. }
  621. // 操作日志
  622. $item = array (
  623. 'date' => date ( "Y-m-d H:i:s" ),
  624. 'operation' => "创建",
  625. 'status' => 1,
  626. 'img' => $this->staff [0] ['avatar'],
  627. 'username' => $this->staff [0] ['username'],
  628. 'uid' => $this->staff [0] ['sid'],
  629. 'category' => $this->staff [0] ['category'],
  630. 'iid' => $iid
  631. );
  632. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  633. $item = array (
  634. 'date' => date ( "Y-m-d H:i:s" ),
  635. 'operation' => "提交审批",
  636. 'status' => 1,
  637. 'img' => $this->staff [0] ['avatar'],
  638. 'username' => $this->staff [0] ['username'],
  639. 'uid' => $this->staff [0] ['sid'],
  640. 'category' => $this->staff [0] ['category'],
  641. 'iid' => $iid
  642. );
  643. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  644. Doo::loadModel ( 'staff' );
  645. $staff = new staff ();
  646. $username2 = $staff->getOne ( array (
  647. 'select' => 'wxid',
  648. 'where' => 'sid=' . $pendingApprovalsSid,
  649. 'asArray' => TRUE
  650. ) );
  651. // 发送微信审批通知
  652. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  653. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  654. }
  655. return "/invoice";
  656. }
  657. function invoiceEdit() {
  658. Doo::loadClass ( 'XDeode' );
  659. $XDeode = new XDeode ( 5 );
  660. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  661. $iid = $XDeode->decode ( $iid );
  662. if (! is_numeric ( $iid ))
  663. die ( 'illegal request' );
  664. Doo::loadModel ( 'invoice' );
  665. $invoice = new invoice ();
  666. Doo::loadModel ( 'invoiceOperationLog' );
  667. $invoiceOperationLog = new invoiceOperationLog ();
  668. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  669. $operation = $invoiceOperationLog->getInvoiceOperationByDropped ( $iid );
  670. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  671. $this->data ['operation'] = $operation;
  672. $this->data ['invoiceDetail'] = $invoiceDetail;
  673. $this->data ['memu'] = "invoice";
  674. $this->data ['staff'] = $this->staff;
  675. $this->data ['receiptMemu'] = 'invoice';
  676. $this->render ( "/admin/invoiceEdit", $this->data );
  677. }
  678. /**
  679. * 重新编辑退回的发票
  680. * @return string
  681. */
  682. function invoiceEditDo() {
  683. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  684. Doo::loadModel ( 'invoice' );
  685. $invoice = new invoice ();
  686. $iid = $invoice->authcode ( $iidKey );
  687. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  688. die ( 'illegal request' );
  689. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  690. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  691. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  692. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  693. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  694. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  695. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  696. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  697. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  698. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  699. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  700. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  701. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  702. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  703. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  704. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  705. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  706. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  707. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  708. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  709. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  710. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  711. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  712. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  713. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  714. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  715. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  716. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  717. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  718. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  719. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  720. if ($invoiceType == 1) {
  721. $temporary = $invoiceQuantity * $invoiceUnitPrice;
  722. if ($temporary > 100001)
  723. die ( 'illegal request-Please priceError' );
  724. }
  725. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  726. Doo::loadModel ( 'invoiceManage' );
  727. $invoiceManage = new invoiceManage ();
  728. Doo::loadModel ( 'invoiceOperationLog' );
  729. $invoiceOperationLog = new invoiceOperationLog ();
  730. Doo::loadModel ( 'invoiceStore' );
  731. $invoiceStore = new invoiceStore ();
  732. $cid = explode ( ':', $cid );
  733. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  734. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  735. $moldManage = array ();
  736. foreach ( $invoiceManageList as $key => $value ) {
  737. if ($value ['mold'] == '发票打印')
  738. $moldManage [$value ['mold']] = $value ['staffList'];
  739. elseif ($value ['mold'] == '发票邮寄')
  740. $moldManage [$value ['mold']] = $value ['staffList'];
  741. elseif ($value ['mold'] == '发票打印')
  742. $moldManage [$value ['mold']] = $value ['staffList'];
  743. }
  744. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  745. $item = array (
  746. 'iid' => $iid,
  747. 'cid' => $cid [0],
  748. 'categoryName' => $cid [1],
  749. 'invoiceElement' => $invoiceElement,
  750. 'invoiceQuantity' => $invoiceQuantity,
  751. 'invoiceUnitPrice' => $invoiceUnitPrice,
  752. 'invoicePrice' => $invoicePrice,
  753. 'invoiceType' => $invoiceType,
  754. 'doPost' => $doPost,
  755. 'status' => 1,
  756. 'updateTime' => date ( "Y-m-d H:i:s" ),
  757. 'remark' => $remark
  758. );
  759. if ($invoiceType == 0)
  760. $item += array (
  761. 'invoiceTitle' => $invoiceTitle,
  762. 'TIN' => $TINT,
  763. 'address' => $addressT,
  764. 'phone' => $phoneT,
  765. 'bank' => $bankT,
  766. 'bankAccount' => $bankAccountT
  767. );
  768. else {
  769. $item += array (
  770. 'invoiceCompany' => $invoiceCompany,
  771. 'TIN' => $TIN,
  772. 'address' => $address,
  773. 'phone' => $phone,
  774. 'bank' => $bank,
  775. 'bankAccount' => $bankAccount
  776. );
  777. }
  778. if ($doPost == 1) {
  779. $mailList = array (
  780. 'invoice' => 1,
  781. 'mailItems' => $mailItems
  782. );
  783. if (! empty ( $softLock ))
  784. $mailList += array (
  785. 'softLock' => $softLockNum
  786. );
  787. else
  788. $mailList += array (
  789. 'softLock' => '0'
  790. );
  791. if (! empty ( $contract ))
  792. $mailList += array (
  793. 'contract' => $contractNum
  794. );
  795. else
  796. $mailList += array (
  797. 'contract' => '0'
  798. );
  799. if (! empty ( $instructions ))
  800. $mailList += array (
  801. 'instructions' => $instructionsNum
  802. );
  803. else
  804. $mailList += array (
  805. 'instructions' => '0'
  806. );
  807. if (! empty ( $remittance ))
  808. $mailList += array (
  809. 'remittance' => $remittance
  810. );
  811. else
  812. $mailList += array (
  813. 'remittance' => ''
  814. );
  815. $mailString = '发票x1,备注:' . $mailItems;
  816. if (! empty ( $softLock ))
  817. $mailString .= ',软件锁x' . $softLockNum;
  818. if (! empty ( $contract ))
  819. $mailString .= ',合同x' . $contractNum;
  820. if (! empty ( $instructions ))
  821. $mailString .= ',说明书x' . $instructionsNum;
  822. if (! empty ( $remittance ))
  823. $mailString .= ',汇款账号单';
  824. $item += array (
  825. 'recipients' => $recipients,
  826. 'recipientsPhone' => $recipientsPhone,
  827. 'recipientsAddress' => $recipientsAddress,
  828. 'mailItems' => $mailString,
  829. 'mailItemsJson' => json_encode ( $mailList )
  830. );
  831. }
  832. $invoice->setInvoiceByCondition ( $item );
  833. // 更新培训班仓库里的发票
  834. $detail = $invoice->getInvoiceByIid ( $iid );
  835. if (! empty ( $detail ['isid'] )) {
  836. $invoiceStore->isid = $detail ['isid'];
  837. $invoiceStore->invoiceQuantity = $invoiceQuantity;
  838. $invoiceStore->invoiceUnitPrice = $invoiceUnitPrice;
  839. $invoiceStore->invoicePrice = $invoicePrice;
  840. $invoiceStore->update ();
  841. }
  842. $item = array (
  843. 'date' => date ( "Y-m-d H:i:s" ),
  844. 'operation' => "重新提交审批",
  845. 'status' => 1,
  846. 'img' => $this->staff [0] ['avatar'],
  847. 'username' => $this->staff [0] ['username'],
  848. 'uid' => $this->staff [0] ['sid'],
  849. 'category' => $this->staff [0] ['category'],
  850. 'iid' => $iid
  851. );
  852. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  853. }
  854. return "/invoice";
  855. }
  856. /**
  857. * 培训班
  858. */
  859. function invoiceTraining() {
  860. Doo::loadModel ( 'L_category' );
  861. $lCategory = new L_category ();
  862. Doo::loadModel ( 'invoiceTraining' );
  863. $invoiceTraining = new invoiceTraining ();
  864. Doo::loadModel ( 'invoiceTrainManage' );
  865. $invoiceTrainManage = new invoiceTrainManage ();
  866. $imcStaff = $invoiceTrainManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  867. $cidList = array ();
  868. foreach ( $imcStaff as $key => $value ) {
  869. array_push ( $cidList, $value ['cid'] );
  870. }
  871. if (empty ( $cidList )) {
  872. $cidString = $this->staff [0] ['cid'];
  873. } else {
  874. $cidString = implode ( ',', $cidList );
  875. $cidString .= $cidString . ',' . $this->staff [0] ['cid'];
  876. }
  877. $itTodoList = $invoiceTraining->getInvoiceTrainingByTodo ( '', $cidString, $this->staff [0] ['sid'] );
  878. $itedList = $invoiceTraining->getInvoiceTrainingByStatus ( 2, '', $cidString, $this->staff [0] ['sid'] );
  879. $category = $lCategory->getCategory ();
  880. $itid = array ();
  881. foreach ( $itTodoList as $key => $value ) {
  882. array_push ( $itid, $value ['itid'] );
  883. // 如果入账100%更新为已完成
  884. if ($itTodoList [$key] ['arriveSchedule'] >= 100) {
  885. $invoiceTraining = new invoiceTraining ();
  886. $invoiceTraining->itid = $value ['itid'];
  887. $invoiceTraining->status = 2;
  888. $invoiceTraining->update ();
  889. }
  890. }
  891. foreach ( $itedList as $value ) {
  892. array_push ( $itid, $value ['itid'] );
  893. }
  894. $itid = implode ( ',', $itid );
  895. $this->data ['itStatist'] = $invoiceTraining->getInvoiceTrainStatistics ( $itid );
  896. // print_r($itTodoList);
  897. $this->data ['trainCount'] = count ( $itTodoList ) + count ( $itedList );
  898. $this->data ['itTodoList'] = $itTodoList;
  899. $this->data ['itedList'] = $itedList;
  900. $this->data ['category'] = $category;
  901. $this->data ['memu'] = "invoice";
  902. $this->data ['staff'] = $this->staff;
  903. $this->data ['receiptMemu'] = 'invoiceTraining';
  904. $this->render ( "/admin/invoiceTraining", $this->data );
  905. }
  906. /**
  907. * 创建培训班
  908. */
  909. function invoiceTrainingAdd() {
  910. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  911. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  912. $trainDate = $this->get_args ( 'trainDate' ) ? $this->get_args ( 'trainDate' ) : "";
  913. if (empty ( $this->staff [0] ))
  914. die ( 'illegal request' );
  915. if (! empty ( $cid ) && ! empty ( $trainName ) && ! empty ( $trainDate )) {
  916. Doo::loadModel ( 'invoiceTraining' );
  917. $invoiceTraining = new invoiceTraining ();
  918. Doo::loadModel ( 'invoice' );
  919. $invoice = new invoice ();
  920. Doo::loadModel ( 'L_category' );
  921. $lCategory = new L_category ();
  922. Doo::loadModel ( 'invoiceManage' );
  923. $invoiceManage = new invoiceManage ();
  924. Doo::loadModel ( 'invoiceOperationLog' );
  925. $invoiceOperationLog = new invoiceOperationLog ();
  926. $item = array (
  927. 'cid' => $cid,
  928. 'trainName' => $trainName,
  929. 'trainDate' => $trainDate,
  930. 'creator' => $this->staff [0] ['sid'],
  931. 'creatorDate' => date ( "Y-m-d H:i:s" )
  932. );
  933. $itid = $invoiceTraining->addInvoiceTraining ( $item );
  934. }
  935. return "/invoiceTraining";
  936. }
  937. /**
  938. * 删除培训班
  939. */
  940. function invoiceTrainingDelDo() {
  941. $itid = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  942. if (! empty ( $itid )) {
  943. Doo::loadModel ( 'invoiceTraining' );
  944. $invoiceTraining = new invoiceTraining ();
  945. $invoiceTraining->delInvoiceTrainingByItid ( $itid );
  946. }
  947. return "/invoiceTraining";
  948. }
  949. /**
  950. * 培训班详情
  951. */
  952. function invoiceTrainingDetail() {
  953. $trainStatus = $this->get_args ( 'trainStatus' ) ? $this->get_args ( 'trainStatus' ) : "ALL";
  954. $itid = isset ( $this->params ['trainingKey'] ) ? $this->params ['trainingKey'] : "";
  955. Doo::loadModel ( 'invoiceTraining' );
  956. $invoiceTraining = new invoiceTraining ();
  957. Doo::loadModel ( 'invoiceStore' );
  958. $invoiceStore = new invoiceStore ();
  959. if (empty ( $itid ))
  960. die ( 'illegal request' );
  961. $con = ' (b.untreadStatus is null or b.untreadStatus!=2) and ';
  962. if ($trainStatus == "SUBED")
  963. $con = ' (b.untreadStatus is null ) and ';
  964. elseif ($trainStatus == "APPROVAL")
  965. $con = ' ( b.status=1 and b.untreadStatus!=2 ) and ';
  966. elseif ($trainStatus == "TICKET")
  967. $con = ' (b.printStatus=1 and b.status=2 and b.untreadStatus!=2) and ';
  968. elseif ($trainStatus == "TICKETING") {
  969. $con = ' (b.status=2 and b.untreadStatus=1) and ';
  970. }
  971. $detail = $invoiceTraining->getInvoiceTrainingByItid ( $itid );
  972. $isList = $invoiceStore->getinvoiceStoreByItid ( $itid, $con );
  973. //print_r($isList);
  974. $trainlist = array ();
  975. foreach ( $isList as $key => $value ) {
  976. $irDetail = array ();
  977. if ($value ['apStatus'] == 1) {
  978. // array_push ( $irDetail, '' );
  979. array_push ( $irDetail, '<input disabled type="checkbox" style="display:none" >' );
  980. } else {
  981. array_push ( $irDetail, '<input type="checkbox" class="hide" id="' . $value ['storeKey'] . '" name="isBox" value="' . $value ['storeKey'] . '" > <a href="/invoiceStoreEdit/' . $value ['storeKey'] . '.html">编辑</a>
  982. <a href="#confirm" onclick="invoiceStoreApproval(\'' . $value ['storeKey'] . '\')" data-toggle="modal">提交审批</a>
  983. <a href="#del" node-iStore="del" data-key="' . $value ['storeKey'] . '" onclick="invoiceStoreDel(\'' . $value ['storeKey'] . '\')" data-toggle="modal" class="colRed">移除</a>' );
  984. }
  985. array_push ( $irDetail, $value ['invoiceSerial'] );
  986. if ($value ['invoiceType'] == 1)
  987. array_push ( $irDetail, $value ['invoiceCompany'] );
  988. else
  989. array_push ( $irDetail, $value ['invoiceTitle'] );
  990. array_push ( $irDetail, $value ['TIN'] );
  991. array_push ( $irDetail, $value ['userName'] );
  992. if (empty ( $value ['mailItems'] ) && $value ['apStatus'] != 1) {
  993. array_push ( $irDetail, '<a href="#confirm-erro" onclick="invoiceStoreMail(\'' . $value ['storeKey'] . '\')" data-toggle="modal">设置邮寄物品</a>' );
  994. } else
  995. array_push ( $irDetail, $value ['mailItems'] );
  996. array_push ( $irDetail, $value ['recipientsAddress'] . $value ['recipients'] . $value ['recipientsPhone'] );
  997. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  998. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  999. array_push ( $irDetail, $value ['invoiceElement'] );
  1000. array_push ( $irDetail, $value ['invoiceQuantity'] );
  1001. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  1002. if ($value ['invoiceType'] == 1)
  1003. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  1004. else
  1005. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  1006. array_push ( $irDetail, $value ['remark'] );
  1007. if ($value ['status'] == 1)
  1008. array_push ( $irDetail, '审批中' );
  1009. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1)
  1010. array_push ( $irDetail, '已出票' );
  1011. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1 && $value ['printStatus'] != 'irid' && ($value ['untreadStatus'] == 3 || $value ['untreadStatus'] == 0))
  1012. array_push ( $irDetail, '已入账' );
  1013. else
  1014. array_push ( $irDetail, '' );
  1015. array_push ( $irDetail, $value ['invoiceNo'] );
  1016. array_push ( $irDetail, $value ['printTime'] );
  1017. $html = '';
  1018. foreach ( $value ['invoiceReceivables'] as $value ) {
  1019. $html .= '&nbsp;<a href="#billing" node-invoice="INFO" data-type="receivables" data-iskey="' . $value [2] . '" data-toggle="modal">' . $value [1] . '</a>';
  1020. }
  1021. array_push ( $irDetail, $html );
  1022. array_push ( $trainlist, $irDetail );
  1023. }
  1024. $trainlistJson = json_encode ( $trainlist );
  1025. if (empty ( $detail ))
  1026. die ( 'illegal request' );
  1027. // 培训班结算是否有和是否已经结算完成
  1028. Doo::loadModel ( 'receipt' );
  1029. $receipt = new receipt ();
  1030. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $itid );
  1031. $this->data ['receiptDetail'] = $receiptDetail;
  1032. $this->data ['trainStatus'] = $trainStatus;
  1033. $this->data ['itid'] = $itid;
  1034. $this->data ['trainlistJson'] = $trainlistJson;
  1035. $this->data ['iTrainDetail'] = $detail;
  1036. $this->data ['memu'] = "invoice";
  1037. $this->data ['staff'] = $this->staff;
  1038. $this->data ['receiptMemu'] = 'invoiceTraining';
  1039. $this->render ( "/admin/invoiceTrainingDetail", $this->data );
  1040. }
  1041. /**
  1042. * 上传培训班发票
  1043. * @return string
  1044. */
  1045. function invoiceTrainingUpload() {
  1046. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  1047. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  1048. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  1049. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  1050. header ( "HTTP/1.1 500 Internal Server Error" );
  1051. echo "POST exceeded maximum allowed size.";
  1052. exit ( 0 );
  1053. }
  1054. // Settings
  1055. $save_path = DOO::conf ()->SITE_PATH . "upload/invoiceTraining/"; // The path were we will save the file (getcwd() may not be reliable and should be tested in your environment)
  1056. $upload_name = "Filedata";
  1057. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  1058. $extension_whitelist = array (
  1059. "doc",
  1060. "txt",
  1061. "jpg",
  1062. "gif",
  1063. "png"
  1064. ); // Allowed file extensions
  1065. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  1066. // Other variables
  1067. $MAX_FILENAME_LENGTH = 260;
  1068. $file_name = "";
  1069. $file_extension = "";
  1070. $uploadErrors = array (
  1071. 0 => "文件上传成功",
  1072. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  1073. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  1074. 3 => "上传的文件仅为部分文件",
  1075. 4 => "没有文件上传",
  1076. 6 => "缺少临时文件夹"
  1077. );
  1078. $nk = time ();
  1079. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  1080. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  1081. echo "文件无法保存.";
  1082. exit ( 0 );
  1083. }
  1084. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  1085. echo json_encode ( array (
  1086. 'filename' => $file_name,
  1087. 'id' => $nk
  1088. ) );
  1089. exit ( 0 );
  1090. }
  1091. /**
  1092. * 导入发票临时仓库
  1093. */
  1094. function invoiceStoreImport() {
  1095. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  1096. $trainingKey = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  1097. $path = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  1098. if ($path != "" && ! empty ( $trainingKey )) {
  1099. Doo::loadModel ( 'invoiceStore' );
  1100. Doo::loadModel ( 'staff' );
  1101. $staff = new staff ();
  1102. Doo::loadModel ( 'invoiceTraining' );
  1103. $invoiceTraining = new invoiceTraining ();
  1104. Doo::loadClass ( 'XDeode' );
  1105. $XDeode = new XDeode ( 5 );
  1106. $itid = $XDeode->decode ( $trainingKey );
  1107. // 培训班结算是否有和是否已经结算完成
  1108. Doo::loadModel ( 'receipt' );
  1109. $receipt = new receipt ();
  1110. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $itid );
  1111. if (! empty ( $receiptDetail )) {
  1112. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9)
  1113. die ( 'illegal request--status' );
  1114. }
  1115. $exlArray = $this->formatExcelToArrayTrain ( DOO::conf ()->SITE_PATH . "upload/invoiceTraining/" . $path );
  1116. $userName = $this->staff [0] ['username'];
  1117. $sDetail = $staff->getStaffByName ( $userName );
  1118. // die('sdd');
  1119. // 可以优化
  1120. foreach ( $exlArray as $key => $value ) {
  1121. // 开票
  1122. $invoice = new invoiceStore ();
  1123. $invoice->trainId = $itid;
  1124. $invoice->invoiceType = 0;
  1125. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  1126. $invoice->invoiceType = 1;
  1127. $invoice->invoiceQuantity = $value ['invoiceQuantity'];
  1128. $invoice->invoiceUnitPrice = $value ['invoiceUnitPrice'];
  1129. $invoice->invoicePrice = $value ['invoiceQuantity'] * $value ['invoiceUnitPrice'];
  1130. $invoice->invoiceTitle = $value ['invoiceTitle'];
  1131. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  1132. $invoice->invoiceCompany = $value ['invoiceTitle'];
  1133. $invoice->userName = $userName;
  1134. $invoice->sid = $sDetail ['sid'];
  1135. $invoice->cid = $sDetail ['cid'];
  1136. $invoice->categoryName = $sDetail ['category'];
  1137. $invoice->invoiceElement = $value ['invoiceElement'];
  1138. $invoice->remark = $value ['remark'];
  1139. // $invoice->date = $value ['date'];
  1140. // $invoice->printTime = $value ['date'];
  1141. $invoice->ipSource = 1;
  1142. $invoice->printStatus = 0;
  1143. $invoice->status = 0;
  1144. $invoice->postStatus = 1;
  1145. $invoice->untreadStatus = 0;
  1146. // $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1147. $invoice->TIN = $value ['TIN'];
  1148. $invoice->address = $value ['address'];
  1149. $invoice->phone = $value ['phone'];
  1150. $invoice->bank = $value ['bank'];
  1151. $invoice->bankAccount = $value ['bankAccount'];
  1152. $invoice->recipientsAddress = $value ['recipientsAddress'];
  1153. $invoice->recipients = $value ['recipients'];
  1154. $invoice->recipientsPhone = $value ['recipientsPhone'];
  1155. $iid = $invoice->insert ();
  1156. }
  1157. // 加入发票总数量
  1158. $item = array (
  1159. 'itid' => $itid,
  1160. 'invoiceTotal' => count ( $exlArray )
  1161. );
  1162. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1163. return '/invoiceTrainingDetail/' . $trainingKey . ".html";
  1164. }
  1165. echo 'no file';
  1166. }
  1167. /**
  1168. * 编辑仓库里的发票
  1169. */
  1170. function invoiceStoreEdit() {
  1171. Doo::loadClass ( 'XDeode' );
  1172. $XDeode = new XDeode ( 5 );
  1173. $iid = isset ( $this->params ['storeKey'] ) ? $this->params ['storeKey'] : "";
  1174. $iid = $XDeode->decode ( $iid );
  1175. if (! is_numeric ( $iid ))
  1176. die ( 'illegal request' );
  1177. Doo::loadModel ( 'invoiceStore' );
  1178. $invoiceStore = new invoiceStore ();
  1179. $invoiceDetail = $invoiceStore->getInvoiceStoreByIsid ( $iid );
  1180. // print_r($invoiceDetail);
  1181. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  1182. $this->data ['invoiceDetail'] = $invoiceDetail;
  1183. $this->data ['memu'] = "invoice";
  1184. $this->data ['staff'] = $this->staff;
  1185. $this->data ['receiptMemu'] = 'invoiceTraining';
  1186. $this->render ( "/admin/invoiceStoreEdit", $this->data );
  1187. }
  1188. function invoiceStoreEditDo() {
  1189. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1190. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1191. Doo::loadModel ( 'invoiceStore' );
  1192. $invoice = new invoiceStore ();
  1193. Doo::loadClass ( 'XDeode' );
  1194. $XDeode = new XDeode ( 5 );
  1195. $iid = $XDeode->decode ( $storeKey );
  1196. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1197. die ( 'illegal request' );
  1198. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  1199. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  1200. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  1201. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  1202. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  1203. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  1204. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  1205. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  1206. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  1207. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  1208. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  1209. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  1210. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  1211. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  1212. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1213. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1214. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1215. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1216. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  1217. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  1218. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  1219. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  1220. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  1221. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  1222. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1223. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1224. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1225. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1226. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1227. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1228. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1229. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  1230. $cid = explode ( ':', $cid );
  1231. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  1232. $item = array (
  1233. 'isid' => $iid,
  1234. 'cid' => $cid [0],
  1235. 'categoryName' => $cid [1],
  1236. 'invoiceElement' => $invoiceElement,
  1237. 'invoiceQuantity' => $invoiceQuantity,
  1238. 'invoiceUnitPrice' => $invoiceUnitPrice,
  1239. 'invoicePrice' => $invoicePrice,
  1240. 'invoiceType' => $invoiceType,
  1241. 'doPost' => $doPost,
  1242. 'status' => 1,
  1243. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1244. 'remark' => $remark
  1245. );
  1246. if ($invoiceType == 0)
  1247. $item += array (
  1248. 'invoiceTitle' => $invoiceTitle,
  1249. 'TIN' => $TINT,
  1250. 'address' => $addressT,
  1251. 'phone' => $phoneT,
  1252. 'bank' => $bankT,
  1253. 'bankAccount' => $bankAccountT
  1254. );
  1255. else {
  1256. $item += array (
  1257. 'invoiceCompany' => $invoiceCompany,
  1258. 'TIN' => $TIN,
  1259. 'address' => $address,
  1260. 'phone' => $phone,
  1261. 'bank' => $bank,
  1262. 'bankAccount' => $bankAccount
  1263. );
  1264. }
  1265. if ($doPost == 1) {
  1266. $mailList = array (
  1267. 'invoice' => 1,
  1268. 'mailItems' => $mailItems
  1269. );
  1270. if (! empty ( $softLock ))
  1271. $mailList += array (
  1272. 'softLock' => $softLockNum
  1273. );
  1274. else
  1275. $mailList += array (
  1276. 'softLock' => '0'
  1277. );
  1278. if (! empty ( $contract ))
  1279. $mailList += array (
  1280. 'contract' => $contractNum
  1281. );
  1282. else
  1283. $mailList += array (
  1284. 'contract' => '0'
  1285. );
  1286. if (! empty ( $instructions ))
  1287. $mailList += array (
  1288. 'instructions' => $instructionsNum
  1289. );
  1290. else
  1291. $mailList += array (
  1292. 'instructions' => '0'
  1293. );
  1294. if (! empty ( $remittance ))
  1295. $mailList += array (
  1296. 'remittance' => $remittance
  1297. );
  1298. else
  1299. $mailList += array (
  1300. 'remittance' => ''
  1301. );
  1302. $mailString = '发票x1,备注:' . $mailItems;
  1303. if (! empty ( $softLock ))
  1304. $mailString .= ',软件锁x' . $softLockNum;
  1305. if (! empty ( $contract ))
  1306. $mailString .= ',合同x' . $contractNum;
  1307. if (! empty ( $instructions ))
  1308. $mailString .= ',说明书x' . $instructionsNum;
  1309. if (! empty ( $remittance ))
  1310. $mailString .= ',汇款账号单';
  1311. $item += array (
  1312. 'recipients' => $recipients,
  1313. 'recipientsPhone' => $recipientsPhone,
  1314. 'recipientsAddress' => $recipientsAddress,
  1315. 'mailItems' => $mailString,
  1316. 'mailItemsJson' => json_encode ( $mailList )
  1317. );
  1318. }
  1319. $invoice->setInvoiceStoreByCondition ( $item );
  1320. }
  1321. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1322. }
  1323. /**
  1324. *
  1325. * @return string
  1326. */
  1327. function invoiceStoreDelete() {
  1328. Doo::loadClass ( 'XDeode' );
  1329. $XDeode = new XDeode ( 5 );
  1330. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1331. $iStoreKey = $this->get_args ( 'iStoreKey' ) ? $this->get_args ( 'iStoreKey' ) : 0;
  1332. $isid = $XDeode->decode ( $iStoreKey );
  1333. $itid = $XDeode->decode ( $trainKey );
  1334. if (! is_numeric ( $isid ))
  1335. die ( 'illegal request' );
  1336. Doo::loadModel ( 'invoiceStore' );
  1337. $invoiceStore = new invoiceStore ();
  1338. $invoiceStore->delete ( array (
  1339. 'where' => 'isid=' . $isid,
  1340. 'limit' => 1
  1341. ) );
  1342. Doo::loadModel ( 'invoiceTraining' );
  1343. $invoiceTraining = new invoiceTraining ();
  1344. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1345. $item = array (
  1346. 'itid' => $itid,
  1347. 'invoiceTotal' => $itDetail ['invoiceTotal'] - 1
  1348. );
  1349. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1350. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1351. }
  1352. /**
  1353. * 批量删除库里发票
  1354. */
  1355. function invoiceStoreBatchDelete() {
  1356. Doo::loadClass ( 'XDeode' );
  1357. $XDeode = new XDeode ( 5 );
  1358. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1359. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1360. if (empty ( $trainKey ) || empty ( $storeKey ))
  1361. die ( 'illegal request-IdKey' );
  1362. $tid = $XDeode->decode ( $trainKey );
  1363. if (! is_numeric ( $tid ) && ! empty ( $storeKey ))
  1364. die ( 'illegal request' );
  1365. Doo::loadModel ( 'invoiceStore' );
  1366. $isidKeyList = explode ( ',', $storeKey );
  1367. $isidList = array ();
  1368. foreach ( $isidKeyList as $value ) {
  1369. $isid = $XDeode->decode ( $value );
  1370. if (! empty ( $isid ) && is_numeric ( $isid ))
  1371. array_push ( $isidList, $isid );
  1372. }
  1373. $isidString = implode ( ',', $isidList );
  1374. $invoiceStore = new invoiceStore ();
  1375. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,apStatus' );
  1376. $isidList = array ();
  1377. foreach ( $isList as $key => $value ) {
  1378. if ($value ['apStatus'] == 0)
  1379. array_push ( $isidList, $value ['isid'] );
  1380. }
  1381. $isidString = implode ( ',', $isidList );
  1382. // print_r($isList);
  1383. // echo $isidString;
  1384. $invoiceStore = new invoiceStore ();
  1385. $invoiceStore->delete ( array (
  1386. 'where' => "isid in ( " . $isidString . ")",
  1387. 'asArray' => TRUE
  1388. ) );
  1389. Doo::loadModel ( 'invoiceTraining' );
  1390. $invoiceTraining = new invoiceTraining ();
  1391. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1392. $item = array (
  1393. 'itid' => $tid,
  1394. 'invoiceTotal' => $itDetail ['invoiceTotal'] - count ( $isidList )
  1395. );
  1396. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1397. // echo $tid;
  1398. // echo $storeKey;
  1399. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1400. }
  1401. /**
  1402. * 仓库发票提交审批
  1403. * @return string
  1404. */
  1405. function invoiceStoreApproval() {
  1406. Doo::loadClass ( 'XDeode' );
  1407. $XDeode = new XDeode ( 5 );
  1408. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1409. $iStoreKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1410. $isid = $XDeode->decode ( $iStoreKey );
  1411. $trainId = $XDeode->decode ( $trainKey );
  1412. if (! is_numeric ( $isid ))
  1413. die ( 'illegal request' );
  1414. Doo::loadModel ( 'invoiceStore' );
  1415. Doo::loadModel ( 'invoice' );
  1416. $invoice = new invoice ();
  1417. // 加入限制必须填写入开票内容和邮寄物品
  1418. $invoiceStore = new invoiceStore ();
  1419. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid, 'isid,trainId ,invoiceElement,mailItemsJson' );
  1420. if (empty ( $isDetail ['invoiceElement'] ) || empty ( $isDetail ['mailItemsJson'] )) {
  1421. header ( 'Content-Type:text/html;charset=utf-8' );
  1422. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1423. }
  1424. // 拷贝插入一条发票数据
  1425. $invoiceStore = new invoiceStore ();
  1426. $iid = $invoiceStore->setInvoiceStoreToApproval ( $isid );
  1427. $invoiceStore = new invoiceStore ();
  1428. $item = array (
  1429. 'isid' => $isid,
  1430. 'iid' => $iid,
  1431. 'apStatus' => 1
  1432. );
  1433. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1434. Doo::loadModel ( 'invoiceManage' );
  1435. $invoiceManage = new invoiceManage ();
  1436. Doo::loadModel ( 'invoiceOperationLog' );
  1437. $invoiceOperationLog = new invoiceOperationLog ();
  1438. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1439. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1440. $moldManage = array ();
  1441. foreach ( $invoiceManageList as $key => $value ) {
  1442. if ($value ['mold'] == '发票打印')
  1443. $moldManage [$value ['mold']] = $value ['staffList'];
  1444. elseif ($value ['mold'] == '发票邮寄')
  1445. $moldManage [$value ['mold']] = $value ['staffList'];
  1446. elseif ($value ['mold'] == '发票退票')
  1447. $moldManage [$value ['mold']] = $value ['staffList'];
  1448. }
  1449. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1450. $item = array (
  1451. 'iid' => $iid,
  1452. 'isid' => $isid,
  1453. 'invoiceSerial' => "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  1454. 'date' => date ( "Y-m-d H:i:s" ),
  1455. 'status' => 1,
  1456. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1457. 'trainId' => $trainId,
  1458. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1459. 'moldManage' => json_encode ( $moldManage ),
  1460. 'settlementType' => 1,
  1461. 'pendingApprovals' => $pendingApprovalsSid
  1462. );
  1463. $invoice->setInvoiceByCondition ( $item );
  1464. Doo::loadModel ( 'invoiceTraining' );
  1465. $invoiceTraining = new invoiceTraining ();
  1466. $item = array (
  1467. 'itid' => $trainId,
  1468. 'submitStatus' => 1
  1469. );
  1470. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1471. $item = array (
  1472. 'date' => date ( "Y-m-d H:i:s" ),
  1473. 'operation' => "创建",
  1474. 'status' => 1,
  1475. 'img' => $this->staff [0] ['avatar'],
  1476. 'username' => $this->staff [0] ['username'],
  1477. 'uid' => $this->staff [0] ['sid'],
  1478. 'category' => $this->staff [0] ['category'],
  1479. 'iid' => $iid
  1480. );
  1481. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1482. $item = array (
  1483. 'date' => date ( "Y-m-d H:i:s" ),
  1484. 'operation' => "提交审批",
  1485. 'status' => 1,
  1486. 'img' => $this->staff [0] ['avatar'],
  1487. 'username' => $this->staff [0] ['username'],
  1488. 'uid' => $this->staff [0] ['sid'],
  1489. 'category' => $this->staff [0] ['category'],
  1490. 'iid' => $iid
  1491. );
  1492. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1493. Doo::loadModel ( 'staff' );
  1494. $staff = new staff ();
  1495. $username2 = $staff->getOne ( array (
  1496. 'select' => 'wxid',
  1497. 'where' => 'sid=' . $pendingApprovalsSid,
  1498. 'asArray' => TRUE
  1499. ) );
  1500. // 发送微信审批通知
  1501. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1502. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1503. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1504. }
  1505. /**
  1506. * 批量提交发票
  1507. * @return string
  1508. */
  1509. function invoiceStoreBatchApproval() {
  1510. Doo::loadClass ( 'XDeode' );
  1511. $XDeode = new XDeode ( 5 );
  1512. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1513. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1514. if (empty ( $trainKey ) || empty ( $storeKey ))
  1515. die ( 'illegal request-IdKey' );
  1516. $trainId = $XDeode->decode ( $trainKey );
  1517. $isidKeyList = explode ( ',', $storeKey );
  1518. $isidList = array ();
  1519. foreach ( $isidKeyList as $value ) {
  1520. $isid = $XDeode->decode ( $value );
  1521. if (! empty ( $isid ) && is_numeric ( $isid ))
  1522. array_push ( $isidList, $isid );
  1523. }
  1524. $isidString = implode ( ',', $isidList );
  1525. if (! is_numeric ( $trainId ))
  1526. die ( 'illegal request' );
  1527. Doo::loadModel ( 'invoiceStore' );
  1528. Doo::loadModel ( 'invoice' );
  1529. // 判断哪些已经加入审批过
  1530. // 加入限制必须填写入开票内容和邮寄物品
  1531. $invoiceStore = new invoiceStore ();
  1532. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,trainId ,invoiceElement,mailItemsJson' );
  1533. foreach ( $isList as $key => $value ) {
  1534. if (empty ( $value ['invoiceElement'] ) || empty ( $value ['mailItemsJson'] )) {
  1535. header ( 'Content-Type:text/html;charset=utf-8' );
  1536. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1537. }
  1538. }
  1539. // 拷贝插入一条发票数据
  1540. $invoiceStore = new invoiceStore ();
  1541. $invoiceStore->setInvoiceStoreBatchToApproval ( $isidString );
  1542. $invoiceStore = new invoiceStore ();
  1543. $item = array (
  1544. 'apStatus' => 1
  1545. );
  1546. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1547. // 获得正式发票ID
  1548. $invoice = new invoice ();
  1549. $iidList = $invoice->getInvoiceByIstoreid ( $isidString, 'iid,isid' );
  1550. $sqlList = array ();
  1551. $iidString = '';
  1552. $iida = array ();
  1553. foreach ( $iidList as $key => $value ) {
  1554. $sqlList [$value ['isid']] = $value ['iid'];
  1555. array_push ( $iida, $value ['iid'] );
  1556. }
  1557. $iidString = implode ( ',', $iida );
  1558. $ids = implode ( ',', array_keys ( $sqlList ) );
  1559. $sql = "UPDATE CLD_invoiceStore SET iid = CASE isid ";
  1560. foreach ( $sqlList as $id => $ordinal ) {
  1561. $sql .= sprintf ( "WHEN %d THEN %d ", $id, $ordinal );
  1562. }
  1563. $sql .= "END WHERE isid IN ($ids)";
  1564. $invoiceStore = new invoiceStore ();
  1565. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1566. Doo::loadModel ( 'invoiceManage' );
  1567. $invoiceManage = new invoiceManage ();
  1568. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1569. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1570. $moldManage = array ();
  1571. foreach ( $invoiceManageList as $key => $value ) {
  1572. if ($value ['mold'] == '发票打印')
  1573. $moldManage [$value ['mold']] = $value ['staffList'];
  1574. elseif ($value ['mold'] == '发票邮寄')
  1575. $moldManage [$value ['mold']] = $value ['staffList'];
  1576. elseif ($value ['mold'] == '发票退票')
  1577. $moldManage [$value ['mold']] = $value ['staffList'];
  1578. }
  1579. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1580. // 批量更新发票信息
  1581. $item = array (
  1582. 'date' => date ( "Y-m-d H:i:s" ),
  1583. 'status' => 1,
  1584. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1585. 'trainId' => $trainId,
  1586. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1587. 'moldManage' => json_encode ( $moldManage ),
  1588. 'settlementType' => 1,
  1589. 'pendingApprovals' => $pendingApprovalsSid
  1590. );
  1591. $invoice = new invoice ();
  1592. $invoice->BatchInvoiceByCondition ( $item, $iidString );
  1593. // 批量更新发票中仓库isid
  1594. $sql = "UPDATE CLD_invoiceStore SET isid = CASE iid ";
  1595. foreach ( $sqlList as $isid => $iid ) {
  1596. $sql .= sprintf ( "WHEN %d THEN %d ", $iid, $isid );
  1597. }
  1598. $sql .= "END WHERE iid IN ($iidString)";
  1599. $invoice = new invoice ();
  1600. $invoice->UpdateBatchInvoice ( $sql );
  1601. // 批量更新发票序列号
  1602. $sqlList = array ();
  1603. foreach ( $iida as $value ) {
  1604. $sqlList [$value] = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1605. }
  1606. $ids = implode ( ',', array_keys ( $sqlList ) );
  1607. $sql = "UPDATE CLD_invoice SET invoiceSerial = CASE iid ";
  1608. foreach ( $sqlList as $id => $ordinal ) {
  1609. $sql .= sprintf ( "WHEN %d THEN '%s' ", $id, $ordinal );
  1610. }
  1611. $sql .= "END WHERE iid IN ($ids)";
  1612. $invoiceStore = new invoiceStore ();
  1613. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1614. // 批量生产操作日志
  1615. Doo::loadModel ( 'invoiceOperationLog' );
  1616. $sqlList = array ();
  1617. foreach ( $iida as $key => $value ) {
  1618. $sql = '("' . date ( "Y-m-d H:i:s" ) . '","创建","1","' . $this->staff [0] ['avatar'] . '","' . $this->staff [0] ['username'] . '","' . $this->staff [0] ['sid'] . '","' . $this->staff [0] ['category'] . '","' . $value . '"),
  1619. ("' . date ( "Y-m-d H:i:s" ) . '","提交审批","1","' . $this->staff [0] ['avatar'] . '","' . $this->staff [0] ['username'] . '","' . $this->staff [0] ['sid'] . '","' . $this->staff [0] ['category'] . '","' . $value . '") ';
  1620. array_push ( $sqlList, $sql );
  1621. }
  1622. $iolSql = implode ( ',', $sqlList );
  1623. $sql = "INSERT INTO `CLD_invoiceOperationLog` (`date`, `operation`, `status`, `img`, `username`, `uid`, `category`, `iid`) VALUES " . $iolSql;
  1624. $invoiceOperationLog = new invoiceOperationLog ();
  1625. $invoiceOperationLog->setInvoiceOperationLogBySql ( $sql );
  1626. Doo::loadModel ( 'invoiceTraining' );
  1627. $invoiceTraining = new invoiceTraining ();
  1628. $item = array (
  1629. 'itid' => $trainId,
  1630. 'submitStatus' => 1
  1631. );
  1632. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1633. Doo::loadModel ( 'staff' );
  1634. $staff = new staff ();
  1635. $username2 = $staff->getOne ( array (
  1636. 'select' => 'wxid',
  1637. 'where' => 'sid=' . $pendingApprovalsSid,
  1638. 'asArray' => TRUE
  1639. ) );
  1640. // 发送微信审批通知
  1641. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1642. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1643. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1644. }
  1645. /**
  1646. */
  1647. function invoiceStoreMailItemSet() {
  1648. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1649. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1650. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1651. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1652. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1653. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1654. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1655. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1656. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1657. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1658. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1659. Doo::loadClass ( 'XDeode' );
  1660. $XDeode = new XDeode ( 5 );
  1661. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1662. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1663. $isid = $XDeode->decode ( $storeKey );
  1664. $trainId = $XDeode->decode ( $trainKey );
  1665. if (! is_numeric ( $isid ))
  1666. die ( 'illegal request' );
  1667. Doo::loadModel ( 'invoiceStore' );
  1668. $invoiceStore = new invoiceStore ();
  1669. $mailList = array (
  1670. 'invoice' => 1,
  1671. 'mailItems' => $mailItems
  1672. );
  1673. if (! empty ( $softLock ))
  1674. $mailList += array (
  1675. 'softLock' => $softLockNum
  1676. );
  1677. else
  1678. $mailList += array (
  1679. 'softLock' => 0
  1680. );
  1681. if (! empty ( $contract ))
  1682. $mailList += array (
  1683. 'contract' => $contractNum
  1684. );
  1685. else
  1686. $mailList += array (
  1687. 'contract' => 0
  1688. );
  1689. if (! empty ( $instructions ))
  1690. $mailList += array (
  1691. 'instructions' => $instructionsNum
  1692. );
  1693. else
  1694. $mailList += array (
  1695. 'instructions' => 0
  1696. );
  1697. if (! empty ( $remittance ))
  1698. $mailList += array (
  1699. 'remittance' => $remittance
  1700. );
  1701. else
  1702. $mailList += array (
  1703. 'remittance' => ''
  1704. );
  1705. $mailString = '发票x1,备注:' . $mailItems;
  1706. if (! empty ( $softLock ))
  1707. $mailString .= ',软件锁x' . $softLockNum;
  1708. if (! empty ( $contract ))
  1709. $mailString .= ',合同x' . $contractNum;
  1710. if (! empty ( $instructions ))
  1711. $mailString .= ',说明书x' . $instructionsNum;
  1712. if (! empty ( $remittance ))
  1713. $mailString .= ',汇款账号单';
  1714. $item = array (
  1715. 'isid' => $isid,
  1716. 'doPost' => 1,
  1717. 'mailItems' => $mailString,
  1718. 'mailItemsJson' => json_encode ( $mailList )
  1719. );
  1720. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1721. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1722. }
  1723. /**
  1724. * 批量设置邮寄物品
  1725. */
  1726. function invoiceStoreBatchMailItemSet() {
  1727. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1728. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1729. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1730. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1731. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1732. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1733. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1734. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1735. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1736. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1737. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1738. Doo::loadClass ( 'XDeode' );
  1739. $XDeode = new XDeode ( 5 );
  1740. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1741. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1742. if (empty ( $trainKey ) || empty ( $storeKey ))
  1743. die ( 'illegal request-IdKey' );
  1744. $isidKeyList = explode ( ',', $storeKey );
  1745. $isidList = array ();
  1746. foreach ( $isidKeyList as $value ) {
  1747. $isid = $XDeode->decode ( $value );
  1748. if (! empty ( $isid ) && is_numeric ( $isid ))
  1749. array_push ( $isidList, $isid );
  1750. }
  1751. $isidString = implode ( ',', $isidList );
  1752. $trainId = $XDeode->decode ( $trainKey );
  1753. if (! is_numeric ( $isid ))
  1754. die ( 'illegal request' );
  1755. Doo::loadModel ( 'invoiceStore' );
  1756. $invoiceStore = new invoiceStore ();
  1757. $mailList = array (
  1758. 'invoice' => 1,
  1759. 'mailItems' => $mailItems
  1760. );
  1761. if (! empty ( $softLock ))
  1762. $mailList += array (
  1763. 'softLock' => $softLockNum
  1764. );
  1765. else
  1766. $mailList += array (
  1767. 'softLock' => 0
  1768. );
  1769. if (! empty ( $contract ))
  1770. $mailList += array (
  1771. 'contract' => $contractNum
  1772. );
  1773. else
  1774. $mailList += array (
  1775. 'contract' => 0
  1776. );
  1777. if (! empty ( $instructions ))
  1778. $mailList += array (
  1779. 'instructions' => $instructionsNum
  1780. );
  1781. else
  1782. $mailList += array (
  1783. 'instructions' => 0
  1784. );
  1785. if (! empty ( $remittance ))
  1786. $mailList += array (
  1787. 'remittance' => $remittance
  1788. );
  1789. else
  1790. $mailList += array (
  1791. 'remittance' => ''
  1792. );
  1793. $mailString = '发票x1,备注:' . $mailItems;
  1794. if (! empty ( $softLock ))
  1795. $mailString .= ',软件锁x' . $softLockNum;
  1796. if (! empty ( $contract ))
  1797. $mailString .= ',合同x' . $contractNum;
  1798. if (! empty ( $instructions ))
  1799. $mailString .= ',说明书x' . $instructionsNum;
  1800. if (! empty ( $remittance ))
  1801. $mailString .= ',汇款账号单';
  1802. $item = array (
  1803. 'doPost' => 1,
  1804. 'mailItems' => $mailString,
  1805. 'mailItemsJson' => json_encode ( $mailList )
  1806. );
  1807. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1808. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1809. }
  1810. /**
  1811. * 废弃
  1812. */
  1813. function ajaxGetMailItemByIstore() {
  1814. Doo::loadClass ( 'XDeode' );
  1815. $XDeode = new XDeode ( 5 );
  1816. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1817. $isid = $XDeode->decode ( $storeKey );
  1818. if (! is_numeric ( $isid ))
  1819. die ( 'illegal request' );
  1820. Doo::loadModel ( 'invoiceStore' );
  1821. $invoiceStore = new invoiceStore ();
  1822. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid );
  1823. $isDetail ['mailItemsJson'] = json_decode ( $isDetail ['mailItemsJson'], true );
  1824. echo json_encode ( $isDetail ['mailItemsJson'] );
  1825. exit ();
  1826. }
  1827. /**
  1828. * 终止开票
  1829. */
  1830. function invoiceDroppedDo() {
  1831. $droppedIidKey = $this->get_args ( 'droppedIidKey' ) ? $this->get_args ( 'droppedIidKey' ) : '';
  1832. Doo::loadModel ( 'invoice' );
  1833. $invoice = new invoice ();
  1834. Doo::loadModel ( 'invoiceOperationLog' );
  1835. $invoiceOperationLog = new invoiceOperationLog ();
  1836. $iid = $invoice->authcode ( $droppedIidKey );
  1837. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1838. die ( 'illegal request' );
  1839. $item = array (
  1840. 'iid' => $iid,
  1841. 'status' => 4,
  1842. 'updateTime' => date ( "Y-m-d H:i:s" )
  1843. );
  1844. $invoice->setInvoiceByCondition ( $item );
  1845. $item = array (
  1846. 'date' => date ( "Y-m-d H:i:s" ),
  1847. 'operation' => '终止了开票',
  1848. 'status' => 4,
  1849. 'img' => $this->staff [0] ['avatar'],
  1850. 'username' => $this->staff [0] ['username'],
  1851. 'uid' => $this->staff [0] ['sid'],
  1852. 'category' => $this->staff [0] ['category'],
  1853. 'iid' => $iid
  1854. );
  1855. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1856. return "/invoice";
  1857. }
  1858. /**
  1859. * 更新退票的邮寄信息
  1860. */
  1861. function invoiceUntreadMailDo() {
  1862. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  1863. $untreadCompany = $this->get_args ( 'untreadCompany' ) ? $this->get_args ( 'untreadCompany' ) : "";
  1864. $untreadNumber = $this->get_args ( 'untreadNumber' ) ? $this->get_args ( 'untreadNumber' ) : "";
  1865. $untreadItems = $this->get_args ( 'untreadItems' ) ? $this->get_args ( 'untreadItems' ) : "";
  1866. Doo::loadModel ( 'invoice' );
  1867. $invoice = new invoice ();
  1868. $iid = $invoice->authcode ( $untreadIidKey );
  1869. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1870. die ( 'illegal request' );
  1871. $item = array (
  1872. 'iid' => $iid,
  1873. 'untreadCompany' => $untreadCompany,
  1874. 'untreadNumber' => $untreadNumber,
  1875. 'untreadItems' => $untreadItems
  1876. );
  1877. $invoice->setInvoiceByCondition ( $item );
  1878. return "/invoice";
  1879. }
  1880. /**
  1881. * 申请退票 --
  1882. */
  1883. function invoiceUntreadDo() {
  1884. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  1885. $untreadReason = $this->get_args ( 'untreadReason' ) ? $this->get_args ( 'untreadReason' ) : "";
  1886. $untreadPost = $this->get_args ( 'untreadPost' ) ? $this->get_args ( 'untreadPost' ) : "";
  1887. Doo::loadModel ( 'invoice' );
  1888. $invoice = new invoice ();
  1889. Doo::loadModel ( 'invoiceOperationLog' );
  1890. $invoiceOperationLog = new invoiceOperationLog ();
  1891. Doo::loadModel ( 'invoiceReceivables' );
  1892. $invoiceReceivables = new invoiceReceivables ();
  1893. $iid = $invoice->authcode ( $untreadIidKey );
  1894. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1895. die ( 'illegal request' );
  1896. /*
  1897. * 需求变革 有绑定收款也可以退票 $lt = $invoiceReceivables->getInvoiceReceivablesByIid ( $untreadIidKey ); if (! empty ( $lt )) { header ( 'Content-Type:text/html;charset=utf-8' ); die ( '该发票有收款绑定,请先移除!' ); }
  1898. */
  1899. $item = array (
  1900. 'iid' => $iid,
  1901. 'untreadStatus' => 1,
  1902. 'untreadReason' => $untreadReason,
  1903. 'untreadPost' => $untreadPost,
  1904. 'updateTime' => date ( "Y-m-d H:i:s" )
  1905. );
  1906. $invoice->setInvoiceByCondition ( $item );
  1907. $item = array (
  1908. 'date' => date ( "Y-m-d H:i:s" ),
  1909. 'operation' => '申请退票',
  1910. 'status' => 7,
  1911. 'img' => $this->staff [0] ['avatar'],
  1912. 'username' => $this->staff [0] ['username'],
  1913. 'uid' => $this->staff [0] ['sid'],
  1914. 'category' => $this->staff [0] ['category'],
  1915. 'iid' => $iid
  1916. );
  1917. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1918. return "/invoice";
  1919. }
  1920. /**
  1921. * 删除已终止的开票
  1922. */
  1923. function invoiceDelDo() {
  1924. Doo::loadModel ( 'invoice' );
  1925. $invoice = new invoice ();
  1926. Doo::loadModel ( 'invoiceOperationLog' );
  1927. $invoiceOperationLog = new invoiceOperationLog ();
  1928. Doo::loadClass ( 'XDeode' );
  1929. $XDeode = new XDeode ( 5 );
  1930. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  1931. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  1932. $iid = $XDeode->decode ( $iid );
  1933. Doo::loadModel ( 'invoiceStore' );
  1934. $invoiceStore = new invoiceStore ();
  1935. if (! is_numeric ( $iid ))
  1936. die ( 'illegal request' );
  1937. $invoiceDetail = $invoice->getMyInvoice ( $sid, $iid );
  1938. if (empty ( $invoiceDetail ))
  1939. die ( 'illegal request' );
  1940. $item = array (
  1941. 'iid' => $iid,
  1942. 'isDelete' => 1,
  1943. 'updateTime' => date ( "Y-m-d H:i:s" )
  1944. );
  1945. $invoice->setInvoiceByCondition ( $item );
  1946. $item = array (
  1947. 'date' => date ( "Y-m-d H:i:s" ),
  1948. 'operation' => '删除了已终止的发票',
  1949. 'status' => 4,
  1950. 'img' => $this->staff [0] ['avatar'],
  1951. 'username' => $this->staff [0] ['username'],
  1952. 'uid' => $this->staff [0] ['sid'],
  1953. 'category' => $this->staff [0] ['category'],
  1954. 'iid' => $iid
  1955. );
  1956. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1957. // 删除培训班发票仓库里的发票
  1958. $invoiceStore->delInvoiceStoreByIsid ( $invoiceDetail ['isid'] );
  1959. return "/invoice";
  1960. }
  1961. /**
  1962. */
  1963. function invoiceApproval() {
  1964. Doo::loadModel ( 'invoice' );
  1965. $invoice = new invoice ();
  1966. Doo::loadClass ( 'XDeode' );
  1967. $XDeode = new XDeode ( 5 );
  1968. Doo::loadModel ( 'staff' );
  1969. $staff = new staff ();
  1970. $invoiceList = $invoice->find ( array (
  1971. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  1972. 'desc' => 'iid',
  1973. 'limit' => 10,
  1974. 'asArray' => true
  1975. ) );
  1976. foreach ( $invoiceList as $key => $value ) {
  1977. $invoiceList [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1978. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1979. if (! empty ( $lastApprover )) {
  1980. $lastApproverKey = array_keys ( $lastApprover );
  1981. $lastApprover = end ( $lastApprover );
  1982. $staffDetail = $staff->getOne ( array (
  1983. 'where' => 'sid=' . end ( $lastApproverKey ),
  1984. 'asArray' => true
  1985. ) );
  1986. $lastApprover ['username'] = $staffDetail ['username'];
  1987. }
  1988. $invoiceList [$key] ['lastApprover'] = $lastApprover;
  1989. }
  1990. $ilist = $invoice->getInvoiceByProcessStatus ();
  1991. foreach ( $ilist as $key => $value ) {
  1992. $ilist [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1993. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1994. if (! empty ( $lastApprover )) {
  1995. $lastApproverKey = array_keys ( $lastApprover );
  1996. $lastApprover = end ( $lastApprover );
  1997. $staffDetail = $staff->getOne ( array (
  1998. 'where' => 'sid=' . end ( $lastApproverKey ),
  1999. 'asArray' => true
  2000. ) );
  2001. $lastApprover ['username'] = $staffDetail ['username'];
  2002. }
  2003. $ilist [$key] ['lastApprover'] = $lastApprover;
  2004. }
  2005. // print_r($ilist);
  2006. $this->data ['invoiceList'] = $invoiceList;
  2007. $this->data ['ilist'] = $ilist;
  2008. $this->data ['memu'] = "invoice";
  2009. $this->data ['staff'] = $this->staff;
  2010. $this->data ['receiptMemu'] = 'invoiceApproval';
  2011. $this->render ( "/admin/invoiceApproval", $this->data );
  2012. }
  2013. function invoiceDetail() {
  2014. Doo::loadClass ( 'XDeode' );
  2015. $XDeode = new XDeode ( 5 );
  2016. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  2017. $iid = $XDeode->decode ( $iid );
  2018. if (! is_numeric ( $iid ))
  2019. die ( 'illegal request' );
  2020. Doo::loadModel ( 'invoice' );
  2021. $invoice = new invoice ();
  2022. Doo::loadModel ( 'invoiceOperationLog' );
  2023. $invoiceOperationLog = new invoiceOperationLog ();
  2024. $invoiceDetail = $invoice->getOne ( array (
  2025. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'] . ' and iid=' . $iid,
  2026. 'asArray' => true
  2027. ) );
  2028. if (empty ( $invoiceDetail ))
  2029. die ( 'illegal request' );
  2030. if ($invoiceDetail ['settlementType'] == 1) {
  2031. Doo::loadModel ( 'invoiceTraining' );
  2032. $invoiceTraining = new invoiceTraining ();
  2033. $invoiceDetail ['invoiceTraining'] = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceDetail ['trainId'] );
  2034. }
  2035. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  2036. $this->data ['invoiceDetail'] = $invoiceDetail;
  2037. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  2038. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  2039. $this->data ['memu'] = "invoice";
  2040. $this->data ['staff'] = $this->staff;
  2041. $this->data ['receiptMemu'] = 'invoiceApproval';
  2042. $this->render ( "/admin/invoiceApprovalDetail", $this->data );
  2043. }
  2044. /**
  2045. * 对发票进行审批,其中操作有终止,退回,同意动作。操作成功并记录下操作日志
  2046. *
  2047. * @since 1.0.0
  2048. * @var integer iid 开票ID 已加密
  2049. * @var integer status 发票审批状态
  2050. * @var integer opintion 审批发票的意见
  2051. * @return string 如操作成功返回审批首页
  2052. */
  2053. function invoiceApprovalDo() {
  2054. Doo::loadModel ( 'invoice' );
  2055. $invoice = new invoice ();
  2056. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2057. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  2058. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  2059. $divApproval = $this->get_args ( 'divApproval' ) ? $this->get_args ( 'divApproval' ) : "";
  2060. $iid = $invoice->authcode ( $iid );
  2061. if (! is_numeric ( $iid ))
  2062. die ( 'illegal request' );
  2063. // && ! empty ( $opinion )
  2064. if (! empty ( $iid ) && ! empty ( $status )) {
  2065. if (! ($status == 2 || $status == 3 || $status == 4))
  2066. die ( 'illegal request' );
  2067. Doo::loadModel ( 'invoiceOperationLog' );
  2068. $invoiceOperationLog = new invoiceOperationLog ();
  2069. $invoiceDetail = $invoice->getOne ( array (
  2070. 'where' => 'status=1 and iid=' . $iid . ' and pendingApprovals=' . $this->staff [0] ['sid'],
  2071. 'asArray' => true
  2072. ) );
  2073. if (empty ( $invoiceDetail ))
  2074. die ( 'illegal request' );
  2075. $processApprovals = json_decode ( $invoiceDetail ['processApprovals'], true );
  2076. $invoiceManage = json_decode ( $invoiceDetail ['invoiceManage'], true );
  2077. if ($status == 3) {
  2078. $invoice->status = $status;
  2079. $item = array (
  2080. 'operation' => $opinion
  2081. );
  2082. } else {
  2083. if (empty ( $processApprovals )) {
  2084. $processApprovals = array (
  2085. $this->staff [0] ['sid'] => array (
  2086. 'date' => date ( "Y-m-d H:i:s" ),
  2087. 'opinion' => $opinion,
  2088. 'status' => $status
  2089. )
  2090. );
  2091. // var_dump(next($invoiceManage));
  2092. $nextInvoiceManage = next ( $invoiceManage );
  2093. // print_r($nextInvoiceManage);
  2094. if ($status != 4 && $nextInvoiceManage !== false)
  2095. $invoice->pendingApprovals = $nextInvoiceManage [0];
  2096. $invoice->processApprovals = json_encode ( $processApprovals );
  2097. // var_dump($invoice);
  2098. // print_r($invoiceManage);
  2099. } else {
  2100. $processApprovals [$this->staff [0] ['sid']] = array (
  2101. 'date' => date ( "Y-m-d H:i:s" ),
  2102. 'opinion' => $opinion,
  2103. 'status' => $status
  2104. );
  2105. $pendingApprovals = 0;
  2106. foreach ( $invoiceManage as $key => $value ) {
  2107. if ($value [0] == $this->staff [0] ['sid']) {
  2108. if (isset ( $invoiceManage [$key + 1] ))
  2109. $pendingApprovals = $invoiceManage [$key + 1] [0];
  2110. break;
  2111. }
  2112. }
  2113. if ($status != 4 && ! empty ( $pendingApprovals ))
  2114. $invoice->pendingApprovals = $pendingApprovals;
  2115. $invoice->processApprovals = json_encode ( $processApprovals );
  2116. }
  2117. $item = array (
  2118. 'operation' => $opinion
  2119. );
  2120. if (count ( $processApprovals ) == count ( $invoiceManage ) && $status != 4) {
  2121. $invoice->status = $status;
  2122. $invoice->pendingApprovals = 0;
  2123. $invoice->approvalTime = date ( "Y-m-d H:i:s" );
  2124. } elseif ($status == 4) {
  2125. $invoice->status = $status;
  2126. $item = array (
  2127. 'operation' => $opinion
  2128. );
  2129. }
  2130. }
  2131. $invoice->updateTime = date ( "Y-m-d H:i:s" );
  2132. $invoice->update ( array (
  2133. 'where' => 'iid=' . $iid
  2134. ) );
  2135. $item += array (
  2136. 'date' => date ( "Y-m-d H:i:s" ),
  2137. 'img' => $this->staff [0] ['avatar'],
  2138. 'username' => $this->staff [0] ['username'],
  2139. 'uid' => $this->staff [0] ['sid'],
  2140. 'category' => $this->staff [0] ['category'],
  2141. 'status' => $status,
  2142. 'iid' => $iid
  2143. );
  2144. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2145. if (empty ( $divApproval ))
  2146. return '/invoiceApproval';
  2147. else
  2148. return '/invoiceApprovalAchieve/PEND';
  2149. }
  2150. die ( 'illegal request' );
  2151. }
  2152. /**
  2153. * 展示需要打印的发票数据
  2154. *
  2155. * @since 1.0.0
  2156. */
  2157. function invoicePrint() {
  2158. Doo::loadModel ( 'invoice' );
  2159. $invoice = new invoice ();
  2160. Doo::loadClass ( 'XDeode' );
  2161. $XDeode = new XDeode ( 5 );
  2162. Doo::loadModel ( 'staff' );
  2163. $staff = new staff ();
  2164. $toPrint = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0 );
  2165. $printed = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 1 );
  2166. foreach ( $toPrint as $key => $value ) {
  2167. $toPrint [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2168. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2169. if (! empty ( $lastApprover )) {
  2170. $lastApproverKey = array_keys ( $lastApprover );
  2171. $lastApprover = end ( $lastApprover );
  2172. $staffDetail = $staff->getOne ( array (
  2173. 'where' => 'sid=' . end ( $lastApproverKey ),
  2174. 'asArray' => true
  2175. ) );
  2176. $lastApprover ['username'] = $staffDetail ['username'];
  2177. }
  2178. $toPrint [$key] ['lastApprover'] = $lastApprover;
  2179. }
  2180. foreach ( $printed as $key => $value ) {
  2181. $printed [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2182. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2183. if (! empty ( $lastApprover )) {
  2184. $lastApproverKey = array_keys ( $lastApprover );
  2185. $lastApprover = end ( $lastApprover );
  2186. $staffDetail = $staff->getOne ( array (
  2187. 'where' => 'sid=' . end ( $lastApproverKey ),
  2188. 'asArray' => true
  2189. ) );
  2190. $lastApprover ['username'] = $staffDetail ['username'];
  2191. }
  2192. $printed [$key] ['lastApprover'] = $lastApprover;
  2193. }
  2194. $this->data ['printed'] = $printed;
  2195. $this->data ['toPrint'] = $toPrint;
  2196. $this->data ['memu'] = "invoice";
  2197. $this->data ['staff'] = $this->staff;
  2198. $this->data ['receiptMemu'] = 'invoicePrint';
  2199. $this->render ( "/admin/invoicePrint", $this->data );
  2200. }
  2201. /**
  2202. * 展示发票打印的详情页面
  2203. *
  2204. * @since 1.0.0
  2205. */
  2206. function invoicePrintDetail() {
  2207. Doo::loadClass ( 'XDeode' );
  2208. $XDeode = new XDeode ( 5 );
  2209. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  2210. $iid = $XDeode->decode ( $iid );
  2211. if (! is_numeric ( $iid ))
  2212. die ( 'illegal request' );
  2213. Doo::loadModel ( 'invoice' );
  2214. $invoice = new invoice ();
  2215. Doo::loadModel ( 'invoiceOperationLog' );
  2216. $invoiceOperationLog = new invoiceOperationLog ();
  2217. Doo::loadModel ( 'invoicePaper' );
  2218. $invoicePaper = new invoicePaper ();
  2219. $invoiceDetail = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0, $iid );
  2220. if (empty ( $invoiceDetail ))
  2221. die ( 'illegal request' );
  2222. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $invoiceDetail ['invoiceType'] );
  2223. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  2224. if ($invoiceDetail ['settlementType'] == 1) {
  2225. Doo::loadModel ( 'invoiceTraining' );
  2226. $invoiceTraining = new invoiceTraining ();
  2227. $invoiceDetail ['invoiceTraining'] = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceDetail ['trainId'] );
  2228. }
  2229. $this->data ['invoicePaperList'] = $invoicePaperList;
  2230. $this->data ['invoiceDetail'] = $invoiceDetail;
  2231. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  2232. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  2233. $this->data ['memu'] = "invoice";
  2234. $this->data ['staff'] = $this->staff;
  2235. $this->data ['receiptMemu'] = 'invoicePrint';
  2236. $this->render ( "/admin/invoicePrintDetail", $this->data );
  2237. }
  2238. /**
  2239. * 所有待打印 发票
  2240. */
  2241. function invoicePrintStayAchieve() {
  2242. Doo::loadModel ( 'invoice' );
  2243. $invoice = new invoice ();
  2244. Doo::loadClass ( 'XDeode' );
  2245. $XDeode = new XDeode ( 5 );
  2246. Doo::loadModel ( 'staff' );
  2247. $staff = new staff ();
  2248. $MebSea = $this->get_args ( 'MebSea' ) ? urldecode ( $this->get_args ( 'MebSea' ) ) : "";
  2249. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  2250. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  2251. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  2252. Doo::loadModel ( 'invoiceTraining' );
  2253. $invoiceTraining = new invoiceTraining ();
  2254. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  2255. $page_size = 12;
  2256. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2257. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : "ALL";
  2258. // $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : "ALL";
  2259. $get = "/" . $status;
  2260. $con = ' and status=2 ';
  2261. if ($status == 'TOPRINT')
  2262. $con = ' and status=2 and printStatus=0 ';
  2263. elseif ($status == 'PRINTED')
  2264. $con = ' and status=2 and printStatus=1';
  2265. if ($invoiceType == 'ORDINARY')
  2266. $con .= ' and invoiceType=0 ';
  2267. elseif ($invoiceType == 'SPECIAL')
  2268. $con .= ' and invoiceType=1 ';
  2269. if ($invoiceTrain == 'ORDINARY')
  2270. $con .= ' and trainId=0 ';
  2271. elseif ($invoiceTrain == 'TRAIN')
  2272. $con .= ' and trainId!=0 ';
  2273. if ($invoiceTrainName != 'ALL') {
  2274. $trainId = $XDeode->decode ( $invoiceTrainName );
  2275. if (is_numeric ( $trainId ))
  2276. $con .= ' and trainId =' . $trainId;
  2277. }
  2278. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2279. $dateArr = explode ( ':', $date );
  2280. $D1 = '';
  2281. $D2 = '';
  2282. if (! empty ( $date )) {
  2283. $D1 = $dateArr [0];
  2284. $D2 = $dateArr [1];
  2285. }
  2286. if (! empty ( $D1 ) && ! empty ( $D2 ) && ! empty ( $date ))
  2287. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2288. if (! empty ( $MebSea )) {
  2289. $con .= ' and ( invoiceNo like "%' . $MebSea . '%" or invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  2290. }
  2291. $pageinfo ['page'] = array (
  2292. 'previous' => ''
  2293. );
  2294. $get .= "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&invoiceType=" . urlencode ( $invoiceType ) . "&invoiceTrain=" . urlencode ( $invoiceTrain ) . "";
  2295. $sql = " (untreadStatus=0 or untreadStatus=3) and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  2296. $action = "invoicePrintStayAchieve";
  2297. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2298. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2299. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  2300. $this->data ['trainList'] = $trainList;
  2301. $this->data ['invoiceType'] = $invoiceType;
  2302. $this->data ['invoiceTrain'] = $invoiceTrain;
  2303. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  2304. $this->data ['MebSeaEn'] = $MebSea;
  2305. $this->data ['MebSea'] = urlencode ( $MebSea );
  2306. $this->data ['get'] = $get;
  2307. $this->data ['page'] = $pageinfo;
  2308. $this->data ['date'] = $date;
  2309. $this->data ['status'] = $status;
  2310. $this->data ['invoiceType'] = $invoiceType;
  2311. $this->data ['memu'] = "invoice";
  2312. $this->data ['staff'] = $this->staff;
  2313. foreach ( $list as $key => $value ) {
  2314. $list [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2315. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2316. if (! empty ( $lastApprover )) {
  2317. $lastApproverKey = array_keys ( $lastApprover );
  2318. $lastApprover = end ( $lastApprover );
  2319. $staffDetail = $staff->getOne ( array (
  2320. 'where' => 'sid=' . end ( $lastApproverKey ),
  2321. 'asArray' => true
  2322. ) );
  2323. $lastApprover ['username'] = $staffDetail ['username'];
  2324. }
  2325. $list [$key] ['lastApprover'] = $lastApprover;
  2326. }
  2327. $this->data ['receiptMemu'] = 'invoicePrint';
  2328. $this->data ['list'] = $list;
  2329. $this->render ( "/admin/invoicePrintStayAchieve", $this->data );
  2330. }
  2331. /**
  2332. * 填写票号并完成打印
  2333. * @since 1.0.0
  2334. */
  2335. function invoicePrintDo() {
  2336. Doo::loadModel ( 'invoice' );
  2337. $invoice = new invoice ();
  2338. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2339. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  2340. $invoicePrintType = $this->get_args ( 'invoicePrintType' ) ? $this->get_args ( 'invoicePrintType' ) : "";
  2341. $iid = $invoice->authcode ( $iid );
  2342. if (! is_numeric ( $iid ))
  2343. die ( 'illegal request' );
  2344. if (! empty ( $iid ) && ! empty ( $invoiceNo )) {
  2345. Doo::loadModel ( 'invoiceOperationLog' );
  2346. $invoiceOperationLog = new invoiceOperationLog ();
  2347. Doo::loadModel ( 'invoiceStatistics' );
  2348. $invoiceStatistics = new invoiceStatistics ();
  2349. $XDeode = new XDeode ( 5 );
  2350. Doo::loadModel ( 'invoicePaper' );
  2351. $invoicePaper = new invoicePaper ();
  2352. $invoicePrintDetail = $invoice->getInvoiceByPrint ( $iid );
  2353. if (empty ( $invoicePrintDetail ))
  2354. die ( 'illegal request' );
  2355. //
  2356. $ipid = $XDeode->decode ( $invoiceNo );
  2357. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  2358. if (empty ( $paperDetail ))
  2359. die ( 'illegal request' );
  2360. $invoicePaper = new invoicePaper ();
  2361. $item = array (
  2362. 'iid' => $iid,
  2363. 'ipid' => $ipid
  2364. );
  2365. $invoicePaper->setInvoicePaperByCondition ( $item );
  2366. $item = array (
  2367. 'iid' => $iid,
  2368. 'printStatus' => 1,
  2369. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2370. 'printer' => $this->staff [0] ['username'],
  2371. 'printTime' => date ( "Y-m-d H:i:s" ),
  2372. 'invoiceNo' => $paperDetail ['invoiceNo']
  2373. );
  2374. $invoice->setInvoiceByCondition ( $item );
  2375. $item = array (
  2376. 'date' => date ( "Y-m-d H:i:s" ),
  2377. 'operation' => '打印发票号:' . $paperDetail ['invoiceNo'],
  2378. 'status' => 5,
  2379. 'img' => $this->staff [0] ['avatar'],
  2380. 'username' => $this->staff [0] ['username'],
  2381. 'uid' => $this->staff [0] ['sid'],
  2382. 'category' => $this->staff [0] ['category'],
  2383. 'iid' => $iid
  2384. );
  2385. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2386. // 去统计--负票不汇总
  2387. if ($invoicePrintDetail ['untreadStatus'] != 4) {
  2388. $item = array (
  2389. 'date' => date ( "Y-m-d H:i:s" ),
  2390. 'priceClass' => 1,
  2391. 'cid' => $invoicePrintDetail ['cid'],
  2392. 'staff' => $invoicePrintDetail ['sid'],
  2393. 'invoicePrice' => $invoicePrintDetail ['invoicePrice']
  2394. );
  2395. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2396. }
  2397. // 发送通知信息到微信-去除
  2398. // $this->setWXMsg($iid,'PRINT');
  2399. // 发票信息库
  2400. $this->autoUpdateInvoiceInfoBase ( $invoicePrintDetail );
  2401. // 申请人获取微信通知
  2402. Doo::loadModel ( 'staff' );
  2403. $staff = new staff ();
  2404. Doo::loadClass ( 'XDeode' );
  2405. $XDeode = new XDeode ( 5 );
  2406. $username2 = $staff->getOne ( array (
  2407. 'select' => 'wxid',
  2408. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2409. 'asArray' => TRUE
  2410. ) );
  2411. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '完成打印';
  2412. $msg = '';
  2413. $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/' . $XDeode->encode ( $invoicePrintDetail ['iid'] ) . '.html';
  2414. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2415. if (empty ( $invoicePrintType ))
  2416. return "/invoicePrint";
  2417. else
  2418. return "/invoicePrintStayAchieve";
  2419. }
  2420. }
  2421. /**
  2422. * 需要邮寄的发票
  2423. * @since 1.0.0
  2424. */
  2425. function invoicePost() {
  2426. Doo::loadModel ( 'invoice' );
  2427. $invoice = new invoice ();
  2428. Doo::loadModel ( 'express' );
  2429. $express = new express ();
  2430. $invoicePost = $invoice->getPostByInvoice ();
  2431. $invoicePosted = $invoice->getPostByInvoice ( 1 );
  2432. $expressList = $express->getExpressByAll ();
  2433. $invoicePostExpress = "";
  2434. if (isset ( $_COOKIE ["invoicePostExpress"] ))
  2435. $invoicePostExpress = $_COOKIE ["invoicePostExpress"];
  2436. $this->data ['invoicePostExpress'] = $invoicePostExpress;
  2437. $this->data ['expressList'] = $expressList;
  2438. $this->data ['invoicePost'] = $invoicePost;
  2439. $this->data ['invoicePosted'] = $invoicePosted;
  2440. $this->data ['memu'] = "invoice";
  2441. $this->data ['staff'] = $this->staff;
  2442. $this->data ['receiptMemu'] = 'invoicePost';
  2443. $this->render ( "/admin/invoicePost", $this->data );
  2444. }
  2445. /**
  2446. * 添加发票邮寄信息
  2447. */
  2448. function invoiceExpressAddDo() {
  2449. Doo::loadModel ( 'invoice' );
  2450. $invoice = new invoice ();
  2451. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2452. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2453. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2454. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2455. $iid = $iid = $invoice->authcode ( $iid );
  2456. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2457. die ( 'illegal request' );
  2458. $invoicePrintDetail = $invoice->getInvoiceByIid ( $iid );
  2459. setcookie ( 'invoicePostExpress', $expressNumber );
  2460. $item = array (
  2461. 'iid' => $iid,
  2462. 'postStatus' => 1,
  2463. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2464. 'postTime' => date ( "Y-m-d H:i:s" ),
  2465. 'expressCompany' => $expressCompany,
  2466. 'expressNumber' => $expressNumber,
  2467. 'actualItems' => $actualItems,
  2468. 'poster' => $this->staff [0] ['username']
  2469. );
  2470. $invoice->setInvoiceByCondition ( $item );
  2471. // 微信通知-去掉
  2472. // $this->setWXMsg ( $iid );
  2473. Doo::loadModel ( 'staff' );
  2474. $staff = new staff ();
  2475. Doo::loadClass ( 'XDeode' );
  2476. $XDeode = new XDeode ( 5 );
  2477. $username2 = $staff->getOne ( array (
  2478. 'select' => 'wxid',
  2479. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2480. 'asArray' => TRUE
  2481. ) );
  2482. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '已邮寄';
  2483. $expCom = explode ( ":", $invoicePrintDetail ['expressCompany'] );
  2484. if (empty ( $expCom ))
  2485. $expCom [0] = '';
  2486. $msg = $expCom [0] . ':' . $invoicePrintDetail ['expressNumber'] . '';
  2487. $url = 'https://m.kuaidi100.com/result.jsp?nu=' . $invoicePrintDetail ['expressNumber'];
  2488. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2489. return '/invoicePost';
  2490. }
  2491. function invoiceExpressUpdateDo() {
  2492. Doo::loadModel ( 'invoice' );
  2493. $invoice = new invoice ();
  2494. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  2495. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2496. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2497. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2498. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2499. $iid = $invoice->authcode ( $iid );
  2500. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2501. die ( 'illegal request' );
  2502. $item = array (
  2503. 'iid' => $iid,
  2504. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2505. 'expressCompany' => $expressCompany,
  2506. 'expressNumber' => $expressNumber,
  2507. 'actualItems' => $actualItems,
  2508. 'poster' => $this->staff [0] ['username']
  2509. );
  2510. $invoice->setInvoiceByCondition ( $item );
  2511. return $action;
  2512. }
  2513. /**
  2514. * 可退票管理
  2515. */
  2516. function invoiceUntreadIsAchieve() {
  2517. Doo::loadModel ( 'invoice' );
  2518. $invoice = new invoice ();
  2519. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2520. /*
  2521. * Doo::loadClass ( 'XDeode' ); $XDeode = new XDeode ( 5 ); $page_size = 18; $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1; $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : ""; $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ); $dateArr = explode ( ':', $date ); $D1 = ''; $D2 = ''; if (! empty ( $date )) { $D1 = $dateArr [0]; $D2 = $dateArr [1]; } $con = ''; if (! empty ( $D1 ) && ! empty ( $D2 )) $con = ' and bindTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" '; // if ($date == 'MONTHO') // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)'; // elseif ($date == 'MONTHT') // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)'; // elseif ($date == 'MONTHY') // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)'; if (! empty ( $MebSea )) { $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )'; } $pageinfo ['page'] = array ( 'previous' => '' );
  2522. */
  2523. if (empty ( $MebSea )) {//
  2524. $con = ' and invoiceNo like "NULL" ';
  2525. } else {
  2526. $con = ' and (invoiceNo like "%' . $MebSea . '%" or invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  2527. }
  2528. // printStatus=1 and
  2529. $sql = " (untreadStatus=0 or untreadStatus=3) and status=2 and sid=" . $this->staff [0] ['sid'] . $con;
  2530. /*
  2531. * $action = "invoiceUntreadIsAchieve"; $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" ); $limit = $pageinfo ['lower'] . ',' . $page_size;
  2532. */
  2533. $limit = '0,20';
  2534. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2535. // print_r($list);
  2536. $this->data ['MebSeaEn'] = $MebSea;
  2537. /*
  2538. * $this->data ['get'] = $get; $this->data ['page'] = $pageinfo; $this->data ['date'] = $date;
  2539. */
  2540. $this->data ['list'] = $list;
  2541. $this->data ['memu'] = "invoice";
  2542. $this->data ['staff'] = $this->staff;
  2543. $this->data ['receiptMemu'] = 'invoice';
  2544. $this->render ( "/admin/invoiceUntreadIsAchieve", $this->data );
  2545. }
  2546. // 已经退票的发票
  2547. function invoiceUntreadED() {
  2548. Doo::loadModel ( 'invoice' );
  2549. $invoice = new invoice ();
  2550. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2551. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "";
  2552. Doo::loadClass ( 'XDeode' );
  2553. $XDeode = new XDeode ( 5 );
  2554. $page_size = 18;
  2555. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2556. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2557. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  2558. $dateArr = explode ( ':', $date );
  2559. $D1 = '';
  2560. $D2 = '';
  2561. if (! empty ( $date )) {
  2562. $D1 = $dateArr [0];
  2563. $D2 = $dateArr [1];
  2564. }
  2565. $con = '';
  2566. if (! empty ( $D1 ) && ! empty ( $D2 )) {
  2567. $con = ' and bindTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2568. }
  2569. // if ($date == 'MONTHO')
  2570. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  2571. // elseif ($date == 'MONTHT')
  2572. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  2573. // elseif ($date == 'MONTHY')
  2574. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  2575. if (! empty ( $MebSea )) {
  2576. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  2577. }
  2578. if ($invoiceType == 'ORDINARY') {
  2579. $con .= ' and invoiceType=0 ';
  2580. } elseif ($invoiceType == 'SPECIAL') {
  2581. $con .= ' and invoiceType=1 ';
  2582. }
  2583. $pageinfo ['page'] = array (
  2584. 'previous' => ''
  2585. );
  2586. // printStatus=1 and
  2587. $sql = " (untreadStatus=2 ) and status=2 and sid=" . $this->staff [0] ['sid'] . $con;
  2588. $action = "invoiceUntreadED";
  2589. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2590. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2591. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2592. // print_r($list);
  2593. $this->data ['MebSeaEn'] = $MebSea;
  2594. $this->data ['get'] = $get;
  2595. $this->data ['page'] = $pageinfo;
  2596. $this->data ['date'] = $date;
  2597. $this->data ['invoiceType'] = $invoiceType;
  2598. $this->data ['list'] = $list;
  2599. $this->data ['memu'] = "invoice";
  2600. $this->data ['staff'] = $this->staff;
  2601. $this->data ['receiptMemu'] = 'invoice';
  2602. $this->render ( "/admin/invoiceUntreadED", $this->data );
  2603. }
  2604. /**
  2605. * 退票处理页面
  2606. */
  2607. function invoiceUntread() {
  2608. Doo::loadModel ( 'invoice' );
  2609. $invoice = new invoice ();
  2610. $untreadInvoice = $invoice->getInvoiceByUntreadStatus ( 1, 0, 50 );
  2611. $establishedInvoice = $invoice->getInvoiceByUntreadStatus ( 2 );
  2612. foreach ( $establishedInvoice as $key => $value ) {
  2613. // months
  2614. $lossDate = strtotime ( "+1 month", strtotime ( $value ['OperationLog'] ['date'] ) );
  2615. $nowDate = strtotime ( 'now' );
  2616. $establishedInvoice [$key] ['lossShow'] = false;
  2617. if ($lossDate < $nowDate)
  2618. $establishedInvoice [$key] ['lossShow'] = true;
  2619. }
  2620. $this->data ['untreadInvoice'] = $untreadInvoice;
  2621. $this->data ['establishedInvoice'] = $establishedInvoice;
  2622. $this->data ['memu'] = "invoice";
  2623. $this->data ['staff'] = $this->staff;
  2624. $this->data ['receiptMemu'] = 'invoiceUntread';
  2625. $this->render ( "/admin/invoiceUntread", $this->data );
  2626. }
  2627. /**
  2628. * 确认收到退回的发票,开票状态为退回 //收款状态解绑,公司统计扣除入账额度
  2629. */
  2630. function invoiceUntreadEstablishedDo() {
  2631. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  2632. Doo::loadModel ( 'invoice' );
  2633. $invoice = new invoice ();
  2634. Doo::loadModel ( 'invoiceOperationLog' );
  2635. $invoiceOperationLog = new invoiceOperationLog ();
  2636. Doo::loadModel ( 'invoiceReceivables' );
  2637. Doo::loadModel ( 'invoiceStatistics' );
  2638. $iid = $invoice->authcode ( $untreadIidKey );
  2639. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2640. die ( 'illegal request' );
  2641. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  2642. if ($invoiceDetails ['untreadStatus'] != 1)
  2643. die ( 'illegal request untreadStatus error !=1' );
  2644. $item = array (
  2645. 'iid' => $iid,
  2646. // 'irid'=>'',
  2647. 'untreadStatus' => 2,
  2648. 'updateTime' => date ( "Y-m-d H:i:s" )
  2649. );
  2650. $invoice->setInvoiceByCondition ( $item );
  2651. $item = array (
  2652. 'date' => date ( "Y-m-d H:i:s" ),
  2653. 'operation' => '已确认退票',
  2654. 'status' => 6,
  2655. 'img' => $this->staff [0] ['avatar'],
  2656. 'username' => $this->staff [0] ['username'],
  2657. 'uid' => $this->staff [0] ['sid'],
  2658. 'category' => $this->staff [0] ['category'],
  2659. 'iid' => $iid
  2660. );
  2661. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2662. // 收款解绑以及入账扣除 收款扣除
  2663. if (! empty ( $invoiceDetails ['irid'] )) {
  2664. $iridList = explode ( ',', $invoiceDetails ['irid'] );
  2665. foreach ( $iridList as $value ) {
  2666. $invoiceReceivables = new invoiceReceivables ();
  2667. $irDetails = $invoiceReceivables->getOne ( array (
  2668. 'where' => " irid=" . $value . ' and bindStatus=1',
  2669. 'asArray' => TRUE
  2670. ) );
  2671. $item = array (
  2672. 'irid' => $value,
  2673. 'bindStatus' => 0,
  2674. 'untreadStatus' => 1,
  2675. 'untreadStaff' => $invoiceDetails ['userName'],
  2676. 'unbundlingTime' => date ( "Y-m-d H:i:s" ),
  2677. 'iid' => 0
  2678. );
  2679. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2680. if (! empty ( $irDetails )) {
  2681. // 扣除入账
  2682. $invoiceStatistics = new invoiceStatistics ();
  2683. $item = array (
  2684. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2685. 'priceClass' => 3,
  2686. 'cid' => $invoiceDetails ['cid'],
  2687. 'staff' => $invoiceDetails ['sid'],
  2688. 'accountPrice' => - $irDetails ['receivablesPrice']
  2689. );
  2690. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2691. // 扣除收款
  2692. $invoiceStatistics = new invoiceStatistics ();
  2693. $item = array (
  2694. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2695. 'priceClass' => 2,
  2696. 'cid' => $invoiceDetails ['cid'],
  2697. 'staff' => $invoiceDetails ['sid'],
  2698. 'irid' => $irDetails ['irid'],
  2699. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  2700. );
  2701. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2702. }
  2703. // 解绑时删除收入流水
  2704. Doo::loadModel ( 'wasteBook' );
  2705. $wasteBook = new wasteBook ();
  2706. $wasteBook->delete ( array (
  2707. 'where' => 'dataID=' . $value . ' and accountType=7',
  2708. 'limit' => 1
  2709. ) );
  2710. }
  2711. }
  2712. return "/invoiceUntread";
  2713. }
  2714. function invoiceUntreadRecallDo() {
  2715. $iidKey = isset ( $this->params ['iidKey'] ) ? $this->params ['iidKey'] : "";
  2716. Doo::loadModel ( 'invoice' );
  2717. $invoice = new invoice ();
  2718. Doo::loadClass ( 'XDeode' );
  2719. $XDeode = new XDeode ( 5 );
  2720. Doo::loadModel ( 'invoiceOperationLog' );
  2721. $invoiceOperationLog = new invoiceOperationLog ();
  2722. $iid = $XDeode->decode ( $iidKey );
  2723. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  2724. if (empty ( $invoiceDetail )) {
  2725. die ( 'illegal request-DATANULL' );
  2726. }
  2727. $item = array (
  2728. 'iid' => $iid,
  2729. 'untreadStatus' => 0
  2730. );
  2731. $invoice->setInvoiceByCondition ( $item );
  2732. $item = array (
  2733. 'date' => date ( "Y-m-d H:i:s" ),
  2734. 'operation' => '撤回申请退票',
  2735. 'status' => 13,
  2736. 'img' => $this->staff [0] ['avatar'],
  2737. 'username' => $this->staff [0] ['username'],
  2738. 'uid' => $this->staff [0] ['sid'],
  2739. 'category' => $this->staff [0] ['category'],
  2740. 'iid' => $iid
  2741. );
  2742. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2743. return "/invoiceUntread";
  2744. }
  2745. /**
  2746. * 建立负票,关联原来发票
  2747. */
  2748. function invoiceLossDo() {
  2749. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2750. if (! empty ( $iidKey )) {
  2751. Doo::loadClass ( 'XDeode' );
  2752. $XDeode = new XDeode ( 5 );
  2753. Doo::loadModel ( 'invoice' );
  2754. $invoice = new invoice ();
  2755. Doo::loadModel ( 'invoiceOperationLog' );
  2756. $invoiceOperationLog = new invoiceOperationLog ();
  2757. $iidKey = $XDeode->decode ( $iidKey );
  2758. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  2759. // 拷贝插入一条发票数据
  2760. $iid = $invoice->setInvoiceLoss ( $iidKey );
  2761. // 更新负票
  2762. $invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  2763. $invoice = new invoice ();
  2764. $item = array (
  2765. 'iid' => $iid,
  2766. 'sid' => $this->staff [0] ['sid'],
  2767. 'userName' => $this->staff [0] ['username'],
  2768. 'cid' => $this->staff [0] ['cid'],
  2769. 'categoryName' => $this->staff [0] ['category'],
  2770. 'invoiceQuantity' => - $invoiceDetail ['invoiceQuantity'],
  2771. 'invoicePrice' => - $invoiceDetail ['invoicePrice'],
  2772. 'invoiceSerial' => $invoiceSerial,
  2773. 'invoiceNo' => '',
  2774. 'printStatus' => 0,
  2775. 'untreadStatus' => 4,
  2776. // 关联发票号
  2777. 'lossIid' => $invoiceDetail ['iid']
  2778. );
  2779. $invoice->setInvoiceByCondition ( $item );
  2780. // 更新原发票
  2781. $invoice = new invoice ();
  2782. $item = array (
  2783. 'iid' => $invoiceDetail ['iid'],
  2784. 'lossIid' => $iid
  2785. );
  2786. $invoice->setInvoiceByCondition ( $item );
  2787. // 操作日志
  2788. $item = array (
  2789. 'date' => date ( "Y-m-d H:i:s" ),
  2790. 'operation' => "创建负票" . $invoiceSerial,
  2791. 'status' => 12,
  2792. 'img' => $this->staff [0] ['avatar'],
  2793. 'username' => $this->staff [0] ['username'],
  2794. 'uid' => $this->staff [0] ['sid'],
  2795. 'category' => $this->staff [0] ['category'],
  2796. 'iid' => $iid
  2797. );
  2798. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2799. // print_r($invoiceDetail);
  2800. // echo $iid;die;
  2801. }
  2802. return '/invoiceUntread';
  2803. }
  2804. /**
  2805. * 上传银行到账 收款文件
  2806. */
  2807. function invoiceReceivablesBankUpload() {
  2808. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  2809. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  2810. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  2811. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  2812. header ( "HTTP/1.1 500 Internal Server Error" );
  2813. echo "POST exceeded maximum allowed size.";
  2814. exit ( 0 );
  2815. }
  2816. // Settings
  2817. $save_path = DOO::conf ()->SITE_PATH . "upload/invoiceReceivablesBank/"; // The path were we will save the file (getcwd() may not be reliable and should be tested in your environment)
  2818. $upload_name = "Filedata";
  2819. $file_name = "";
  2820. $nk = time ();
  2821. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  2822. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  2823. echo "文件无法保存.";
  2824. exit ( 0 );
  2825. }
  2826. echo json_encode ( array (
  2827. 'filename' => $file_name,
  2828. 'id' => $nk
  2829. ) );
  2830. exit ( 0 );
  2831. }
  2832. /**
  2833. * 解析银行到账收款execl并导入库中
  2834. */
  2835. function invoiceReceivablesImport() {
  2836. $path = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  2837. if ($path != "") {
  2838. Doo::loadModel ( 'invoiceReceivables' );
  2839. $invoiceReceivables = new invoiceReceivables ();
  2840. Doo::loadClass ( 'invoice.func' );
  2841. Doo::loadModel ( 'invoiceROLog' );
  2842. $invoiceROLog = new invoiceROLog ();
  2843. Doo::loadModel ( 'invoiceStatistics' );
  2844. $invoiceStatistics = new invoiceStatistics ();
  2845. $exlArray = formatExcelToArrayBank ( DOO::conf ()->SITE_PATH . "upload/invoiceReceivablesBank/" . $path );
  2846. $bankBatchNumber = 'BBN_' . time ();
  2847. Doo::db ()->beginTransaction ();
  2848. // 批量存储收款--由于必须获得收款ID,
  2849. $sql = 'INSERT INTO CLD_invoiceReceivables (OriginalPrice,receivablesPrice, receivablesMessage,receivablesSerial,receivablesBank,receivablesDate,inputStaff,date,receivablesCategory,receivablesStaff,bankBatchNumber,recepitTitleMark)
  2850. VALUES ';
  2851. $date = date ( "Y-m-d" );
  2852. $receivablesList = array ();
  2853. foreach ( $exlArray as $key => $value ) {
  2854. $receivablesSql = '(' . $value ["receivablesPrice"] . ',' . $value ["receivablesPrice"] . ',"' . $value ["receivablesMessage"] . '",' . '"#SK' . date ( "Ymd" ) . mt_rand ( 1000, 9999 ) . '","' . $value ["receivablesBank"] . '","' . $value ["receivablesDate"] . '","' . $this->staff [0] ['username'] . '","' . $date . '","PUBLIC","PUBLIC","' . $bankBatchNumber . '","' . $value ["receivablesMessage"] . '")';
  2855. array_push ( $receivablesList, $receivablesSql );
  2856. }
  2857. $sql = $sql . implode ( ',', $receivablesList );
  2858. // echo $sql;
  2859. Doo::db ()->query ( $sql );
  2860. // 批量存储收款统计
  2861. // 获得刚刚导入数据的irid组-缺少办事处和人员
  2862. $iridList = $invoiceReceivables->getInvoiceReceivablesByBBN ( $bankBatchNumber );
  2863. // 没有irid 回滚所有操作
  2864. if (empty ( $iridList )) {
  2865. Doo::db ()->rollBack ();
  2866. header ( 'Content-Type:text/html;charset=utf-8' );
  2867. die ( '文档或数据不正确,请重新<a href="/invoiceReceivables">上传</a>.' );
  2868. }
  2869. $sql = 'INSERT INTO CLD_invoiceStatistics (date, priceClass,irid,receivablesPrice)
  2870. VALUES ';
  2871. $statisticsList = array ();
  2872. foreach ( $iridList as $value ) {
  2873. $statisticsSql = '("' . $date . '",2,' . $value ['irid'] . ',' . $value ["receivablesPrice"] . ')';
  2874. array_push ( $statisticsList, $statisticsSql );
  2875. }
  2876. $sql = $sql . implode ( ',', $statisticsList );
  2877. Doo::db ()->query ( $sql );
  2878. // 批量存储操作日志
  2879. $sql = 'INSERT INTO CLD_invoiceROLog (operation, date,status,img, username,uid,category,irid)
  2880. VALUES ';
  2881. $ROLogList = array ();
  2882. foreach ( $iridList as $value ) {
  2883. $ROLogSql = '("' . $this->staff [0] ['username'] . ' 转入 公共待认领款项","' . $date . '",1,"' . $this->staff [0] ['avatar'] . '","' . $this->staff [0] ['username'] . '","' . $this->staff [0] ['sid'] . '","' . $this->staff [0] ['category'] . '","' . $value ['irid'] . '")';
  2884. array_push ( $ROLogList, $ROLogSql );
  2885. }
  2886. $sql = $sql . implode ( ',', $ROLogList );
  2887. Doo::db ()->query ( $sql );
  2888. // 批量写入流水
  2889. $sql = 'INSERT INTO CLD_wasteBook (dataID, expensesType,accountType,accountPriceShow, accountPrice,accountBank,category,cid,name,sid,inputDate)
  2890. VALUES ';
  2891. $wasteBookList = array ();
  2892. foreach ( $iridList as $value ) {
  2893. $accountBank = '';
  2894. if ($value ['receivablesBank'] == '纵横广发') {
  2895. $accountBank = 'CGBDeposit';
  2896. } elseif ($value ['receivablesBank'] == '纵横工行') {
  2897. $accountBank = 'ICBCDeposit';
  2898. } elseif ($value ['receivablesBank'] == '华润银行') {
  2899. $accountBank = 'HUADeposit';
  2900. } elseif ($value ['receivablesBank'] == '个人广发') {
  2901. $accountBank = 'PersonalDeposit';
  2902. }
  2903. $wasteBookSql = '("' . $value ['irid'] . ' ",1,7,"' . $value ['receivablesPrice'] . '","' . $value ['receivablesPrice'] . '","' . $accountBank . '",
  2904. "' . $this->staff [0] ['category'] . '","' . $this->staff [0] ['cid'] . '","' . $this->staff [0] ['username'] . '","' . $this->staff [0] ['sid'] . '","' . date ( "Y-m-d H:i:s" ) . '")';
  2905. array_push ( $wasteBookList, $wasteBookSql );
  2906. }
  2907. $sql = $sql . implode ( ',', $wasteBookList );
  2908. Doo::db ()->query ( $sql );
  2909. Doo::db ()->commit ();
  2910. return "/invoiceReceivables";
  2911. }
  2912. echo 'no file';
  2913. }
  2914. function invoiceReceivables() {
  2915. $invoiceTC = $this->get_args ( 'invoiceTC' ) ? $this->get_args ( 'invoiceTC' ) : '';
  2916. Doo::loadModel ( 'L_category' );
  2917. $lCategory = new L_category ();
  2918. Doo::loadModel ( 'staff' );
  2919. $staff = new staff ();
  2920. Doo::loadModel ( 'invoiceReceivables' );
  2921. $invoiceReceivables = new invoiceReceivables ();
  2922. Doo::loadModel ( 'invoice' );
  2923. $invoice = new invoice ();
  2924. Doo::loadClass ( 'XDeode' );
  2925. $XDeode = new XDeode ( 5 );
  2926. $category = $lCategory->getCategory ();
  2927. $staffList = $staff->getStaffByCid ( $this->staff [0] ['cid'] );
  2928. $sql = 'bindStatus=1 and iid!=0';
  2929. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByNew ( 4, $sql );
  2930. // 获取未入账发票
  2931. $invoiceUnAccount = $invoice->getInvoiceByUnAccount ( $invoiceTC );
  2932. $invoiceExistAccount = $invoice->getInvoiceByUnAccount ( '', true );
  2933. foreach ( $invoiceUnAccount as $key => $value ) {
  2934. $invoiceUnAccount [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2935. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2936. if (! empty ( $lastApprover )) {
  2937. $lastApproverKey = array_keys ( $lastApprover );
  2938. $lastApprover = end ( $lastApprover );
  2939. $staffDetail = $staff->getOne ( array (
  2940. 'where' => 'sid=' . end ( $lastApproverKey ),
  2941. 'asArray' => true
  2942. ) );
  2943. $lastApprover ['username'] = $staffDetail ['username'];
  2944. }
  2945. $invoiceUnAccount [$key] ['lastApprover'] = $lastApprover;
  2946. }
  2947. foreach ( $invoiceExistAccount as $key => $value ) {
  2948. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  2949. if (empty ( $irList ))
  2950. $irList [0] ['sumPrice'] = 0;
  2951. $balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  2952. $invoiceExistAccount [$key] ['existAccount'] = $irList [0] ['sumPrice'];
  2953. $invoiceExistAccount [$key] ['balance'] = $balance;
  2954. }
  2955. $receivablesInput = $invoiceReceivables->getInvoiceReceivablesByInput ();
  2956. $halfList = $invoiceReceivables->getInvoiceReceivablesByHalf ();
  2957. $this->data ['halfList'] = $halfList;
  2958. $this->data ['halfCount'] = count ( $halfList );
  2959. // print_r($receivablesList);
  2960. $this->data ['receivablesDate'] = date ( "Y-m-d" );
  2961. $this->data ['ieaCount'] = count ( $invoiceExistAccount );
  2962. $this->data ['invoiceExistAccount'] = $invoiceExistAccount;
  2963. $this->data ['receivablesInput'] = $receivablesInput;
  2964. $this->data ['year'] = date ( 'Y' );
  2965. $this->data ['invoiceUnAccount'] = $invoiceUnAccount;
  2966. $this->data ['receivablesList'] = $receivablesList;
  2967. $this->data ['staffList'] = $staffList;
  2968. $this->data ['category'] = $category;
  2969. $this->data ['memu'] = "invoice";
  2970. $this->data ['staff'] = $this->staff;
  2971. $this->data ['receiptMemu'] = 'invoiceReceivables';
  2972. $this->render ( "/admin/invoiceReceivables", $this->data );
  2973. }
  2974. /**
  2975. * 设置收款认领地区
  2976. */
  2977. function setInvoiceReceivablesClaim() {
  2978. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  2979. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  2980. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  2981. if (! empty ( $iridKey ) && ! empty ( $receivablesCategory )) {
  2982. Doo::loadModel ( 'invoiceReceivables' );
  2983. $invoiceReceivables = new invoiceReceivables ();
  2984. Doo::loadClass ( 'XDeode' );
  2985. $XDeode = new XDeode ( 5 );
  2986. Doo::loadModel ( 'invoiceROLog' );
  2987. $invoiceROLog = new invoiceROLog ();
  2988. $irid = $XDeode->decode ( $iridKey );
  2989. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  2990. if (empty ( $irDetail ))
  2991. die ( 'illegal request' );
  2992. $item = array (
  2993. 'irid' => $irid,
  2994. 'receivablesCategory' => $receivablesCategory
  2995. );
  2996. if ($receivablesCategory != 'PUBLIC') {
  2997. $item += array (
  2998. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  2999. 'inputType' => 1
  3000. );
  3001. }
  3002. $invoiceReceivables = new invoiceReceivables ();
  3003. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3004. // 收款操作日志
  3005. $item = array (
  3006. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 ",
  3007. 'date' => date ( "Y-m-d" ),
  3008. 'status' => 1,
  3009. 'img' => $this->staff [0] ['avatar'],
  3010. 'username' => $this->staff [0] ['username'],
  3011. 'uid' => $this->staff [0] ['sid'],
  3012. 'category' => $this->staff [0] ['category'],
  3013. 'irid' => $irid
  3014. );
  3015. $invoiceROLog->setInvoiceROLog ( $item );
  3016. if (empty ( $action ))
  3017. return '/invoiceReceivables';
  3018. else
  3019. return "/invoiceReceivablesAS";
  3020. }
  3021. die ( 'illegal request' );
  3022. }
  3023. /**
  3024. * 新添加收款直接入账发票
  3025. */
  3026. function invoiceCompareClaimPrice() {
  3027. // 收款录入
  3028. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  3029. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3030. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3031. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3032. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3033. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $iidKey )) {
  3034. Doo::loadModel ( 'invoiceReceivables' );
  3035. $invoiceReceivables = new invoiceReceivables ();
  3036. Doo::loadModel ( 'invoiceROLog' );
  3037. $invoiceROLog = new invoiceROLog ();
  3038. Doo::loadModel ( 'invoiceStatistics' );
  3039. Doo::loadModel ( 'invoice' );
  3040. $invoice = new invoice ();
  3041. Doo::loadClass ( 'XDeode' );
  3042. $XDeode = new XDeode ( 5 );
  3043. Doo::loadModel ( 'invoiceOperationLog' );
  3044. $invoiceOperationLog = new invoiceOperationLog ();
  3045. $iidKey = $XDeode->decode ( $iidKey );
  3046. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  3047. if (! ($invoiceDetail ['status'] == 2 && $invoiceDetail ['printStatus'] == 1 && $invoiceDetail ['untreadStatus'] == 0))
  3048. die ( 'illegal request' );
  3049. $receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  3050. // 收款录入 并绑定发票
  3051. Doo::db ()->beginTransaction ();
  3052. $bindStatus = 0;
  3053. if ($receivablesPrice <= $invoiceDetail ['invoicePrice']){
  3054. $bindStatus = 1;
  3055. }
  3056. $titleMark = $invoiceDetail ['invoiceTitle'];
  3057. if (! empty ( $invoiceDetail ['invoiceCompany'] ))
  3058. $titleMark = $invoiceDetail ['invoiceCompany'];
  3059. $item = array (
  3060. 'recepitTitleMark' => $titleMark,
  3061. 'bindStatus' => $bindStatus,
  3062. 'iid' => $invoiceDetail ['iid'],
  3063. 'bindPrice' => $invoiceDetail ['invoicePrice'],
  3064. 'bindDate' => date ( "Y-m-d H:i:s" ),
  3065. 'receivablesPrice' => $receivablesPrice,
  3066. 'OriginalPrice' => $receivablesPrice,
  3067. 'receivablesMessage' => $receivablesMessage,
  3068. 'receivablesSerial' => $receivablesSerial,
  3069. 'receivablesBank' => $receivablesBank,
  3070. 'receivablesDate' => $receivablesDate,
  3071. 'inputStaff' => $this->staff [0] ['username'],
  3072. 'accountClerk' => $this->staff [0] ['username'],
  3073. 'date' => date ( "Y-m-d" ),
  3074. 'receivablesCategory' => $invoiceDetail ['cid'] . ':' . $invoiceDetail ['categoryName'],
  3075. 'receivablesStaff' => $invoiceDetail ['sid'] . '-' . $invoiceDetail ['userName'],
  3076. 'confirmTime' => date ( "Y-m-d H:i:s" )
  3077. );
  3078. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  3079. $item = array ();
  3080. // 收款操作日志
  3081. $item = array (
  3082. 'operation' => $this->staff [0] ['username'] . " 转入 " . $invoiceDetail ['userName']
  3083. );
  3084. $item += array (
  3085. 'date' => date ( "Y-m-d" ),
  3086. 'status' => 1,
  3087. 'img' => $this->staff [0] ['avatar'],
  3088. 'username' => $this->staff [0] ['username'],
  3089. 'uid' => $this->staff [0] ['sid'],
  3090. 'category' => $this->staff [0] ['category'],
  3091. 'irid' => $irid
  3092. );
  3093. $invoiceROLog->setInvoiceROLog ( $item );
  3094. // 收款统计
  3095. $invoiceStatistics = new invoiceStatistics ();
  3096. $item = array (
  3097. 'date' => $receivablesDate,
  3098. 'priceClass' => 2,
  3099. 'irid' => $irid,
  3100. 'cid' => $invoiceDetail ['cid'],
  3101. 'staff' => $invoiceDetail ['sid'],
  3102. 'receivablesPrice' => $receivablesPrice
  3103. );
  3104. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3105. // 收款 入 发票
  3106. $detail = $invoiceDetail;
  3107. $iridString = "";
  3108. if (empty ( $detail ['irid'] ))
  3109. $iridString = $irid;
  3110. else
  3111. $iridString = $detail ['irid'] . ',' . $irid;
  3112. $item = array (
  3113. 'irid' => $iridString,
  3114. 'bindTime' => date ( "Y-m-d H:i:s" ),
  3115. 'updateTime' => date ( "Y-m-d H:i:s" ),
  3116. 'iid' => $detail ['iid']
  3117. );
  3118. $invoiceReceivables = new invoiceReceivables ();
  3119. $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  3120. if ($detail ['invoicePrice'] <= $sum)
  3121. $item += array (
  3122. 'untreadStatus' => 3
  3123. );
  3124. $invoice->setInvoiceByCondition ( $item );
  3125. // 操作日志
  3126. $item = array (
  3127. 'date' => date ( "Y-m-d H:i:s" ),
  3128. 'operation' => "收款入账" . $receivablesSerial . "到发票" . $detail ['invoiceSerial'],
  3129. 'status' => 8,
  3130. 'img' => $this->staff [0] ['avatar'],
  3131. 'username' => $this->staff [0] ['username'],
  3132. 'uid' => $this->staff [0] ['sid'],
  3133. 'category' => $this->staff [0] ['category'],
  3134. 'iid' => $detail ['iid']
  3135. );
  3136. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3137. // 入账汇总
  3138. $invoiceStatistics = new invoiceStatistics ();
  3139. // $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $iridString );
  3140. // $accountPrice = 0;
  3141. // foreach ( $list as $key => $value ) {
  3142. // $accountPrice += $value ['receivablesPrice'];
  3143. // }
  3144. $item = array (
  3145. 'date' => $receivablesDate,
  3146. 'priceClass' => 3,
  3147. 'cid' => $invoiceDetail ['cid'],
  3148. 'staff' => $invoiceDetail ['sid'],
  3149. 'accountPrice' => $receivablesPrice
  3150. );
  3151. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3152. // 公司流水记录
  3153. Doo::loadModel ( 'wasteBook' );
  3154. $wasteBook = new wasteBook ();
  3155. $abDetail = $wasteBook->getAccountBookByAid ( 2, 7, $irid );
  3156. $accountBank = '';
  3157. if ($receivablesBank == '纵横广发') {
  3158. $accountBank = 'CGBDeposit';
  3159. } elseif ($receivablesBank == '纵横工行') {
  3160. $accountBank = 'ICBCDeposit';
  3161. } elseif ($receivablesBank == '华润银行') {
  3162. $accountBank = 'HUADeposit';
  3163. } elseif ($receivablesBank == '个人广发') {
  3164. $accountBank = 'PersonalDeposit';
  3165. }
  3166. if (empty ( $abDetail )) {
  3167. $item = array (
  3168. 'dataID' => $irid,
  3169. 'expensesType' => 1,
  3170. 'accountType' => 7,
  3171. 'accountPrice' => $receivablesPrice,
  3172. 'accountPriceShow' => $receivablesPrice,
  3173. 'accountBank' => $accountBank,
  3174. 'category' => $this->staff [0] ['category'],
  3175. 'cid' => $this->staff [0] ['cid'],
  3176. 'name' => $this->staff [0] ['username'],
  3177. 'sid' => $this->staff [0] ['sid'],
  3178. 'inputDate' => date ( "Y-m-d H:i:s" )
  3179. );
  3180. $wasteBook->setAccountBookStatistics ( $item );
  3181. }
  3182. Doo::db ()->commit ();
  3183. }
  3184. return '/invoiceReceivables';
  3185. }
  3186. /**
  3187. * 录入收款数据
  3188. * @return string
  3189. */
  3190. function invoiceReceivablesDo() {
  3191. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3192. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3193. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3194. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3195. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3196. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  3197. Doo::loadModel ( 'invoiceReceivables' );
  3198. $invoiceReceivables = new invoiceReceivables ();
  3199. Doo::loadModel ( 'invoiceROLog' );
  3200. $invoiceROLog = new invoiceROLog ();
  3201. Doo::loadModel ( 'invoiceStatistics' );
  3202. $invoiceStatistics = new invoiceStatistics ();
  3203. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $receivablesCategory ) && ! empty ( $receivablesStaff )) {
  3204. $item = array (
  3205. 'receivablesPrice' => $receivablesPrice,
  3206. 'OriginalPrice' => $receivablesPrice,
  3207. 'receivablesMessage' => $receivablesMessage,
  3208. 'receivablesSerial' => "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  3209. 'receivablesBank' => $receivablesBank,
  3210. 'receivablesDate' => $receivablesDate,
  3211. 'inputStaff' => $this->staff [0] ['username'],
  3212. 'date' => date ( "Y-m-d" ),
  3213. 'receivablesCategory' => $receivablesCategory,
  3214. 'receivablesStaff' => $receivablesStaff
  3215. );
  3216. if ($receivablesCategory != 'PUBLIC') {
  3217. $item += array (
  3218. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3219. 'inputType' => 1
  3220. );
  3221. }
  3222. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  3223. $item = array ();
  3224. // 收款操作日志
  3225. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3226. $item = array (
  3227. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  3228. );
  3229. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3230. $item = array (
  3231. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  3232. );
  3233. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3234. $receivablesStaff = explode ( '-', $receivablesStaff );
  3235. $item = array (
  3236. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  3237. );
  3238. }
  3239. $item += array (
  3240. 'date' => date ( "Y-m-d" ),
  3241. 'status' => 1,
  3242. 'img' => $this->staff [0] ['avatar'],
  3243. 'username' => $this->staff [0] ['username'],
  3244. 'uid' => $this->staff [0] ['sid'],
  3245. 'category' => $this->staff [0] ['category'],
  3246. 'irid' => $irid
  3247. );
  3248. $invoiceROLog->setInvoiceROLog ( $item );
  3249. $item = array (
  3250. 'date' => $receivablesDate,
  3251. 'priceClass' => 2,
  3252. 'irid' => $irid,
  3253. 'receivablesPrice' => $receivablesPrice
  3254. );
  3255. if ($receivablesCategory != 'PUBLIC') {
  3256. $receivablesCategory = explode ( ":", $receivablesCategory );
  3257. $item += array (
  3258. 'cid' => $receivablesCategory [0]
  3259. );
  3260. }
  3261. if ($receivablesStaff2 != 'PUBLIC') {
  3262. $receivablesStaff = explode ( "-", $receivablesStaff2 );
  3263. $item += array (
  3264. 'staff' => $receivablesStaff [0]
  3265. );
  3266. }
  3267. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3268. $toparty = $this->getWxidByCategory ( $receivablesCategory [1] );
  3269. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  3270. $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  3271. if ($toparty != 0)
  3272. $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  3273. // 公司流水记录
  3274. Doo::loadModel ( 'wasteBook' );
  3275. $wasteBook = new wasteBook ();
  3276. $abDetail = $wasteBook->getAccountBookByAid ( 1, 7, $irid );
  3277. $accountBank = '';
  3278. if ($receivablesBank == '纵横广发') {
  3279. $accountBank = 'CGBDeposit';
  3280. } elseif ($receivablesBank == '纵横工行') {
  3281. $accountBank = 'ICBCDeposit';
  3282. } elseif ($receivablesBank == '华润银行') {
  3283. $accountBank = 'HUADeposit';
  3284. } elseif ($receivablesBank == '个人广发') {
  3285. $accountBank = 'PersonalDeposit';
  3286. }
  3287. $item = array (
  3288. 'dataID' => $irid,
  3289. 'expensesType' => 1,
  3290. 'accountType' => 7,
  3291. 'accountPriceShow' => $receivablesPrice,
  3292. 'accountPrice' => $receivablesPrice,
  3293. 'accountBank' => $accountBank,
  3294. 'category' => $this->staff [0] ['category'],
  3295. 'cid' => $this->staff [0] ['cid'],
  3296. 'name' => $this->staff [0] ['username'],
  3297. 'sid' => $this->staff [0] ['sid'],
  3298. 'inputDate' => date ( "Y-m-d H:i:s" )
  3299. );
  3300. $wasteBook->setAccountBookStatistics ( $item );
  3301. }
  3302. return "/invoiceReceivables";
  3303. }
  3304. /**
  3305. * 收款认领页面-包括公共认领 办事处认领 最近已认领数据
  3306. */
  3307. function invoiceReceivablesClaim() {
  3308. Doo::loadModel ( 'invoiceReceivables' );
  3309. $invoiceReceivables = new invoiceReceivables ();
  3310. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  3311. $this->data ['receivablesList'] = $receivablesList;
  3312. $this->data ['memu'] = "invoice";
  3313. $this->data ['staff'] = $this->staff;
  3314. $this->data ['receiptMemu'] = 'invoiceReceivablesClaim';
  3315. $this->render ( "/admin/invoiceReceivablesClaim", $this->data );
  3316. }
  3317. function invoiceReceivablesTitleMarkSet() {
  3318. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  3319. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  3320. if (empty ( $iridKey ) || empty ( $recepitTitleMark ))
  3321. die ( 'illegal request' );
  3322. Doo::loadModel ( 'invoiceReceivables' );
  3323. $invoiceReceivables = new invoiceReceivables ();
  3324. Doo::loadClass ( 'XDeode' );
  3325. $XDeode = new XDeode ( 5 );
  3326. $irid = $XDeode->decode ( $iridKey );
  3327. if (! is_numeric ( $irid ))
  3328. die ( 'illegal request' );
  3329. $invoiceReceivables->recepitTitleMark = $recepitTitleMark;
  3330. $invoiceReceivables->update ( array (
  3331. 'where' => 'irid = ' . $irid
  3332. ) );
  3333. return '/invoiceReceivablesClaim';
  3334. }
  3335. /**
  3336. * 更新收款相关数据
  3337. */
  3338. function invoiceReceivablesUpdateClaim() {
  3339. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3340. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3341. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3342. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3343. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3344. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  3345. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  3346. if (empty ( $claimKey ))
  3347. die ( 'illegal request' );
  3348. Doo::loadModel ( 'invoiceReceivables' );
  3349. $invoiceReceivables = new invoiceReceivables ();
  3350. Doo::loadModel ( 'invoiceROLog' );
  3351. $invoiceROLog = new invoiceROLog ();
  3352. $con = ' and iid=0 and bindStatus=0'; // and receivablesCategory!="PUBLIC" and receivablesStaff!="PUBLIC"
  3353. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  3354. if (empty ( $detail ))
  3355. die ( 'illegal request' );
  3356. $invoiceReceivables = new invoiceReceivables ();
  3357. $item = array (
  3358. 'irid' => $detail ['irid']
  3359. );
  3360. if ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3361. $item += array (
  3362. 'confirmTime' => date ( "Y-m-d H:i:s" )
  3363. );
  3364. }
  3365. if (! empty ( $receivablesCategory ))
  3366. $item += array (
  3367. 'receivablesCategory' => $receivablesCategory
  3368. );
  3369. if (! empty ( $receivablesStaff ))
  3370. $item += array (
  3371. 'receivablesStaff' => $receivablesStaff
  3372. );
  3373. if (! empty ( $receivablesPrice ))
  3374. $item += array (
  3375. 'receivablesPrice' => $receivablesPrice
  3376. );
  3377. if (! empty ( $receivablesMessage ))
  3378. $item += array (
  3379. 'receivablesMessage' => $receivablesMessage
  3380. );
  3381. if (! empty ( $receivablesBank ))
  3382. $item += array (
  3383. 'receivablesBank' => $receivablesBank
  3384. );
  3385. if (! empty ( $receivablesDate ))
  3386. $item += array (
  3387. 'receivablesDate' => $receivablesDate
  3388. );
  3389. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3390. // 收款操作日志
  3391. $item = array ();
  3392. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3393. $item = array (
  3394. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  3395. );
  3396. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3397. $item = array (
  3398. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  3399. );
  3400. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3401. $receivablesStaff = explode ( '-', $receivablesStaff );
  3402. $item = array (
  3403. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  3404. );
  3405. }
  3406. $item += array (
  3407. 'date' => date ( "Y-m-d" ),
  3408. 'status' => 1,
  3409. 'img' => $this->staff [0] ['avatar'],
  3410. 'username' => $this->staff [0] ['username'],
  3411. 'uid' => $this->staff [0] ['sid'],
  3412. 'category' => $this->staff [0] ['category'],
  3413. 'irid' => $detail ['irid']
  3414. );
  3415. $invoiceROLog->setInvoiceROLog ( $item );
  3416. return '/invoiceReceivablesAS';
  3417. }
  3418. function invoiceReceivablesDelete() {
  3419. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  3420. $skll = $this->get_args ( 'skll' ) ? $this->get_args ( 'skll' ) : "";
  3421. if ($skll != '删除到款')
  3422. die ( 'illegal request' );
  3423. if (empty ( $claimKey ))
  3424. die ( 'illegal request' );
  3425. Doo::loadModel ( 'invoiceReceivables' );
  3426. $invoiceReceivables = new invoiceReceivables ();
  3427. $con = ' and bindStatus=0 ';
  3428. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  3429. if (empty ( $detail ))
  3430. die ( 'illegal request' );
  3431. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  3432. // 扣除收款汇总信息 汇总
  3433. Doo::loadModel ( 'invoiceStatistics' );
  3434. $invoiceStatistics = new invoiceStatistics ();
  3435. $item = array (
  3436. 'date' => $detail ['receivablesDate'],
  3437. 'priceClass' => 2,
  3438. 'irid' => $detail ['irid'],
  3439. 'receivablesPrice' => - $detail ['receivablesPrice']
  3440. );
  3441. if ($detail ['receivablesCategory'] != 'PUBLIC') {
  3442. $receivablesCategory = explode ( ":", $detail ['receivablesCategory'] );
  3443. $item += array (
  3444. 'cid' => $receivablesCategory [0]
  3445. );
  3446. }
  3447. if ($detail ['receivablesStaff'] != 'PUBLIC') {
  3448. $receivablesStaff = explode ( "-", $detail ['receivablesStaff'] );
  3449. $item += array (
  3450. 'staff' => $receivablesStaff [0]
  3451. );
  3452. }
  3453. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3454. // 公司流水-删除时删除流水
  3455. Doo::loadModel ( 'wasteBook' );
  3456. $wasteBook = new wasteBook ();
  3457. $wasteBook->delete ( array (
  3458. 'where' => 'dataID=' . $detail ['irid'] . ' and accountType=7',
  3459. 'limit' => 1
  3460. ) );
  3461. return '/invoiceReceivablesAS';
  3462. }
  3463. /**
  3464. * 管理员录入的收款 ,确认认领到谁的名下.统计收款金额
  3465. */
  3466. function invoiceReceivablesAscription() {
  3467. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  3468. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  3469. Doo::loadModel ( 'invoiceReceivables' );
  3470. $invoiceReceivables = new invoiceReceivables ();
  3471. Doo::loadModel ( 'invoiceROLog' );
  3472. $invoiceROLog = new invoiceROLog ();
  3473. Doo::loadModel ( 'invoiceStatistics' );
  3474. $invoiceStatistics = new invoiceStatistics ();
  3475. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  3476. if (! empty ( $detail ) && $detail ['receivablesStaff'] == 'PUBLIC' && ! empty ( $recepitTitleMark )) {
  3477. $item = array (
  3478. 'irid' => $detail ['irid'],
  3479. 'receivablesCategory' => $this->staff [0] ['cid'] . ":" . $this->staff [0] ['category'],
  3480. 'receivablesStaff' => $this->staff [0] ['sid'] . "-" . $this->staff [0] ['username'],
  3481. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3482. 'recepitTitleMark' => $recepitTitleMark,
  3483. 'source' => 1
  3484. );
  3485. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3486. $item = array (
  3487. 'date' => date ( "Y-m-d" ),
  3488. 'operation' => $this->staff [0] ['username'] . " 认领 ",
  3489. 'status' => 2,
  3490. 'img' => $this->staff [0] ['avatar'],
  3491. 'username' => $this->staff [0] ['username'],
  3492. 'uid' => $this->staff [0] ['sid'],
  3493. 'category' => $this->staff [0] ['category'],
  3494. 'irid' => $irid
  3495. );
  3496. $invoiceROLog->setInvoiceROLog ( $item );
  3497. $item = array (
  3498. 'cid' => $this->staff [0] ['cid'],
  3499. 'staff' => $this->staff [0] ['sid']
  3500. );
  3501. $invoiceStatistics->updateInvoiceStatisticsByIrid ( $item, $detail ['irid'], 2 );
  3502. }
  3503. return "/invoiceReceivablesClaim";
  3504. }
  3505. /**
  3506. */
  3507. function invoiceMyReceivables() {
  3508. Doo::loadModel ( 'invoiceReceivables' );
  3509. $invoiceReceivables = new invoiceReceivables ();
  3510. Doo::loadModel ( 'invoiceStatistics' );
  3511. $invoiceStatistics = new invoiceStatistics ();
  3512. $isMonth = $invoiceStatistics->getStatisticsByMonth ( $this->staff [0] ['sid'] );
  3513. $year = date ( "Y" );
  3514. $tmp_date = date ( "Ym" );
  3515. $tmp_year = substr ( $tmp_date, 0, 4 );
  3516. $tmp_mon = substr ( $tmp_date, 4, 2 );
  3517. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  3518. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  3519. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . ".htm";
  3520. $htm = $this->showCache ( $path );
  3521. $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  3522. $this->data ['isMonth'] = $isMonth;
  3523. $this->data ['htm'] = $htm;
  3524. $this->data ['list'] = $list;
  3525. $this->data ['memu'] = "invoice";
  3526. $this->data ['staff'] = $this->staff;
  3527. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  3528. $this->render ( "/admin/invoiceMyReceivables", $this->data );
  3529. }
  3530. /**
  3531. * 纸票管理
  3532. */
  3533. function invoicePaper() {
  3534. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3535. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3536. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3537. $this->data ['dateString'] = $date;
  3538. $this->data ['status'] = $status;
  3539. $this->data ['invoiceType'] = $invoiceType;
  3540. $this->data ['memu'] = "invoice";
  3541. $this->data ['staff'] = $this->staff;
  3542. $this->data ['receiptMemu'] = 'invoicePaper';
  3543. $this->render ( "/admin/invoicePaper", $this->data );
  3544. }
  3545. /**
  3546. * 获得纸票分页数据
  3547. */
  3548. function ajaxGetinvoicePaperAchieve() {
  3549. Doo::loadModel ( 'invoicePaper' );
  3550. $invoicePaper = new invoicePaper ();
  3551. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3552. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3553. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ORDINARY";
  3554. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3555. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  3556. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  3557. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  3558. $MebSea = $this->get_args ( 'search' );
  3559. $MebSea = $MebSea ['value'];
  3560. $page_size = $length;
  3561. $con = '';
  3562. if ($status == 'ALL')
  3563. $con = ' where 1 ';
  3564. elseif ($status == 'PRINTED')
  3565. $con = ' where a.iid!=0 '; // $con = ' where b.isDelete=0 and a.iid!=0 and b.status=2 and b.untreadStatus=0 ';
  3566. elseif ($status == 'UNPRINT')
  3567. $con = ' where a.iid=0 '; // $con = ' where b.isDelete=0 and a.iid=0 and b.status=2 and b.untreadStatus=0 ';
  3568. elseif ($status == 'TICKET')
  3569. $con = ' where b.isDelete=0 and b.untreadStatus=2';
  3570. if ($invoiceType == 'ORDINARY')
  3571. $con .= ' and a.invoiceType=0 ';
  3572. elseif ($invoiceType == 'SPECIAL')
  3573. $con .= ' and a.invoiceType=1 ';
  3574. $dateArr = explode ( ':', $date );
  3575. $D1 = $dateString = '';
  3576. $D2 = '';
  3577. if (! empty ( $date )) {
  3578. $D1 = $dateArr [0];
  3579. if (isset ( $dateArr [1] ))
  3580. $D2 = $dateArr [1];
  3581. else
  3582. $D2 = '';
  3583. $dateString = $D1 . " : " . $D2;
  3584. }
  3585. if (! empty ( $D1 ) && ! empty ( $D2 ))
  3586. $con .= ' and b.printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  3587. elseif (! empty ( $D1 ) && empty ( $D2 ))
  3588. $con .= ' and b.printTime like "%' . $D1 . '%" ';
  3589. if (! empty ( $MebSea ))
  3590. $con .= ' and ( b.invoiceTitle like "%' . $MebSea . '%" or b.invoiceCompany like "%' . $MebSea . '%" or a.invoiceNo like "%' . $MebSea . '%" )';
  3591. $invoiceTotal = $invoicePaper->getInvoicePaperCount ();
  3592. $sql = ' ' . $con;
  3593. $limit = $page . ',' . $page_size;
  3594. $list = $invoicePaper->getInvoicePaper ( $limit, $sql, 'desc' );
  3595. $paperList = array ();
  3596. foreach ( $list as $key => $value ) {
  3597. $irDetail = array ();
  3598. if ($value ['iid'] == 0)
  3599. array_push ( $irDetail, '<a href="javascript:if(window.confirm(\'确认删除?\'))window.location=\'/invoicePaperDel/' . $value ['ipidKey'] . '\'" >删除</a>' );
  3600. else
  3601. array_push ( $irDetail, '' );
  3602. array_push ( $irDetail, $value ['invoiceCode'] );
  3603. array_push ( $irDetail, $value ['invoiceNo'] );
  3604. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKey'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  3605. if ($value ['invoiceType'] == 1)
  3606. array_push ( $irDetail, $value ['invoiceCompany'] );
  3607. else
  3608. array_push ( $irDetail, $value ['invoiceTitle'] );
  3609. if ($value ['invoiceType'] == 1)
  3610. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  3611. else
  3612. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  3613. array_push ( $irDetail, $value ['invoiceElement'] );
  3614. array_push ( $irDetail, $value ['categoryName'] . '-' . $value ['userName'] );
  3615. array_push ( $irDetail, $value ['printTime'] );
  3616. array_push ( $paperList, $irDetail );
  3617. }
  3618. // $approvalListJson = json_encode ( $approvalList );
  3619. $recordsFiltered = $invoiceTotal;
  3620. echo json_encode ( array (
  3621. "draw" => intval ( $draw ),
  3622. "recordsTotal" => intval ( $invoiceTotal ),
  3623. "recordsFiltered" => intval ( $recordsFiltered ),
  3624. "data" => $paperList
  3625. ), JSON_UNESCAPED_UNICODE );
  3626. }
  3627. function invoicePaperDel() {
  3628. $ipidKey = isset ( $this->params ['ipidKey'] ) ? $this->params ['ipidKey'] : "";
  3629. $XDeode = new XDeode ( 5 );
  3630. $ipid = $XDeode->decode ( $ipidKey );
  3631. if (empty ( $ipid ))
  3632. die ( 'illegal request' );
  3633. Doo::loadModel ( 'invoicePaper' );
  3634. $invoicePaper = new invoicePaper ();
  3635. $invoicePaper->delete ( array (
  3636. 'where' => 'ipid=' . $ipid . ' and iid=0',
  3637. 'limit' => 1
  3638. ) );
  3639. return '/invoicePaper';
  3640. }
  3641. /**
  3642. * 添加纸质发票号
  3643. */
  3644. function invoicePaperAdd() {
  3645. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : '0';
  3646. $invoiceCode = $this->get_args ( 'invoiceCode' ) ? $this->get_args ( 'invoiceCode' ) : "";
  3647. $invoiceNoStart = $this->get_args ( 'invoiceNoStart' ) && is_numeric ( $this->get_args ( 'invoiceNoStart' ) ) ? $this->get_args ( 'invoiceNoStart' ) : 0;
  3648. $invoiceNoTotal = $this->get_args ( 'invoiceNoTotal' ) && is_numeric ( $this->get_args ( 'invoiceNoTotal' ) ) ? $this->get_args ( 'invoiceNoTotal' ) : 0;
  3649. if ($invoiceType != '' && ! empty ( $invoiceCode ) && ! empty ( $invoiceNoStart ) && ! empty ( $invoiceNoTotal )) {
  3650. $sum = $invoiceNoStart + $invoiceNoTotal;
  3651. if (empty ( $sum ))
  3652. die ( 'illegal request' );
  3653. // echo $invoiceNoStart;
  3654. // echo $sum;
  3655. // echo strlen((int)$invoiceNoStart);
  3656. $sumLenght = strlen ( $invoiceNoStart ) - strlen ( ( int ) $invoiceNoStart );
  3657. Doo::db ()->beginTransaction ();
  3658. // 批量存储纸质发票
  3659. $date = date ( "Y-m-d H:i:s" );
  3660. $sql = 'INSERT INTO CLD_invoicePaper (invoiceType, invoiceCode,invoiceNo,date)
  3661. VALUES ';
  3662. $paperList = array ();
  3663. for($invoiceNoStart; $invoiceNoStart <= $sum - 1; $invoiceNoStart ++) {
  3664. // 数字前面自加0
  3665. $INLENGHT = strlen ( ( int ) $invoiceNoStart ) + $sumLenght;
  3666. $var = sprintf ( "%0" . $INLENGHT . "d", $invoiceNoStart );
  3667. $paperSql = '(' . $invoiceType . ',"' . $invoiceCode . '","' . $var . '","' . $date . '")';
  3668. array_push ( $paperList, $paperSql );
  3669. }
  3670. if (empty ( $paperList ))
  3671. die ( 'illegal request' );
  3672. $sql = $sql . implode ( ',', $paperList );
  3673. Doo::db ()->query ( $sql );
  3674. Doo::db ()->commit ();
  3675. return 'invoicePaper';
  3676. }
  3677. die ( 'illegal request' );
  3678. }
  3679. /**
  3680. * 收款绑定发票 ,//一个收款只能绑定一个发票
  3681. */
  3682. function invoiceBindReceivables() {
  3683. $claimKey = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  3684. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  3685. Doo::loadModel ( 'invoice' );
  3686. $invoice = new invoice ();
  3687. Doo::loadModel ( 'invoiceReceivables' );
  3688. $invoiceReceivables = new invoiceReceivables ();
  3689. Doo::loadModel ( 'invoiceOperationLog' );
  3690. $invoiceOperationLog = new invoiceOperationLog ();
  3691. if (empty ( $invoiceKey ) || empty ( $claimKey ))
  3692. die ( 'illegal request' );
  3693. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  3694. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey );
  3695. if (empty ( $detail ) && empty ( $detailM ))
  3696. die ( 'illegal request' );
  3697. if ($detail ['untreadStatus'] == 3)
  3698. die ( 'illegal request' );
  3699. // 修改 绑定状态改为 金额
  3700. $invoiceReceivables = new invoiceReceivables ();
  3701. //有BUG-需修改
  3702. $invoicePrice = $detail ['invoicePrice'] + $detailM ['bindPrice'];
  3703. if ($detailM ['receivablesPrice'] > $invoicePrice) {
  3704. $item = array (
  3705. 'bindPrice' => $invoicePrice
  3706. );
  3707. } elseif ($detailM ['receivablesPrice'] <= $invoicePrice) {
  3708. $item = array (
  3709. 'bindPrice' => $invoicePrice,
  3710. 'bindStatus' => 1,
  3711. 'bindDate' => date ( "Y-m-d H:i:s" )
  3712. );
  3713. } else {
  3714. die ( 'illegal request' );
  3715. }
  3716. if ($detailM ['iid'] == 0) {
  3717. $item += array (
  3718. 'iid' => $detail ['iid']
  3719. );
  3720. } else {
  3721. $iidExtend = explode ( ',', $detailM ['iidExtend'] );
  3722. array_push ( $iidExtend, $detail ['iid'] );
  3723. $item += array (
  3724. 'iidExtend' => implode ( ',', $iidExtend )
  3725. );
  3726. }
  3727. $titleMark = $detail ['invoiceTitle'];
  3728. if (! empty ( $detail ['invoiceCompany'] ))
  3729. $titleMark = $detail ['invoiceCompany'];
  3730. $item += array (
  3731. 'irid' => $detailM ['irid'],
  3732. 'recepitTitleMark' => $titleMark,
  3733. 'accountClerk' => $this->staff [0] ['username']
  3734. );
  3735. // 如何没有人收款 则自动绑定收款
  3736. if ($detailM ['receivablesCategory'] == 'PUBLIC' || $detailM ['receivablesStaff'] == 'PUBLIC') {
  3737. $item += array (
  3738. 'receivablesCategory' => $detail ['cid'] . ':' . $detail ['categoryName'],
  3739. 'receivablesStaff' => $detail ['sid'] . '-' . $detail ['userName']
  3740. );
  3741. }
  3742. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3743. $iridString = "";
  3744. if (empty ( $detail ['irid'] ))
  3745. $iridString = $detailM ['irid'];
  3746. else
  3747. $iridString = $detail ['irid'] . ',' . $detailM ['irid'];
  3748. $item = array (
  3749. 'iid' => $detail ['iid'],
  3750. 'irid' => $iridString
  3751. );
  3752. $invoiceReceivables = new invoiceReceivables ();
  3753. $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  3754. if ($detail ['invoicePrice'] <= $sum)
  3755. $item += array (
  3756. 'untreadStatus' => 3,
  3757. 'bindTime' => date ( "Y-m-d H:i:s" )
  3758. );
  3759. // print_r($item);
  3760. // echo $sum;die;
  3761. $invoice->setInvoiceByCondition ( $item );
  3762. // 操作日志
  3763. $item = array (
  3764. 'date' => date ( "Y-m-d H:i:s" ),
  3765. 'operation' => "收款" . $detailM ['receivablesSerial'] . "入账到发票" . $detail ['invoiceSerial'],
  3766. 'status' => 8,
  3767. 'img' => $this->staff [0] ['avatar'],
  3768. 'username' => $this->staff [0] ['username'],
  3769. 'uid' => $this->staff [0] ['sid'],
  3770. 'category' => $this->staff [0] ['category'],
  3771. 'iid' => $detail ['iid']
  3772. );
  3773. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3774. Doo::loadModel ( 'invoiceStatistics' );
  3775. $invoiceStatistics = new invoiceStatistics ();
  3776. $item = array (
  3777. 'date' => $detailM ['receivablesDate'],
  3778. 'priceClass' => 3,
  3779. 'cid' => $detail ['cid'],
  3780. 'staff' => $detail ['sid'],
  3781. 'accountPrice' => $detailM ['receivablesPrice']
  3782. );
  3783. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3784. // 公司流水记录
  3785. // Doo::loadModel ( 'wasteBook' );
  3786. // $wasteBook = new wasteBook ();
  3787. // $abDetail = $wasteBook->getAccountBookByAid (1,8,$detail ['iid'] );
  3788. // $accountBank='';
  3789. // if ($detailM ['receivablesBank']=='纵横广发'){
  3790. // $accountBank='CGBDeposit';
  3791. // }elseif($detailM ['receivablesBank']=='纵横工行'){
  3792. // $accountBank='ICBCDeposit';
  3793. // }elseif($detailM ['receivablesBank']=='华润银行'){
  3794. // $accountBank='HUADeposit';
  3795. // }elseif($detailM ['receivablesBank']=='个人广发'){
  3796. // $accountBank='PersonalDeposit';
  3797. // }
  3798. // if (empty($abDetail)){
  3799. // $item = array (
  3800. // 'dataID' => $detail ['iid'],
  3801. // 'expensesType' => 1,
  3802. // 'accountType' => 8,
  3803. // 'accountPriceShow'=>$detail ['invoicePrice'],
  3804. // 'accountPrice'=>$detail ['invoicePrice'],
  3805. // 'accountBank'=>$accountBank,
  3806. // 'category'=>$this->staff[0]['category'],
  3807. // 'cid'=>$this->staff[0]['cid'],
  3808. // 'name'=>$this->staff[0]['username'],
  3809. // 'sid'=>$this->staff[0]['sid'],
  3810. // 'inputDate'=>date ( "Y-m-d H:i:s" )
  3811. // );
  3812. // $wasteBook->setAccountBookStatistics($item);
  3813. // }
  3814. return "/invoiceReceivables";
  3815. }
  3816. /**
  3817. * 核销 动作,确认入账统计 发票收款完成--需求更变 废弃 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"; }
  3818. */
  3819. function invoiceAggregate() {
  3820. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3821. Doo::loadModel ( 'invoiceStatistics' );
  3822. $invoiceStatistics = new invoiceStatistics ();
  3823. Doo::loadModel ( 'L_category' );
  3824. $Lcategory = new L_category ();
  3825. $isList = $invoiceStatistics->getInvoiceStatisticsByYear ( $year );
  3826. $LcategoryList = $Lcategory->getCategory ();
  3827. // print_r($isList);
  3828. $html = ""; // $invoicePriceCategory=0;$receivablesPriceCategory=0;$accountPriceCategory=0;
  3829. foreach ( $LcategoryList as $key => $value ) {
  3830. $html .= '<tr><th><a href="/invoiceAggregateCategory/' . $value ['cidKey'] . '">' . $value ['title'] . '</a></th>';
  3831. $month = 1;
  3832. $invoicePriceYear = 0;
  3833. $receivablesPriceYear = 0;
  3834. $accountPriceYear = 0;
  3835. for(; $month <= 12; $month ++) {
  3836. $flag = true;
  3837. foreach ( $isList ['statisticsMonthCid'] as $k => $v ) {
  3838. if ($value ['cid'] == $v ['cid'] && $month == $v ['month']) {
  3839. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  3840. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  3841. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  3842. ';
  3843. $invoicePriceYear += $v ['invoicePrice'];
  3844. $receivablesPriceYear += $v ['receivablesPrice'];
  3845. $accountPriceYear += $v ['accountPrice'];
  3846. $flag = false;
  3847. break;
  3848. }
  3849. }
  3850. if ($flag)
  3851. $html .= '<td class="taR"></td>
  3852. <td class="taR"></td>
  3853. <td class="taR"><b></b></td>
  3854. ';
  3855. }
  3856. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  3857. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  3858. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  3859. ';
  3860. $html .= '</tr>';
  3861. }
  3862. $html .= '<tr><th><b class="colGreen">月合计</b></th>';
  3863. $invoicePriceYear = 0;
  3864. $receivablesPriceYear = 0;
  3865. $accountPriceYear = 0;
  3866. for($month = 1; $month <= 12; $month ++) {
  3867. $flag = true;
  3868. foreach ( $isList ['statisticsMonth'] as $k => $v ) {
  3869. if ($month == $v ['month']) {
  3870. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  3871. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  3872. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  3873. ';
  3874. $invoicePriceYear += $v ['invoicePrice'];
  3875. $receivablesPriceYear += $v ['receivablesPrice'];
  3876. $accountPriceYear += $v ['accountPrice'];
  3877. $flag = false;
  3878. break;
  3879. }
  3880. }
  3881. if ($flag) {
  3882. $html .= '<td class="taR"></td>
  3883. <td class="taR"></td>
  3884. <td class="taR"><b></b></td>
  3885. ';
  3886. }
  3887. }
  3888. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  3889. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  3890. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  3891. ';
  3892. $html .= '</tr>';
  3893. // print_r($isList);
  3894. $this->data ['html'] = $html;
  3895. $this->data ['LcategoryList'] = $LcategoryList;
  3896. $this->data ['isList'] = $isList;
  3897. $this->data ['year'] = $year;
  3898. $this->data ['memu'] = "invoice";
  3899. $this->data ['staff'] = $this->staff;
  3900. $this->data ['receiptMemu'] = 'invoiceAggregate';
  3901. $this->render ( "/admin/invoiceAggregate", $this->data );
  3902. }
  3903. function invoiceAggregateStaff() {
  3904. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3905. Doo::loadModel ( 'invoiceStatistics' );
  3906. $invoiceStatistics = new invoiceStatistics ();
  3907. Doo::loadModel ( 'L_category' );
  3908. $Lcategory = new L_category ();
  3909. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year );
  3910. $staffList = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year );
  3911. $cStaff = $Lcategory->getCategoryStaff ();
  3912. $html = '';
  3913. foreach ( $cStaff as $key => $value ) {
  3914. $categoryFir = true;
  3915. foreach ( $value ['staff'] as $k => $v ) {
  3916. if ($categoryFir) {
  3917. $width = count ( $value ['staff'] ) + 1;
  3918. $html .= '<tr><th rowspan="' . $width . '">' . $value ['title'] . ' </th>';
  3919. $categoryFir = false;
  3920. } else
  3921. $html .= '<tr>';
  3922. $html .= '<th>' . $v ['username'] . '</th>';
  3923. $invoicePriceStaffYear = 0;
  3924. $receivablesPriceStaffYear = 0;
  3925. $accountPriceStaffYear = 0;
  3926. for($month = 1; $month <= 12; $month ++) {
  3927. $flag = true;
  3928. foreach ( $staffList ['statisticsMonthStaff'] as $sl => $slv ) {
  3929. if ($v ['sid'] == $slv ['staff'] && $month == $slv ['month']) {
  3930. $html .= '<td class="taR">¥' . $slv ['invoicePrice'] . '</td>
  3931. <td class="taR">¥' . $slv ['receivablesPrice'] . '</td>
  3932. <td class="taR"><b>¥' . $slv ['accountPrice'] . '</b></td>
  3933. ';
  3934. $invoicePriceStaffYear += $slv ['invoicePrice'];
  3935. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  3936. $accountPriceStaffYear += $slv ['accountPrice'];
  3937. $flag = false;
  3938. break;
  3939. }
  3940. }
  3941. if ($flag)
  3942. $html .= '<td class="taR"></td>
  3943. <td class="taR"></td>
  3944. <td class="taR"><b></b></td>
  3945. ';
  3946. }
  3947. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  3948. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  3949. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  3950. ';
  3951. }
  3952. $html .= '</tr>';
  3953. // 小计
  3954. if (! empty ( $value ['staff'] )) {
  3955. $html .= '<tr><th class="taR">小计</th>';
  3956. $invoicePriceStaffYear = 0;
  3957. $receivablesPriceStaffYear = 0;
  3958. $accountPriceStaffYear = 0;
  3959. for($month = 1; $month <= 12; $month ++) {
  3960. $flag = true;
  3961. foreach ( $staffList ['statisticsMonthCid'] as $smc => $smcv ) {
  3962. if ($value ['cid'] == $smcv ['cid'] && $month == $slv ['month']) {
  3963. $html .= '<td class="taR">¥' . $smcv ['invoicePrice'] . '</td>
  3964. <td class="taR">¥' . $smcv ['receivablesPrice'] . '</td>
  3965. <td class="taR"><b>¥' . $smcv ['accountPrice'] . '</b></td>
  3966. ';
  3967. $invoicePriceStaffYear += $slv ['invoicePrice'];
  3968. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  3969. $accountPriceStaffYear += $slv ['accountPrice'];
  3970. $flag = false;
  3971. break;
  3972. }
  3973. }
  3974. if ($flag)
  3975. $html .= '<td class="taR"></td>
  3976. <td class="taR"></td>
  3977. <td class="taR"><b></b></td>
  3978. ';
  3979. }
  3980. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  3981. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  3982. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  3983. ';
  3984. $html .= '</tr>';
  3985. }
  3986. }
  3987. $html .= '<tr class="warning"><th colspan="2"><b class="colGreen" >月合计</b></th>';
  3988. $invoicePriceYear = 0;
  3989. $receivablesPriceYear = 0;
  3990. $accountPriceYear = 0;
  3991. for($month = 1; $month <= 12; $month ++) {
  3992. $flag = true;
  3993. foreach ( $staffList ['statisticsMonth'] as $k => $v ) {
  3994. if ($month == $v ['month']) {
  3995. $html .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>
  3996. <td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>
  3997. <td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>
  3998. ';
  3999. $invoicePriceYear += $v ['invoicePrice'];
  4000. $receivablesPriceYear += $v ['receivablesPrice'];
  4001. $accountPriceYear += $v ['accountPrice'];
  4002. $flag = false;
  4003. break;
  4004. }
  4005. }
  4006. if ($flag)
  4007. $html .= '<td class="taR"></td>
  4008. <td class="taR"></td>
  4009. <td class="taR"><b></b></td>
  4010. ';
  4011. }
  4012. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  4013. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  4014. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  4015. ';
  4016. $html .= '</tr>';
  4017. $this->data ['html'] = $html;
  4018. $this->data ['isList'] = $toteList;
  4019. $this->data ['year'] = $year;
  4020. $this->data ['memu'] = "invoice";
  4021. $this->data ['staff'] = $this->staff;
  4022. $this->data ['receiptMemu'] = 'invoiceAggregate';
  4023. $this->render ( "/admin/invoiceAggregateStaff", $this->data );
  4024. }
  4025. function invoiceAggregateCategory() {
  4026. Doo::loadClass ( 'XDeode' );
  4027. $XDeode = new XDeode ( 5 );
  4028. $cid = $cidKey = isset ( $this->params ['cid'] ) ? $this->params ['cid'] : "";
  4029. $cid = $XDeode->decode ( $cid );
  4030. if (! is_numeric ( $cid ))
  4031. die ( 'illegal request' );
  4032. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  4033. Doo::loadModel ( 'invoiceStatistics' );
  4034. $invoiceStatistics = new invoiceStatistics ();
  4035. Doo::loadModel ( 'staff' );
  4036. $staff = new staff ();
  4037. $list = $staff->getStaffByCid ( $cid );
  4038. $isCategory = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year, $cid );
  4039. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year, $cid );
  4040. if (empty ( $list ))
  4041. die ( '该办事处没有成员' );
  4042. $htmlA = $htmlB = $htmlC = $html = '';
  4043. foreach ( $list as $key => $value ) {
  4044. $htmlA = '<tr><th rowspan="3">' . $value ['username'] . '</th><th class="taC">开票</th>';
  4045. $htmlB = '<tr><th class="taC">收款</th>';
  4046. $htmlC = '<tr><th class="taC">入账</th>';
  4047. $invoicePriceStaffYear = 0;
  4048. $receivablesPriceStaffYear = 0;
  4049. $accountPriceStaffYear = 0;
  4050. for($month = 1; $month <= 12; $month ++) {
  4051. $flag = true;
  4052. foreach ( $isCategory ['statisticsMonthStaff'] as $k => $v ) {
  4053. if ($value ['sid'] == $v ['staff'] && $month == $v ['month']) {
  4054. $htmlA .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>';
  4055. $htmlB .= '<td class="taR">¥' . $v ['receivablesPrice'] . '</td>';
  4056. $htmlC .= '<td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>';
  4057. $invoicePriceStaffYear += $v ['invoicePrice'];
  4058. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  4059. $accountPriceStaffYear += $v ['accountPrice'];
  4060. $flag = false;
  4061. break;
  4062. }
  4063. }
  4064. if ($flag) {
  4065. $htmlA .= '<td class="taR">-</td>';
  4066. $htmlB .= '<td class="taR">-</td>';
  4067. $htmlC .= '<td class="taR"><b>-</b></td>';
  4068. }
  4069. }
  4070. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  4071. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  4072. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  4073. $htmlA .= '</tr>';
  4074. $htmlB .= '</tr>';
  4075. $htmlC .= '</tr>';
  4076. $html .= $htmlA . $htmlB . $htmlC;
  4077. }
  4078. $htmlA = $htmlB = $htmlC = "";
  4079. $htmlA = '<tr><th rowspan="3">月合计</th><th class="taC">开票</th>';
  4080. $htmlB = '<tr><th class="taC">收款</th>';
  4081. $htmlC = '<tr><th class="taC">入账</th>';
  4082. $invoicePriceStaffYear = 0;
  4083. $receivablesPriceStaffYear = 0;
  4084. $accountPriceStaffYear = 0;
  4085. for($month = 1; $month <= 12; $month ++) {
  4086. $flag = true;
  4087. foreach ( $isCategory ['statisticsMonth'] as $k => $v ) {
  4088. if ($month == $v ['month']) {
  4089. $htmlA .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>';
  4090. $htmlB .= '<td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>';
  4091. $htmlC .= '<td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>';
  4092. $invoicePriceStaffYear += $v ['invoicePrice'];
  4093. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  4094. $accountPriceStaffYear += $v ['accountPrice'];
  4095. $flag = false;
  4096. break;
  4097. }
  4098. }
  4099. if ($flag) {
  4100. $htmlA .= '<td class="taR">-</td>';
  4101. $htmlB .= '<td class="taR">-</td>';
  4102. $htmlC .= '<td class="taR"><b>-</b></td>';
  4103. }
  4104. }
  4105. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  4106. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  4107. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  4108. $htmlA .= '</tr>';
  4109. $htmlB .= '</tr>';
  4110. $htmlC .= '</tr>';
  4111. $html .= $htmlA . $htmlB . $htmlC;
  4112. $this->data ['html'] = $html;
  4113. $this->data ['cidKey'] = $cidKey;
  4114. $this->data ['slist'] = $list;
  4115. $this->data ['isList'] = $toteList;
  4116. $this->data ['year'] = $year;
  4117. $this->data ['memu'] = "invoice";
  4118. $this->data ['staff'] = $this->staff;
  4119. $this->data ['receiptMemu'] = 'invoiceAggregate';
  4120. $this->render ( "/admin/invoiceAggregateCategory", $this->data );
  4121. }
  4122. /**
  4123. * 办事处汇总信息
  4124. */
  4125. function invoiceAggregateCategoryDetail() {
  4126. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  4127. Doo::loadClass ( 'XDeode' );
  4128. $XDeode = new XDeode ( 5 );
  4129. Doo::loadModel ( 'invoiceStatistics' );
  4130. $invoiceStatistics = new invoiceStatistics ();
  4131. Doo::loadModel ( 'L_category' );
  4132. $category = new L_category ();
  4133. Doo::loadModel ( 'invoice' );
  4134. $invoice = new invoice ();
  4135. Doo::loadModel ( 'staff' );
  4136. $staff = new staff ();
  4137. Doo::loadModel ( "invoiceCategoryManage" );
  4138. $invoiceCategoryManage = new invoiceCategoryManage ();
  4139. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4140. $cidList = array ();
  4141. foreach ( $imcStaff as $key => $value ) {
  4142. array_push ( $cidList, $value ['cid'] );
  4143. if (empty ( $cidKey ))
  4144. $cidKey = $XDeode->encode ( $value ['cid'] );
  4145. }
  4146. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  4147. $cid = $XDeode->decode ( $cidKey );
  4148. $month = date ( "m", strtotime ( "-1 month" ) );
  4149. $YearMonth = date ( "Y-m", strtotime ( "-1 month" ) );
  4150. $redis = new Redis ();
  4151. $redis->connect ( '127.0.0.1', '6379' );
  4152. $redisKey = ''; // date('Y-m-d').'_iacd_'.$cid;
  4153. $redisValue = ''; // $redis->lrange($redisKey, 0, -1);
  4154. if (empty ( $redisValue )) {
  4155. $isMC = $invoiceStatistics->getInvoiceStatistiscsMothByCategory ( $cid );
  4156. $schedule = $invoice->getInvoiceScheduleByCid ( $cid );
  4157. // 获得办事处人员下的汇总
  4158. $slist = $staff->getStaffByCid ( $cid );
  4159. $ismsbMonth = $invoiceStatistics->getISMSByCategoryByMonth ( $cid, $YearMonth ); // 上一个月的汇总
  4160. $ismsb = $invoiceStatistics->getISMSByCategory ( $cid ); // 当月汇总
  4161. $ISAS = $invoiceStatistics->getISASByCategory ( $cid ); // 全部汇总
  4162. $scheduleStaff = $invoice->getInvoiceScheduleByCidGroupSid ( $cid ); // 完成度
  4163. foreach ( $slist as $key => $value ) {
  4164. $slist [$key] ['invoicePrice'] = 0;
  4165. $slist [$key] ['receivablesPrice'] = 0;
  4166. $slist [$key] ['accountPrice'] = 0;
  4167. $slist [$key] ['invoiceAllPrice'] = 0;
  4168. $slist [$key] ['receivablesAllPrice'] = 0;
  4169. $slist [$key] ['accountAllPrice'] = 0;
  4170. $slist [$key] ['schedule'] = 0;
  4171. $slist [$key] ['invoiceMonthPrice'] = 0;
  4172. $slist [$key] ['receivablesMonthPrice'] = 0;
  4173. $slist [$key] ['accountMonthPrice'] = 0;
  4174. foreach ( $ismsbMonth as $y => $l ) {
  4175. if ($value ['sid'] == $l ['staff']) {
  4176. $slist [$key] ['invoiceMonthPrice'] = $l ['invoicePrice'];
  4177. $slist [$key] ['receivablesMonthPrice'] = $l ['receivablesPrice'];
  4178. $slist [$key] ['accountMonthPrice'] = $l ['accountPrice'];
  4179. }
  4180. }
  4181. foreach ( $ismsb as $k => $v ) {
  4182. if ($value ['sid'] == $v ['staff']) {
  4183. $slist [$key] ['invoicePrice'] = $v ['invoicePrice'];
  4184. $slist [$key] ['receivablesPrice'] = $v ['receivablesPrice'];
  4185. $slist [$key] ['accountPrice'] = $v ['accountPrice'];
  4186. }
  4187. }
  4188. foreach ( $ISAS as $e => $a ) {
  4189. if ($value ['sid'] == $a ['staff']) {
  4190. $slist [$key] ['invoiceAllPrice'] = $a ['invoicePrice'];
  4191. $slist [$key] ['receivablesAllPrice'] = $a ['receivablesPrice'];
  4192. $slist [$key] ['accountAllPrice'] = $a ['accountPrice'];
  4193. }
  4194. }
  4195. if (isset ( $scheduleStaff [$value ['sid']] ))
  4196. $slist [$key] ['schedule'] = $scheduleStaff [$value ['sid']];
  4197. }
  4198. $this->data ['cidKey'] = $cidKey;
  4199. $schedule = ( int ) ($schedule * 100);
  4200. $this->data ['slist'] = $slist;
  4201. $this->data ['isMC'] = $isMC;
  4202. $this->data ['schedule'] = $schedule;
  4203. $slist = json_encode ( $slist );
  4204. $isMC = json_encode ( $isMC );
  4205. $schedule = json_encode ( $schedule );
  4206. $redis->lpush ( $redisKey, $slist );
  4207. $redis->lpush ( $redisKey, $isMC );
  4208. $redis->lpush ( $redisKey, $schedule );
  4209. } else {
  4210. $this->data ['cidKey'] = $cidKey;
  4211. $this->data ['slist'] = json_decode ( $redisValue [2], true );
  4212. $this->data ['isMC'] = json_decode ( $redisValue [1], true );
  4213. $this->data ['schedule'] = json_decode ( $redisValue [0], true );
  4214. }
  4215. $this->data ['month'] = $month;
  4216. $this->data ['categoryList'] = $categoryList;
  4217. $this->data ['memu'] = "invoice";
  4218. $this->data ['staff'] = $this->staff;
  4219. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4220. $this->render ( "/admin/invoiceAggregateCategoryDetail", $this->data );
  4221. }
  4222. /**
  4223. * 办事处人员汇总详情
  4224. */
  4225. function invoiceAggregateStaffDetail() {
  4226. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  4227. // $sidKey = isset ( $this->params ['sidKey'] ) ? $this->params ['sidKey'] : '';
  4228. Doo::loadClass ( 'XDeode' );
  4229. $XDeode = new XDeode ( 5 );
  4230. Doo::loadModel ( 'invoice' );
  4231. $invoice = new invoice ();
  4232. Doo::loadModel ( 'staff' );
  4233. $staff = new staff ();
  4234. Doo::loadModel ( "invoiceCategoryManage" );
  4235. $invoiceCategoryManage = new invoiceCategoryManage ();
  4236. $sid = $XDeode->decode ( $sidKey );
  4237. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4238. $cidList = array ();
  4239. foreach ( $imcStaff as $key => $value ) {
  4240. array_push ( $cidList, $value ['cid'] );
  4241. if (empty ( $cidKey ))
  4242. $cidKey = $XDeode->encode ( $value ['cid'] );
  4243. }
  4244. $cidString = implode ( ',', $cidList );
  4245. $staffList = $staff->getStaffInCid ( $cidString );
  4246. $staffDetail = $staff->getStaffBySid ( $sid );
  4247. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4248. $page_size = 18;
  4249. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4250. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4251. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  4252. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  4253. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  4254. $dateArr = explode ( ':', $date );
  4255. $D1 = '';
  4256. $D2 = '';
  4257. if (! empty ( $date )) {
  4258. $D1 = $dateArr [0] . " 00:00:00 ";
  4259. if (isset ( $dateArr [1] ))
  4260. $D2 = $dateArr [1] . " 23:59:59 ";
  4261. else
  4262. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4263. // $D2 = $dateArr [1];
  4264. }
  4265. $con = ' status=2 ';
  4266. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4267. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4268. if ($status == 'UNRECORD')
  4269. $con .= ' and printStatus=1 and untreadStatus=0';
  4270. elseif ($status == 'RECORD')
  4271. $con .= ' and printStatus=1 and untreadStatus=3';
  4272. elseif ($status == 'BOUNCED')
  4273. $con .= ' and untreadStatus=2';
  4274. elseif ($status == 'PARTRECORD')
  4275. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  4276. elseif ($status == 'All') {
  4277. $con .= ' and ( untreadStatus=2 or untreadStatus=0 or untreadStatus=3 )';
  4278. }
  4279. $con .= ' and sid=' . $sid;
  4280. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  4281. if (! empty ( $MebSea )) {
  4282. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  4283. }
  4284. $pageinfo ['page'] = array (
  4285. 'previous' => ''
  4286. );
  4287. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateStaffDetail", $get, "" );
  4288. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4289. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  4290. $this->data ['staffDetail'] = $staffDetail;
  4291. $this->data ['staffList'] = $staffList;
  4292. $this->data ['MebSeaEn'] = $MebSea;
  4293. $this->data ['MebSea'] = urlencode ( $MebSea );
  4294. $this->data ['date'] = $date;
  4295. $this->data ['page'] = $pageinfo;
  4296. $this->data ['get'] = $get;
  4297. $this->data ['list'] = $list;
  4298. $this->data ['status'] = $status;
  4299. $this->data ['sidKey'] = $sidKey;
  4300. $this->data ['memu'] = "invoice";
  4301. $this->data ['staff'] = $this->staff;
  4302. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4303. $this->render ( "/admin/invoiceAggregateStaffDetail", $this->data );
  4304. }
  4305. /**
  4306. * 办事处人员汇总收款情
  4307. */
  4308. function invoiceAggregateStaffReceivablesDetail() {
  4309. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  4310. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  4311. Doo::loadModel ( 'invoiceReceivables' );
  4312. $invoiceReceivables = new invoiceReceivables ();
  4313. Doo::loadModel ( 'staff' );
  4314. $staff = new staff ();
  4315. Doo::loadModel ( "invoiceCategoryManage" );
  4316. $invoiceCategoryManage = new invoiceCategoryManage ();
  4317. Doo::loadClass ( 'XDeode' );
  4318. $XDeode = new XDeode ( 5 );
  4319. $sid = $XDeode->decode ( $sidKey );
  4320. $staffDetail = $staff->getStaffBySid ( $sid );
  4321. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4322. $cidList = array ();
  4323. foreach ( $imcStaff as $key => $value ) {
  4324. array_push ( $cidList, $value ['cid'] );
  4325. if (empty ( $cidKey ))
  4326. $cidKey = $XDeode->encode ( $value ['cid'] );
  4327. }
  4328. $cidString = implode ( ',', $cidList );
  4329. $staffList = $staff->getStaffInCid ( $cidString );
  4330. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4331. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  4332. $page_size = 10;
  4333. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4334. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4335. if ($timeType == "BINDOTP") {
  4336. $status = 'Credited';
  4337. }
  4338. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  4339. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  4340. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  4341. $dateArr = explode ( ':', $date );
  4342. $D1 = '';
  4343. $D2 = '';
  4344. if (! empty ( $date )) {
  4345. $D1 = $dateArr [0] . " 00:00:00 ";
  4346. if (isset ( $dateArr [1] ))
  4347. $D2 = $dateArr [1] . " 23:59:59 ";
  4348. else
  4349. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4350. }
  4351. $con = ' a.receivablesStaff like "%' . $staffDetail ['username'] . '%" ';
  4352. $descField = 'a.bindDate';
  4353. if ($timeType == 'CREATE')
  4354. $descField = 'a.date';
  4355. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4356. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4357. elseif (! empty ( $D1 ) && empty ( $D2 ))
  4358. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  4359. if ($status == 'Unclaimed')
  4360. $con .= ' and a.bindStatus=0';
  4361. elseif ($status == 'Credited')
  4362. $con .= ' and a.bindStatus=1';
  4363. elseif ($status == 'Claim')
  4364. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  4365. elseif ($status == 'BBN')
  4366. $con .= ' and a.bindPrice>a.receivablesPrice';
  4367. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  4368. if (! empty ( $MebSea )) {
  4369. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" )';
  4370. }
  4371. $pageinfo ['page'] = array (
  4372. 'previous' => ''
  4373. );
  4374. $sql = 'select group_concat(b.invoiceSerial) as invoiceSerial ,group_concat(b.iid) as invoiceId
  4375. from CLD_invoiceReceivables as a left join CLD_invoice as b on
  4376. find_in_set(b.iid,a.iidExtend) or a.iid=b.iid
  4377. where ' . $con . ' group by a.irid ';
  4378. $pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceAggregateStaffReceivablesDetail", $get, "" );
  4379. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4380. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', 'printTime' );
  4381. foreach ( $list as $key => $value ) {
  4382. $list [$key] ['category'] = '';
  4383. if ($value ['receivablesCategory'] != 'PUBLIC') {
  4384. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  4385. $list [$key] ['category'] = $receivablesCategory [1];
  4386. }
  4387. }
  4388. // print_r($list);
  4389. $this->data ['staffDetail'] = $staffDetail;
  4390. $this->data ['sidKey'] = $sidKey;
  4391. $this->data ['staffList'] = $staffList;
  4392. $this->data ['timeType'] = $timeType;
  4393. $this->data ['MebSeaEn'] = $MebSea;
  4394. $this->data ['MebSea'] = urlencode ( $MebSea );
  4395. $this->data ['date'] = $date;
  4396. $this->data ['page'] = $pageinfo;
  4397. $this->data ['get'] = $get;
  4398. $this->data ['list'] = $list;
  4399. $this->data ['status'] = $status;
  4400. $this->data ['memu'] = "invoice";
  4401. $this->data ['staff'] = $this->staff;
  4402. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4403. $this->render ( "/admin/invoiceAggregateStaffReceivablesDetail", $this->data );
  4404. }
  4405. function invoiceAchieve() {
  4406. Doo::loadModel ( 'invoice' );
  4407. $invoice = new invoice ();
  4408. Doo::loadClass ( 'XDeode' );
  4409. $XDeode = new XDeode ( 5 );
  4410. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4411. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4412. $page_size = 18;
  4413. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4414. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4415. $get = "/" . $date;
  4416. $con = '';
  4417. if ($date == 'MONTHO')
  4418. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4419. elseif ($date == 'MONTHT')
  4420. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4421. elseif ($date == 'MONTHY')
  4422. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4423. if (! empty ( $MebSea )) {
  4424. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4425. $get .= "/" . $MebSea;
  4426. }
  4427. $pageinfo ['page'] = array (
  4428. 'previous' => ''
  4429. );
  4430. $sql = 'status=2 and printStatus=1 and irid!="" and ( untreadStatus=3 or untreadStatus=0 ) and sid=' . $sid . $con;
  4431. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceAchieve", $get, "" );
  4432. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4433. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  4434. // print_r($pageinfo);
  4435. $this->data ['MebSeaEn'] = $MebSea;
  4436. $this->data ['MebSea'] = urlencode ( $MebSea );
  4437. $this->data ['get'] = $get;
  4438. $this->data ['page'] = $pageinfo;
  4439. $this->data ['list'] = $list;
  4440. $this->data ['date'] = $date;
  4441. $this->data ['memu'] = "invoice";
  4442. $this->data ['staff'] = $this->staff;
  4443. $this->data ['receiptMemu'] = 'invoice';
  4444. $this->render ( "/admin/invoiceAchieve", $this->data );
  4445. }
  4446. /**
  4447. */
  4448. function invoiceMyUnAccountAchieve() {
  4449. Doo::loadModel ( 'invoice' );
  4450. $invoice = new invoice ();
  4451. Doo::loadClass ( 'XDeode' );
  4452. $XDeode = new XDeode ( 5 );
  4453. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4454. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4455. $page_size = 18;
  4456. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4457. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4458. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4459. $dateArr = explode ( ':', $date );
  4460. $D1 = '';
  4461. $D2 = '';
  4462. if (! empty ( $date )) {
  4463. $D1 = $dateArr [0];
  4464. $D2 = $dateArr [1];
  4465. }
  4466. $con = '';
  4467. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4468. $con = ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4469. if (! empty ( $MebSea )) {
  4470. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4471. }
  4472. $pageinfo ['page'] = array (
  4473. 'previous' => ''
  4474. );
  4475. // and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  4476. $sql = " status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid= " . $sid . $con;
  4477. $action = "invoiceMyUnAccountAchieve";
  4478. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  4479. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4480. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 'desc', 'printTime' );
  4481. Doo::loadModel ( 'express' );
  4482. $express = new express ();
  4483. $expressList = $express->getExpressByAll ();
  4484. $this->data ['expressList'] = $expressList;
  4485. // print_r($list);
  4486. $this->data ['MebSeaEn'] = $MebSea;
  4487. $this->data ['get'] = $get;
  4488. $this->data ['page'] = $pageinfo;
  4489. $this->data ['date'] = $date;
  4490. $this->data ['list'] = $list;
  4491. $this->data ['memu'] = "invoice";
  4492. $this->data ['staff'] = $this->staff;
  4493. $this->data ['receiptMemu'] = 'invoice';
  4494. $this->render ( "/admin/invoiceMyUnAccountAchieve", $this->data );
  4495. }
  4496. function invoiceReceivablesAchieve() {
  4497. Doo::loadModel ( 'invoiceReceivables' );
  4498. $invoiceReceivables = new invoiceReceivables ();
  4499. Doo::loadClass ( 'XDeode' );
  4500. $XDeode = new XDeode ( 5 );
  4501. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4502. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  4503. $page_size = 12;
  4504. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4505. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4506. $get = "/" . $date;
  4507. $con = '';
  4508. if ($date == 'MONTHO')
  4509. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4510. elseif ($date == 'MONTHT')
  4511. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4512. elseif ($date == 'MONTHY')
  4513. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4514. if (! empty ( $MebSea )) {
  4515. $con .= ' and ( receivablesMessage like "%' . $MebSea . '%" or receivablesPrice like "%' . $MebSea . '%" )';
  4516. $get .= "/" . $MebSea;
  4517. }
  4518. $pageinfo ['page'] = array (
  4519. 'previous' => ''
  4520. );
  4521. $sql = " bindStatus=1 and receivablesStaff like '" . $sid . "-%' " . $con;
  4522. $pageinfo = $this->get_page ( "CLD_invoiceReceivables", $sql, $page, $page_size, "invoiceReceivablesAchieve", $get, "" );
  4523. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4524. $list = $invoiceReceivables->getReceivablesByUntreadStatusPage ( $limit, $sql );
  4525. // print_r($pageinfo);
  4526. $this->data ['MebSeaEn'] = $MebSea;
  4527. $this->data ['MebSea'] = urlencode ( $MebSea );
  4528. $this->data ['get'] = $get;
  4529. $this->data ['page'] = $pageinfo;
  4530. $this->data ['list'] = $list;
  4531. $this->data ['date'] = $date;
  4532. $this->data ['memu'] = "invoice";
  4533. $this->data ['staff'] = $this->staff;
  4534. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  4535. $this->render ( "/admin/invoiceReceivablesAchieve", $this->data );
  4536. }
  4537. /**
  4538. * 收款解绑
  4539. */
  4540. function invoiceUnBundLing() {
  4541. $unBundKey = $this->get_args ( 'unBundKey' ) ? $this->get_args ( 'unBundKey' ) : '';
  4542. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  4543. Doo::loadModel ( 'invoice' );
  4544. $invoice = new invoice ();
  4545. Doo::loadModel ( 'invoiceReceivables' );
  4546. $invoiceReceivables = new invoiceReceivables ();
  4547. Doo::loadModel ( 'invoiceOperationLog' );
  4548. $invoiceOperationLog = new invoiceOperationLog ();
  4549. Doo::loadModel ( 'invoiceROLog' );
  4550. $invoiceROLog = new invoiceROLog ();
  4551. Doo::loadModel ( 'invoiceStatistics' );
  4552. Doo::loadClass ( 'XDeode' );
  4553. $XDeode = new XDeode ( 5 );
  4554. if (empty ( $iidKey ) || empty ( $unBundKey ))
  4555. die ( 'illegal request' );
  4556. $iid = $XDeode->decode ( $iidKey );
  4557. $irid = $invoice->authcode ( $unBundKey );
  4558. if ((! empty ( $irid ) && ! is_numeric ( $irid )) || (! empty ( $iid ) && ! is_numeric ( $iid )))
  4559. die ( 'illegal request' );
  4560. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4561. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  4562. if (empty ( $irDetails ) || empty ( $invoiceDetails ) || (empty ( $irDetails ['iid'] ) && empty ( $irDetails ['iidExtend'] )) || $invoiceDetails ['untreadStatus'] == 2)
  4563. die ( 'illegal request' );
  4564. // 收款
  4565. $item = array (
  4566. 'irid' => $irDetails ['irid'],
  4567. 'bindPrice' => $irDetails ['bindPrice'] - $invoiceDetails ['invoicePrice'],
  4568. 'bindStatus' => 0
  4569. );
  4570. if ($irDetails ['iid'] == $iid)
  4571. $item += array (
  4572. 'iid' => 0
  4573. );
  4574. else {
  4575. $iidExtend = explode ( ',', $irDetails ['iidExtend'] );
  4576. foreach ( $iidExtend as $key => $value ) {
  4577. if ($value == $iid)
  4578. unset ( $iidExtend [$key] );
  4579. }
  4580. $iidExtend = implode ( ',', $iidExtend );
  4581. $item += array (
  4582. 'iidExtend' => $iidExtend
  4583. );
  4584. }
  4585. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4586. // 收款操作日志
  4587. $item = array (
  4588. 'operation' => $this->staff [0] ['username'] . " 解绑 " . $irDetails ['receivablesSerial'],
  4589. 'date' => date ( "Y-m-d" ),
  4590. 'status' => 3,
  4591. 'img' => $this->staff [0] ['avatar'],
  4592. 'username' => $this->staff [0] ['username'],
  4593. 'uid' => $this->staff [0] ['sid'],
  4594. 'category' => $this->staff [0] ['category'],
  4595. 'irid' => $irid
  4596. );
  4597. $invoiceROLog->setInvoiceROLog ( $item );
  4598. // 扣除入账统计金额
  4599. $invoiceStatistics = new invoiceStatistics ();
  4600. $item = array (
  4601. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  4602. 'priceClass' => 3,
  4603. 'cid' => $invoiceDetails ['cid'],
  4604. 'staff' => $invoiceDetails ['sid'],
  4605. 'accountPrice' => - $irDetails ['receivablesPrice']
  4606. );
  4607. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4608. // 扣除收款统计金额
  4609. $invoiceStatistics = new invoiceStatistics ();
  4610. $item = array (
  4611. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  4612. 'priceClass' => 2,
  4613. 'cid' => $invoiceDetails ['cid'],
  4614. 'staff' => $invoiceDetails ['sid'],
  4615. 'irid' => $irDetails ['irid'],
  4616. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  4617. );
  4618. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4619. // 发票解绑去收款ID
  4620. $iridString = $invoiceDetails ['irid'];
  4621. if (! empty ( $invoiceDetails ['irid'] )) {
  4622. $list = explode ( ',', $invoiceDetails ['irid'] );
  4623. foreach ( $list as $key => $value ) {
  4624. if ($value == $irDetails ['irid']) {
  4625. unset ( $list [$key] );
  4626. break;
  4627. }
  4628. }
  4629. $iridString = implode ( ",", $list );
  4630. }
  4631. $item = array (
  4632. 'iid' => $invoiceDetails ['iid'],
  4633. 'irid' => $iridString,
  4634. 'updateTime' => date ( "Y-m-d H:i:s" )
  4635. );
  4636. if ($invoiceDetails ['untreadStatus'] == 3)
  4637. $item += array (
  4638. 'untreadStatus' => 0
  4639. );
  4640. $invoice->setInvoiceByCondition ( $item );
  4641. $item = array (
  4642. 'date' => date ( "Y-m-d H:i:s" ),
  4643. 'operation' => '解绑 收款 ' . $irDetails ['receivablesSerial'],
  4644. 'status' => 11,
  4645. 'img' => $this->staff [0] ['avatar'],
  4646. 'username' => $this->staff [0] ['username'],
  4647. 'uid' => $this->staff [0] ['sid'],
  4648. 'category' => $this->staff [0] ['category'],
  4649. 'iid' => $invoiceDetails ['iid']
  4650. );
  4651. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  4652. // 公司流水-解绑时删除流水
  4653. Doo::loadModel ( 'wasteBook' );
  4654. $wasteBook = new wasteBook ();
  4655. // $wasteBook->delete ( array (
  4656. // 'where' => 'dataID=' . $irDetails ['irid'] . ' and accountType=7',
  4657. // 'limit' => 1
  4658. // ) );
  4659. // 银行
  4660. /*
  4661. * $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); }
  4662. */
  4663. return "/invoiceReceivablesAS";
  4664. }
  4665. /**
  4666. * 或者该收款下的所以发票
  4667. */
  4668. function ajaxGetInvoiceReceivablesByInvoice() {
  4669. $irid = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : '';
  4670. Doo::loadModel ( 'invoice' );
  4671. $invoice = new invoice ();
  4672. Doo::loadModel ( 'invoiceReceivables' );
  4673. $invoiceReceivables = new invoiceReceivables ();
  4674. $irid = $invoice->authcode ( $irid );
  4675. if (! empty ( $irid ) && ! is_numeric ( $irid ))
  4676. die ( 'illegal request' );
  4677. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4678. $iidString = $irDetails ['iid'];
  4679. $iidExtend = array_filter ( explode ( ',', $irDetails ['iidExtend'] ) );
  4680. if (! empty ( $irDetails ['iidExtend'] ))
  4681. $iidString .= ',' . implode ( ',', $iidExtend );
  4682. $invoiceList = $invoice->getInvoiceInIid ( $iidString, 'iid,invoiceSerial,invoicePrice,invoiceTitle,invoiceCompany,invoiceElement' );
  4683. $html = "";
  4684. foreach ( $invoiceList as $key => $value ) {
  4685. $title = $value ['invoiceTitle'];
  4686. if (! empty ( $value ['invoiceCompany'] ))
  4687. $title = $value ['invoiceCompany'];
  4688. $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>';
  4689. }
  4690. echo json_encode ( array (
  4691. 'status' => 1,
  4692. 'html' => $html
  4693. ) );
  4694. }
  4695. /**
  4696. * 发票管理
  4697. */
  4698. function invoiceAS() {
  4699. Doo::loadModel ( 'invoice' );
  4700. $invoice = new invoice ();
  4701. Doo::loadModel ( 'invoiceReceivables' );
  4702. $invoiceReceivables = new invoiceReceivables ();
  4703. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4704. $page_size = 18;
  4705. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4706. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4707. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4708. $dateArr = explode ( ':', $date );
  4709. $D1 = '';
  4710. $D2 = '';
  4711. if (! empty ( $date )) {
  4712. $D1 = $dateArr [0] . " 00:00:00 ";
  4713. if (isset ( $dateArr [1] ))
  4714. $D2 = $dateArr [1] . " 23:59:59 ";
  4715. else
  4716. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4717. // $D2 = $dateArr [1];
  4718. }
  4719. $con = ' status=2 ';
  4720. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4721. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4722. if ($status == 'UNRECORD')
  4723. $con .= ' and printStatus=1 and untreadStatus=0';
  4724. elseif ($status == 'RECORD')
  4725. $con .= ' and printStatus=1 and untreadStatus=3';
  4726. elseif ($status == 'BOUNCED')
  4727. $con .= ' and untreadStatus=2';
  4728. elseif ($status == 'PARTRECORD')
  4729. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  4730. elseif ($status == 'All') {
  4731. $con .= ' and ( untreadStatus=2 or untreadStatus=1 or untreadStatus=0 or untreadStatus=3 )';
  4732. }
  4733. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4734. if (! empty ( $MebSea )) {
  4735. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  4736. }
  4737. $pageinfo ['page'] = array (
  4738. 'previous' => ''
  4739. );
  4740. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAS", $get, "" );
  4741. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4742. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  4743. $this->data ['MebSeaEn'] = $MebSea;
  4744. $this->data ['MebSea'] = urlencode ( $MebSea );
  4745. $this->data ['date'] = $date;
  4746. $this->data ['page'] = $pageinfo;
  4747. $this->data ['get'] = $get;
  4748. $this->data ['list'] = $list;
  4749. $this->data ['status'] = $status;
  4750. $this->data ['memu'] = "invoice";
  4751. $this->data ['staff'] = $this->staff;
  4752. $this->data ['receiptMemu'] = 'invoiceReceivables';
  4753. $this->render ( "/admin/invoiceAS", $this->data );
  4754. }
  4755. /**
  4756. * 收款管理
  4757. */
  4758. function invoiceReceivablesAS() {
  4759. Doo::loadModel ( 'invoiceReceivables' );
  4760. $invoiceReceivables = new invoiceReceivables ();
  4761. Doo::loadModel ( 'L_category' );
  4762. $lCategory = new L_category ();
  4763. $category = $lCategory->getCategory ();
  4764. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4765. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  4766. $page_size = 10;
  4767. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4768. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4769. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4770. $dateArr = explode ( ':', $date );
  4771. $D1 = '';
  4772. $D2 = '';
  4773. if (! empty ( $date )) {
  4774. $D1 = $dateArr [0]; // ." 00:00:00 ";
  4775. if (isset ( $dateArr [1] ))
  4776. $D2 = $dateArr [1]; // ." 23:59:59 ";
  4777. else
  4778. $D2 = $dateArr [0]; // ." 23:59:59 ";//date ( "Y-m-d" );
  4779. }
  4780. $descField = 'a.receivablesDate';
  4781. if ($timeType == 'CREATE')
  4782. $descField = 'a.date';
  4783. $con = ' 1 ';
  4784. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4785. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4786. elseif (! empty ( $D1 ) && empty ( $D2 ))
  4787. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  4788. if ($status == 'Unclaimed')
  4789. $con .= ' and a.bindStatus=0';
  4790. elseif ($status == 'Credited')
  4791. $con .= ' and a.bindStatus=1';
  4792. elseif ($status == 'Claim')
  4793. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  4794. elseif ($status == 'BBN')
  4795. $con .= ' and a.bankBatchNumber!=""';
  4796. elseif ($status == 'REFUND')
  4797. $con .= ' and ( (a.bindStatus=0 and a.refundLog!="" ) or a.bindStatus=2)';
  4798. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4799. if (! empty ( $MebSea )) {
  4800. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" or a.receivablesSerial like "%' . $MebSea . '%" )';
  4801. }
  4802. $pageinfo ['page'] = array (
  4803. 'previous' => ''
  4804. );
  4805. // if(!empty($con)){
  4806. // $con=' where 1 '.$con;
  4807. // }
  4808. // $sql = 'select a.iid from CLD_invoiceReceivables as a
  4809. // ' . $con ;
  4810. $pageinfo =$this->get_page ( "CLD_invoiceReceivables as a", $con, $page, $page_size, "invoiceApprovalAchieve", $get, "" );
  4811. //echo $sql;
  4812. //$pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceReceivablesAS", $get, "" );
  4813. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4814. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', $descField );
  4815. foreach ( $list as $key => $value ) {
  4816. $list [$key] ['category'] = '';
  4817. if ($value ['receivablesCategory'] != 'PUBLIC') {
  4818. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  4819. $list [$key] ['category'] = $receivablesCategory [1];
  4820. }
  4821. }
  4822. // print_r($list);
  4823. $this->data ['category'] = $category;
  4824. $this->data ['timeType'] = $timeType;
  4825. $this->data ['MebSeaEn'] = $MebSea;
  4826. $this->data ['MebSea'] = urlencode ( $MebSea );
  4827. $this->data ['date'] = $date;
  4828. $this->data ['page'] = $pageinfo;
  4829. $this->data ['get'] = $get;
  4830. $this->data ['list'] = $list;
  4831. $this->data ['status'] = $status;
  4832. $this->data ['memu'] = "invoice";
  4833. $this->data ['staff'] = $this->staff;
  4834. $this->data ['receiptMemu'] = 'invoiceReceivables';
  4835. $this->render ( "/admin/invoiceReceivablesAS", $this->data );
  4836. }
  4837. /**
  4838. * 删除一条收款
  4839. */
  4840. function delInvoiceReceivables() {
  4841. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  4842. if (empty ( $iridKey ))
  4843. die ( 'illegal request' );
  4844. Doo::loadClass ( 'XDeode' );
  4845. $XDeode = new XDeode ( 5 );
  4846. $irid = $XDeode->decode ( $iridKey );
  4847. Doo::loadModel ( 'invoiceReceivables' );
  4848. $invoiceReceivables = new invoiceReceivables ();
  4849. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4850. if (empty ( $detail ))
  4851. die ( 'illegal request' );
  4852. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  4853. // 扣除收款汇总信息 汇总
  4854. Doo::loadModel ( 'invoiceStatistics' );
  4855. $invoiceStatistics = new invoiceStatistics ();
  4856. $item = array (
  4857. 'date' => $detail ['receivablesDate'],
  4858. 'priceClass' => 2,
  4859. 'irid' => $detail ['irid'],
  4860. 'receivablesPrice' => - $detail ['receivablesPrice']
  4861. );
  4862. if ($detail ['receivablesCategory'] != 'PUBLIC') {
  4863. $receivablesCategory = explode ( ":", $detail ['receivablesCategory'] );
  4864. $item += array (
  4865. 'cid' => $receivablesCategory [0]
  4866. );
  4867. }
  4868. if ($detail ['receivablesStaff'] != 'PUBLIC') {
  4869. $receivablesStaff = explode ( "-", $detail ['receivablesStaff'] );
  4870. $item += array (
  4871. 'staff' => $receivablesStaff [0]
  4872. );
  4873. }
  4874. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4875. return '/invoiceReceivablesAS';
  4876. }
  4877. /**
  4878. * 添加退款信息
  4879. */
  4880. function setInvoiceReceivablesRefund() {
  4881. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  4882. $refundType = $this->get_args ( 'refundType' ) && is_numeric ( $this->get_args ( 'refundType' ) ) ? $this->get_args ( 'refundType' ) : '0';
  4883. $refundCompany = $this->get_args ( 'refundCompany' ) ? $this->get_args ( 'refundCompany' ) : "";
  4884. $refundNumber = $this->get_args ( 'refundNumber' ) ? $this->get_args ( 'refundNumber' ) : "";
  4885. $refundPrice = $this->get_args ( 'refundPrice' ) ? $this->get_args ( 'refundPrice' ) : "";
  4886. $refundRemarks = $this->get_args ( 'refundRemarks' ) ? $this->get_args ( 'refundRemarks' ) : "";
  4887. if ($refundPrice < 0)
  4888. die ( 'illegal request' );
  4889. if (! empty ( $iridKey ) && ! empty ( $refundCompany ) && ! empty ( $refundNumber ) && ! empty ( $refundPrice )) {
  4890. Doo::loadModel ( 'invoiceReceivables' );
  4891. $invoiceReceivables = new invoiceReceivables ();
  4892. Doo::loadModel ( 'invoiceRefund' );
  4893. $invoiceRefund = new invoiceRefund ();
  4894. $irid = $invoiceReceivables->authcode ( $iridKey );
  4895. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4896. if ($irDetail ['receivablesPrice'] < $refundPrice)
  4897. die ( 'illegal request' );
  4898. $invoiceReceivables = new invoiceReceivables ();
  4899. $refundLog = $this->staff [0] ['username'] . ' 退款 <b class="colRed">¥' . $refundPrice . '</b>
  4900. <br/><a href="#refunded" onclick="getRefundByDetail(\'' . $iridKey . '\')" data-toggle="modal">退款信息</a> <br/>' . date ( "Y-m-d H:i:s" ) . '
  4901. ';
  4902. $item = array (
  4903. 'irid' => $irid,
  4904. 'refundCompany' => $refundCompany,
  4905. 'refundNumber' => $refundNumber,
  4906. 'refundPrice' => $refundPrice,
  4907. 'refundRemarks' => $refundRemarks,
  4908. 'refundLog' => $refundLog
  4909. );
  4910. if ($refundType == 1) {
  4911. $item += array (
  4912. 'refundType' => $refundType,
  4913. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice,
  4914. 'bindStatus' => 2
  4915. );
  4916. } elseif ($refundType == 0 && $irDetail ['receivablesPrice'] <= $refundPrice) {
  4917. $item += array (
  4918. 'refundType' => 1,
  4919. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice,
  4920. 'bindStatus' => 2
  4921. );
  4922. } else {
  4923. $item += array (
  4924. 'refundType' => $refundType,
  4925. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice
  4926. );
  4927. }
  4928. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4929. // 添加退款记录
  4930. $item = array (
  4931. 'irid' => $irid,
  4932. 'refundType' => $refundType,
  4933. 'refundCompany' => $refundCompany,
  4934. 'refundNumber' => $refundNumber,
  4935. 'refundPrice' => $refundPrice,
  4936. 'refundLog' => $refundLog,
  4937. 'refundRemarks' => $refundRemarks,
  4938. 'date' => date ( "Y-m-d H:i:s" )
  4939. );
  4940. $invoiceRefund->addInvoiceRefund ( $item );
  4941. // 扣除收款汇总信息 汇总
  4942. Doo::loadModel ( 'invoiceStatistics' );
  4943. $invoiceStatistics = new invoiceStatistics ();
  4944. $item = array (
  4945. 'date' => $irDetail ['receivablesDate'],
  4946. 'priceClass' => 2,
  4947. 'irid' => $irDetail ['irid'],
  4948. 'receivablesPrice' => - $refundPrice
  4949. );
  4950. if ($irDetail ['receivablesCategory'] != 'PUBLIC') {
  4951. $receivablesCategory = explode ( ":", $irDetail ['receivablesCategory'] );
  4952. $item += array (
  4953. 'cid' => $receivablesCategory [0]
  4954. );
  4955. }
  4956. if ($irDetail ['receivablesStaff'] != 'PUBLIC') {
  4957. $receivablesStaff = explode ( "-", $irDetail ['receivablesStaff'] );
  4958. $item += array (
  4959. 'staff' => $receivablesStaff [0]
  4960. );
  4961. }
  4962. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4963. // 公司日常支出流水
  4964. Doo::loadModel ( 'wasteBook' );
  4965. $wasteBook = new wasteBook ();
  4966. $accountBank = '';
  4967. if ($irDetail ['receivablesBank'] == '纵横广发') {
  4968. $accountBank = 'CGBDeposit';
  4969. } elseif ($irDetail ['receivablesBank'] == '纵横工行') {
  4970. $accountBank = 'ICBCDeposit';
  4971. } elseif ($irDetail ['receivablesBank'] == '华润银行') {
  4972. $accountBank = 'HUADeposit';
  4973. } elseif ($irDetail ['receivablesBank'] == '个人广发') {
  4974. $accountBank = 'PersonalDeposit';
  4975. }
  4976. $itemWaste = array (
  4977. 'accountPrice' => - $refundPrice,
  4978. 'expensesType' => 2,
  4979. 'accountType' => 11,
  4980. 'accountPriceShow' => $refundPrice,
  4981. 'dataID' => $irid,
  4982. 'accountBank' => $accountBank,
  4983. 'category' => $this->staff [0] ['category'],
  4984. 'cid' => $this->staff [0] ['cid'],
  4985. 'name' => $this->staff [0] ['username'],
  4986. 'sid' => $this->staff [0] ['sid'],
  4987. 'inputDate' => date ( "Y-m-d H:i:s" )
  4988. );
  4989. $wasteBook->setAccountBookStatistics ( $itemWaste );
  4990. return '/invoiceReceivablesAS';
  4991. }
  4992. die ( 'illegal request' );
  4993. }
  4994. function ajaxCheckInvoiceReceivablesRefund() {
  4995. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  4996. $refundPrice = $this->get_args ( 'refundPrice' ) ? $this->get_args ( 'refundPrice' ) : "";
  4997. if ($refundPrice < 0) {
  4998. echo json_encode ( array (
  4999. 'error' => '金额不能为负'
  5000. ) );
  5001. die ();
  5002. }
  5003. if (! empty ( $refundPrice ) && ! empty ( $iridKey )) {
  5004. Doo::loadModel ( 'invoiceReceivables' );
  5005. $invoiceReceivables = new invoiceReceivables ();
  5006. $irid = $invoiceReceivables->authcode ( $iridKey );
  5007. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5008. if ($irDetail ['receivablesPrice'] < $refundPrice) {
  5009. echo json_encode ( array (
  5010. 'error' => '退款金额不能超过收款金额'
  5011. ) );
  5012. die ();
  5013. }
  5014. echo json_encode ( array (
  5015. 'ok' => '可以使用!'
  5016. ) );
  5017. die ();
  5018. }
  5019. }
  5020. /**
  5021. * 获得收款退款信息
  5022. */
  5023. function getRefundByDetail() {
  5024. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5025. Doo::loadModel ( 'invoiceReceivables' );
  5026. $invoiceReceivables = new invoiceReceivables ();
  5027. if (! empty ( $iridKey )) {
  5028. $irid = $invoiceReceivables->authcode ( $iridKey );
  5029. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5030. echo json_encode ( array (
  5031. 'status' => 1,
  5032. 'irDetail' => $irDetail
  5033. ) );
  5034. die ();
  5035. }
  5036. echo json_encode ( array (
  5037. 'status' => 2
  5038. ) );
  5039. }
  5040. /**
  5041. * 根据收款序列号获得收款退款信息
  5042. */
  5043. function ajaxGetInvoiceReceivablesBySerial() {
  5044. $receivablesSerial = $this->get_args ( 'receivablesSerial' ) ? $this->get_args ( 'receivablesSerial' ) : '';
  5045. if (! empty ( $receivablesSerial )) {
  5046. Doo::loadModel ( 'invoiceReceivables' );
  5047. $invoiceReceivables = new invoiceReceivables ();
  5048. // , ' and refundLog=""'
  5049. $irDetail = $invoiceReceivables->getInvoiceReceivablesBySerial ( $receivablesSerial );
  5050. $html = '';
  5051. if (! empty ( $irDetail ))
  5052. $html = '<td><b>¥' . $irDetail ['receivablesPrice'] . '</b></td>
  5053. <td>' . $irDetail ['receivablesMessage'] . '</td>
  5054. <td>' . $irDetail ['receivablesBank'] . '<br>' . $irDetail ['receivablesDate'] . '</td>
  5055. <td>' . $irDetail ['title'] . '-' . $irDetail ['username'] . '<br>' . $irDetail ['confirmTime'] . '</td>
  5056. <td>' . $irDetail ['recepitTitleMark'] . '
  5057. <input type="hidden" name="iridKey" id="iridKey" value="' . $irDetail ['iridKey'] . '">
  5058. </td>';
  5059. echo json_encode ( array (
  5060. 'status' => 1,
  5061. 'html' => $html,
  5062. 'irDetail' => $irDetail
  5063. ) );
  5064. die ();
  5065. }
  5066. echo json_encode ( array (
  5067. 'status' => 2
  5068. ) );
  5069. }
  5070. /**
  5071. * 绑定新收款
  5072. */
  5073. function relationNewInvoiceReceivables() {
  5074. $iridKeyOld = $this->get_args ( 'iridKeyOld' ) ? $this->get_args ( 'iridKeyOld' ) : '';
  5075. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5076. if (! empty ( $iridKeyOld ) && ! empty ( $iridKey )) {
  5077. Doo::loadModel ( 'invoiceReceivables' );
  5078. $invoiceReceivables = new invoiceReceivables ();
  5079. Doo::loadClass ( 'XDeode' );
  5080. $XDeode = new XDeode ( 5 );
  5081. $irid = $XDeode->decode ( $iridKey );
  5082. $iridOld = $invoiceReceivables->authcode ( $iridKeyOld );
  5083. echo $irid . 'bbb' . $iridOld;
  5084. $oldIrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $iridOld );
  5085. $IrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5086. if (empty ( $oldIrDetail ) || empty ( $IrDetail ))
  5087. die ( 'illegal request' );
  5088. $relationLog = $this->staff [0] ['username'] . ' 关联新款 <a href="#billing" onclick="invoiceReceivblesDivShow(\'' . $iridKey . '\',\'receivables\')" data-toggle="modal">' . $IrDetail ['receivablesSerial'] . '</a>
  5089. <br/>' . date ( "Y-m-d H:i:s" ) . '
  5090. ';
  5091. $invoiceReceivables = new invoiceReceivables ();
  5092. $item = array (
  5093. 'irid' => $iridOld,
  5094. 'relationIrid' => $irid,
  5095. 'relationLog' => $relationLog
  5096. );
  5097. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  5098. return '/invoiceReceivablesAS';
  5099. }
  5100. die ( 'illegal request' );
  5101. }
  5102. // function invoiceApprovalAchieve() {
  5103. // Doo::loadModel ( 'invoice' );
  5104. // $invoice = new invoice ();
  5105. // $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  5106. // $page_size = 12;
  5107. // $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5108. // $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  5109. // $get = "/" . $date;
  5110. // $con = '';
  5111. // if ($date == 'MONTHO')
  5112. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  5113. // elseif ($date == 'MONTHT')
  5114. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  5115. // elseif ($date == 'MONTHY')
  5116. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  5117. // if (! empty ( $MebSea )) {
  5118. // $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  5119. // $get .= "/" . $MebSea;
  5120. // }
  5121. // $pageinfo ['page'] = array (
  5122. // 'previous' => ''
  5123. // );
  5124. // $sql = '(status=1 or status=2 or status=3 or status=4) and processApprovals!=""' . $con; // echo $sql;
  5125. // $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", $get, "" );
  5126. // $limit = $pageinfo ['lower'] . ',' . $page_size;
  5127. // $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  5128. // // print_r($list);
  5129. // $this->data ['MebSeaEn'] = $MebSea;
  5130. // $this->data ['MebSea'] = urlencode ( $MebSea );
  5131. // $this->data ['get'] = $get;
  5132. // $this->data ['page'] = $pageinfo;
  5133. // $this->data ['list'] = $list;
  5134. // $this->data ['date'] = $date;
  5135. // $this->data ['memu'] = "invoice";
  5136. // $this->data ['staff'] = $this->staff;
  5137. // $this->data ['receiptMemu'] = 'invoiceApproval';
  5138. // $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  5139. // }
  5140. /**
  5141. * 获得审批发票的信息以及审批页面
  5142. */
  5143. function ajaxGetInvoiceApprovalDetail() {
  5144. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5145. if (empty ( $serial )) {
  5146. echo json_encode ( array (
  5147. 'status' => 2,
  5148. 'msg' => 'illegal request'
  5149. ) );
  5150. die ();
  5151. }
  5152. Doo::loadModel ( 'invoice' );
  5153. $invoice = new invoice ();
  5154. Doo::loadModel ( 'invoiceOperationLog' );
  5155. $invoiceOperationLog = new invoiceOperationLog ();
  5156. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5157. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5158. if (empty ( $detail ))
  5159. $html = '';
  5160. else {
  5161. $html = '
  5162. <form action="/invoiceApprovalDo" method="post" name="invoiceApproval" class="nice-validator n-yellow" novalidate="novalidate">
  5163. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  5164. <input type="hidden" name="status" value="">
  5165. <input type="hidden" name="divApproval" value="divApproval">
  5166. <div class="modal-dialog modal-lg">
  5167. <div class="modal-content"><div class="modal-header"><h3>发票审批详情</h3></div>
  5168. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  5169. <tr>
  5170. <th class="taC" width="150">发票审批</th><td><textarea name="opinion" style="width:98%" placeholder="在这写下您的审批意见,选填。"></textarea></td>
  5171. </tr>
  5172. <tr>
  5173. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5174. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5175. </tr>
  5176. <tr>
  5177. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5178. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5179. </tr>
  5180. <tr>
  5181. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5182. </td>
  5183. </tr>
  5184. <tr>
  5185. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5186. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5187. </tr>
  5188. <tr>
  5189. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5190. </tr></tbody></table>';
  5191. if ($detail ['invoiceType'] == 0)
  5192. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5193. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5194. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5195. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5196. </tr>';
  5197. else
  5198. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5199. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5200. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5201. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5202. ';
  5203. $html .= '<tr>
  5204. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5205. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5206. </tr>
  5207. <tr>
  5208. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5209. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5210. </tr></tbody></table>';
  5211. if ($detail ['doPost'] == 1) {
  5212. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5213. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5214. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5215. </tr><tr>
  5216. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5217. </tr><tr>
  5218. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5219. </tr>
  5220. ';
  5221. if ($detail ['expressCom'] == 'SF')
  5222. $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>';
  5223. else
  5224. $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>';
  5225. $html .= '</tbody></table>';
  5226. }
  5227. if (! empty ( $invoiceOperationLogList )) {
  5228. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  5229. foreach ( $invoiceOperationLogList as $key => $value ) {
  5230. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5231. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5232. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5233. if ($value ['status'] == 2) {
  5234. $html .= '<span class="colGreen">同意</span>';
  5235. } elseif ($value ['status'] == 3) {
  5236. $html .= '<span class="colOrange">退回</span>';
  5237. } elseif ($value ['status'] == 5) {
  5238. $html .= '<span class="colGreen">打印</span>';
  5239. } elseif ($value ['status'] == 4) {
  5240. $html .= '<span class="colRed">终止</span>';
  5241. }
  5242. $html .= $value ['operation'] . '</p></blockquote>';
  5243. }
  5244. }
  5245. $html .= '</td></tr></tbody></table>';
  5246. }
  5247. $html .= '</div><div class="modal-footer">
  5248. <a href="javascript:void(0)" node-approval="approval" diss-data="2" class="button btn-done" data-placement="top" data-toggle="ctooltip" >同意</a>
  5249. <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>
  5250. <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>
  5251. <a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>
  5252. </form>
  5253. <script type="text/javascript">
  5254. $("a[node-approval^=\'approval\']").click(function() {
  5255. $("input[name=\'status\']").val($(this).attr("diss-data"));
  5256. $("form[name=\'invoiceApproval\']").submit();
  5257. });
  5258. </script>
  5259. ';
  5260. }
  5261. echo json_encode ( array (
  5262. 'status' => 1,
  5263. 'html' => $html
  5264. ) );
  5265. die ();
  5266. }
  5267. /**
  5268. * 获得审批发票分页数据
  5269. */
  5270. function ajaxGetinvoiceApprovalAchieve() {
  5271. Doo::loadModel ( 'invoice' );
  5272. $invoice = new invoice ();
  5273. Doo::loadModel ( 'staff' );
  5274. $staff = new staff ();
  5275. Doo::loadClass ( 'XDeode' );
  5276. $XDeode = new XDeode ( 5 );
  5277. Doo::loadModel ( 'invoiceTraining' );
  5278. $invoiceTraining = new invoiceTraining ();
  5279. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  5280. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5281. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5282. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5283. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5284. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  5285. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  5286. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  5287. $MebSea = $this->get_args ( 'search' );
  5288. $MebSea = $MebSea ['value'];
  5289. $page_size = $length;
  5290. $con = '';
  5291. if ($status == 'ALL')
  5292. $con = ' (status=1 or status=2 or status=3 or status=4) and isDelete=0 ';
  5293. elseif ($status == 'PEND')
  5294. $con = ' isDelete=0 and status=1';
  5295. elseif ($status == 'APPROVED')
  5296. $con = ' isDelete=0 and status=2';
  5297. if ($invoiceType == 'ORDINARY')
  5298. $con .= ' and invoiceType=0 ';
  5299. elseif ($invoiceType == 'SPECIAL')
  5300. $con .= ' and invoiceType=1 ';
  5301. if ($invoiceTrain == 'ORDINARY')
  5302. $con .= ' and trainId=0 ';
  5303. elseif ($invoiceTrain == 'TRAIN')
  5304. $con .= ' and trainId!=0 ';
  5305. if ($invoiceTrainName != 'ALL') {
  5306. $trainId = $XDeode->decode ( $invoiceTrainName );
  5307. if (is_numeric ( $trainId ))
  5308. $con .= ' and trainId =' . $trainId;
  5309. }
  5310. $dateArr = explode ( ':', $date );
  5311. $D1 = $dateString = '';
  5312. $D2 = '';
  5313. if (! empty ( $date )) {
  5314. $D1 = $dateArr [0];
  5315. if (isset ( $dateArr [1] ))
  5316. $D2 = $dateArr [1];
  5317. else
  5318. $D2 = '';
  5319. $dateString = $D1 . " : " . $D2;
  5320. }
  5321. if (! empty ( $D1 ) && ! empty ( $D2 ))
  5322. $con .= ' and approvalTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  5323. elseif (! empty ( $D1 ) && empty ( $D2 ))
  5324. $con .= ' and approvalTime like "%' . $D1 . '%" ';
  5325. if (! empty ( $MebSea ))
  5326. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceSerial like "%' . $MebSea . '%" )';
  5327. // /
  5328. $pageinfo ['page'] = array (
  5329. 'previous' => ''
  5330. );
  5331. $sql = ' ' . $con;
  5332. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", '', "" );
  5333. $limit = $page . ',' . $page_size;
  5334. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  5335. $approvalList = array ();
  5336. $html = '<script type="text/javascript">
  5337. </script>';
  5338. // 结算结束不能修改方式
  5339. Doo::loadModel ( 'receipt' );
  5340. $receipt = new receipt ();
  5341. foreach ( $list as $key => $value ) {
  5342. $irDetail = array ();
  5343. // 结算方式
  5344. $receiptDetail = array ();
  5345. if ($value ['trainId'] != 0) {
  5346. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $value ['trainId'] );
  5347. }
  5348. if (! empty ( $receiptDetail )) {
  5349. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9) {
  5350. array_push ( $irDetail, '' );
  5351. } else {
  5352. if ($value ['status'] == 1 && $value ['pendingApprovals'] == $this->staff [0] ['sid']) {
  5353. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoiceApproval(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">审批发票</a>' );
  5354. } elseif ($value ['status'] == 2) {
  5355. array_push ( $irDetail, '<a href="#editPay" class="fnSettlementType" data-iidKey="' . $value ['iidKeyK'] . '" data-toggle="modal">结算方式</a>' );
  5356. } else
  5357. array_push ( $irDetail, '' );
  5358. }
  5359. } else {
  5360. if ($value ['status'] == 2) {
  5361. array_push ( $irDetail, '<a href="#editPay" class="fnSettlementType" data-iidKey="' . $value ['iidKeyK'] . '" data-toggle="modal">结算方式</a>' );
  5362. } else
  5363. array_push ( $irDetail, '' );
  5364. }
  5365. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  5366. if ($value ['invoiceType'] == 1)
  5367. array_push ( $irDetail, $value ['invoiceCompany'] );
  5368. else
  5369. array_push ( $irDetail, $value ['invoiceTitle'] );
  5370. array_push ( $irDetail, $value ['TIN'] );
  5371. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  5372. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  5373. array_push ( $irDetail, $value ['remark'] );
  5374. array_push ( $irDetail, $value ['invoiceElement'] );
  5375. array_push ( $irDetail, $value ['invoiceQuantity'] );
  5376. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  5377. if ($value ['invoiceType'] == 1) {
  5378. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  5379. } else {
  5380. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  5381. }
  5382. if ($value ['settlementType'] == 0) {
  5383. array_push ( $irDetail, '软件销售' );
  5384. } else {
  5385. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $value ['trainId'] );
  5386. array_push ( $irDetail, $itDetail ['trainName'] );
  5387. }
  5388. array_push ( $irDetail, $value ['recipients'] . $value ['recipientsPhone'] );
  5389. array_push ( $irDetail, $value ['recipientsAddress'] );
  5390. array_push ( $irDetail, $value ['mailItems'] );
  5391. array_push ( $irDetail, $value ['userName'] . '&nbsp;' . $value ['date'] );
  5392. $fchtml = $value ['OL'] ['operation'];
  5393. if (count ( $list ) == $page_size)
  5394. $fchtml = $value ['OL'] ['operation'] . $html;
  5395. // 最后的审批意见
  5396. array_push ( $irDetail, $fchtml );
  5397. if ($value ['status'] == 2)
  5398. array_push ( $irDetail, '<span class="colGreen">同意</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5399. elseif ($value ['status'] == 3)
  5400. array_push ( $irDetail, '<span class="colOrange">退回</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5401. elseif ($value ['status'] == 4)
  5402. array_push ( $irDetail, '<span class="colRed">终止</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5403. else
  5404. array_push ( $irDetail, '' );
  5405. array_push ( $approvalList, $irDetail );
  5406. }
  5407. // $approvalListJson = json_encode ( $approvalList );
  5408. $recordsFiltered = $pageinfo ['total_data'];
  5409. echo json_encode ( array (
  5410. "draw" => intval ( $draw ),
  5411. "recordsTotal" => intval ( $pageinfo ['total_data'] ),
  5412. "recordsFiltered" => intval ( $recordsFiltered ),
  5413. "data" => $approvalList
  5414. ), JSON_UNESCAPED_UNICODE );
  5415. }
  5416. /**
  5417. * 审批发票查看更多--重构
  5418. */
  5419. function invoiceApprovalAchieve() {
  5420. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'ALL';
  5421. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5422. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5423. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5424. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5425. Doo::loadModel ( 'invoiceTraining' );
  5426. $invoiceTraining = new invoiceTraining ();
  5427. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  5428. $this->data ['trainList'] = $trainList;
  5429. $this->data ['dateString'] = $date;
  5430. $this->data ['status'] = $status;
  5431. $this->data ['invoiceType'] = $invoiceType;
  5432. $this->data ['invoiceTrain'] = $invoiceTrain;
  5433. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  5434. $this->data ['memu'] = "invoice";
  5435. $this->data ['staff'] = $this->staff;
  5436. $this->data ['receiptMemu'] = 'invoiceApproval';
  5437. $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  5438. }
  5439. function invoiceTAchieve() {
  5440. Doo::loadModel ( 'invoice' );
  5441. $invoice = new invoice ();
  5442. Doo::loadClass ( 'XDeode' );
  5443. $XDeode = new XDeode ( 5 );
  5444. Doo::loadModel ( 'staff' );
  5445. $staff = new staff ();
  5446. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  5447. $page_size = 12;
  5448. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5449. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  5450. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5451. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5452. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5453. Doo::loadModel ( 'invoiceTraining' );
  5454. $invoiceTraining = new invoiceTraining ();
  5455. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  5456. $get = "/" . $date;
  5457. $con = '';
  5458. if ($date == 'MONTHO')
  5459. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  5460. elseif ($date == 'MONTHT')
  5461. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  5462. elseif ($date == 'MONTHY')
  5463. $con = ' and YEAR(updateTime) = YEAR(NOW())'; // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  5464. if ($invoiceType == 'ORDINARY')
  5465. $con .= ' and invoiceType=0 ';
  5466. elseif ($invoiceType == 'SPECIAL')
  5467. $con .= ' and invoiceType=1 ';
  5468. if ($invoiceTrain == 'ORDINARY')
  5469. $con .= ' and trainId=0 ';
  5470. elseif ($invoiceTrain == 'TRAIN')
  5471. $con .= ' and trainId!=0 ';
  5472. if ($invoiceTrainName != 'ALL') {
  5473. $trainId = $XDeode->decode ( $invoiceTrainName );
  5474. if (is_numeric ( $trainId ))
  5475. $con .= ' and trainId =' . $trainId;
  5476. }
  5477. if (! empty ( $MebSea )) {
  5478. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  5479. $get .= "/" . $MebSea;
  5480. }
  5481. $pageinfo ['page'] = array (
  5482. 'previous' => ''
  5483. );
  5484. $sql = "";
  5485. $action = "";
  5486. if ($this->ACTION == 'invoicePrintAchieve') {
  5487. $sql = "status=2 and printStatus=1 and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  5488. $action = "invoicePrintAchieve";
  5489. } elseif ($this->ACTION == 'invoicePostAchieve') {
  5490. // and untreadStatus=0
  5491. $sql = "postStatus=1 and doPost=1 and status=2 and isDelete=0" . $con;
  5492. $action = "invoicePostAchieve";
  5493. } elseif ($this->ACTION == 'invoiceUntreadAchieve') { // printStatus=1 and
  5494. $sql = " untreadStatus=2 and status=2 " . $con;
  5495. $action = "invoiceUntreadAchieve";
  5496. }
  5497. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  5498. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5499. $this->data ['MebSeaEn'] = $MebSea;
  5500. $this->data ['MebSea'] = urlencode ( $MebSea );
  5501. $this->data ['get'] = $get;
  5502. $this->data ['page'] = $pageinfo;
  5503. $this->data ['trainList'] = $trainList;
  5504. $this->data ['invoiceType'] = $invoiceType;
  5505. $this->data ['invoiceTrain'] = $invoiceTrain;
  5506. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  5507. $this->data ['date'] = $date;
  5508. $this->data ['memu'] = "invoice";
  5509. $this->data ['staff'] = $this->staff;
  5510. if ($this->ACTION == 'invoicePrintAchieve') {
  5511. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  5512. $this->data ['receiptMemu'] = 'invoicePrint';
  5513. $this->data ['list'] = $list;
  5514. $this->render ( "/admin/invoicePrintAchieve", $this->data );
  5515. } elseif ($this->ACTION == 'invoicePostAchieve') {
  5516. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  5517. Doo::loadModel ( 'express' );
  5518. $express = new express ();
  5519. $expressList = $express->getExpressByAll ();
  5520. $this->data ['expressList'] = $expressList;
  5521. $this->data ['receiptMemu'] = 'invoicePost';
  5522. $this->data ['list'] = $list;
  5523. $this->render ( "/admin/invoicePostAchieve", $this->data );
  5524. } elseif ($this->ACTION == 'invoiceUntreadAchieve') {
  5525. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  5526. $this->data ['receiptMemu'] = 'invoiceUntread';
  5527. $this->data ['list'] = $list;
  5528. $this->render ( "/admin/invoiceUntreadAchieve", $this->data );
  5529. }
  5530. }
  5531. /**
  5532. * 公司应收款
  5533. */
  5534. function invoiceAggregateCompanyDetail() {
  5535. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  5536. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  5537. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : 'ALL';
  5538. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  5539. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  5540. $titleORno = $this->get_args ( 'titleORno' ) ? $this->get_args ( 'titleORno' ) : "";
  5541. Doo::loadClass ( 'XDeode' );
  5542. $XDeode = new XDeode ( 5 );
  5543. Doo::loadModel ( 'invoice' );
  5544. $invoice = new invoice ();
  5545. Doo::loadModel ( 'staff' );
  5546. $staff = new staff ();
  5547. Doo::loadModel ( "invoiceCompanyManage" );
  5548. $invoiceCompanyManage = new invoiceCompanyManage ();
  5549. Doo::loadModel ( 'L_category' );
  5550. $category = new L_category ();
  5551. $sid = '';
  5552. if (! empty ( $sidKey )) {
  5553. $sid = $XDeode->decode ( $sidKey );
  5554. }
  5555. $staffDetail = $staff->getStaffBySid ( $sid );
  5556. $cid = '';
  5557. if (! empty ( $cidKey )) {
  5558. $cid = $XDeode->decode ( $cidKey );
  5559. }
  5560. $imcStaff = $invoiceCompanyManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  5561. $cidList = array ();
  5562. foreach ( $imcStaff as $key => $value ) {
  5563. array_push ( $cidList, $value ['cid'] );
  5564. }
  5565. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  5566. $cidString = implode ( ',', $cidList );
  5567. if (empty ( $cid ))
  5568. $staffList = $staff->getStaffInCid ( $cidString );
  5569. else
  5570. $staffList = $staff->getStaffByCidAll ( $cid ); //
  5571. //$MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  5572. $page_size = 25;
  5573. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5574. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  5575. $con = ' status=2 and untreadStatus!=2 ';
  5576. $statisticsCon = '';
  5577. if (! empty ( $year ) && is_numeric ( $year ))
  5578. $con .= ' and Year(printTime)=' . $year . '';
  5579. if (! empty ( $month ) && is_numeric ( $month ))
  5580. $con .= ' and Month(printTime)="' . $month . '" ';
  5581. if ($status == 'UNRECORD')
  5582. $con .= ' and printStatus=1 and untreadStatus=0';
  5583. elseif ($status == 'RECORD')
  5584. $con .= ' and printStatus=1 and untreadStatus=3';
  5585. elseif ($status == 'BOUNCED')
  5586. $con .= ' and untreadStatus=2';
  5587. elseif ($status == 'PARTRECORD')
  5588. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  5589. elseif ($status == 'All') {
  5590. $con .= ' and printStatus=1 and ( untreadStatus=0 or untreadStatus=3 )';
  5591. }
  5592. if (! empty ( $sid ) && is_numeric ( $sid ))
  5593. $con .= ' and sid=' . $sid;
  5594. if (! empty ( $cid ) && is_numeric ( $cid ))
  5595. $con .= ' and cid=' . $cid;
  5596. else
  5597. $con .= ' and cid in (' . $cidString . ')';
  5598. // 开票内容筛选
  5599. if (! empty ( $invoiceElement ) && $invoiceElement != 'ALL') {
  5600. $con .= ' and invoiceElement="' . $invoiceElement . '"';
  5601. }
  5602. $get = "/" . $status . "?cidKey=" . $cidKey . "&sidKey=" . $sidKey . "&year=" . $year . "&month=" . $month
  5603. . "&invoiceElement=" . $invoiceElement."&titleORno=".urlencode ( $titleORno );
  5604. if (! empty ( $titleORno )) {
  5605. $con .= ' and ( invoiceTitle like "%' . $titleORno . '%" or invoiceCompany like "%' . $titleORno . '%" or invoiceNo like "%'.$titleORno.'%" )';
  5606. }
  5607. $pageinfo ['page'] = array (
  5608. 'previous' => ''
  5609. );
  5610. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateCompanyDetail", $get, "" );
  5611. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5612. // 应收款合计
  5613. $ics = $invoice->getInvoiceCompanyStatistics ( $con );
  5614. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  5615. $monthHtml = "";
  5616. if ($year != "ALL") {
  5617. for($i = 1; $i <= 12; $i ++) {
  5618. if ($i == $month)
  5619. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  5620. else
  5621. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  5622. }
  5623. }
  5624. $this->data ['monthHtml'] = $monthHtml;
  5625. $this->data ['year'] = $year;
  5626. $this->data ['month'] = $month;
  5627. $this->data ['ics'] = $ics;
  5628. $this->data ['cidKey'] = $cidKey;
  5629. $this->data ['sid'] = $sid;
  5630. $this->data ['staffDetail'] = $staffDetail;
  5631. $this->data ['staffList'] = $staffList;
  5632. $this->data ['titleORnoEn'] = $titleORno;
  5633. $this->data ['titleORno'] = urlencode ( $titleORno );
  5634. $this->data ['invoiceDetail'] = array (
  5635. 'invoiceElement' => $invoiceElement
  5636. );
  5637. $this->data ['page'] = $pageinfo;
  5638. $this->data ['get'] = $get;
  5639. $this->data ['list'] = $list;
  5640. $this->data ['status'] = $status;
  5641. $this->data ['categoryList'] = $categoryList;
  5642. $this->data ['memu'] = "invoice";
  5643. $this->data ['staff'] = $this->staff;
  5644. $this->data ['receiptMemu'] = 'invoiceAggregateCompanyDetail';
  5645. $this->render ( "/admin/invoiceAggregateCompanyDetail", $this->data );
  5646. }
  5647. /**
  5648. * 获取一条收款信息
  5649. */
  5650. function ajaxGetInvoiceReceivables() {
  5651. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  5652. Doo::loadModel ( 'invoiceReceivables' );
  5653. $invoiceReceivables = new invoiceReceivables ();
  5654. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5655. echo json_encode ( array (
  5656. 'status' => 1,
  5657. 'detail' => $detail
  5658. ) );
  5659. }
  5660. /**
  5661. * 异步获取办事处用户
  5662. */
  5663. function ajaxGetStaffByCategory() {
  5664. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "";
  5665. Doo::loadModel ( 'staff' );
  5666. $staff = new staff ();
  5667. if ($cid == "PUBLIC") {
  5668. echo json_encode ( array (
  5669. 'status' => 1,
  5670. 'html' => '<option value="PUBLIC">办事处待认领款项</option>'
  5671. ) );
  5672. die ();
  5673. }
  5674. if (! is_numeric ( $cid )) {
  5675. echo json_encode ( array (
  5676. 'status' => 0,
  5677. 'msg' => 'illegal request'
  5678. ) );
  5679. die ();
  5680. }
  5681. $staffList = $staff->getStaffByCid ( $cid );
  5682. $html = '<option value="PUBLIC">办事处待认领款项</option>';
  5683. foreach ( $staffList as $key => $value ) {
  5684. $html .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  5685. }
  5686. echo json_encode ( array (
  5687. 'status' => 1,
  5688. 'html' => $html
  5689. ) );
  5690. }
  5691. /**
  5692. * 异步获取一条发票的邮寄信息
  5693. */
  5694. function ajaxGetInvoicePostDetail() {
  5695. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  5696. Doo::loadModel ( 'invoice' );
  5697. $invoice = new invoice ();
  5698. $iid = $invoice->authcode ( $iid );
  5699. Doo::loadModel ( 'express' );
  5700. $express = new express ();
  5701. $expressList = $express->getExpressByAll ();
  5702. if (! is_numeric ( $iid )) {
  5703. echo json_encode ( array (
  5704. 'status' => 0,
  5705. 'msg' => 'illegal request'
  5706. ) );
  5707. die ();
  5708. }
  5709. $select = "iid,recipients,recipientsPhone,recipientsAddress,mailItems,expressCompany,expressNumber,actualItems";
  5710. $invoiceDetail = $invoice->getInvoiceByIid ( $iid, $select );
  5711. $html = "";
  5712. foreach ( $expressList as $key => $value ) {
  5713. if ($value ['company'] == $invoiceDetail ['expressCompany'])
  5714. $html .= '<option selected value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  5715. else
  5716. $html .= '<option value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  5717. }
  5718. $invoiceDetail ['eaHtml'] = $html;
  5719. echo json_encode ( array (
  5720. 'status' => 1,
  5721. 'invoiceDetail' => $invoiceDetail
  5722. ) );
  5723. }
  5724. /**
  5725. *
  5726. * @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 ) ); }
  5727. */
  5728. /**
  5729. *
  5730. * @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 ) ); }
  5731. */
  5732. /**
  5733. * 我的收款中 选择哪个发票入账,进行金额判断
  5734. */
  5735. function ajaxCompareInvoicePrice() {
  5736. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  5737. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  5738. Doo::loadModel ( 'invoice' );
  5739. $invoice = new invoice ();
  5740. Doo::loadModel ( 'invoiceReceivables' );
  5741. $invoiceReceivables = new invoiceReceivables ();
  5742. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  5743. $keyList = explode ( ';', $claimKey );
  5744. $receivablesPrice = 0;
  5745. foreach ( $keyList as $key => $value ) {
  5746. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $value );
  5747. $receivablesPrice += $detailM ['receivablesPrice'];
  5748. }
  5749. if ($receivablesPrice > $detail ['invoicePrice']) {
  5750. $price = $receivablesPrice - $detail ['invoicePrice'];
  5751. echo json_encode ( array (
  5752. 'status' => 1,
  5753. 'price' => $price
  5754. ) );
  5755. } else
  5756. echo json_encode ( array (
  5757. 'status' => 2
  5758. ) );
  5759. }
  5760. /**
  5761. * 获得打印发票
  5762. */
  5763. function ajaxGetInvoiceInfoByPrint() {
  5764. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5765. if (empty ( $serial )) {
  5766. echo json_encode ( array (
  5767. 'status' => 2,
  5768. 'msg' => 'illegal request'
  5769. ) );
  5770. die ();
  5771. }
  5772. Doo::loadModel ( 'invoice' );
  5773. $invoice = new invoice ();
  5774. Doo::loadModel ( 'invoiceOperationLog' );
  5775. $invoiceOperationLog = new invoiceOperationLog ();
  5776. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5777. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5778. Doo::loadModel ( 'invoicePaper' );
  5779. $invoicePaper = new invoicePaper ();
  5780. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $detail ['invoiceType'] );
  5781. if (empty ( $detail ))
  5782. $html = '';
  5783. else {
  5784. $html = '
  5785. <form action="/invoicePrintDo" method="post" name="invoicePrint" class="nice-validator n-yellow" onSubmit="return checkPrintForm()" novalidate="novalidate">
  5786. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  5787. <input type="hidden" name="invoicePrintType" value="invoicePrintType">
  5788. <div class="modal-dialog modal-lg">
  5789. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  5790. <div class="modal-body saeaList">
  5791. <table class="table table-bordered table-condensed"><tbody>
  5792. <tr>
  5793. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5794. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5795. </tr>
  5796. <tr>
  5797. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5798. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5799. </tr>
  5800. <tr>
  5801. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5802. </td>
  5803. </tr>
  5804. <tr>
  5805. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5806. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5807. </tr>
  5808. <tr>
  5809. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5810. </tr></tbody></table>';
  5811. if ($detail ['invoiceType'] == 0)
  5812. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5813. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5814. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5815. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5816. </tr>';
  5817. else
  5818. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5819. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5820. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5821. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5822. ';
  5823. $html .= '<tr>
  5824. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5825. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5826. </tr>
  5827. <tr>
  5828. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5829. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5830. </tr></tbody></table>';
  5831. if ($detail ['doPost'] == 1)
  5832. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5833. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5834. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5835. </tr><tr>
  5836. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5837. </tr><tr>
  5838. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5839. </tr></tbody></table>';
  5840. if (! empty ( $invoiceOperationLogList )) {
  5841. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th><th class="taC">发票打印</th></tr><tr><td>';
  5842. foreach ( $invoiceOperationLogList as $key => $value ) {
  5843. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5844. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5845. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5846. if ($value ['status'] == 2) {
  5847. $html .= '<span class="colGreen">同意</span>';
  5848. } elseif ($value ['status'] == 3) {
  5849. $html .= '<span class="colOrange">退回</span>';
  5850. } elseif ($value ['status'] == 5) {
  5851. $html .= '<span class="colGreen">打印</span>';
  5852. } elseif ($value ['status'] == 4) {
  5853. $html .= '<span class="colRed">终止</span>';
  5854. }
  5855. $html .= $value ['operation'] . '</p></blockquote>';
  5856. }
  5857. }
  5858. $html .= '</td>
  5859. <td><span class="colRed">*</span>
  5860. <select name="invoiceNo" id="invoiceNo" style="width:97%">';
  5861. foreach ( $invoicePaperList as $key => $value ) {
  5862. $html .= '<option value="' . $value ['ipidKey'] . '">No.' . $value ['invoiceNo'] . '</option>';
  5863. }
  5864. $html .= '</select>
  5865. <span class="red" id="p-msg"></span>
  5866. </td>
  5867. </tr></tbody></table>';
  5868. }
  5869. $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>
  5870. </div></div></form>
  5871. <link rel=stylesheet href="' . WEB_SITE_GLOBAL . 'css/jquery.validator.css">
  5872. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/jquery.validator.min.js"></script>
  5873. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/zh-CN.js"></script>
  5874. <script src="' . WEB_SITE_GLOBAL . 'js/invoice.validator.js"></script>
  5875. ';
  5876. }
  5877. echo json_encode ( array (
  5878. 'status' => 1,
  5879. 'html' => $html
  5880. ) );
  5881. die ();
  5882. }
  5883. /**
  5884. * @ 获得与我有关收款数据 --需求变更 废弃 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 ) ); }
  5885. */
  5886. function ajaxGetInvoiceInfoByType() {
  5887. $type = $this->get_args ( 'type' ) ? $this->get_args ( 'type' ) : "";
  5888. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5889. $loss = $this->get_args ( 'loss' ) ? $this->get_args ( 'loss' ) : false;
  5890. if (empty ( $serial )) {
  5891. echo json_encode ( array (
  5892. 'status' => 2,
  5893. 'msg' => 'illegal request'
  5894. ) );
  5895. die ();
  5896. }
  5897. if ($type == 'INVOICE') {
  5898. Doo::loadModel ( 'invoice' );
  5899. $invoice = new invoice ();
  5900. Doo::loadModel ( 'invoiceOperationLog' );
  5901. $invoiceOperationLog = new invoiceOperationLog ();
  5902. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5903. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5904. if (empty ( $detail ))
  5905. $html = '';
  5906. else {
  5907. $html = '
  5908. <div class="modal-dialog modal-lg">
  5909. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  5910. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  5911. <tr>
  5912. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5913. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5914. </tr>
  5915. <tr>
  5916. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5917. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5918. </tr>
  5919. <tr>
  5920. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5921. </td>
  5922. </tr>
  5923. <tr>
  5924. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5925. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5926. </tr>
  5927. <tr>
  5928. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5929. </tr>';
  5930. if ($detail ['settlementType'] == 1)
  5931. $html .= '<tr>
  5932. <th class="taC" width="150">结算方式</th><td colspan="3">培训班(<a href="/invoiceTrainingDetail/' . $detail ['invoiceTraining'] ['trainingKey'] . '.html" target="_blank">' . $detail ['invoiceTraining'] ['trainName'] . '</a>)</td>
  5933. </tr>';
  5934. else
  5935. $html .= '<tr>
  5936. <th class="taC" width="150">结算方式</th><td colspan="3">软件销售</td>
  5937. </tr>';
  5938. $html .= ' </tbody></table>';
  5939. if ($detail ['invoiceType'] == 0)
  5940. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5941. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5942. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5943. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5944. </tr>';
  5945. else
  5946. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5947. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5948. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5949. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5950. ';
  5951. $html .= '<tr>
  5952. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5953. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5954. </tr>
  5955. <tr>
  5956. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5957. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5958. </tr></tbody></table>';
  5959. if ($detail ['doPost'] == 1) {
  5960. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5961. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5962. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5963. </tr><tr>
  5964. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5965. </tr><tr>
  5966. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5967. </tr>
  5968. ';
  5969. if ($detail ['expressCom'] == 'SF')
  5970. $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>';
  5971. else
  5972. $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>';
  5973. $html .= '</tbody></table>';
  5974. }
  5975. if (! empty ( $invoiceOperationLogList )) {
  5976. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  5977. foreach ( $invoiceOperationLogList as $key => $value ) {
  5978. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5979. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5980. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5981. if ($value ['status'] == 2) {
  5982. $html .= '<span class="colGreen">同意</span>';
  5983. } elseif ($value ['status'] == 3) {
  5984. $html .= '<span class="colOrange">退回</span>';
  5985. } elseif ($value ['status'] == 5) {
  5986. $html .= '<span class="colGreen">打印</span>';
  5987. } elseif ($value ['status'] == 4) {
  5988. $html .= '<span class="colRed">终止</span>';
  5989. }
  5990. $html .= $value ['operation'] . '</p></blockquote>';
  5991. }
  5992. }
  5993. $html .= '</td></tr></tbody></table>';
  5994. }
  5995. $html .= '</div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  5996. }
  5997. echo json_encode ( array (
  5998. 'status' => 1,
  5999. 'html' => $html
  6000. ) );
  6001. die ();
  6002. } elseif ($type == 'RECEIVABLES') {
  6003. Doo::loadModel ( 'invoiceReceivables' );
  6004. $invoiceReceivables = new invoiceReceivables ();
  6005. Doo::loadModel ( 'invoiceRefund' );
  6006. $invoiceRefund = new invoiceRefund ();
  6007. $detail = $invoiceReceivables->getInvoiceReceivablesByIrsid ( $serial );
  6008. $ireList = $invoiceRefund->getInvoiceRefundIrid ( $detail ['irid'] );
  6009. if (empty ( $detail ))
  6010. $html = '';
  6011. else {
  6012. $html = '<div class="modal-dialog modal-lg"><div class="modal-content"><div class="modal-header"><h3>收款单详情</h3></div><div class="modal-body saeaList">
  6013. <table class="table table-bordered table-condensed">
  6014. <tbody><tr>
  6015. <th class="taC">收款流水号</th><td>' . $detail ['receivablesSerial'] . '</td>
  6016. <th class="taC">录入收款</th><td>' . $detail ['inputStaff'] . ' ' . $detail ['date'] . '</td>
  6017. </tr><tr>
  6018. <th class="taC">收款金额</th><td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  6019. <th class="taC">收款信息</th><td>' . $detail ['receivablesMessage'] . '</td>
  6020. </tr>
  6021. <tr>
  6022. <th class="taC">收款银行</th><td>' . $detail ['receivablesBank'] . '</td>
  6023. <th class="taC">银行到账</th><td>' . $detail ['receivablesDate'] . '</td>
  6024. </tr>
  6025. <tr>
  6026. <th class="taC">认领收款</th><td colspan="3">' . $detail ['inputStaff'] . ' 转入 ' . $detail ['username'] . ' ' . $detail ['confirmTime'] . '</td>
  6027. </tr>
  6028. </tbody></table>';
  6029. if (! empty ( $ireList )) {
  6030. $html .= '
  6031. <table class="table table-bordered table-condensed"><tbody><tr><th class="taC" colspan="5">退款记录</th></tr>
  6032. <tr>
  6033. <th class="taC">退款单位名称</th>
  6034. <th class="taC">退款的账号</th>
  6035. <th class="taC">退款金额</th>
  6036. <th class="taC">退款</th>
  6037. <th class="taC">备注</th>
  6038. </tr>
  6039. ';
  6040. foreach ( $ireList as $key => $value ) {
  6041. $refundLogList = explode ( "<br/>", $value ['refundLog'] );
  6042. $html .= '<tr>
  6043. <td>' . $value ['refundCompany'] . '</td>
  6044. <td>' . $value ['refundNumber'] . '</td>
  6045. <td><b class="colRed">¥' . $value ['refundPrice'] . '</b></td>
  6046. <td>' . $refundLogList [0] . $refundLogList [2] . '</td>
  6047. <td>' . $value ['refundRemarks'] . '</td>
  6048. </tr>
  6049. ';
  6050. }
  6051. }
  6052. $html .= '</tbody></table></div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  6053. }
  6054. echo json_encode ( array (
  6055. 'status' => 1,
  6056. 'html' => $html
  6057. ) );
  6058. die ();
  6059. } elseif ($type == 'IRTC') {
  6060. Doo::loadModel ( 'invoice' );
  6061. $invoice = new invoice ();
  6062. Doo::loadModel ( 'invoiceOperationLog' );
  6063. $invoiceOperationLog = new invoiceOperationLog ();
  6064. Doo::loadModel ( 'invoiceReceivables' );
  6065. $invoiceReceivables = new invoiceReceivables ();
  6066. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  6067. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  6068. if (empty ( $detail ))
  6069. $html = '';
  6070. else {
  6071. $receivablesPriceedHtml = '';
  6072. $receivablesPrice = $detail ['invoicePrice'];
  6073. if (! empty ( $detail ['irid'] )) {
  6074. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $detail ['irid'] );
  6075. if (empty ( $irList ))
  6076. $irList [0] ['sumPrice'] = 0;
  6077. $balance = $detail ['invoicePrice'] - $irList [0] ['sumPrice'];
  6078. $receivablesPriceedHtml = '<table class="table table-bordered table-condensed"><tbody><tr>
  6079. <th class="taC">已入账金额</th><td><b class="colGreen" style="font-size:18px">¥' . $irList [0] ['sumPrice'] . '</b></td>
  6080. <th class="taC">剩余入账金额</th><td><b class="colRed" style="font-size:18px">¥' . $balance . '</b></td>
  6081. </tr></tbody></table>';
  6082. $receivablesPrice = $balance;
  6083. }
  6084. if ($loss)
  6085. $detail ['invoicePrice'] = - $detail ['invoicePrice'];
  6086. $html = $receivablesPriceedHtml . '
  6087. <table class="table table-bordered table-condensed"><tbody>
  6088. <tr>
  6089. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  6090. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  6091. </tr>
  6092. <tr>
  6093. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  6094. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  6095. </tr>
  6096. <tr>
  6097. <th class="taC" width="150">发票备注</th><td colspan="3">' . $detail ['remark'] . '</td>
  6098. </tr>
  6099. <tr>
  6100. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  6101. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  6102. </tr>
  6103. <tr>
  6104. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  6105. </tr></tbody></table>';
  6106. if ($detail ['invoiceType'] == 0) {
  6107. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6108. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  6109. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  6110. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  6111. </tr>';
  6112. $receivablesMessage = $detail ['invoiceTitle'];
  6113. } else {
  6114. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6115. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  6116. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  6117. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  6118. ';
  6119. $receivablesMessage = $detail ['invoiceCompany'];
  6120. }
  6121. $html .= '<tr>
  6122. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  6123. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  6124. </tr>
  6125. <tr>
  6126. <th class="taC">开户银行</th><td>' . $detail ['bankAccount'] . '</td>
  6127. <th class="taC">银行账号</th><td>' . $detail ['bank'] . '</td>
  6128. </tr></tbody></table>';
  6129. if ($detail ['doPost'] == 1)
  6130. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  6131. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  6132. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  6133. </tr><tr>
  6134. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  6135. </tr><tr>
  6136. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  6137. </tr></tbody></table>';
  6138. if (! empty ( $invoiceOperationLogList )) {
  6139. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  6140. foreach ( $invoiceOperationLogList as $key => $value ) {
  6141. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  6142. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  6143. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  6144. if ($value ['status'] == 2) {
  6145. $html .= '<span class="colGreen">同意</span>';
  6146. } elseif ($value ['status'] == 3) {
  6147. $html .= '<span class="colOrange">退回</span>';
  6148. } elseif ($value ['status'] == 5) {
  6149. $html .= '<span class="colGreen">打印</span>';
  6150. }
  6151. $html .= $value ['operation'] . '</p></blockquote>';
  6152. }
  6153. }
  6154. $html .= '</td></tr></tbody></table>';
  6155. }
  6156. }
  6157. echo json_encode ( array (
  6158. 'status' => 1,
  6159. 'html' => $html,
  6160. 'receivablesPrice' => $receivablesPrice,
  6161. 'receivablesMessage' => $receivablesMessage,
  6162. 'receivablesDate' => date ( "Y-m-d" ),
  6163. 'iidKey' => $serial
  6164. ) );
  6165. die ();
  6166. }
  6167. }
  6168. function ajaxGetInvoiceReceivablesByStaff() {
  6169. $postData = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : "";
  6170. if (empty ( $postData )) {
  6171. echo json_encode ( array (
  6172. 'status' => 2,
  6173. 'msg' => 'illegal request'
  6174. ) );
  6175. die ();
  6176. }
  6177. Doo::loadModel ( 'invoiceReceivables' );
  6178. $invoiceReceivables = new invoiceReceivables ();
  6179. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $postData );
  6180. if (empty ( $detail )) {
  6181. echo json_encode ( array (
  6182. 'status' => 2,
  6183. 'msg' => 'illegal request'
  6184. ) );
  6185. die ();
  6186. }
  6187. Doo::loadModel ( 'L_category' );
  6188. $lCategory = new L_category ();
  6189. Doo::loadModel ( 'staff' );
  6190. $staff = new staff ();
  6191. $staffList = $staff->getStaffByCid ( $detail ['cid'] );
  6192. $category = $lCategory->getCategory ();
  6193. $categoryHtml = '<option post-data="PUBLIC" value="PUBLIC" >公共待认领款项</option>';
  6194. $staffHtml = '<option value="PUBLIC">办事处待认领款项</option>';
  6195. foreach ( $category as $key => $value ) {
  6196. $categoryHtml .= '<option post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  6197. if ($value ['cid'] == $detail ['cid'])
  6198. $categoryHtml .= '<option selected post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  6199. }
  6200. foreach ( $staffList as $key => $value ) {
  6201. $staffHtml .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  6202. if ($value ['sid'] == $detail ['sid'])
  6203. $staffHtml .= '<option selected value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  6204. }
  6205. $rbankHtml = '<option value="广发银行珠海分行柠溪支行">广发银行珠海分行柠溪支行</option>';
  6206. echo json_encode ( array (
  6207. 'status' => 1,
  6208. 'categoryHtml' => $categoryHtml,
  6209. 'staffHtml' => $staffHtml,
  6210. 'rbankHtml' => $rbankHtml,
  6211. 'detail' => $detail
  6212. ) );
  6213. }
  6214. function ajaxGetInvoiceReceivablesByIrid() {
  6215. $irid = $this->get_args ( 'irid' ) ? $this->get_args ( 'irid' ) : "";
  6216. if (empty ( $irid )) {
  6217. echo json_encode ( array (
  6218. 'status' => 2,
  6219. 'msg' => 'illegal request'
  6220. ) );
  6221. die ();
  6222. }
  6223. Doo::loadModel ( 'invoiceReceivables' );
  6224. $invoiceReceivables = new invoiceReceivables ();
  6225. Doo::loadModel ( 'invoice' );
  6226. $invoice = new invoice ();
  6227. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid ); // 入账完成 待定 and postStatus=1
  6228. $flag = true;
  6229. $invoiceDetail = $invoice->getInvoiceByTitle ( $detail ['recepitTitleMark'], 'EXACTLY', " and status=2 and printStatus=1 and untreadStatus=0 ", $flag ); //
  6230. $bakDetail = array ();
  6231. if ($flag === false) {
  6232. array_push ( $bakDetail, $invoiceDetail );
  6233. $invoiceDetail = $bakDetail;
  6234. }
  6235. $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>
  6236. <tr>
  6237. <td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  6238. <td>' . $detail ['receivablesMessage'] . '</td>
  6239. <td>' . $detail ['receivablesBank'] . '<br>' . $detail ['receivablesDate'] . '</td>
  6240. <td>' . $detail ['title'] . '-' . $detail ['username'] . '<br>' . $detail ['confirmTime'] . '</td>
  6241. <td>' . $detail ['recepitTitleMark'] . '</td>
  6242. </tr></tbody></table>';
  6243. $isInvoice = false;
  6244. $invoiceHtml = '';
  6245. if (empty ( $invoiceDetail )) {
  6246. $isInvoice = true;
  6247. } else {
  6248. $invoiceHtml = '<table class="table table-bordered table-condensed">
  6249. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody>';
  6250. foreach ( $invoiceDetail as $key => $value ) {
  6251. $invoiceHtml .= '<tr>';
  6252. if (! empty ( $value ['invoiceType'] )) {
  6253. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  6254. } else {
  6255. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  6256. }
  6257. if (! empty ( $value ['invoiceType'] )) {
  6258. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  6259. } else {
  6260. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  6261. }
  6262. $invoiceHtml .= '
  6263. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  6264. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  6265. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir" data-ikey="' . $value ['iidKey'] . '" href="javascript:void(0)">入账</a></td>
  6266. </tr>
  6267. ';
  6268. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  6269. if (empty ( $irList ))
  6270. $irList [0] ['sumPrice'] = 0;
  6271. $balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  6272. $priceString = '';
  6273. if ($balance < $detail ['receivablesPrice']) {
  6274. $priceString = '收款金额超过开票金额,';
  6275. }
  6276. if ($balance > $detail ['receivablesPrice']) {
  6277. $priceString = '收款金额低于开票金额,';
  6278. }
  6279. }
  6280. $invoiceHtml .= '
  6281. <script>
  6282. $(\'a[bind-receivables^="ir"]\').click(function() {
  6283. var data = $(this).attr("data-ikey");
  6284. $("input[name=\'invoiceKey\']").val(data);
  6285. var invoiceKey=data;
  6286. if(invoiceKey==""){
  6287. alert("入账错误,请重新刷新页面");
  6288. return false;
  6289. }
  6290. if(window.confirm("' . $priceString . '确定入账吗?")){
  6291. $("#IBR").submit();
  6292. }else{
  6293. return false;
  6294. }
  6295. });
  6296. </script>
  6297. ';
  6298. $invoiceHtml .= '</tbody></table>';
  6299. }
  6300. echo json_encode ( array (
  6301. 'status' => 1,
  6302. 'irkey' => $detail ['iridEn'],
  6303. 'receivablesHtml' => $receivablesHtml,
  6304. 'isInvoice' => $isInvoice,
  6305. 'invoiceHtml' => $invoiceHtml
  6306. ) );
  6307. }
  6308. function ajaxGetInvoiceReceivablesByTitle() {
  6309. $title = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  6310. if (empty ( $title )) {
  6311. echo json_encode ( array (
  6312. 'status' => 2,
  6313. 'msg' => 'illegal request'
  6314. ) );
  6315. die ();
  6316. }
  6317. Doo::loadModel ( 'invoice' );
  6318. $invoice = new invoice ();
  6319. $invoiceDetail = $invoice->getInvoiceByTitle ( $title, 'FUZZY', " and status=2 and printStatus=1 and untreadStatus=0 and irid='' ", true );
  6320. $invoiceHtml = '';
  6321. if (! empty ( $invoiceDetail )) {
  6322. $invoiceHtml = '<table class="table table-bordered table-condensed">
  6323. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody><tr>';
  6324. foreach ( $invoiceDetail as $key => $value ) {
  6325. if (! empty ( $value ['invoiceType'] )) {
  6326. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  6327. } else {
  6328. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  6329. }
  6330. if (! empty ( $value ['invoiceType'] )) {
  6331. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  6332. } else {
  6333. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  6334. }
  6335. $invoiceHtml .= '
  6336. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  6337. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  6338. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir' . $value ['iidKeyXD'] . '" data-ikey="' . $value ['iidKey'] . '" href="#">入账</a></td>
  6339. </tr>
  6340. ';
  6341. }
  6342. $invoiceHtml .= '</tbody></table>
  6343. <script>
  6344. $(\'a[bind-receivables^="ir"]\').click(function() {
  6345. var data = $(this).attr("data-ikey");
  6346. $("input[name=\'invoiceKey\']").val(data);
  6347. var invoiceKey=$("input[name=\'invoiceKey\']").val();
  6348. if(invoiceKey==""){
  6349. alert("入账错误,请重新刷新页面");
  6350. return false;
  6351. }
  6352. if(window.confirm("确定入账吗?")){
  6353. $("#IBR").submit();
  6354. }else{
  6355. return false;
  6356. }
  6357. });
  6358. </script>
  6359. ';
  6360. }
  6361. echo json_encode ( array (
  6362. 'status' => 1,
  6363. 'invoiceHtml' => $invoiceHtml
  6364. ) );
  6365. }
  6366. function ajaxInvoicePushNotice() {
  6367. Doo::loadModel ( 'invoice' );
  6368. $invoice = new invoice ();
  6369. $approval = $invoice->getOne ( array (
  6370. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  6371. 'desc' => 'iid',
  6372. 'asArray' => true
  6373. ) );
  6374. $isNotice = false;
  6375. if (! empty ( $approval ))
  6376. $isNotice = true;
  6377. $response = array (
  6378. 'error' => 0,
  6379. 'isNotice' => $isNotice
  6380. );
  6381. echo json_encode ( $response );
  6382. exit ();
  6383. }
  6384. public function ajaxCheckInvoiceNoUniqueness() {
  6385. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  6386. Doo::loadModel ( 'invoice' );
  6387. $invoice = new invoice ();
  6388. if (! empty ( $invoiceNo )) {
  6389. Doo::loadModel ( 'invoicePaper' );
  6390. $invoicePaper = new invoicePaper ();
  6391. Doo::loadClass ( 'XDeode' );
  6392. $XDeode = new XDeode ( 5 );
  6393. $ipid = $XDeode->decode ( $invoiceNo );
  6394. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  6395. $info = $invoice->getOne ( array (
  6396. 'where' => "invoiceNo = '" . $paperDetail ['invoiceNo'] . "'",
  6397. 'asArray' => TRUE
  6398. ) );
  6399. if (! empty ( $info )) {
  6400. echo json_encode ( array (
  6401. 'error' => '发票号已存在'
  6402. ) );
  6403. die ();
  6404. } else
  6405. echo json_encode ( array (
  6406. 'ok' => '可以使用!'
  6407. ) );
  6408. die ();
  6409. }
  6410. }
  6411. function ajaxCheckInvoicePrice() {
  6412. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) && is_numeric ( $this->get_args ( 'receivablesPrice' ) ) ? $this->get_args ( 'receivablesPrice' ) : "";
  6413. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  6414. Doo::loadModel ( 'invoice' );
  6415. $invoice = new invoice ();
  6416. Doo::loadModel ( 'invoiceReceivables' );
  6417. $invoiceReceivables = new invoiceReceivables ();
  6418. Doo::loadClass ( 'XDeode' );
  6419. $XDeode = new XDeode ( 5 );
  6420. if (! empty ( $receivablesPrice ) && ! empty ( $iidKey )) {
  6421. $iidKey = $XDeode->decode ( $iidKey );
  6422. $info = $invoice->getInvoiceByIid ( $iidKey );
  6423. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $info ['irid'] );
  6424. if (empty ( $irList ))
  6425. $irList [0] ['sumPrice'] = 0;
  6426. $balance = $info ['invoicePrice'] - $irList [0] ['sumPrice'];
  6427. if ($balance < $receivablesPrice) {
  6428. echo json_encode ( array (
  6429. 'error' => '收款金额超过开票金额。'
  6430. ) );
  6431. die ();
  6432. }
  6433. if ($balance > $receivablesPrice) {
  6434. echo json_encode ( array (
  6435. 'error' => '收款金额低于开票金额。'
  6436. ) );
  6437. die ();
  6438. }
  6439. }
  6440. }
  6441. function ajaxGetInvoiceByNew() {
  6442. Doo::loadModel ( 'invoice' );
  6443. $invoice = new invoice ();
  6444. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );
  6445. echo json_encode ( array (
  6446. 'status' => 1,
  6447. 'detail' => $detail
  6448. ) );
  6449. }
  6450. /**
  6451. * 旧输入导入
  6452. */
  6453. function importInvoice() {
  6454. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  6455. $data ['emsg'] = "";
  6456. if ($emsg != "")
  6457. $data ['emsg'] = "请填写完整的数据";
  6458. $data ['time'] = time ();
  6459. $this->render ( "/admin/invoiceImport", $data );
  6460. }
  6461. function uploadInvoice() {
  6462. // move_uploaded_file($_FILES['Filedata']['tmp_name'], "/upload/".$_FILES['Filedata']['name']);
  6463. if (isset ( $_FILES ['Filedata'] ['name'] )) {
  6464. $file = $_FILES ['Filedata'] ['tmp_name'];
  6465. $error = false;
  6466. if (! is_uploaded_file ( $file )) {
  6467. $error = '400 Bad Request';
  6468. }
  6469. if ($error) {
  6470. header ( 'HTTP/1.0 ' . $error );
  6471. die ( 'Error ' . $error );
  6472. } else {
  6473. include (DOO::conf ()->SITE_PATH . 'protected/plugin/io.han.php');
  6474. $this->IoHandler = new IoHandler ();
  6475. $pics = explode ( '.', $_FILES ['Filedata'] ['name'] );
  6476. // $filedir=$_POST['time'];
  6477. // 调用定义物理路径
  6478. $t = DOO::conf ()->SITE_PATH . "upload/invoice/";
  6479. $this->IoHandler->MakeDir ( $t );
  6480. $filename = $this->_GetFileEXT ( $_FILES ['Filedata'] ['name'] );
  6481. if ($filename != 'xlsx')
  6482. return "";
  6483. // $upload_dir = $t."/".time().rand(10,100).".".$filename;
  6484. $upload_file = iconv ( "UTF-8", "GB2312", $_FILES ["Filedata"] ["name"] );
  6485. $upload_dir = $t . "/" . $upload_file;
  6486. $k = move_uploaded_file ( $file, $upload_dir );
  6487. if ($k) {
  6488. $m = round ( $_FILES ['Filedata'] ['size'] / 1024 / 1024, 2 );
  6489. echo $pics [0] . "." . $filename . "#" . $m . "#" . $_FILES ['Filedata'] ['size'];
  6490. }
  6491. }
  6492. }
  6493. }
  6494. function importInvoiceDo() {
  6495. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  6496. if ($path != "") {
  6497. Doo::loadModel ( 'invoice' );
  6498. Doo::loadModel ( 'staff' );
  6499. $staff = new staff ();
  6500. Doo::loadModel ( 'invoiceStatistics' );
  6501. Doo::loadModel ( 'invoiceOperationLog' );
  6502. echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  6503. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . $path );
  6504. // print_r ( $exlArray );
  6505. // die ();
  6506. // echo json_encode($exlArray);die;
  6507. foreach ( $exlArray as $key => $value ) {
  6508. // 开票
  6509. $invoice = new invoice ();
  6510. $invoice->invoiceNo = $value ['invoiceNo'];
  6511. $invoice->invoiceType = 0;
  6512. if ($value ['invoiceType'] == '专')
  6513. $invoice->invoiceType = 1;
  6514. $invoice->invoicePrice = $value ['invoicePrice'];
  6515. $invoice->invoiceQuantity = 1;
  6516. $invoice->invoiceUnitPrice = $value ['invoicePrice'];
  6517. $invoice->invoiceTitle = $value ['invoiceTitle'];
  6518. if ($value ['invoiceType'] == '专')
  6519. $invoice->invoiceCompany = $value ['invoiceTitle'];
  6520. $invoice->userName = $value ['userName'];
  6521. $sDetail = $staff->getStaffByName ( $value ['userName'] );
  6522. $invoice->sid = $sDetail ['sid'];
  6523. $invoice->cid = $sDetail ['cid'];
  6524. $invoice->categoryName = $sDetail ['category'];
  6525. $invoice->invoiceElement = $value ['invoiceElement'];
  6526. $invoice->remark = $value ['remark'];
  6527. $invoice->date = $value ['date'];
  6528. $invoice->printTime = $value ['date'];
  6529. $invoice->ipSource = 1;
  6530. $invoice->printStatus = 1;
  6531. $invoice->status = 2;
  6532. $invoice->postStatus = 1;
  6533. $invoice->untreadStatus = 0;
  6534. $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  6535. $iid = $invoice->insert ();
  6536. // 汇总
  6537. $invoiceStatistics = new invoiceStatistics ();
  6538. //
  6539. $item = array (
  6540. 'date' => $value ['date'],
  6541. 'priceClass' => 1,
  6542. 'cid' => $sDetail ['cid'],
  6543. 'staff' => $sDetail ['sid'],
  6544. 'invoicePrice' => $value ['invoicePrice']
  6545. );
  6546. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  6547. $invoiceOperationLog = new invoiceOperationLog ();
  6548. $item = array (
  6549. 'date' => date ( "Y-m-d H:i:s" ),
  6550. 'operation' => date ( "Y-m-d" ) . " 导入",
  6551. 'status' => 1,
  6552. 'img' => $sDetail ['avatar'],
  6553. 'username' => $sDetail ['username'],
  6554. 'uid' => $sDetail ['sid'],
  6555. 'category' => $sDetail ['category'],
  6556. 'iid' => $iid
  6557. );
  6558. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  6559. }
  6560. return '/importInvoice?count=' . count ( $exlArray );
  6561. // return "/keyonline";
  6562. }
  6563. echo 'no file';
  6564. }
  6565. function importInvoiceReceivables() {
  6566. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  6567. $data ['emsg'] = "";
  6568. if ($emsg != "")
  6569. $data ['emsg'] = "请填写完整的数据";
  6570. $data ['time'] = time ();
  6571. $this->render ( "/admin/invoiceReceivablesImport", $data );
  6572. }
  6573. // 导入入账数据
  6574. function importInvoiceReceivablesDo() {
  6575. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  6576. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  6577. if ($path != "") {
  6578. Doo::loadModel ( 'invoiceReceivables' );
  6579. Doo::loadModel ( 'invoice' );
  6580. Doo::loadModel ( 'staff' );
  6581. $staff = new staff ();
  6582. Doo::loadModel ( 'invoiceStatistics' );
  6583. // echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  6584. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path ), 'invoiceReceivables' );
  6585. // print_r ( $exlArray );
  6586. // die ();
  6587. // echo json_encode($exlArray);die;
  6588. foreach ( $exlArray as $key => $value ) {
  6589. // 收款
  6590. $invoiceReceivables = new invoiceReceivables ();
  6591. $invoice = new invoice ();
  6592. $invoiceReceivables->bindStatus = 1;
  6593. $invoiceReceivables->receivablesPrice = $value ['receivablesPrice'];
  6594. $invoiceReceivables->receivablesMessage = $value ['receivablesMessage'];
  6595. $invoiceReceivables->receivablesBank = $value ['receivablesBank'];
  6596. $invoiceReceivables->receivablesDate = $value ['receivablesDate'];
  6597. $sDetail = $staff->getStaffByName ( $value ['receivablesStaff'] );
  6598. $invoiceReceivables->receivablesCategory = $sDetail ['cid'] . ':' . $sDetail ['category'];
  6599. $invoiceReceivables->receivablesStaff = $sDetail ['sid'] . '-' . $sDetail ['username'];
  6600. $invoiceReceivables->receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  6601. $invoiceReceivables->sourcePrice = $value ['sourcePrice'];
  6602. $iDetail = $invoice->getInvoiceByInvoiceNo ( $value ['invoiceNo'] );
  6603. $invoiceReceivables->iid = $iDetail ['iid'];
  6604. $irid = $invoiceReceivables->insert ();
  6605. // 发票绑定收款
  6606. $detail = $iDetail;
  6607. $iridString = "";
  6608. if (empty ( $detail ['irid'] ))
  6609. $iridString = $irid;
  6610. else
  6611. $iridString = $detail ['irid'] . ',' . $irid;
  6612. $item = array (
  6613. 'irid' => $iridString,
  6614. 'iid' => $detail ['iid']
  6615. );
  6616. $invoice->setInvoiceByCondition ( $item );
  6617. // 汇总
  6618. $invoiceStatistics = new invoiceStatistics ();
  6619. // 扣除入账统计金额
  6620. $item = array (
  6621. 'date' => $value ['receivablesDate'],
  6622. 'priceClass' => 3,
  6623. 'cid' => $sDetail ['cid'],
  6624. 'staff' => $sDetail ['sid'],
  6625. // 'irid' => $irid,
  6626. 'accountPrice' => $value ['receivablesPrice']
  6627. );
  6628. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  6629. }
  6630. return '/importInvoiceReceivables?count=' . count ( $exlArray );
  6631. echo 'data count ' . count ( $exlArray );
  6632. die ();
  6633. // return "/keyonline";
  6634. }
  6635. echo 'no file';
  6636. }
  6637. function formatExcelToArrayTrain($file_url = "") {
  6638. if (! file_exists ( $file_url )) {
  6639. return array ();
  6640. }
  6641. // Doo::loadClass ( 'PHPExcel' );
  6642. Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  6643. $PHPExcel = new PHPExcel ();
  6644. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  6645. if (! $PHPReader->canRead ( $file_url )) {
  6646. $PHPReader = new PHPExcel_Reader_Excel5 ();
  6647. if (! $PHPReader->canRead ( $file_url )) {
  6648. echo 'no Excel';
  6649. return;
  6650. }
  6651. }
  6652. $PHPExcel = $PHPReader->load ( $file_url );
  6653. /* * 读取excel文件中的第一个工作表 */
  6654. $currentSheet = $PHPExcel->getSheet ( 0 );
  6655. /* * 取得最大的列号 */
  6656. $allColumn = $currentSheet->getHighestColumn ();
  6657. /* * 取得一共有多少行 */
  6658. $allRow = $currentSheet->getHighestRow ();
  6659. $excel_array = array ();
  6660. // die($file_url);
  6661. $conk = 2;
  6662. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  6663. $excel_column = array ();
  6664. // 后期改进
  6665. if ($allColumn == 'AM')
  6666. $allColumn = 'Z';
  6667. /* * 从第A列开始输出 */
  6668. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  6669. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  6670. if ($val instanceof PHPExcel_RichText)
  6671. $val = $val->__toString ();
  6672. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  6673. // $val = "'" . addslashes ( $val ) . "'";
  6674. if ($currentColumn == 'A') {
  6675. $excel_column ['invoiceTitle'] = $val;
  6676. } elseif ($currentColumn == 'B')
  6677. $excel_column ['invoiceType'] = $val;
  6678. elseif ($currentColumn == 'C') {
  6679. $excel_column ['TIN'] = $val;
  6680. } elseif ($currentColumn == 'D') {
  6681. $excel_column ['address'] = $val;
  6682. } elseif ($currentColumn == 'E') {
  6683. $excel_column ['phone'] = $val;
  6684. } elseif ($currentColumn == 'F') {
  6685. $excel_column ['bank'] = $val;
  6686. } elseif ($currentColumn == 'G') {
  6687. $excel_column ['bankAccount'] = $val;
  6688. } elseif ($currentColumn == 'H') {
  6689. $excel_column ['invoiceElement'] = $val;
  6690. } elseif ($currentColumn == 'I') {
  6691. $excel_column ['invoiceQuantity'] = $val;
  6692. } elseif ($currentColumn == 'J') {
  6693. $excel_column ['invoiceUnitPrice'] = $val;
  6694. } elseif ($currentColumn == 'K') {
  6695. $excel_column ['remark'] = $val;
  6696. } elseif ($currentColumn == 'L') {
  6697. $excel_column ['recipientsAddress'] = $val;
  6698. } elseif ($currentColumn == 'M') {
  6699. $excel_column ['recipients'] = $val;
  6700. } elseif ($currentColumn == 'N') {
  6701. $excel_column ['recipientsPhone'] = $val;
  6702. }
  6703. }
  6704. if (! empty ( $excel_column ['invoiceTitle'] ) && ! empty ( $excel_column ['invoiceQuantity'] ) && ! empty ( $excel_column ['invoiceUnitPrice'] ))
  6705. array_push ( $excel_array, $excel_column );
  6706. }
  6707. return $excel_array;
  6708. }
  6709. /**
  6710. * 格式化excel文件为数组
  6711. * @param unknown_type $file_url
  6712. * @param unknown_type $mcid
  6713. */
  6714. function _format_excel_to_array($file_url = "", $sType = "") {
  6715. if (! file_exists ( $file_url )) {
  6716. return array ();
  6717. }
  6718. Doo::loadClass ( 'PHPExcel' );
  6719. // Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  6720. $PHPExcel = new PHPExcel ();
  6721. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  6722. if (! $PHPReader->canRead ( $file_url )) {
  6723. $PHPReader = new PHPExcel_Reader_Excel5 ();
  6724. if (! $PHPReader->canRead ( $file_url )) {
  6725. echo 'no Excel';
  6726. return;
  6727. }
  6728. }
  6729. $PHPExcel = $PHPReader->load ( $file_url );
  6730. /* * 读取excel文件中的第一个工作表 */
  6731. $currentSheet = $PHPExcel->getSheet ( 0 );
  6732. /* * 取得最大的列号 */
  6733. $allColumn = $currentSheet->getHighestColumn ();
  6734. /* * 取得一共有多少行 */
  6735. $allRow = $currentSheet->getHighestRow ();
  6736. $excel_array = array ();
  6737. // die($file_url);
  6738. $conk = 2;
  6739. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  6740. $excel_column = array ();
  6741. // 后期改进
  6742. if ($allColumn == 'AM')
  6743. $allColumn = 'Z';
  6744. /* * 从第A列开始输出 */
  6745. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  6746. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  6747. if ($val instanceof PHPExcel_RichText)
  6748. $val = $val->__toString ();
  6749. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  6750. // $val = "'" . addslashes ( $val ) . "'";
  6751. if ($sType == 'invoiceReceivables') {
  6752. if ($currentColumn == 'A')
  6753. $excel_column ['invoiceNo'] = $val;
  6754. elseif ($currentColumn == 'B')
  6755. $excel_column ['receivablesPrice'] = $val;
  6756. elseif ($currentColumn == 'C') {
  6757. $excel_column ['receivablesMessage'] = $val;
  6758. } elseif ($currentColumn == 'D') {
  6759. $excel_column ['receivablesBank'] = $val;
  6760. } elseif ($currentColumn == 'E') {
  6761. $excel_column ['receivablesDate'] = $this->excelTime ( $val );
  6762. } elseif ($currentColumn == 'F') {
  6763. $excel_column ['receivablesStaff'] = $val;
  6764. } elseif ($currentColumn == 'G') {
  6765. $excel_column ['sourcePrice'] = $val;
  6766. }
  6767. } elseif ($sType == "invoiceTrain") {
  6768. if ($currentColumn == 'A') {
  6769. $excel_column ['invoiceTitle'] = $val;
  6770. } elseif ($currentColumn == 'B')
  6771. $excel_column ['invoiceType'] = $val;
  6772. elseif ($currentColumn == 'C') {
  6773. $excel_column ['TIN'] = $val;
  6774. } elseif ($currentColumn == 'D') {
  6775. $excel_column ['address'] = $val;
  6776. } elseif ($currentColumn == 'E') {
  6777. $excel_column ['phone'] = $val;
  6778. } elseif ($currentColumn == 'F') {
  6779. $excel_column ['bank'] = $val;
  6780. } elseif ($currentColumn == 'G') {
  6781. $excel_column ['bankAccount'] = $val;
  6782. } elseif ($currentColumn == 'H') {
  6783. $excel_column ['invoiceElement'] = $val;
  6784. } elseif ($currentColumn == 'I') {
  6785. $excel_column ['invoiceQuantity'] = $val;
  6786. } elseif ($currentColumn == 'J') {
  6787. $excel_column ['invoiceUnitPrice'] = $val;
  6788. } elseif ($currentColumn == 'K') {
  6789. $excel_column ['remark'] = $val;
  6790. } elseif ($currentColumn == 'L') {
  6791. $excel_column ['recipientsAddress'] = $val;
  6792. } elseif ($currentColumn == 'M') {
  6793. $excel_column ['recipients'] = $val;
  6794. } elseif ($currentColumn == 'N') {
  6795. $excel_column ['recipientsPhone'] = $val;
  6796. }
  6797. } else {
  6798. if ($currentColumn == 'A')
  6799. $excel_column ['invoiceNo'] = $val;
  6800. elseif ($currentColumn == 'B')
  6801. $excel_column ['invoiceType'] = $val;
  6802. elseif ($currentColumn == 'C') {
  6803. $excel_column ['invoicePrice'] = $val;
  6804. } elseif ($currentColumn == 'D') {
  6805. $excel_column ['invoiceTitle'] = $val;
  6806. } elseif ($currentColumn == 'E') {
  6807. $excel_column ['userName'] = $val;
  6808. } elseif ($currentColumn == 'F') {
  6809. $excel_column ['categoryName'] = $val;
  6810. } elseif ($currentColumn == 'G') {
  6811. $excel_column ['invoiceElement'] = $val;
  6812. } elseif ($currentColumn == 'H') {
  6813. $excel_column ['remark'] = $val;
  6814. } elseif ($currentColumn == 'I') {
  6815. $excel_column ['date'] = $this->excelTime ( $val );
  6816. }
  6817. }
  6818. }
  6819. array_push ( $excel_array, $excel_column );
  6820. }
  6821. return $excel_array;
  6822. }
  6823. function excelTime($date, $time = false) {
  6824. if (function_exists ( 'GregorianToJD' )) {
  6825. if (is_numeric ( $date )) {
  6826. $jd = GregorianToJD ( 1, 1, 1970 );
  6827. $gregorian = JDToGregorian ( $jd + intval ( $date ) - 25569 );
  6828. $date = explode ( '/', $gregorian );
  6829. $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" : '');
  6830. return $date_str;
  6831. }
  6832. } else {
  6833. $date = $date > 25568 ? $date + 1 : 25569;
  6834. /* There was a bug if Converting date before 1-1-1970 (tstamp 0) */
  6835. $ofs = (70 * 365 + 17 + 2) * 86400;
  6836. $date = date ( "Y-m-d", ($date * 86400) - $ofs ) . ($time ? " 00:00:00" : '');
  6837. }
  6838. return $date;
  6839. }
  6840. /**
  6841. * 旧输入导入
  6842. */
  6843. function _GetFileEXT($filename) {
  6844. $pics = explode ( '.', $filename );
  6845. $num = count ( $pics );
  6846. return $pics [$num - 1];
  6847. }
  6848. function showCache($path = "", $sid = 0) {
  6849. // if (file_exists ( $path )) {
  6850. // $htm = file_get_contents ( $path );
  6851. // } else {
  6852. Doo::loadModel ( 'invoiceStatistics' );
  6853. $invoiceStatistics = new invoiceStatistics ();
  6854. $isBriefly = $invoiceStatistics->getBrieflyStatistics ( $sid );
  6855. $htm = '<tr><th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计开票</th>
  6856. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['invoicePrice'] . '</td>
  6857. <th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计入账</th>
  6858. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['accountPrice'] . '</td></tr>';
  6859. /*
  6860. * '<tr><th class="taC">今年累计开票</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['invoicePrice'] . '</td> <th class="taC">今年累计入账</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['accountPrice'] . '</td></tr>';
  6861. */
  6862. file_put_contents ( $path, $htm );
  6863. // }
  6864. return $htm;
  6865. }
  6866. /**
  6867. * 生成token
  6868. * @return string
  6869. */
  6870. function set_token() {
  6871. $str = md5 ( uniqid ( md5 ( microtime ( true ) ), true ) ); // 生成一个不会重复的字符串
  6872. $str = sha1 ( $str ); // 加密
  6873. return $str;
  6874. }
  6875. /**
  6876. * 获取get或者POST值
  6877. *
  6878. * @param string $name 属性名称
  6879. * @return fixed 值
  6880. */
  6881. function get_args($name) {
  6882. if (isset ( $_GET [$name] )) {
  6883. if (is_array ( $_GET [$name] ))
  6884. return $_GET [$name];
  6885. else
  6886. return addslashes ( $_GET [$name] );
  6887. } elseif (isset ( $_POST [$name] )) {
  6888. if (is_array ( $_POST [$name] ))
  6889. return $_POST [$name];
  6890. else
  6891. return addslashes ( $_POST [$name] );
  6892. } else
  6893. return false;
  6894. }
  6895. function SafeFilter(&$arr) {
  6896. $ra = Array (
  6897. '/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/',
  6898. '/script/',
  6899. '/javascript/',
  6900. '/vbscript/',
  6901. '/expression/',
  6902. '/applet/',
  6903. '/meta/',
  6904. '/xml/',
  6905. '/blink/',
  6906. '/link/',
  6907. '/style/',
  6908. '/embed/',
  6909. '/object/',
  6910. '/frame/',
  6911. '/layer/',
  6912. '/title/',
  6913. '/bgsound/',
  6914. '/base/',
  6915. '/onload/',
  6916. '/onunload/',
  6917. '/onchange/',
  6918. '/onsubmit/',
  6919. '/onreset/',
  6920. '/onselect/',
  6921. '/onblur/',
  6922. '/onfocus/',
  6923. '/onabort/',
  6924. '/onkeydown/',
  6925. '/onkeypress/',
  6926. '/onkeyup/',
  6927. '/onclick/',
  6928. '/ondblclick/',
  6929. '/onmousedown/',
  6930. '/onmousemove/',
  6931. '/onmouseout/',
  6932. '/onmouseover/',
  6933. '/onmouseup/',
  6934. '/onunload/'
  6935. );
  6936. if (is_array ( $arr )) {
  6937. foreach ( $arr as $key => $value ) {
  6938. if (! is_array ( $value )) {
  6939. if (! get_magic_quotes_gpc ()) // 不对magic_quotes_gpc转义过的字符使用addslashes(),避免双重转义。
  6940. {
  6941. $value = addslashes ( $value ); // 给单引号(')、双引号(")、反斜线(\)与 NUL(NULL 字符)加上反斜线转义
  6942. }
  6943. $value = preg_replace ( $ra, '', $value ); // 删除非打印字符,粗暴式过滤xss可疑字符串
  6944. $arr [$key] = htmlentities ( strip_tags ( $value ) ); // 去除 HTML 和 PHP 标记并转换为 HTML 实体
  6945. } else {
  6946. SafeFilter ( $arr [$key] );
  6947. }
  6948. }
  6949. }
  6950. }
  6951. /**
  6952. * Escape String
  6953. *
  6954. * @access public
  6955. * @param string
  6956. * @param bool whether or not the string will be used in a LIKE condition
  6957. * @return string
  6958. */
  6959. function escape_str($str, $like = FALSE) {
  6960. if (is_array ( $str )) {
  6961. foreach ( $str as $key => $val ) {
  6962. $str [$key] = $this->escape_str ( $val, $like );
  6963. }
  6964. return $str;
  6965. }
  6966. var_dump ( Doo::db ()->getDbObject () );
  6967. die ();
  6968. if (function_exists ( 'mysql_real_escape_string' ) and is_resource ( Doo::db ()->getDbObject () )) { // Doo::db ()->getDbObject()
  6969. $str = mysql_real_escape_string ( $str, Doo::db ()->getDbObject () );
  6970. } elseif (function_exists ( 'mysql_escape_string' )) {
  6971. $str = mysql_escape_string ( $str );
  6972. } else {
  6973. $str = addslashes ( $str );
  6974. }
  6975. // escape LIKE condition wildcards
  6976. if ($like === TRUE) {
  6977. $str = str_replace ( array (
  6978. '%',
  6979. '_'
  6980. ), array (
  6981. '\\%',
  6982. '\\_'
  6983. ), $str );
  6984. }
  6985. return $str;
  6986. }
  6987. /**
  6988. * 获得分页数据
  6989. * @param unknown_type $table
  6990. * @param unknown_type $condition
  6991. * @param unknown_type $on_page
  6992. * @param unknown_type $page_size
  6993. */
  6994. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  6995. $page_c = "";
  6996. $page ['previous'] = $this->get_previous ( $on_page );
  6997. $page ['on_page'] = $on_page;
  6998. $total_count = $this->get_table_count ( $table, $condition );
  6999. $total = intval ( $total_count / $page_size );
  7000. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  7001. $page ['total_data'] = $total_count;
  7002. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  7003. $i = 1;
  7004. $page_max = 1;
  7005. $page_width = 3;
  7006. if ($on_page >= $page_width) {
  7007. $page_max = intval ( $on_page / $page_width ) + 1;
  7008. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  7009. }
  7010. for(; $i <= $page ['total_page']; $i ++) {
  7011. if ($i == $on_page)
  7012. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  7013. else
  7014. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  7015. if ($i == ($page_width * $page_max))
  7016. break;
  7017. }
  7018. $page ['page'] = $page_c;
  7019. $page ['lower'] = (-- $on_page) * $page_size;
  7020. return $page;
  7021. }
  7022. /**
  7023. * 获取上一页
  7024. * @param unknown_type $on_page
  7025. */
  7026. function get_previous($on_page = 1) {
  7027. return $on_page != 0 ? $on_page - 1 : $on_page;
  7028. }
  7029. /**
  7030. * 获取总页数
  7031. * @param unknown_type $table
  7032. * @param unknown_type $condition
  7033. */
  7034. public function get_table_count($table = "", $condition = "") {
  7035. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  7036. $sql = "select count(*) as count from " . $table . " where " . $condition;
  7037. // echo $sql;die;
  7038. $query = Doo::db ()->query ( $sql );
  7039. $result = $query->fetch ();
  7040. return $result ['count'];
  7041. }
  7042. /**
  7043. * 获得分页数据
  7044. * @param unknown_type $table
  7045. * @param unknown_type $condition
  7046. * @param unknown_type $on_page
  7047. * @param unknown_type $page_size
  7048. */
  7049. function getPageBySql($sql = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  7050. $page_c = "";
  7051. $page ['previous'] = $this->get_previous ( $on_page );
  7052. $page ['on_page'] = $on_page;
  7053. $total_count = $this->getTableCountBySql ( $sql );
  7054. $total = intval ( $total_count / $page_size );
  7055. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  7056. $page ['total_data'] = $total_count;
  7057. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  7058. $i = 1;
  7059. $page_max = 1;
  7060. $page_width = 3;
  7061. if ($on_page >= $page_width) {
  7062. $page_max = intval ( $on_page / $page_width ) + 1;
  7063. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  7064. }
  7065. for(; $i <= $page ['total_page']; $i ++) {
  7066. if ($i == $on_page)
  7067. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  7068. else
  7069. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  7070. if ($i == ($page_width * $page_max))
  7071. break;
  7072. }
  7073. $page ['page'] = $page_c;
  7074. $page ['lower'] = (-- $on_page) * $page_size;
  7075. return $page;
  7076. }
  7077. /**
  7078. * 获得总页数 sql
  7079. * @param string $type
  7080. * @return boolean[]
  7081. */
  7082. public function getTableCountBySql($sql = "") {
  7083. $query = Doo::db ()->query ( $sql );
  7084. $result = $query->fetchAll ();
  7085. return count ( $result );
  7086. }
  7087. function isInvoiceNew($type = "GLOBAL") {
  7088. Doo::loadModel ( 'invoice' );
  7089. $invoice = new invoice ();
  7090. Doo::loadModel ( 'invoiceReceivables' );
  7091. $invoiceReceivables = new invoiceReceivables ();
  7092. Doo::loadModel ( 'staff' );
  7093. $staff = new staff ();
  7094. $st = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  7095. // 我的发票待处理
  7096. $pendingInvoice = $invoice->getOne ( array ( // or (status=2 and printStatus=1 and untreadStatus=0 ) or (status=2 and printStatus=1 and untreadStatus=2 )
  7097. 'where' => "(status=3 or status=4) and isDelete=0 and sid=" . $st [0] ['sid'],
  7098. 'desc' => 'iid',
  7099. 'asArray' => TRUE
  7100. ) );
  7101. // 我的收款待入账
  7102. /*
  7103. * $myClaim = $invoiceReceivables->getOne ( array ( 'where' => " receivablesStaff like '" . $st [0] ['sid'] . "-%' and receivablesCategory like '" . $st [0] ['cid'] . ":%' and bindStatus=0", 'desc' => 'irid', 'asArray' => TRUE ) );
  7104. */
  7105. // 发票审批
  7106. $approval = $invoice->getOne ( array (
  7107. 'where' => 'status=1 and pendingApprovals=' . $st [0] ['sid'],
  7108. 'desc' => 'iid',
  7109. 'asArray' => true
  7110. ) );
  7111. // 发票邮寄
  7112. $post = $invoice->getOne ( array (
  7113. 'where' => "postStatus=0 and printStatus=1 and isDelete=0 and doPost=1 and status=2",
  7114. 'asArray' => TRUE
  7115. ) );
  7116. // 发票打印
  7117. $print = $invoice->getOne ( array (
  7118. 'where' => "status=2 and printStatus=0 and untreadStatus=0 and moldManage like '%[\"" . $st [0] ['sid'] . "\",%'",
  7119. 'desc' => 'iid',
  7120. 'asArray' => TRUE
  7121. ) );
  7122. // 发票退票 printStatus=1 and
  7123. $untread = $invoice->getOne ( array (
  7124. 'where' => " untreadStatus=1 and status=2 ",
  7125. 'asArray' => TRUE
  7126. ) );
  7127. $new = array (
  7128. 'GLOBAL' => FALSE,
  7129. 'pendingInvoice' => FALSE,
  7130. // 'myClaim' => FALSE,
  7131. 'approval' => FALSE,
  7132. 'post' => FALSE,
  7133. 'print' => FALSE,
  7134. 'untread' => FALSE
  7135. );
  7136. // || ! empty ( $myClaim )
  7137. if (! empty ( $pendingInvoice ) || ! empty ( $approval ) || ! empty ( $post ) || ! empty ( $print ) || ! empty ( $untread ))
  7138. $new ['GLOBAL'] = TRUE;
  7139. if (! empty ( $pendingInvoice ))
  7140. $new ['pendingInvoice'] = TRUE;
  7141. // if (! empty ( $myClaim ))
  7142. // $new ['myClaim'] = TRUE;
  7143. if (! empty ( $approval ))
  7144. $new ['approval'] = TRUE;
  7145. if (! empty ( $post ))
  7146. $new ['post'] = TRUE;
  7147. if (! empty ( $print ))
  7148. $new ['print'] = TRUE;
  7149. if (! empty ( $untread ))
  7150. $new ['untread'] = TRUE;
  7151. return $new;
  7152. }
  7153. function setWXMsg($rid, $typeMsg = '') {
  7154. Doo::loadModel ( 'invoice' );
  7155. $invoice = new invoice ();
  7156. $invoiceDetail = $invoice->getOne ( array (
  7157. 'where' => 'iid=' . $rid,
  7158. 'asArray' => true
  7159. ) );
  7160. if (! empty ( $invoiceDetail )) {
  7161. Doo::loadModel ( 'staff' );
  7162. $staff = new staff ();
  7163. $staffmsg = $staff->getOne ( array (
  7164. 'where' => "sid='" . $invoiceDetail ['sid'] . "'",
  7165. 'asArray' => TRUE
  7166. ) );
  7167. if (! empty ( $staffmsg ['wxid'] )) {
  7168. require_once (SITE_PATH . '/protected/class/client.php');
  7169. $client = new client ( 'http://m.cld.smartcost.com.cn/' );
  7170. $user = $staffmsg ['wxid'];
  7171. $expCom = explode ( ":", $invoiceDetail ['expressCompany'] );
  7172. if (empty ( $expCom ))
  7173. $expCom [0] = '';
  7174. $msg = "";
  7175. if (empty ( $typeMsg ))
  7176. $msg = '太好了,您的发票' . $invoiceDetail ['invoiceSerial'] . ' 已邮寄 ' . $expCom [0] . ' ,快递号: <a href="https://m.kuaidi100.com/result.jsp?nu=' . $invoiceDetail ['expressNumber'] . '" >' . $invoiceDetail ['expressNumber'] . '</a>';
  7177. elseif ($typeMsg == "PRINT")
  7178. $msg = '太好了,您的发票已打印完成。';
  7179. $result = $client->SendMsg ( $user, $msg, 'text' );
  7180. }
  7181. }
  7182. }
  7183. /**
  7184. * 获取微信部门
  7185. * @param string $category
  7186. * @return number|mixed
  7187. */
  7188. function getToparty($category = '') {
  7189. $token = $this->getAccessToken (); //
  7190. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token={$token}&id=5" ), true );
  7191. $toparty = 0;
  7192. foreach ( $result ['department'] as $key => $value ) {
  7193. if ($value ['name'] == $category)
  7194. $toparty = $value ['id'];
  7195. }
  7196. return $toparty;
  7197. }
  7198. /**
  7199. * 获得某部门下的用户
  7200. * @param string $toparty
  7201. */
  7202. function getUserByToparty($toparty = '') {
  7203. $token = $this->getAccessToken (); //
  7204. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token={$token}&department_id={$toparty}" ), true );
  7205. $userList = array ();
  7206. foreach ( $result ['userlist'] as $key => $value ) {
  7207. array_push ( $userList, "'" . $value ['userid'] . "'" );
  7208. }
  7209. return $userList;
  7210. }
  7211. function msgSendToparty($msg, $title, $url, $toparty, $text = '') {
  7212. $token = $this->getAccessToken ();
  7213. if ($text == 'text') {
  7214. $data = '{
  7215. "touser": "' . $toparty . '",
  7216. "toparty": "",
  7217. "totag": "",
  7218. "msgtype": "text",
  7219. "agentid": 1000002,
  7220. "text": {
  7221. "content": "' . $msg . '"
  7222. },
  7223. "safe":0
  7224. }';
  7225. }
  7226. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  7227. if ($result->errmsg != 'ok') {
  7228. return 0;
  7229. } else {
  7230. return 1;
  7231. }
  7232. }
  7233. /**
  7234. * 获得可以发送微信用户列表
  7235. * @param string $category
  7236. * @return string
  7237. */
  7238. function getWxidByCategory($category = "") {
  7239. if (empty ( $category ))
  7240. return "";
  7241. Doo::loadModel ( 'staff' );
  7242. $staff = new staff ();
  7243. $toparty = $this->getToparty ( $category );
  7244. $wxList = array ();
  7245. $wxString = "";
  7246. if (! empty ( $toparty )) {
  7247. $userList = $this->getUserByToparty ( $toparty );
  7248. $userCon = implode ( ',', $userList );
  7249. // echo $userCon;
  7250. $sidList = $staff->getStaffByWxid ( $userCon );
  7251. foreach ( $sidList as $key => $value ) {
  7252. $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  7253. if ($falg) {
  7254. array_push ( $wxList, $value ['wxid'] );
  7255. }
  7256. }
  7257. $wxString = implode ( '|', $wxList );
  7258. }
  7259. return $wxString;
  7260. }
  7261. /**
  7262. * 读取发送信息规则判断是否需要发送
  7263. * @param number $sid
  7264. * @param string $sendType
  7265. * @return boolean
  7266. */
  7267. function isSendNotification($sid = 0, $sendType = '') {
  7268. Doo::loadModel ( "notificationConf" );
  7269. $notificationConf = new notificationConf ();
  7270. $detail = $notificationConf->getNotificationConfBySid ( $sid );
  7271. $conf = array ();
  7272. $sendFlag = true;
  7273. if (! empty ( $detail )) {
  7274. $conf = json_decode ( $detail ['conf'], true );
  7275. if (! empty ( $sendType )) {
  7276. if (isset ( $conf [$sendType] )) {
  7277. if ($conf [$sendType] == "CLOSE")
  7278. $sendFlag = false;
  7279. elseif ($conf [$sendType] == "Weekend") {
  7280. $day = date ( "w" );
  7281. if (1 <= $day && 5 >= $day)
  7282. $sendFlag = false;
  7283. } elseif ($conf [$sendType] == "OneToFriday") {
  7284. $day = date ( "w" );
  7285. if (0 == $day || 6 == $day)
  7286. $sendFlag = false;
  7287. }
  7288. }
  7289. } else
  7290. $sendFlag = false;
  7291. }
  7292. return $sendFlag;
  7293. }
  7294. /**
  7295. * 根据规则发送信息
  7296. * @param unknown $msg
  7297. * @param unknown $title
  7298. * @param unknown $url
  7299. * @param unknown $user
  7300. * @param string $text
  7301. * @return number
  7302. */
  7303. private function msgSend($msg, $title, $url, $user, $sid = 0, $sendType = '') {
  7304. $token = $this->getAccessToken ();
  7305. $falg = $this->isSendNotification ( $sid, $sendType );
  7306. // if ($text == 'text') {
  7307. // $data = '{
  7308. // "touser": "' . $user . '",
  7309. // "toparty": "",
  7310. // "totag": "",
  7311. // "msgtype": "text",
  7312. // "agentid": 1000002,
  7313. // "text": {
  7314. // "content": "' . $msg . '"
  7315. // },
  7316. // "safe":0
  7317. // }';
  7318. // } else {
  7319. $data = '{
  7320. "touser": "' . $user . '",
  7321. "toparty": "",
  7322. "totag": "",
  7323. "msgtype": "news",
  7324. "agentid": 1000002,
  7325. "news": {
  7326. "articles":[
  7327. {
  7328. "title": "' . $title . '",
  7329. "description": "' . $msg . '",
  7330. "url": "' . $url . '",
  7331. "picurl": ""
  7332. }
  7333. ]
  7334. }
  7335. }';
  7336. // }
  7337. if ($falg) {
  7338. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  7339. if ($result->errmsg != 'ok') {
  7340. return 0;
  7341. } else {
  7342. return 1;
  7343. }
  7344. } else
  7345. return 0;
  7346. }
  7347. private function getAccessToken() {
  7348. // access_token 应该全局存储与更新,以下代码以写入到文件中做示例
  7349. // $file = './access_token.txt';
  7350. // $data = json_decode ( file_get_contents ( $file ) );
  7351. // if ($data->expire_time < time () or ! $data->expire_time) {
  7352. // 如果是企业号用以下URL获取access_token
  7353. $url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$this->appId&corpsecret=$this->appSecret";
  7354. // $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$this->appId&secret=$this->appSecret";
  7355. $res = json_decode ( $this->httpGet ( $url ) );
  7356. $access_token = $res->access_token;
  7357. // echo $access_token;
  7358. // if ($access_token) {
  7359. // $data->expire_time = time () + 7000;
  7360. // $data->access_token = $access_token;
  7361. // $fp = fopen ( $file, "w" );
  7362. // fwrite ( $fp, json_encode ( $data ) );
  7363. // fclose ( $fp );
  7364. // }
  7365. // } else {
  7366. // $access_token = $data->access_token;
  7367. // }
  7368. return $access_token;
  7369. }
  7370. private function httpGet($url) {
  7371. $curl = curl_init ();
  7372. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  7373. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  7374. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  7375. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  7376. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  7377. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  7378. curl_setopt ( $curl, CURLOPT_URL, $url );
  7379. $res = curl_exec ( $curl );
  7380. curl_close ( $curl );
  7381. return $res;
  7382. }
  7383. private function httpPost($url, $data) {
  7384. $curl = curl_init ();
  7385. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  7386. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  7387. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  7388. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  7389. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  7390. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  7391. curl_setopt ( $curl, CURLOPT_URL, $url );
  7392. curl_setopt ( $curl, CURLOPT_POST, 1 );
  7393. curl_setopt ( $curl, CURLOPT_POSTFIELDS, $data );
  7394. $res = curl_exec ( $curl );
  7395. curl_close ( $curl );
  7396. return $res;
  7397. }
  7398. }
  7399. ?>