InvoiceController.php 329 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075
  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. //echo $routeRs ['1'];
  102. //die('dd');
  103. if (isset ( $_COOKIE ["staff"] )) {
  104. if (! empty ( $_COOKIE ["staff"] )) {
  105. Doo::loadModel ( 'staff' );
  106. $staff = new staff ();
  107. $uriPartsOrig = explode ( '/', $_SERVER ['REQUEST_URI'] );
  108. $this->ACTION = $uriPartsOrig [1];
  109. $this->data ['new'] = $this->isInvoiceNew ();
  110. $this->staff = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  111. $this->data ['isStaffCompleteMsg'] = false;
  112. $detail = $staff->checkStaffInfoIsComplete ( $_COOKIE ["staff"] );
  113. if (! empty ( $detail ))
  114. $this->data ['isStaffCompleteMsg'] = true;
  115. return "/";
  116. }
  117. }
  118. Doo::loadCore ( 'uri/DooUriRouter' );
  119. $router = new DooUriRouter ();
  120. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  121. if ($routeRs ['1'] != "login") {
  122. header ( 'Content-Type:text/html;charset=utf-8' );
  123. @header ( "Location: /login" );
  124. }
  125. }
  126. function testSend() {
  127. // 测试根据规则发送信息 普通发送
  128. // $pendingApprovalsSid = 41;
  129. // Doo::loadModel ( 'staff' );
  130. // $staff = new staff ();
  131. // $username2 = $staff->getOne ( array ( 'select' => 'wxid', 'where' => 'sid=' . $pendingApprovalsSid, 'asArray' => TRUE ) );
  132. // // 发送微信审批通知
  133. // $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  134. // $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  135. // Doo::loadModel ( 'staff' );
  136. // $staff = new staff ();
  137. // $toparty = $this->getToparty ( '广东办' );
  138. // $wxList = array ();
  139. // if (! empty ( $toparty )) {
  140. // $userList = $this->getUserByToparty ( $toparty );
  141. // $userCon = implode ( ',', $userList );
  142. // // echo $userCon;
  143. // $sidList = $staff->getStaffByWxid ( $userCon );
  144. // foreach ( $sidList as $key => $value ) {
  145. // $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  146. // if ($falg) {
  147. // array_push ( $wxList, $value ['wxid'] );
  148. // }
  149. // }
  150. // $wxString = implode ( '|', $wxList );
  151. // print_r ( $wxList );
  152. // echo $wxString;
  153. // }
  154. // 测试发送
  155. /*
  156. * //$toparty = $this->getWxidByCategory( $receivablesCategory [1] ); $toparty = $this->getToparty ( $receivablesCategory [1] ); $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。'; if ($toparty != 0) $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  157. */
  158. // print_r ( $userList );
  159. // $msTouser='caipin|outaozhen';
  160. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  161. // $title2 = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  162. // $hfreult = $this->msgSend ( '', $title2, '', 'outaozhen' );
  163. // $toparty= $this->getToparty('广东办');
  164. // $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  165. // $toparty = 26;
  166. // $msg = '';
  167. // $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/1.html';
  168. // $hfreult = $this->msgSendToparty ( $msg, '', '', $toparty,'text' );
  169. }
  170. function invoice() {
  171. Doo::loadModel ( 'invoice' );
  172. $invoice = new invoice ();
  173. Doo::loadModel ( 'express' );
  174. $express = new express ();
  175. $expressList = $express->getExpressByAll ();
  176. $this->data ['expressList'] = $expressList;
  177. // Doo::loadModel ( 'invoiceReceivables' );
  178. // $invoiceReceivables = new invoiceReceivables ();
  179. // $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  180. Doo::loadClass ( 'XDeode' );
  181. $XDeode = new XDeode ( 5 );
  182. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  183. Doo::loadModel ( 'invoiceStatistics' );
  184. $invoiceStatistics = new invoiceStatistics ();
  185. $isMonth = $invoiceStatistics->getStatisticsByMonth ( $sid );
  186. // 缓存统计结果
  187. $year = date ( "Y" );
  188. $tmp_date = date ( "Ym" );
  189. $tmp_year = substr ( $tmp_date, 0, 4 );
  190. $tmp_mon = substr ( $tmp_date, 4, 2 );
  191. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  192. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  193. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . "_" . $sid . ".htm";
  194. if (is_file ( $path ))
  195. $htm = file_get_contents ( $path );
  196. else
  197. $htm = $this->showCache ( $path, $sid );
  198. $invoiceList = $invoice->getMyInvoice ( $sid );
  199. $sql = 'status=2 and printStatus=1 and irid!="" and sid=' . $sid;
  200. $list = $invoice->getInvoiceByUntreadStatusPage ( 4, $sql );
  201. // 我的待入账发票 and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  202. $sql = "status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid=" . $sid;
  203. $myInvoiceUnAccount = $invoice->getInvoiceByUntreadStatusPage ( 4, $sql );
  204. // 获得已退票功能
  205. $untreadStatusList = $invoice->getMyInvoiceByUntreadStatus ( 2, 0, 5, $sid );
  206. $this->data ['untreadStatusList'] = $untreadStatusList;
  207. // print_r($untreadStatusList);
  208. $this->data ['isMonth'] = $isMonth;
  209. $this->data ['htm'] = $htm;
  210. $this->data ['invoiceList'] = $invoiceList;
  211. $this->data ['receivablesList'] = $list;
  212. $this->data ['myInvoiceUnAccount'] = $myInvoiceUnAccount;
  213. $this->data ['memu'] = "invoice";
  214. $this->data ['staff'] = $this->staff;
  215. $this->data ['receiptMemu'] = 'invoice';
  216. $this->render ( "/admin/invoice", $this->data );
  217. }
  218. function invoiceExpress() {
  219. $expressCom = isset ( $this->params ['expressCom'] ) ? $this->params ['expressCom'] : "";
  220. $expressNumber = isset ( $this->params ['expressNumber'] ) ? $this->params ['expressNumber'] : "";
  221. $this->data ['expressCom'] = $expressCom;
  222. $this->data ['expressNumber'] = $expressNumber;
  223. $this->render ( "/admin/invoiceExpress", $this->data );
  224. }
  225. function invoiceAdd() {
  226. session_start ();
  227. /*Doo::loadModel ( 'invoice' );
  228. $invoice = new invoice ();
  229. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );*/
  230. Doo::loadModel ( 'L_category' );
  231. $lCategory = new L_category ();
  232. $category = $lCategory->find ( array (
  233. 'asArray' => true
  234. ) );
  235. $this->data ['category'] = $category;
  236. Doo::loadModel ( 'invoiceTraining' );
  237. $invoiceTraining = new invoiceTraining ();
  238. $itList = $invoiceTraining->getInvoiceTrainingByCid ( $this->staff [0] ['cid'] );
  239. Doo::loadModel ( 'receipt' );
  240. $receipt = new receipt ();
  241. foreach ( $itList as $key => $value ) { // 不展示已结算完结的培训班
  242. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $value ['itid'] );
  243. if (! empty ( $receiptDetail )) {
  244. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9) {
  245. unset ( $itList [$key] );
  246. }
  247. }
  248. }
  249. $this->data ['itList'] = $itList;
  250. $token = $this->set_token ();
  251. $tokenTime=time().rand(5, 15);
  252. $_SESSION ['token_' . $this->staff [0] ['sidKey'].'_'.$tokenTime] = $token;
  253. $this->data ['token'] = $token;
  254. $this->data['tokenTime']=$tokenTime;
  255. $this->data ['memu'] = "invoice";
  256. $this->data ['staff'] = $this->staff;
  257. $this->data ['receiptMemu'] = 'invoice';
  258. $this->render ( "/admin/invoiceAdd", $this->data );
  259. }
  260. /**
  261. * 自更新发票信息库
  262. * @param unknown $invoicePrintDetail
  263. */
  264. function autoUpdateInvoiceInfoBase($invoicePrintDetail) {
  265. // 发票信息库
  266. Doo::loadModel ( 'invoiceInfoBase' );
  267. $invoiceInfoBase = new invoiceInfoBase ();
  268. $updateDate = strtotime ( $invoicePrintDetail ['date'] );
  269. $TIN = $invoicePrintDetail ['TIN'];
  270. $invoiceTitle = $invoicePrintDetail ['invoiceTitle'];
  271. if (empty ( $invoiceTitle ))
  272. $invoiceTitle = $invoicePrintDetail ['invoiceCompany'];
  273. $IIBList = $invoiceInfoBase->getInvoiceInfoByTT ( $TIN, $invoiceTitle );
  274. // 确认有该条发票信息
  275. $invoiceInfoBase = new invoiceInfoBase ();
  276. if (! empty ( $IIBList )) {
  277. // 发票库里的信息数量
  278. $IIBListCount = count ( $IIBList );
  279. if ($IIBListCount == 1) { // 更新发票--提交是最新的时间
  280. $item = array (
  281. 'iibID' => $IIBList [0] ['iibID'],
  282. 'invoiceTitle' => $invoiceTitle,
  283. 'TIN' => $TIN
  284. );
  285. if (! empty ( $invoicePrintDetail ['address'] )) {
  286. $item += array (
  287. 'address' => $invoicePrintDetail ['address']
  288. );
  289. }
  290. if (! empty ( $invoicePrintDetail ['phone'] )) {
  291. $item += array (
  292. 'phone' => $invoicePrintDetail ['phone']
  293. );
  294. }
  295. if (! empty ( $invoicePrintDetail ['bank'] )) {
  296. $item += array (
  297. 'bank' => $invoicePrintDetail ['bank']
  298. );
  299. }
  300. if (! empty ( $invoicePrintDetail ['bankAccount'] )) {
  301. $item += array (
  302. 'bankAccount' => $invoicePrintDetail ['bankAccount']
  303. );
  304. }
  305. if ($updateDate >= strtotime ($IIBList [0] ['updateDate'])) {
  306. $item += array (
  307. 'updateDate' => $invoicePrintDetail ['date']
  308. );
  309. $invoiceInfoBase->setInvoiceInfoBaseByCondition ( $item );
  310. }
  311. } else { // 删除多张发票,重新添加发票
  312. $iibIDStr = '';
  313. $iibID = array ();
  314. foreach ( $IIBList as $key => $value ) {
  315. array_push ( $iibID, $value ['iibID'] );
  316. }
  317. $iibIDStr = implode ( ",", $iibID ); // 删除
  318. $invoiceInfoBase->delInvoiceInfoBaseByIibStr ( $iibIDStr );
  319. $item = array (
  320. 'invoiceTitle' => $invoiceTitle,
  321. 'TIN' => $TIN,
  322. 'address' => $invoicePrintDetail ['address'],
  323. 'phone' => $invoicePrintDetail ['phone'],
  324. 'bank' => $invoicePrintDetail ['bank'],
  325. 'bankAccount' => $invoicePrintDetail ['bankAccount'],
  326. 'updateDate' => $invoicePrintDetail ['date']
  327. );
  328. $invoiceInfoBase->addInvoiceInfoBase ( $item );
  329. }
  330. } else { // 没有新增发票信息
  331. $item = array (
  332. 'invoiceTitle' => $invoiceTitle,
  333. 'TIN' => $TIN,
  334. 'address' => $invoicePrintDetail ['address'],
  335. 'phone' => $invoicePrintDetail ['phone'],
  336. 'bank' => $invoicePrintDetail ['bank'],
  337. 'bankAccount' => $invoicePrintDetail ['bankAccount'],
  338. 'updateDate' => $invoicePrintDetail ['date']
  339. );
  340. $invoiceInfoBase->addInvoiceInfoBase ( $item );
  341. }
  342. }
  343. function invoiceAddFill() {
  344. session_start ();
  345. Doo::loadModel ( 'L_category' );
  346. $lCategory = new L_category ();
  347. $category = $lCategory->find ( array (
  348. 'asArray' => true
  349. ) );
  350. $this->data ['category'] = $category;
  351. Doo::loadModel ( 'invoiceTraining' );
  352. $invoiceTraining = new invoiceTraining ();
  353. $itList = $invoiceTraining->getInvoiceTrainingByCid ( $this->staff [0] ['cid'] );
  354. $this->data ['itList'] = $itList;
  355. Doo::loadModel ( 'invoice' );
  356. $invoice = new invoice ();
  357. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );
  358. $detail ['mailItemsArray'] = json_decode ( $detail ['mailItemsJson'], true );
  359. $token = $this->set_token ();
  360. $tokenTime=time().rand(5, 15);
  361. $_SESSION ['token_' . $this->staff [0] ['sidKey'].'_'.$tokenTime] = $token;
  362. $this->data ['token'] = $token;
  363. $this->data['tokenTime']=$tokenTime;
  364. $this->data ['invoiceDetail'] = $detail;
  365. $this->data ['memu'] = "invoice";
  366. $this->data ['staff'] = $this->staff;
  367. $this->data ['receiptMemu'] = 'invoice';
  368. $this->render ( "/admin/invoiceAddFill", $this->data );
  369. }
  370. /**
  371. * 提交一份开票申请,并记录下操作日志
  372. *
  373. * @since 1.0.0
  374. * @var integer cid 办事处ID
  375. * @var integer invoiceType 发票类型
  376. * @var integer doPost 是否邮寄
  377. * @var integer invoicePrice 开票金额
  378. * @var string invoiceElement 开票内容
  379. * @var string invoiceTitle 发票抬头
  380. * @var string invoiceCompany 单位名称
  381. * @var string TIN 纳税人识别码
  382. * @var string address 注册地址
  383. * @var string phone 注册电话
  384. * @var string bank 开户银行
  385. * @var string bankAccount 银行账户
  386. * @var string recipients 收件人
  387. * @var string recipientsPhone 收件人手机/电话
  388. * @var string recipientsAddress 收件地址
  389. * @var string mailItems 邮寄物品
  390. * @var string remark 备注
  391. * @return string 返回跳转开票主页路径
  392. */
  393. function invoiceAddDo() {
  394. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  395. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  396. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  397. // $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  398. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  399. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  400. $invoiceForm = $this->get_args ( 'invoiceForm' ) ? $this->get_args ( 'invoiceForm' ) : "";
  401. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  402. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  403. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  404. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  405. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  406. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  407. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  408. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  409. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  410. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  411. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  412. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  413. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  414. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  415. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  416. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  417. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  418. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  419. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  420. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  421. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  422. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  423. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  424. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  425. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  426. $trainId = $this->get_args ( 'trainId' ) ? $this->get_args ( 'trainId' ) : 0;
  427. $settlementType = $this->get_args ( 'settlementType' ) ? $this->get_args ( 'settlementType' ) : "";
  428. $electronicPhone= $this->get_args ( 'electronicPhone' ) ? $this->get_args ( 'electronicPhone' ) : "";
  429. $electronicEmail = $this->get_args ( 'electronicEmail' ) ? $this->get_args ( 'electronicEmail' ) : "";
  430. /*
  431. * $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;
  432. */
  433. $token = $this->get_args ( 'token' ) ? $this->get_args ( 'token' ) : "";
  434. $tokenTime = $this->get_args ( 'tokenTime' ) ? $this->get_args ( 'tokenTime' ) : "";
  435. if (empty ( $token )) {
  436. die ( 'illegal request-token' );
  437. } else {
  438. session_start ();
  439. $sessionKey='token_' . $this->staff [0] ['sidKey'].'_'.$tokenTime;
  440. header ( 'Content-Type:text/html;charset=utf-8' );
  441. if (!isset($_SESSION [$sessionKey])||empty($_SESSION [$sessionKey])) {
  442. die ( '请重新刷新发票申请页面' );
  443. }elseif($_SESSION [$sessionKey]=='repeat'){
  444. die ( '请勿重复申请发票' );
  445. } else {
  446. if ($_SESSION [$sessionKey] != $token){
  447. die ( '请勿重复申请发票' );
  448. }else{
  449. $_SESSION [$sessionKey] = 'repeat';
  450. }
  451. }
  452. }
  453. if($invoiceForm=='electronic'){
  454. if(empty(trim($electronicPhone))&&empty(trim($electronicEmail))){
  455. die ( '请至少填写一种联系方式--电子发票' );
  456. }
  457. }
  458. if ($invoiceType == 1) {
  459. $temporary = $invoiceQuantity * $invoiceUnitPrice;
  460. if ($temporary > 100001) {
  461. header ( 'Content-Type:text/html;charset=utf-8' );
  462. die ( '专用发票总金额暂时不能超过100000.00(十万)元。' );
  463. }
  464. }elseif($invoiceType == 0){
  465. $temporary = $invoiceQuantity * $invoiceUnitPrice;
  466. if ($temporary > 100001) {
  467. header ( 'Content-Type:text/html;charset=utf-8' );
  468. die ( '专用发票总金额暂时不能超过100000.00(十万)元。' );
  469. }
  470. }else{
  471. die ( 'illegal request-invoiceType' );
  472. }
  473. if (empty ( $this->staff [0] ))
  474. die ( 'illegal request-Please login' );
  475. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $settlementType )&&!empty($invoiceForm)) {
  476. Doo::loadModel ( 'invoice' );
  477. $invoice = new invoice ();
  478. Doo::loadModel ( 'L_category' );
  479. $lCategory = new L_category ();
  480. Doo::loadModel ( 'invoiceManage' );
  481. $invoiceManage = new invoiceManage ();
  482. Doo::loadModel ( 'invoiceOperationLog' );
  483. $invoiceOperationLog = new invoiceOperationLog ();
  484. Doo::loadClass ( 'XDeode' );
  485. $XDeode = new XDeode ( 5 );
  486. $trainId = $XDeode->decode ( $trainId );
  487. $categoryDetil = $lCategory->getOne ( array (
  488. 'SELECT' => 'title',
  489. 'where' => 'cid=' . $cid,
  490. 'asArray' => true
  491. ) );
  492. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  493. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  494. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  495. // print_r(current($invoiceManageDetail ['staffList']));
  496. // die;
  497. $moldManage = array ();
  498. foreach ( $invoiceManageList as $key => $value ) {
  499. if ($value ['mold'] == '发票打印')
  500. $moldManage [$value ['mold']] = $value ['staffList'];
  501. elseif ($value ['mold'] == '发票邮寄')
  502. $moldManage [$value ['mold']] = $value ['staffList'];
  503. elseif ($value ['mold'] == '发票退票')
  504. $moldManage [$value ['mold']] = $value ['staffList'];
  505. }
  506. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  507. $st = '';
  508. if ($settlementType == 'SOFTWARE') {
  509. $st = 0;
  510. $trainId = 0;
  511. } elseif ($settlementType == 'TRAINING') {
  512. $st = 1;
  513. if (empty ( $trainId ) && ! is_numeric ( $trainId )) {
  514. die ( 'illegal request-trainingIdError' );
  515. }
  516. } else {
  517. die ( 'illegal request-settlementError' );
  518. }
  519. if($invoiceForm=='electronic'){
  520. $invoiceSerial="#FE" . date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
  521. $invoiceForm=1;
  522. $invoiceType=0;
  523. if(!empty($electronicPhone)||!empty($electronicEmail)){
  524. }else{
  525. die ( 'illegal request-electronicContact' );
  526. }
  527. $mailList = array ();
  528. $mailString = '备注:' . $mailItems;
  529. }elseif($invoiceForm=='paper'){
  530. $invoiceSerial="#F" . date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
  531. $invoiceForm=0;
  532. $mailList = array (
  533. 'invoice' => 1,
  534. 'mailItems' => $mailItems
  535. );
  536. $mailString = '发票x1张,备注:' . $mailItems;
  537. }else{
  538. die ( 'illegal request-invoiceForm' );
  539. }
  540. $item = array (
  541. 'cid' => $cid,
  542. 'categoryName' => $categoryDetil ['title'],
  543. 'invoiceElement' => $invoiceElement,
  544. 'invoiceForm'=>$invoiceForm,
  545. 'electronicPhone'=>$electronicPhone,
  546. 'electronicEmail'=>$electronicEmail,
  547. 'invoiceQuantity' => $invoiceQuantity,
  548. 'invoiceUnitPrice' => $invoiceUnitPrice,
  549. 'invoicePrice' => $invoicePrice,
  550. 'invoiceType' => $invoiceType,
  551. 'settlementType' => $st,
  552. 'doPost' => $doPost,
  553. 'status' => 1,
  554. 'invoiceSerial' => $invoiceSerial,
  555. 'date' => date ( "Y-m-d H:i:s" ),
  556. 'updateTime' => date ( "Y-m-d H:i:s" ),
  557. 'sid' => $this->staff [0] ['sid'],
  558. 'userName' => $this->staff [0] ['username'],
  559. 'invoiceManage' => $invoiceManageDetail ['staff'],
  560. 'pendingApprovals' => $pendingApprovalsSid,
  561. 'moldManage' => json_encode ( $moldManage ),
  562. 'remark' => $remark,
  563. 'trainId' => $trainId
  564. );
  565. if ($invoiceType == 0)
  566. $item += array (
  567. 'invoiceTitle' => $invoiceTitle,
  568. 'TIN' => $TINT,
  569. 'address' => $addressT,
  570. 'phone' => $phoneT,
  571. 'bank' => $bankT,
  572. 'bankAccount' => $bankAccountT
  573. );
  574. else {
  575. $item += array (
  576. 'invoiceCompany' => $invoiceCompany,
  577. 'TIN' => $TIN,
  578. 'address' => $address,
  579. 'phone' => $phone,
  580. 'bank' => $bank,
  581. 'bankAccount' => $bankAccount
  582. );
  583. }
  584. if ($doPost == 1) {
  585. if (! empty ( $softLock ))
  586. $mailList += array (
  587. 'softLock' => $softLockNum
  588. );
  589. else
  590. $mailList += array (
  591. 'softLock' => 0
  592. );
  593. if (! empty ( $contract ))
  594. $mailList += array (
  595. 'contract' => $contractNum
  596. );
  597. else
  598. $mailList += array (
  599. 'contract' => 0
  600. );
  601. if (! empty ( $instructions ))
  602. $mailList += array (
  603. 'instructions' => $instructionsNum
  604. );
  605. else
  606. $mailList += array (
  607. 'instructions' => 0
  608. );
  609. if (! empty ( $remittance ))
  610. $mailList += array (
  611. 'remittance' => $remittance
  612. );
  613. else
  614. $mailList += array (
  615. 'remittance' => ''
  616. );
  617. if (! empty ( $softLock ))
  618. $mailString .= ',软件锁x' . $softLockNum . '个';
  619. if (! empty ( $contract ))
  620. $mailString .= ',合同x' . $contractNum . '份';
  621. if (! empty ( $instructions ))
  622. $mailString .= ',说明书x' . $instructionsNum . '本';
  623. if (! empty ( $remittance ))
  624. $mailString .= ',汇款账号单(张)';
  625. $item += array (
  626. 'recipients' => $recipients,
  627. 'recipientsPhone' => $recipientsPhone,
  628. 'recipientsAddress' => $recipientsAddress,
  629. 'mailItems' => $mailString,
  630. 'mailItemsJson' => json_encode ( $mailList )
  631. );
  632. }
  633. $iid = $invoice->addInvoice ( $item );
  634. // 如果是培训班结算 创建培训班发票到培训班备份中
  635. if (! empty ( $st ) && $st == 1) {
  636. Doo::loadModel ( 'invoiceStore' );
  637. $invoiceStore = new invoiceStore ();
  638. Doo::loadModel ( 'invoiceTraining' );
  639. $invoiceTraining = new invoiceTraining ();
  640. $isid = $invoiceStore->setInvoiceToInvoiceStore ( $iid );
  641. $itemIS = array (
  642. 'isid' => $isid,
  643. 'ipSource' => 1,
  644. 'apStatus' => 1,
  645. 'iid' => $iid
  646. );
  647. $invoiceStore->setInvoiceStoreByCondition ( $itemIS );
  648. // 更新培训班总数量
  649. $detailIT = $invoiceTraining->getInvoiceTrainingByItid ( $trainId );
  650. $item = array (
  651. 'itid' => $trainId,
  652. 'invoiceTotal' => $detailIT ['invoiceTotal'] + 1,
  653. 'submitStatus' => 1
  654. );
  655. $itid = $invoiceTraining->setInvoiceTrainByCondition ( $item );
  656. }
  657. // 操作日志
  658. $item = array (
  659. 'date' => date ( "Y-m-d H:i:s" ),
  660. 'operation' => "创建",
  661. 'status' => 1,
  662. 'img' => $this->staff [0] ['avatar'],
  663. 'username' => $this->staff [0] ['username'],
  664. 'uid' => $this->staff [0] ['sid'],
  665. 'category' => $this->staff [0] ['category'],
  666. 'iid' => $iid
  667. );
  668. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  669. $item = array (
  670. 'date' => date ( "Y-m-d H:i:s" ),
  671. 'operation' => "提交审批",
  672. 'status' => 1,
  673. 'img' => $this->staff [0] ['avatar'],
  674. 'username' => $this->staff [0] ['username'],
  675. 'uid' => $this->staff [0] ['sid'],
  676. 'category' => $this->staff [0] ['category'],
  677. 'iid' => $iid
  678. );
  679. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  680. Doo::loadModel ( 'staff' );
  681. $staff = new staff ();
  682. $username2 = $staff->getOne ( array (
  683. 'select' => 'wxid',
  684. 'where' => 'sid=' . $pendingApprovalsSid,
  685. 'asArray' => TRUE
  686. ) );
  687. // 发送微信审批通知
  688. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  689. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  690. }
  691. return "/invoice";
  692. }
  693. function invoiceEdit() {
  694. Doo::loadClass ( 'XDeode' );
  695. $XDeode = new XDeode ( 5 );
  696. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  697. $iid = $XDeode->decode ( $iid );
  698. if (! is_numeric ( $iid ))
  699. die ( 'illegal request' );
  700. Doo::loadModel ( 'invoice' );
  701. $invoice = new invoice ();
  702. Doo::loadModel ( 'invoiceOperationLog' );
  703. $invoiceOperationLog = new invoiceOperationLog ();
  704. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  705. $operation = $invoiceOperationLog->getInvoiceOperationByDropped ( $iid );
  706. $invoiceDetail ['mailItemsJson'] ='';
  707. if(isset($invoiceDetail ['mailItemsJson'])){
  708. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  709. }
  710. $this->data ['operation'] = $operation;
  711. $this->data ['invoiceDetail'] = $invoiceDetail;
  712. $this->data ['memu'] = "invoice";
  713. $this->data ['staff'] = $this->staff;
  714. $this->data ['receiptMemu'] = 'invoice';
  715. $this->render ( "/admin/invoiceEdit", $this->data );
  716. }
  717. /**
  718. * 重新编辑退回的发票
  719. * @return string
  720. */
  721. function invoiceEditDo() {
  722. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  723. Doo::loadModel ( 'invoice' );
  724. $invoice = new invoice ();
  725. $iid = $invoice->authcode ( $iidKey );
  726. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  727. die ( 'illegal request' );
  728. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  729. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  730. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  731. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  732. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  733. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  734. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  735. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  736. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  737. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  738. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  739. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  740. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  741. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  742. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  743. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  744. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  745. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  746. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  747. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  748. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  749. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  750. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  751. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  752. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  753. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  754. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  755. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  756. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  757. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  758. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  759. $electronicPhone = $this->get_args ( 'electronicPhone' ) ? $this->get_args ( 'electronicPhone' ) : "";
  760. $electronicEmail = $this->get_args ( 'electronicEmail' ) ? $this->get_args ( 'electronicEmail' ) : "";
  761. $invoiceForm = $this->get_args ( 'invoiceForm' ) ? $this->get_args ( 'invoiceForm' ) : "";
  762. if ($invoiceType == 1) {
  763. $temporary = $invoiceQuantity * $invoiceUnitPrice;
  764. if ($temporary > 100001)
  765. die ( 'illegal request-Please priceError' );
  766. }
  767. if($invoiceForm=='electronic'){
  768. if(empty(trim($electronicPhone))&&empty(trim($electronicEmail))){
  769. die ( '请至少填写一种联系方式--电子发票' );
  770. }
  771. }
  772. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  773. Doo::loadModel ( 'invoiceManage' );
  774. $invoiceManage = new invoiceManage ();
  775. Doo::loadModel ( 'invoiceOperationLog' );
  776. $invoiceOperationLog = new invoiceOperationLog ();
  777. Doo::loadModel ( 'invoiceStore' );
  778. $invoiceStore = new invoiceStore ();
  779. $cid = explode ( ':', $cid );
  780. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  781. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  782. $moldManage = array ();
  783. foreach ( $invoiceManageList as $key => $value ) {
  784. if ($value ['mold'] == '发票打印')
  785. $moldManage [$value ['mold']] = $value ['staffList'];
  786. elseif ($value ['mold'] == '发票邮寄')
  787. $moldManage [$value ['mold']] = $value ['staffList'];
  788. elseif ($value ['mold'] == '发票打印')
  789. $moldManage [$value ['mold']] = $value ['staffList'];
  790. }
  791. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  792. if($invoiceForm=='electronic'){
  793. $invoiceForm=1;
  794. $invoiceType=0;
  795. if(!empty($electronicPhone)||!empty($electronicEmail)){
  796. }else{
  797. die ( 'illegal request-electronicContact' );
  798. }
  799. $mailList = array ();
  800. $mailString = '备注:' . $mailItems;
  801. }elseif($invoiceForm=='paper'){
  802. $invoiceForm=0;
  803. $mailList = array (
  804. 'invoice' => 1,
  805. 'mailItems' => $mailItems
  806. );
  807. $mailString = '发票x1张,备注:' . $mailItems;
  808. }else{
  809. die ( 'illegal request-invoiceForm' );
  810. }
  811. $item = array (
  812. 'iid' => $iid,
  813. 'cid' => $cid [0],
  814. 'categoryName' => $cid [1],
  815. 'invoiceElement' => $invoiceElement,
  816. 'invoiceForm'=>$invoiceForm,
  817. 'electronicPhone'=>$electronicPhone,
  818. 'electronicEmail'=>$electronicEmail,
  819. 'invoiceQuantity' => $invoiceQuantity,
  820. 'invoiceUnitPrice' => $invoiceUnitPrice,
  821. 'invoicePrice' => $invoicePrice,
  822. 'invoiceType' => $invoiceType,
  823. 'doPost' => $doPost,
  824. 'status' => 1,
  825. 'updateTime' => date ( "Y-m-d H:i:s" ),
  826. 'remark' => $remark
  827. );
  828. if ($invoiceType == 0)
  829. $item += array (
  830. 'invoiceTitle' => $invoiceTitle,
  831. 'TIN' => $TINT,
  832. 'address' => $addressT,
  833. 'phone' => $phoneT,
  834. 'bank' => $bankT,
  835. 'bankAccount' => $bankAccountT
  836. );
  837. else {
  838. $item += array (
  839. 'invoiceCompany' => $invoiceCompany,
  840. 'TIN' => $TIN,
  841. 'address' => $address,
  842. 'phone' => $phone,
  843. 'bank' => $bank,
  844. 'bankAccount' => $bankAccount
  845. );
  846. }
  847. if ($doPost == 1) {
  848. if (! empty ( $softLock ))
  849. $mailList += array (
  850. 'softLock' => $softLockNum
  851. );
  852. else
  853. $mailList += array (
  854. 'softLock' => '0'
  855. );
  856. if (! empty ( $contract ))
  857. $mailList += array (
  858. 'contract' => $contractNum
  859. );
  860. else
  861. $mailList += array (
  862. 'contract' => '0'
  863. );
  864. if (! empty ( $instructions ))
  865. $mailList += array (
  866. 'instructions' => $instructionsNum
  867. );
  868. else
  869. $mailList += array (
  870. 'instructions' => '0'
  871. );
  872. if (! empty ( $remittance ))
  873. $mailList += array (
  874. 'remittance' => $remittance
  875. );
  876. else
  877. $mailList += array (
  878. 'remittance' => ''
  879. );
  880. if (! empty ( $softLock ))
  881. $mailString .= ',软件锁x' . $softLockNum;
  882. if (! empty ( $contract ))
  883. $mailString .= ',合同x' . $contractNum;
  884. if (! empty ( $instructions ))
  885. $mailString .= ',说明书x' . $instructionsNum;
  886. if (! empty ( $remittance ))
  887. $mailString .= ',汇款账号单';
  888. $item += array (
  889. 'recipients' => $recipients,
  890. 'recipientsPhone' => $recipientsPhone,
  891. 'recipientsAddress' => $recipientsAddress,
  892. 'mailItems' => $mailString,
  893. 'mailItemsJson' => json_encode ( $mailList )
  894. );
  895. }
  896. $invoice->setInvoiceByCondition ( $item );
  897. // 更新培训班仓库里的发票
  898. $detail = $invoice->getInvoiceByIid ( $iid );
  899. if (! empty ( $detail ['isid'] )) {
  900. $invoiceStore->isid = $detail ['isid'];
  901. $invoiceStore->invoiceQuantity = $invoiceQuantity;
  902. $invoiceStore->invoiceUnitPrice = $invoiceUnitPrice;
  903. $invoiceStore->invoicePrice = $invoicePrice;
  904. $invoiceStore->update ();
  905. }
  906. $item = array (
  907. 'date' => date ( "Y-m-d H:i:s" ),
  908. 'operation' => "重新提交审批",
  909. 'status' => 1,
  910. 'img' => $this->staff [0] ['avatar'],
  911. 'username' => $this->staff [0] ['username'],
  912. 'uid' => $this->staff [0] ['sid'],
  913. 'category' => $this->staff [0] ['category'],
  914. 'iid' => $iid
  915. );
  916. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  917. }
  918. return "/invoice";
  919. }
  920. /**
  921. * 培训班
  922. */
  923. function invoiceTraining() {
  924. Doo::loadModel ( 'L_category' );
  925. $lCategory = new L_category ();
  926. Doo::loadModel ( 'invoiceTraining' );
  927. $invoiceTraining = new invoiceTraining ();
  928. Doo::loadModel ( 'invoiceTrainManage' );
  929. $invoiceTrainManage = new invoiceTrainManage ();
  930. $imcStaff = $invoiceTrainManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  931. $cidList = array ();
  932. foreach ( $imcStaff as $key => $value ) {
  933. array_push ( $cidList, $value ['cid'] );
  934. }
  935. if (empty ( $cidList )) {
  936. $cidString = $this->staff [0] ['cid'];
  937. } else {
  938. $cidString = implode ( ',', $cidList );
  939. $cidString .= $cidString . ',' . $this->staff [0] ['cid'];
  940. }
  941. $itTodoList = $invoiceTraining->getInvoiceTrainingByTodo ( '', $cidString, $this->staff [0] ['sid'] );
  942. $itedList = $invoiceTraining->getInvoiceTrainingByStatus ( 2, '', $cidString, $this->staff [0] ['sid'] );
  943. $category = $lCategory->getCategory ();
  944. $itid = array ();
  945. foreach ( $itTodoList as $key => $value ) {
  946. array_push ( $itid, $value ['itid'] );
  947. // 如果入账100%更新为已完成
  948. if ($itTodoList [$key] ['arriveSchedule'] >= 100) {
  949. $invoiceTraining = new invoiceTraining ();
  950. $invoiceTraining->itid = $value ['itid'];
  951. $invoiceTraining->status = 2;
  952. $invoiceTraining->update ();
  953. }
  954. }
  955. foreach ( $itedList as $value ) {
  956. array_push ( $itid, $value ['itid'] );
  957. }
  958. $itid = implode ( ',', $itid );
  959. $this->data ['itStatist'] = $invoiceTraining->getInvoiceTrainStatistics ( $itid );
  960. // print_r($itTodoList);
  961. $this->data ['trainCount'] = count ( $itTodoList ) + count ( $itedList );
  962. $this->data ['itTodoList'] = $itTodoList;
  963. $this->data ['itedList'] = $itedList;
  964. $this->data ['category'] = $category;
  965. $this->data ['memu'] = "invoice";
  966. $this->data ['staff'] = $this->staff;
  967. $this->data ['receiptMemu'] = 'invoiceTraining';
  968. $this->render ( "/admin/invoiceTraining", $this->data );
  969. }
  970. /**
  971. * 创建培训班
  972. */
  973. function invoiceTrainingAdd() {
  974. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  975. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  976. $trainDate = $this->get_args ( 'trainDate' ) ? $this->get_args ( 'trainDate' ) : "";
  977. if (empty ( $this->staff [0] ))
  978. die ( 'illegal request' );
  979. if (! empty ( $cid ) && ! empty ( $trainName ) && ! empty ( $trainDate )) {
  980. Doo::loadModel ( 'invoiceTraining' );
  981. $invoiceTraining = new invoiceTraining ();
  982. Doo::loadModel ( 'invoice' );
  983. $invoice = new invoice ();
  984. Doo::loadModel ( 'L_category' );
  985. $lCategory = new L_category ();
  986. Doo::loadModel ( 'invoiceManage' );
  987. $invoiceManage = new invoiceManage ();
  988. Doo::loadModel ( 'invoiceOperationLog' );
  989. $invoiceOperationLog = new invoiceOperationLog ();
  990. $item = array (
  991. 'cid' => $cid,
  992. 'trainName' => $trainName,
  993. 'trainDate' => $trainDate,
  994. 'creator' => $this->staff [0] ['sid'],
  995. 'creatorDate' => date ( "Y-m-d H:i:s" )
  996. );
  997. $itid = $invoiceTraining->addInvoiceTraining ( $item );
  998. }
  999. return "/invoiceTraining";
  1000. }
  1001. /**
  1002. * 删除培训班
  1003. */
  1004. function invoiceTrainingDelDo() {
  1005. $itid = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  1006. if (! empty ( $itid )) {
  1007. Doo::loadModel ( 'invoiceTraining' );
  1008. $invoiceTraining = new invoiceTraining ();
  1009. $invoiceTraining->delInvoiceTrainingByItid ( $itid );
  1010. }
  1011. return "/invoiceTraining";
  1012. }
  1013. /**
  1014. * 培训班详情
  1015. */
  1016. function invoiceTrainingDetail() {
  1017. $trainStatus = $this->get_args ( 'trainStatus' ) ? $this->get_args ( 'trainStatus' ) : "ALL";
  1018. $itid = isset ( $this->params ['trainingKey'] ) ? $this->params ['trainingKey'] : "";
  1019. Doo::loadModel ( 'invoiceTraining' );
  1020. $invoiceTraining = new invoiceTraining ();
  1021. Doo::loadModel ( 'invoiceStore' );
  1022. $invoiceStore = new invoiceStore ();
  1023. if (empty ( $itid ))
  1024. die ( 'illegal request' );
  1025. $con = '(b.untreadStatus is null or b.untreadStatus!=2) and ';
  1026. if ($trainStatus == "SUBED")
  1027. $con = ' (b.untreadStatus is null ) and ';
  1028. elseif ($trainStatus == "APPROVAL")
  1029. $con = ' ( b.status=1 and b.untreadStatus!=2 ) and ';
  1030. elseif ($trainStatus == "TICKET")
  1031. $con = ' (b.printStatus=1 and b.status=2 and b.untreadStatus!=2) and ';
  1032. elseif ($trainStatus == "TICKETING") {
  1033. $con = ' (b.status=2 and b.untreadStatus=1) and ';
  1034. }
  1035. $con.=' a.invoiceForm=0 and ';
  1036. $detail = $invoiceTraining->getInvoiceTrainingByItid ( $itid );
  1037. $isList = $invoiceStore->getinvoiceStoreByItid ( $itid, $con,0 );
  1038. //print_r($isList);
  1039. $trainlistJson=$this->_trainList($isList);
  1040. if (empty ( $detail ))
  1041. die ( 'illegal request' );
  1042. // 培训班结算是否有和是否已经结算完成
  1043. Doo::loadModel ( 'receipt' );
  1044. $receipt = new receipt ();
  1045. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $itid );
  1046. $this->data ['receiptDetail'] = $receiptDetail;
  1047. $this->data ['trainStatus'] = $trainStatus;
  1048. $this->data ['itid'] = $itid;
  1049. $this->data ['trainlistJson'] = $trainlistJson;
  1050. $this->data ['iTrainDetail'] = $detail;
  1051. $this->data ['memu'] = "invoice";
  1052. $this->data ['staff'] = $this->staff;
  1053. $this->data ['receiptMemu'] = 'invoiceTraining';
  1054. $this->render ( "/admin/invoiceTrainingDetail", $this->data );
  1055. }
  1056. function invoiceTrainingElectronicDetail(){
  1057. $trainStatus = $this->get_args ( 'trainStatus' ) ? $this->get_args ( 'trainStatus' ) : "ALL";
  1058. $itid = isset ( $this->params ['trainingKey'] ) ? $this->params ['trainingKey'] : "";
  1059. Doo::loadModel ( 'invoiceTraining' );
  1060. $invoiceTraining = new invoiceTraining ();
  1061. Doo::loadModel ( 'invoiceStore' );
  1062. $invoiceStore = new invoiceStore ();
  1063. if (empty ( $itid ))
  1064. die ( 'illegal request' );
  1065. $con = ' (b.untreadStatus is null or b.untreadStatus!=2) and ';
  1066. if ($trainStatus == "SUBED")
  1067. $con = ' (b.untreadStatus is null ) and ';
  1068. elseif ($trainStatus == "APPROVAL")
  1069. $con = ' ( b.status=1 and b.untreadStatus!=2 ) and ';
  1070. elseif ($trainStatus == "TICKET")
  1071. $con = ' (b.printStatus=1 and b.status=2 and b.untreadStatus!=2) and ';
  1072. elseif ($trainStatus == "TICKETING") {
  1073. $con = ' (b.status=2 and b.untreadStatus=1) and ';
  1074. }
  1075. $con.=' a.invoiceForm=1 and ';
  1076. $detail = $invoiceTraining->getInvoiceTrainingByItid ( $itid );
  1077. $isList = $invoiceStore->getinvoiceStoreByItid ( $itid, $con,1 );
  1078. //print_r($isList);
  1079. if (empty ( $detail )){
  1080. die ( 'illegal request' );
  1081. }
  1082. $trainlistJson=$this->_trainList($isList,1);
  1083. // 培训班结算是否有和是否已经结算完成
  1084. Doo::loadModel ( 'receipt' );
  1085. $receipt = new receipt ();
  1086. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $itid );
  1087. $this->data ['receiptDetail'] = $receiptDetail;
  1088. $this->data ['trainStatus'] = $trainStatus;
  1089. $this->data ['itid'] = $itid;
  1090. $this->data ['trainlistJson'] = $trainlistJson;
  1091. $this->data ['iTrainDetail'] = $detail;
  1092. $this->data ['memu'] = "invoice";
  1093. $this->data ['staff'] = $this->staff;
  1094. $this->data ['receiptMemu'] = 'invoiceTraining';
  1095. $this->render ( "/invoice/invoiceTrainingElectronicDetail", $this->data );
  1096. }
  1097. function _trainList($isList,$type=0){
  1098. $trainlist = array ();
  1099. foreach ( $isList as $key => $value ) {
  1100. $irDetail = array ();
  1101. if ($value ['apStatus'] == 1) {
  1102. // array_push ( $irDetail, '' );
  1103. array_push ( $irDetail, '<input disabled type="checkbox" style="display:none" >' );
  1104. } else {
  1105. array_push ( $irDetail, '<input type="checkbox" class="hide" id="' . $value ['storeKey'] . '" name="isBox" value="' . $value ['storeKey'] . '" > <a href="/invoiceStoreEdit/' . $value ['storeKey'] . '.html">编辑</a>
  1106. <a href="#confirm" onclick="invoiceStoreApproval(\'' . $value ['storeKey'] . '\')" data-toggle="modal">提交审批</a>
  1107. <a href="#del" node-iStore="del" data-key="' . $value ['storeKey'] . '" onclick="invoiceStoreDel(\'' . $value ['storeKey'] . '\')" data-toggle="modal" class="colRed">移除</a>' );
  1108. }
  1109. array_push ( $irDetail, $value ['invoiceSerial'] );
  1110. if ($value ['invoiceType'] == 1)
  1111. array_push ( $irDetail, $value ['invoiceCompany'] );
  1112. else
  1113. array_push ( $irDetail, $value ['invoiceTitle'] );
  1114. array_push ( $irDetail, $value ['TIN'] );
  1115. array_push ( $irDetail, $value ['userName'] );
  1116. if (empty ( $value ['mailItems'] ) && $value ['apStatus'] != 1) {
  1117. array_push ( $irDetail, '<a href="#confirm-erro" onclick="invoiceStoreMail(\'' . $value ['storeKey'] . '\')" data-toggle="modal">设置邮寄物品</a>' );
  1118. } else
  1119. array_push ( $irDetail, $value ['mailItems'] );
  1120. array_push ( $irDetail, $value ['recipientsAddress'] . $value ['recipients'] . $value ['recipientsPhone'] );
  1121. if($type==1){
  1122. array_push ( $irDetail, $value ['electronicPhone'] );
  1123. array_push ( $irDetail, $value ['electronicEmail'] );
  1124. }
  1125. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  1126. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  1127. array_push ( $irDetail, $value ['invoiceElement'] );
  1128. array_push ( $irDetail, $value ['invoiceQuantity'] );
  1129. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  1130. if ($value ['invoiceType'] == 1)
  1131. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  1132. else
  1133. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  1134. array_push ( $irDetail, $value ['remark'] );
  1135. if ($value ['status'] == 1)
  1136. array_push ( $irDetail, '审批中' );
  1137. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1)
  1138. array_push ( $irDetail, '已出票' );
  1139. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1 && $value ['printStatus'] != 'irid' && ($value ['untreadStatus'] == 3 || $value ['untreadStatus'] == 0))
  1140. array_push ( $irDetail, '已入账' );
  1141. else
  1142. array_push ( $irDetail, '' );
  1143. array_push ( $irDetail, $value ['invoiceNo'] );
  1144. array_push ( $irDetail, $value ['printTime'] );
  1145. $html = '';
  1146. foreach ( $value ['invoiceReceivables'] as $v ) {
  1147. $html .= '&nbsp;<a href="#billing" node-invoice="INFO" data-type="receivables" data-iskey="' . $v [2] . '" data-toggle="modal">' . $v [1] . '</a>';
  1148. }
  1149. array_push ( $irDetail, $html );
  1150. array_push ( $trainlist, $irDetail );
  1151. }
  1152. $trainlistJson = json_encode ( $trainlist );
  1153. return $trainlistJson;
  1154. }
  1155. /**
  1156. * 上传培训班发票
  1157. * @return string
  1158. */
  1159. function invoiceTrainingUpload() {
  1160. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  1161. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  1162. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  1163. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  1164. header ( "HTTP/1.1 500 Internal Server Error" );
  1165. echo "POST exceeded maximum allowed size.";
  1166. exit ( 0 );
  1167. }
  1168. // Settings
  1169. $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)
  1170. $upload_name = "Filedata";
  1171. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  1172. $extension_whitelist = array (
  1173. "doc",
  1174. "txt",
  1175. "jpg",
  1176. "gif",
  1177. "png"
  1178. ); // Allowed file extensions
  1179. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  1180. // Other variables
  1181. $MAX_FILENAME_LENGTH = 260;
  1182. $file_name = "";
  1183. $file_extension = "";
  1184. $uploadErrors = array (
  1185. 0 => "文件上传成功",
  1186. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  1187. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  1188. 3 => "上传的文件仅为部分文件",
  1189. 4 => "没有文件上传",
  1190. 6 => "缺少临时文件夹"
  1191. );
  1192. $nk = time ();
  1193. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  1194. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  1195. echo "文件无法保存.";
  1196. exit ( 0 );
  1197. }
  1198. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  1199. echo json_encode ( array (
  1200. 'filename' => $file_name,
  1201. 'id' => $nk
  1202. ) );
  1203. exit ( 0 );
  1204. }
  1205. /**
  1206. * 导入发票临时仓库
  1207. */
  1208. function invoiceStoreImport() {
  1209. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  1210. $trainingKey = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  1211. $path = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  1212. if ($path != "" && ! empty ( $trainingKey )) {
  1213. Doo::loadModel ( 'invoiceStore' );
  1214. Doo::loadModel ( 'staff' );
  1215. $staff = new staff ();
  1216. Doo::loadModel ( 'invoiceTraining' );
  1217. $invoiceTraining = new invoiceTraining ();
  1218. Doo::loadClass ( 'XDeode' );
  1219. $XDeode = new XDeode ( 5 );
  1220. $itid = $XDeode->decode ( $trainingKey );
  1221. // 培训班结算是否有和是否已经结算完成
  1222. Doo::loadModel ( 'receipt' );
  1223. $receipt = new receipt ();
  1224. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $itid );
  1225. if (! empty ( $receiptDetail )) {
  1226. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9)
  1227. die ( 'illegal request--status' );
  1228. }
  1229. $exlArray = $this->formatExcelToArrayTrain ( DOO::conf ()->SITE_PATH . "upload/invoiceTraining/" . $path );
  1230. $userName = $this->staff [0] ['username'];
  1231. $sDetail = $staff->getStaffByName ( $userName );
  1232. //print_r($exlArray);die;
  1233. // die('sdd');
  1234. // 可以优化
  1235. foreach ( $exlArray as $key => $value ) {
  1236. // 开票
  1237. $invoice = new invoiceStore ();
  1238. $invoice->trainId = $itid;
  1239. $invoice->invoiceType = 0;
  1240. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  1241. $invoice->invoiceType = 1;
  1242. elseif($value ['invoiceType'] == '电子'){
  1243. $invoice->invoiceType = 0;
  1244. $invoice->invoiceForm=1;
  1245. }
  1246. $invoice->invoiceQuantity = $value ['invoiceQuantity'];
  1247. $invoice->invoiceUnitPrice = $value ['invoiceUnitPrice'];
  1248. $invoice->invoicePrice = $value ['invoiceQuantity'] * $value ['invoiceUnitPrice'];
  1249. $invoice->invoiceTitle = $value ['invoiceTitle'];
  1250. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  1251. $invoice->invoiceCompany = $value ['invoiceTitle'];
  1252. $invoice->userName = $userName;
  1253. $invoice->sid = $sDetail ['sid'];
  1254. $invoice->cid = $sDetail ['cid'];
  1255. $invoice->categoryName = $sDetail ['category'];
  1256. $invoice->invoiceElement = $value ['invoiceElement'];
  1257. $invoice->remark = $value ['remark'];
  1258. // $invoice->date = $value ['date'];
  1259. // $invoice->printTime = $value ['date'];
  1260. $invoice->ipSource = 1;
  1261. $invoice->printStatus = 0;
  1262. $invoice->status = 0;
  1263. $invoice->postStatus = 1;
  1264. $invoice->untreadStatus = 0;
  1265. // $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1266. $invoice->TIN = $value ['TIN'];
  1267. $invoice->address = $value ['address'];
  1268. $invoice->phone = $value ['phone'];
  1269. $invoice->bank = $value ['bank'];
  1270. $invoice->bankAccount = $value ['bankAccount'];
  1271. $invoice->recipientsAddress = $value ['recipientsAddress'];
  1272. $invoice->recipients = $value ['recipients'];
  1273. $invoice->recipientsPhone = $value ['recipientsPhone'];
  1274. $invoice->electronicPhone = $value ['electronicPhone'];
  1275. $invoice->electronicEmail = $value ['electronicEmail'];
  1276. $iid = $invoice->insert ();
  1277. }
  1278. // 加入发票总数量
  1279. $item = array (
  1280. 'itid' => $itid,
  1281. 'invoiceTotal' => count ( $exlArray )
  1282. );
  1283. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1284. return '/invoiceTrainingDetail/' . $trainingKey . ".html";
  1285. }
  1286. echo 'no file';
  1287. }
  1288. /**
  1289. * 编辑仓库里的发票
  1290. */
  1291. function invoiceStoreEdit() {
  1292. Doo::loadClass ( 'XDeode' );
  1293. $XDeode = new XDeode ( 5 );
  1294. $iid = isset ( $this->params ['storeKey'] ) ? $this->params ['storeKey'] : "";
  1295. $iid = $XDeode->decode ( $iid );
  1296. if (! is_numeric ( $iid ))
  1297. die ( 'illegal request' );
  1298. Doo::loadModel ( 'invoiceStore' );
  1299. $invoiceStore = new invoiceStore ();
  1300. $invoiceDetail = $invoiceStore->getInvoiceStoreByIsid ( $iid );
  1301. // print_r($invoiceDetail);
  1302. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  1303. $this->data ['invoiceDetail'] = $invoiceDetail;
  1304. $this->data ['memu'] = "invoice";
  1305. $this->data ['staff'] = $this->staff;
  1306. $this->data ['receiptMemu'] = 'invoiceTraining';
  1307. $this->render ( "/admin/invoiceStoreEdit", $this->data );
  1308. }
  1309. function invoiceStoreEditDo() {
  1310. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1311. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1312. Doo::loadModel ( 'invoiceStore' );
  1313. $invoice = new invoiceStore ();
  1314. Doo::loadClass ( 'XDeode' );
  1315. $XDeode = new XDeode ( 5 );
  1316. $iid = $XDeode->decode ( $storeKey );
  1317. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1318. die ( 'illegal request' );
  1319. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  1320. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  1321. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  1322. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  1323. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  1324. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  1325. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  1326. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  1327. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  1328. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  1329. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  1330. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  1331. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  1332. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  1333. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1334. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1335. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1336. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1337. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  1338. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  1339. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  1340. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  1341. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  1342. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  1343. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1344. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1345. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1346. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1347. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1348. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1349. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1350. $electronicPhone = $this->get_args ( 'electronicPhone' ) ? $this->get_args ( 'electronicPhone' ) : "";
  1351. $electronicEmail = $this->get_args ( 'electronicEmail' ) ? $this->get_args ( 'electronicEmail' ) : "";
  1352. $invoiceForm = $this->get_args ( 'invoiceForm' ) ? $this->get_args ( 'invoiceForm' ) : "";
  1353. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  1354. $cid = explode ( ':', $cid );
  1355. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  1356. $item = array (
  1357. 'isid' => $iid,
  1358. 'cid' => $cid [0],
  1359. 'categoryName' => $cid [1],
  1360. 'invoiceElement' => $invoiceElement,
  1361. 'invoiceQuantity' => $invoiceQuantity,
  1362. 'invoiceUnitPrice' => $invoiceUnitPrice,
  1363. 'invoicePrice' => $invoicePrice,
  1364. 'invoiceType' => $invoiceType,
  1365. 'doPost' => $doPost,
  1366. 'status' => 1,
  1367. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1368. 'remark' => $remark
  1369. );
  1370. if ($invoiceType == 0)
  1371. $item += array (
  1372. 'invoiceTitle' => $invoiceTitle,
  1373. 'TIN' => $TINT,
  1374. 'address' => $addressT,
  1375. 'phone' => $phoneT,
  1376. 'bank' => $bankT,
  1377. 'bankAccount' => $bankAccountT
  1378. );
  1379. else {
  1380. $item += array (
  1381. 'invoiceCompany' => $invoiceCompany,
  1382. 'TIN' => $TIN,
  1383. 'address' => $address,
  1384. 'phone' => $phone,
  1385. 'bank' => $bank,
  1386. 'bankAccount' => $bankAccount
  1387. );
  1388. }
  1389. if($invoiceForm=='paper'){
  1390. $item += array (
  1391. 'invoiceForm' => 0
  1392. );
  1393. }elseif($invoiceForm=='electronic'){
  1394. $item += array (
  1395. 'invoiceForm' => 1,
  1396. 'electronicPhone' => $electronicPhone,
  1397. 'electronicEmail' => $electronicEmail,
  1398. );
  1399. }
  1400. if ($doPost == 1) {
  1401. $mailList = array (
  1402. 'invoice' => 1,
  1403. 'mailItems' => $mailItems
  1404. );
  1405. if (! empty ( $softLock ))
  1406. $mailList += array (
  1407. 'softLock' => $softLockNum
  1408. );
  1409. else
  1410. $mailList += array (
  1411. 'softLock' => '0'
  1412. );
  1413. if (! empty ( $contract ))
  1414. $mailList += array (
  1415. 'contract' => $contractNum
  1416. );
  1417. else
  1418. $mailList += array (
  1419. 'contract' => '0'
  1420. );
  1421. if (! empty ( $instructions ))
  1422. $mailList += array (
  1423. 'instructions' => $instructionsNum
  1424. );
  1425. else
  1426. $mailList += array (
  1427. 'instructions' => '0'
  1428. );
  1429. if (! empty ( $remittance ))
  1430. $mailList += array (
  1431. 'remittance' => $remittance
  1432. );
  1433. else
  1434. $mailList += array (
  1435. 'remittance' => ''
  1436. );
  1437. $mailString = '发票x1,备注:' . $mailItems;
  1438. if (! empty ( $softLock ))
  1439. $mailString .= ',软件锁x' . $softLockNum;
  1440. if (! empty ( $contract ))
  1441. $mailString .= ',合同x' . $contractNum;
  1442. if (! empty ( $instructions ))
  1443. $mailString .= ',说明书x' . $instructionsNum;
  1444. if (! empty ( $remittance ))
  1445. $mailString .= ',汇款账号单';
  1446. $item += array (
  1447. 'recipients' => $recipients,
  1448. 'recipientsPhone' => $recipientsPhone,
  1449. 'recipientsAddress' => $recipientsAddress,
  1450. 'mailItems' => $mailString,
  1451. 'mailItemsJson' => json_encode ( $mailList )
  1452. );
  1453. }
  1454. $invoice->setInvoiceStoreByCondition ( $item );
  1455. }
  1456. if(!empty($invoiceForm)&&$invoiceForm=='electronic'){
  1457. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1458. }else{
  1459. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1460. }
  1461. }
  1462. /**
  1463. *
  1464. * @return string
  1465. */
  1466. function invoiceStoreDelete() {
  1467. Doo::loadClass ( 'XDeode' );
  1468. $XDeode = new XDeode ( 5 );
  1469. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1470. $iStoreKey = $this->get_args ( 'iStoreKey' ) ? $this->get_args ( 'iStoreKey' ) : 0;
  1471. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1472. $isid = $XDeode->decode ( $iStoreKey );
  1473. $itid = $XDeode->decode ( $trainKey );
  1474. if (! is_numeric ( $isid ))
  1475. die ( 'illegal request' );
  1476. Doo::loadModel ( 'invoiceStore' );
  1477. $invoiceStore = new invoiceStore ();
  1478. $invoiceStore->delete ( array (
  1479. 'where' => 'isid=' . $isid,
  1480. 'limit' => 1
  1481. ) );
  1482. Doo::loadModel ( 'invoiceTraining' );
  1483. $invoiceTraining = new invoiceTraining ();
  1484. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1485. $item = array (
  1486. 'itid' => $itid,
  1487. 'invoiceTotal' => $itDetail ['invoiceTotal'] - 1
  1488. );
  1489. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1490. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1491. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1492. }else{
  1493. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1494. }
  1495. }
  1496. /**
  1497. * 批量删除库里发票
  1498. */
  1499. function invoiceStoreBatchDelete() {
  1500. Doo::loadClass ( 'XDeode' );
  1501. $XDeode = new XDeode ( 5 );
  1502. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1503. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1504. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1505. if (empty ( $trainKey ) || empty ( $storeKey ))
  1506. die ( 'illegal request-IdKey' );
  1507. $tid = $XDeode->decode ( $trainKey );
  1508. if (! is_numeric ( $tid ) && ! empty ( $storeKey ))
  1509. die ( 'illegal request' );
  1510. Doo::loadModel ( 'invoiceStore' );
  1511. $isidKeyList = explode ( ',', $storeKey );
  1512. $isidList = array ();
  1513. foreach ( $isidKeyList as $value ) {
  1514. $isid = $XDeode->decode ( $value );
  1515. if (! empty ( $isid ) && is_numeric ( $isid ))
  1516. array_push ( $isidList, $isid );
  1517. }
  1518. $isidString = implode ( ',', $isidList );
  1519. $invoiceStore = new invoiceStore ();
  1520. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,apStatus' );
  1521. $isidList = array ();
  1522. foreach ( $isList as $key => $value ) {
  1523. if ($value ['apStatus'] == 0)
  1524. array_push ( $isidList, $value ['isid'] );
  1525. }
  1526. $isidString = implode ( ',', $isidList );
  1527. // print_r($isList);
  1528. // echo $isidString;
  1529. $invoiceStore = new invoiceStore ();
  1530. $invoiceStore->delete ( array (
  1531. 'where' => "isid in ( " . $isidString . ")",
  1532. 'asArray' => TRUE
  1533. ) );
  1534. Doo::loadModel ( 'invoiceTraining' );
  1535. $invoiceTraining = new invoiceTraining ();
  1536. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1537. $item = array (
  1538. 'itid' => $tid,
  1539. 'invoiceTotal' => $itDetail ['invoiceTotal'] - count ( $isidList )
  1540. );
  1541. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1542. // echo $tid;
  1543. // echo $storeKey;
  1544. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1545. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1546. }else{
  1547. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1548. }
  1549. }
  1550. function invoiceStoreBatchElectronicPhone(){
  1551. $electronicPhone = $this->get_args ( 'electronicPhone' ) ? $this->get_args ( 'electronicPhone' ) : '';
  1552. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1553. Doo::loadClass ( 'XDeode' );
  1554. $XDeode = new XDeode ( 5 );
  1555. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1556. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1557. if (empty ( $trainKey ) || empty ( $storeKey ))
  1558. die ( 'illegal request-IdKey' );
  1559. $isidKeyList = explode ( ',', $storeKey );
  1560. $isidList = array ();
  1561. foreach ( $isidKeyList as $value ) {
  1562. $isid = $XDeode->decode ( $value );
  1563. if (! empty ( $isid ) && is_numeric ( $isid ))
  1564. array_push ( $isidList, $isid );
  1565. }
  1566. $isidString = implode ( ',', $isidList );
  1567. $trainId = $XDeode->decode ( $trainKey );
  1568. if (! is_numeric ( $isid ))
  1569. die ( 'illegal request--isid' );
  1570. Doo::loadModel ( 'invoiceStore' );
  1571. $invoiceStore = new invoiceStore ();
  1572. $item = array (
  1573. 'electronicPhone' => $electronicPhone
  1574. );
  1575. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1576. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1577. }
  1578. function invoiceStoreBatchElectronicEmail(){
  1579. $electronicEmail = $this->get_args ( 'electronicEmail' ) ? $this->get_args ( 'electronicEmail' ) : '';
  1580. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1581. Doo::loadClass ( 'XDeode' );
  1582. $XDeode = new XDeode ( 5 );
  1583. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1584. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1585. if (empty ( $trainKey ) || empty ( $storeKey ))
  1586. die ( 'illegal request-IdKey' );
  1587. $isidKeyList = explode ( ',', $storeKey );
  1588. $isidList = array ();
  1589. foreach ( $isidKeyList as $value ) {
  1590. $isid = $XDeode->decode ( $value );
  1591. if (! empty ( $isid ) && is_numeric ( $isid ))
  1592. array_push ( $isidList, $isid );
  1593. }
  1594. $isidString = implode ( ',', $isidList );
  1595. $trainId = $XDeode->decode ( $trainKey );
  1596. if (! is_numeric ( $isid ))
  1597. die ( 'illegal request' );
  1598. Doo::loadModel ( 'invoiceStore' );
  1599. $invoiceStore = new invoiceStore ();
  1600. $item = array (
  1601. 'electronicEmail' => $electronicEmail
  1602. );
  1603. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1604. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1605. }
  1606. /**
  1607. * 仓库发票提交审批
  1608. * @return string
  1609. */
  1610. function invoiceStoreApproval() {
  1611. Doo::loadClass ( 'XDeode' );
  1612. $XDeode = new XDeode ( 5 );
  1613. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1614. $iStoreKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1615. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1616. $isid = $XDeode->decode ( $iStoreKey );
  1617. $trainId = $XDeode->decode ( $trainKey );
  1618. if (! is_numeric ( $isid ))
  1619. die ( 'illegal request' );
  1620. Doo::loadModel ( 'invoiceStore' );
  1621. Doo::loadModel ( 'invoice' );
  1622. $invoice = new invoice ();
  1623. // 加入限制必须填写入开票内容和邮寄物品
  1624. $invoiceStore = new invoiceStore ();
  1625. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid, 'isid,trainId ,invoiceElement,mailItemsJson,electronicPhone,electronicEmail' );
  1626. if (empty ( $isDetail ['invoiceElement'] ) || empty ( $isDetail ['mailItemsJson'] )) {
  1627. header ( 'Content-Type:text/html;charset=utf-8' );
  1628. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1629. }
  1630. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1631. if (empty ( $isDetail ['electronicPhone'] ) && empty ( $isDetail ['electronicEmail'] )) {
  1632. header ( 'Content-Type:text/html;charset=utf-8' );
  1633. die ( 'illegal request! 请设置电子开票的收件人手机或者邮箱' );
  1634. }
  1635. }
  1636. // 拷贝插入一条发票数据
  1637. $invoiceStore = new invoiceStore ();
  1638. $iid = $invoiceStore->setInvoiceStoreToApproval ( $isid );
  1639. $invoiceStore = new invoiceStore ();
  1640. $item = array (
  1641. 'isid' => $isid,
  1642. 'iid' => $iid,
  1643. 'apStatus' => 1
  1644. );
  1645. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1646. Doo::loadModel ( 'invoiceManage' );
  1647. $invoiceManage = new invoiceManage ();
  1648. Doo::loadModel ( 'invoiceOperationLog' );
  1649. $invoiceOperationLog = new invoiceOperationLog ();
  1650. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1651. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1652. $moldManage = array ();
  1653. foreach ( $invoiceManageList as $key => $value ) {
  1654. if ($value ['mold'] == '发票打印')
  1655. $moldManage [$value ['mold']] = $value ['staffList'];
  1656. elseif ($value ['mold'] == '发票邮寄')
  1657. $moldManage [$value ['mold']] = $value ['staffList'];
  1658. elseif ($value ['mold'] == '发票退票')
  1659. $moldManage [$value ['mold']] = $value ['staffList'];
  1660. }
  1661. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1662. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1663. $invoiceSerial="#FE" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1664. }else{
  1665. $invoiceSerial="#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1666. }
  1667. $item = array (
  1668. 'iid' => $iid,
  1669. 'isid' => $isid,
  1670. 'invoiceSerial' => $invoiceSerial,
  1671. 'date' => date ( "Y-m-d H:i:s" ),
  1672. 'status' => 1,
  1673. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1674. 'trainId' => $trainId,
  1675. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1676. 'moldManage' => json_encode ( $moldManage ),
  1677. 'settlementType' => 1,
  1678. 'pendingApprovals' => $pendingApprovalsSid
  1679. );
  1680. $invoice->setInvoiceByCondition ( $item );
  1681. Doo::loadModel ( 'invoiceTraining' );
  1682. $invoiceTraining = new invoiceTraining ();
  1683. $item = array (
  1684. 'itid' => $trainId,
  1685. 'submitStatus' => 1
  1686. );
  1687. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1688. $item = array (
  1689. 'date' => date ( "Y-m-d H:i:s" ),
  1690. 'operation' => "创建",
  1691. 'status' => 1,
  1692. 'img' => $this->staff [0] ['avatar'],
  1693. 'username' => $this->staff [0] ['username'],
  1694. 'uid' => $this->staff [0] ['sid'],
  1695. 'category' => $this->staff [0] ['category'],
  1696. 'iid' => $iid
  1697. );
  1698. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1699. $item = array (
  1700. 'date' => date ( "Y-m-d H:i:s" ),
  1701. 'operation' => "提交审批",
  1702. 'status' => 1,
  1703. 'img' => $this->staff [0] ['avatar'],
  1704. 'username' => $this->staff [0] ['username'],
  1705. 'uid' => $this->staff [0] ['sid'],
  1706. 'category' => $this->staff [0] ['category'],
  1707. 'iid' => $iid
  1708. );
  1709. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1710. Doo::loadModel ( 'staff' );
  1711. $staff = new staff ();
  1712. $username2 = $staff->getOne ( array (
  1713. 'select' => 'wxid',
  1714. 'where' => 'sid=' . $pendingApprovalsSid,
  1715. 'asArray' => TRUE
  1716. ) );
  1717. // 发送微信审批通知
  1718. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1719. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1720. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1721. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1722. }else{
  1723. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1724. }
  1725. }
  1726. /**
  1727. * 批量提交发票
  1728. * @return string
  1729. */
  1730. function invoiceStoreBatchApproval() {
  1731. Doo::loadClass ( 'XDeode' );
  1732. $XDeode = new XDeode ( 5 );
  1733. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1734. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1735. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : '';
  1736. if (empty ( $trainKey ) || empty ( $storeKey ))
  1737. die ( 'illegal request-IdKey' );
  1738. $trainId = $XDeode->decode ( $trainKey );
  1739. $isidKeyList = explode ( ',', $storeKey );
  1740. $isidList = array ();
  1741. foreach ( $isidKeyList as $value ) {
  1742. $isid = $XDeode->decode ( $value );
  1743. if (! empty ( $isid ) && is_numeric ( $isid ))
  1744. array_push ( $isidList, $isid );
  1745. }
  1746. $isidString = implode ( ',', $isidList );
  1747. if (! is_numeric ( $trainId ))
  1748. die ( 'illegal request' );
  1749. Doo::loadModel ( 'invoiceStore' );
  1750. Doo::loadModel ( 'invoice' );
  1751. // 判断哪些已经加入审批过
  1752. // 加入限制必须填写入开票内容和邮寄物品
  1753. $invoiceStore = new invoiceStore ();
  1754. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,trainId ,invoiceElement,mailItemsJson,electronicPhone,electronicEmail,invoiceForm' );
  1755. foreach ( $isList as $key => $value ) {
  1756. if (empty ( $value ['invoiceElement'] ) || empty ( $value ['mailItemsJson'] )) {
  1757. header ( 'Content-Type:text/html;charset=utf-8' );
  1758. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1759. }
  1760. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic' ){
  1761. $value ['electronicPhone']=trim($value ['electronicPhone']);
  1762. $value ['electronicEmail']=trim($value ['electronicEmail']);
  1763. if(empty ( $value ['electronicPhone'] )&&empty ( $value ['electronicEmail'] )){
  1764. header ( 'Content-Type:text/html;charset=utf-8' );
  1765. die ( 'illegal request! 请设置电子开票的收件人手机或者邮箱' );
  1766. }
  1767. }
  1768. }
  1769. // 拷贝插入一条发票数据
  1770. $invoiceStore = new invoiceStore ();
  1771. $invoiceStore->setInvoiceStoreBatchToApproval ( $isidString );
  1772. $invoiceStore = new invoiceStore ();
  1773. $item = array (
  1774. 'apStatus' => 1
  1775. );
  1776. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1777. // 获得正式发票ID
  1778. $invoice = new invoice ();
  1779. $iidList = $invoice->getInvoiceByIstoreid ( $isidString, 'iid,isid' );
  1780. $sqlList = array ();
  1781. $iidString = '';
  1782. $iida = array ();
  1783. foreach ( $iidList as $key => $value ) {
  1784. $sqlList [$value ['isid']] = $value ['iid'];
  1785. array_push ( $iida, $value ['iid'] );
  1786. }
  1787. $iidString = implode ( ',', $iida );
  1788. $ids = implode ( ',', array_keys ( $sqlList ) );
  1789. $sql = "UPDATE CLD_invoiceStore SET iid = CASE isid ";
  1790. foreach ( $sqlList as $id => $ordinal ) {
  1791. $sql .= sprintf ( "WHEN %d THEN %d ", $id, $ordinal );
  1792. }
  1793. $sql .= "END WHERE isid IN ($ids)";
  1794. $invoiceStore = new invoiceStore ();
  1795. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1796. Doo::loadModel ( 'invoiceManage' );
  1797. $invoiceManage = new invoiceManage ();
  1798. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1799. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1800. $moldManage = array ();
  1801. foreach ( $invoiceManageList as $key => $value ) {
  1802. if ($value ['mold'] == '发票打印')
  1803. $moldManage [$value ['mold']] = $value ['staffList'];
  1804. elseif ($value ['mold'] == '发票邮寄')
  1805. $moldManage [$value ['mold']] = $value ['staffList'];
  1806. elseif ($value ['mold'] == '发票退票')
  1807. $moldManage [$value ['mold']] = $value ['staffList'];
  1808. }
  1809. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1810. // 批量更新发票信息
  1811. $item = array (
  1812. 'date' => date ( "Y-m-d H:i:s" ),
  1813. 'status' => 1,
  1814. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1815. 'trainId' => $trainId,
  1816. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1817. 'moldManage' => json_encode ( $moldManage ),
  1818. 'settlementType' => 1,
  1819. 'pendingApprovals' => $pendingApprovalsSid
  1820. );
  1821. $invoice = new invoice ();
  1822. $invoice->BatchInvoiceByCondition ( $item, $iidString );
  1823. // 批量更新发票中仓库isid
  1824. $sql = "UPDATE CLD_invoiceStore SET isid = CASE iid ";
  1825. foreach ( $sqlList as $isid => $iid ) {
  1826. $sql .= sprintf ( "WHEN %d THEN %d ", $iid, $isid );
  1827. }
  1828. $sql .= "END WHERE iid IN ($iidString)";
  1829. $invoice = new invoice ();
  1830. $invoice->UpdateBatchInvoice ( $sql );
  1831. // 批量更新发票序列号
  1832. $sqlList = array ();
  1833. foreach ( $iida as $value ) {
  1834. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1835. $sqlList [$value] = "#FE" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1836. }else{
  1837. $sqlList [$value] = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1838. }
  1839. }
  1840. $ids = implode ( ',', array_keys ( $sqlList ) );
  1841. $sql = "UPDATE CLD_invoice SET invoiceSerial = CASE iid ";
  1842. foreach ( $sqlList as $id => $ordinal ) {
  1843. $sql .= sprintf ( "WHEN %d THEN '%s' ", $id, $ordinal );
  1844. }
  1845. $sql .= "END WHERE iid IN ($ids)";
  1846. $invoiceStore = new invoiceStore ();
  1847. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1848. // 批量生产操作日志
  1849. Doo::loadModel ( 'invoiceOperationLog' );
  1850. $sqlList = array ();
  1851. foreach ( $iida as $key => $value ) {
  1852. $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 . '"),
  1853. ("' . 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 . '") ';
  1854. array_push ( $sqlList, $sql );
  1855. }
  1856. $iolSql = implode ( ',', $sqlList );
  1857. $sql = "INSERT INTO `CLD_invoiceOperationLog` (`date`, `operation`, `status`, `img`, `username`, `uid`, `category`, `iid`) VALUES " . $iolSql;
  1858. $invoiceOperationLog = new invoiceOperationLog ();
  1859. $invoiceOperationLog->setInvoiceOperationLogBySql ( $sql );
  1860. Doo::loadModel ( 'invoiceTraining' );
  1861. $invoiceTraining = new invoiceTraining ();
  1862. $item = array (
  1863. 'itid' => $trainId,
  1864. 'submitStatus' => 1
  1865. );
  1866. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1867. Doo::loadModel ( 'staff' );
  1868. $staff = new staff ();
  1869. $username2 = $staff->getOne ( array (
  1870. 'select' => 'wxid',
  1871. 'where' => 'sid=' . $pendingApprovalsSid,
  1872. 'asArray' => TRUE
  1873. ) );
  1874. // 发送微信审批通知
  1875. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1876. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1877. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1878. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1879. }else{
  1880. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1881. }
  1882. }
  1883. /**
  1884. */
  1885. function invoiceStoreMailItemSet() {
  1886. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1887. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1888. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1889. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1890. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1891. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1892. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1893. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1894. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1895. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1896. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1897. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1898. Doo::loadClass ( 'XDeode' );
  1899. $XDeode = new XDeode ( 5 );
  1900. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1901. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1902. $isid = $XDeode->decode ( $storeKey );
  1903. $trainId = $XDeode->decode ( $trainKey );
  1904. if (! is_numeric ( $isid ))
  1905. die ( 'illegal request' );
  1906. Doo::loadModel ( 'invoiceStore' );
  1907. $invoiceStore = new invoiceStore ();
  1908. $mailList = array (
  1909. 'mailItems' => $mailItems
  1910. );
  1911. $mailString = '发票x1,备注:' . $mailItems;
  1912. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1913. $mailString = '备注:' . $mailItems;
  1914. }else{
  1915. $mailList += array (
  1916. 'invoice' => 1,
  1917. );
  1918. }
  1919. if (! empty ( $softLock ))
  1920. $mailList += array (
  1921. 'softLock' => $softLockNum
  1922. );
  1923. else
  1924. $mailList += array (
  1925. 'softLock' => 0
  1926. );
  1927. if (! empty ( $contract ))
  1928. $mailList += array (
  1929. 'contract' => $contractNum
  1930. );
  1931. else
  1932. $mailList += array (
  1933. 'contract' => 0
  1934. );
  1935. if (! empty ( $instructions ))
  1936. $mailList += array (
  1937. 'instructions' => $instructionsNum
  1938. );
  1939. else
  1940. $mailList += array (
  1941. 'instructions' => 0
  1942. );
  1943. if (! empty ( $remittance ))
  1944. $mailList += array (
  1945. 'remittance' => $remittance
  1946. );
  1947. else
  1948. $mailList += array (
  1949. 'remittance' => ''
  1950. );
  1951. if (! empty ( $softLock ))
  1952. $mailString .= ',软件锁x' . $softLockNum;
  1953. if (! empty ( $contract ))
  1954. $mailString .= ',合同x' . $contractNum;
  1955. if (! empty ( $instructions ))
  1956. $mailString .= ',说明书x' . $instructionsNum;
  1957. if (! empty ( $remittance ))
  1958. $mailString .= ',汇款账号单';
  1959. $item = array (
  1960. 'isid' => $isid,
  1961. 'doPost' => 1,
  1962. 'mailItems' => $mailString,
  1963. 'mailItemsJson' => json_encode ( $mailList )
  1964. );
  1965. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1966. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1967. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1968. }else{
  1969. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1970. }
  1971. }
  1972. /**
  1973. * 批量设置邮寄物品
  1974. */
  1975. function invoiceStoreBatchMailItemSet() {
  1976. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1977. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1978. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1979. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1980. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1981. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1982. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1983. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1984. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1985. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1986. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1987. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1988. Doo::loadClass ( 'XDeode' );
  1989. $XDeode = new XDeode ( 5 );
  1990. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1991. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1992. if (empty ( $trainKey ) || empty ( $storeKey ))
  1993. die ( 'illegal request-IdKey' );
  1994. $isidKeyList = explode ( ',', $storeKey );
  1995. $isidList = array ();
  1996. foreach ( $isidKeyList as $value ) {
  1997. $isid = $XDeode->decode ( $value );
  1998. if (! empty ( $isid ) && is_numeric ( $isid ))
  1999. array_push ( $isidList, $isid );
  2000. }
  2001. $isidString = implode ( ',', $isidList );
  2002. $trainId = $XDeode->decode ( $trainKey );
  2003. if (! is_numeric ( $isid ))
  2004. die ( 'illegal request' );
  2005. Doo::loadModel ( 'invoiceStore' );
  2006. $invoiceStore = new invoiceStore ();
  2007. $mailList = array (
  2008. 'mailItems' => $mailItems
  2009. );
  2010. $mailString = '发票x1,备注:' . $mailItems;
  2011. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  2012. $mailString = '备注:' . $mailItems;
  2013. }else{
  2014. $mailList += array (
  2015. 'invoice' => 1,
  2016. );
  2017. }
  2018. if (! empty ( $softLock ))
  2019. $mailList += array (
  2020. 'softLock' => $softLockNum
  2021. );
  2022. else
  2023. $mailList += array (
  2024. 'softLock' => 0
  2025. );
  2026. if (! empty ( $contract ))
  2027. $mailList += array (
  2028. 'contract' => $contractNum
  2029. );
  2030. else
  2031. $mailList += array (
  2032. 'contract' => 0
  2033. );
  2034. if (! empty ( $instructions ))
  2035. $mailList += array (
  2036. 'instructions' => $instructionsNum
  2037. );
  2038. else
  2039. $mailList += array (
  2040. 'instructions' => 0
  2041. );
  2042. if (! empty ( $remittance ))
  2043. $mailList += array (
  2044. 'remittance' => $remittance
  2045. );
  2046. else
  2047. $mailList += array (
  2048. 'remittance' => ''
  2049. );
  2050. if (! empty ( $softLock ))
  2051. $mailString .= ',软件锁x' . $softLockNum;
  2052. if (! empty ( $contract ))
  2053. $mailString .= ',合同x' . $contractNum;
  2054. if (! empty ( $instructions ))
  2055. $mailString .= ',说明书x' . $instructionsNum;
  2056. if (! empty ( $remittance ))
  2057. $mailString .= ',汇款账号单';
  2058. $item = array (
  2059. 'doPost' => 1,
  2060. 'mailItems' => $mailString,
  2061. 'mailItemsJson' => json_encode ( $mailList )
  2062. );
  2063. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  2064. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  2065. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  2066. }else{
  2067. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  2068. }
  2069. }
  2070. /**
  2071. * 废弃
  2072. */
  2073. function ajaxGetMailItemByIstore() {
  2074. Doo::loadClass ( 'XDeode' );
  2075. $XDeode = new XDeode ( 5 );
  2076. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  2077. $isid = $XDeode->decode ( $storeKey );
  2078. if (! is_numeric ( $isid ))
  2079. die ( 'illegal request' );
  2080. Doo::loadModel ( 'invoiceStore' );
  2081. $invoiceStore = new invoiceStore ();
  2082. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid );
  2083. $isDetail ['mailItemsJson'] = json_decode ( $isDetail ['mailItemsJson'], true );
  2084. echo json_encode ( $isDetail ['mailItemsJson'] );
  2085. exit ();
  2086. }
  2087. /**
  2088. * 终止开票
  2089. */
  2090. function invoiceDroppedDo() {
  2091. $droppedIidKey = $this->get_args ( 'droppedIidKey' ) ? $this->get_args ( 'droppedIidKey' ) : '';
  2092. Doo::loadModel ( 'invoice' );
  2093. $invoice = new invoice ();
  2094. Doo::loadModel ( 'invoiceOperationLog' );
  2095. $invoiceOperationLog = new invoiceOperationLog ();
  2096. $iid = $invoice->authcode ( $droppedIidKey );
  2097. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2098. die ( 'illegal request' );
  2099. $item = array (
  2100. 'iid' => $iid,
  2101. 'status' => 4,
  2102. 'updateTime' => date ( "Y-m-d H:i:s" )
  2103. );
  2104. $invoice->setInvoiceByCondition ( $item );
  2105. $item = array (
  2106. 'date' => date ( "Y-m-d H:i:s" ),
  2107. 'operation' => '终止了开票',
  2108. 'status' => 4,
  2109. 'img' => $this->staff [0] ['avatar'],
  2110. 'username' => $this->staff [0] ['username'],
  2111. 'uid' => $this->staff [0] ['sid'],
  2112. 'category' => $this->staff [0] ['category'],
  2113. 'iid' => $iid
  2114. );
  2115. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2116. return "/invoice";
  2117. }
  2118. /**
  2119. * 更新退票的邮寄信息
  2120. */
  2121. function invoiceUntreadMailDo() {
  2122. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  2123. $untreadCompany = $this->get_args ( 'untreadCompany' ) ? $this->get_args ( 'untreadCompany' ) : "";
  2124. $untreadNumber = $this->get_args ( 'untreadNumber' ) ? $this->get_args ( 'untreadNumber' ) : "";
  2125. $untreadItems = $this->get_args ( 'untreadItems' ) ? $this->get_args ( 'untreadItems' ) : "";
  2126. Doo::loadModel ( 'invoice' );
  2127. $invoice = new invoice ();
  2128. $iid = $invoice->authcode ( $untreadIidKey );
  2129. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2130. die ( 'illegal request' );
  2131. $item = array (
  2132. 'iid' => $iid,
  2133. 'untreadCompany' => $untreadCompany,
  2134. 'untreadNumber' => $untreadNumber,
  2135. 'untreadItems' => $untreadItems
  2136. );
  2137. $invoice->setInvoiceByCondition ( $item );
  2138. return "/invoice";
  2139. }
  2140. /**
  2141. * 申请退票 --
  2142. */
  2143. function invoiceUntreadDo() {
  2144. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  2145. $untreadReason = $this->get_args ( 'untreadReason' ) ? $this->get_args ( 'untreadReason' ) : "";
  2146. $untreadPost = $this->get_args ( 'untreadPost' ) ? $this->get_args ( 'untreadPost' ) : 0;
  2147. Doo::loadModel ( 'invoice' );
  2148. $invoice = new invoice ();
  2149. Doo::loadModel ( 'invoiceOperationLog' );
  2150. $invoiceOperationLog = new invoiceOperationLog ();
  2151. Doo::loadModel ( 'invoiceReceivables' );
  2152. $invoiceReceivables = new invoiceReceivables ();
  2153. $iid = $invoice->authcode ( $untreadIidKey );
  2154. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2155. die ( 'illegal request' );
  2156. /*
  2157. * 需求变革 有绑定收款也可以退票 $lt = $invoiceReceivables->getInvoiceReceivablesByIid ( $untreadIidKey ); if (! empty ( $lt )) { header ( 'Content-Type:text/html;charset=utf-8' ); die ( '该发票有收款绑定,请先移除!' ); }
  2158. */
  2159. $item = array (
  2160. 'iid' => $iid,
  2161. 'untreadStatus' => 1,
  2162. 'untreadReason' => $untreadReason,
  2163. 'untreadPost' => $untreadPost,
  2164. 'updateTime' => date ( "Y-m-d H:i:s" )
  2165. );
  2166. $invoice->setInvoiceByCondition ( $item );
  2167. $item = array (
  2168. 'date' => date ( "Y-m-d H:i:s" ),
  2169. 'operation' => '申请退票',
  2170. 'status' => 7,
  2171. 'img' => $this->staff [0] ['avatar'],
  2172. 'username' => $this->staff [0] ['username'],
  2173. 'uid' => $this->staff [0] ['sid'],
  2174. 'category' => $this->staff [0] ['category'],
  2175. 'iid' => $iid
  2176. );
  2177. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2178. return "/invoice";
  2179. }
  2180. /**
  2181. * 删除已终止的开票
  2182. */
  2183. function invoiceDelDo() {
  2184. Doo::loadModel ( 'invoice' );
  2185. $invoice = new invoice ();
  2186. Doo::loadModel ( 'invoiceOperationLog' );
  2187. $invoiceOperationLog = new invoiceOperationLog ();
  2188. Doo::loadClass ( 'XDeode' );
  2189. $XDeode = new XDeode ( 5 );
  2190. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  2191. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  2192. $iid = $XDeode->decode ( $iid );
  2193. Doo::loadModel ( 'invoiceStore' );
  2194. $invoiceStore = new invoiceStore ();
  2195. if (! is_numeric ( $iid ))
  2196. die ( 'illegal request' );
  2197. $invoiceDetail = $invoice->getMyInvoice ( $sid, $iid );
  2198. if (empty ( $invoiceDetail ))
  2199. die ( 'illegal request' );
  2200. $item = array (
  2201. 'iid' => $iid,
  2202. 'isDelete' => 1,
  2203. 'updateTime' => date ( "Y-m-d H:i:s" )
  2204. );
  2205. $invoice->setInvoiceByCondition ( $item );
  2206. $item = array (
  2207. 'date' => date ( "Y-m-d H:i:s" ),
  2208. 'operation' => '删除了已终止的发票',
  2209. 'status' => 4,
  2210. 'img' => $this->staff [0] ['avatar'],
  2211. 'username' => $this->staff [0] ['username'],
  2212. 'uid' => $this->staff [0] ['sid'],
  2213. 'category' => $this->staff [0] ['category'],
  2214. 'iid' => $iid
  2215. );
  2216. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2217. // 删除培训班发票仓库里的发票
  2218. $invoiceStore->delInvoiceStoreByIsid ( $invoiceDetail ['isid'] );
  2219. return "/invoice";
  2220. }
  2221. /**
  2222. */
  2223. function invoiceApproval() {
  2224. Doo::loadModel ( 'invoice' );
  2225. $invoice = new invoice ();
  2226. Doo::loadClass ( 'XDeode' );
  2227. $XDeode = new XDeode ( 5 );
  2228. Doo::loadModel ( 'staff' );
  2229. $staff = new staff ();
  2230. $invoiceList = $invoice->find ( array (
  2231. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  2232. 'desc' => 'iid',
  2233. 'limit' => 10,
  2234. 'asArray' => true
  2235. ) );
  2236. foreach ( $invoiceList as $key => $value ) {
  2237. $invoiceList [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2238. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2239. if (! empty ( $lastApprover )) {
  2240. $lastApproverKey = array_keys ( $lastApprover );
  2241. $lastApprover = end ( $lastApprover );
  2242. $staffDetail = $staff->getOne ( array (
  2243. 'where' => 'sid=' . end ( $lastApproverKey ),
  2244. 'asArray' => true
  2245. ) );
  2246. $lastApprover ['username'] = $staffDetail ['username'];
  2247. }
  2248. $invoiceList [$key] ['lastApprover'] = $lastApprover;
  2249. }
  2250. $ilist = $invoice->getInvoiceByProcessStatus ();
  2251. foreach ( $ilist as $key => $value ) {
  2252. $ilist [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2253. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2254. if (! empty ( $lastApprover )) {
  2255. $lastApproverKey = array_keys ( $lastApprover );
  2256. $lastApprover = end ( $lastApprover );
  2257. $staffDetail = $staff->getOne ( array (
  2258. 'where' => 'sid=' . end ( $lastApproverKey ),
  2259. 'asArray' => true
  2260. ) );
  2261. $lastApprover ['username'] = $staffDetail ['username'];
  2262. }
  2263. $ilist [$key] ['lastApprover'] = $lastApprover;
  2264. }
  2265. // print_r($ilist);
  2266. $this->data ['invoiceList'] = $invoiceList;
  2267. $this->data ['ilist'] = $ilist;
  2268. $this->data ['memu'] = "invoice";
  2269. $this->data ['staff'] = $this->staff;
  2270. $this->data ['receiptMemu'] = 'invoiceApproval';
  2271. $this->render ( "/admin/invoiceApproval", $this->data );
  2272. }
  2273. function invoiceDetail() {
  2274. Doo::loadClass ( 'XDeode' );
  2275. $XDeode = new XDeode ( 5 );
  2276. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  2277. $iid = $XDeode->decode ( $iid );
  2278. if (! is_numeric ( $iid ))
  2279. die ( 'illegal request' );
  2280. Doo::loadModel ( 'invoice' );
  2281. $invoice = new invoice ();
  2282. Doo::loadModel ( 'invoiceOperationLog' );
  2283. $invoiceOperationLog = new invoiceOperationLog ();
  2284. $invoiceDetail = $invoice->getOne ( array (
  2285. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'] . ' and iid=' . $iid,
  2286. 'asArray' => true
  2287. ) );
  2288. if (empty ( $invoiceDetail ))
  2289. die ( 'illegal request' );
  2290. if ($invoiceDetail ['settlementType'] == 1) {
  2291. Doo::loadModel ( 'invoiceTraining' );
  2292. $invoiceTraining = new invoiceTraining ();
  2293. $invoiceDetail ['invoiceTraining'] = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceDetail ['trainId'] );
  2294. }
  2295. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  2296. $this->data ['invoiceDetail'] = $invoiceDetail;
  2297. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  2298. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  2299. $this->data ['memu'] = "invoice";
  2300. $this->data ['staff'] = $this->staff;
  2301. $this->data ['receiptMemu'] = 'invoiceApproval';
  2302. $this->render ( "/admin/invoiceApprovalDetail", $this->data );
  2303. }
  2304. /**
  2305. * 对发票进行审批,其中操作有终止,退回,同意动作。操作成功并记录下操作日志
  2306. *
  2307. * @since 1.0.0
  2308. * @var integer iid 开票ID 已加密
  2309. * @var integer status 发票审批状态
  2310. * @var integer opintion 审批发票的意见
  2311. * @return string 如操作成功返回审批首页
  2312. */
  2313. function invoiceApprovalDo() {
  2314. Doo::loadModel ( 'invoice' );
  2315. $invoice = new invoice ();
  2316. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2317. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  2318. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  2319. $divApproval = $this->get_args ( 'divApproval' ) ? $this->get_args ( 'divApproval' ) : "";
  2320. $iid = $invoice->authcode ( $iid );
  2321. if (! is_numeric ( $iid ))
  2322. die ( 'illegal request' );
  2323. // && ! empty ( $opinion )
  2324. if (! empty ( $iid ) && ! empty ( $status )) {
  2325. if (! ($status == 2 || $status == 3 || $status == 4))
  2326. die ( 'illegal request' );
  2327. Doo::loadModel ( 'invoiceOperationLog' );
  2328. $invoiceOperationLog = new invoiceOperationLog ();
  2329. $invoiceDetail = $invoice->getOne ( array (
  2330. 'where' => 'status=1 and iid=' . $iid . ' and pendingApprovals=' . $this->staff [0] ['sid'],
  2331. 'asArray' => true
  2332. ) );
  2333. if (empty ( $invoiceDetail ))
  2334. die ( 'illegal request' );
  2335. $processApprovals = json_decode ( $invoiceDetail ['processApprovals'], true );
  2336. $invoiceManage = json_decode ( $invoiceDetail ['invoiceManage'], true );
  2337. if ($status == 3) {
  2338. $invoice->status = $status;
  2339. $item = array (
  2340. 'operation' => $opinion
  2341. );
  2342. } else {
  2343. if (empty ( $processApprovals )) {
  2344. $processApprovals = array (
  2345. $this->staff [0] ['sid'] => array (
  2346. 'date' => date ( "Y-m-d H:i:s" ),
  2347. 'opinion' => $opinion,
  2348. 'status' => $status
  2349. )
  2350. );
  2351. // var_dump(next($invoiceManage));
  2352. $nextInvoiceManage = next ( $invoiceManage );
  2353. // print_r($nextInvoiceManage);
  2354. if ($status != 4 && $nextInvoiceManage !== false)
  2355. $invoice->pendingApprovals = $nextInvoiceManage [0];
  2356. $invoice->processApprovals = json_encode ( $processApprovals );
  2357. // var_dump($invoice);
  2358. // print_r($invoiceManage);
  2359. } else {
  2360. $processApprovals [$this->staff [0] ['sid']] = array (
  2361. 'date' => date ( "Y-m-d H:i:s" ),
  2362. 'opinion' => $opinion,
  2363. 'status' => $status
  2364. );
  2365. $pendingApprovals = 0;
  2366. foreach ( $invoiceManage as $key => $value ) {
  2367. if ($value [0] == $this->staff [0] ['sid']) {
  2368. if (isset ( $invoiceManage [$key + 1] ))
  2369. $pendingApprovals = $invoiceManage [$key + 1] [0];
  2370. break;
  2371. }
  2372. }
  2373. if ($status != 4 && ! empty ( $pendingApprovals ))
  2374. $invoice->pendingApprovals = $pendingApprovals;
  2375. $invoice->processApprovals = json_encode ( $processApprovals );
  2376. }
  2377. $item = array (
  2378. 'operation' => $opinion
  2379. );
  2380. if (count ( $processApprovals ) == count ( $invoiceManage ) && $status != 4) {
  2381. $invoice->status = $status;
  2382. $invoice->pendingApprovals = 0;
  2383. $invoice->approvalTime = date ( "Y-m-d H:i:s" );
  2384. } elseif ($status == 4) {
  2385. $invoice->status = $status;
  2386. $item = array (
  2387. 'operation' => $opinion
  2388. );
  2389. }
  2390. }
  2391. $invoice->updateTime = date ( "Y-m-d H:i:s" );
  2392. $invoice->update ( array (
  2393. 'where' => 'iid=' . $iid
  2394. ) );
  2395. $item += array (
  2396. 'date' => date ( "Y-m-d H:i:s" ),
  2397. 'img' => $this->staff [0] ['avatar'],
  2398. 'username' => $this->staff [0] ['username'],
  2399. 'uid' => $this->staff [0] ['sid'],
  2400. 'category' => $this->staff [0] ['category'],
  2401. 'status' => $status,
  2402. 'iid' => $iid
  2403. );
  2404. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2405. if (empty ( $divApproval ))
  2406. return '/invoiceApproval';
  2407. else
  2408. return '/invoiceApprovalAchieve/PEND';
  2409. }
  2410. die ( 'illegal request' );
  2411. }
  2412. /**
  2413. * 展示需要打印的发票数据
  2414. *
  2415. * @since 1.0.0
  2416. */
  2417. function invoicePrint() {
  2418. Doo::loadModel ( 'invoice' );
  2419. $invoice = new invoice ();
  2420. Doo::loadClass ( 'XDeode' );
  2421. $XDeode = new XDeode ( 5 );
  2422. Doo::loadModel ( 'staff' );
  2423. $staff = new staff ();
  2424. $toPrint = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0 );
  2425. $printed = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 1 );
  2426. foreach ( $toPrint as $key => $value ) {
  2427. $toPrint [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2428. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2429. if (! empty ( $lastApprover )) {
  2430. $lastApproverKey = array_keys ( $lastApprover );
  2431. $lastApprover = end ( $lastApprover );
  2432. $staffDetail = $staff->getOne ( array (
  2433. 'where' => 'sid=' . end ( $lastApproverKey ),
  2434. 'asArray' => true
  2435. ) );
  2436. $lastApprover ['username'] = $staffDetail ['username'];
  2437. }
  2438. $toPrint [$key] ['lastApprover'] = $lastApprover;
  2439. }
  2440. foreach ( $printed as $key => $value ) {
  2441. $printed [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2442. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2443. if (! empty ( $lastApprover )) {
  2444. $lastApproverKey = array_keys ( $lastApprover );
  2445. $lastApprover = end ( $lastApprover );
  2446. $staffDetail = $staff->getOne ( array (
  2447. 'where' => 'sid=' . end ( $lastApproverKey ),
  2448. 'asArray' => true
  2449. ) );
  2450. $lastApprover ['username'] = $staffDetail ['username'];
  2451. }
  2452. $printed [$key] ['lastApprover'] = $lastApprover;
  2453. }
  2454. $this->data ['printed'] = $printed;
  2455. $this->data ['toPrint'] = $toPrint;
  2456. $this->data ['memu'] = "invoice";
  2457. $this->data ['staff'] = $this->staff;
  2458. $this->data ['receiptMemu'] = 'invoicePrint';
  2459. $this->render ( "/admin/invoicePrint", $this->data );
  2460. }
  2461. /**
  2462. * 展示发票打印的详情页面
  2463. *
  2464. * @since 1.0.0
  2465. */
  2466. function invoicePrintDetail() {
  2467. Doo::loadClass ( 'XDeode' );
  2468. $XDeode = new XDeode ( 5 );
  2469. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  2470. $iid = $XDeode->decode ( $iid );
  2471. if (! is_numeric ( $iid ))
  2472. die ( 'illegal request' );
  2473. Doo::loadModel ( 'invoice' );
  2474. $invoice = new invoice ();
  2475. Doo::loadModel ( 'invoiceOperationLog' );
  2476. $invoiceOperationLog = new invoiceOperationLog ();
  2477. Doo::loadModel ( 'invoicePaper' );
  2478. $invoicePaper = new invoicePaper ();
  2479. $invoiceDetail = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0, $iid );
  2480. if (empty ( $invoiceDetail ))
  2481. die ( 'illegal request' );
  2482. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $invoiceDetail ['invoiceType'],$invoiceDetail['invoiceForm'] );
  2483. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  2484. if ($invoiceDetail ['settlementType'] == 1) {
  2485. Doo::loadModel ( 'invoiceTraining' );
  2486. $invoiceTraining = new invoiceTraining ();
  2487. $invoiceDetail ['invoiceTraining'] = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceDetail ['trainId'] );
  2488. }
  2489. $this->data ['invoicePaperList'] = $invoicePaperList;
  2490. $this->data ['invoiceDetail'] = $invoiceDetail;
  2491. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  2492. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  2493. $this->data ['memu'] = "invoice";
  2494. $this->data ['staff'] = $this->staff;
  2495. $this->data ['receiptMemu'] = 'invoicePrint';
  2496. $this->render ( "/admin/invoicePrintDetail", $this->data );
  2497. }
  2498. /**
  2499. * 所有待打印 发票
  2500. */
  2501. function invoicePrintStayAchieve() {
  2502. Doo::loadModel ( 'invoice' );
  2503. $invoice = new invoice ();
  2504. Doo::loadClass ( 'XDeode' );
  2505. $XDeode = new XDeode ( 5 );
  2506. Doo::loadModel ( 'staff' );
  2507. $staff = new staff ();
  2508. $MebSea = $this->get_args ( 'MebSea' ) ? urldecode ( $this->get_args ( 'MebSea' ) ) : "";
  2509. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  2510. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  2511. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  2512. Doo::loadModel ( 'invoiceTraining' );
  2513. $invoiceTraining = new invoiceTraining ();
  2514. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  2515. $page_size = 12;
  2516. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2517. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : "ALL";
  2518. // $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : "ALL";
  2519. $get = "/" . $status;
  2520. $con = ' and status=2 ';
  2521. if ($status == 'TOPRINT')
  2522. $con = ' and status=2 and printStatus=0 ';
  2523. elseif ($status == 'PRINTED')
  2524. $con = ' and status=2 and printStatus=1';
  2525. if ($invoiceType == 'ORDINARY')
  2526. $con .= ' and invoiceType=0 ';
  2527. elseif ($invoiceType == 'SPECIAL')
  2528. $con .= ' and invoiceType=1 ';
  2529. if ($invoiceTrain == 'ORDINARY')
  2530. $con .= ' and trainId=0 ';
  2531. elseif ($invoiceTrain == 'TRAIN')
  2532. $con .= ' and trainId!=0 ';
  2533. if ($invoiceTrainName != 'ALL') {
  2534. $trainId = $XDeode->decode ( $invoiceTrainName );
  2535. if (is_numeric ( $trainId ))
  2536. $con .= ' and trainId =' . $trainId;
  2537. }
  2538. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2539. $dateArr = explode ( ':', $date );
  2540. $D1 = '';
  2541. $D2 = '';
  2542. if (! empty ( $date )) {
  2543. $D1 = $dateArr [0];
  2544. $D2 = $dateArr [1];
  2545. }
  2546. if (! empty ( $D1 ) && ! empty ( $D2 ) && ! empty ( $date ))
  2547. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2548. if (! empty ( $MebSea )) {
  2549. $con .= ' and ( invoiceNo like "%' . $MebSea . '%" or invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  2550. }
  2551. $pageinfo ['page'] = array (
  2552. 'previous' => ''
  2553. );
  2554. $get .= "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&invoiceType=" . urlencode ( $invoiceType ) . "&invoiceTrain=" . urlencode ( $invoiceTrain ) . "";
  2555. $sql = " (untreadStatus=0 or untreadStatus=3) and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  2556. $action = "invoicePrintStayAchieve";
  2557. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2558. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2559. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  2560. $this->data ['trainList'] = $trainList;
  2561. $this->data ['invoiceType'] = $invoiceType;
  2562. $this->data ['invoiceTrain'] = $invoiceTrain;
  2563. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  2564. $this->data ['MebSeaEn'] = $MebSea;
  2565. $this->data ['MebSea'] = urlencode ( $MebSea );
  2566. $this->data ['get'] = $get;
  2567. $this->data ['page'] = $pageinfo;
  2568. $this->data ['date'] = $date;
  2569. $this->data ['status'] = $status;
  2570. $this->data ['invoiceType'] = $invoiceType;
  2571. $this->data ['memu'] = "invoice";
  2572. $this->data ['staff'] = $this->staff;
  2573. foreach ( $list as $key => $value ) {
  2574. $list [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2575. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2576. if (! empty ( $lastApprover )) {
  2577. $lastApproverKey = array_keys ( $lastApprover );
  2578. $lastApprover = end ( $lastApprover );
  2579. $staffDetail = $staff->getOne ( array (
  2580. 'where' => 'sid=' . end ( $lastApproverKey ),
  2581. 'asArray' => true
  2582. ) );
  2583. $lastApprover ['username'] = $staffDetail ['username'];
  2584. }
  2585. $list [$key] ['lastApprover'] = $lastApprover;
  2586. }
  2587. $this->data ['receiptMemu'] = 'invoicePrint';
  2588. $this->data ['list'] = $list;
  2589. $this->render ( "/admin/invoicePrintStayAchieve", $this->data );
  2590. }
  2591. /**
  2592. * 填写票号并完成打印
  2593. * @since 1.0.0
  2594. */
  2595. function invoicePrintDo() {
  2596. Doo::loadModel ( 'invoice' );
  2597. $invoice = new invoice ();
  2598. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2599. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  2600. $invoicePrintType = $this->get_args ( 'invoicePrintType' ) ? $this->get_args ( 'invoicePrintType' ) : "";
  2601. $iid = $invoice->authcode ( $iid );
  2602. if (! is_numeric ( $iid ))
  2603. die ( 'illegal request-iid' );
  2604. if (! empty ( $iid ) && ! empty ( $invoiceNo )) {
  2605. Doo::loadModel ( 'invoiceOperationLog' );
  2606. $invoiceOperationLog = new invoiceOperationLog ();
  2607. Doo::loadModel ( 'invoiceStatistics' );
  2608. $invoiceStatistics = new invoiceStatistics ();
  2609. $XDeode = new XDeode ( 5 );
  2610. Doo::loadModel ( 'invoicePaper' );
  2611. $invoicePaper = new invoicePaper ();
  2612. $invoicePrintDetail = $invoice->getInvoiceByPrint ( $iid );
  2613. if (empty ( $invoicePrintDetail ))
  2614. die ( 'illegal request-data_empty' );
  2615. //
  2616. $ipid = $XDeode->decode ( $invoiceNo );
  2617. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  2618. if (empty ( $paperDetail ))
  2619. die ( 'illegal request-paper_empty' );
  2620. $invoicePaper = new invoicePaper ();
  2621. $item = array (
  2622. 'iid' => $iid,
  2623. 'ipid' => $ipid
  2624. );
  2625. $invoicePaper->setInvoicePaperByCondition ( $item );
  2626. $item = array (
  2627. 'iid' => $iid,
  2628. 'printStatus' => 1,
  2629. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2630. 'printer' => $this->staff [0] ['username'],
  2631. 'printTime' => date ( "Y-m-d H:i:s" ),
  2632. 'invoiceNo' => $paperDetail ['invoiceNo']
  2633. );
  2634. $invoice->setInvoiceByCondition ( $item );
  2635. $item = array (
  2636. 'date' => date ( "Y-m-d H:i:s" ),
  2637. 'operation' => '打印发票号:' . $paperDetail ['invoiceNo'],
  2638. 'status' => 5,
  2639. 'img' => $this->staff [0] ['avatar'],
  2640. 'username' => $this->staff [0] ['username'],
  2641. 'uid' => $this->staff [0] ['sid'],
  2642. 'category' => $this->staff [0] ['category'],
  2643. 'iid' => $iid
  2644. );
  2645. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2646. // 去统计--负票不汇总
  2647. if ($invoicePrintDetail ['untreadStatus'] != 4) {
  2648. $item = array (
  2649. 'date' => date ( "Y-m-d H:i:s" ),
  2650. 'priceClass' => 1,
  2651. 'cid' => $invoicePrintDetail ['cid'],
  2652. 'staff' => $invoicePrintDetail ['sid'],
  2653. 'invoicePrice' => $invoicePrintDetail ['invoicePrice']
  2654. );
  2655. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2656. }
  2657. // 发送通知信息到微信-去除
  2658. // $this->setWXMsg($iid,'PRINT');
  2659. // 发票信息库
  2660. $this->autoUpdateInvoiceInfoBase ( $invoicePrintDetail );
  2661. // 申请人获取微信通知
  2662. Doo::loadModel ( 'staff' );
  2663. $staff = new staff ();
  2664. Doo::loadClass ( 'XDeode' );
  2665. $XDeode = new XDeode ( 5 );
  2666. $username2 = $staff->getOne ( array (
  2667. 'select' => 'wxid',
  2668. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2669. 'asArray' => TRUE
  2670. ) );
  2671. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '完成打印';
  2672. $msg = '';
  2673. $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/' . $XDeode->encode ( $invoicePrintDetail ['iid'] ) . '.html';
  2674. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2675. if (empty ( $invoicePrintType ))
  2676. return "/invoicePrint";
  2677. else
  2678. return "/invoicePrintStayAchieve";
  2679. }
  2680. }
  2681. /**
  2682. * 需要邮寄的发票
  2683. * @since 1.0.0
  2684. */
  2685. function invoicePost() {
  2686. Doo::loadModel ( 'invoice' );
  2687. $invoice = new invoice ();
  2688. Doo::loadModel ( 'express' );
  2689. $express = new express ();
  2690. $invoicePost = $invoice->getPostByInvoice ();
  2691. $invoicePosted = $invoice->getPostByInvoice ( 1 );
  2692. $expressList = $express->getExpressByAll ();
  2693. $invoicePostExpress = "";
  2694. if (isset ( $_COOKIE ["invoicePostExpress"] ))
  2695. $invoicePostExpress = $_COOKIE ["invoicePostExpress"];
  2696. $this->data ['invoicePostExpress'] = $invoicePostExpress;
  2697. $this->data ['expressList'] = $expressList;
  2698. $this->data ['invoicePost'] = $invoicePost;
  2699. $this->data ['invoicePosted'] = $invoicePosted;
  2700. $this->data ['memu'] = "invoice";
  2701. $this->data ['staff'] = $this->staff;
  2702. $this->data ['receiptMemu'] = 'invoicePost';
  2703. $this->render ( "/admin/invoicePost", $this->data );
  2704. }
  2705. /**
  2706. * 添加发票邮寄信息
  2707. */
  2708. function invoiceExpressAddDo() {
  2709. Doo::loadModel ( 'invoice' );
  2710. $invoice = new invoice ();
  2711. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2712. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2713. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2714. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2715. $iid = $iid = $invoice->authcode ( $iid );
  2716. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2717. die ( 'illegal request' );
  2718. $invoicePrintDetail = $invoice->getInvoiceByIid ( $iid );
  2719. setcookie ( 'invoicePostExpress', $expressNumber );
  2720. $item = array (
  2721. 'iid' => $iid,
  2722. 'postStatus' => 1,
  2723. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2724. 'postTime' => date ( "Y-m-d H:i:s" ),
  2725. 'expressCompany' => $expressCompany,
  2726. 'expressNumber' => $expressNumber,
  2727. 'actualItems' => $actualItems,
  2728. 'poster' => $this->staff [0] ['username']
  2729. );
  2730. $invoice->setInvoiceByCondition ( $item );
  2731. // 微信通知-去掉
  2732. // $this->setWXMsg ( $iid );
  2733. Doo::loadModel ( 'staff' );
  2734. $staff = new staff ();
  2735. Doo::loadClass ( 'XDeode' );
  2736. $XDeode = new XDeode ( 5 );
  2737. $username2 = $staff->getOne ( array (
  2738. 'select' => 'wxid',
  2739. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2740. 'asArray' => TRUE
  2741. ) );
  2742. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '已邮寄';
  2743. $expCom = explode ( ":", $invoicePrintDetail ['expressCompany'] );
  2744. if (empty ( $expCom ))
  2745. $expCom [0] = '';
  2746. $msg = $expCom [0] . ':' . $invoicePrintDetail ['expressNumber'] . '';
  2747. $url = 'https://m.kuaidi100.com/result.jsp?nu=' . $invoicePrintDetail ['expressNumber'];
  2748. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2749. return '/invoicePost';
  2750. }
  2751. function invoiceExpressUpdateDo() {
  2752. Doo::loadModel ( 'invoice' );
  2753. $invoice = new invoice ();
  2754. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  2755. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2756. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2757. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2758. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2759. $iid = $invoice->authcode ( $iid );
  2760. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2761. die ( 'illegal request' );
  2762. $item = array (
  2763. 'iid' => $iid,
  2764. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2765. 'expressCompany' => $expressCompany,
  2766. 'expressNumber' => $expressNumber,
  2767. 'actualItems' => $actualItems,
  2768. 'poster' => $this->staff [0] ['username']
  2769. );
  2770. $invoice->setInvoiceByCondition ( $item );
  2771. return $action;
  2772. }
  2773. /**
  2774. * 可退票管理
  2775. */
  2776. function invoiceUntreadIsAchieve() {
  2777. Doo::loadModel ( 'invoice' );
  2778. $invoice = new invoice ();
  2779. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2780. /*
  2781. * 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' => '' );
  2782. */
  2783. if (empty ( $MebSea )) {//
  2784. $con = ' and invoiceNo like "NULL" ';
  2785. } else {
  2786. $con = ' and (invoiceNo like "%' . $MebSea . '%" or invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  2787. }
  2788. // printStatus=1 and
  2789. $sql = " (untreadStatus=0 or untreadStatus=3) and status=2 and sid=" . $this->staff [0] ['sid'] . $con;
  2790. /*
  2791. * $action = "invoiceUntreadIsAchieve"; $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" ); $limit = $pageinfo ['lower'] . ',' . $page_size;
  2792. */
  2793. $limit = '0,20';
  2794. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2795. //print_r($list);
  2796. $this->data ['MebSeaEn'] = $MebSea;
  2797. /*
  2798. * $this->data ['get'] = $get; $this->data ['page'] = $pageinfo; $this->data ['date'] = $date;
  2799. */
  2800. $this->data ['list'] = $list;
  2801. $this->data ['memu'] = "invoice";
  2802. $this->data ['staff'] = $this->staff;
  2803. $this->data ['receiptMemu'] = 'invoice';
  2804. $this->render ( "/admin/invoiceUntreadIsAchieve", $this->data );
  2805. }
  2806. // 已经退票的发票
  2807. function invoiceUntreadED() {
  2808. Doo::loadModel ( 'invoice' );
  2809. $invoice = new invoice ();
  2810. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2811. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "";
  2812. Doo::loadClass ( 'XDeode' );
  2813. $XDeode = new XDeode ( 5 );
  2814. $page_size = 18;
  2815. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2816. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2817. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  2818. $dateArr = explode ( ':', $date );
  2819. $D1 = '';
  2820. $D2 = '';
  2821. if (! empty ( $date )) {
  2822. $D1 = $dateArr [0];
  2823. $D2 = $dateArr [1];
  2824. }
  2825. $con = '';
  2826. if (! empty ( $D1 ) && ! empty ( $D2 )) {
  2827. $con = ' and bindTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2828. }
  2829. // if ($date == 'MONTHO')
  2830. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  2831. // elseif ($date == 'MONTHT')
  2832. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  2833. // elseif ($date == 'MONTHY')
  2834. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  2835. if (! empty ( $MebSea )) {
  2836. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  2837. }
  2838. if ($invoiceType == 'ORDINARY') {
  2839. $con .= ' and invoiceType=0 ';
  2840. } elseif ($invoiceType == 'SPECIAL') {
  2841. $con .= ' and invoiceType=1 ';
  2842. }
  2843. $pageinfo ['page'] = array (
  2844. 'previous' => ''
  2845. );
  2846. // printStatus=1 and
  2847. $sql = " (untreadStatus=2 ) and status=2 and sid=" . $this->staff [0] ['sid'] . $con;
  2848. $action = "invoiceUntreadED";
  2849. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2850. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2851. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2852. // print_r($list);
  2853. $this->data ['MebSeaEn'] = $MebSea;
  2854. $this->data ['get'] = $get;
  2855. $this->data ['page'] = $pageinfo;
  2856. $this->data ['date'] = $date;
  2857. $this->data ['invoiceType'] = $invoiceType;
  2858. $this->data ['list'] = $list;
  2859. $this->data ['memu'] = "invoice";
  2860. $this->data ['staff'] = $this->staff;
  2861. $this->data ['receiptMemu'] = 'invoice';
  2862. $this->render ( "/admin/invoiceUntreadED", $this->data );
  2863. }
  2864. /**
  2865. * 退票处理页面
  2866. */
  2867. function invoiceUntread() {
  2868. Doo::loadModel ( 'invoice' );
  2869. $invoice = new invoice ();
  2870. $untreadInvoice = $invoice->getInvoiceByUntreadStatus ( 1, 0, 50 );
  2871. $establishedInvoice = $invoice->getInvoiceByUntreadStatus ( 2 );
  2872. //print_r($establishedInvoice);
  2873. // foreach ( $establishedInvoice as $key => $value ) {
  2874. // // months
  2875. // $lossDate = strtotime ( "+1 month", strtotime ( $value ['OperationLog'] ['date'] ) );
  2876. // $nowDate = strtotime ( 'now' );
  2877. // $establishedInvoice [$key] ['lossShow'] = false;
  2878. // if ($lossDate < $nowDate)
  2879. // $establishedInvoice [$key] ['lossShow'] = true;
  2880. // }
  2881. $this->data ['untreadInvoice'] = $untreadInvoice;
  2882. $this->data ['establishedInvoice'] = $establishedInvoice;
  2883. $this->data ['memu'] = "invoice";
  2884. $this->data ['staff'] = $this->staff;
  2885. $this->data ['receiptMemu'] = 'invoiceUntread';
  2886. $this->render ( "/admin/invoiceUntread", $this->data );
  2887. }
  2888. /**
  2889. * 确认收到退回的发票,开票状态为退回 //收款状态解绑,公司统计扣除入账额度
  2890. */
  2891. function invoiceUntreadEstablishedDo() {
  2892. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  2893. Doo::loadModel ( 'invoice' );
  2894. $invoice = new invoice ();
  2895. Doo::loadModel ( 'invoiceOperationLog' );
  2896. $invoiceOperationLog = new invoiceOperationLog ();
  2897. Doo::loadModel ( 'invoiceReceivables' );
  2898. Doo::loadModel ( 'invoiceStatistics' );
  2899. $iid = $invoice->authcode ( $untreadIidKey );
  2900. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2901. die ( 'illegal request' );
  2902. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  2903. if ($invoiceDetails ['untreadStatus'] != 1)
  2904. die ( 'illegal request untreadStatus error !=1' );
  2905. $item = array (
  2906. 'iid' => $iid,
  2907. // 'irid'=>'',
  2908. 'untreadStatus' => 2,
  2909. 'untreadTime'=>date ( "Y-m-d H:i:s" ) ,
  2910. 'updateTime' => date ( "Y-m-d H:i:s" )
  2911. );
  2912. $invoice->setInvoiceByCondition ( $item );
  2913. $item = array (
  2914. 'date' => date ( "Y-m-d H:i:s" ),
  2915. 'operation' => '已确认退票',
  2916. 'status' => 6,
  2917. 'img' => $this->staff [0] ['avatar'],
  2918. 'username' => $this->staff [0] ['username'],
  2919. 'uid' => $this->staff [0] ['sid'],
  2920. 'category' => $this->staff [0] ['category'],
  2921. 'iid' => $iid
  2922. );
  2923. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2924. // 收款解绑以及入账扣除 收款扣除
  2925. if (! empty ( $invoiceDetails ['irid'] )) {
  2926. $iridList = explode ( ',', $invoiceDetails ['irid'] );
  2927. foreach ( $iridList as $value ) {
  2928. $invoiceReceivables = new invoiceReceivables ();
  2929. $irDetails = $invoiceReceivables->getOne ( array (
  2930. 'where' => " irid=" . $value . ' and bindStatus=1',
  2931. 'asArray' => TRUE
  2932. ) );
  2933. $item = array (
  2934. 'irid' => $value,
  2935. 'bindStatus' => 0,
  2936. 'untreadStatus' => 1,
  2937. 'untreadStaff' => $invoiceDetails ['userName'],
  2938. 'unbundlingTime' => date ( "Y-m-d H:i:s" ),
  2939. 'iid' => 0
  2940. );
  2941. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2942. if (! empty ( $irDetails )) {
  2943. // 扣除入账
  2944. $invoiceStatistics = new invoiceStatistics ();
  2945. $item = array (
  2946. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2947. 'priceClass' => 3,
  2948. 'cid' => $invoiceDetails ['cid'],
  2949. 'staff' => $invoiceDetails ['sid'],
  2950. 'accountPrice' => - $irDetails ['receivablesPrice']
  2951. );
  2952. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2953. // 扣除收款
  2954. $invoiceStatistics = new invoiceStatistics ();
  2955. $item = array (
  2956. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2957. 'priceClass' => 2,
  2958. 'cid' => $invoiceDetails ['cid'],
  2959. 'staff' => $invoiceDetails ['sid'],
  2960. 'irid' => $irDetails ['irid'],
  2961. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  2962. );
  2963. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2964. }
  2965. // 解绑时删除收入流水
  2966. Doo::loadModel ( 'wasteBook' );
  2967. $wasteBook = new wasteBook ();
  2968. $wasteBook->delete ( array (
  2969. 'where' => 'dataID=' . $value . ' and accountType=7',
  2970. 'limit' => 1
  2971. ) );
  2972. }
  2973. }
  2974. return "/invoiceUntread";
  2975. }
  2976. function invoiceUntreadRecallDo() {
  2977. $iidKey = isset ( $this->params ['iidKey'] ) ? $this->params ['iidKey'] : "";
  2978. Doo::loadModel ( 'invoice' );
  2979. $invoice = new invoice ();
  2980. Doo::loadClass ( 'XDeode' );
  2981. $XDeode = new XDeode ( 5 );
  2982. Doo::loadModel ( 'invoiceOperationLog' );
  2983. $invoiceOperationLog = new invoiceOperationLog ();
  2984. $iid = $XDeode->decode ( $iidKey );
  2985. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  2986. if (empty ( $invoiceDetail )) {
  2987. die ( 'illegal request-DATANULL' );
  2988. }
  2989. $item = array (
  2990. 'iid' => $iid,
  2991. 'untreadStatus' => 0
  2992. );
  2993. $invoice->setInvoiceByCondition ( $item );
  2994. $item = array (
  2995. 'date' => date ( "Y-m-d H:i:s" ),
  2996. 'operation' => '撤回申请退票',
  2997. 'status' => 13,
  2998. 'img' => $this->staff [0] ['avatar'],
  2999. 'username' => $this->staff [0] ['username'],
  3000. 'uid' => $this->staff [0] ['sid'],
  3001. 'category' => $this->staff [0] ['category'],
  3002. 'iid' => $iid
  3003. );
  3004. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3005. return "/invoiceUntread";
  3006. }
  3007. /**
  3008. * 建立负票,关联原来发票
  3009. */
  3010. function invoiceLossDo() {
  3011. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  3012. if (! empty ( $iidKey )) {
  3013. Doo::loadClass ( 'XDeode' );
  3014. $XDeode = new XDeode ( 5 );
  3015. Doo::loadModel ( 'invoice' );
  3016. $invoice = new invoice ();
  3017. Doo::loadModel ( 'invoiceOperationLog' );
  3018. $invoiceOperationLog = new invoiceOperationLog ();
  3019. $iidKey = $XDeode->decode ( $iidKey );
  3020. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  3021. // 拷贝插入一条发票数据
  3022. $iid = $invoice->setInvoiceLoss ( $iidKey );
  3023. // 更新负票
  3024. $invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  3025. $invoice = new invoice ();
  3026. $item = array (
  3027. 'iid' => $iid,
  3028. 'sid' => $this->staff [0] ['sid'],
  3029. 'userName' => $this->staff [0] ['username'],
  3030. 'cid' => $this->staff [0] ['cid'],
  3031. 'categoryName' => $this->staff [0] ['category'],
  3032. 'invoiceQuantity' => - $invoiceDetail ['invoiceQuantity'],
  3033. 'invoicePrice' => - $invoiceDetail ['invoicePrice'],
  3034. 'invoiceSerial' => $invoiceSerial,
  3035. 'invoiceNo' => '',
  3036. 'printStatus' => 0,
  3037. 'untreadStatus' => 4,
  3038. // 关联发票号
  3039. 'lossIid' => $invoiceDetail ['iid']
  3040. );
  3041. $invoice->setInvoiceByCondition ( $item );
  3042. // 更新原发票
  3043. $invoice = new invoice ();
  3044. $item = array (
  3045. 'iid' => $invoiceDetail ['iid'],
  3046. 'lossIid' => $iid
  3047. );
  3048. $invoice->setInvoiceByCondition ( $item );
  3049. // 操作日志
  3050. $item = array (
  3051. 'date' => date ( "Y-m-d H:i:s" ),
  3052. 'operation' => "创建负票" . $invoiceSerial,
  3053. 'status' => 12,
  3054. 'img' => $this->staff [0] ['avatar'],
  3055. 'username' => $this->staff [0] ['username'],
  3056. 'uid' => $this->staff [0] ['sid'],
  3057. 'category' => $this->staff [0] ['category'],
  3058. 'iid' => $iid
  3059. );
  3060. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3061. // print_r($invoiceDetail);
  3062. // echo $iid;die;
  3063. }
  3064. return '/invoiceUntread';
  3065. }
  3066. /**
  3067. * 上传银行到账 收款文件
  3068. */
  3069. function invoiceReceivablesBankUpload() {
  3070. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  3071. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  3072. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  3073. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  3074. header ( "HTTP/1.1 500 Internal Server Error" );
  3075. echo "POST exceeded maximum allowed size.";
  3076. exit ( 0 );
  3077. }
  3078. // Settings
  3079. $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)
  3080. $upload_name = "Filedata";
  3081. $file_name = "";
  3082. $nk = time ();
  3083. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  3084. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  3085. echo "文件无法保存.";
  3086. exit ( 0 );
  3087. }
  3088. echo json_encode ( array (
  3089. 'filename' => $file_name,
  3090. 'id' => $nk
  3091. ) );
  3092. exit ( 0 );
  3093. }
  3094. /**
  3095. * 解析银行到账收款execl并导入库中
  3096. */
  3097. function invoiceReceivablesImport() {
  3098. $path = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  3099. if ($path != "") {
  3100. Doo::loadModel ( 'invoiceReceivables' );
  3101. $invoiceReceivables = new invoiceReceivables ();
  3102. Doo::loadClass ( 'invoice.func' );
  3103. Doo::loadModel ( 'invoiceROLog' );
  3104. $invoiceROLog = new invoiceROLog ();
  3105. Doo::loadModel ( 'invoiceStatistics' );
  3106. $invoiceStatistics = new invoiceStatistics ();
  3107. $exlArray = formatExcelToArrayBank ( DOO::conf ()->SITE_PATH . "upload/invoiceReceivablesBank/" . $path );
  3108. $bankBatchNumber = 'BBN_' . time ();
  3109. Doo::db ()->beginTransaction ();
  3110. // 批量存储收款--由于必须获得收款ID,
  3111. $sql = 'INSERT INTO CLD_invoiceReceivables (OriginalPrice,receivablesPrice, receivablesMessage,receivablesSerial,receivablesBank,receivablesDate,inputStaff,date,receivablesCategory,receivablesStaff,bankBatchNumber,recepitTitleMark)
  3112. VALUES ';
  3113. $date = date ( "Y-m-d" );
  3114. $receivablesList = array ();
  3115. foreach ( $exlArray as $key => $value ) {
  3116. $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"] . '")';
  3117. array_push ( $receivablesList, $receivablesSql );
  3118. }
  3119. $sql = $sql . implode ( ',', $receivablesList );
  3120. // echo $sql;
  3121. Doo::db ()->query ( $sql );
  3122. // 批量存储收款统计
  3123. // 获得刚刚导入数据的irid组-缺少办事处和人员
  3124. $iridList = $invoiceReceivables->getInvoiceReceivablesByBBN ( $bankBatchNumber );
  3125. // 没有irid 回滚所有操作
  3126. if (empty ( $iridList )) {
  3127. Doo::db ()->rollBack ();
  3128. header ( 'Content-Type:text/html;charset=utf-8' );
  3129. die ( '文档或数据不正确,请重新<a href="/invoiceReceivables">上传</a>.' );
  3130. }
  3131. $sql = 'INSERT INTO CLD_invoiceStatistics (date, priceClass,irid,receivablesPrice)
  3132. VALUES ';
  3133. $statisticsList = array ();
  3134. foreach ( $iridList as $value ) {
  3135. $statisticsSql = '("' . $date . '",2,' . $value ['irid'] . ',' . $value ["receivablesPrice"] . ')';
  3136. array_push ( $statisticsList, $statisticsSql );
  3137. }
  3138. $sql = $sql . implode ( ',', $statisticsList );
  3139. Doo::db ()->query ( $sql );
  3140. // 批量存储操作日志
  3141. $sql = 'INSERT INTO CLD_invoiceROLog (operation, date,status,img, username,uid,category,irid)
  3142. VALUES ';
  3143. $ROLogList = array ();
  3144. foreach ( $iridList as $value ) {
  3145. $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'] . '")';
  3146. array_push ( $ROLogList, $ROLogSql );
  3147. }
  3148. $sql = $sql . implode ( ',', $ROLogList );
  3149. Doo::db ()->query ( $sql );
  3150. // 批量写入流水
  3151. $sql = 'INSERT INTO CLD_wasteBook (dataID, expensesType,accountType,accountPriceShow, accountPrice,accountBank,category,cid,name,sid,inputDate)
  3152. VALUES ';
  3153. $wasteBookList = array ();
  3154. foreach ( $iridList as $value ) {
  3155. $accountBank = '';
  3156. if ($value ['receivablesBank'] == '纵横广发') {
  3157. $accountBank = 'CGBDeposit';
  3158. } elseif ($value ['receivablesBank'] == '纵横工行') {
  3159. $accountBank = 'ICBCDeposit';
  3160. } elseif ($value ['receivablesBank'] == '华润银行') {
  3161. $accountBank = 'HUADeposit';
  3162. } elseif ($value ['receivablesBank'] == '个人广发') {
  3163. $accountBank = 'PersonalDeposit';
  3164. }
  3165. $wasteBookSql = '("' . $value ['irid'] . ' ",1,7,"' . $value ['receivablesPrice'] . '","' . $value ['receivablesPrice'] . '","' . $accountBank . '",
  3166. "' . $this->staff [0] ['category'] . '","' . $this->staff [0] ['cid'] . '","' . $this->staff [0] ['username'] . '","' . $this->staff [0] ['sid'] . '","' . date ( "Y-m-d H:i:s" ) . '")';
  3167. array_push ( $wasteBookList, $wasteBookSql );
  3168. }
  3169. $sql = $sql . implode ( ',', $wasteBookList );
  3170. Doo::db ()->query ( $sql );
  3171. Doo::db ()->commit ();
  3172. return "/invoiceReceivables";
  3173. }
  3174. echo 'no file';
  3175. }
  3176. function invoiceReceivables() {
  3177. $invoiceTC = $this->get_args ( 'invoiceTC' ) ? $this->get_args ( 'invoiceTC' ) : '';
  3178. Doo::loadModel ( 'L_category' );
  3179. $lCategory = new L_category ();
  3180. Doo::loadModel ( 'staff' );
  3181. $staff = new staff ();
  3182. Doo::loadModel ( 'invoiceReceivables' );
  3183. $invoiceReceivables = new invoiceReceivables ();
  3184. Doo::loadModel ( 'invoice' );
  3185. $invoice = new invoice ();
  3186. Doo::loadClass ( 'XDeode' );
  3187. $XDeode = new XDeode ( 5 );
  3188. $category = $lCategory->getCategory ();
  3189. $staffList = $staff->getStaffByCid ( $this->staff [0] ['cid'] );
  3190. $sql = 'bindStatus=1 and iid!=0';
  3191. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByNew ( 4, $sql );
  3192. // 获取未入账发票
  3193. $invoiceUnAccount = $invoice->getInvoiceByUnAccount ( $invoiceTC );
  3194. $invoiceExistAccount = $invoice->getInvoiceByUnAccount ( '', true );
  3195. foreach ( $invoiceUnAccount as $key => $value ) {
  3196. $invoiceUnAccount [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  3197. $lastApprover = json_decode ( $value ['processApprovals'], true );
  3198. if (! empty ( $lastApprover )) {
  3199. $lastApproverKey = array_keys ( $lastApprover );
  3200. $lastApprover = end ( $lastApprover );
  3201. $staffDetail = $staff->getOne ( array (
  3202. 'where' => 'sid=' . end ( $lastApproverKey ),
  3203. 'asArray' => true
  3204. ) );
  3205. $lastApprover ['username'] = $staffDetail ['username'];
  3206. }
  3207. $invoiceUnAccount [$key] ['lastApprover'] = $lastApprover;
  3208. }
  3209. foreach ( $invoiceExistAccount as $key => $value ) {
  3210. // $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  3211. // if (empty ( $irList ))
  3212. // $irList [0] ['sumPrice'] = 0;
  3213. //$balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  3214. $invoiceExistAccount [$key] ['existAccount'] = $value ['invoicePrice']-$value ['invoiceBalance'];
  3215. //$invoiceExistAccount [$key] ['balance'] = $balance;
  3216. }
  3217. $receivablesInput = $invoiceReceivables->getInvoiceReceivablesByInput ();
  3218. $halfList = $invoiceReceivables->getInvoiceReceivablesByHalf ();
  3219. $this->data ['halfList'] = $halfList;
  3220. $this->data ['halfCount'] = count ( $halfList );
  3221. // print_r($receivablesList);
  3222. $this->data ['receivablesDate'] = date ( "Y-m-d" );
  3223. $this->data ['ieaCount'] = count ( $invoiceExistAccount );
  3224. $this->data ['invoiceExistAccount'] = $invoiceExistAccount;
  3225. $this->data ['receivablesInput'] = $receivablesInput;
  3226. $this->data ['year'] = date ( 'Y' );
  3227. $this->data ['invoiceUnAccount'] = $invoiceUnAccount;
  3228. $this->data ['receivablesList'] = $receivablesList;
  3229. $this->data ['staffList'] = $staffList;
  3230. $this->data ['category'] = $category;
  3231. $this->data ['memu'] = "invoice";
  3232. $this->data ['staff'] = $this->staff;
  3233. $this->data ['receiptMemu'] = 'invoiceReceivables';
  3234. $this->render ( "/admin/invoiceReceivables", $this->data );
  3235. }
  3236. /**
  3237. * 设置收款认领地区
  3238. */
  3239. function setInvoiceReceivablesClaim() {
  3240. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  3241. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3242. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  3243. if (! empty ( $iridKey ) && ! empty ( $receivablesCategory )) {
  3244. Doo::loadModel ( 'invoiceReceivables' );
  3245. $invoiceReceivables = new invoiceReceivables ();
  3246. Doo::loadClass ( 'XDeode' );
  3247. $XDeode = new XDeode ( 5 );
  3248. Doo::loadModel ( 'invoiceROLog' );
  3249. $invoiceROLog = new invoiceROLog ();
  3250. $irid = $XDeode->decode ( $iridKey );
  3251. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  3252. if (empty ( $irDetail ))
  3253. die ( 'illegal request' );
  3254. $item = array (
  3255. 'irid' => $irid,
  3256. 'receivablesCategory' => $receivablesCategory
  3257. );
  3258. if ($receivablesCategory != 'PUBLIC') {
  3259. $item += array (
  3260. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3261. 'inputType' => 1
  3262. );
  3263. }
  3264. $invoiceReceivables = new invoiceReceivables ();
  3265. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3266. // 收款操作日志
  3267. $item = array (
  3268. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 ",
  3269. 'date' => date ( "Y-m-d" ),
  3270. 'status' => 1,
  3271. 'img' => $this->staff [0] ['avatar'],
  3272. 'username' => $this->staff [0] ['username'],
  3273. 'uid' => $this->staff [0] ['sid'],
  3274. 'category' => $this->staff [0] ['category'],
  3275. 'irid' => $irid
  3276. );
  3277. $invoiceROLog->setInvoiceROLog ( $item );
  3278. if (empty ( $action ))
  3279. return '/invoiceReceivables';
  3280. else
  3281. return "/invoiceReceivablesAS";
  3282. }
  3283. die ( 'illegal request' );
  3284. }
  3285. /**
  3286. * 新添加收款直接入账发票
  3287. */
  3288. function invoiceCompareClaimPrice() {
  3289. // 收款录入
  3290. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  3291. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3292. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3293. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3294. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3295. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $iidKey )) {
  3296. Doo::loadModel ( 'invoiceReceivables' );
  3297. $invoiceReceivables = new invoiceReceivables ();
  3298. Doo::loadModel ( 'invoiceROLog' );
  3299. $invoiceROLog = new invoiceROLog ();
  3300. Doo::loadModel ( 'invoiceStatistics' );
  3301. Doo::loadModel ( 'invoice' );
  3302. $invoice = new invoice ();
  3303. Doo::loadModel ( 'bill' );
  3304. $bill = new bill ();
  3305. Doo::loadClass ( 'XDeode' );
  3306. $XDeode = new XDeode ( 5 );
  3307. Doo::loadModel ( 'invoiceOperationLog' );
  3308. $invoiceOperationLog = new invoiceOperationLog ();
  3309. $iidKey = $XDeode->decode ( $iidKey );
  3310. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  3311. if (! ($invoiceDetail ['status'] == 2 && $invoiceDetail ['printStatus'] == 1 && $invoiceDetail ['untreadStatus'] == 0))
  3312. die ( 'illegal request' );
  3313. $receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  3314. // 收款录入 并绑定发票
  3315. Doo::db ()->beginTransaction ();
  3316. //获得发票入账余额
  3317. //$bindInvicePrice=$invoiceReceivables->getSumOfReceivablesPrice ( $invoiceDetail['irid'] );
  3318. //$bindPrice=$invoiceDetail ['invoiceBalance']-$bindInvicePrice;
  3319. $bindStatus = 0;
  3320. $invoiceBalance=$invoiceDetail ['invoicePrice'];
  3321. if($invoiceDetail ['invoiceBalance']!=0){
  3322. $invoiceBalance=$invoiceDetail ['invoiceBalance'];
  3323. }
  3324. if ($receivablesPrice <= $invoiceBalance){
  3325. $bindStatus = 1;
  3326. //$bindPrice=$receivablesPrice;
  3327. }
  3328. $titleMark = $invoiceDetail ['invoiceTitle'];
  3329. if (! empty ( $invoiceDetail ['invoiceCompany'] ))
  3330. $titleMark = $invoiceDetail ['invoiceCompany'];
  3331. $item = array (
  3332. 'recepitTitleMark' => $titleMark,
  3333. 'bindStatus' => $bindStatus,
  3334. 'iid' => $invoiceDetail ['iid'],
  3335. 'bindPrice' => $receivablesPrice,
  3336. 'bindDate' => date ( "Y-m-d H:i:s" ),
  3337. 'receivablesPrice' => $receivablesPrice,
  3338. 'OriginalPrice' => $receivablesPrice,
  3339. 'receivablesMessage' => $receivablesMessage,
  3340. 'receivablesSerial' => $receivablesSerial,
  3341. 'receivablesBank' => $receivablesBank,
  3342. 'receivablesDate' => $receivablesDate,
  3343. 'inputStaff' => $this->staff [0] ['username'],
  3344. 'accountClerk' => $this->staff [0] ['username'],
  3345. 'date' => date ( "Y-m-d" ),
  3346. 'receivablesCategory' => $invoiceDetail ['cid'] . ':' . $invoiceDetail ['categoryName'],
  3347. 'receivablesStaff' => $invoiceDetail ['sid'] . '-' . $invoiceDetail ['userName'],
  3348. 'confirmTime' => date ( "Y-m-d H:i:s" )
  3349. );
  3350. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  3351. $item = array ();
  3352. // 收款操作日志
  3353. $item = array (
  3354. 'operation' => $this->staff [0] ['username'] . " 转入 " . $invoiceDetail ['userName']
  3355. );
  3356. $item += array (
  3357. 'date' => date ( "Y-m-d" ),
  3358. 'status' => 1,
  3359. 'img' => $this->staff [0] ['avatar'],
  3360. 'username' => $this->staff [0] ['username'],
  3361. 'uid' => $this->staff [0] ['sid'],
  3362. 'category' => $this->staff [0] ['category'],
  3363. 'irid' => $irid
  3364. );
  3365. $invoiceROLog->setInvoiceROLog ( $item );
  3366. // 收款统计
  3367. $invoiceStatistics = new invoiceStatistics ();
  3368. $item = array (
  3369. 'date' => $receivablesDate,
  3370. 'priceClass' => 2,
  3371. 'irid' => $irid,
  3372. 'cid' => $invoiceDetail ['cid'],
  3373. 'staff' => $invoiceDetail ['sid'],
  3374. 'receivablesPrice' => $receivablesPrice
  3375. );
  3376. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3377. // 收款 入 发票
  3378. $detail = $invoiceDetail;
  3379. $iridString = "";
  3380. if (empty ( $detail ['irid'] ))
  3381. $iridString = $irid;
  3382. else
  3383. $iridString = $detail ['irid'] . ',' . $irid;
  3384. $item = array (
  3385. 'irid' => $iridString,
  3386. 'bindTime' => date ( "Y-m-d H:i:s" ),
  3387. 'updateTime' => date ( "Y-m-d H:i:s" ),
  3388. 'iid' => $detail ['iid']
  3389. );
  3390. // $invoiceReceivables = new invoiceReceivables ();
  3391. // $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  3392. // $sumBind = $bindInvicePrice;
  3393. // $sumBalance=$invoiceReceivables->balanceOfReceivablesPrice($irid);
  3394. // $sum=$sumBind+$sumBalance;
  3395. // ;
  3396. if ($receivablesPrice>=$invoiceBalance){
  3397. $item += array (
  3398. 'invoiceBalance'=>0,
  3399. 'untreadStatus' => 3
  3400. );
  3401. }else{
  3402. $item += array (
  3403. 'invoiceBalance'=>$invoiceBalance-$receivablesPrice
  3404. );
  3405. }
  3406. $invoice->setInvoiceByCondition ( $item );
  3407. // 操作日志
  3408. $item = array (
  3409. 'date' => date ( "Y-m-d H:i:s" ),
  3410. 'operation' => "收款入账" . $receivablesSerial . "到发票" . $detail ['invoiceSerial'],
  3411. 'status' => 8,
  3412. 'img' => $this->staff [0] ['avatar'],
  3413. 'username' => $this->staff [0] ['username'],
  3414. 'uid' => $this->staff [0] ['sid'],
  3415. 'category' => $this->staff [0] ['category'],
  3416. 'iid' => $detail ['iid']
  3417. );
  3418. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3419. // 入账汇总
  3420. $invoiceStatistics = new invoiceStatistics ();
  3421. // $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $iridString );
  3422. // $accountPrice = 0;
  3423. // foreach ( $list as $key => $value ) {
  3424. // $accountPrice += $value ['receivablesPrice'];
  3425. // }
  3426. $item = array (
  3427. 'date' => $receivablesDate,
  3428. 'priceClass' => 3,
  3429. 'cid' => $invoiceDetail ['cid'],
  3430. 'staff' => $invoiceDetail ['sid'],
  3431. 'accountPrice' => $receivablesPrice
  3432. );
  3433. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3434. //发票入账记录
  3435. $bill->iid=$invoiceDetail['iid'];
  3436. $bill->trainId=$invoiceDetail['trainId'];
  3437. $bill->irid=$irid;
  3438. $bill->create_time=date ( "Y-m-d H:i:s" );
  3439. $bill->price=$receivablesPrice;
  3440. $bill->insert ();
  3441. // 公司流水记录
  3442. Doo::loadModel ( 'wasteBook' );
  3443. $wasteBook = new wasteBook ();
  3444. $abDetail = $wasteBook->getAccountBookByAid ( 2, 7, $irid );
  3445. $accountBank = '';
  3446. if ($receivablesBank == '纵横广发') {
  3447. $accountBank = 'CGBDeposit';
  3448. } elseif ($receivablesBank == '纵横工行') {
  3449. $accountBank = 'ICBCDeposit';
  3450. } elseif ($receivablesBank == '华润银行') {
  3451. $accountBank = 'HUADeposit';
  3452. } elseif ($receivablesBank == '个人广发') {
  3453. $accountBank = 'PersonalDeposit';
  3454. }
  3455. if (empty ( $abDetail )) {
  3456. $item = array (
  3457. 'dataID' => $irid,
  3458. 'expensesType' => 1,
  3459. 'accountType' => 7,
  3460. 'accountPrice' => $receivablesPrice,
  3461. 'accountPriceShow' => $receivablesPrice,
  3462. 'accountBank' => $accountBank,
  3463. 'category' => $this->staff [0] ['category'],
  3464. 'cid' => $this->staff [0] ['cid'],
  3465. 'name' => $this->staff [0] ['username'],
  3466. 'sid' => $this->staff [0] ['sid'],
  3467. 'inputDate' => date ( "Y-m-d H:i:s" )
  3468. );
  3469. $wasteBook->setAccountBookStatistics ( $item );
  3470. }
  3471. Doo::db ()->commit ();
  3472. }
  3473. return '/invoiceReceivables';
  3474. }
  3475. /**
  3476. * 录入收款数据
  3477. * @return string
  3478. */
  3479. function invoiceReceivablesDo() {
  3480. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3481. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3482. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3483. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3484. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3485. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  3486. Doo::loadModel ( 'invoiceReceivables' );
  3487. $invoiceReceivables = new invoiceReceivables ();
  3488. Doo::loadModel ( 'invoiceROLog' );
  3489. $invoiceROLog = new invoiceROLog ();
  3490. Doo::loadModel ( 'invoiceStatistics' );
  3491. $invoiceStatistics = new invoiceStatistics ();
  3492. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $receivablesCategory ) && ! empty ( $receivablesStaff )) {
  3493. $item = array (
  3494. 'receivablesPrice' => $receivablesPrice,
  3495. 'OriginalPrice' => $receivablesPrice,
  3496. 'receivablesMessage' => $receivablesMessage,
  3497. 'receivablesSerial' => "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  3498. 'receivablesBank' => $receivablesBank,
  3499. 'receivablesDate' => $receivablesDate,
  3500. 'inputStaff' => $this->staff [0] ['username'],
  3501. 'date' => date ( "Y-m-d" ),
  3502. 'receivablesCategory' => $receivablesCategory,
  3503. 'receivablesStaff' => $receivablesStaff
  3504. );
  3505. if ($receivablesCategory != 'PUBLIC') {
  3506. $item += array (
  3507. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3508. 'inputType' => 1
  3509. );
  3510. }
  3511. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  3512. $item = array ();
  3513. // 收款操作日志
  3514. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3515. $item = array (
  3516. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  3517. );
  3518. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3519. $item = array (
  3520. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  3521. );
  3522. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3523. $receivablesStaff = explode ( '-', $receivablesStaff );
  3524. $item = array (
  3525. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  3526. );
  3527. }
  3528. $item += array (
  3529. 'date' => date ( "Y-m-d" ),
  3530. 'status' => 1,
  3531. 'img' => $this->staff [0] ['avatar'],
  3532. 'username' => $this->staff [0] ['username'],
  3533. 'uid' => $this->staff [0] ['sid'],
  3534. 'category' => $this->staff [0] ['category'],
  3535. 'irid' => $irid
  3536. );
  3537. $invoiceROLog->setInvoiceROLog ( $item );
  3538. $item = array (
  3539. 'date' => $receivablesDate,
  3540. 'priceClass' => 2,
  3541. 'irid' => $irid,
  3542. 'receivablesPrice' => $receivablesPrice
  3543. );
  3544. if ($receivablesCategory != 'PUBLIC') {
  3545. $receivablesCategory = explode ( ":", $receivablesCategory );
  3546. $item += array (
  3547. 'cid' => $receivablesCategory [0]
  3548. );
  3549. }
  3550. if ($receivablesStaff2 != 'PUBLIC') {
  3551. $receivablesStaff = explode ( "-", $receivablesStaff2 );
  3552. $item += array (
  3553. 'staff' => $receivablesStaff [0]
  3554. );
  3555. }
  3556. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3557. $toparty = $this->getWxidByCategory ( $receivablesCategory [1] );
  3558. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  3559. $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  3560. if ($toparty != 0)
  3561. $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  3562. // 公司流水记录
  3563. Doo::loadModel ( 'wasteBook' );
  3564. $wasteBook = new wasteBook ();
  3565. $abDetail = $wasteBook->getAccountBookByAid ( 1, 7, $irid );
  3566. $accountBank = '';
  3567. if ($receivablesBank == '纵横广发') {
  3568. $accountBank = 'CGBDeposit';
  3569. } elseif ($receivablesBank == '纵横工行') {
  3570. $accountBank = 'ICBCDeposit';
  3571. } elseif ($receivablesBank == '华润银行') {
  3572. $accountBank = 'HUADeposit';
  3573. } elseif ($receivablesBank == '个人广发') {
  3574. $accountBank = 'PersonalDeposit';
  3575. }
  3576. $item = array (
  3577. 'dataID' => $irid,
  3578. 'expensesType' => 1,
  3579. 'accountType' => 7,
  3580. 'accountPriceShow' => $receivablesPrice,
  3581. 'accountPrice' => $receivablesPrice,
  3582. 'accountBank' => $accountBank,
  3583. 'category' => $this->staff [0] ['category'],
  3584. 'cid' => $this->staff [0] ['cid'],
  3585. 'name' => $this->staff [0] ['username'],
  3586. 'sid' => $this->staff [0] ['sid'],
  3587. 'inputDate' => date ( "Y-m-d H:i:s" )
  3588. );
  3589. $wasteBook->setAccountBookStatistics ( $item );
  3590. }
  3591. return "/invoiceReceivables";
  3592. }
  3593. /**
  3594. * 收款认领页面-包括公共认领 办事处认领 最近已认领数据
  3595. */
  3596. function invoiceReceivablesClaim() {
  3597. Doo::loadModel ( 'invoiceReceivables' );
  3598. $invoiceReceivables = new invoiceReceivables ();
  3599. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  3600. $this->data ['receivablesList'] = $receivablesList;
  3601. $this->data ['memu'] = "invoice";
  3602. $this->data ['staff'] = $this->staff;
  3603. $this->data ['receiptMemu'] = 'invoiceReceivablesClaim';
  3604. $this->render ( "/admin/invoiceReceivablesClaim", $this->data );
  3605. }
  3606. function invoiceReceivablesTitleMarkSet() {
  3607. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  3608. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  3609. if (empty ( $iridKey ) || empty ( $recepitTitleMark ))
  3610. die ( 'illegal request' );
  3611. Doo::loadModel ( 'invoiceReceivables' );
  3612. $invoiceReceivables = new invoiceReceivables ();
  3613. Doo::loadClass ( 'XDeode' );
  3614. $XDeode = new XDeode ( 5 );
  3615. $irid = $XDeode->decode ( $iridKey );
  3616. if (! is_numeric ( $irid ))
  3617. die ( 'illegal request' );
  3618. $invoiceReceivables->recepitTitleMark = $recepitTitleMark;
  3619. $invoiceReceivables->update ( array (
  3620. 'where' => 'irid = ' . $irid
  3621. ) );
  3622. return '/invoiceReceivablesClaim';
  3623. }
  3624. /**
  3625. * 更新收款相关数据
  3626. */
  3627. function invoiceReceivablesUpdateClaim() {
  3628. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3629. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3630. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3631. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3632. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3633. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  3634. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  3635. if (empty ( $claimKey ))
  3636. die ( 'illegal request' );
  3637. Doo::loadModel ( 'invoiceReceivables' );
  3638. $invoiceReceivables = new invoiceReceivables ();
  3639. Doo::loadModel ( 'invoiceROLog' );
  3640. $invoiceROLog = new invoiceROLog ();
  3641. $con = ' and iid=0 and bindStatus=0'; // and receivablesCategory!="PUBLIC" and receivablesStaff!="PUBLIC"
  3642. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  3643. if (empty ( $detail ))
  3644. die ( 'illegal request' );
  3645. $invoiceReceivables = new invoiceReceivables ();
  3646. $item = array (
  3647. 'irid' => $detail ['irid']
  3648. );
  3649. if ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3650. $item += array (
  3651. 'confirmTime' => date ( "Y-m-d H:i:s" )
  3652. );
  3653. }
  3654. if (! empty ( $receivablesCategory ))
  3655. $item += array (
  3656. 'receivablesCategory' => $receivablesCategory
  3657. );
  3658. if (! empty ( $receivablesStaff ))
  3659. $item += array (
  3660. 'receivablesStaff' => $receivablesStaff
  3661. );
  3662. if (! empty ( $receivablesPrice ))
  3663. $item += array (
  3664. 'receivablesPrice' => $receivablesPrice
  3665. );
  3666. if (! empty ( $receivablesMessage ))
  3667. $item += array (
  3668. 'receivablesMessage' => $receivablesMessage
  3669. );
  3670. if (! empty ( $receivablesBank ))
  3671. $item += array (
  3672. 'receivablesBank' => $receivablesBank
  3673. );
  3674. if (! empty ( $receivablesDate ))
  3675. $item += array (
  3676. 'receivablesDate' => $receivablesDate
  3677. );
  3678. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3679. // 收款操作日志
  3680. $item = array ();
  3681. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3682. $item = array (
  3683. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  3684. );
  3685. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3686. $item = array (
  3687. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  3688. );
  3689. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3690. $receivablesStaff = explode ( '-', $receivablesStaff );
  3691. $item = array (
  3692. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  3693. );
  3694. }
  3695. $item += array (
  3696. 'date' => date ( "Y-m-d" ),
  3697. 'status' => 1,
  3698. 'img' => $this->staff [0] ['avatar'],
  3699. 'username' => $this->staff [0] ['username'],
  3700. 'uid' => $this->staff [0] ['sid'],
  3701. 'category' => $this->staff [0] ['category'],
  3702. 'irid' => $detail ['irid']
  3703. );
  3704. $invoiceROLog->setInvoiceROLog ( $item );
  3705. return '/invoiceReceivablesAS';
  3706. }
  3707. function invoiceReceivablesDelete() {
  3708. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  3709. $skll = $this->get_args ( 'skll' ) ? $this->get_args ( 'skll' ) : "";
  3710. if ($skll != '删除到款')
  3711. die ( 'illegal request' );
  3712. if (empty ( $claimKey ))
  3713. die ( 'illegal request' );
  3714. Doo::loadModel ( 'invoiceReceivables' );
  3715. $invoiceReceivables = new invoiceReceivables ();
  3716. $con = ' and bindStatus=0 ';
  3717. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  3718. if (empty ( $detail ))
  3719. die ( 'illegal request' );
  3720. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  3721. // 扣除收款汇总信息 汇总
  3722. Doo::loadModel ( 'invoiceStatistics' );
  3723. $invoiceStatistics = new invoiceStatistics ();
  3724. $item = array (
  3725. 'date' => $detail ['receivablesDate'],
  3726. 'priceClass' => 2,
  3727. 'irid' => $detail ['irid'],
  3728. 'receivablesPrice' => - $detail ['receivablesPrice']
  3729. );
  3730. if ($detail ['receivablesCategory'] != 'PUBLIC') {
  3731. $receivablesCategory = explode ( ":", $detail ['receivablesCategory'] );
  3732. $item += array (
  3733. 'cid' => $receivablesCategory [0]
  3734. );
  3735. }
  3736. if ($detail ['receivablesStaff'] != 'PUBLIC') {
  3737. $receivablesStaff = explode ( "-", $detail ['receivablesStaff'] );
  3738. $item += array (
  3739. 'staff' => $receivablesStaff [0]
  3740. );
  3741. }
  3742. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3743. // 公司流水-删除时删除流水
  3744. Doo::loadModel ( 'wasteBook' );
  3745. $wasteBook = new wasteBook ();
  3746. $wasteBook->delete ( array (
  3747. 'where' => 'dataID=' . $detail ['irid'] . ' and accountType=7',
  3748. 'limit' => 1
  3749. ) );
  3750. return '/invoiceReceivablesAS';
  3751. }
  3752. /**
  3753. * 管理员录入的收款 ,确认认领到谁的名下.统计收款金额
  3754. */
  3755. function invoiceReceivablesAscription() {
  3756. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  3757. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  3758. Doo::loadModel ( 'invoiceReceivables' );
  3759. $invoiceReceivables = new invoiceReceivables ();
  3760. Doo::loadModel ( 'invoiceROLog' );
  3761. $invoiceROLog = new invoiceROLog ();
  3762. Doo::loadModel ( 'invoiceStatistics' );
  3763. $invoiceStatistics = new invoiceStatistics ();
  3764. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  3765. $irid = $invoiceReceivables->authcode ( $irid );
  3766. if (! empty ( $detail ) && $detail ['receivablesStaff'] == 'PUBLIC' && ! empty ( $recepitTitleMark )) {
  3767. $item = array (
  3768. 'irid' => $detail ['irid'],
  3769. 'receivablesCategory' => $this->staff [0] ['cid'] . ":" . $this->staff [0] ['category'],
  3770. 'receivablesStaff' => $this->staff [0] ['sid'] . "-" . $this->staff [0] ['username'],
  3771. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3772. 'recepitTitleMark' => $recepitTitleMark,
  3773. 'source' => 1
  3774. );
  3775. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3776. $item = array (
  3777. 'date' => date ( "Y-m-d" ),
  3778. 'operation' => $this->staff [0] ['username'] . " 认领 ",
  3779. 'status' => 2,
  3780. 'img' => $this->staff [0] ['avatar'],
  3781. 'username' => $this->staff [0] ['username'],
  3782. 'uid' => $this->staff [0] ['sid'],
  3783. 'category' => $this->staff [0] ['category'],
  3784. 'irid' => $irid
  3785. );
  3786. $invoiceROLog->setInvoiceROLog ( $item );
  3787. $item = array (
  3788. 'cid' => $this->staff [0] ['cid'],
  3789. 'staff' => $this->staff [0] ['sid']
  3790. );
  3791. $invoiceStatistics->updateInvoiceStatisticsByIrid ( $item, $detail ['irid'], 2 );
  3792. }
  3793. return "/invoiceReceivablesClaim";
  3794. }
  3795. /**
  3796. */
  3797. function invoiceMyReceivables() {
  3798. Doo::loadModel ( 'invoiceReceivables' );
  3799. $invoiceReceivables = new invoiceReceivables ();
  3800. Doo::loadModel ( 'invoiceStatistics' );
  3801. $invoiceStatistics = new invoiceStatistics ();
  3802. $isMonth = $invoiceStatistics->getStatisticsByMonth ( $this->staff [0] ['sid'] );
  3803. $year = date ( "Y" );
  3804. $tmp_date = date ( "Ym" );
  3805. $tmp_year = substr ( $tmp_date, 0, 4 );
  3806. $tmp_mon = substr ( $tmp_date, 4, 2 );
  3807. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  3808. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  3809. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . ".htm";
  3810. $htm = $this->showCache ( $path );
  3811. $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  3812. $this->data ['isMonth'] = $isMonth;
  3813. $this->data ['htm'] = $htm;
  3814. $this->data ['list'] = $list;
  3815. $this->data ['memu'] = "invoice";
  3816. $this->data ['staff'] = $this->staff;
  3817. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  3818. $this->render ( "/admin/invoiceMyReceivables", $this->data );
  3819. }
  3820. /**
  3821. * 纸票管理
  3822. */
  3823. function invoicePaper() {
  3824. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3825. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3826. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3827. $this->data ['dateString'] = $date;
  3828. $this->data ['status'] = $status;
  3829. $this->data ['invoiceType'] = $invoiceType;
  3830. $this->data ['memu'] = "invoice";
  3831. $this->data ['staff'] = $this->staff;
  3832. $this->data ['receiptMemu'] = 'invoicePaper';
  3833. $this->render ( "/admin/invoicePaper", $this->data );
  3834. }
  3835. /**
  3836. * 电子发票管理
  3837. */
  3838. function invoiceElectronic() {
  3839. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3840. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3841. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3842. $this->data ['dateString'] = $date;
  3843. $this->data ['status'] = $status;
  3844. $this->data ['invoiceType'] = $invoiceType;
  3845. $this->data ['memu'] = "invoice";
  3846. $this->data ['staff'] = $this->staff;
  3847. $this->data ['receiptMemu'] = 'invoicePaper';
  3848. $this->render ( "/invoice/invoiceElectronic", $this->data );
  3849. }
  3850. /**
  3851. * 获得纸票分页数据
  3852. */
  3853. function ajaxGetinvoicePaperAchieve() {
  3854. //include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  3855. Doo::loadModel ( 'invoicePaper' );
  3856. $invoicePaper = new invoicePaper ();
  3857. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3858. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3859. $invoiceForm = $this->get_args ( 'invoiceForm' )&&is_numeric($this->get_args ( 'invoiceForm' )) ? $this->get_args ( 'invoiceForm' ) : "0";
  3860. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ORDINARY";
  3861. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3862. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  3863. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  3864. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  3865. $MebSea = $this->get_args ( 'search' );
  3866. $MebSea = $MebSea ['value'];
  3867. $page_size = $length;
  3868. $con = '';
  3869. if ($status == 'ALL')
  3870. $con = ' where 1 ';
  3871. elseif ($status == 'PRINTED')
  3872. $con = ' where a.iid!=0 '; // $con = ' where b.isDelete=0 and a.iid!=0 and b.status=2 and b.untreadStatus=0 ';
  3873. elseif ($status == 'UNPRINT')
  3874. $con = ' where a.iid=0 '; // $con = ' where b.isDelete=0 and a.iid=0 and b.status=2 and b.untreadStatus=0 ';
  3875. elseif ($status == 'TICKET')
  3876. $con = ' where b.isDelete=0 and b.untreadStatus=2';
  3877. if ($invoiceType == 'ORDINARY')
  3878. $con .= ' and a.invoiceType=0 ';
  3879. elseif ($invoiceType == 'SPECIAL')
  3880. $con .= ' and a.invoiceType=1 ';
  3881. if($invoiceForm==0){
  3882. $con .= ' and a.invoiceForm=0 ';
  3883. }else{
  3884. $con .= ' and a.invoiceForm=1 ';
  3885. }
  3886. $dateArr = explode ( ':', $date );
  3887. $D1 = $dateString = '';
  3888. $D2 = '';
  3889. if (! empty ( $date )) {
  3890. $D1 = $dateArr [0];
  3891. if (isset ( $dateArr [1] ))
  3892. $D2 = $dateArr [1];
  3893. else
  3894. $D2 = '';
  3895. $dateString = $D1 . " : " . $D2;
  3896. }
  3897. if (! empty ( $D1 ) && ! empty ( $D2 ))
  3898. $con .= ' and b.printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  3899. elseif (! empty ( $D1 ) && empty ( $D2 ))
  3900. $con .= ' and b.printTime like "%' . $D1 . '%" ';
  3901. if (! empty ( $MebSea ))
  3902. $con .= ' and ( b.invoiceTitle like "%' . $MebSea . '%" or b.invoiceCompany like "%' . $MebSea . '%" or a.invoiceNo like "%' . $MebSea . '%" )';
  3903. $invoiceTotal = $invoicePaper->getInvoicePaperCount ($invoiceForm);
  3904. $sql = ' ' . $con;
  3905. $limit = $page . ',' . $page_size;
  3906. $list = $invoicePaper->getInvoicePaper ( $limit, $sql, 'desc' );
  3907. $paperList = array ();
  3908. foreach ( $list as $key => $value ) {
  3909. $irDetail = array ();
  3910. if ($value ['iid'] == 0)
  3911. array_push ( $irDetail, '<a href="javascript:if(window.confirm(\'确认删除?\'))window.location=\'/invoicePaperDel/' . $value ['ipidKey'] . '\'" >删除</a>' );
  3912. else
  3913. array_push ( $irDetail, '' );
  3914. array_push ( $irDetail, $value ['invoiceCode'] );
  3915. array_push ( $irDetail, $value ['invoiceNo'] );
  3916. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKey'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  3917. if ($value ['invoiceType'] == 1)
  3918. array_push ( $irDetail, $value ['invoiceCompany'] );
  3919. else
  3920. array_push ( $irDetail, $value ['invoiceTitle'] );
  3921. if ($value ['invoiceType'] == 1)
  3922. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  3923. else
  3924. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  3925. array_push ( $irDetail, $value ['invoiceElement'] );
  3926. array_push ( $irDetail, $value ['categoryName'] . '-' . $value ['userName'] );
  3927. array_push ( $irDetail, $value ['printTime'] );
  3928. array_push ( $paperList, $irDetail );
  3929. }
  3930. // $approvalListJson = json_encode ( $approvalList );
  3931. $recordsFiltered = $invoiceTotal;
  3932. echo json_encode ( array (
  3933. "draw" => intval ( $draw ),
  3934. "recordsTotal" => intval ( $invoiceTotal ),
  3935. "recordsFiltered" => intval ( $recordsFiltered ),
  3936. "data" => $paperList
  3937. ), JSON_UNESCAPED_UNICODE );
  3938. }
  3939. function invoicePaperDel() {
  3940. $ipidKey = isset ( $this->params ['ipidKey'] ) ? $this->params ['ipidKey'] : "";
  3941. $XDeode = new XDeode ( 5 );
  3942. $ipid = $XDeode->decode ( $ipidKey );
  3943. if (empty ( $ipid ))
  3944. die ( 'illegal request' );
  3945. Doo::loadModel ( 'invoicePaper' );
  3946. $invoicePaper = new invoicePaper ();
  3947. $ipdetail=$invoicePaper->getInvoicePaperByIpid($ipid);
  3948. $invoicePaper->delete ( array (
  3949. 'where' => 'ipid=' . $ipid . ' and iid=0',
  3950. 'limit' => 1
  3951. ) );
  3952. if($ipdetail['invoiceForm']==1){
  3953. return '/invoiceElectronic';
  3954. }else{
  3955. return '/invoicePaper';
  3956. }
  3957. }
  3958. /**
  3959. * 添加纸质发票号
  3960. */
  3961. function invoicePaperAdd() {
  3962. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : '0';
  3963. $invoiceCode = $this->get_args ( 'invoiceCode' ) ? $this->get_args ( 'invoiceCode' ) : "";
  3964. $invoiceNoStart = $this->get_args ( 'invoiceNoStart' ) && is_numeric ( $this->get_args ( 'invoiceNoStart' ) ) ? $this->get_args ( 'invoiceNoStart' ) : 0;
  3965. $invoiceNoTotal = $this->get_args ( 'invoiceNoTotal' ) && is_numeric ( $this->get_args ( 'invoiceNoTotal' ) ) ? $this->get_args ( 'invoiceNoTotal' ) : 0;
  3966. $invoiceForm = $this->get_args ( 'invoiceForm' ) && is_numeric ( $this->get_args ( 'invoiceForm' ) ) ? $this->get_args ( 'invoiceForm' ) : 0;
  3967. if ($invoiceType != '' && ! empty ( $invoiceCode ) && ! empty ( $invoiceNoStart ) && ! empty ( $invoiceNoTotal )) {
  3968. $sum = $invoiceNoStart + $invoiceNoTotal;
  3969. if (empty ( $sum ))
  3970. die ( 'illegal request' );
  3971. // echo $invoiceNoStart;
  3972. // echo $sum;
  3973. // echo strlen((int)$invoiceNoStart);
  3974. $sumLenght = strlen ( $invoiceNoStart ) - strlen ( ( int ) $invoiceNoStart );
  3975. if($invoiceType==0||$invoiceType==1){
  3976. }else{
  3977. die ( 'illegal request invoiceType' );
  3978. }
  3979. if($invoiceForm==1){
  3980. $invoiceType=0;
  3981. }
  3982. Doo::db ()->beginTransaction ();
  3983. // 批量存储纸质发票
  3984. $date = date ( "Y-m-d H:i:s" );
  3985. $sql = 'INSERT INTO CLD_invoicePaper (invoiceType, invoiceCode,invoiceNo,date,invoiceForm)
  3986. VALUES ';
  3987. $paperList = array ();
  3988. for($invoiceNoStart; $invoiceNoStart <= $sum - 1; $invoiceNoStart ++) {
  3989. // 数字前面自加0
  3990. $INLENGHT = strlen ( ( int ) $invoiceNoStart ) + $sumLenght;
  3991. $var = sprintf ( "%0" . $INLENGHT . "d", $invoiceNoStart );
  3992. $paperSql = '(' . $invoiceType . ',"' . $invoiceCode . '","' . $var . '","' . $date . '","'.$invoiceForm.'")';
  3993. array_push ( $paperList, $paperSql );
  3994. }
  3995. if (empty ( $paperList ))
  3996. die ( 'illegal request' );
  3997. $sql = $sql . implode ( ',', $paperList );
  3998. Doo::db ()->query ( $sql );
  3999. Doo::db ()->commit ();
  4000. if($invoiceForm==1){
  4001. return 'invoiceElectronic';
  4002. }else{
  4003. return 'invoicePaper';
  4004. }
  4005. }
  4006. die ( 'illegal request' );
  4007. }
  4008. /**
  4009. * 收款绑定发票 ,//一个收款只能绑定一个发票
  4010. */
  4011. function invoiceBindReceivables() {
  4012. $claimKey = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  4013. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  4014. Doo::loadModel ( 'invoice' );
  4015. $invoice = new invoice ();
  4016. Doo::loadModel ( 'invoiceReceivables' );
  4017. $invoiceReceivables = new invoiceReceivables ();
  4018. Doo::loadModel ( 'invoiceOperationLog' );
  4019. $invoiceOperationLog = new invoiceOperationLog ();
  4020. if (empty ( $invoiceKey ) || empty ( $claimKey ))
  4021. die ( 'illegal request' );
  4022. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  4023. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey );
  4024. if (empty ( $detail ) && empty ( $detailM ))
  4025. die ( 'illegal request' );
  4026. if ($detail ['untreadStatus'] == 3)
  4027. die ( 'illegal request' );
  4028. // 修改 绑定状态改为 金额
  4029. $invoiceReceivables = new invoiceReceivables ();
  4030. $invoicePrice = $detail ['invoicePrice'] + $detailM ['bindPrice'];
  4031. $billPrice=0;
  4032. if ($detailM ['receivablesPrice'] > $invoicePrice) {
  4033. $item = array (
  4034. 'bindPrice' => $invoicePrice
  4035. );
  4036. $billPrice=$invoicePrice;
  4037. } elseif ($detailM ['receivablesPrice'] <= $invoicePrice) { //发票金额大于收款金额,绑定金额为收款金额
  4038. $item = array (
  4039. 'bindPrice' => $detailM ['receivablesPrice'],
  4040. 'bindStatus' => 1,
  4041. 'bindDate' => date ( "Y-m-d H:i:s" )
  4042. );
  4043. $billPrice=$detailM ['receivablesPrice'];
  4044. } else {
  4045. die ( 'illegal request' );
  4046. }
  4047. if ($detailM ['iid'] == 0) {
  4048. $item += array (
  4049. 'iid' => $detail ['iid']
  4050. );
  4051. } else {
  4052. $iidExtend = explode ( ',', $detailM ['iidExtend'] );
  4053. array_push ( $iidExtend, $detail ['iid'] );
  4054. $item += array (
  4055. 'iidExtend' => implode ( ',', $iidExtend )
  4056. );
  4057. }
  4058. $titleMark = $detail ['invoiceTitle'];
  4059. if (! empty ( $detail ['invoiceCompany'] ))
  4060. $titleMark = $detail ['invoiceCompany'];
  4061. $item += array (
  4062. 'irid' => $detailM ['irid'],
  4063. 'recepitTitleMark' => $titleMark,
  4064. 'accountClerk' => $this->staff [0] ['username']
  4065. );
  4066. // 如何没有人收款 则自动绑定收款
  4067. if ($detailM ['receivablesCategory'] == 'PUBLIC' || $detailM ['receivablesStaff'] == 'PUBLIC') {
  4068. $item += array (
  4069. 'receivablesCategory' => $detail ['cid'] . ':' . $detail ['categoryName'],
  4070. 'receivablesStaff' => $detail ['sid'] . '-' . $detail ['userName']
  4071. );
  4072. }
  4073. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4074. $iridString = "";
  4075. if (empty ( $detail ['irid'] ))
  4076. $iridString = $detailM ['irid'];
  4077. else
  4078. $iridString = $detail ['irid'] . ',' . $detailM ['irid'];
  4079. // $invoiceReceivables = new invoiceReceivables ();
  4080. // $sumBind = $invoiceReceivables->getSumOfReceivablesPrice ( $detail ['irid'] );
  4081. // //这个收款余额
  4082. // $sumBalance=$invoiceReceivables->balanceOfReceivablesPrice($detailM ['irid']);
  4083. // $sum=$sumBind+$sumBalance;
  4084. //这个收款余额
  4085. $sumBalance=$detailM ['receivablesPrice']-$detailM ['bindPrice'];
  4086. // echo $detailM ['irid'].'/'.$sumBalance.'/'.$detail ['invoicePrice'];
  4087. // die;
  4088. $item = array (
  4089. 'iid' => $detail ['iid'],
  4090. 'irid' => $iridString
  4091. );
  4092. if ($detail ['invoicePrice'] <= $sumBalance){
  4093. $item += array (
  4094. 'invoiceBalance'=>0,
  4095. 'untreadStatus' => 3,
  4096. 'bindTime' => date ( "Y-m-d H:i:s" )
  4097. );
  4098. }else{
  4099. $item += array (
  4100. 'invoiceBalance'=>$detail ['invoicePrice']-$sumBalance,
  4101. );
  4102. }
  4103. // print_r($item);
  4104. // echo $sum;die;
  4105. $invoice->setInvoiceByCondition ( $item );
  4106. //发票入账记录
  4107. Doo::loadModel ( 'bill' );
  4108. $bill = new bill ();
  4109. $bill->iid=$detail ['iid'];
  4110. $bill->trainId=$detail['trainId'];
  4111. $bill->irid=$detailM ['irid'];
  4112. $bill->create_time=date ( "Y-m-d H:i:s" );
  4113. $bill->price=$billPrice;
  4114. $bill->insert ();
  4115. // 操作日志
  4116. $item = array (
  4117. 'date' => date ( "Y-m-d H:i:s" ),
  4118. 'operation' => "收款" . $detailM ['receivablesSerial'] . "入账到发票" . $detail ['invoiceSerial'],
  4119. 'status' => 8,
  4120. 'img' => $this->staff [0] ['avatar'],
  4121. 'username' => $this->staff [0] ['username'],
  4122. 'uid' => $this->staff [0] ['sid'],
  4123. 'category' => $this->staff [0] ['category'],
  4124. 'iid' => $detail ['iid']
  4125. );
  4126. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  4127. Doo::loadModel ( 'invoiceStatistics' );
  4128. $invoiceStatistics = new invoiceStatistics ();
  4129. $item = array (
  4130. 'date' => $detailM ['receivablesDate'],
  4131. 'priceClass' => 3,
  4132. 'cid' => $detail ['cid'],
  4133. 'staff' => $detail ['sid'],
  4134. 'accountPrice' => $detailM ['receivablesPrice']
  4135. );
  4136. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4137. // 公司流水记录
  4138. // Doo::loadModel ( 'wasteBook' );
  4139. // $wasteBook = new wasteBook ();
  4140. // $abDetail = $wasteBook->getAccountBookByAid (1,8,$detail ['iid'] );
  4141. // $accountBank='';
  4142. // if ($detailM ['receivablesBank']=='纵横广发'){
  4143. // $accountBank='CGBDeposit';
  4144. // }elseif($detailM ['receivablesBank']=='纵横工行'){
  4145. // $accountBank='ICBCDeposit';
  4146. // }elseif($detailM ['receivablesBank']=='华润银行'){
  4147. // $accountBank='HUADeposit';
  4148. // }elseif($detailM ['receivablesBank']=='个人广发'){
  4149. // $accountBank='PersonalDeposit';
  4150. // }
  4151. // if (empty($abDetail)){
  4152. // $item = array (
  4153. // 'dataID' => $detail ['iid'],
  4154. // 'expensesType' => 1,
  4155. // 'accountType' => 8,
  4156. // 'accountPriceShow'=>$detail ['invoicePrice'],
  4157. // 'accountPrice'=>$detail ['invoicePrice'],
  4158. // 'accountBank'=>$accountBank,
  4159. // 'category'=>$this->staff[0]['category'],
  4160. // 'cid'=>$this->staff[0]['cid'],
  4161. // 'name'=>$this->staff[0]['username'],
  4162. // 'sid'=>$this->staff[0]['sid'],
  4163. // 'inputDate'=>date ( "Y-m-d H:i:s" )
  4164. // );
  4165. // $wasteBook->setAccountBookStatistics($item);
  4166. // }
  4167. return "/invoiceReceivables";
  4168. }
  4169. /**
  4170. * 核销 动作,确认入账统计 发票收款完成--需求更变 废弃 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"; }
  4171. */
  4172. function invoiceAggregate() {
  4173. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  4174. Doo::loadModel ( 'invoiceStatistics' );
  4175. $invoiceStatistics = new invoiceStatistics ();
  4176. Doo::loadModel ( 'L_category' );
  4177. $Lcategory = new L_category ();
  4178. $isList = $invoiceStatistics->getInvoiceStatisticsByYear ( $year );
  4179. $LcategoryList = $Lcategory->getCategory ();
  4180. // print_r($isList);
  4181. $html = ""; // $invoicePriceCategory=0;$receivablesPriceCategory=0;$accountPriceCategory=0;
  4182. foreach ( $LcategoryList as $key => $value ) {
  4183. $html .= '<tr><th><a href="/invoiceAggregateCategory/' . $value ['cidKey'] . '">' . $value ['title'] . '</a></th>';
  4184. $month = 1;
  4185. $invoicePriceYear = 0;
  4186. $receivablesPriceYear = 0;
  4187. $accountPriceYear = 0;
  4188. for(; $month <= 12; $month ++) {
  4189. $flag = true;
  4190. foreach ( $isList ['statisticsMonthCid'] as $k => $v ) {
  4191. if ($value ['cid'] == $v ['cid'] && $month == $v ['month']) {
  4192. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  4193. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  4194. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  4195. ';
  4196. $invoicePriceYear += $v ['invoicePrice'];
  4197. $receivablesPriceYear += $v ['receivablesPrice'];
  4198. $accountPriceYear += $v ['accountPrice'];
  4199. $flag = false;
  4200. break;
  4201. }
  4202. }
  4203. if ($flag)
  4204. $html .= '<td class="taR"></td>
  4205. <td class="taR"></td>
  4206. <td class="taR"><b></b></td>
  4207. ';
  4208. }
  4209. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  4210. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  4211. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  4212. ';
  4213. $html .= '</tr>';
  4214. }
  4215. $html .= '<tr><th><b class="colGreen">月合计</b></th>';
  4216. $invoicePriceYear = 0;
  4217. $receivablesPriceYear = 0;
  4218. $accountPriceYear = 0;
  4219. for($month = 1; $month <= 12; $month ++) {
  4220. $flag = true;
  4221. foreach ( $isList ['statisticsMonth'] as $k => $v ) {
  4222. if ($month == $v ['month']) {
  4223. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  4224. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  4225. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  4226. ';
  4227. $invoicePriceYear += $v ['invoicePrice'];
  4228. $receivablesPriceYear += $v ['receivablesPrice'];
  4229. $accountPriceYear += $v ['accountPrice'];
  4230. $flag = false;
  4231. break;
  4232. }
  4233. }
  4234. if ($flag) {
  4235. $html .= '<td class="taR"></td>
  4236. <td class="taR"></td>
  4237. <td class="taR"><b></b></td>
  4238. ';
  4239. }
  4240. }
  4241. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  4242. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  4243. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  4244. ';
  4245. $html .= '</tr>';
  4246. // print_r($isList);
  4247. $this->data ['html'] = $html;
  4248. $this->data ['LcategoryList'] = $LcategoryList;
  4249. $this->data ['isList'] = $isList;
  4250. $this->data ['year'] = $year;
  4251. $this->data ['memu'] = "invoice";
  4252. $this->data ['staff'] = $this->staff;
  4253. $this->data ['receiptMemu'] = 'invoiceAggregate';
  4254. $this->render ( "/admin/invoiceAggregate", $this->data );
  4255. }
  4256. function invoiceAggregateStaff() {
  4257. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  4258. Doo::loadModel ( 'invoiceStatistics' );
  4259. $invoiceStatistics = new invoiceStatistics ();
  4260. Doo::loadModel ( 'L_category' );
  4261. $Lcategory = new L_category ();
  4262. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year );
  4263. $staffList = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year );
  4264. $cStaff = $Lcategory->getCategoryStaff ();
  4265. $html = '';
  4266. foreach ( $cStaff as $key => $value ) {
  4267. $categoryFir = true;
  4268. foreach ( $value ['staff'] as $k => $v ) {
  4269. if ($categoryFir) {
  4270. $width = count ( $value ['staff'] ) + 1;
  4271. $html .= '<tr><th rowspan="' . $width . '">' . $value ['title'] . ' </th>';
  4272. $categoryFir = false;
  4273. } else
  4274. $html .= '<tr>';
  4275. $html .= '<th>' . $v ['username'] . '</th>';
  4276. $invoicePriceStaffYear = 0;
  4277. $receivablesPriceStaffYear = 0;
  4278. $accountPriceStaffYear = 0;
  4279. for($month = 1; $month <= 12; $month ++) {
  4280. $flag = true;
  4281. foreach ( $staffList ['statisticsMonthStaff'] as $sl => $slv ) {
  4282. if ($v ['sid'] == $slv ['staff'] && $month == $slv ['month']) {
  4283. $html .= '<td class="taR">¥' . $slv ['invoicePrice'] . '</td>
  4284. <td class="taR">¥' . $slv ['receivablesPrice'] . '</td>
  4285. <td class="taR"><b>¥' . $slv ['accountPrice'] . '</b></td>
  4286. ';
  4287. $invoicePriceStaffYear += $slv ['invoicePrice'];
  4288. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  4289. $accountPriceStaffYear += $slv ['accountPrice'];
  4290. $flag = false;
  4291. break;
  4292. }
  4293. }
  4294. if ($flag)
  4295. $html .= '<td class="taR"></td>
  4296. <td class="taR"></td>
  4297. <td class="taR"><b></b></td>
  4298. ';
  4299. }
  4300. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  4301. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  4302. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  4303. ';
  4304. }
  4305. $html .= '</tr>';
  4306. // 小计
  4307. if (! empty ( $value ['staff'] )) {
  4308. $html .= '<tr><th class="taR">小计</th>';
  4309. $invoicePriceStaffYear = 0;
  4310. $receivablesPriceStaffYear = 0;
  4311. $accountPriceStaffYear = 0;
  4312. for($month = 1; $month <= 12; $month ++) {
  4313. $flag = true;
  4314. foreach ( $staffList ['statisticsMonthCid'] as $smc => $smcv ) {
  4315. if ($value ['cid'] == $smcv ['cid'] && $month == $slv ['month']) {
  4316. $html .= '<td class="taR">¥' . $smcv ['invoicePrice'] . '</td>
  4317. <td class="taR">¥' . $smcv ['receivablesPrice'] . '</td>
  4318. <td class="taR"><b>¥' . $smcv ['accountPrice'] . '</b></td>
  4319. ';
  4320. $invoicePriceStaffYear += $slv ['invoicePrice'];
  4321. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  4322. $accountPriceStaffYear += $slv ['accountPrice'];
  4323. $flag = false;
  4324. break;
  4325. }
  4326. }
  4327. if ($flag)
  4328. $html .= '<td class="taR"></td>
  4329. <td class="taR"></td>
  4330. <td class="taR"><b></b></td>
  4331. ';
  4332. }
  4333. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  4334. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  4335. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  4336. ';
  4337. $html .= '</tr>';
  4338. }
  4339. }
  4340. $html .= '<tr class="warning"><th colspan="2"><b class="colGreen" >月合计</b></th>';
  4341. $invoicePriceYear = 0;
  4342. $receivablesPriceYear = 0;
  4343. $accountPriceYear = 0;
  4344. for($month = 1; $month <= 12; $month ++) {
  4345. $flag = true;
  4346. foreach ( $staffList ['statisticsMonth'] as $k => $v ) {
  4347. if ($month == $v ['month']) {
  4348. $html .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>
  4349. <td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>
  4350. <td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>
  4351. ';
  4352. $invoicePriceYear += $v ['invoicePrice'];
  4353. $receivablesPriceYear += $v ['receivablesPrice'];
  4354. $accountPriceYear += $v ['accountPrice'];
  4355. $flag = false;
  4356. break;
  4357. }
  4358. }
  4359. if ($flag)
  4360. $html .= '<td class="taR"></td>
  4361. <td class="taR"></td>
  4362. <td class="taR"><b></b></td>
  4363. ';
  4364. }
  4365. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  4366. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  4367. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  4368. ';
  4369. $html .= '</tr>';
  4370. $this->data ['html'] = $html;
  4371. $this->data ['isList'] = $toteList;
  4372. $this->data ['year'] = $year;
  4373. $this->data ['memu'] = "invoice";
  4374. $this->data ['staff'] = $this->staff;
  4375. $this->data ['receiptMemu'] = 'invoiceAggregate';
  4376. $this->render ( "/admin/invoiceAggregateStaff", $this->data );
  4377. }
  4378. function invoiceAggregateCategory() {
  4379. Doo::loadClass ( 'XDeode' );
  4380. $XDeode = new XDeode ( 5 );
  4381. $cid = $cidKey = isset ( $this->params ['cid'] ) ? $this->params ['cid'] : "";
  4382. $cid = $XDeode->decode ( $cid );
  4383. if (! is_numeric ( $cid ))
  4384. die ( 'illegal request' );
  4385. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  4386. Doo::loadModel ( 'invoiceStatistics' );
  4387. $invoiceStatistics = new invoiceStatistics ();
  4388. Doo::loadModel ( 'staff' );
  4389. $staff = new staff ();
  4390. $list = $staff->getStaffByCid ( $cid );
  4391. $isCategory = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year, $cid );
  4392. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year, $cid );
  4393. if (empty ( $list ))
  4394. die ( '该办事处没有成员' );
  4395. $htmlA = $htmlB = $htmlC = $html = '';
  4396. foreach ( $list as $key => $value ) {
  4397. $htmlA = '<tr><th rowspan="3">' . $value ['username'] . '</th><th class="taC">开票</th>';
  4398. $htmlB = '<tr><th class="taC">收款</th>';
  4399. $htmlC = '<tr><th class="taC">入账</th>';
  4400. $invoicePriceStaffYear = 0;
  4401. $receivablesPriceStaffYear = 0;
  4402. $accountPriceStaffYear = 0;
  4403. for($month = 1; $month <= 12; $month ++) {
  4404. $flag = true;
  4405. foreach ( $isCategory ['statisticsMonthStaff'] as $k => $v ) {
  4406. if ($value ['sid'] == $v ['staff'] && $month == $v ['month']) {
  4407. $htmlA .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>';
  4408. $htmlB .= '<td class="taR">¥' . $v ['receivablesPrice'] . '</td>';
  4409. $htmlC .= '<td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>';
  4410. $invoicePriceStaffYear += $v ['invoicePrice'];
  4411. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  4412. $accountPriceStaffYear += $v ['accountPrice'];
  4413. $flag = false;
  4414. break;
  4415. }
  4416. }
  4417. if ($flag) {
  4418. $htmlA .= '<td class="taR">-</td>';
  4419. $htmlB .= '<td class="taR">-</td>';
  4420. $htmlC .= '<td class="taR"><b>-</b></td>';
  4421. }
  4422. }
  4423. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  4424. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  4425. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  4426. $htmlA .= '</tr>';
  4427. $htmlB .= '</tr>';
  4428. $htmlC .= '</tr>';
  4429. $html .= $htmlA . $htmlB . $htmlC;
  4430. }
  4431. $htmlA = $htmlB = $htmlC = "";
  4432. $htmlA = '<tr><th rowspan="3">月合计</th><th class="taC">开票</th>';
  4433. $htmlB = '<tr><th class="taC">收款</th>';
  4434. $htmlC = '<tr><th class="taC">入账</th>';
  4435. $invoicePriceStaffYear = 0;
  4436. $receivablesPriceStaffYear = 0;
  4437. $accountPriceStaffYear = 0;
  4438. for($month = 1; $month <= 12; $month ++) {
  4439. $flag = true;
  4440. foreach ( $isCategory ['statisticsMonth'] as $k => $v ) {
  4441. if ($month == $v ['month']) {
  4442. $htmlA .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>';
  4443. $htmlB .= '<td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>';
  4444. $htmlC .= '<td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>';
  4445. $invoicePriceStaffYear += $v ['invoicePrice'];
  4446. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  4447. $accountPriceStaffYear += $v ['accountPrice'];
  4448. $flag = false;
  4449. break;
  4450. }
  4451. }
  4452. if ($flag) {
  4453. $htmlA .= '<td class="taR">-</td>';
  4454. $htmlB .= '<td class="taR">-</td>';
  4455. $htmlC .= '<td class="taR"><b>-</b></td>';
  4456. }
  4457. }
  4458. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  4459. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  4460. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  4461. $htmlA .= '</tr>';
  4462. $htmlB .= '</tr>';
  4463. $htmlC .= '</tr>';
  4464. $html .= $htmlA . $htmlB . $htmlC;
  4465. $this->data ['html'] = $html;
  4466. $this->data ['cidKey'] = $cidKey;
  4467. $this->data ['slist'] = $list;
  4468. $this->data ['isList'] = $toteList;
  4469. $this->data ['year'] = $year;
  4470. $this->data ['memu'] = "invoice";
  4471. $this->data ['staff'] = $this->staff;
  4472. $this->data ['receiptMemu'] = 'invoiceAggregate';
  4473. $this->render ( "/admin/invoiceAggregateCategory", $this->data );
  4474. }
  4475. /**
  4476. * 办事处汇总信息
  4477. */
  4478. function invoiceAggregateCategoryDetail() {
  4479. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  4480. Doo::loadClass ( 'XDeode' );
  4481. $XDeode = new XDeode ( 5 );
  4482. Doo::loadModel ( 'invoiceStatistics' );
  4483. $invoiceStatistics = new invoiceStatistics ();
  4484. Doo::loadModel ( 'L_category' );
  4485. $category = new L_category ();
  4486. Doo::loadModel ( 'invoice' );
  4487. $invoice = new invoice ();
  4488. Doo::loadModel ( 'staff' );
  4489. $staff = new staff ();
  4490. Doo::loadModel ( "invoiceCategoryManage" );
  4491. $invoiceCategoryManage = new invoiceCategoryManage ();
  4492. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4493. $cidList = array ();
  4494. foreach ( $imcStaff as $key => $value ) {
  4495. array_push ( $cidList, $value ['cid'] );
  4496. if (empty ( $cidKey ))
  4497. $cidKey = $XDeode->encode ( $value ['cid'] );
  4498. }
  4499. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  4500. $cid = $XDeode->decode ( $cidKey );
  4501. $month = date ( "m", strtotime ( "-1 month" ) );
  4502. $YearMonth = date ( "Y-m", strtotime ( "-1 month" ) );
  4503. $redis = new Redis ();
  4504. $redis->connect ( '127.0.0.1', '6379' );
  4505. $redisKey = ''; // date('Y-m-d').'_iacd_'.$cid;
  4506. $redisValue = ''; // $redis->lrange($redisKey, 0, -1);
  4507. if (empty ( $redisValue )) {
  4508. $isMC = $invoiceStatistics->getInvoiceStatistiscsMothByCategory ( $cid );
  4509. $schedule = $invoice->getInvoiceScheduleByCid ( $cid );
  4510. // 获得办事处人员下的汇总
  4511. $slist = $staff->getStaffByCid ( $cid );
  4512. $ismsbMonth = $invoiceStatistics->getISMSByCategoryByMonth ( $cid, $YearMonth ); // 上一个月的汇总
  4513. $ismsb = $invoiceStatistics->getISMSByCategory ( $cid ); // 当月汇总
  4514. $ISAS = $invoiceStatistics->getISASByCategory ( $cid ); // 全部汇总
  4515. $scheduleStaff = $invoice->getInvoiceScheduleByCidGroupSid ( $cid ); // 完成度
  4516. foreach ( $slist as $key => $value ) {
  4517. $slist [$key] ['invoicePrice'] = 0;
  4518. $slist [$key] ['receivablesPrice'] = 0;
  4519. $slist [$key] ['accountPrice'] = 0;
  4520. $slist [$key] ['invoiceAllPrice'] = 0;
  4521. $slist [$key] ['receivablesAllPrice'] = 0;
  4522. $slist [$key] ['accountAllPrice'] = 0;
  4523. $slist [$key] ['schedule'] = 0;
  4524. $slist [$key] ['invoiceMonthPrice'] = 0;
  4525. $slist [$key] ['receivablesMonthPrice'] = 0;
  4526. $slist [$key] ['accountMonthPrice'] = 0;
  4527. foreach ( $ismsbMonth as $y => $l ) {
  4528. if ($value ['sid'] == $l ['staff']) {
  4529. $slist [$key] ['invoiceMonthPrice'] = $l ['invoicePrice'];
  4530. $slist [$key] ['receivablesMonthPrice'] = $l ['receivablesPrice'];
  4531. $slist [$key] ['accountMonthPrice'] = $l ['accountPrice'];
  4532. }
  4533. }
  4534. foreach ( $ismsb as $k => $v ) {
  4535. if ($value ['sid'] == $v ['staff']) {
  4536. $slist [$key] ['invoicePrice'] = $v ['invoicePrice'];
  4537. $slist [$key] ['receivablesPrice'] = $v ['receivablesPrice'];
  4538. $slist [$key] ['accountPrice'] = $v ['accountPrice'];
  4539. }
  4540. }
  4541. foreach ( $ISAS as $e => $a ) {
  4542. if ($value ['sid'] == $a ['staff']) {
  4543. $slist [$key] ['invoiceAllPrice'] = $a ['invoicePrice'];
  4544. $slist [$key] ['receivablesAllPrice'] = $a ['receivablesPrice'];
  4545. $slist [$key] ['accountAllPrice'] = $a ['accountPrice'];
  4546. }
  4547. }
  4548. if (isset ( $scheduleStaff [$value ['sid']] ))
  4549. $slist [$key] ['schedule'] = $scheduleStaff [$value ['sid']];
  4550. }
  4551. $this->data ['cidKey'] = $cidKey;
  4552. $schedule = ( int ) ($schedule * 100);
  4553. $this->data ['slist'] = $slist;
  4554. $this->data ['isMC'] = $isMC;
  4555. $this->data ['schedule'] = $schedule;
  4556. $slist = json_encode ( $slist );
  4557. $isMC = json_encode ( $isMC );
  4558. $schedule = json_encode ( $schedule );
  4559. $redis->lpush ( $redisKey, $slist );
  4560. $redis->lpush ( $redisKey, $isMC );
  4561. $redis->lpush ( $redisKey, $schedule );
  4562. } else {
  4563. $this->data ['cidKey'] = $cidKey;
  4564. $this->data ['slist'] = json_decode ( $redisValue [2], true );
  4565. $this->data ['isMC'] = json_decode ( $redisValue [1], true );
  4566. $this->data ['schedule'] = json_decode ( $redisValue [0], true );
  4567. }
  4568. $this->data ['month'] = $month;
  4569. $this->data ['categoryList'] = $categoryList;
  4570. $this->data ['memu'] = "invoice";
  4571. $this->data ['staff'] = $this->staff;
  4572. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4573. $this->render ( "/admin/invoiceAggregateCategoryDetail", $this->data );
  4574. }
  4575. /**
  4576. * 办事处人员汇总详情
  4577. */
  4578. function invoiceAggregateStaffDetail() {
  4579. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  4580. // $sidKey = isset ( $this->params ['sidKey'] ) ? $this->params ['sidKey'] : '';
  4581. Doo::loadClass ( 'XDeode' );
  4582. $XDeode = new XDeode ( 5 );
  4583. Doo::loadModel ( 'invoice' );
  4584. $invoice = new invoice ();
  4585. Doo::loadModel ( 'staff' );
  4586. $staff = new staff ();
  4587. Doo::loadModel ( "invoiceCategoryManage" );
  4588. $invoiceCategoryManage = new invoiceCategoryManage ();
  4589. $sid = $XDeode->decode ( $sidKey );
  4590. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4591. $cidList = array ();
  4592. foreach ( $imcStaff as $key => $value ) {
  4593. array_push ( $cidList, $value ['cid'] );
  4594. if (empty ( $cidKey ))
  4595. $cidKey = $XDeode->encode ( $value ['cid'] );
  4596. }
  4597. $cidString = implode ( ',', $cidList );
  4598. $staffList = $staff->getStaffInCid ( $cidString );
  4599. $staffDetail = $staff->getStaffBySid ( $sid );
  4600. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4601. $page_size = 18;
  4602. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4603. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4604. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  4605. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  4606. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  4607. $dateArr = explode ( ':', $date );
  4608. $D1 = '';
  4609. $D2 = '';
  4610. if (! empty ( $date )) {
  4611. $D1 = $dateArr [0] . " 00:00:00 ";
  4612. if (isset ( $dateArr [1] ))
  4613. $D2 = $dateArr [1] . " 23:59:59 ";
  4614. else
  4615. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4616. // $D2 = $dateArr [1];
  4617. }
  4618. $con = ' status=2 ';
  4619. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4620. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4621. if ($status == 'UNRECORD')
  4622. $con .= ' and printStatus=1 and untreadStatus=0';
  4623. elseif ($status == 'RECORD')
  4624. $con .= ' and printStatus=1 and untreadStatus=3';
  4625. elseif ($status == 'BOUNCED')
  4626. $con .= ' and untreadStatus=2';
  4627. elseif ($status == 'PARTRECORD')
  4628. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  4629. elseif ($status == 'All') {
  4630. $con .= ' and ( untreadStatus=2 or untreadStatus=0 or untreadStatus=3 )';
  4631. }
  4632. $con .= ' and sid=' . $sid;
  4633. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  4634. if (! empty ( $MebSea )) {
  4635. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  4636. }
  4637. $pageinfo ['page'] = array (
  4638. 'previous' => ''
  4639. );
  4640. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateStaffDetail", $get, "" );
  4641. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4642. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  4643. $this->data ['staffDetail'] = $staffDetail;
  4644. $this->data ['staffList'] = $staffList;
  4645. $this->data ['MebSeaEn'] = $MebSea;
  4646. $this->data ['MebSea'] = urlencode ( $MebSea );
  4647. $this->data ['date'] = $date;
  4648. $this->data ['page'] = $pageinfo;
  4649. $this->data ['get'] = $get;
  4650. $this->data ['list'] = $list;
  4651. $this->data ['status'] = $status;
  4652. $this->data ['sidKey'] = $sidKey;
  4653. $this->data ['memu'] = "invoice";
  4654. $this->data ['staff'] = $this->staff;
  4655. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4656. $this->render ( "/admin/invoiceAggregateStaffDetail", $this->data );
  4657. }
  4658. /**
  4659. * 办事处人员汇总收款情
  4660. */
  4661. function invoiceAggregateStaffReceivablesDetail() {
  4662. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  4663. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  4664. Doo::loadModel ( 'invoiceReceivables' );
  4665. $invoiceReceivables = new invoiceReceivables ();
  4666. Doo::loadModel ( 'staff' );
  4667. $staff = new staff ();
  4668. Doo::loadModel ( "invoiceCategoryManage" );
  4669. $invoiceCategoryManage = new invoiceCategoryManage ();
  4670. Doo::loadClass ( 'XDeode' );
  4671. $XDeode = new XDeode ( 5 );
  4672. $sid = $XDeode->decode ( $sidKey );
  4673. $staffDetail = $staff->getStaffBySid ( $sid );
  4674. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4675. $cidList = array ();
  4676. foreach ( $imcStaff as $key => $value ) {
  4677. array_push ( $cidList, $value ['cid'] );
  4678. if (empty ( $cidKey ))
  4679. $cidKey = $XDeode->encode ( $value ['cid'] );
  4680. }
  4681. $cidString = implode ( ',', $cidList );
  4682. $staffList = $staff->getStaffInCid ( $cidString );
  4683. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4684. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  4685. $page_size = 10;
  4686. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4687. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4688. if ($timeType == "BINDOTP") {
  4689. $status = 'Credited';
  4690. }
  4691. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  4692. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  4693. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  4694. $dateArr = explode ( ':', $date );
  4695. $D1 = '';
  4696. $D2 = '';
  4697. if (! empty ( $date )) {
  4698. $D1 = $dateArr [0] . " 00:00:00 ";
  4699. if (isset ( $dateArr [1] ))
  4700. $D2 = $dateArr [1] . " 23:59:59 ";
  4701. else
  4702. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4703. }
  4704. $con = ' a.receivablesStaff like "%' . $staffDetail ['username'] . '%" ';
  4705. $descField = 'a.bindDate';
  4706. if ($timeType == 'CREATE')
  4707. $descField = 'a.date';
  4708. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4709. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4710. elseif (! empty ( $D1 ) && empty ( $D2 ))
  4711. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  4712. if ($status == 'Unclaimed')
  4713. $con .= ' and a.bindStatus=0';
  4714. elseif ($status == 'Credited')
  4715. $con .= ' and a.bindStatus=1';
  4716. elseif ($status == 'Claim')
  4717. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  4718. elseif ($status == 'BBN')
  4719. $con .= ' and a.bindPrice>a.receivablesPrice';
  4720. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  4721. if (! empty ( $MebSea )) {
  4722. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" )';
  4723. }
  4724. $pageinfo ['page'] = array (
  4725. 'previous' => ''
  4726. );
  4727. // $sql = 'select group_concat(b.invoiceSerial) as invoiceSerial ,group_concat(b.iid) as invoiceId
  4728. // from CLD_invoiceReceivables as a left join CLD_invoice as b on
  4729. // find_in_set(b.iid,a.iidExtend) or a.iid=b.iid
  4730. // where ' . $con . ' group by a.irid ';
  4731. $pageinfo =$this->get_page ( "CLD_invoiceReceivables as a", $con, $page, $page_size, "invoiceAggregateStaffReceivablesDetail", $get, "" );
  4732. //$pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceAggregateStaffReceivablesDetail", $get, "" );
  4733. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4734. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', $descField);
  4735. foreach ( $list as $key => $value ) {
  4736. $list [$key] ['category'] = '';
  4737. if ($value ['receivablesCategory'] != 'PUBLIC') {
  4738. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  4739. $list [$key] ['category'] = $receivablesCategory [1];
  4740. }
  4741. }
  4742. // print_r($list);
  4743. $this->data ['staffDetail'] = $staffDetail;
  4744. $this->data ['sidKey'] = $sidKey;
  4745. $this->data ['staffList'] = $staffList;
  4746. $this->data ['timeType'] = $timeType;
  4747. $this->data ['MebSeaEn'] = $MebSea;
  4748. $this->data ['MebSea'] = urlencode ( $MebSea );
  4749. $this->data ['date'] = $date;
  4750. $this->data ['page'] = $pageinfo;
  4751. $this->data ['get'] = $get;
  4752. $this->data ['list'] = $list;
  4753. $this->data ['status'] = $status;
  4754. $this->data ['memu'] = "invoice";
  4755. $this->data ['staff'] = $this->staff;
  4756. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4757. $this->render ( "/admin/invoiceAggregateStaffReceivablesDetail", $this->data );
  4758. }
  4759. function invoiceAchieve() {
  4760. Doo::loadModel ( 'invoice' );
  4761. $invoice = new invoice ();
  4762. Doo::loadClass ( 'XDeode' );
  4763. $XDeode = new XDeode ( 5 );
  4764. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4765. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4766. $page_size = 18;
  4767. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4768. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4769. $get = "/" . $date;
  4770. $con = '';
  4771. if ($date == 'MONTHO')
  4772. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4773. elseif ($date == 'MONTHT')
  4774. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4775. elseif ($date == 'MONTHY')
  4776. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4777. if (! empty ( $MebSea )) {
  4778. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4779. $get .= "/" . $MebSea;
  4780. }
  4781. $pageinfo ['page'] = array (
  4782. 'previous' => ''
  4783. );
  4784. $sql = 'status=2 and printStatus=1 and irid!="" and ( untreadStatus=3 or untreadStatus=0 ) and sid=' . $sid . $con;
  4785. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceAchieve", $get, "" );
  4786. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4787. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  4788. // print_r($pageinfo);
  4789. $this->data ['MebSeaEn'] = $MebSea;
  4790. $this->data ['MebSea'] = urlencode ( $MebSea );
  4791. $this->data ['get'] = $get;
  4792. $this->data ['page'] = $pageinfo;
  4793. $this->data ['list'] = $list;
  4794. $this->data ['date'] = $date;
  4795. $this->data ['memu'] = "invoice";
  4796. $this->data ['staff'] = $this->staff;
  4797. $this->data ['receiptMemu'] = 'invoice';
  4798. $this->render ( "/admin/invoiceAchieve", $this->data );
  4799. }
  4800. /**
  4801. */
  4802. function invoiceMyUnAccountAchieve() {
  4803. Doo::loadModel ( 'invoice' );
  4804. $invoice = new invoice ();
  4805. Doo::loadClass ( 'XDeode' );
  4806. $XDeode = new XDeode ( 5 );
  4807. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4808. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4809. $page_size = 18;
  4810. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4811. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4812. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4813. $dateArr = explode ( ':', $date );
  4814. $D1 = '';
  4815. $D2 = '';
  4816. if (! empty ( $date )) {
  4817. $D1 = $dateArr [0];
  4818. $D2 = $dateArr [1];
  4819. }
  4820. $con = '';
  4821. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4822. $con = ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4823. if (! empty ( $MebSea )) {
  4824. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4825. }
  4826. $pageinfo ['page'] = array (
  4827. 'previous' => ''
  4828. );
  4829. // and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  4830. $sql = " status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid= " . $sid . $con;
  4831. $action = "invoiceMyUnAccountAchieve";
  4832. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  4833. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4834. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 'desc', 'printTime' );
  4835. Doo::loadModel ( 'express' );
  4836. $express = new express ();
  4837. $expressList = $express->getExpressByAll ();
  4838. $this->data ['expressList'] = $expressList;
  4839. // print_r($list);
  4840. $this->data ['MebSeaEn'] = $MebSea;
  4841. $this->data ['get'] = $get;
  4842. $this->data ['page'] = $pageinfo;
  4843. $this->data ['date'] = $date;
  4844. $this->data ['list'] = $list;
  4845. $this->data ['memu'] = "invoice";
  4846. $this->data ['staff'] = $this->staff;
  4847. $this->data ['receiptMemu'] = 'invoice';
  4848. $this->render ( "/admin/invoiceMyUnAccountAchieve", $this->data );
  4849. }
  4850. function invoiceReceivablesAchieve() {
  4851. Doo::loadModel ( 'invoiceReceivables' );
  4852. $invoiceReceivables = new invoiceReceivables ();
  4853. Doo::loadClass ( 'XDeode' );
  4854. $XDeode = new XDeode ( 5 );
  4855. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4856. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  4857. $page_size = 12;
  4858. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4859. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4860. $get = "/" . $date;
  4861. $con = '';
  4862. if ($date == 'MONTHO')
  4863. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4864. elseif ($date == 'MONTHT')
  4865. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4866. elseif ($date == 'MONTHY')
  4867. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4868. if (! empty ( $MebSea )) {
  4869. $con .= ' and ( receivablesMessage like "%' . $MebSea . '%" or receivablesPrice like "%' . $MebSea . '%" )';
  4870. $get .= "/" . $MebSea;
  4871. }
  4872. $pageinfo ['page'] = array (
  4873. 'previous' => ''
  4874. );
  4875. $sql = " bindStatus=1 and receivablesStaff like '" . $sid . "-%' " . $con;
  4876. $pageinfo = $this->get_page ( "CLD_invoiceReceivables", $sql, $page, $page_size, "invoiceReceivablesAchieve", $get, "" );
  4877. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4878. $list = $invoiceReceivables->getReceivablesByUntreadStatusPage ( $limit, $sql );
  4879. // print_r($pageinfo);
  4880. $this->data ['MebSeaEn'] = $MebSea;
  4881. $this->data ['MebSea'] = urlencode ( $MebSea );
  4882. $this->data ['get'] = $get;
  4883. $this->data ['page'] = $pageinfo;
  4884. $this->data ['list'] = $list;
  4885. $this->data ['date'] = $date;
  4886. $this->data ['memu'] = "invoice";
  4887. $this->data ['staff'] = $this->staff;
  4888. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  4889. $this->render ( "/admin/invoiceReceivablesAchieve", $this->data );
  4890. }
  4891. /**
  4892. * 收款解绑
  4893. */
  4894. function invoiceUnBundLing() {
  4895. $unBundKey = $this->get_args ( 'unBundKey' ) ? $this->get_args ( 'unBundKey' ) : '';
  4896. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  4897. Doo::loadModel ( 'invoice' );
  4898. $invoice = new invoice ();
  4899. Doo::loadModel ( 'invoiceReceivables' );
  4900. $invoiceReceivables = new invoiceReceivables ();
  4901. Doo::loadModel ( 'invoiceOperationLog' );
  4902. $invoiceOperationLog = new invoiceOperationLog ();
  4903. Doo::loadModel ( 'invoiceROLog' );
  4904. $invoiceROLog = new invoiceROLog ();
  4905. Doo::loadModel ( 'invoiceStatistics' );
  4906. Doo::loadClass ( 'XDeode' );
  4907. $XDeode = new XDeode ( 5 );
  4908. if (empty ( $iidKey ) || empty ( $unBundKey ))
  4909. die ( 'illegal request' );
  4910. $iid = $XDeode->decode ( $iidKey );
  4911. $irid = $invoice->authcode ( $unBundKey );
  4912. if ((! empty ( $irid ) && ! is_numeric ( $irid )) || (! empty ( $iid ) && ! is_numeric ( $iid )))
  4913. die ( 'illegal request' );
  4914. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4915. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  4916. if (empty ( $irDetails ) || empty ( $invoiceDetails ) || (empty ( $irDetails ['iid'] ) && empty ( $irDetails ['iidExtend'] )) || $invoiceDetails ['untreadStatus'] == 2)
  4917. die ( 'illegal request' );
  4918. // 收款
  4919. $item = array (
  4920. 'irid' => $irDetails ['irid'],
  4921. 'bindPrice' => $irDetails ['bindPrice'] - $invoiceDetails ['invoicePrice'],
  4922. 'bindStatus' => 0
  4923. );
  4924. if ($irDetails ['iid'] == $iid)
  4925. $item += array (
  4926. 'iid' => 0
  4927. );
  4928. else {
  4929. $iidExtend = explode ( ',', $irDetails ['iidExtend'] );
  4930. foreach ( $iidExtend as $key => $value ) {
  4931. if ($value == $iid)
  4932. unset ( $iidExtend [$key] );
  4933. }
  4934. $iidExtend = implode ( ',', $iidExtend );
  4935. $item += array (
  4936. 'iidExtend' => $iidExtend
  4937. );
  4938. }
  4939. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4940. // 收款操作日志
  4941. $item = array (
  4942. 'operation' => $this->staff [0] ['username'] . " 解绑 " . $irDetails ['receivablesSerial'],
  4943. 'date' => date ( "Y-m-d" ),
  4944. 'status' => 3,
  4945. 'img' => $this->staff [0] ['avatar'],
  4946. 'username' => $this->staff [0] ['username'],
  4947. 'uid' => $this->staff [0] ['sid'],
  4948. 'category' => $this->staff [0] ['category'],
  4949. 'irid' => $irid
  4950. );
  4951. $invoiceROLog->setInvoiceROLog ( $item );
  4952. // 扣除入账统计金额
  4953. $invoiceStatistics = new invoiceStatistics ();
  4954. $item = array (
  4955. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  4956. 'priceClass' => 3,
  4957. 'cid' => $invoiceDetails ['cid'],
  4958. 'staff' => $invoiceDetails ['sid'],
  4959. 'accountPrice' => - $invoiceDetails ['invoicePrice']
  4960. );
  4961. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4962. // 扣除收款统计金额
  4963. $invoiceStatistics = new invoiceStatistics ();
  4964. $item = array (
  4965. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  4966. 'priceClass' => 2,
  4967. 'cid' => $invoiceDetails ['cid'],
  4968. 'staff' => $invoiceDetails ['sid'],
  4969. 'irid' => $irDetails ['irid'],
  4970. 'receivablesPrice' => - $invoiceDetails ['invoicePrice']
  4971. );
  4972. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4973. // 发票解绑去收款ID
  4974. $iridString = $invoiceDetails ['irid'];
  4975. if (! empty ( $invoiceDetails ['irid'] )) {
  4976. $list = explode ( ',', $invoiceDetails ['irid'] );
  4977. foreach ( $list as $key => $value ) {
  4978. if ($value == $irDetails ['irid']) {
  4979. unset ( $list [$key] );
  4980. break;
  4981. }
  4982. }
  4983. $iridString = implode ( ",", $list );
  4984. }
  4985. $item = array (
  4986. 'iid' => $invoiceDetails ['iid'],
  4987. 'irid' => $iridString,
  4988. 'updateTime' => date ( "Y-m-d H:i:s" )
  4989. );
  4990. if ($invoiceDetails ['untreadStatus'] == 3)
  4991. $item += array (
  4992. 'untreadStatus' => 0
  4993. );
  4994. $invoice->setInvoiceByCondition ( $item );
  4995. Doo::loadModel ( 'bill' );
  4996. $bill = new bill ();
  4997. $bill->iid=$invoiceDetails ['iid'];
  4998. $bill->trainId=$invoiceDetails['trainId'];
  4999. $bill->irid=$irDetails ['irid'];
  5000. $bill->create_time=date ( "Y-m-d H:i:s" );
  5001. $bill->price=-$invoiceDetails ['invoicePrice'];
  5002. $bill->remark='解绑-扣除入账';
  5003. $bill->insert ();
  5004. $item = array (
  5005. 'date' => date ( "Y-m-d H:i:s" ),
  5006. 'operation' => '解绑 收款 ' . $irDetails ['receivablesSerial'],
  5007. 'status' => 11,
  5008. 'img' => $this->staff [0] ['avatar'],
  5009. 'username' => $this->staff [0] ['username'],
  5010. 'uid' => $this->staff [0] ['sid'],
  5011. 'category' => $this->staff [0] ['category'],
  5012. 'iid' => $invoiceDetails ['iid']
  5013. );
  5014. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  5015. // 公司流水-解绑时删除流水
  5016. // Doo::loadModel ( 'wasteBook' );
  5017. // $wasteBook = new wasteBook ();
  5018. // $wasteBook->delete ( array (
  5019. // 'where' => 'dataID=' . $irDetails ['irid'] . ' and accountType=7',
  5020. // 'limit' => 1
  5021. // ) );
  5022. // 银行
  5023. /*
  5024. * $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); }
  5025. */
  5026. return "/invoiceReceivablesAS";
  5027. }
  5028. /**
  5029. * 或者该收款下的所以发票
  5030. */
  5031. function ajaxGetInvoiceReceivablesByInvoice() {
  5032. $irid = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : '';
  5033. Doo::loadModel ( 'invoice' );
  5034. $invoice = new invoice ();
  5035. Doo::loadModel ( 'invoiceReceivables' );
  5036. $invoiceReceivables = new invoiceReceivables ();
  5037. $irid = $invoice->authcode ( $irid );
  5038. if (! empty ( $irid ) && ! is_numeric ( $irid ))
  5039. die ( 'illegal request' );
  5040. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5041. $iidString = $irDetails ['iid'];
  5042. $iidExtend = array_filter ( explode ( ',', $irDetails ['iidExtend'] ) );
  5043. if (! empty ( $irDetails ['iidExtend'] ))
  5044. $iidString .= ',' . implode ( ',', $iidExtend );
  5045. $invoiceList = $invoice->getInvoiceInIid ( $iidString, 'iid,invoiceSerial,invoicePrice,invoiceTitle,invoiceCompany,invoiceElement' );
  5046. $html = "";
  5047. foreach ( $invoiceList as $key => $value ) {
  5048. $title = $value ['invoiceTitle'];
  5049. if (! empty ( $value ['invoiceCompany'] ))
  5050. $title = $value ['invoiceCompany'];
  5051. $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>';
  5052. }
  5053. echo json_encode ( array (
  5054. 'status' => 1,
  5055. 'html' => $html
  5056. ) );
  5057. }
  5058. /**
  5059. * 发票管理
  5060. */
  5061. function invoiceAS() {
  5062. Doo::loadModel ( 'invoice' );
  5063. $invoice = new invoice ();
  5064. Doo::loadModel ( 'invoiceReceivables' );
  5065. $invoiceReceivables = new invoiceReceivables ();
  5066. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  5067. $page_size = 18;
  5068. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5069. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  5070. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5071. $dateArr = explode ( ':', $date );
  5072. $D1 = '';
  5073. $D2 = '';
  5074. if (! empty ( $date )) {
  5075. $D1 = $dateArr [0] . " 00:00:00 ";
  5076. if (isset ( $dateArr [1] ))
  5077. $D2 = $dateArr [1] . " 23:59:59 ";
  5078. else
  5079. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  5080. // $D2 = $dateArr [1];
  5081. }
  5082. $con = ' status=2 ';
  5083. if (! empty ( $D1 ) && ! empty ( $D2 ))
  5084. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  5085. if ($status == 'UNRECORD')
  5086. $con .= ' and printStatus=1 and untreadStatus=0';
  5087. elseif ($status == 'RECORD')
  5088. $con .= ' and printStatus=1 and untreadStatus=3';
  5089. elseif ($status == 'BOUNCED')
  5090. $con .= ' and untreadStatus=2';
  5091. elseif ($status == 'PARTRECORD')
  5092. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  5093. elseif ($status == 'All') {
  5094. $con .= ' and ( untreadStatus=2 or untreadStatus=1 or untreadStatus=0 or untreadStatus=3 )';
  5095. }
  5096. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  5097. if (! empty ( $MebSea )) {
  5098. $con .= ' and ( invoiceSerial like "%' . $MebSea . '%" or invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  5099. }
  5100. $pageinfo ['page'] = array (
  5101. 'previous' => ''
  5102. );
  5103. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAS", $get, "" );
  5104. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5105. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  5106. $this->data ['MebSeaEn'] = $MebSea;
  5107. $this->data ['MebSea'] = urlencode ( $MebSea );
  5108. $this->data ['date'] = $date;
  5109. $this->data ['page'] = $pageinfo;
  5110. $this->data ['get'] = $get;
  5111. $this->data ['list'] = $list;
  5112. $this->data ['status'] = $status;
  5113. $this->data ['memu'] = "invoice";
  5114. $this->data ['staff'] = $this->staff;
  5115. $this->data ['receiptMemu'] = 'invoiceReceivables';
  5116. $this->render ( "/admin/invoiceAS", $this->data );
  5117. }
  5118. /**
  5119. * 收款管理
  5120. */
  5121. function invoiceReceivablesAS() {
  5122. Doo::loadModel ( 'invoiceReceivables' );
  5123. $invoiceReceivables = new invoiceReceivables ();
  5124. Doo::loadModel ( 'L_category' );
  5125. $lCategory = new L_category ();
  5126. $category = $lCategory->getCategory ();
  5127. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  5128. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  5129. $page_size = 10;
  5130. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5131. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  5132. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5133. $dateArr = explode ( ':', $date );
  5134. $D1 = '';
  5135. $D2 = '';
  5136. if (! empty ( $date )) {
  5137. $D1 = $dateArr [0]; // ." 00:00:00 ";
  5138. if (isset ( $dateArr [1] ))
  5139. $D2 = $dateArr [1]; // ." 23:59:59 ";
  5140. else
  5141. $D2 = $dateArr [0]; // ." 23:59:59 ";//date ( "Y-m-d" );
  5142. }
  5143. $descField = 'a.receivablesDate';
  5144. if ($timeType == 'CREATE')
  5145. $descField = 'a.date';
  5146. $con = ' 1 ';
  5147. if (! empty ( $D1 ) && ! empty ( $D2 ))
  5148. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  5149. elseif (! empty ( $D1 ) && empty ( $D2 ))
  5150. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  5151. if ($status == 'Unclaimed')
  5152. $con .= ' and a.bindStatus=0';
  5153. elseif ($status == 'Credited')
  5154. $con .= ' and a.bindStatus=1';
  5155. elseif ($status == 'Claim')
  5156. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  5157. elseif ($status == 'BBN')
  5158. $con .= ' and a.bankBatchNumber!=""';
  5159. elseif ($status == 'REFUND')
  5160. $con .= ' and ( (a.bindStatus=0 and a.refundLog!="" ) or a.bindStatus=2)';
  5161. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  5162. if (! empty ( $MebSea )) {
  5163. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" or a.receivablesSerial like "%' . $MebSea . '%" )';
  5164. }
  5165. $pageinfo ['page'] = array (
  5166. 'previous' => ''
  5167. );
  5168. // if(!empty($con)){
  5169. // $con=' where 1 '.$con;
  5170. // }
  5171. // $sql = 'select a.iid from CLD_invoiceReceivables as a
  5172. // ' . $con ;
  5173. $pageinfo =$this->get_page ( "CLD_invoiceReceivables as a", $con, $page, $page_size, "invoiceReceivablesAS", $get, "" );
  5174. //echo $sql;
  5175. //$pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceReceivablesAS", $get, "" );
  5176. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5177. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', $descField );
  5178. foreach ( $list as $key => $value ) {
  5179. $list [$key] ['category'] = '';
  5180. if ($value ['receivablesCategory'] != 'PUBLIC') {
  5181. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  5182. $list [$key] ['category'] = $receivablesCategory [1];
  5183. }
  5184. }
  5185. // print_r($list);
  5186. $this->data ['category'] = $category;
  5187. $this->data ['timeType'] = $timeType;
  5188. $this->data ['MebSeaEn'] = $MebSea;
  5189. $this->data ['MebSea'] = urlencode ( $MebSea );
  5190. $this->data ['date'] = $date;
  5191. $this->data ['page'] = $pageinfo;
  5192. $this->data ['get'] = $get;
  5193. $this->data ['list'] = $list;
  5194. $this->data ['status'] = $status;
  5195. $this->data ['memu'] = "invoice";
  5196. $this->data ['staff'] = $this->staff;
  5197. $this->data ['receiptMemu'] = 'invoiceReceivables';
  5198. $this->render ( "/admin/invoiceReceivablesAS", $this->data );
  5199. }
  5200. /**
  5201. * 删除一条收款
  5202. */
  5203. function delInvoiceReceivables() {
  5204. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  5205. if (empty ( $iridKey ))
  5206. die ( 'illegal request' );
  5207. Doo::loadClass ( 'XDeode' );
  5208. $XDeode = new XDeode ( 5 );
  5209. $irid = $XDeode->decode ( $iridKey );
  5210. Doo::loadModel ( 'invoiceReceivables' );
  5211. $invoiceReceivables = new invoiceReceivables ();
  5212. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5213. if (empty ( $detail ))
  5214. die ( 'illegal request' );
  5215. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  5216. // 扣除收款汇总信息 汇总
  5217. Doo::loadModel ( 'invoiceStatistics' );
  5218. $invoiceStatistics = new invoiceStatistics ();
  5219. $item = array (
  5220. 'date' => $detail ['receivablesDate'],
  5221. 'priceClass' => 2,
  5222. 'irid' => $detail ['irid'],
  5223. 'receivablesPrice' => - $detail ['receivablesPrice']
  5224. );
  5225. if ($detail ['receivablesCategory'] != 'PUBLIC') {
  5226. $receivablesCategory = explode ( ":", $detail ['receivablesCategory'] );
  5227. $item += array (
  5228. 'cid' => $receivablesCategory [0]
  5229. );
  5230. }
  5231. if ($detail ['receivablesStaff'] != 'PUBLIC') {
  5232. $receivablesStaff = explode ( "-", $detail ['receivablesStaff'] );
  5233. $item += array (
  5234. 'staff' => $receivablesStaff [0]
  5235. );
  5236. }
  5237. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  5238. return '/invoiceReceivablesAS';
  5239. }
  5240. /**
  5241. * 添加退款信息
  5242. */
  5243. function setInvoiceReceivablesRefund() {
  5244. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5245. $refundType = $this->get_args ( 'refundType' ) && is_numeric ( $this->get_args ( 'refundType' ) ) ? $this->get_args ( 'refundType' ) : '0';
  5246. $refundCompany = $this->get_args ( 'refundCompany' ) ? $this->get_args ( 'refundCompany' ) : "";
  5247. $refundNumber = $this->get_args ( 'refundNumber' ) ? $this->get_args ( 'refundNumber' ) : "";
  5248. $refundPrice = $this->get_args ( 'refundPrice' ) ? $this->get_args ( 'refundPrice' ) : "";
  5249. $refundRemarks = $this->get_args ( 'refundRemarks' ) ? $this->get_args ( 'refundRemarks' ) : "";
  5250. if ($refundPrice < 0)
  5251. die ( 'illegal request' );
  5252. if (! empty ( $iridKey ) && ! empty ( $refundCompany ) && ! empty ( $refundNumber ) && ! empty ( $refundPrice )) {
  5253. Doo::loadModel ( 'invoiceReceivables' );
  5254. $invoiceReceivables = new invoiceReceivables ();
  5255. Doo::loadModel ( 'invoiceRefund' );
  5256. $invoiceRefund = new invoiceRefund ();
  5257. $irid = $invoiceReceivables->authcode ( $iridKey );
  5258. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5259. if ($irDetail ['receivablesPrice'] < $refundPrice)
  5260. die ( 'illegal request' );
  5261. $invoiceReceivables = new invoiceReceivables ();
  5262. $refundLog = $this->staff [0] ['username'] . ' 退款 <b class="colRed">¥' . $refundPrice . '</b>
  5263. <br/><a href="#refunded" onclick="getRefundByDetail(\'' . $iridKey . '\')" data-toggle="modal">退款信息</a> <br/>' . date ( "Y-m-d H:i:s" ) . '
  5264. ';
  5265. $item = array (
  5266. 'irid' => $irid,
  5267. 'refundCompany' => $refundCompany,
  5268. 'refundNumber' => $refundNumber,
  5269. 'refundPrice' => $refundPrice,
  5270. 'refundRemarks' => $refundRemarks,
  5271. 'refundLog' => $refundLog
  5272. );
  5273. if ($refundType == 1) {
  5274. $item += array (
  5275. 'refundType' => $refundType,
  5276. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice,
  5277. 'bindStatus' => 2
  5278. );
  5279. } elseif ($refundType == 0 && $irDetail ['receivablesPrice'] <= $refundPrice) {
  5280. $item += array (
  5281. 'refundType' => 1,
  5282. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice,
  5283. 'bindStatus' => 2
  5284. );
  5285. } else {
  5286. $item += array (
  5287. 'refundType' => $refundType,
  5288. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice
  5289. );
  5290. }
  5291. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  5292. // 添加退款记录
  5293. $item = array (
  5294. 'irid' => $irid,
  5295. 'refundType' => $refundType,
  5296. 'refundCompany' => $refundCompany,
  5297. 'refundNumber' => $refundNumber,
  5298. 'refundPrice' => $refundPrice,
  5299. 'refundLog' => $refundLog,
  5300. 'refundRemarks' => $refundRemarks,
  5301. 'date' => date ( "Y-m-d H:i:s" )
  5302. );
  5303. $invoiceRefund->addInvoiceRefund ( $item );
  5304. // 扣除收款汇总信息 汇总
  5305. Doo::loadModel ( 'invoiceStatistics' );
  5306. $invoiceStatistics = new invoiceStatistics ();
  5307. $item = array (
  5308. 'date' => $irDetail ['receivablesDate'],
  5309. 'priceClass' => 2,
  5310. 'irid' => $irDetail ['irid'],
  5311. 'receivablesPrice' => - $refundPrice
  5312. );
  5313. if ($irDetail ['receivablesCategory'] != 'PUBLIC') {
  5314. $receivablesCategory = explode ( ":", $irDetail ['receivablesCategory'] );
  5315. $item += array (
  5316. 'cid' => $receivablesCategory [0]
  5317. );
  5318. }
  5319. if ($irDetail ['receivablesStaff'] != 'PUBLIC') {
  5320. $receivablesStaff = explode ( "-", $irDetail ['receivablesStaff'] );
  5321. $item += array (
  5322. 'staff' => $receivablesStaff [0]
  5323. );
  5324. }
  5325. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  5326. // 公司日常支出流水
  5327. Doo::loadModel ( 'wasteBook' );
  5328. $wasteBook = new wasteBook ();
  5329. $accountBank = '';
  5330. if ($irDetail ['receivablesBank'] == '纵横广发') {
  5331. $accountBank = 'CGBDeposit';
  5332. } elseif ($irDetail ['receivablesBank'] == '纵横工行') {
  5333. $accountBank = 'ICBCDeposit';
  5334. } elseif ($irDetail ['receivablesBank'] == '华润银行') {
  5335. $accountBank = 'HUADeposit';
  5336. } elseif ($irDetail ['receivablesBank'] == '个人广发') {
  5337. $accountBank = 'PersonalDeposit';
  5338. }
  5339. $itemWaste = array (
  5340. 'accountPrice' => - $refundPrice,
  5341. 'expensesType' => 2,
  5342. 'accountType' => 11,
  5343. 'accountPriceShow' => $refundPrice,
  5344. 'dataID' => $irid,
  5345. 'accountBank' => $accountBank,
  5346. 'category' => $this->staff [0] ['category'],
  5347. 'cid' => $this->staff [0] ['cid'],
  5348. 'name' => $this->staff [0] ['username'],
  5349. 'sid' => $this->staff [0] ['sid'],
  5350. 'inputDate' => date ( "Y-m-d H:i:s" )
  5351. );
  5352. $wasteBook->setAccountBookStatistics ( $itemWaste );
  5353. return '/invoiceReceivablesAS';
  5354. }
  5355. die ( 'illegal request' );
  5356. }
  5357. function ajaxCheckInvoiceReceivablesRefund() {
  5358. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5359. $refundPrice = $this->get_args ( 'refundPrice' ) ? $this->get_args ( 'refundPrice' ) : "";
  5360. if ($refundPrice < 0) {
  5361. echo json_encode ( array (
  5362. 'error' => '金额不能为负'
  5363. ) );
  5364. die ();
  5365. }
  5366. if (! empty ( $refundPrice ) && ! empty ( $iridKey )) {
  5367. Doo::loadModel ( 'invoiceReceivables' );
  5368. $invoiceReceivables = new invoiceReceivables ();
  5369. $irid = $invoiceReceivables->authcode ( $iridKey );
  5370. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5371. if ($irDetail ['receivablesPrice'] < $refundPrice) {
  5372. echo json_encode ( array (
  5373. 'error' => '退款金额不能超过收款金额'
  5374. ) );
  5375. die ();
  5376. }
  5377. echo json_encode ( array (
  5378. 'ok' => '可以使用!'
  5379. ) );
  5380. die ();
  5381. }
  5382. }
  5383. /**
  5384. * 获得收款退款信息
  5385. */
  5386. function getRefundByDetail() {
  5387. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5388. Doo::loadModel ( 'invoiceReceivables' );
  5389. $invoiceReceivables = new invoiceReceivables ();
  5390. if (! empty ( $iridKey )) {
  5391. $irid = $invoiceReceivables->authcode ( $iridKey );
  5392. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5393. echo json_encode ( array (
  5394. 'status' => 1,
  5395. 'irDetail' => $irDetail
  5396. ) );
  5397. die ();
  5398. }
  5399. echo json_encode ( array (
  5400. 'status' => 2
  5401. ) );
  5402. }
  5403. /**
  5404. * 根据收款序列号获得收款退款信息
  5405. */
  5406. function ajaxGetInvoiceReceivablesBySerial() {
  5407. $receivablesSerial = $this->get_args ( 'receivablesSerial' ) ? $this->get_args ( 'receivablesSerial' ) : '';
  5408. if (! empty ( $receivablesSerial )) {
  5409. Doo::loadModel ( 'invoiceReceivables' );
  5410. $invoiceReceivables = new invoiceReceivables ();
  5411. // , ' and refundLog=""'
  5412. $irDetail = $invoiceReceivables->getInvoiceReceivablesBySerial ( $receivablesSerial );
  5413. $html = '';
  5414. if (! empty ( $irDetail ))
  5415. $html = '<td><b>¥' . $irDetail ['receivablesPrice'] . '</b></td>
  5416. <td>' . $irDetail ['receivablesMessage'] . '</td>
  5417. <td>' . $irDetail ['receivablesBank'] . '<br>' . $irDetail ['receivablesDate'] . '</td>
  5418. <td>' . $irDetail ['title'] . '-' . $irDetail ['username'] . '<br>' . $irDetail ['confirmTime'] . '</td>
  5419. <td>' . $irDetail ['recepitTitleMark'] . '
  5420. <input type="hidden" name="iridKey" id="iridKey" value="' . $irDetail ['iridKey'] . '">
  5421. </td>';
  5422. echo json_encode ( array (
  5423. 'status' => 1,
  5424. 'html' => $html,
  5425. 'irDetail' => $irDetail
  5426. ) );
  5427. die ();
  5428. }
  5429. echo json_encode ( array (
  5430. 'status' => 2
  5431. ) );
  5432. }
  5433. /**
  5434. * 绑定新收款
  5435. */
  5436. function relationNewInvoiceReceivables() {
  5437. $iridKeyOld = $this->get_args ( 'iridKeyOld' ) ? $this->get_args ( 'iridKeyOld' ) : '';
  5438. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5439. if (! empty ( $iridKeyOld ) && ! empty ( $iridKey )) {
  5440. Doo::loadModel ( 'invoiceReceivables' );
  5441. $invoiceReceivables = new invoiceReceivables ();
  5442. Doo::loadClass ( 'XDeode' );
  5443. $XDeode = new XDeode ( 5 );
  5444. $irid = $XDeode->decode ( $iridKey );
  5445. $iridOld = $invoiceReceivables->authcode ( $iridKeyOld );
  5446. echo $irid . 'bbb' . $iridOld;
  5447. $oldIrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $iridOld );
  5448. $IrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5449. if (empty ( $oldIrDetail ) || empty ( $IrDetail ))
  5450. die ( 'illegal request' );
  5451. $relationLog = $this->staff [0] ['username'] . ' 关联新款 <a href="#billing" onclick="invoiceReceivblesDivShow(\'' . $iridKey . '\',\'receivables\')" data-toggle="modal">' . $IrDetail ['receivablesSerial'] . '</a>
  5452. <br/>' . date ( "Y-m-d H:i:s" ) . '
  5453. ';
  5454. $invoiceReceivables = new invoiceReceivables ();
  5455. $item = array (
  5456. 'irid' => $iridOld,
  5457. 'relationIrid' => $irid,
  5458. 'relationLog' => $relationLog
  5459. );
  5460. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  5461. return '/invoiceReceivablesAS';
  5462. }
  5463. die ( 'illegal request' );
  5464. }
  5465. // function invoiceApprovalAchieve() {
  5466. // Doo::loadModel ( 'invoice' );
  5467. // $invoice = new invoice ();
  5468. // $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  5469. // $page_size = 12;
  5470. // $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5471. // $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  5472. // $get = "/" . $date;
  5473. // $con = '';
  5474. // if ($date == 'MONTHO')
  5475. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  5476. // elseif ($date == 'MONTHT')
  5477. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  5478. // elseif ($date == 'MONTHY')
  5479. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  5480. // if (! empty ( $MebSea )) {
  5481. // $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  5482. // $get .= "/" . $MebSea;
  5483. // }
  5484. // $pageinfo ['page'] = array (
  5485. // 'previous' => ''
  5486. // );
  5487. // $sql = '(status=1 or status=2 or status=3 or status=4) and processApprovals!=""' . $con; // echo $sql;
  5488. // $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", $get, "" );
  5489. // $limit = $pageinfo ['lower'] . ',' . $page_size;
  5490. // $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  5491. // // print_r($list);
  5492. // $this->data ['MebSeaEn'] = $MebSea;
  5493. // $this->data ['MebSea'] = urlencode ( $MebSea );
  5494. // $this->data ['get'] = $get;
  5495. // $this->data ['page'] = $pageinfo;
  5496. // $this->data ['list'] = $list;
  5497. // $this->data ['date'] = $date;
  5498. // $this->data ['memu'] = "invoice";
  5499. // $this->data ['staff'] = $this->staff;
  5500. // $this->data ['receiptMemu'] = 'invoiceApproval';
  5501. // $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  5502. // }
  5503. /**
  5504. * 获得审批发票的信息以及审批页面
  5505. */
  5506. function ajaxGetInvoiceApprovalDetail() {
  5507. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5508. if (empty ( $serial )) {
  5509. echo json_encode ( array (
  5510. 'status' => 2,
  5511. 'msg' => 'illegal request'
  5512. ) );
  5513. die ();
  5514. }
  5515. Doo::loadModel ( 'invoice' );
  5516. $invoice = new invoice ();
  5517. Doo::loadModel ( 'invoiceOperationLog' );
  5518. $invoiceOperationLog = new invoiceOperationLog ();
  5519. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5520. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5521. if (empty ( $detail ))
  5522. $html = '';
  5523. else {
  5524. $html = '
  5525. <form action="/invoiceApprovalDo" method="post" name="invoiceApproval" class="nice-validator n-yellow" novalidate="novalidate">
  5526. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  5527. <input type="hidden" name="status" value="">
  5528. <input type="hidden" name="divApproval" value="divApproval">
  5529. <div class="modal-dialog modal-lg">
  5530. <div class="modal-content"><div class="modal-header"><h3>发票审批详情</h3></div>
  5531. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  5532. <tr>
  5533. <th class="taC" width="150">发票审批</th><td><textarea name="opinion" style="width:98%" placeholder="在这写下您的审批意见,选填。"></textarea></td>
  5534. </tr>
  5535. <tr>
  5536. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5537. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5538. </tr>
  5539. <tr>
  5540. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5541. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5542. </tr>
  5543. <tr>
  5544. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5545. </td>
  5546. </tr>
  5547. <tr>
  5548. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5549. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5550. </tr>
  5551. <tr>
  5552. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5553. </tr></tbody></table>';
  5554. if ($detail ['invoiceType'] == 0)
  5555. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5556. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5557. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5558. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5559. </tr>';
  5560. else
  5561. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5562. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5563. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5564. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5565. ';
  5566. $html .= '<tr>
  5567. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5568. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5569. </tr>
  5570. <tr>
  5571. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5572. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5573. </tr></tbody></table>';
  5574. if ($detail ['doPost'] == 1) {
  5575. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5576. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5577. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5578. </tr><tr>
  5579. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5580. </tr><tr>
  5581. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5582. </tr>
  5583. ';
  5584. if ($detail ['expressCom'] == 'SF')
  5585. $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>';
  5586. else
  5587. $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>';
  5588. $html .= '</tbody></table>';
  5589. }
  5590. if (! empty ( $invoiceOperationLogList )) {
  5591. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  5592. foreach ( $invoiceOperationLogList as $key => $value ) {
  5593. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5594. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5595. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5596. if ($value ['status'] == 2) {
  5597. $html .= '<span class="colGreen">同意</span>';
  5598. } elseif ($value ['status'] == 3) {
  5599. $html .= '<span class="colOrange">退回</span>';
  5600. } elseif ($value ['status'] == 5) {
  5601. $html .= '<span class="colGreen">打印</span>';
  5602. } elseif ($value ['status'] == 4) {
  5603. $html .= '<span class="colRed">终止</span>';
  5604. }
  5605. $html .= $value ['operation'] . '</p></blockquote>';
  5606. }
  5607. }
  5608. $html .= '</td></tr></tbody></table>';
  5609. }
  5610. $html .= '</div><div class="modal-footer">
  5611. <a href="javascript:void(0)" node-approval="approval" diss-data="2" class="button btn-done" data-placement="top" data-toggle="ctooltip" >同意</a>
  5612. <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>
  5613. <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>
  5614. <a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>
  5615. </form>
  5616. <script type="text/javascript">
  5617. $("a[node-approval^=\'approval\']").click(function() {
  5618. $("input[name=\'status\']").val($(this).attr("diss-data"));
  5619. $("form[name=\'invoiceApproval\']").submit();
  5620. });
  5621. </script>
  5622. ';
  5623. }
  5624. echo json_encode ( array (
  5625. 'status' => 1,
  5626. 'html' => $html
  5627. ) );
  5628. die ();
  5629. }
  5630. /**
  5631. * 获得审批发票分页数据
  5632. */
  5633. function ajaxGetinvoiceApprovalAchieve() {
  5634. Doo::loadModel ( 'invoice' );
  5635. $invoice = new invoice ();
  5636. Doo::loadModel ( 'staff' );
  5637. $staff = new staff ();
  5638. Doo::loadClass ( 'XDeode' );
  5639. $XDeode = new XDeode ( 5 );
  5640. Doo::loadModel ( 'invoiceTraining' );
  5641. $invoiceTraining = new invoiceTraining ();
  5642. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  5643. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5644. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5645. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5646. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5647. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  5648. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  5649. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  5650. $MebSea = $this->get_args ( 'search' );
  5651. $MebSea = $MebSea ['value'];
  5652. $page_size = $length;
  5653. $con = '';
  5654. if ($status == 'ALL')
  5655. $con = ' (status=1 or status=2 or status=3 or status=4) and isDelete=0 ';
  5656. elseif ($status == 'PEND')
  5657. $con = ' isDelete=0 and status=1';
  5658. elseif ($status == 'APPROVED')
  5659. $con = ' isDelete=0 and status=2';
  5660. if ($invoiceType == 'ORDINARY')
  5661. $con .= ' and invoiceType=0 ';
  5662. elseif ($invoiceType == 'SPECIAL')
  5663. $con .= ' and invoiceType=1 ';
  5664. if ($invoiceTrain == 'ORDINARY')
  5665. $con .= ' and trainId=0 ';
  5666. elseif ($invoiceTrain == 'TRAIN')
  5667. $con .= ' and trainId!=0 ';
  5668. if ($invoiceTrainName != 'ALL') {
  5669. $trainId = $XDeode->decode ( $invoiceTrainName );
  5670. if (is_numeric ( $trainId ))
  5671. $con .= ' and trainId =' . $trainId;
  5672. }
  5673. $dateArr = explode ( ':', $date );
  5674. $D1 = $dateString = '';
  5675. $D2 = '';
  5676. if (! empty ( $date )) {
  5677. $D1 = $dateArr [0];
  5678. if (isset ( $dateArr [1] ))
  5679. $D2 = $dateArr [1];
  5680. else
  5681. $D2 = '';
  5682. $dateString = $D1 . " : " . $D2;
  5683. }
  5684. if (! empty ( $D1 ) && ! empty ( $D2 ))
  5685. $con .= ' and approvalTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  5686. elseif (! empty ( $D1 ) && empty ( $D2 ))
  5687. $con .= ' and approvalTime like "%' . $D1 . '%" ';
  5688. if (! empty ( $MebSea ))
  5689. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceSerial like "%' . $MebSea . '%" )';
  5690. // /
  5691. $pageinfo ['page'] = array (
  5692. 'previous' => ''
  5693. );
  5694. $sql = ' ' . $con;
  5695. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", '', "" );
  5696. $limit = $page . ',' . $page_size;
  5697. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  5698. $approvalList = array ();
  5699. $html = '<script type="text/javascript">
  5700. </script>';
  5701. // 结算结束不能修改方式
  5702. Doo::loadModel ( 'receipt' );
  5703. $receipt = new receipt ();
  5704. foreach ( $list as $key => $value ) {
  5705. $irDetail = array ();
  5706. // 结算方式
  5707. $receiptDetail = array ();
  5708. if ($value ['trainId'] != 0) {
  5709. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $value ['trainId'] );
  5710. }
  5711. if (! empty ( $receiptDetail )) {
  5712. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9) {
  5713. array_push ( $irDetail, '' );
  5714. } else {
  5715. if ($value ['status'] == 1 && $value ['pendingApprovals'] == $this->staff [0] ['sid']) {
  5716. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoiceApproval(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">审批发票</a>' );
  5717. } elseif ($value ['status'] == 2) {
  5718. array_push ( $irDetail, '<a href="#editPay" class="fnSettlementType" data-iidKey="' . $value ['iidKeyK'] . '" data-toggle="modal">结算方式</a>' );
  5719. } else
  5720. array_push ( $irDetail, '' );
  5721. }
  5722. } else {
  5723. if ($value ['status'] == 2) {
  5724. array_push ( $irDetail, '<a href="#editPay" class="fnSettlementType" data-iidKey="' . $value ['iidKeyK'] . '" data-toggle="modal">结算方式</a>' );
  5725. } else
  5726. array_push ( $irDetail, '' );
  5727. }
  5728. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  5729. if ($value ['invoiceType'] == 1)
  5730. array_push ( $irDetail, $value ['invoiceCompany'] );
  5731. else
  5732. array_push ( $irDetail, $value ['invoiceTitle'] );
  5733. array_push ( $irDetail, $value ['TIN'] );
  5734. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  5735. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  5736. array_push ( $irDetail, $value ['remark'] );
  5737. array_push ( $irDetail, $value ['invoiceElement'] );
  5738. array_push ( $irDetail, $value ['invoiceQuantity'] );
  5739. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  5740. if ($value ['invoiceType'] == 1) {
  5741. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  5742. } else {
  5743. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  5744. }
  5745. if ($value ['settlementType'] == 0) {
  5746. array_push ( $irDetail, '软件销售' );
  5747. } else {
  5748. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $value ['trainId'] );
  5749. array_push ( $irDetail, $itDetail ['trainName'] );
  5750. }
  5751. array_push ( $irDetail, $value ['recipients'] . $value ['recipientsPhone'] );
  5752. array_push ( $irDetail, $value ['recipientsAddress'] );
  5753. array_push ( $irDetail, $value ['mailItems'] );
  5754. array_push ( $irDetail, $value ['userName'] . '&nbsp;' . $value ['date'] );
  5755. $fchtml = $value ['OL'] ['operation'];
  5756. if (count ( $list ) == $page_size)
  5757. $fchtml = $value ['OL'] ['operation'] . $html;
  5758. // 最后的审批意见
  5759. array_push ( $irDetail, $fchtml );
  5760. if ($value ['status'] == 2)
  5761. array_push ( $irDetail, '<span class="colGreen">同意</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5762. elseif ($value ['status'] == 3)
  5763. array_push ( $irDetail, '<span class="colOrange">退回</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5764. elseif ($value ['status'] == 4)
  5765. array_push ( $irDetail, '<span class="colRed">终止</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5766. else
  5767. array_push ( $irDetail, '' );
  5768. array_push ( $approvalList, $irDetail );
  5769. }
  5770. // $approvalListJson = json_encode ( $approvalList );
  5771. $recordsFiltered = $pageinfo ['total_data'];
  5772. echo json_encode ( array (
  5773. "draw" => intval ( $draw ),
  5774. "recordsTotal" => intval ( $pageinfo ['total_data'] ),
  5775. "recordsFiltered" => intval ( $recordsFiltered ),
  5776. "data" => $approvalList
  5777. ), JSON_UNESCAPED_UNICODE );
  5778. }
  5779. /**
  5780. * 审批发票查看更多--重构
  5781. */
  5782. function invoiceApprovalAchieve() {
  5783. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'ALL';
  5784. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5785. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5786. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5787. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5788. Doo::loadModel ( 'invoiceTraining' );
  5789. $invoiceTraining = new invoiceTraining ();
  5790. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  5791. $this->data ['trainList'] = $trainList;
  5792. $this->data ['dateString'] = $date;
  5793. $this->data ['status'] = $status;
  5794. $this->data ['invoiceType'] = $invoiceType;
  5795. $this->data ['invoiceTrain'] = $invoiceTrain;
  5796. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  5797. $this->data ['memu'] = "invoice";
  5798. $this->data ['staff'] = $this->staff;
  5799. $this->data ['receiptMemu'] = 'invoiceApproval';
  5800. $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  5801. }
  5802. function invoiceTAchieve() {
  5803. Doo::loadModel ( 'invoice' );
  5804. $invoice = new invoice ();
  5805. Doo::loadClass ( 'XDeode' );
  5806. $XDeode = new XDeode ( 5 );
  5807. Doo::loadModel ( 'staff' );
  5808. $staff = new staff ();
  5809. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  5810. $page_size = 12;
  5811. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5812. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  5813. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5814. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5815. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5816. Doo::loadModel ( 'invoiceTraining' );
  5817. $invoiceTraining = new invoiceTraining ();
  5818. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  5819. $get = "/" . $date;
  5820. $con = '';
  5821. if ($date == 'MONTHO')
  5822. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  5823. elseif ($date == 'MONTHT')
  5824. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  5825. elseif ($date == 'MONTHY')
  5826. $con = ' and YEAR(updateTime) = YEAR(NOW())'; // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  5827. if ($invoiceType == 'ORDINARY')
  5828. $con .= ' and invoiceType=0 ';
  5829. elseif ($invoiceType == 'SPECIAL')
  5830. $con .= ' and invoiceType=1 ';
  5831. if ($invoiceTrain == 'ORDINARY')
  5832. $con .= ' and trainId=0 ';
  5833. elseif ($invoiceTrain == 'TRAIN')
  5834. $con .= ' and trainId!=0 ';
  5835. if ($invoiceTrainName != 'ALL') {
  5836. $trainId = $XDeode->decode ( $invoiceTrainName );
  5837. if (is_numeric ( $trainId ))
  5838. $con .= ' and trainId =' . $trainId;
  5839. }
  5840. if (! empty ( $MebSea )) {
  5841. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  5842. $get .= "/" . $MebSea;
  5843. }
  5844. $pageinfo ['page'] = array (
  5845. 'previous' => ''
  5846. );
  5847. $sql = "";
  5848. $action = "";
  5849. if ($this->ACTION == 'invoicePrintAchieve') {
  5850. $sql = "status=2 and printStatus=1 and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  5851. $action = "invoicePrintAchieve";
  5852. } elseif ($this->ACTION == 'invoicePostAchieve') {
  5853. // and untreadStatus=0
  5854. $sql = "postStatus=1 and doPost=1 and status=2 and isDelete=0" . $con;
  5855. $action = "invoicePostAchieve";
  5856. } elseif ($this->ACTION == 'invoiceUntreadAchieve') { // printStatus=1 and
  5857. $sql = " untreadStatus=2 and status=2 " . $con;
  5858. $action = "invoiceUntreadAchieve";
  5859. }
  5860. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  5861. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5862. $this->data ['MebSeaEn'] = $MebSea;
  5863. $this->data ['MebSea'] = urlencode ( $MebSea );
  5864. $this->data ['get'] = $get;
  5865. $this->data ['page'] = $pageinfo;
  5866. $this->data ['trainList'] = $trainList;
  5867. $this->data ['invoiceType'] = $invoiceType;
  5868. $this->data ['invoiceTrain'] = $invoiceTrain;
  5869. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  5870. $this->data ['date'] = $date;
  5871. $this->data ['memu'] = "invoice";
  5872. $this->data ['staff'] = $this->staff;
  5873. if ($this->ACTION == 'invoicePrintAchieve') {
  5874. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  5875. $this->data ['receiptMemu'] = 'invoicePrint';
  5876. $this->data ['list'] = $list;
  5877. $this->render ( "/admin/invoicePrintAchieve", $this->data );
  5878. } elseif ($this->ACTION == 'invoicePostAchieve') {
  5879. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  5880. Doo::loadModel ( 'express' );
  5881. $express = new express ();
  5882. $expressList = $express->getExpressByAll ();
  5883. $this->data ['expressList'] = $expressList;
  5884. $this->data ['receiptMemu'] = 'invoicePost';
  5885. $this->data ['list'] = $list;
  5886. $this->render ( "/admin/invoicePostAchieve", $this->data );
  5887. } elseif ($this->ACTION == 'invoiceUntreadAchieve') {
  5888. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql,'desc','desc','untreadTime' );
  5889. $this->data ['receiptMemu'] = 'invoiceUntread';
  5890. $this->data ['list'] = $list;
  5891. $this->render ( "/admin/invoiceUntreadAchieve", $this->data );
  5892. }
  5893. }
  5894. /**
  5895. * 公司应收款
  5896. */
  5897. function invoiceAggregateCompanyDetail() {
  5898. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  5899. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  5900. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : 'ALL';
  5901. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  5902. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  5903. $titleORno = $this->get_args ( 'titleORno' ) ? $this->get_args ( 'titleORno' ) : "";
  5904. Doo::loadClass ( 'XDeode' );
  5905. $XDeode = new XDeode ( 5 );
  5906. Doo::loadModel ( 'invoice' );
  5907. $invoice = new invoice ();
  5908. Doo::loadModel ( 'staff' );
  5909. $staff = new staff ();
  5910. Doo::loadModel ( "invoiceCompanyManage" );
  5911. $invoiceCompanyManage = new invoiceCompanyManage ();
  5912. Doo::loadModel ( 'L_category' );
  5913. $category = new L_category ();
  5914. $sid = '';
  5915. if (! empty ( $sidKey )) {
  5916. $sid = $XDeode->decode ( $sidKey );
  5917. }
  5918. $staffDetail = $staff->getStaffBySid ( $sid );
  5919. $cid = '';
  5920. if (! empty ( $cidKey )) {
  5921. $cid = $XDeode->decode ( $cidKey );
  5922. }
  5923. $imcStaff = $invoiceCompanyManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  5924. $cidList = array ();
  5925. foreach ( $imcStaff as $key => $value ) {
  5926. array_push ( $cidList, $value ['cid'] );
  5927. }
  5928. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  5929. $cidString = implode ( ',', $cidList );
  5930. if (empty ( $cid ))
  5931. $staffList = $staff->getStaffInCid ( $cidString );
  5932. else
  5933. $staffList = $staff->getStaffByCidAll ( $cid ); //
  5934. //$MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  5935. $page_size = 25;
  5936. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5937. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  5938. $con = ' status=2 and untreadStatus!=2 and invalid=0 and isDelete=0 and badDebt=0 ';
  5939. $statisticsCon = '';
  5940. if (! empty ( $year ) && is_numeric ( $year ))
  5941. $con .= ' and Year(printTime)=' . $year . '';
  5942. if (! empty ( $month ) && is_numeric ( $month ))
  5943. $con .= ' and Month(printTime)="' . $month . '" ';
  5944. if ($status == 'UNRECORD')
  5945. $con .= ' and printStatus=1 and untreadStatus=0';
  5946. elseif ($status == 'RECORD')
  5947. $con .= ' and printStatus=1 and untreadStatus=3';
  5948. elseif ($status == 'BOUNCED')
  5949. $con .= ' and untreadStatus=2';
  5950. elseif ($status == 'PARTRECORD')
  5951. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  5952. elseif ($status == 'All') {
  5953. $con .= ' and printStatus=1 and ( untreadStatus=0 or untreadStatus=3 )';
  5954. }
  5955. if (! empty ( $sid ) && is_numeric ( $sid ))
  5956. $con .= ' and sid=' . $sid;
  5957. if (! empty ( $cid ) && is_numeric ( $cid ))
  5958. $con .= ' and cid=' . $cid;
  5959. else
  5960. $con .= ' and cid in (' . $cidString . ')';
  5961. // 开票内容筛选
  5962. if (! empty ( $invoiceElement ) && $invoiceElement != 'ALL') {
  5963. $con .= ' and invoiceElement="' . $invoiceElement . '"';
  5964. }
  5965. $get = "/" . $status . "?cidKey=" . $cidKey . "&sidKey=" . $sidKey . "&year=" . $year . "&month=" . $month
  5966. . "&invoiceElement=" . $invoiceElement."&titleORno=".urlencode ( $titleORno );
  5967. if (! empty ( $titleORno )) {
  5968. $con .= ' and ( invoiceTitle like "%' . $titleORno . '%" or invoiceCompany like "%' . $titleORno . '%" or invoiceNo like "%'.$titleORno.'%" )';
  5969. }
  5970. $pageinfo ['page'] = array (
  5971. 'previous' => ''
  5972. );
  5973. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateCompanyDetail", $get, "" );
  5974. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5975. // 应收款合计
  5976. $ics = $invoice->getInvoiceCompanyStatistics ( $con );
  5977. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  5978. $monthHtml = "";
  5979. if ($year != "ALL") {
  5980. for($i = 1; $i <= 12; $i ++) {
  5981. if ($i == $month)
  5982. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  5983. else
  5984. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  5985. }
  5986. }
  5987. $this->data ['monthHtml'] = $monthHtml;
  5988. $this->data ['year'] = $year;
  5989. $this->data ['month'] = $month;
  5990. $this->data ['ics'] = $ics;
  5991. $this->data ['cidKey'] = $cidKey;
  5992. $this->data ['sid'] = $sid;
  5993. $this->data ['staffDetail'] = $staffDetail;
  5994. $this->data ['staffList'] = $staffList;
  5995. $this->data ['titleORnoEn'] = $titleORno;
  5996. $this->data ['titleORno'] = urlencode ( $titleORno );
  5997. $this->data ['invoiceDetail'] = array (
  5998. 'invoiceElement' => $invoiceElement
  5999. );
  6000. $this->data ['page'] = $pageinfo;
  6001. $this->data ['get'] = $get;
  6002. $this->data ['list'] = $list;
  6003. $this->data ['status'] = $status;
  6004. $this->data ['categoryList'] = $categoryList;
  6005. $this->data ['memu'] = "invoice";
  6006. $this->data ['staff'] = $this->staff;
  6007. $this->data ['receiptMemu'] = 'invoiceAggregateCompanyDetail';
  6008. $this->render ( "/admin/invoiceAggregateCompanyDetail", $this->data );
  6009. }
  6010. /**
  6011. * 获取一条收款信息
  6012. */
  6013. function ajaxGetInvoiceReceivables() {
  6014. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  6015. Doo::loadModel ( 'invoiceReceivables' );
  6016. $invoiceReceivables = new invoiceReceivables ();
  6017. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  6018. echo json_encode ( array (
  6019. 'status' => 1,
  6020. 'detail' => $detail
  6021. ) );
  6022. }
  6023. /**
  6024. * 异步获取办事处用户
  6025. */
  6026. function ajaxGetStaffByCategory() {
  6027. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "";
  6028. Doo::loadModel ( 'staff' );
  6029. $staff = new staff ();
  6030. if ($cid == "PUBLIC") {
  6031. echo json_encode ( array (
  6032. 'status' => 1,
  6033. 'html' => '<option value="PUBLIC">办事处待认领款项</option>'
  6034. ) );
  6035. die ();
  6036. }
  6037. if (! is_numeric ( $cid )) {
  6038. echo json_encode ( array (
  6039. 'status' => 0,
  6040. 'msg' => 'illegal request'
  6041. ) );
  6042. die ();
  6043. }
  6044. $staffList = $staff->getStaffByCid ( $cid );
  6045. $html = '<option value="PUBLIC">办事处待认领款项</option>';
  6046. foreach ( $staffList as $key => $value ) {
  6047. $html .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  6048. }
  6049. echo json_encode ( array (
  6050. 'status' => 1,
  6051. 'html' => $html
  6052. ) );
  6053. }
  6054. /**
  6055. * 异步获取一条发票的邮寄信息
  6056. */
  6057. function ajaxGetInvoicePostDetail() {
  6058. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  6059. Doo::loadModel ( 'invoice' );
  6060. $invoice = new invoice ();
  6061. $iid = $invoice->authcode ( $iid );
  6062. Doo::loadModel ( 'express' );
  6063. $express = new express ();
  6064. $expressList = $express->getExpressByAll ();
  6065. if (! is_numeric ( $iid )) {
  6066. echo json_encode ( array (
  6067. 'status' => 0,
  6068. 'msg' => 'illegal request'
  6069. ) );
  6070. die ();
  6071. }
  6072. $select = "iid,recipients,recipientsPhone,recipientsAddress,mailItems,expressCompany,expressNumber,actualItems";
  6073. $invoiceDetail = $invoice->getInvoiceByIid ( $iid, $select );
  6074. $html = "";
  6075. foreach ( $expressList as $key => $value ) {
  6076. if ($value ['company'] == $invoiceDetail ['expressCompany'])
  6077. $html .= '<option selected value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  6078. else
  6079. $html .= '<option value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  6080. }
  6081. $invoiceDetail ['eaHtml'] = $html;
  6082. echo json_encode ( array (
  6083. 'status' => 1,
  6084. 'invoiceDetail' => $invoiceDetail
  6085. ) );
  6086. }
  6087. /**
  6088. *
  6089. * @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 ) ); }
  6090. */
  6091. /**
  6092. *
  6093. * @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 ) ); }
  6094. */
  6095. /**
  6096. * 我的收款中 选择哪个发票入账,进行金额判断
  6097. */
  6098. function ajaxCompareInvoicePrice() {
  6099. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  6100. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  6101. Doo::loadModel ( 'invoice' );
  6102. $invoice = new invoice ();
  6103. Doo::loadModel ( 'invoiceReceivables' );
  6104. $invoiceReceivables = new invoiceReceivables ();
  6105. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  6106. $keyList = explode ( ';', $claimKey );
  6107. $receivablesPrice = 0;
  6108. foreach ( $keyList as $key => $value ) {
  6109. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $value );
  6110. $receivablesPrice += $detailM ['receivablesPrice'];
  6111. }
  6112. if ($receivablesPrice > $detail ['invoicePrice']) {
  6113. $price = $receivablesPrice - $detail ['invoicePrice'];
  6114. echo json_encode ( array (
  6115. 'status' => 1,
  6116. 'price' => $price
  6117. ) );
  6118. } else
  6119. echo json_encode ( array (
  6120. 'status' => 2
  6121. ) );
  6122. }
  6123. /**
  6124. * 获得打印发票
  6125. */
  6126. function ajaxGetInvoiceInfoByPrint() {
  6127. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  6128. if (empty ( $serial )) {
  6129. echo json_encode ( array (
  6130. 'status' => 2,
  6131. 'msg' => 'illegal request'
  6132. ) );
  6133. die ();
  6134. }
  6135. Doo::loadModel ( 'invoice' );
  6136. $invoice = new invoice ();
  6137. Doo::loadModel ( 'invoiceOperationLog' );
  6138. $invoiceOperationLog = new invoiceOperationLog ();
  6139. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  6140. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  6141. Doo::loadModel ( 'invoicePaper' );
  6142. $invoicePaper = new invoicePaper ();
  6143. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $detail ['invoiceType'] );
  6144. if (empty ( $detail ))
  6145. $html = '';
  6146. else {
  6147. $html = '
  6148. <form action="/invoicePrintDo" method="post" name="invoicePrint" class="nice-validator n-yellow" onSubmit="return checkPrintForm()" novalidate="novalidate">
  6149. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  6150. <input type="hidden" name="invoicePrintType" value="invoicePrintType">
  6151. <div class="modal-dialog modal-lg">
  6152. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  6153. <div class="modal-body saeaList">
  6154. <table class="table table-bordered table-condensed"><tbody>
  6155. <tr>
  6156. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  6157. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  6158. </tr>
  6159. <tr>
  6160. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  6161. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  6162. </tr>
  6163. <tr>
  6164. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  6165. </td>
  6166. </tr>
  6167. <tr>
  6168. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  6169. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  6170. </tr>
  6171. <tr>
  6172. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  6173. </tr></tbody></table>';
  6174. if ($detail ['invoiceType'] == 0)
  6175. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6176. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  6177. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  6178. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  6179. </tr>';
  6180. else
  6181. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6182. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  6183. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  6184. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  6185. ';
  6186. $html .= '<tr>
  6187. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  6188. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  6189. </tr>
  6190. <tr>
  6191. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  6192. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  6193. </tr></tbody></table>';
  6194. if ($detail ['doPost'] == 1)
  6195. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  6196. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  6197. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  6198. </tr><tr>
  6199. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  6200. </tr><tr>
  6201. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  6202. </tr></tbody></table>';
  6203. if (! empty ( $invoiceOperationLogList )) {
  6204. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th><th class="taC">发票打印</th></tr><tr><td>';
  6205. foreach ( $invoiceOperationLogList as $key => $value ) {
  6206. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  6207. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  6208. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  6209. if ($value ['status'] == 2) {
  6210. $html .= '<span class="colGreen">同意</span>';
  6211. } elseif ($value ['status'] == 3) {
  6212. $html .= '<span class="colOrange">退回</span>';
  6213. } elseif ($value ['status'] == 5) {
  6214. $html .= '<span class="colGreen">打印</span>';
  6215. } elseif ($value ['status'] == 4) {
  6216. $html .= '<span class="colRed">终止</span>';
  6217. }
  6218. $html .= $value ['operation'] . '</p></blockquote>';
  6219. }
  6220. }
  6221. $html .= '</td>
  6222. <td><span class="colRed">*</span>
  6223. <select name="invoiceNo" id="invoiceNo" style="width:97%">';
  6224. foreach ( $invoicePaperList as $key => $value ) {
  6225. $html .= '<option value="' . $value ['ipidKey'] . '">No.' . $value ['invoiceNo'] . '</option>';
  6226. }
  6227. $html .= '</select>
  6228. <span class="red" id="p-msg"></span>
  6229. </td>
  6230. </tr></tbody></table>';
  6231. }
  6232. $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>
  6233. </div></div></form>
  6234. <link rel=stylesheet href="' . WEB_SITE_GLOBAL . 'css/jquery.validator.css">
  6235. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/jquery.validator.min.js"></script>
  6236. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/zh-CN.js"></script>
  6237. <script src="' . WEB_SITE_GLOBAL . 'js/invoice.validator.js"></script>
  6238. ';
  6239. }
  6240. echo json_encode ( array (
  6241. 'status' => 1,
  6242. 'html' => $html
  6243. ) );
  6244. die ();
  6245. }
  6246. /**
  6247. * @ 获得与我有关收款数据 --需求变更 废弃 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 ) ); }
  6248. */
  6249. function ajaxGetInvoiceInfoByType() {
  6250. $type = $this->get_args ( 'type' ) ? $this->get_args ( 'type' ) : "";
  6251. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  6252. $loss = $this->get_args ( 'loss' ) ? $this->get_args ( 'loss' ) : false;
  6253. if (empty ( $serial )) {
  6254. echo json_encode ( array (
  6255. 'status' => 2,
  6256. 'msg' => 'illegal request'
  6257. ) );
  6258. die ();
  6259. }
  6260. if ($type == 'INVOICE') {
  6261. Doo::loadModel ( 'invoice' );
  6262. $invoice = new invoice ();
  6263. Doo::loadModel ( 'invoiceOperationLog' );
  6264. $invoiceOperationLog = new invoiceOperationLog ();
  6265. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  6266. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  6267. if (empty ( $detail ))
  6268. $html = '';
  6269. else {
  6270. $html = '
  6271. <div class="modal-dialog modal-lg">
  6272. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  6273. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  6274. <tr>
  6275. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  6276. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  6277. </tr>
  6278. <tr>
  6279. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  6280. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  6281. </tr>
  6282. <tr>
  6283. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  6284. </td>
  6285. </tr>
  6286. <tr>
  6287. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  6288. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  6289. </tr>
  6290. <tr>
  6291. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  6292. </tr>';
  6293. if ($detail ['settlementType'] == 1)
  6294. $html .= '<tr>
  6295. <th class="taC" width="150">结算方式</th><td colspan="3">培训班(<a href="/invoiceTrainingDetail/' . $detail ['invoiceTraining'] ['trainingKey'] . '.html" target="_blank">' . $detail ['invoiceTraining'] ['trainName'] . '</a>)</td>
  6296. </tr>';
  6297. else
  6298. $html .= '<tr>
  6299. <th class="taC" width="150">结算方式</th><td colspan="3">软件销售</td>
  6300. </tr>';
  6301. $html .= ' </tbody></table>';
  6302. if ($detail ['invoiceType'] == 0){
  6303. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6304. <tr><th colspan="4" class="taC">增值税普通发票';
  6305. if($detail ['invoiceForm']==1){
  6306. $html .= '( <span class="colRed">电子发票</span> )';
  6307. }
  6308. $html .= '</th></tr><tr>
  6309. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  6310. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  6311. </tr>';
  6312. }else{
  6313. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6314. <tr><th colspan="4" class="taC">增值税专用发票';
  6315. if($detail ['invoiceForm']==1){
  6316. $html .= '( <span class="colRed">电子发票</span> )';
  6317. }
  6318. $html .= '</th></tr><tr>
  6319. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  6320. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  6321. ';
  6322. }
  6323. $html .= '<tr>
  6324. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  6325. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  6326. </tr>
  6327. <tr>
  6328. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  6329. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  6330. </tr></tbody></table>';
  6331. if ($detail ['doPost'] == 1) {
  6332. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  6333. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  6334. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  6335. </tr><tr>
  6336. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  6337. </tr><tr>
  6338. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  6339. </tr>
  6340. ';
  6341. if ($detail ['expressCom'] == 'SF')
  6342. $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>';
  6343. else
  6344. $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>';
  6345. $html .= '</tbody></table>';
  6346. }
  6347. if ($detail ['invoiceForm'] == 1) {
  6348. $html .= '<table class="table table-bordered table-condensed">
  6349. <tbody><tr><th colspan="4" class="taC">电子发票发送方式</th></tr>
  6350. <tr>
  6351. <th class="taC" width="150">收件人手机</th><td>'.$detail ['electronicPhone'].'</td>
  6352. <th class="taC" width="150">收件人邮箱</th><td>'.$detail ['electronicEmail'].'</td>
  6353. </tr></tbody></table>';
  6354. }
  6355. if (! empty ( $invoiceOperationLogList )) {
  6356. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  6357. foreach ( $invoiceOperationLogList as $key => $value ) {
  6358. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  6359. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  6360. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  6361. if ($value ['status'] == 2) {
  6362. $html .= '<span class="colGreen">同意</span>';
  6363. } elseif ($value ['status'] == 3) {
  6364. $html .= '<span class="colOrange">退回</span>';
  6365. } elseif ($value ['status'] == 5) {
  6366. $html .= '<span class="colGreen">打印</span>';
  6367. } elseif ($value ['status'] == 4) {
  6368. $html .= '<span class="colRed">终止</span>';
  6369. }
  6370. $html .= $value ['operation'] . '</p></blockquote>';
  6371. }
  6372. }
  6373. $html .= '</td></tr></tbody></table>';
  6374. }
  6375. $html .= '</div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  6376. }
  6377. echo json_encode ( array (
  6378. 'status' => 1,
  6379. 'html' => $html
  6380. ) );
  6381. die ();
  6382. } elseif ($type == 'RECEIVABLES') {
  6383. Doo::loadModel ( 'invoiceReceivables' );
  6384. $invoiceReceivables = new invoiceReceivables ();
  6385. Doo::loadModel ( 'invoiceRefund' );
  6386. $invoiceRefund = new invoiceRefund ();
  6387. $detail = $invoiceReceivables->getInvoiceReceivablesByIrsid ( $serial );
  6388. $ireList = $invoiceRefund->getInvoiceRefundIrid ( $detail ['irid'] );
  6389. if (empty ( $detail ))
  6390. $html = '';
  6391. else {
  6392. $html = '<div class="modal-dialog modal-lg"><div class="modal-content"><div class="modal-header"><h3>收款单详情</h3></div><div class="modal-body saeaList">
  6393. <table class="table table-bordered table-condensed">
  6394. <tbody><tr>
  6395. <th class="taC">收款流水号</th><td>' . $detail ['receivablesSerial'] . '</td>
  6396. <th class="taC">录入收款</th><td>' . $detail ['inputStaff'] . ' ' . $detail ['date'] . '</td>
  6397. </tr><tr>
  6398. <th class="taC">收款金额</th><td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  6399. <th class="taC">收款信息</th><td>' . $detail ['receivablesMessage'] . '</td>
  6400. </tr>
  6401. <tr>
  6402. <th class="taC">收款银行</th><td>' . $detail ['receivablesBank'] . '</td>
  6403. <th class="taC">银行到账</th><td>' . $detail ['receivablesDate'] . '</td>
  6404. </tr>
  6405. <tr>
  6406. <th class="taC">认领收款</th><td colspan="3">' . $detail ['inputStaff'] . ' 转入 ' . $detail ['username'] . ' ' . $detail ['confirmTime'] . '</td>
  6407. </tr>
  6408. </tbody></table>';
  6409. if (! empty ( $ireList )) {
  6410. $html .= '
  6411. <table class="table table-bordered table-condensed"><tbody><tr><th class="taC" colspan="5">退款记录</th></tr>
  6412. <tr>
  6413. <th class="taC">退款单位名称</th>
  6414. <th class="taC">退款的账号</th>
  6415. <th class="taC">退款金额</th>
  6416. <th class="taC">退款</th>
  6417. <th class="taC">备注</th>
  6418. </tr>
  6419. ';
  6420. foreach ( $ireList as $key => $value ) {
  6421. $refundLogList = explode ( "<br/>", $value ['refundLog'] );
  6422. $html .= '<tr>
  6423. <td>' . $value ['refundCompany'] . '</td>
  6424. <td>' . $value ['refundNumber'] . '</td>
  6425. <td><b class="colRed">¥' . $value ['refundPrice'] . '</b></td>
  6426. <td>' . $refundLogList [0] . $refundLogList [2] . '</td>
  6427. <td>' . $value ['refundRemarks'] . '</td>
  6428. </tr>
  6429. ';
  6430. }
  6431. }
  6432. $html .= '</tbody></table></div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  6433. }
  6434. echo json_encode ( array (
  6435. 'status' => 1,
  6436. 'html' => $html
  6437. ) );
  6438. die ();
  6439. } elseif ($type == 'IRTC') {
  6440. Doo::loadModel ( 'invoice' );
  6441. $invoice = new invoice ();
  6442. Doo::loadModel ( 'invoiceOperationLog' );
  6443. $invoiceOperationLog = new invoiceOperationLog ();
  6444. // Doo::loadModel ( 'invoiceReceivables' );
  6445. // $invoiceReceivables = new invoiceReceivables ();
  6446. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  6447. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  6448. if (empty ( $detail ))
  6449. $html = '';
  6450. else {
  6451. $receivablesPriceedHtml = '';
  6452. $receivablesPrice = $detail ['invoicePrice'];
  6453. if (! empty ( $detail ['irid'] )) {
  6454. // $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $detail ['irid'] );
  6455. // if (empty ( $irList ))
  6456. // $irList [0] ['sumPrice'] = 0;
  6457. // $balance = $detail ['invoicePrice'] - $irList [0] ['sumPrice'];
  6458. $enteredPrice=$detail ['invoicePrice']-$detail ['invoiceBalance'];
  6459. $receivablesPriceedHtml = '<table class="table table-bordered table-condensed"><tbody><tr>
  6460. <th class="taC">已入账金额</th><td><b class="colGreen" style="font-size:18px">¥' . $enteredPrice . '</b></td>
  6461. <th class="taC">剩余入账金额</th><td><b class="colRed" style="font-size:18px">¥' . $detail ['invoiceBalance'] . '</b></td>
  6462. </tr></tbody></table>';
  6463. $receivablesPrice = $detail ['invoiceBalance'];
  6464. }
  6465. if ($loss)
  6466. $detail ['invoicePrice'] = - $detail ['invoicePrice'];
  6467. $html = $receivablesPriceedHtml . '
  6468. <table class="table table-bordered table-condensed"><tbody>
  6469. <tr>
  6470. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  6471. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  6472. </tr>
  6473. <tr>
  6474. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  6475. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  6476. </tr>
  6477. <tr>
  6478. <th class="taC" width="150">发票备注</th><td colspan="3">' . $detail ['remark'] . '</td>
  6479. </tr>
  6480. <tr>
  6481. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  6482. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  6483. </tr>
  6484. <tr>
  6485. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  6486. </tr></tbody></table>';
  6487. if ($detail ['invoiceType'] == 0) {
  6488. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6489. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  6490. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  6491. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  6492. </tr>';
  6493. $receivablesMessage = $detail ['invoiceTitle'];
  6494. } else {
  6495. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6496. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  6497. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  6498. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  6499. ';
  6500. $receivablesMessage = $detail ['invoiceCompany'];
  6501. }
  6502. $html .= '<tr>
  6503. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  6504. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  6505. </tr>
  6506. <tr>
  6507. <th class="taC">开户银行</th><td>' . $detail ['bankAccount'] . '</td>
  6508. <th class="taC">银行账号</th><td>' . $detail ['bank'] . '</td>
  6509. </tr></tbody></table>';
  6510. if ($detail ['doPost'] == 1)
  6511. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  6512. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  6513. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  6514. </tr><tr>
  6515. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  6516. </tr><tr>
  6517. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  6518. </tr></tbody></table>';
  6519. if (! empty ( $invoiceOperationLogList )) {
  6520. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  6521. foreach ( $invoiceOperationLogList as $key => $value ) {
  6522. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  6523. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  6524. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  6525. if ($value ['status'] == 2) {
  6526. $html .= '<span class="colGreen">同意</span>';
  6527. } elseif ($value ['status'] == 3) {
  6528. $html .= '<span class="colOrange">退回</span>';
  6529. } elseif ($value ['status'] == 5) {
  6530. $html .= '<span class="colGreen">打印</span>';
  6531. }
  6532. $html .= $value ['operation'] . '</p></blockquote>';
  6533. }
  6534. }
  6535. $html .= '</td></tr></tbody></table>';
  6536. }
  6537. }
  6538. echo json_encode ( array (
  6539. 'status' => 1,
  6540. 'html' => $html,
  6541. 'receivablesPrice' => $receivablesPrice,
  6542. 'receivablesMessage' => $receivablesMessage,
  6543. 'receivablesDate' => date ( "Y-m-d" ),
  6544. 'iidKey' => $serial
  6545. ) );
  6546. die ();
  6547. }
  6548. }
  6549. function ajaxGetInvoiceReceivablesByStaff() {
  6550. $postData = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : "";
  6551. if (empty ( $postData )) {
  6552. echo json_encode ( array (
  6553. 'status' => 2,
  6554. 'msg' => 'illegal request'
  6555. ) );
  6556. die ();
  6557. }
  6558. Doo::loadModel ( 'invoiceReceivables' );
  6559. $invoiceReceivables = new invoiceReceivables ();
  6560. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $postData );
  6561. if (empty ( $detail )) {
  6562. echo json_encode ( array (
  6563. 'status' => 2,
  6564. 'msg' => 'illegal request'
  6565. ) );
  6566. die ();
  6567. }
  6568. Doo::loadModel ( 'L_category' );
  6569. $lCategory = new L_category ();
  6570. Doo::loadModel ( 'staff' );
  6571. $staff = new staff ();
  6572. $staffList = $staff->getStaffByCid ( $detail ['cid'] );
  6573. $category = $lCategory->getCategory ();
  6574. $categoryHtml = '<option post-data="PUBLIC" value="PUBLIC" >公共待认领款项</option>';
  6575. $staffHtml = '<option value="PUBLIC">办事处待认领款项</option>';
  6576. foreach ( $category as $key => $value ) {
  6577. $categoryHtml .= '<option post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  6578. if ($value ['cid'] == $detail ['cid'])
  6579. $categoryHtml .= '<option selected post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  6580. }
  6581. foreach ( $staffList as $key => $value ) {
  6582. $staffHtml .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  6583. if ($value ['sid'] == $detail ['sid'])
  6584. $staffHtml .= '<option selected value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  6585. }
  6586. $rbankHtml = '<option value="广发银行珠海分行柠溪支行">广发银行珠海分行柠溪支行</option>';
  6587. echo json_encode ( array (
  6588. 'status' => 1,
  6589. 'categoryHtml' => $categoryHtml,
  6590. 'staffHtml' => $staffHtml,
  6591. 'rbankHtml' => $rbankHtml,
  6592. 'detail' => $detail
  6593. ) );
  6594. }
  6595. function ajaxGetInvoiceReceivablesByIrid() {
  6596. $irid = $this->get_args ( 'irid' ) ? $this->get_args ( 'irid' ) : "";
  6597. if (empty ( $irid )) {
  6598. echo json_encode ( array (
  6599. 'status' => 2,
  6600. 'msg' => 'illegal request'
  6601. ) );
  6602. die ();
  6603. }
  6604. Doo::loadModel ( 'invoiceReceivables' );
  6605. $invoiceReceivables = new invoiceReceivables ();
  6606. Doo::loadModel ( 'invoice' );
  6607. $invoice = new invoice ();
  6608. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid ); // 入账完成 待定 and postStatus=1
  6609. $flag = true;
  6610. $invoiceDetail = $invoice->getInvoiceByTitle ( $detail ['recepitTitleMark'], 'EXACTLY', " and status=2 and printStatus=1 and untreadStatus=0 ", $flag ); //
  6611. $bakDetail = array ();
  6612. if ($flag === false) {
  6613. array_push ( $bakDetail, $invoiceDetail );
  6614. $invoiceDetail = $bakDetail;
  6615. }
  6616. $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>
  6617. <tr>
  6618. <td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  6619. <td>' . $detail ['receivablesMessage'] . '</td>
  6620. <td>' . $detail ['receivablesBank'] . '<br>' . $detail ['receivablesDate'] . '</td>
  6621. <td>' . $detail ['title'] . '-' . $detail ['username'] . '<br>' . $detail ['confirmTime'] . '</td>
  6622. <td>' . $detail ['recepitTitleMark'] . '</td>
  6623. </tr></tbody></table>';
  6624. $isInvoice = false;
  6625. $invoiceHtml = '';
  6626. if (empty ( $invoiceDetail )) {
  6627. $isInvoice = true;
  6628. } else {
  6629. $invoiceHtml = '<table class="table table-bordered table-condensed">
  6630. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody>';
  6631. foreach ( $invoiceDetail as $key => $value ) {
  6632. $invoiceHtml .= '<tr>';
  6633. if (! empty ( $value ['invoiceType'] )) {
  6634. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  6635. } else {
  6636. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  6637. }
  6638. if (! empty ( $value ['invoiceType'] )) {
  6639. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  6640. } else {
  6641. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  6642. }
  6643. $invoiceHtml .= '
  6644. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  6645. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  6646. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir" data-ikey="' . $value ['iidKey'] . '" href="javascript:void(0)">入账</a></td>
  6647. </tr>
  6648. ';
  6649. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  6650. if (empty ( $irList ))
  6651. $irList [0] ['sumPrice'] = 0;
  6652. $balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  6653. $priceString = '';
  6654. if ($balance < $detail ['receivablesPrice']) {
  6655. $priceString = '收款金额超过开票金额,';
  6656. }
  6657. if ($balance > $detail ['receivablesPrice']) {
  6658. $priceString = '收款金额低于开票金额,';
  6659. }
  6660. }
  6661. $invoiceHtml .= '
  6662. <script>
  6663. $(\'a[bind-receivables^="ir"]\').click(function() {
  6664. var data = $(this).attr("data-ikey");
  6665. $("input[name=\'invoiceKey\']").val(data);
  6666. var invoiceKey=data;
  6667. if(invoiceKey==""){
  6668. alert("入账错误,请重新刷新页面");
  6669. return false;
  6670. }
  6671. if(window.confirm("' . $priceString . '确定入账吗?")){
  6672. $("#IBR").submit();
  6673. }else{
  6674. return false;
  6675. }
  6676. });
  6677. </script>
  6678. ';
  6679. $invoiceHtml .= '</tbody></table>';
  6680. }
  6681. echo json_encode ( array (
  6682. 'status' => 1,
  6683. 'irkey' => $detail ['iridEn'],
  6684. 'receivablesHtml' => $receivablesHtml,
  6685. 'isInvoice' => $isInvoice,
  6686. 'invoiceHtml' => $invoiceHtml
  6687. ) );
  6688. }
  6689. function ajaxGetInvoiceReceivablesByTitle() {
  6690. $title = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  6691. if (empty ( $title )) {
  6692. echo json_encode ( array (
  6693. 'status' => 2,
  6694. 'msg' => 'illegal request'
  6695. ) );
  6696. die ();
  6697. }
  6698. Doo::loadModel ( 'invoice' );
  6699. $invoice = new invoice ();
  6700. $invoiceDetail = $invoice->getInvoiceByTitle ( $title, 'FUZZY', " and status=2 and printStatus=1 and untreadStatus=0 and (irid='' or irid is null) ", true );
  6701. $invoiceHtml = '';
  6702. if (! empty ( $invoiceDetail )) {
  6703. $invoiceHtml = '<table class="table table-bordered table-condensed">
  6704. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody><tr>';
  6705. foreach ( $invoiceDetail as $key => $value ) {
  6706. if (! empty ( $value ['invoiceType'] )) {
  6707. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  6708. } else {
  6709. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  6710. }
  6711. if (! empty ( $value ['invoiceType'] )) {
  6712. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  6713. } else {
  6714. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  6715. }
  6716. $invoiceHtml .= '
  6717. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  6718. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  6719. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir' . $value ['iidKeyXD'] . '" data-ikey="' . $value ['iidKey'] . '" href="#">入账</a></td>
  6720. </tr>
  6721. ';
  6722. }
  6723. $invoiceHtml .= '</tbody></table>
  6724. <script>
  6725. $(\'a[bind-receivables^="ir"]\').click(function() {
  6726. var data = $(this).attr("data-ikey");
  6727. $("input[name=\'invoiceKey\']").val(data);
  6728. var invoiceKey=$("input[name=\'invoiceKey\']").val();
  6729. if(invoiceKey==""){
  6730. alert("入账错误,请重新刷新页面");
  6731. return false;
  6732. }
  6733. if(window.confirm("确定入账吗?")){
  6734. $("#IBR").submit();
  6735. }else{
  6736. return false;
  6737. }
  6738. });
  6739. </script>
  6740. ';
  6741. }
  6742. echo json_encode ( array (
  6743. 'status' => 1,
  6744. 'invoiceHtml' => $invoiceHtml
  6745. ) );
  6746. }
  6747. function ajaxInvoicePushNotice() {
  6748. Doo::loadModel ( 'invoice' );
  6749. $invoice = new invoice ();
  6750. $approval = $invoice->getOne ( array (
  6751. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  6752. 'desc' => 'iid',
  6753. 'asArray' => true
  6754. ) );
  6755. $isNotice = false;
  6756. if (! empty ( $approval ))
  6757. $isNotice = true;
  6758. $response = array (
  6759. 'error' => 0,
  6760. 'isNotice' => $isNotice
  6761. );
  6762. echo json_encode ( $response );
  6763. exit ();
  6764. }
  6765. public function ajaxCheckInvoiceNoUniqueness() {
  6766. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  6767. Doo::loadModel ( 'invoice' );
  6768. $invoice = new invoice ();
  6769. if (! empty ( $invoiceNo )) {
  6770. Doo::loadModel ( 'invoicePaper' );
  6771. $invoicePaper = new invoicePaper ();
  6772. Doo::loadClass ( 'XDeode' );
  6773. $XDeode = new XDeode ( 5 );
  6774. $ipid = $XDeode->decode ( $invoiceNo );
  6775. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  6776. $info = $invoice->getOne ( array (
  6777. 'where' => "invoiceNo = '" . $paperDetail ['invoiceNo'] . "'",
  6778. 'asArray' => TRUE
  6779. ) );
  6780. if (! empty ( $info )) {
  6781. echo json_encode ( array (
  6782. 'error' => '发票号已存在'
  6783. ) );
  6784. die ();
  6785. } else
  6786. echo json_encode ( array (
  6787. 'ok' => '可以使用!'
  6788. ) );
  6789. die ();
  6790. }
  6791. }
  6792. function ajaxCheckInvoicePrice() {
  6793. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) && is_numeric ( $this->get_args ( 'receivablesPrice' ) ) ? $this->get_args ( 'receivablesPrice' ) : "";
  6794. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  6795. Doo::loadModel ( 'invoice' );
  6796. $invoice = new invoice ();
  6797. Doo::loadModel ( 'invoiceReceivables' );
  6798. $invoiceReceivables = new invoiceReceivables ();
  6799. Doo::loadClass ( 'XDeode' );
  6800. $XDeode = new XDeode ( 5 );
  6801. if (! empty ( $receivablesPrice ) && ! empty ( $iidKey )) {
  6802. $iidKey = $XDeode->decode ( $iidKey );
  6803. $info = $invoice->getInvoiceByIid ( $iidKey );
  6804. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $info ['irid'] );
  6805. if (empty ( $irList ))
  6806. $irList [0] ['sumPrice'] = 0;
  6807. $balance = $info ['invoicePrice'] - $irList [0] ['sumPrice'];
  6808. if ($balance < $receivablesPrice) {
  6809. echo json_encode ( array (
  6810. 'error' => '收款金额超过开票金额。'
  6811. ) );
  6812. die ();
  6813. }
  6814. if ($balance > $receivablesPrice) {
  6815. echo json_encode ( array (
  6816. 'error' => '收款金额低于开票金额。'
  6817. ) );
  6818. die ();
  6819. }
  6820. }
  6821. }
  6822. function ajaxGetInvoiceByNew() {
  6823. Doo::loadModel ( 'invoice' );
  6824. $invoice = new invoice ();
  6825. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );
  6826. echo json_encode ( array (
  6827. 'status' => 1,
  6828. 'detail' => $detail
  6829. ) );
  6830. }
  6831. /**
  6832. * 旧输入导入
  6833. */
  6834. function importInvoice() {
  6835. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  6836. $data ['emsg'] = "";
  6837. if ($emsg != "")
  6838. $data ['emsg'] = "请填写完整的数据";
  6839. $data ['time'] = time ();
  6840. $this->render ( "/admin/invoiceImport", $data );
  6841. }
  6842. function uploadInvoice() {
  6843. // move_uploaded_file($_FILES['Filedata']['tmp_name'], "/upload/".$_FILES['Filedata']['name']);
  6844. if (isset ( $_FILES ['Filedata'] ['name'] )) {
  6845. $file = $_FILES ['Filedata'] ['tmp_name'];
  6846. $error = false;
  6847. if (! is_uploaded_file ( $file )) {
  6848. $error = '400 Bad Request';
  6849. }
  6850. if ($error) {
  6851. header ( 'HTTP/1.0 ' . $error );
  6852. die ( 'Error ' . $error );
  6853. } else {
  6854. include (DOO::conf ()->SITE_PATH . 'protected/plugin/io.han.php');
  6855. $this->IoHandler = new IoHandler ();
  6856. $pics = explode ( '.', $_FILES ['Filedata'] ['name'] );
  6857. // $filedir=$_POST['time'];
  6858. // 调用定义物理路径
  6859. $t = DOO::conf ()->SITE_PATH . "upload/invoice/";
  6860. $this->IoHandler->MakeDir ( $t );
  6861. $filename = $this->_GetFileEXT ( $_FILES ['Filedata'] ['name'] );
  6862. if ($filename != 'xlsx')
  6863. return "";
  6864. // $upload_dir = $t."/".time().rand(10,100).".".$filename;
  6865. $upload_file = iconv ( "UTF-8", "GB2312", $_FILES ["Filedata"] ["name"] );
  6866. $upload_dir = $t . "/" . $upload_file;
  6867. $k = move_uploaded_file ( $file, $upload_dir );
  6868. if ($k) {
  6869. $m = round ( $_FILES ['Filedata'] ['size'] / 1024 / 1024, 2 );
  6870. echo $pics [0] . "." . $filename . "#" . $m . "#" . $_FILES ['Filedata'] ['size'];
  6871. }
  6872. }
  6873. }
  6874. }
  6875. function importInvoiceDo() {
  6876. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  6877. if ($path != "") {
  6878. Doo::loadModel ( 'invoice' );
  6879. Doo::loadModel ( 'staff' );
  6880. $staff = new staff ();
  6881. Doo::loadModel ( 'invoiceStatistics' );
  6882. Doo::loadModel ( 'invoiceOperationLog' );
  6883. echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  6884. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . $path );
  6885. // print_r ( $exlArray );
  6886. // die ();
  6887. // echo json_encode($exlArray);die;
  6888. foreach ( $exlArray as $key => $value ) {
  6889. // 开票
  6890. $invoice = new invoice ();
  6891. $invoice->invoiceNo = $value ['invoiceNo'];
  6892. $invoice->invoiceType = 0;
  6893. if ($value ['invoiceType'] == '专')
  6894. $invoice->invoiceType = 1;
  6895. $invoice->invoicePrice = $value ['invoicePrice'];
  6896. $invoice->invoiceQuantity = 1;
  6897. $invoice->invoiceUnitPrice = $value ['invoicePrice'];
  6898. $invoice->invoiceTitle = $value ['invoiceTitle'];
  6899. if ($value ['invoiceType'] == '专')
  6900. $invoice->invoiceCompany = $value ['invoiceTitle'];
  6901. $invoice->userName = $value ['userName'];
  6902. $sDetail = $staff->getStaffByName ( $value ['userName'] );
  6903. $invoice->sid = $sDetail ['sid'];
  6904. $invoice->cid = $sDetail ['cid'];
  6905. $invoice->categoryName = $sDetail ['category'];
  6906. $invoice->invoiceElement = $value ['invoiceElement'];
  6907. $invoice->remark = $value ['remark'];
  6908. $invoice->date = $value ['date'];
  6909. $invoice->printTime = $value ['date'];
  6910. $invoice->ipSource = 1;
  6911. $invoice->printStatus = 1;
  6912. $invoice->status = 2;
  6913. $invoice->postStatus = 1;
  6914. $invoice->untreadStatus = 0;
  6915. $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  6916. $iid = $invoice->insert ();
  6917. // 汇总
  6918. $invoiceStatistics = new invoiceStatistics ();
  6919. //
  6920. $item = array (
  6921. 'date' => $value ['date'],
  6922. 'priceClass' => 1,
  6923. 'cid' => $sDetail ['cid'],
  6924. 'staff' => $sDetail ['sid'],
  6925. 'invoicePrice' => $value ['invoicePrice']
  6926. );
  6927. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  6928. $invoiceOperationLog = new invoiceOperationLog ();
  6929. $item = array (
  6930. 'date' => date ( "Y-m-d H:i:s" ),
  6931. 'operation' => date ( "Y-m-d" ) . " 导入",
  6932. 'status' => 1,
  6933. 'img' => $sDetail ['avatar'],
  6934. 'username' => $sDetail ['username'],
  6935. 'uid' => $sDetail ['sid'],
  6936. 'category' => $sDetail ['category'],
  6937. 'iid' => $iid
  6938. );
  6939. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  6940. }
  6941. return '/importInvoice?count=' . count ( $exlArray );
  6942. // return "/keyonline";
  6943. }
  6944. echo 'no file';
  6945. }
  6946. function importInvoiceReceivables() {
  6947. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  6948. $data ['emsg'] = "";
  6949. if ($emsg != "")
  6950. $data ['emsg'] = "请填写完整的数据";
  6951. $data ['time'] = time ();
  6952. $this->render ( "/admin/invoiceReceivablesImport", $data );
  6953. }
  6954. // 导入入账数据
  6955. function importInvoiceReceivablesDo() {
  6956. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  6957. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  6958. if ($path != "") {
  6959. Doo::loadModel ( 'invoiceReceivables' );
  6960. Doo::loadModel ( 'invoice' );
  6961. Doo::loadModel ( 'staff' );
  6962. $staff = new staff ();
  6963. Doo::loadModel ( 'invoiceStatistics' );
  6964. // echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  6965. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path ), 'invoiceReceivables' );
  6966. // print_r ( $exlArray );
  6967. // die ();
  6968. // echo json_encode($exlArray);die;
  6969. foreach ( $exlArray as $key => $value ) {
  6970. // 收款
  6971. $invoiceReceivables = new invoiceReceivables ();
  6972. $invoice = new invoice ();
  6973. $invoiceReceivables->bindStatus = 1;
  6974. $invoiceReceivables->receivablesPrice = $value ['receivablesPrice'];
  6975. $invoiceReceivables->receivablesMessage = $value ['receivablesMessage'];
  6976. $invoiceReceivables->receivablesBank = $value ['receivablesBank'];
  6977. $invoiceReceivables->receivablesDate = $value ['receivablesDate'];
  6978. $sDetail = $staff->getStaffByName ( $value ['receivablesStaff'] );
  6979. $invoiceReceivables->receivablesCategory = $sDetail ['cid'] . ':' . $sDetail ['category'];
  6980. $invoiceReceivables->receivablesStaff = $sDetail ['sid'] . '-' . $sDetail ['username'];
  6981. $invoiceReceivables->receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  6982. $invoiceReceivables->sourcePrice = $value ['sourcePrice'];
  6983. $iDetail = $invoice->getInvoiceByInvoiceNo ( $value ['invoiceNo'] );
  6984. $invoiceReceivables->iid = $iDetail ['iid'];
  6985. $irid = $invoiceReceivables->insert ();
  6986. // 发票绑定收款
  6987. $detail = $iDetail;
  6988. $iridString = "";
  6989. if (empty ( $detail ['irid'] ))
  6990. $iridString = $irid;
  6991. else
  6992. $iridString = $detail ['irid'] . ',' . $irid;
  6993. $item = array (
  6994. 'irid' => $iridString,
  6995. 'iid' => $detail ['iid']
  6996. );
  6997. $invoice->setInvoiceByCondition ( $item );
  6998. // 汇总
  6999. $invoiceStatistics = new invoiceStatistics ();
  7000. // 扣除入账统计金额
  7001. $item = array (
  7002. 'date' => $value ['receivablesDate'],
  7003. 'priceClass' => 3,
  7004. 'cid' => $sDetail ['cid'],
  7005. 'staff' => $sDetail ['sid'],
  7006. // 'irid' => $irid,
  7007. 'accountPrice' => $value ['receivablesPrice']
  7008. );
  7009. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  7010. }
  7011. return '/importInvoiceReceivables?count=' . count ( $exlArray );
  7012. echo 'data count ' . count ( $exlArray );
  7013. die ();
  7014. // return "/keyonline";
  7015. }
  7016. echo 'no file';
  7017. }
  7018. function formatExcelToArrayTrain($file_url = "") {
  7019. if (! file_exists ( $file_url )) {
  7020. return array ();
  7021. }
  7022. // Doo::loadClass ( 'PHPExcel' );
  7023. Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  7024. $PHPExcel = new PHPExcel ();
  7025. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  7026. if (! $PHPReader->canRead ( $file_url )) {
  7027. $PHPReader = new PHPExcel_Reader_Excel5 ();
  7028. if (! $PHPReader->canRead ( $file_url )) {
  7029. echo 'no Excel';
  7030. return;
  7031. }
  7032. }
  7033. $PHPExcel = $PHPReader->load ( $file_url );
  7034. /* * 读取excel文件中的第一个工作表 */
  7035. $currentSheet = $PHPExcel->getSheet ( 0 );
  7036. /* * 取得最大的列号 */
  7037. $allColumn = $currentSheet->getHighestColumn ();
  7038. /* * 取得一共有多少行 */
  7039. $allRow = $currentSheet->getHighestRow ();
  7040. $excel_array = array ();
  7041. // die($file_url);
  7042. $conk = 2;
  7043. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  7044. $excel_column = array ();
  7045. // 后期改进
  7046. if ($allColumn == 'AM')
  7047. $allColumn = 'Z';
  7048. /* * 从第A列开始输出 */
  7049. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  7050. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  7051. if ($val instanceof PHPExcel_RichText)
  7052. $val = $val->__toString ();
  7053. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  7054. // $val = "'" . addslashes ( $val ) . "'";
  7055. if ($currentColumn == 'A') {
  7056. $excel_column ['invoiceTitle'] = $val;
  7057. } elseif ($currentColumn == 'B')
  7058. $excel_column ['invoiceType'] = $val;
  7059. elseif ($currentColumn == 'C') {
  7060. $excel_column ['TIN'] = $val;
  7061. } elseif ($currentColumn == 'D') {
  7062. $excel_column ['address'] = $val;
  7063. } elseif ($currentColumn == 'E') {
  7064. $excel_column ['phone'] = $val;
  7065. } elseif ($currentColumn == 'F') {
  7066. $excel_column ['bank'] = $val;
  7067. } elseif ($currentColumn == 'G') {
  7068. $excel_column ['bankAccount'] = $val;
  7069. } elseif ($currentColumn == 'H') {
  7070. $excel_column ['invoiceElement'] = $val;
  7071. } elseif ($currentColumn == 'I') {
  7072. $excel_column ['invoiceQuantity'] = $val;
  7073. } elseif ($currentColumn == 'J') {
  7074. $excel_column ['invoiceUnitPrice'] = $val;
  7075. } elseif ($currentColumn == 'K') {
  7076. $excel_column ['remark'] = $val;
  7077. } elseif ($currentColumn == 'L') {
  7078. $excel_column ['recipientsAddress'] = $val;
  7079. } elseif ($currentColumn == 'M') {
  7080. $excel_column ['recipients'] = $val;
  7081. } elseif ($currentColumn == 'N') {
  7082. $excel_column ['recipientsPhone'] = $val;
  7083. }elseif ($currentColumn == 'O') {
  7084. $excel_column ['electronicPhone'] = $val;
  7085. } elseif ($currentColumn == 'P') {
  7086. $excel_column ['electronicEmail'] = $val;
  7087. }
  7088. }
  7089. if (! empty ( $excel_column ['invoiceTitle'] ) && ! empty ( $excel_column ['invoiceQuantity'] ) && ! empty ( $excel_column ['invoiceUnitPrice'] ))
  7090. array_push ( $excel_array, $excel_column );
  7091. }
  7092. return $excel_array;
  7093. }
  7094. /**
  7095. * 格式化excel文件为数组
  7096. * @param unknown_type $file_url
  7097. * @param unknown_type $mcid
  7098. */
  7099. function _format_excel_to_array($file_url = "", $sType = "") {
  7100. if (! file_exists ( $file_url )) {
  7101. return array ();
  7102. }
  7103. Doo::loadClass ( 'PHPExcel' );
  7104. // Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  7105. $PHPExcel = new PHPExcel ();
  7106. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  7107. if (! $PHPReader->canRead ( $file_url )) {
  7108. $PHPReader = new PHPExcel_Reader_Excel5 ();
  7109. if (! $PHPReader->canRead ( $file_url )) {
  7110. echo 'no Excel';
  7111. return;
  7112. }
  7113. }
  7114. $PHPExcel = $PHPReader->load ( $file_url );
  7115. /* * 读取excel文件中的第一个工作表 */
  7116. $currentSheet = $PHPExcel->getSheet ( 0 );
  7117. /* * 取得最大的列号 */
  7118. $allColumn = $currentSheet->getHighestColumn ();
  7119. /* * 取得一共有多少行 */
  7120. $allRow = $currentSheet->getHighestRow ();
  7121. $excel_array = array ();
  7122. // die($file_url);
  7123. $conk = 2;
  7124. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  7125. $excel_column = array ();
  7126. // 后期改进
  7127. if ($allColumn == 'AM')
  7128. $allColumn = 'Z';
  7129. /* * 从第A列开始输出 */
  7130. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  7131. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  7132. if ($val instanceof PHPExcel_RichText)
  7133. $val = $val->__toString ();
  7134. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  7135. // $val = "'" . addslashes ( $val ) . "'";
  7136. if ($sType == 'invoiceReceivables') {
  7137. if ($currentColumn == 'A')
  7138. $excel_column ['invoiceNo'] = $val;
  7139. elseif ($currentColumn == 'B')
  7140. $excel_column ['receivablesPrice'] = $val;
  7141. elseif ($currentColumn == 'C') {
  7142. $excel_column ['receivablesMessage'] = $val;
  7143. } elseif ($currentColumn == 'D') {
  7144. $excel_column ['receivablesBank'] = $val;
  7145. } elseif ($currentColumn == 'E') {
  7146. $excel_column ['receivablesDate'] = $this->excelTime ( $val );
  7147. } elseif ($currentColumn == 'F') {
  7148. $excel_column ['receivablesStaff'] = $val;
  7149. } elseif ($currentColumn == 'G') {
  7150. $excel_column ['sourcePrice'] = $val;
  7151. }
  7152. } elseif ($sType == "invoiceTrain") {
  7153. if ($currentColumn == 'A') {
  7154. $excel_column ['invoiceTitle'] = $val;
  7155. } elseif ($currentColumn == 'B')
  7156. $excel_column ['invoiceType'] = $val;
  7157. elseif ($currentColumn == 'C') {
  7158. $excel_column ['TIN'] = $val;
  7159. } elseif ($currentColumn == 'D') {
  7160. $excel_column ['address'] = $val;
  7161. } elseif ($currentColumn == 'E') {
  7162. $excel_column ['phone'] = $val;
  7163. } elseif ($currentColumn == 'F') {
  7164. $excel_column ['bank'] = $val;
  7165. } elseif ($currentColumn == 'G') {
  7166. $excel_column ['bankAccount'] = $val;
  7167. } elseif ($currentColumn == 'H') {
  7168. $excel_column ['invoiceElement'] = $val;
  7169. } elseif ($currentColumn == 'I') {
  7170. $excel_column ['invoiceQuantity'] = $val;
  7171. } elseif ($currentColumn == 'J') {
  7172. $excel_column ['invoiceUnitPrice'] = $val;
  7173. } elseif ($currentColumn == 'K') {
  7174. $excel_column ['remark'] = $val;
  7175. } elseif ($currentColumn == 'L') {
  7176. $excel_column ['recipientsAddress'] = $val;
  7177. } elseif ($currentColumn == 'M') {
  7178. $excel_column ['recipients'] = $val;
  7179. } elseif ($currentColumn == 'N') {
  7180. $excel_column ['recipientsPhone'] = $val;
  7181. }
  7182. } else {
  7183. if ($currentColumn == 'A')
  7184. $excel_column ['invoiceNo'] = $val;
  7185. elseif ($currentColumn == 'B')
  7186. $excel_column ['invoiceType'] = $val;
  7187. elseif ($currentColumn == 'C') {
  7188. $excel_column ['invoicePrice'] = $val;
  7189. } elseif ($currentColumn == 'D') {
  7190. $excel_column ['invoiceTitle'] = $val;
  7191. } elseif ($currentColumn == 'E') {
  7192. $excel_column ['userName'] = $val;
  7193. } elseif ($currentColumn == 'F') {
  7194. $excel_column ['categoryName'] = $val;
  7195. } elseif ($currentColumn == 'G') {
  7196. $excel_column ['invoiceElement'] = $val;
  7197. } elseif ($currentColumn == 'H') {
  7198. $excel_column ['remark'] = $val;
  7199. } elseif ($currentColumn == 'I') {
  7200. $excel_column ['date'] = $this->excelTime ( $val );
  7201. }
  7202. }
  7203. }
  7204. array_push ( $excel_array, $excel_column );
  7205. }
  7206. return $excel_array;
  7207. }
  7208. function excelTime($date, $time = false) {
  7209. if (function_exists ( 'GregorianToJD' )) {
  7210. if (is_numeric ( $date )) {
  7211. $jd = GregorianToJD ( 1, 1, 1970 );
  7212. $gregorian = JDToGregorian ( $jd + intval ( $date ) - 25569 );
  7213. $date = explode ( '/', $gregorian );
  7214. $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" : '');
  7215. return $date_str;
  7216. }
  7217. } else {
  7218. $date = $date > 25568 ? $date + 1 : 25569;
  7219. /* There was a bug if Converting date before 1-1-1970 (tstamp 0) */
  7220. $ofs = (70 * 365 + 17 + 2) * 86400;
  7221. $date = date ( "Y-m-d", ($date * 86400) - $ofs ) . ($time ? " 00:00:00" : '');
  7222. }
  7223. return $date;
  7224. }
  7225. /**
  7226. * 旧输入导入
  7227. */
  7228. function _GetFileEXT($filename) {
  7229. $pics = explode ( '.', $filename );
  7230. $num = count ( $pics );
  7231. return $pics [$num - 1];
  7232. }
  7233. function showCache($path = "", $sid = 0) {
  7234. // if (file_exists ( $path )) {
  7235. // $htm = file_get_contents ( $path );
  7236. // } else {
  7237. Doo::loadModel ( 'invoiceStatistics' );
  7238. $invoiceStatistics = new invoiceStatistics ();
  7239. $isBriefly = $invoiceStatistics->getBrieflyStatistics ( $sid );
  7240. $htm = '<tr><th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计开票</th>
  7241. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['invoicePrice'] . '</td>
  7242. <th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计入账</th>
  7243. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['accountPrice'] . '</td></tr>';
  7244. /*
  7245. * '<tr><th class="taC">今年累计开票</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['invoicePrice'] . '</td> <th class="taC">今年累计入账</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['accountPrice'] . '</td></tr>';
  7246. */
  7247. file_put_contents ( $path, $htm );
  7248. // }
  7249. return $htm;
  7250. }
  7251. /**
  7252. * 生成token
  7253. * @return string
  7254. */
  7255. function set_token() {
  7256. $str = md5 ( uniqid ( md5 ( microtime ( true ) ), true ) ); // 生成一个不会重复的字符串
  7257. $str = sha1 ( $str ); // 加密
  7258. return $str;
  7259. }
  7260. /**
  7261. * 获取get或者POST值
  7262. *
  7263. * @param string $name 属性名称
  7264. * @return fixed 值
  7265. */
  7266. function get_args($name) {
  7267. if (isset ( $_GET [$name] )) {
  7268. if (is_array ( $_GET [$name] ))
  7269. return $_GET [$name];
  7270. else
  7271. return addslashes ( $_GET [$name] );
  7272. } elseif (isset ( $_POST [$name] )) {
  7273. if (is_array ( $_POST [$name] ))
  7274. return $_POST [$name];
  7275. else
  7276. return addslashes ( $_POST [$name] );
  7277. } else
  7278. return false;
  7279. }
  7280. function SafeFilter(&$arr) {
  7281. $ra = Array (
  7282. '/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/',
  7283. '/script/',
  7284. '/javascript/',
  7285. '/vbscript/',
  7286. '/expression/',
  7287. '/applet/',
  7288. '/meta/',
  7289. '/xml/',
  7290. '/blink/',
  7291. '/link/',
  7292. '/style/',
  7293. '/embed/',
  7294. '/object/',
  7295. '/frame/',
  7296. '/layer/',
  7297. '/title/',
  7298. '/bgsound/',
  7299. '/base/',
  7300. '/onload/',
  7301. '/onunload/',
  7302. '/onchange/',
  7303. '/onsubmit/',
  7304. '/onreset/',
  7305. '/onselect/',
  7306. '/onblur/',
  7307. '/onfocus/',
  7308. '/onabort/',
  7309. '/onkeydown/',
  7310. '/onkeypress/',
  7311. '/onkeyup/',
  7312. '/onclick/',
  7313. '/ondblclick/',
  7314. '/onmousedown/',
  7315. '/onmousemove/',
  7316. '/onmouseout/',
  7317. '/onmouseover/',
  7318. '/onmouseup/',
  7319. '/onunload/'
  7320. );
  7321. if (is_array ( $arr )) {
  7322. foreach ( $arr as $key => $value ) {
  7323. if (! is_array ( $value )) {
  7324. if (! get_magic_quotes_gpc ()) // 不对magic_quotes_gpc转义过的字符使用addslashes(),避免双重转义。
  7325. {
  7326. $value = addslashes ( $value ); // 给单引号(')、双引号(")、反斜线(\)与 NUL(NULL 字符)加上反斜线转义
  7327. }
  7328. $value = preg_replace ( $ra, '', $value ); // 删除非打印字符,粗暴式过滤xss可疑字符串
  7329. $arr [$key] = htmlentities ( strip_tags ( $value ) ); // 去除 HTML 和 PHP 标记并转换为 HTML 实体
  7330. } else {
  7331. SafeFilter ( $arr [$key] );
  7332. }
  7333. }
  7334. }
  7335. }
  7336. /**
  7337. * Escape String
  7338. *
  7339. * @access public
  7340. * @param string
  7341. * @param bool whether or not the string will be used in a LIKE condition
  7342. * @return string
  7343. */
  7344. function escape_str($str, $like = FALSE) {
  7345. if (is_array ( $str )) {
  7346. foreach ( $str as $key => $val ) {
  7347. $str [$key] = $this->escape_str ( $val, $like );
  7348. }
  7349. return $str;
  7350. }
  7351. var_dump ( Doo::db ()->getDbObject () );
  7352. die ();
  7353. if (function_exists ( 'mysql_real_escape_string' ) and is_resource ( Doo::db ()->getDbObject () )) { // Doo::db ()->getDbObject()
  7354. $str = mysql_real_escape_string ( $str, Doo::db ()->getDbObject () );
  7355. } elseif (function_exists ( 'mysql_escape_string' )) {
  7356. $str = mysql_escape_string ( $str );
  7357. } else {
  7358. $str = addslashes ( $str );
  7359. }
  7360. // escape LIKE condition wildcards
  7361. if ($like === TRUE) {
  7362. $str = str_replace ( array (
  7363. '%',
  7364. '_'
  7365. ), array (
  7366. '\\%',
  7367. '\\_'
  7368. ), $str );
  7369. }
  7370. return $str;
  7371. }
  7372. /**
  7373. * 获得分页数据
  7374. * @param unknown_type $table
  7375. * @param unknown_type $condition
  7376. * @param unknown_type $on_page
  7377. * @param unknown_type $page_size
  7378. */
  7379. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  7380. $page_c = "";
  7381. $page ['previous'] = $this->get_previous ( $on_page );
  7382. $page ['on_page'] = $on_page;
  7383. $total_count = $this->get_table_count ( $table, $condition );
  7384. $total = intval ( $total_count / $page_size );
  7385. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  7386. $page ['total_data'] = $total_count;
  7387. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  7388. $i = 1;
  7389. $page_max = 1;
  7390. $page_width = 3;
  7391. if ($on_page >= $page_width) {
  7392. $page_max = intval ( $on_page / $page_width ) + 1;
  7393. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  7394. }
  7395. for(; $i <= $page ['total_page']; $i ++) {
  7396. if ($i == $on_page)
  7397. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  7398. else
  7399. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  7400. if ($i == ($page_width * $page_max))
  7401. break;
  7402. }
  7403. $page ['page'] = $page_c;
  7404. $page ['lower'] = (-- $on_page) * $page_size;
  7405. return $page;
  7406. }
  7407. /**
  7408. * 获取上一页
  7409. * @param unknown_type $on_page
  7410. */
  7411. function get_previous($on_page = 1) {
  7412. return $on_page != 0 ? $on_page - 1 : $on_page;
  7413. }
  7414. /**
  7415. * 获取总页数
  7416. * @param unknown_type $table
  7417. * @param unknown_type $condition
  7418. */
  7419. public function get_table_count($table = "", $condition = "") {
  7420. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  7421. $sql = "select count(*) as count from " . $table . " where " . $condition;
  7422. // echo $sql;die;
  7423. $query = Doo::db ()->query ( $sql );
  7424. $result = $query->fetch ();
  7425. return $result ['count'];
  7426. }
  7427. function isInvoiceNew($type = "GLOBAL") {
  7428. Doo::loadModel ( 'invoice' );
  7429. $invoice = new invoice ();
  7430. Doo::loadModel ( 'invoiceReceivables' );
  7431. $invoiceReceivables = new invoiceReceivables ();
  7432. Doo::loadModel ( 'staff' );
  7433. $staff = new staff ();
  7434. $st = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  7435. // 我的发票待处理
  7436. $pendingInvoice = $invoice->getOne ( array ( // or (status=2 and printStatus=1 and untreadStatus=0 ) or (status=2 and printStatus=1 and untreadStatus=2 )
  7437. 'where' => "(status=3 or status=4) and isDelete=0 and sid=" . $st [0] ['sid'],
  7438. 'desc' => 'iid',
  7439. 'asArray' => TRUE
  7440. ) );
  7441. // 我的收款待入账
  7442. /*
  7443. * $myClaim = $invoiceReceivables->getOne ( array ( 'where' => " receivablesStaff like '" . $st [0] ['sid'] . "-%' and receivablesCategory like '" . $st [0] ['cid'] . ":%' and bindStatus=0", 'desc' => 'irid', 'asArray' => TRUE ) );
  7444. */
  7445. // 发票审批
  7446. $approval = $invoice->getOne ( array (
  7447. 'where' => 'status=1 and pendingApprovals=' . $st [0] ['sid'],
  7448. 'desc' => 'iid',
  7449. 'asArray' => true
  7450. ) );
  7451. // 发票邮寄
  7452. $post = $invoice->getOne ( array (
  7453. 'where' => "postStatus=0 and printStatus=1 and isDelete=0 and doPost=1 and status=2",
  7454. 'asArray' => TRUE
  7455. ) );
  7456. // 发票打印
  7457. $print = $invoice->getOne ( array (
  7458. 'where' => "status=2 and printStatus=0 and untreadStatus=0 and moldManage like '%[\"" . $st [0] ['sid'] . "\",%'",
  7459. 'desc' => 'iid',
  7460. 'asArray' => TRUE
  7461. ) );
  7462. // 发票退票 printStatus=1 and
  7463. $untread = $invoice->getOne ( array (
  7464. 'where' => " untreadStatus=1 and status=2 ",
  7465. 'asArray' => TRUE
  7466. ) );
  7467. $new = array (
  7468. 'GLOBAL' => FALSE,
  7469. 'pendingInvoice' => FALSE,
  7470. // 'myClaim' => FALSE,
  7471. 'approval' => FALSE,
  7472. 'post' => FALSE,
  7473. 'print' => FALSE,
  7474. 'untread' => FALSE
  7475. );
  7476. // || ! empty ( $myClaim )
  7477. if (! empty ( $pendingInvoice ) || ! empty ( $approval ) || ! empty ( $post ) || ! empty ( $print ) || ! empty ( $untread ))
  7478. $new ['GLOBAL'] = TRUE;
  7479. if (! empty ( $pendingInvoice ))
  7480. $new ['pendingInvoice'] = TRUE;
  7481. // if (! empty ( $myClaim ))
  7482. // $new ['myClaim'] = TRUE;
  7483. if (! empty ( $approval ))
  7484. $new ['approval'] = TRUE;
  7485. if (! empty ( $post ))
  7486. $new ['post'] = TRUE;
  7487. if (! empty ( $print ))
  7488. $new ['print'] = TRUE;
  7489. if (! empty ( $untread ))
  7490. $new ['untread'] = TRUE;
  7491. return $new;
  7492. }
  7493. function setWXMsg($rid, $typeMsg = '') {
  7494. Doo::loadModel ( 'invoice' );
  7495. $invoice = new invoice ();
  7496. $invoiceDetail = $invoice->getOne ( array (
  7497. 'where' => 'iid=' . $rid,
  7498. 'asArray' => true
  7499. ) );
  7500. if (! empty ( $invoiceDetail )) {
  7501. Doo::loadModel ( 'staff' );
  7502. $staff = new staff ();
  7503. $staffmsg = $staff->getOne ( array (
  7504. 'where' => "sid='" . $invoiceDetail ['sid'] . "'",
  7505. 'asArray' => TRUE
  7506. ) );
  7507. if (! empty ( $staffmsg ['wxid'] )) {
  7508. require_once (SITE_PATH . '/protected/class/client.php');
  7509. $client = new client ( 'http://m.cld.smartcost.com.cn/' );
  7510. $user = $staffmsg ['wxid'];
  7511. $expCom = explode ( ":", $invoiceDetail ['expressCompany'] );
  7512. if (empty ( $expCom ))
  7513. $expCom [0] = '';
  7514. $msg = "";
  7515. if (empty ( $typeMsg ))
  7516. $msg = '太好了,您的发票' . $invoiceDetail ['invoiceSerial'] . ' 已邮寄 ' . $expCom [0] . ' ,快递号: <a href="https://m.kuaidi100.com/result.jsp?nu=' . $invoiceDetail ['expressNumber'] . '" >' . $invoiceDetail ['expressNumber'] . '</a>';
  7517. elseif ($typeMsg == "PRINT")
  7518. $msg = '太好了,您的发票已打印完成。';
  7519. $result = $client->SendMsg ( $user, $msg, 'text' );
  7520. }
  7521. }
  7522. }
  7523. /**
  7524. * 获取微信部门
  7525. * @param string $category
  7526. * @return number|mixed
  7527. */
  7528. function getToparty($category = '') {
  7529. $token = $this->getAccessToken (); //
  7530. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token={$token}&id=5" ), true );
  7531. $toparty = 0;
  7532. foreach ( $result ['department'] as $key => $value ) {
  7533. if ($value ['name'] == $category)
  7534. $toparty = $value ['id'];
  7535. }
  7536. return $toparty;
  7537. }
  7538. /**
  7539. * 获得某部门下的用户
  7540. * @param string $toparty
  7541. */
  7542. function getUserByToparty($toparty = '') {
  7543. $token = $this->getAccessToken (); //
  7544. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token={$token}&department_id={$toparty}" ), true );
  7545. $userList = array ();
  7546. foreach ( $result ['userlist'] as $key => $value ) {
  7547. array_push ( $userList, "'" . $value ['userid'] . "'" );
  7548. }
  7549. return $userList;
  7550. }
  7551. function msgSendToparty($msg, $title, $url, $toparty, $text = '') {
  7552. $token = $this->getAccessToken ();
  7553. if ($text == 'text') {
  7554. $data = '{
  7555. "touser": "' . $toparty . '",
  7556. "toparty": "",
  7557. "totag": "",
  7558. "msgtype": "text",
  7559. "agentid": 1000002,
  7560. "text": {
  7561. "content": "' . $msg . '"
  7562. },
  7563. "safe":0
  7564. }';
  7565. }
  7566. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  7567. if ($result->errmsg != 'ok') {
  7568. return 0;
  7569. } else {
  7570. return 1;
  7571. }
  7572. }
  7573. /**
  7574. * 获得可以发送微信用户列表
  7575. * @param string $category
  7576. * @return string
  7577. */
  7578. function getWxidByCategory($category = "") {
  7579. if (empty ( $category ))
  7580. return "";
  7581. Doo::loadModel ( 'staff' );
  7582. $staff = new staff ();
  7583. $toparty = $this->getToparty ( $category );
  7584. $wxList = array ();
  7585. $wxString = "";
  7586. if (! empty ( $toparty )) {
  7587. $userList = $this->getUserByToparty ( $toparty );
  7588. $userCon = implode ( ',', $userList );
  7589. // echo $userCon;
  7590. $sidList = $staff->getStaffByWxid ( $userCon );
  7591. foreach ( $sidList as $key => $value ) {
  7592. $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  7593. if ($falg) {
  7594. array_push ( $wxList, $value ['wxid'] );
  7595. }
  7596. }
  7597. $wxString = implode ( '|', $wxList );
  7598. }
  7599. return $wxString;
  7600. }
  7601. /**
  7602. * 读取发送信息规则判断是否需要发送
  7603. * @param number $sid
  7604. * @param string $sendType
  7605. * @return boolean
  7606. */
  7607. function isSendNotification($sid = 0, $sendType = '') {
  7608. Doo::loadModel ( "notificationConf" );
  7609. $notificationConf = new notificationConf ();
  7610. $detail = $notificationConf->getNotificationConfBySid ( $sid );
  7611. $conf = array ();
  7612. $sendFlag = true;
  7613. if (! empty ( $detail )) {
  7614. $conf = json_decode ( $detail ['conf'], true );
  7615. if (! empty ( $sendType )) {
  7616. if (isset ( $conf [$sendType] )) {
  7617. if ($conf [$sendType] == "CLOSE")
  7618. $sendFlag = false;
  7619. elseif ($conf [$sendType] == "Weekend") {
  7620. $day = date ( "w" );
  7621. if (1 <= $day && 5 >= $day)
  7622. $sendFlag = false;
  7623. } elseif ($conf [$sendType] == "OneToFriday") {
  7624. $day = date ( "w" );
  7625. if (0 == $day || 6 == $day)
  7626. $sendFlag = false;
  7627. }
  7628. }
  7629. } else
  7630. $sendFlag = false;
  7631. }
  7632. return $sendFlag;
  7633. }
  7634. /**
  7635. * 根据规则发送信息
  7636. * @param unknown $msg
  7637. * @param unknown $title
  7638. * @param unknown $url
  7639. * @param unknown $user
  7640. * @param string $text
  7641. * @return number
  7642. */
  7643. private function msgSend($msg, $title, $url, $user, $sid = 0, $sendType = '') {
  7644. $token = $this->getAccessToken ();
  7645. $falg = $this->isSendNotification ( $sid, $sendType );
  7646. // if ($text == 'text') {
  7647. // $data = '{
  7648. // "touser": "' . $user . '",
  7649. // "toparty": "",
  7650. // "totag": "",
  7651. // "msgtype": "text",
  7652. // "agentid": 1000002,
  7653. // "text": {
  7654. // "content": "' . $msg . '"
  7655. // },
  7656. // "safe":0
  7657. // }';
  7658. // } else {
  7659. $data = '{
  7660. "touser": "' . $user . '",
  7661. "toparty": "",
  7662. "totag": "",
  7663. "msgtype": "news",
  7664. "agentid": 1000002,
  7665. "news": {
  7666. "articles":[
  7667. {
  7668. "title": "' . $title . '",
  7669. "description": "' . $msg . '",
  7670. "url": "' . $url . '",
  7671. "picurl": ""
  7672. }
  7673. ]
  7674. }
  7675. }';
  7676. // }
  7677. if ($falg) {
  7678. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  7679. if ($result->errmsg != 'ok') {
  7680. return 0;
  7681. } else {
  7682. return 1;
  7683. }
  7684. } else
  7685. return 0;
  7686. }
  7687. private function getAccessToken() {
  7688. // access_token 应该全局存储与更新,以下代码以写入到文件中做示例
  7689. // $file = './access_token.txt';
  7690. // $data = json_decode ( file_get_contents ( $file ) );
  7691. // if ($data->expire_time < time () or ! $data->expire_time) {
  7692. // 如果是企业号用以下URL获取access_token
  7693. $url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$this->appId&corpsecret=$this->appSecret";
  7694. // $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$this->appId&secret=$this->appSecret";
  7695. $res = json_decode ( $this->httpGet ( $url ) );
  7696. $access_token = $res->access_token;
  7697. // echo $access_token;
  7698. // if ($access_token) {
  7699. // $data->expire_time = time () + 7000;
  7700. // $data->access_token = $access_token;
  7701. // $fp = fopen ( $file, "w" );
  7702. // fwrite ( $fp, json_encode ( $data ) );
  7703. // fclose ( $fp );
  7704. // }
  7705. // } else {
  7706. // $access_token = $data->access_token;
  7707. // }
  7708. return $access_token;
  7709. }
  7710. private function httpGet($url) {
  7711. $curl = curl_init ();
  7712. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  7713. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  7714. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  7715. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  7716. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  7717. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  7718. curl_setopt ( $curl, CURLOPT_URL, $url );
  7719. $res = curl_exec ( $curl );
  7720. curl_close ( $curl );
  7721. return $res;
  7722. }
  7723. private function httpPost($url, $data) {
  7724. $curl = curl_init ();
  7725. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  7726. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  7727. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  7728. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  7729. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  7730. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  7731. curl_setopt ( $curl, CURLOPT_URL, $url );
  7732. curl_setopt ( $curl, CURLOPT_POST, 1 );
  7733. curl_setopt ( $curl, CURLOPT_POSTFIELDS, $data );
  7734. $res = curl_exec ( $curl );
  7735. curl_close ( $curl );
  7736. return $res;
  7737. }
  7738. }
  7739. ?>