InvoiceController.php 332 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162
  1. <?php
  2. /**
  3. * 开票功能控制器
  4. * @author CP
  5. * @version 1.0
  6. * @namespace invoice
  7. * @package invoiceController
  8. */
  9. require "protected/services/invoice_service.php";
  10. class InvoiceController extends DooController {
  11. public $staff;
  12. public $NEW;
  13. public $data;
  14. public $invoiceService;
  15. private $INVOICEKEY = "APPROVAL";
  16. private $INVOICECOLLECTPATH = "protected/cache/invoiceCollect/";
  17. private $ACTION = '';
  18. private $appId = 'wx3ee46531947a1384';
  19. private $appSecret = 'awGWzy3J5q_96VXKBLA2BQ9RpiT0LiPXnkMF-xV6h5o'; // awGWzy3J5q_96VXKBLA2BXU6mVCGynPGD-sxUCsdNDE //'PeiQVH8tbQE7pM9pVO4AIPlX9FFNpwu7O6Iy6VFcAVtpjTA3Qn42dbNmktBFkUHo';
  20. public function beforeRun($resource, $action) {
  21. Doo::loadModel ( "invoiceManage" );
  22. $invoiceManage = new invoiceManage ();
  23. Doo::loadClass ( 'XDeode' );
  24. $XDeode = new XDeode ( 5 );
  25. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  26. header ( 'Content-Type:text/html;charset=utf-8' );
  27. $moldList = $invoiceManage->getInvoiceByStaff ( $sid );
  28. if (empty ( $moldList )) {
  29. $flag = false;
  30. $uGroups = 'ordinary';
  31. if (Doo::acl ()->isAllowed ( $uGroups, $resource, $action )) {
  32. $flag = true;
  33. }
  34. } else {
  35. $flag = false;
  36. array_push ( $moldList, array (
  37. 'mold' => 'ordinary'
  38. ) );
  39. // 删除审批人后-加入权限问题-暂时关闭
  40. $fileInvoice = file_get_contents ( "protected/config/invoice/invoice.ini" );
  41. $fiML = json_decode ( $fileInvoice, true );
  42. if (empty ( $fiML ))
  43. $fiML = array ();
  44. foreach ( $fiML as $key => $value ) {
  45. $sidList = explode ( ',', $value );
  46. foreach ( $sidList as $k => $v ) {
  47. if ($v == $sid) {
  48. array_push ( $moldList, array (
  49. 'mold' => $key
  50. ) );
  51. break;
  52. }
  53. }
  54. }
  55. foreach ( $moldList as $value ) {
  56. if (Doo::acl ()->isAllowed ( $value ['mold'], $resource, $action )) {
  57. $flag = true;
  58. break;
  59. }
  60. }
  61. }
  62. /*
  63. * Doo::acl()->isAllowed($uGroups['groups'], $resource, $action);
  64. */
  65. // 单独判断办事处汇总的访问权限 invoiceAggregateCategoryDetail,invoiceAggregateStaffDetail
  66. if ($action == 'invoiceAggregateCategoryDetail' || $action == 'invoiceAggregateStaffDetail') {
  67. Doo::loadModel ( "invoiceCategoryManage" );
  68. $invoiceCategoryManage = new invoiceCategoryManage ();
  69. $icm = $invoiceCategoryManage->getInvoiceCMByStaff ( $sid );
  70. if (empty ( $icm ))
  71. die ( 'illegal request-iacd' );
  72. }
  73. // 单独判断应收款访问权限
  74. if ($action == 'invoiceAggregateCompanyDetail') {
  75. Doo::loadModel ( "invoiceCompanyManage" );
  76. $invoiceCompanyManage = new invoiceCompanyManage ();
  77. $icm = $invoiceCompanyManage->getInvoiceCMByStaff ( $sid );
  78. if (empty ( $icm ))
  79. die ( 'illegal request' );
  80. }
  81. // 主权限获得与判断
  82. Doo::loadModel ( 'staff' );
  83. $staff = new staff ();
  84. $detail = $staff->getStaffBySid ( $_COOKIE ["staff"] );
  85. $accessModular = 'INVOICE';
  86. if (empty ( $detail ['cldAccessArray'] ))
  87. die ( 'illegal request' );
  88. else {
  89. if (in_array ( $accessModular, $detail ['cldAccessArray'] )) {
  90. if (Doo::acl ()->isAllowed ( $accessModular, $resource, $action )) {
  91. $flag = true;
  92. } else {
  93. $flag = false;
  94. }
  95. } else {
  96. die ( 'illegal request' );
  97. }
  98. }
  99. if (! $flag)
  100. die ( 'illegal request' );
  101. }
  102. function __construct() {
  103. $this->invoiceService = new invoice_service ();
  104. //echo $routeRs ['1'];
  105. //die('dd');
  106. if (isset ( $_COOKIE ["staff"] )) {
  107. if (! empty ( $_COOKIE ["staff"] )) {
  108. Doo::loadModel ( 'staff' );
  109. $staff = new staff ();
  110. $uriPartsOrig = explode ( '/', $_SERVER ['REQUEST_URI'] );
  111. $this->ACTION = $uriPartsOrig [1];
  112. $this->data ['new'] = $this->isInvoiceNew ();
  113. $this->staff = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  114. $this->data ['isStaffCompleteMsg'] = false;
  115. $detail = $staff->checkStaffInfoIsComplete ( $_COOKIE ["staff"] );
  116. if (! empty ( $detail ))
  117. $this->data ['isStaffCompleteMsg'] = true;
  118. return "/";
  119. }
  120. }
  121. Doo::loadCore ( 'uri/DooUriRouter' );
  122. $router = new DooUriRouter ();
  123. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  124. if ($routeRs ['1'] != "login") {
  125. header ( 'Content-Type:text/html;charset=utf-8' );
  126. @header ( "Location: /login" );
  127. }
  128. }
  129. function testSend() {
  130. // 测试根据规则发送信息 普通发送
  131. // $pendingApprovalsSid = 41;
  132. // Doo::loadModel ( 'staff' );
  133. // $staff = new staff ();
  134. // $username2 = $staff->getOne ( array ( 'select' => 'wxid', 'where' => 'sid=' . $pendingApprovalsSid, 'asArray' => TRUE ) );
  135. // // 发送微信审批通知
  136. // $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  137. // $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  138. // Doo::loadModel ( 'staff' );
  139. // $staff = new staff ();
  140. // $toparty = $this->getToparty ( '广东办' );
  141. // $wxList = array ();
  142. // if (! empty ( $toparty )) {
  143. // $userList = $this->getUserByToparty ( $toparty );
  144. // $userCon = implode ( ',', $userList );
  145. // // echo $userCon;
  146. // $sidList = $staff->getStaffByWxid ( $userCon );
  147. // foreach ( $sidList as $key => $value ) {
  148. // $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  149. // if ($falg) {
  150. // array_push ( $wxList, $value ['wxid'] );
  151. // }
  152. // }
  153. // $wxString = implode ( '|', $wxList );
  154. // print_r ( $wxList );
  155. // echo $wxString;
  156. // }
  157. // 测试发送
  158. /*
  159. * //$toparty = $this->getWxidByCategory( $receivablesCategory [1] ); $toparty = $this->getToparty ( $receivablesCategory [1] ); $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。'; if ($toparty != 0) $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  160. */
  161. // print_r ( $userList );
  162. // $msTouser='caipin|outaozhen';
  163. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  164. // $title2 = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  165. // $hfreult = $this->msgSend ( '', $title2, '', 'outaozhen' );
  166. // $toparty= $this->getToparty('广东办');
  167. // $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  168. // $toparty = 26;
  169. // $msg = '';
  170. // $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/1.html';
  171. // $hfreult = $this->msgSendToparty ( $msg, '', '', $toparty,'text' );
  172. }
  173. function invoice() {
  174. Doo::loadModel ( 'invoice' );
  175. $invoice = new invoice ();
  176. Doo::loadModel ( 'express' );
  177. $express = new express ();
  178. $expressList = $express->getExpressByAll ();
  179. $this->data ['expressList'] = $expressList;
  180. // Doo::loadModel ( 'invoiceReceivables' );
  181. // $invoiceReceivables = new invoiceReceivables ();
  182. // $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  183. Doo::loadClass ( 'XDeode' );
  184. $XDeode = new XDeode ( 5 );
  185. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  186. Doo::loadModel ( 'invoiceStatistics' );
  187. $invoiceStatistics = new invoiceStatistics ();
  188. $isMonth = $invoiceStatistics->getStatisticsByMonth ( $sid );
  189. // 缓存统计结果
  190. $year = date ( "Y" );
  191. $tmp_date = date ( "Ym" );
  192. $tmp_year = substr ( $tmp_date, 0, 4 );
  193. $tmp_mon = substr ( $tmp_date, 4, 2 );
  194. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  195. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  196. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . "_" . $sid . ".htm";
  197. if (is_file ( $path ))
  198. $htm = file_get_contents ( $path );
  199. else
  200. $htm = $this->showCache ( $path, $sid );
  201. $invoiceList = $invoice->getMyInvoice ( $sid );
  202. $sql = 'status=2 and printStatus=1 and irid!="" and sid=' . $sid;
  203. $list = $invoice->getInvoiceByUntreadStatusPage ( 4, $sql );
  204. // 我的待入账发票 and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  205. $sql = "status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid=" . $sid;
  206. $myInvoiceUnAccount = $invoice->getInvoiceByUntreadStatusPage ( 4, $sql );
  207. // 获得已退票功能
  208. $untreadStatusList = $invoice->getMyInvoiceByUntreadStatus ( 2, 0, 5, $sid );
  209. $this->data ['untreadStatusList'] = $untreadStatusList;
  210. // print_r($untreadStatusList);
  211. $this->data ['isMonth'] = $isMonth;
  212. $this->data ['htm'] = $htm;
  213. $this->data ['invoiceList'] = $invoiceList;
  214. $this->data ['receivablesList'] = $list;
  215. $this->data ['myInvoiceUnAccount'] = $myInvoiceUnAccount;
  216. $this->data ['memu'] = "invoice";
  217. $this->data ['staff'] = $this->staff;
  218. $this->data ['receiptMemu'] = 'invoice';
  219. $this->render ( "/admin/invoice", $this->data );
  220. }
  221. function invoiceExpress() {
  222. $expressCom = isset ( $this->params ['expressCom'] ) ? $this->params ['expressCom'] : "";
  223. $expressNumber = isset ( $this->params ['expressNumber'] ) ? $this->params ['expressNumber'] : "";
  224. $this->data ['expressCom'] = $expressCom;
  225. $this->data ['expressNumber'] = $expressNumber;
  226. $this->render ( "/admin/invoiceExpress", $this->data );
  227. }
  228. function invoiceAdd() {
  229. session_start ();
  230. /*Doo::loadModel ( 'invoice' );
  231. $invoice = new invoice ();
  232. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );*/
  233. Doo::loadModel ( 'L_category' );
  234. $lCategory = new L_category ();
  235. $category = $lCategory->find ( array (
  236. 'asArray' => true
  237. ) );
  238. $this->data ['category'] = $category;
  239. Doo::loadModel ( 'invoiceTraining' );
  240. $invoiceTraining = new invoiceTraining ();
  241. $itList = $invoiceTraining->findAll( array (
  242. 'where' => " cid=" . $this->staff [0] ['cid'].' or creator ='.$this->staff [0]['sid'],
  243. 'desc'=>'itid',
  244. 'asArray' => TRUE
  245. ) );
  246. //$itList = $invoiceTraining->getInvoiceTrainingByCid ( $this->staff [0] ['cid'] );
  247. Doo::loadModel ( 'receipt' );
  248. $receipt = new receipt ();
  249. foreach ( $itList as $key => $value ) { // 不展示已结算完结的培训班
  250. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $value ['itid'] );
  251. if (! empty ( $receiptDetail )) {
  252. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9) {
  253. unset ( $itList [$key] );
  254. }
  255. }
  256. }
  257. $this->data ['itList'] = $itList;
  258. $token = $this->set_token ();
  259. $tokenTime=time().rand(5, 15);
  260. $_SESSION ['token_' . $this->staff [0] ['sidKey'].'_'.$tokenTime] = $token;
  261. $this->data ['token'] = $token;
  262. $this->data['tokenTime']=$tokenTime;
  263. $this->data ['memu'] = "invoice";
  264. $this->data ['staff'] = $this->staff;
  265. $this->data ['receiptMemu'] = 'invoice';
  266. $this->render ( "/admin/invoiceAdd", $this->data );
  267. }
  268. /**
  269. * 自更新发票信息库
  270. * @param unknown $invoicePrintDetail
  271. */
  272. function autoUpdateInvoiceInfoBase($invoicePrintDetail) {
  273. // 发票信息库
  274. Doo::loadModel ( 'invoiceInfoBase' );
  275. $invoiceInfoBase = new invoiceInfoBase ();
  276. $updateDate = strtotime ( $invoicePrintDetail ['date'] );
  277. $TIN = $invoicePrintDetail ['TIN'];
  278. $invoiceTitle = $invoicePrintDetail ['invoiceTitle'];
  279. if (empty ( $invoiceTitle ))
  280. $invoiceTitle = $invoicePrintDetail ['invoiceCompany'];
  281. $IIBList = $invoiceInfoBase->getInvoiceInfoByTT ( $TIN, $invoiceTitle );
  282. // 确认有该条发票信息
  283. $invoiceInfoBase = new invoiceInfoBase ();
  284. if (! empty ( $IIBList )) {
  285. // 发票库里的信息数量
  286. $IIBListCount = count ( $IIBList );
  287. if ($IIBListCount == 1) { // 更新发票--提交是最新的时间
  288. $item = array (
  289. 'iibID' => $IIBList [0] ['iibID'],
  290. 'invoiceTitle' => $invoiceTitle,
  291. 'TIN' => $TIN
  292. );
  293. if (! empty ( $invoicePrintDetail ['address'] )) {
  294. $item += array (
  295. 'address' => $invoicePrintDetail ['address']
  296. );
  297. }
  298. if (! empty ( $invoicePrintDetail ['phone'] )) {
  299. $item += array (
  300. 'phone' => $invoicePrintDetail ['phone']
  301. );
  302. }
  303. if (! empty ( $invoicePrintDetail ['bank'] )) {
  304. $item += array (
  305. 'bank' => $invoicePrintDetail ['bank']
  306. );
  307. }
  308. if (! empty ( $invoicePrintDetail ['bankAccount'] )) {
  309. $item += array (
  310. 'bankAccount' => $invoicePrintDetail ['bankAccount']
  311. );
  312. }
  313. if ($updateDate >= strtotime ($IIBList [0] ['updateDate'])) {
  314. $item += array (
  315. 'updateDate' => $invoicePrintDetail ['date']
  316. );
  317. $invoiceInfoBase->setInvoiceInfoBaseByCondition ( $item );
  318. }
  319. } else { // 删除多张发票,重新添加发票
  320. $iibIDStr = '';
  321. $iibID = array ();
  322. foreach ( $IIBList as $key => $value ) {
  323. array_push ( $iibID, $value ['iibID'] );
  324. }
  325. $iibIDStr = implode ( ",", $iibID ); // 删除
  326. $invoiceInfoBase->delInvoiceInfoBaseByIibStr ( $iibIDStr );
  327. $item = array (
  328. 'invoiceTitle' => $invoiceTitle,
  329. 'TIN' => $TIN,
  330. 'address' => $invoicePrintDetail ['address'],
  331. 'phone' => $invoicePrintDetail ['phone'],
  332. 'bank' => $invoicePrintDetail ['bank'],
  333. 'bankAccount' => $invoicePrintDetail ['bankAccount'],
  334. 'updateDate' => $invoicePrintDetail ['date']
  335. );
  336. $invoiceInfoBase->addInvoiceInfoBase ( $item );
  337. }
  338. } else { // 没有新增发票信息
  339. $item = array (
  340. 'invoiceTitle' => $invoiceTitle,
  341. 'TIN' => $TIN,
  342. 'address' => $invoicePrintDetail ['address'],
  343. 'phone' => $invoicePrintDetail ['phone'],
  344. 'bank' => $invoicePrintDetail ['bank'],
  345. 'bankAccount' => $invoicePrintDetail ['bankAccount'],
  346. 'updateDate' => $invoicePrintDetail ['date']
  347. );
  348. $invoiceInfoBase->addInvoiceInfoBase ( $item );
  349. }
  350. }
  351. function invoiceAddFill() {
  352. session_start ();
  353. Doo::loadModel ( 'L_category' );
  354. $lCategory = new L_category ();
  355. $category = $lCategory->find ( array (
  356. 'asArray' => true
  357. ) );
  358. $this->data ['category'] = $category;
  359. Doo::loadModel ( 'invoiceTraining' );
  360. $invoiceTraining = new invoiceTraining ();
  361. $itList = $invoiceTraining->getInvoiceTrainingByCid ( $this->staff [0] ['cid'] );
  362. $this->data ['itList'] = $itList;
  363. Doo::loadModel ( 'invoice' );
  364. $invoice = new invoice ();
  365. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );
  366. $detail ['mailItemsArray'] = json_decode ( $detail ['mailItemsJson'], true );
  367. $token = $this->set_token ();
  368. $tokenTime=time().rand(5, 15);
  369. $_SESSION ['token_' . $this->staff [0] ['sidKey'].'_'.$tokenTime] = $token;
  370. $this->data ['token'] = $token;
  371. $this->data['tokenTime']=$tokenTime;
  372. $this->data ['invoiceDetail'] = $detail;
  373. $this->data ['memu'] = "invoice";
  374. $this->data ['staff'] = $this->staff;
  375. $this->data ['receiptMemu'] = 'invoice';
  376. $this->render ( "/admin/invoiceAddFill", $this->data );
  377. }
  378. /**
  379. * 提交一份开票申请,并记录下操作日志
  380. *
  381. * @since 1.0.0
  382. * @var integer cid 办事处ID
  383. * @var integer invoiceType 发票类型
  384. * @var integer doPost 是否邮寄
  385. * @var integer invoicePrice 开票金额
  386. * @var string invoiceElement 开票内容
  387. * @var string invoiceTitle 发票抬头
  388. * @var string invoiceCompany 单位名称
  389. * @var string TIN 纳税人识别码
  390. * @var string address 注册地址
  391. * @var string phone 注册电话
  392. * @var string bank 开户银行
  393. * @var string bankAccount 银行账户
  394. * @var string recipients 收件人
  395. * @var string recipientsPhone 收件人手机/电话
  396. * @var string recipientsAddress 收件地址
  397. * @var string mailItems 邮寄物品
  398. * @var string remark 备注
  399. * @return string 返回跳转开票主页路径
  400. */
  401. function invoiceAddDo() {
  402. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  403. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  404. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  405. // $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  406. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  407. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  408. $invoiceForm = $this->get_args ( 'invoiceForm' ) ? $this->get_args ( 'invoiceForm' ) : "";
  409. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  410. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  411. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  412. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  413. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  414. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  415. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  416. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  417. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  418. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  419. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  420. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  421. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  422. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  423. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  424. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  425. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  426. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  427. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  428. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  429. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  430. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  431. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  432. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  433. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  434. $trainId = $this->get_args ( 'trainId' ) ? $this->get_args ( 'trainId' ) : 0;
  435. $settlementType = $this->get_args ( 'settlementType' ) ? $this->get_args ( 'settlementType' ) : "";
  436. $electronicPhone= $this->get_args ( 'electronicPhone' ) ? $this->get_args ( 'electronicPhone' ) : "";
  437. $electronicEmail = $this->get_args ( 'electronicEmail' ) ? $this->get_args ( 'electronicEmail' ) : "";
  438. /*
  439. * $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;
  440. */
  441. $token = $this->get_args ( 'token' ) ? $this->get_args ( 'token' ) : "";
  442. $tokenTime = $this->get_args ( 'tokenTime' ) ? $this->get_args ( 'tokenTime' ) : "";
  443. if (empty ( $token )) {
  444. die ( 'illegal request-token' );
  445. } else {
  446. session_start ();
  447. $sessionKey='token_' . $this->staff [0] ['sidKey'].'_'.$tokenTime;
  448. header ( 'Content-Type:text/html;charset=utf-8' );
  449. if (!isset($_SESSION [$sessionKey])||empty($_SESSION [$sessionKey])) {
  450. die ( '请重新刷新发票申请页面' );
  451. }elseif($_SESSION [$sessionKey]=='repeat'){
  452. die ( '请勿重复申请发票' );
  453. } else {
  454. if ($_SESSION [$sessionKey] != $token){
  455. die ( '请勿重复申请发票' );
  456. }else{
  457. $_SESSION [$sessionKey] = 'repeat';
  458. }
  459. }
  460. }
  461. if($invoiceForm=='electronic'){
  462. if(empty(trim($electronicPhone))&&empty(trim($electronicEmail))){
  463. die ( '请至少填写一种联系方式--电子发票' );
  464. }
  465. }
  466. if ($invoiceType == 1) {
  467. $temporary = $invoiceQuantity * $invoiceUnitPrice;
  468. if ($temporary > 100001) {
  469. header ( 'Content-Type:text/html;charset=utf-8' );
  470. die ( '专用发票总金额暂时不能超过100000.00(十万)元。' );
  471. }
  472. }elseif($invoiceType == 0){
  473. $temporary = $invoiceQuantity * $invoiceUnitPrice;
  474. if ($temporary > 100001) {
  475. header ( 'Content-Type:text/html;charset=utf-8' );
  476. die ( '专用发票总金额暂时不能超过100000.00(十万)元。' );
  477. }
  478. }else{
  479. die ( 'illegal request-invoiceType' );
  480. }
  481. if (empty ( $this->staff [0] ))
  482. die ( 'illegal request-Please login' );
  483. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $settlementType )&&!empty($invoiceForm)) {
  484. Doo::loadModel ( 'invoice' );
  485. $invoice = new invoice ();
  486. Doo::loadModel ( 'L_category' );
  487. $lCategory = new L_category ();
  488. Doo::loadModel ( 'invoiceManage' );
  489. $invoiceManage = new invoiceManage ();
  490. Doo::loadModel ( 'invoiceOperationLog' );
  491. $invoiceOperationLog = new invoiceOperationLog ();
  492. Doo::loadClass ( 'XDeode' );
  493. $XDeode = new XDeode ( 5 );
  494. $trainId = $XDeode->decode ( $trainId );
  495. $categoryDetil = $lCategory->getOne ( array (
  496. 'SELECT' => 'title',
  497. 'where' => 'cid=' . $cid,
  498. 'asArray' => true
  499. ) );
  500. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  501. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  502. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  503. // print_r(current($invoiceManageDetail ['staffList']));
  504. // die;
  505. $moldManage = array ();
  506. foreach ( $invoiceManageList as $key => $value ) {
  507. if ($value ['mold'] == '发票打印')
  508. $moldManage [$value ['mold']] = $value ['staffList'];
  509. elseif ($value ['mold'] == '发票邮寄')
  510. $moldManage [$value ['mold']] = $value ['staffList'];
  511. elseif ($value ['mold'] == '发票退票')
  512. $moldManage [$value ['mold']] = $value ['staffList'];
  513. }
  514. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  515. $st = '';
  516. if ($settlementType == 'SOFTWARE') {
  517. $st = 0;
  518. $trainId = 0;
  519. } elseif ($settlementType == 'TRAINING') {
  520. $st = 1;
  521. if (empty ( $trainId ) && ! is_numeric ( $trainId )) {
  522. die ( 'illegal request-trainingIdError' );
  523. }
  524. } else {
  525. die ( 'illegal request-settlementError' );
  526. }
  527. if($invoiceForm=='electronic'){
  528. $invoiceSerial="#FE" . date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
  529. $invoiceForm=1;
  530. $invoiceType=0;
  531. if(!empty($electronicPhone)||!empty($electronicEmail)){
  532. }else{
  533. die ( 'illegal request-electronicContact' );
  534. }
  535. $mailList = array ();
  536. $mailString = '备注:' . $mailItems;
  537. }elseif($invoiceForm=='paper'){
  538. $invoiceSerial="#F" . date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
  539. $invoiceForm=0;
  540. $mailList = array (
  541. 'invoice' => 1,
  542. 'mailItems' => $mailItems
  543. );
  544. $mailString = '发票x1张,备注:' . $mailItems;
  545. }else{
  546. die ( 'illegal request-invoiceForm' );
  547. }
  548. $item = array (
  549. 'cid' => $cid,
  550. 'categoryName' => $categoryDetil ['title'],
  551. 'invoiceElement' => $invoiceElement,
  552. 'invoiceForm'=>$invoiceForm,
  553. 'electronicPhone'=>$electronicPhone,
  554. 'electronicEmail'=>$electronicEmail,
  555. 'invoiceQuantity' => $invoiceQuantity,
  556. 'invoiceUnitPrice' => $invoiceUnitPrice,
  557. 'invoicePrice' => $invoicePrice,
  558. 'invoiceType' => $invoiceType,
  559. 'settlementType' => $st,
  560. 'doPost' => $doPost,
  561. 'status' => 1,
  562. 'invoiceSerial' => $invoiceSerial,
  563. 'date' => date ( "Y-m-d H:i:s" ),
  564. 'updateTime' => date ( "Y-m-d H:i:s" ),
  565. 'sid' => $this->staff [0] ['sid'],
  566. 'userName' => $this->staff [0] ['username'],
  567. 'invoiceManage' => $invoiceManageDetail ['staff'],
  568. 'pendingApprovals' => $pendingApprovalsSid,
  569. 'moldManage' => json_encode ( $moldManage ),
  570. 'remark' => $remark,
  571. 'trainId' => $trainId
  572. );
  573. if ($invoiceType == 0)
  574. $item += array (
  575. 'invoiceTitle' => $invoiceTitle,
  576. 'TIN' => $TINT,
  577. 'address' => $addressT,
  578. 'phone' => $phoneT,
  579. 'bank' => $bankT,
  580. 'bankAccount' => $bankAccountT
  581. );
  582. else {
  583. $item += array (
  584. 'invoiceCompany' => $invoiceCompany,
  585. 'TIN' => $TIN,
  586. 'address' => $address,
  587. 'phone' => $phone,
  588. 'bank' => $bank,
  589. 'bankAccount' => $bankAccount
  590. );
  591. }
  592. if ($doPost == 1) {
  593. if (! empty ( $softLock ))
  594. $mailList += array (
  595. 'softLock' => $softLockNum
  596. );
  597. else
  598. $mailList += array (
  599. 'softLock' => 0
  600. );
  601. if (! empty ( $contract ))
  602. $mailList += array (
  603. 'contract' => $contractNum
  604. );
  605. else
  606. $mailList += array (
  607. 'contract' => 0
  608. );
  609. if (! empty ( $instructions ))
  610. $mailList += array (
  611. 'instructions' => $instructionsNum
  612. );
  613. else
  614. $mailList += array (
  615. 'instructions' => 0
  616. );
  617. if (! empty ( $remittance ))
  618. $mailList += array (
  619. 'remittance' => $remittance
  620. );
  621. else
  622. $mailList += array (
  623. 'remittance' => ''
  624. );
  625. if (! empty ( $softLock ))
  626. $mailString .= ',软件锁x' . $softLockNum . '个';
  627. if (! empty ( $contract ))
  628. $mailString .= ',合同x' . $contractNum . '份';
  629. if (! empty ( $instructions ))
  630. $mailString .= ',说明书x' . $instructionsNum . '本';
  631. if (! empty ( $remittance ))
  632. $mailString .= ',汇款账号单(张)';
  633. $item += array (
  634. 'recipients' => $recipients,
  635. 'recipientsPhone' => $recipientsPhone,
  636. 'recipientsAddress' => $recipientsAddress,
  637. 'mailItems' => $mailString,
  638. 'mailItemsJson' => json_encode ( $mailList )
  639. );
  640. }
  641. $iid = $invoice->addInvoice ( $item );
  642. // 如果是培训班结算 创建培训班发票到培训班备份中
  643. if (! empty ( $st ) && $st == 1) {
  644. Doo::loadModel ( 'invoiceStore' );
  645. $invoiceStore = new invoiceStore ();
  646. Doo::loadModel ( 'invoiceTraining' );
  647. $invoiceTraining = new invoiceTraining ();
  648. $isid = $invoiceStore->setInvoiceToInvoiceStore ( $iid );
  649. $itemIS = array (
  650. 'isid' => $isid,
  651. 'ipSource' => 1,
  652. 'apStatus' => 1,
  653. 'iid' => $iid
  654. );
  655. $invoiceStore->setInvoiceStoreByCondition ( $itemIS );
  656. // 更新培训班总数量
  657. $detailIT = $invoiceTraining->getInvoiceTrainingByItid ( $trainId );
  658. $item = array (
  659. 'itid' => $trainId,
  660. 'invoiceTotal' => $detailIT ['invoiceTotal'] + 1,
  661. 'submitStatus' => 1
  662. );
  663. $itid = $invoiceTraining->setInvoiceTrainByCondition ( $item );
  664. }
  665. // 操作日志
  666. $item = array (
  667. 'date' => date ( "Y-m-d H:i:s" ),
  668. 'operation' => "创建",
  669. 'status' => 1,
  670. 'img' => $this->staff [0] ['avatar'],
  671. 'username' => $this->staff [0] ['username'],
  672. 'uid' => $this->staff [0] ['sid'],
  673. 'category' => $this->staff [0] ['category'],
  674. 'iid' => $iid
  675. );
  676. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  677. $item = array (
  678. 'date' => date ( "Y-m-d H:i:s" ),
  679. 'operation' => "提交审批",
  680. 'status' => 1,
  681. 'img' => $this->staff [0] ['avatar'],
  682. 'username' => $this->staff [0] ['username'],
  683. 'uid' => $this->staff [0] ['sid'],
  684. 'category' => $this->staff [0] ['category'],
  685. 'iid' => $iid
  686. );
  687. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  688. Doo::loadModel ( 'staff' );
  689. $staff = new staff ();
  690. $username2 = $staff->getOne ( array (
  691. 'select' => 'wxid',
  692. 'where' => 'sid=' . $pendingApprovalsSid,
  693. 'asArray' => TRUE
  694. ) );
  695. // 发送微信审批通知
  696. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  697. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  698. }
  699. return "/invoice";
  700. }
  701. function invoiceEdit() {
  702. Doo::loadClass ( 'XDeode' );
  703. $XDeode = new XDeode ( 5 );
  704. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  705. $iid = $XDeode->decode ( $iid );
  706. if (! is_numeric ( $iid ))
  707. die ( 'illegal request' );
  708. Doo::loadModel ( 'invoice' );
  709. $invoice = new invoice ();
  710. Doo::loadModel ( 'invoiceOperationLog' );
  711. $invoiceOperationLog = new invoiceOperationLog ();
  712. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  713. $operation = $invoiceOperationLog->getInvoiceOperationByDropped ( $iid );
  714. $invoiceDetail ['mailItemsJson'] ='';
  715. if(isset($invoiceDetail ['mailItemsJson'])){
  716. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  717. }
  718. $this->data ['operation'] = $operation;
  719. $this->data ['invoiceDetail'] = $invoiceDetail;
  720. $this->data ['memu'] = "invoice";
  721. $this->data ['staff'] = $this->staff;
  722. $this->data ['receiptMemu'] = 'invoice';
  723. $this->render ( "/admin/invoiceEdit", $this->data );
  724. }
  725. /**
  726. * 重新编辑退回的发票
  727. * @return string
  728. */
  729. function invoiceEditDo() {
  730. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  731. Doo::loadModel ( 'invoice' );
  732. $invoice = new invoice ();
  733. $iid = $invoice->authcode ( $iidKey );
  734. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  735. die ( 'illegal request' );
  736. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  737. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  738. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  739. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  740. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  741. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  742. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  743. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  744. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  745. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  746. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  747. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  748. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  749. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  750. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  751. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  752. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  753. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  754. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  755. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  756. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  757. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  758. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  759. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  760. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  761. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  762. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  763. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  764. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  765. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  766. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  767. $electronicPhone = $this->get_args ( 'electronicPhone' ) ? $this->get_args ( 'electronicPhone' ) : "";
  768. $electronicEmail = $this->get_args ( 'electronicEmail' ) ? $this->get_args ( 'electronicEmail' ) : "";
  769. $invoiceForm = $this->get_args ( 'invoiceForm' ) ? $this->get_args ( 'invoiceForm' ) : "";
  770. if ($invoiceType == 1) {
  771. $temporary = $invoiceQuantity * $invoiceUnitPrice;
  772. if ($temporary > 100001)
  773. die ( 'illegal request-Please priceError' );
  774. }
  775. if($invoiceForm=='electronic'){
  776. if(empty(trim($electronicPhone))&&empty(trim($electronicEmail))){
  777. die ( '请至少填写一种联系方式--电子发票' );
  778. }
  779. }
  780. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  781. Doo::loadModel ( 'invoiceManage' );
  782. $invoiceManage = new invoiceManage ();
  783. Doo::loadModel ( 'invoiceOperationLog' );
  784. $invoiceOperationLog = new invoiceOperationLog ();
  785. Doo::loadModel ( 'invoiceStore' );
  786. $invoiceStore = new invoiceStore ();
  787. $cid = explode ( ':', $cid );
  788. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  789. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  790. $moldManage = array ();
  791. foreach ( $invoiceManageList as $key => $value ) {
  792. if ($value ['mold'] == '发票打印')
  793. $moldManage [$value ['mold']] = $value ['staffList'];
  794. elseif ($value ['mold'] == '发票邮寄')
  795. $moldManage [$value ['mold']] = $value ['staffList'];
  796. elseif ($value ['mold'] == '发票打印')
  797. $moldManage [$value ['mold']] = $value ['staffList'];
  798. }
  799. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  800. if($invoiceForm=='electronic'){
  801. $invoiceForm=1;
  802. $invoiceType=0;
  803. if(!empty($electronicPhone)||!empty($electronicEmail)){
  804. }else{
  805. die ( 'illegal request-electronicContact' );
  806. }
  807. $mailList = array ();
  808. $mailString = '备注:' . $mailItems;
  809. }elseif($invoiceForm=='paper'){
  810. $invoiceForm=0;
  811. $mailList = array (
  812. 'invoice' => 1,
  813. 'mailItems' => $mailItems
  814. );
  815. $mailString = '发票x1张,备注:' . $mailItems;
  816. }else{
  817. die ( 'illegal request-invoiceForm' );
  818. }
  819. $item = array (
  820. 'iid' => $iid,
  821. 'cid' => $cid [0],
  822. 'categoryName' => $cid [1],
  823. 'invoiceElement' => $invoiceElement,
  824. 'invoiceForm'=>$invoiceForm,
  825. 'electronicPhone'=>$electronicPhone,
  826. 'electronicEmail'=>$electronicEmail,
  827. 'invoiceQuantity' => $invoiceQuantity,
  828. 'invoiceUnitPrice' => $invoiceUnitPrice,
  829. 'invoicePrice' => $invoicePrice,
  830. 'invoiceType' => $invoiceType,
  831. 'doPost' => $doPost,
  832. 'status' => 1,
  833. 'updateTime' => date ( "Y-m-d H:i:s" ),
  834. 'remark' => $remark
  835. );
  836. if ($invoiceType == 0)
  837. $item += array (
  838. 'invoiceTitle' => $invoiceTitle,
  839. 'TIN' => $TINT,
  840. 'address' => $addressT,
  841. 'phone' => $phoneT,
  842. 'bank' => $bankT,
  843. 'bankAccount' => $bankAccountT
  844. );
  845. else {
  846. $item += array (
  847. 'invoiceCompany' => $invoiceCompany,
  848. 'TIN' => $TIN,
  849. 'address' => $address,
  850. 'phone' => $phone,
  851. 'bank' => $bank,
  852. 'bankAccount' => $bankAccount
  853. );
  854. }
  855. if ($doPost == 1) {
  856. if (! empty ( $softLock ))
  857. $mailList += array (
  858. 'softLock' => $softLockNum
  859. );
  860. else
  861. $mailList += array (
  862. 'softLock' => '0'
  863. );
  864. if (! empty ( $contract ))
  865. $mailList += array (
  866. 'contract' => $contractNum
  867. );
  868. else
  869. $mailList += array (
  870. 'contract' => '0'
  871. );
  872. if (! empty ( $instructions ))
  873. $mailList += array (
  874. 'instructions' => $instructionsNum
  875. );
  876. else
  877. $mailList += array (
  878. 'instructions' => '0'
  879. );
  880. if (! empty ( $remittance ))
  881. $mailList += array (
  882. 'remittance' => $remittance
  883. );
  884. else
  885. $mailList += array (
  886. 'remittance' => ''
  887. );
  888. if (! empty ( $softLock ))
  889. $mailString .= ',软件锁x' . $softLockNum;
  890. if (! empty ( $contract ))
  891. $mailString .= ',合同x' . $contractNum;
  892. if (! empty ( $instructions ))
  893. $mailString .= ',说明书x' . $instructionsNum;
  894. if (! empty ( $remittance ))
  895. $mailString .= ',汇款账号单';
  896. $item += array (
  897. 'recipients' => $recipients,
  898. 'recipientsPhone' => $recipientsPhone,
  899. 'recipientsAddress' => $recipientsAddress,
  900. 'mailItems' => $mailString,
  901. 'mailItemsJson' => json_encode ( $mailList )
  902. );
  903. }
  904. $invoice->setInvoiceByCondition ( $item );
  905. // 更新培训班仓库里的发票
  906. $detail = $invoice->getInvoiceByIid ( $iid );
  907. if (! empty ( $detail ['isid'] )) {
  908. $invoiceStore->isid = $detail ['isid'];
  909. $invoiceStore->invoiceQuantity = $invoiceQuantity;
  910. $invoiceStore->invoiceUnitPrice = $invoiceUnitPrice;
  911. $invoiceStore->invoicePrice = $invoicePrice;
  912. $invoiceStore->update ();
  913. }
  914. $item = array (
  915. 'date' => date ( "Y-m-d H:i:s" ),
  916. 'operation' => "重新提交审批",
  917. 'status' => 1,
  918. 'img' => $this->staff [0] ['avatar'],
  919. 'username' => $this->staff [0] ['username'],
  920. 'uid' => $this->staff [0] ['sid'],
  921. 'category' => $this->staff [0] ['category'],
  922. 'iid' => $iid
  923. );
  924. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  925. }
  926. return "/invoice";
  927. }
  928. /**
  929. * 培训班
  930. */
  931. function invoiceTraining() {
  932. Doo::loadModel ( 'L_category' );
  933. $lCategory = new L_category ();
  934. Doo::loadModel ( 'invoiceTraining' );
  935. $invoiceTraining = new invoiceTraining ();
  936. Doo::loadModel ( 'invoiceTrainManage' );
  937. $invoiceTrainManage = new invoiceTrainManage ();
  938. $imcStaff = $invoiceTrainManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  939. $cidList = array ();
  940. foreach ( $imcStaff as $key => $value ) {
  941. array_push ( $cidList, $value ['cid'] );
  942. }
  943. if (empty ( $cidList )) {
  944. $cidString = $this->staff [0] ['cid'];
  945. } else {
  946. $cidString = implode ( ',', $cidList );
  947. $cidString .= $cidString . ',' . $this->staff [0] ['cid'];
  948. }
  949. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  950. // $itTodoList = $invoiceTraining->getInvoiceTrainingByTodo ( '', $cidString, $this->staff [0] ['sid'] );
  951. //TODO 待完成入账培训班
  952. $itTodoList=$this->invoiceService->getTrainByCategoryStaff(0,$cidString,$this->staff [0] ['sid']);
  953. // if($this->staff [0] ['sid']==94){
  954. // $itTodoList=$this->invoiceService->getTrainByCategoryStaff(0,$cidString,$this->staff [0] ['sid']);
  955. // }else{
  956. // $itTodoList = $invoiceTraining->getInvoiceTrainingByTodo ( '', $cidString, $this->staff [0] ['sid'] );
  957. // }
  958. // $itTodoList=$this->invoiceService->getTrainByCategoryStaff(0,$cidString,$this->staff [0] ['sid']);
  959. $itedList = $invoiceTraining->getInvoiceTrainingByStatus ( 2, '', $cidString, $this->staff [0] ['sid'] );
  960. $category = $lCategory->getCategory ();
  961. $itid = array ();
  962. foreach ( $itTodoList as $key => $value ) {
  963. array_push ( $itid, $value ['itid'] );
  964. // 如果入账100%更新为已完成
  965. if ($itTodoList [$key] ['arriveSchedule'] >= 100) {
  966. $invoiceTraining = new invoiceTraining ();
  967. $invoiceTraining->itid = $value ['itid'];
  968. $invoiceTraining->status = 2;
  969. $invoiceTraining->update ();
  970. }
  971. }
  972. foreach ( $itedList as $value ) {
  973. array_push ( $itid, $value ['itid'] );
  974. }
  975. $itid = implode ( ',', $itid );
  976. $this->data ['itStatist'] = $invoiceTraining->getInvoiceTrainStatistics ( $itid );
  977. // print_r($itTodoList);
  978. $this->data ['trainCount'] = count ( $itTodoList ) + count ( $itedList );
  979. $this->data ['itTodoList'] = $itTodoList;
  980. $this->data ['itedList'] = $itedList;
  981. $this->data ['category'] = $category;
  982. $this->data ['memu'] = "invoice";
  983. $this->data ['staff'] = $this->staff;
  984. $this->data ['receiptMemu'] = 'invoiceTraining';
  985. $this->render ( "/admin/invoiceTraining", $this->data );
  986. }
  987. /**
  988. * 创建培训班
  989. */
  990. function invoiceTrainingAdd() {
  991. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  992. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  993. $trainDate = $this->get_args ( 'trainDate' ) ? $this->get_args ( 'trainDate' ) : "";
  994. if (empty ( $this->staff [0] ))
  995. die ( 'illegal request' );
  996. if (! empty ( $cid ) && ! empty ( $trainName ) && ! empty ( $trainDate )) {
  997. Doo::loadModel ( 'invoiceTraining' );
  998. $invoiceTraining = new invoiceTraining ();
  999. Doo::loadModel ( 'invoice' );
  1000. $invoice = new invoice ();
  1001. Doo::loadModel ( 'L_category' );
  1002. $lCategory = new L_category ();
  1003. Doo::loadModel ( 'invoiceManage' );
  1004. $invoiceManage = new invoiceManage ();
  1005. Doo::loadModel ( 'invoiceOperationLog' );
  1006. $invoiceOperationLog = new invoiceOperationLog ();
  1007. $item = array (
  1008. 'cid' => $cid,
  1009. 'trainName' => $trainName,
  1010. 'trainDate' => $trainDate,
  1011. 'creator' => $this->staff [0] ['sid'],
  1012. 'creatorDate' => date ( "Y-m-d H:i:s" )
  1013. );
  1014. $itid = $invoiceTraining->addInvoiceTraining ( $item );
  1015. }
  1016. return "/invoiceTraining";
  1017. }
  1018. /**
  1019. * 删除培训班
  1020. */
  1021. function invoiceTrainingDelDo() {
  1022. $itid = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  1023. if (! empty ( $itid )) {
  1024. Doo::loadModel ( 'invoiceTraining' );
  1025. $invoiceTraining = new invoiceTraining ();
  1026. $invoiceTraining->delInvoiceTrainingByItid ( $itid );
  1027. }
  1028. return "/invoiceTraining";
  1029. }
  1030. /**
  1031. * 培训班详情
  1032. */
  1033. function invoiceTrainingDetail() {
  1034. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  1035. $trainStatus = $this->get_args ( 'trainStatus' ) ? $this->get_args ( 'trainStatus' ) : "ALL";
  1036. $itid = isset ( $this->params ['trainingKey'] ) ? $this->params ['trainingKey'] : "";
  1037. Doo::loadModel ( 'invoiceTraining' );
  1038. $invoiceTraining = new invoiceTraining ();
  1039. Doo::loadModel ( 'invoiceStore' );
  1040. $invoiceStore = new invoiceStore ();
  1041. if (empty ( $itid ))
  1042. die ( 'illegal request' );
  1043. $con = '(b.untreadStatus is null or b.untreadStatus!=2) and ';
  1044. if ($trainStatus == "SUBED")
  1045. $con = ' (b.untreadStatus is null ) and ';
  1046. elseif ($trainStatus == "APPROVAL")
  1047. $con = ' ( b.status=1 and b.untreadStatus!=2 ) and ';
  1048. elseif ($trainStatus == "TICKET")
  1049. $con = ' (b.printStatus=1 and b.status=2 and b.untreadStatus!=2) and ';
  1050. elseif ($trainStatus == "TICKETING") {
  1051. $con = ' (b.status=2 and b.untreadStatus=1) and ';
  1052. }
  1053. $con.=' a.invoiceForm=0 and ';
  1054. $detail = $invoiceTraining->getInvoiceTrainingByItid ( $itid );
  1055. $isList = $invoiceStore->getinvoiceStoreByItid ( $itid, $con,0 );
  1056. //print_r($isList);
  1057. $trainlistJson=$this->_trainList($isList);
  1058. if (empty ( $detail ))
  1059. die ( 'illegal request' );
  1060. // 培训班结算是否有和是否已经结算完成
  1061. Doo::loadModel ( 'receipt' );
  1062. $receipt = new receipt ();
  1063. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $itid );
  1064. $this->data ['receiptDetail'] = $receiptDetail;
  1065. $this->data ['trainStatus'] = $trainStatus;
  1066. $this->data ['itid'] = $itid;
  1067. $this->data ['trainlistJson'] = $trainlistJson;
  1068. $this->data ['iTrainDetail'] = $detail;
  1069. $this->data ['memu'] = "invoice";
  1070. $this->data ['staff'] = $this->staff;
  1071. $this->data ['receiptMemu'] = 'invoiceTraining';
  1072. $this->render ( "/admin/invoiceTrainingDetail", $this->data );
  1073. }
  1074. function invoiceTrainingElectronicDetail(){
  1075. $trainStatus = $this->get_args ( 'trainStatus' ) ? $this->get_args ( 'trainStatus' ) : "ALL";
  1076. $itid = isset ( $this->params ['trainingKey'] ) ? $this->params ['trainingKey'] : "";
  1077. Doo::loadModel ( 'invoiceTraining' );
  1078. $invoiceTraining = new invoiceTraining ();
  1079. Doo::loadModel ( 'invoiceStore' );
  1080. $invoiceStore = new invoiceStore ();
  1081. if (empty ( $itid ))
  1082. die ( 'illegal request' );
  1083. $con = ' (b.untreadStatus is null or b.untreadStatus!=2) and ';
  1084. if ($trainStatus == "SUBED")
  1085. $con = ' (b.untreadStatus is null ) and ';
  1086. elseif ($trainStatus == "APPROVAL")
  1087. $con = ' ( b.status=1 and b.untreadStatus!=2 ) and ';
  1088. elseif ($trainStatus == "TICKET")
  1089. $con = ' (b.printStatus=1 and b.status=2 and b.untreadStatus!=2) and ';
  1090. elseif ($trainStatus == "TICKETING") {
  1091. $con = ' (b.status=2 and b.untreadStatus=1) and ';
  1092. }
  1093. $con.=' a.invoiceForm=1 and ';
  1094. $detail = $invoiceTraining->getInvoiceTrainingByItid ( $itid );
  1095. // TODO 获得电子票
  1096. $isList = $invoiceStore->getinvoiceStoreByItid ( $itid, $con,1 );
  1097. //print_r($isList);
  1098. if (empty ( $detail )){
  1099. die ( 'illegal request' );
  1100. }
  1101. $trainlistJson=$this->_trainList($isList,1);
  1102. // 培训班结算是否有和是否已经结算完成
  1103. Doo::loadModel ( 'receipt' );
  1104. $receipt = new receipt ();
  1105. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $itid );
  1106. $this->data ['receiptDetail'] = $receiptDetail;
  1107. $this->data ['trainStatus'] = $trainStatus;
  1108. $this->data ['itid'] = $itid;
  1109. $this->data ['trainlistJson'] = $trainlistJson;
  1110. $this->data ['iTrainDetail'] = $detail;
  1111. $this->data ['memu'] = "invoice";
  1112. $this->data ['staff'] = $this->staff;
  1113. $this->data ['receiptMemu'] = 'invoiceTraining';
  1114. $this->render ( "/invoice/invoiceTrainingElectronicDetail", $this->data );
  1115. }
  1116. function _trainList($isList,$type=0){
  1117. $trainlist = array ();
  1118. foreach ( $isList as $key => $value ) {
  1119. $irDetail = array ();
  1120. if ($value ['apStatus'] == 1) {
  1121. // array_push ( $irDetail, '' );
  1122. array_push ( $irDetail, '<input disabled type="checkbox" style="display:none" >' );
  1123. } else {
  1124. array_push ( $irDetail, '<input type="checkbox" class="hide" id="' . $value ['storeKey'] . '" name="isBox" value="' . $value ['storeKey'] . '" > <a href="/invoiceStoreEdit/' . $value ['storeKey'] . '.html">编辑</a>
  1125. <a href="#confirm" onclick="invoiceStoreApproval(\'' . $value ['storeKey'] . '\')" data-toggle="modal">提交审批</a>
  1126. <a href="#del" node-iStore="del" data-key="' . $value ['storeKey'] . '" onclick="invoiceStoreDel(\'' . $value ['storeKey'] . '\')" data-toggle="modal" class="colRed">移除</a>' );
  1127. }
  1128. array_push ( $irDetail, $value ['invoiceSerial'] );
  1129. if ($value ['invoiceType'] == 1)
  1130. array_push ( $irDetail, $value ['invoiceCompany'] );
  1131. else
  1132. array_push ( $irDetail, $value ['invoiceTitle'] );
  1133. array_push ( $irDetail, $value ['TIN'] );
  1134. array_push ( $irDetail, $value ['userName'] );
  1135. if (empty ( $value ['mailItems'] ) && $value ['apStatus'] != 1) {
  1136. array_push ( $irDetail, '<a href="#confirm-erro" onclick="invoiceStoreMail(\'' . $value ['storeKey'] . '\')" data-toggle="modal">设置邮寄物品</a>' );
  1137. } else
  1138. array_push ( $irDetail, $value ['mailItems'] );
  1139. array_push ( $irDetail, $value ['recipientsAddress'] . $value ['recipients'] . $value ['recipientsPhone'] );
  1140. if($type==1){
  1141. array_push ( $irDetail, $value ['electronicPhone'] );
  1142. array_push ( $irDetail, $value ['electronicEmail'] );
  1143. }
  1144. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  1145. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  1146. array_push ( $irDetail, $value ['invoiceElement'] );
  1147. array_push ( $irDetail, $value ['invoiceQuantity'] );
  1148. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  1149. if ($value ['invoiceType'] == 1)
  1150. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  1151. else
  1152. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  1153. array_push ( $irDetail, $value ['remark'] );
  1154. if ($value ['status'] == 1)
  1155. array_push ( $irDetail, '审批中' );
  1156. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1)
  1157. array_push ( $irDetail, '已出票' );
  1158. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1 && $value ['printStatus'] != 'irid' && ($value ['untreadStatus'] == 3 || $value ['untreadStatus'] == 0))
  1159. array_push ( $irDetail, '已入账' );
  1160. else
  1161. array_push ( $irDetail, '' );
  1162. array_push ( $irDetail, $value ['invoiceNo'] );
  1163. array_push ( $irDetail, $value ['printTime'] );
  1164. $html = '';
  1165. foreach ( $value ['invoiceReceivables'] as $v ) {
  1166. $html .= '&nbsp;<a href="#billing" node-invoice="INFO" data-type="receivables" data-iskey="' . $v [2] . '" data-toggle="modal">' . $v [1] . '</a>';
  1167. }
  1168. array_push ( $irDetail, $html );
  1169. array_push ( $trainlist, $irDetail );
  1170. }
  1171. $trainlistJson = json_encode ( $trainlist );
  1172. return $trainlistJson;
  1173. }
  1174. /**
  1175. * 上传培训班发票
  1176. * @return string
  1177. */
  1178. function invoiceTrainingUpload() {
  1179. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  1180. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  1181. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  1182. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  1183. header ( "HTTP/1.1 500 Internal Server Error" );
  1184. echo "POST exceeded maximum allowed size.";
  1185. exit ( 0 );
  1186. }
  1187. // Settings
  1188. $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)
  1189. $upload_name = "Filedata";
  1190. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  1191. $extension_whitelist = array (
  1192. "doc",
  1193. "txt",
  1194. "jpg",
  1195. "gif",
  1196. "png"
  1197. ); // Allowed file extensions
  1198. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  1199. // Other variables
  1200. $MAX_FILENAME_LENGTH = 260;
  1201. $file_name = "";
  1202. $file_extension = "";
  1203. $uploadErrors = array (
  1204. 0 => "文件上传成功",
  1205. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  1206. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  1207. 3 => "上传的文件仅为部分文件",
  1208. 4 => "没有文件上传",
  1209. 6 => "缺少临时文件夹"
  1210. );
  1211. $nk = time ();
  1212. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  1213. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  1214. echo "文件无法保存.";
  1215. exit ( 0 );
  1216. }
  1217. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  1218. echo json_encode ( array (
  1219. 'filename' => $file_name,
  1220. 'id' => $nk
  1221. ) );
  1222. exit ( 0 );
  1223. }
  1224. /**
  1225. * 导入发票临时仓库
  1226. */
  1227. function invoiceStoreImport() {
  1228. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  1229. $trainingKey = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  1230. $path = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  1231. if ($path != "" && ! empty ( $trainingKey )) {
  1232. Doo::loadModel ( 'invoiceStore' );
  1233. Doo::loadModel ( 'staff' );
  1234. $staff = new staff ();
  1235. Doo::loadModel ( 'invoiceTraining' );
  1236. $invoiceTraining = new invoiceTraining ();
  1237. Doo::loadClass ( 'XDeode' );
  1238. $XDeode = new XDeode ( 5 );
  1239. $itid = $XDeode->decode ( $trainingKey );
  1240. // 培训班结算是否有和是否已经结算完成
  1241. Doo::loadModel ( 'receipt' );
  1242. $receipt = new receipt ();
  1243. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $itid );
  1244. if (! empty ( $receiptDetail )) {
  1245. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9)
  1246. die ( 'illegal request--status' );
  1247. }
  1248. $exlArray = $this->formatExcelToArrayTrain ( DOO::conf ()->SITE_PATH . "upload/invoiceTraining/" . $path );
  1249. $userName = $this->staff [0] ['username'];
  1250. $sDetail = $staff->getStaffByName ( $userName );
  1251. //print_r($exlArray);die;
  1252. // die('sdd');
  1253. // 可以优化
  1254. foreach ( $exlArray as $key => $value ) {
  1255. // 开票
  1256. $invoice = new invoiceStore ();
  1257. $invoice->trainId = $itid;
  1258. $invoice->invoiceType = 0;
  1259. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  1260. $invoice->invoiceType = 1;
  1261. elseif($value ['invoiceType'] == '电子'){
  1262. $invoice->invoiceType = 0;
  1263. $invoice->invoiceForm=1;
  1264. }
  1265. $invoice->invoiceQuantity = $value ['invoiceQuantity'];
  1266. $invoice->invoiceUnitPrice = $value ['invoiceUnitPrice'];
  1267. $invoice->invoicePrice = $value ['invoiceQuantity'] * $value ['invoiceUnitPrice'];
  1268. $invoice->invoiceTitle = $value ['invoiceTitle'];
  1269. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  1270. $invoice->invoiceCompany = $value ['invoiceTitle'];
  1271. $invoice->userName = $userName;
  1272. $invoice->sid = $sDetail ['sid'];
  1273. $invoice->cid = $sDetail ['cid'];
  1274. $invoice->categoryName = $sDetail ['category'];
  1275. $invoice->invoiceElement = $value ['invoiceElement'];
  1276. $invoice->remark = $value ['remark'];
  1277. // $invoice->date = $value ['date'];
  1278. // $invoice->printTime = $value ['date'];
  1279. $invoice->ipSource = 1;
  1280. $invoice->printStatus = 0;
  1281. $invoice->status = 0;
  1282. $invoice->postStatus = 1;
  1283. $invoice->untreadStatus = 0;
  1284. // $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1285. $invoice->TIN = $value ['TIN'];
  1286. $invoice->address = $value ['address'];
  1287. $invoice->phone = $value ['phone'];
  1288. $invoice->bank = $value ['bank'];
  1289. $invoice->bankAccount = $value ['bankAccount'];
  1290. $invoice->recipientsAddress = $value ['recipientsAddress'];
  1291. $invoice->recipients = $value ['recipients'];
  1292. $invoice->recipientsPhone = $value ['recipientsPhone'];
  1293. $invoice->electronicPhone = $value ['electronicPhone'];
  1294. $invoice->electronicEmail = $value ['electronicEmail'];
  1295. $iid = $invoice->insert ();
  1296. }
  1297. // 加入发票总数量
  1298. $item = array (
  1299. 'itid' => $itid,
  1300. 'invoiceTotal' => count ( $exlArray )
  1301. );
  1302. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1303. return '/invoiceTrainingDetail/' . $trainingKey . ".html";
  1304. }
  1305. echo 'no file';
  1306. }
  1307. /**
  1308. * 编辑仓库里的发票
  1309. */
  1310. function invoiceStoreEdit() {
  1311. Doo::loadClass ( 'XDeode' );
  1312. $XDeode = new XDeode ( 5 );
  1313. $iid = isset ( $this->params ['storeKey'] ) ? $this->params ['storeKey'] : "";
  1314. $iid = $XDeode->decode ( $iid );
  1315. if (! is_numeric ( $iid ))
  1316. die ( 'illegal request' );
  1317. Doo::loadModel ( 'invoiceStore' );
  1318. $invoiceStore = new invoiceStore ();
  1319. $invoiceDetail = $invoiceStore->getInvoiceStoreByIsid ( $iid );
  1320. // print_r($invoiceDetail);
  1321. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  1322. $this->data ['invoiceDetail'] = $invoiceDetail;
  1323. $this->data ['memu'] = "invoice";
  1324. $this->data ['staff'] = $this->staff;
  1325. $this->data ['receiptMemu'] = 'invoiceTraining';
  1326. $this->render ( "/admin/invoiceStoreEdit", $this->data );
  1327. }
  1328. function invoiceStoreEditDo() {
  1329. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1330. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1331. Doo::loadModel ( 'invoiceStore' );
  1332. $invoice = new invoiceStore ();
  1333. Doo::loadClass ( 'XDeode' );
  1334. $XDeode = new XDeode ( 5 );
  1335. $iid = $XDeode->decode ( $storeKey );
  1336. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1337. die ( 'illegal request' );
  1338. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  1339. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  1340. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  1341. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  1342. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  1343. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  1344. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  1345. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  1346. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  1347. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  1348. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  1349. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  1350. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  1351. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  1352. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1353. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1354. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1355. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1356. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  1357. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  1358. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  1359. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  1360. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  1361. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  1362. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1363. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1364. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1365. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1366. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1367. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1368. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1369. $electronicPhone = $this->get_args ( 'electronicPhone' ) ? $this->get_args ( 'electronicPhone' ) : "";
  1370. $electronicEmail = $this->get_args ( 'electronicEmail' ) ? $this->get_args ( 'electronicEmail' ) : "";
  1371. $invoiceForm = $this->get_args ( 'invoiceForm' ) ? $this->get_args ( 'invoiceForm' ) : "";
  1372. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  1373. $cid = explode ( ':', $cid );
  1374. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  1375. $item = array (
  1376. 'isid' => $iid,
  1377. 'cid' => $cid [0],
  1378. 'categoryName' => $cid [1],
  1379. 'invoiceElement' => $invoiceElement,
  1380. 'invoiceQuantity' => $invoiceQuantity,
  1381. 'invoiceUnitPrice' => $invoiceUnitPrice,
  1382. 'invoicePrice' => $invoicePrice,
  1383. 'invoiceType' => $invoiceType,
  1384. 'doPost' => $doPost,
  1385. 'status' => 1,
  1386. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1387. 'remark' => $remark
  1388. );
  1389. if ($invoiceType == 0)
  1390. $item += array (
  1391. 'invoiceTitle' => $invoiceTitle,
  1392. 'TIN' => $TINT,
  1393. 'address' => $addressT,
  1394. 'phone' => $phoneT,
  1395. 'bank' => $bankT,
  1396. 'bankAccount' => $bankAccountT
  1397. );
  1398. else {
  1399. $item += array (
  1400. 'invoiceCompany' => $invoiceCompany,
  1401. 'TIN' => $TIN,
  1402. 'address' => $address,
  1403. 'phone' => $phone,
  1404. 'bank' => $bank,
  1405. 'bankAccount' => $bankAccount
  1406. );
  1407. }
  1408. if($invoiceForm=='paper'){
  1409. $item += array (
  1410. 'invoiceForm' => 0
  1411. );
  1412. }elseif($invoiceForm=='electronic'){
  1413. $item += array (
  1414. 'invoiceForm' => 1,
  1415. 'electronicPhone' => $electronicPhone,
  1416. 'electronicEmail' => $electronicEmail,
  1417. );
  1418. }
  1419. if ($doPost == 1) {
  1420. $mailList = array (
  1421. 'invoice' => 1,
  1422. 'mailItems' => $mailItems
  1423. );
  1424. if (! empty ( $softLock ))
  1425. $mailList += array (
  1426. 'softLock' => $softLockNum
  1427. );
  1428. else
  1429. $mailList += array (
  1430. 'softLock' => '0'
  1431. );
  1432. if (! empty ( $contract ))
  1433. $mailList += array (
  1434. 'contract' => $contractNum
  1435. );
  1436. else
  1437. $mailList += array (
  1438. 'contract' => '0'
  1439. );
  1440. if (! empty ( $instructions ))
  1441. $mailList += array (
  1442. 'instructions' => $instructionsNum
  1443. );
  1444. else
  1445. $mailList += array (
  1446. 'instructions' => '0'
  1447. );
  1448. if (! empty ( $remittance ))
  1449. $mailList += array (
  1450. 'remittance' => $remittance
  1451. );
  1452. else
  1453. $mailList += array (
  1454. 'remittance' => ''
  1455. );
  1456. $mailString = '发票x1,备注:' . $mailItems;
  1457. if (! empty ( $softLock ))
  1458. $mailString .= ',软件锁x' . $softLockNum;
  1459. if (! empty ( $contract ))
  1460. $mailString .= ',合同x' . $contractNum;
  1461. if (! empty ( $instructions ))
  1462. $mailString .= ',说明书x' . $instructionsNum;
  1463. if (! empty ( $remittance ))
  1464. $mailString .= ',汇款账号单';
  1465. $item += array (
  1466. 'recipients' => $recipients,
  1467. 'recipientsPhone' => $recipientsPhone,
  1468. 'recipientsAddress' => $recipientsAddress,
  1469. 'mailItems' => $mailString,
  1470. 'mailItemsJson' => json_encode ( $mailList )
  1471. );
  1472. }
  1473. $invoice->setInvoiceStoreByCondition ( $item );
  1474. }
  1475. if(!empty($invoiceForm)&&$invoiceForm=='electronic'){
  1476. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1477. }else{
  1478. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1479. }
  1480. }
  1481. /**
  1482. *
  1483. * @return string
  1484. */
  1485. function invoiceStoreDelete() {
  1486. Doo::loadClass ( 'XDeode' );
  1487. $XDeode = new XDeode ( 5 );
  1488. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1489. $iStoreKey = $this->get_args ( 'iStoreKey' ) ? $this->get_args ( 'iStoreKey' ) : 0;
  1490. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1491. $isid = $XDeode->decode ( $iStoreKey );
  1492. $itid = $XDeode->decode ( $trainKey );
  1493. if (! is_numeric ( $isid ))
  1494. die ( 'illegal request' );
  1495. Doo::loadModel ( 'invoiceStore' );
  1496. $invoiceStore = new invoiceStore ();
  1497. $invoiceStore->delete ( array (
  1498. 'where' => 'isid=' . $isid,
  1499. 'limit' => 1
  1500. ) );
  1501. Doo::loadModel ( 'invoiceTraining' );
  1502. $invoiceTraining = new invoiceTraining ();
  1503. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1504. $item = array (
  1505. 'itid' => $itid,
  1506. 'invoiceTotal' => $itDetail ['invoiceTotal'] - 1
  1507. );
  1508. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1509. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1510. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1511. }else{
  1512. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1513. }
  1514. }
  1515. /**
  1516. * 批量删除库里发票
  1517. */
  1518. function invoiceStoreBatchDelete() {
  1519. Doo::loadClass ( 'XDeode' );
  1520. $XDeode = new XDeode ( 5 );
  1521. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1522. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1523. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1524. if (empty ( $trainKey ) || empty ( $storeKey ))
  1525. die ( 'illegal request-IdKey' );
  1526. $tid = $XDeode->decode ( $trainKey );
  1527. if (! is_numeric ( $tid ) && ! empty ( $storeKey ))
  1528. die ( 'illegal request' );
  1529. Doo::loadModel ( 'invoiceStore' );
  1530. $isidKeyList = explode ( ',', $storeKey );
  1531. $isidList = array ();
  1532. foreach ( $isidKeyList as $value ) {
  1533. $isid = $XDeode->decode ( $value );
  1534. if (! empty ( $isid ) && is_numeric ( $isid ))
  1535. array_push ( $isidList, $isid );
  1536. }
  1537. $isidString = implode ( ',', $isidList );
  1538. $invoiceStore = new invoiceStore ();
  1539. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,apStatus' );
  1540. $isidList = array ();
  1541. foreach ( $isList as $key => $value ) {
  1542. if ($value ['apStatus'] == 0)
  1543. array_push ( $isidList, $value ['isid'] );
  1544. }
  1545. $isidString = implode ( ',', $isidList );
  1546. // print_r($isList);
  1547. // echo $isidString;
  1548. $invoiceStore = new invoiceStore ();
  1549. $invoiceStore->delete ( array (
  1550. 'where' => "isid in ( " . $isidString . ")",
  1551. 'asArray' => TRUE
  1552. ) );
  1553. Doo::loadModel ( 'invoiceTraining' );
  1554. $invoiceTraining = new invoiceTraining ();
  1555. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1556. $item = array (
  1557. 'itid' => $tid,
  1558. 'invoiceTotal' => $itDetail ['invoiceTotal'] - count ( $isidList )
  1559. );
  1560. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1561. // echo $tid;
  1562. // echo $storeKey;
  1563. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1564. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1565. }else{
  1566. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1567. }
  1568. }
  1569. function invoiceStoreBatchElectronicPhone(){
  1570. $electronicPhone = $this->get_args ( 'electronicPhone' ) ? $this->get_args ( 'electronicPhone' ) : '';
  1571. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1572. Doo::loadClass ( 'XDeode' );
  1573. $XDeode = new XDeode ( 5 );
  1574. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1575. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1576. if (empty ( $trainKey ) || empty ( $storeKey ))
  1577. die ( 'illegal request-IdKey' );
  1578. $isidKeyList = explode ( ',', $storeKey );
  1579. $isidList = array ();
  1580. foreach ( $isidKeyList as $value ) {
  1581. $isid = $XDeode->decode ( $value );
  1582. if (! empty ( $isid ) && is_numeric ( $isid ))
  1583. array_push ( $isidList, $isid );
  1584. }
  1585. $isidString = implode ( ',', $isidList );
  1586. $trainId = $XDeode->decode ( $trainKey );
  1587. if (! is_numeric ( $isid ))
  1588. die ( 'illegal request--isid' );
  1589. Doo::loadModel ( 'invoiceStore' );
  1590. $invoiceStore = new invoiceStore ();
  1591. $item = array (
  1592. 'electronicPhone' => $electronicPhone
  1593. );
  1594. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1595. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1596. }
  1597. function invoiceStoreBatchElectronicEmail(){
  1598. $electronicEmail = $this->get_args ( 'electronicEmail' ) ? $this->get_args ( 'electronicEmail' ) : '';
  1599. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1600. Doo::loadClass ( 'XDeode' );
  1601. $XDeode = new XDeode ( 5 );
  1602. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1603. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1604. if (empty ( $trainKey ) || empty ( $storeKey ))
  1605. die ( 'illegal request-IdKey' );
  1606. $isidKeyList = explode ( ',', $storeKey );
  1607. $isidList = array ();
  1608. foreach ( $isidKeyList as $value ) {
  1609. $isid = $XDeode->decode ( $value );
  1610. if (! empty ( $isid ) && is_numeric ( $isid ))
  1611. array_push ( $isidList, $isid );
  1612. }
  1613. $isidString = implode ( ',', $isidList );
  1614. $trainId = $XDeode->decode ( $trainKey );
  1615. if (! is_numeric ( $isid ))
  1616. die ( 'illegal request' );
  1617. Doo::loadModel ( 'invoiceStore' );
  1618. $invoiceStore = new invoiceStore ();
  1619. $item = array (
  1620. 'electronicEmail' => $electronicEmail
  1621. );
  1622. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1623. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1624. }
  1625. /**
  1626. * 仓库发票提交审批
  1627. * @return string
  1628. */
  1629. function invoiceStoreApproval() {
  1630. Doo::loadClass ( 'XDeode' );
  1631. $XDeode = new XDeode ( 5 );
  1632. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1633. $iStoreKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1634. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1635. $isid = $XDeode->decode ( $iStoreKey );
  1636. $trainId = $XDeode->decode ( $trainKey );
  1637. if (! is_numeric ( $isid ))
  1638. die ( 'illegal request' );
  1639. Doo::loadModel ( 'invoiceStore' );
  1640. Doo::loadModel ( 'invoice' );
  1641. $invoice = new invoice ();
  1642. // 加入限制必须填写入开票内容和邮寄物品
  1643. $invoiceStore = new invoiceStore ();
  1644. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid, 'isid,trainId ,invoiceElement,mailItemsJson,electronicPhone,electronicEmail' );
  1645. if (empty ( $isDetail ['invoiceElement'] ) || empty ( $isDetail ['mailItemsJson'] )) {
  1646. header ( 'Content-Type:text/html;charset=utf-8' );
  1647. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1648. }
  1649. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1650. if (empty ( $isDetail ['electronicPhone'] ) && empty ( $isDetail ['electronicEmail'] )) {
  1651. header ( 'Content-Type:text/html;charset=utf-8' );
  1652. die ( 'illegal request! 请设置电子开票的收件人手机或者邮箱' );
  1653. }
  1654. }
  1655. // 拷贝插入一条发票数据
  1656. $invoiceStore = new invoiceStore ();
  1657. $iid = $invoiceStore->setInvoiceStoreToApproval ( $isid );
  1658. $invoiceStore = new invoiceStore ();
  1659. $item = array (
  1660. 'isid' => $isid,
  1661. 'iid' => $iid,
  1662. 'apStatus' => 1
  1663. );
  1664. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1665. Doo::loadModel ( 'invoiceManage' );
  1666. $invoiceManage = new invoiceManage ();
  1667. Doo::loadModel ( 'invoiceOperationLog' );
  1668. $invoiceOperationLog = new invoiceOperationLog ();
  1669. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1670. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1671. $moldManage = array ();
  1672. foreach ( $invoiceManageList as $key => $value ) {
  1673. if ($value ['mold'] == '发票打印')
  1674. $moldManage [$value ['mold']] = $value ['staffList'];
  1675. elseif ($value ['mold'] == '发票邮寄')
  1676. $moldManage [$value ['mold']] = $value ['staffList'];
  1677. elseif ($value ['mold'] == '发票退票')
  1678. $moldManage [$value ['mold']] = $value ['staffList'];
  1679. }
  1680. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1681. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1682. $invoiceSerial="#FE" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1683. }else{
  1684. $invoiceSerial="#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1685. }
  1686. $item = array (
  1687. 'iid' => $iid,
  1688. 'isid' => $isid,
  1689. 'invoiceSerial' => $invoiceSerial,
  1690. 'date' => date ( "Y-m-d H:i:s" ),
  1691. 'status' => 1,
  1692. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1693. 'trainId' => $trainId,
  1694. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1695. 'moldManage' => json_encode ( $moldManage ),
  1696. 'settlementType' => 1,
  1697. 'pendingApprovals' => $pendingApprovalsSid
  1698. );
  1699. $invoice->setInvoiceByCondition ( $item );
  1700. Doo::loadModel ( 'invoiceTraining' );
  1701. $invoiceTraining = new invoiceTraining ();
  1702. $item = array (
  1703. 'itid' => $trainId,
  1704. 'submitStatus' => 1
  1705. );
  1706. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1707. $item = array (
  1708. 'date' => date ( "Y-m-d H:i:s" ),
  1709. 'operation' => "创建",
  1710. 'status' => 1,
  1711. 'img' => $this->staff [0] ['avatar'],
  1712. 'username' => $this->staff [0] ['username'],
  1713. 'uid' => $this->staff [0] ['sid'],
  1714. 'category' => $this->staff [0] ['category'],
  1715. 'iid' => $iid
  1716. );
  1717. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1718. $item = array (
  1719. 'date' => date ( "Y-m-d H:i:s" ),
  1720. 'operation' => "提交审批",
  1721. 'status' => 1,
  1722. 'img' => $this->staff [0] ['avatar'],
  1723. 'username' => $this->staff [0] ['username'],
  1724. 'uid' => $this->staff [0] ['sid'],
  1725. 'category' => $this->staff [0] ['category'],
  1726. 'iid' => $iid
  1727. );
  1728. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1729. Doo::loadModel ( 'staff' );
  1730. $staff = new staff ();
  1731. $username2 = $staff->getOne ( array (
  1732. 'select' => 'wxid',
  1733. 'where' => 'sid=' . $pendingApprovalsSid,
  1734. 'asArray' => TRUE
  1735. ) );
  1736. // 发送微信审批通知
  1737. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1738. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1739. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1740. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1741. }else{
  1742. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1743. }
  1744. }
  1745. /**
  1746. * 批量提交发票
  1747. * @return string
  1748. */
  1749. function invoiceStoreBatchApproval() {
  1750. Doo::loadClass ( 'XDeode' );
  1751. $XDeode = new XDeode ( 5 );
  1752. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1753. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1754. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : '';
  1755. if (empty ( $trainKey ) || empty ( $storeKey ))
  1756. die ( 'illegal request-IdKey' );
  1757. $trainId = $XDeode->decode ( $trainKey );
  1758. $isidKeyList = explode ( ',', $storeKey );
  1759. $isidList = array ();
  1760. foreach ( $isidKeyList as $value ) {
  1761. $isid = $XDeode->decode ( $value );
  1762. if (! empty ( $isid ) && is_numeric ( $isid ))
  1763. array_push ( $isidList, $isid );
  1764. }
  1765. $isidString = implode ( ',', $isidList );
  1766. if (! is_numeric ( $trainId ))
  1767. die ( 'illegal request' );
  1768. Doo::loadModel ( 'invoiceStore' );
  1769. Doo::loadModel ( 'invoice' );
  1770. // 判断哪些已经加入审批过
  1771. // 加入限制必须填写入开票内容和邮寄物品
  1772. $invoiceStore = new invoiceStore ();
  1773. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,trainId ,invoiceElement,mailItemsJson,electronicPhone,electronicEmail,invoiceForm' );
  1774. foreach ( $isList as $key => $value ) {
  1775. if (empty ( $value ['invoiceElement'] ) || empty ( $value ['mailItemsJson'] )) {
  1776. header ( 'Content-Type:text/html;charset=utf-8' );
  1777. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1778. }
  1779. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic' ){
  1780. $value ['electronicPhone']=trim($value ['electronicPhone']);
  1781. $value ['electronicEmail']=trim($value ['electronicEmail']);
  1782. if(empty ( $value ['electronicPhone'] )&&empty ( $value ['electronicEmail'] )){
  1783. header ( 'Content-Type:text/html;charset=utf-8' );
  1784. die ( 'illegal request! 请设置电子开票的收件人手机或者邮箱' );
  1785. }
  1786. }
  1787. }
  1788. // 拷贝插入一条发票数据
  1789. $invoiceStore = new invoiceStore ();
  1790. $invoiceStore->setInvoiceStoreBatchToApproval ( $isidString );
  1791. $invoiceStore = new invoiceStore ();
  1792. $item = array (
  1793. 'apStatus' => 1
  1794. );
  1795. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1796. // 获得正式发票ID
  1797. $invoice = new invoice ();
  1798. $iidList = $invoice->getInvoiceByIstoreid ( $isidString, 'iid,isid' );
  1799. $sqlList = array ();
  1800. $iidString = '';
  1801. $iida = array ();
  1802. foreach ( $iidList as $key => $value ) {
  1803. $sqlList [$value ['isid']] = $value ['iid'];
  1804. array_push ( $iida, $value ['iid'] );
  1805. }
  1806. $iidString = implode ( ',', $iida );
  1807. $ids = implode ( ',', array_keys ( $sqlList ) );
  1808. $sql = "UPDATE CLD_invoiceStore SET iid = CASE isid ";
  1809. foreach ( $sqlList as $id => $ordinal ) {
  1810. $sql .= sprintf ( "WHEN %d THEN %d ", $id, $ordinal );
  1811. }
  1812. $sql .= "END WHERE isid IN ($ids)";
  1813. $invoiceStore = new invoiceStore ();
  1814. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1815. Doo::loadModel ( 'invoiceManage' );
  1816. $invoiceManage = new invoiceManage ();
  1817. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1818. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1819. $moldManage = array ();
  1820. foreach ( $invoiceManageList as $key => $value ) {
  1821. if ($value ['mold'] == '发票打印')
  1822. $moldManage [$value ['mold']] = $value ['staffList'];
  1823. elseif ($value ['mold'] == '发票邮寄')
  1824. $moldManage [$value ['mold']] = $value ['staffList'];
  1825. elseif ($value ['mold'] == '发票退票')
  1826. $moldManage [$value ['mold']] = $value ['staffList'];
  1827. }
  1828. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1829. // 批量更新发票信息
  1830. $item = array (
  1831. 'date' => date ( "Y-m-d H:i:s" ),
  1832. 'status' => 1,
  1833. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1834. 'trainId' => $trainId,
  1835. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1836. 'moldManage' => json_encode ( $moldManage ),
  1837. 'settlementType' => 1,
  1838. 'pendingApprovals' => $pendingApprovalsSid
  1839. );
  1840. $invoice = new invoice ();
  1841. $invoice->BatchInvoiceByCondition ( $item, $iidString );
  1842. // 批量更新发票中仓库isid
  1843. $sql = "UPDATE CLD_invoiceStore SET isid = CASE iid ";
  1844. foreach ( $sqlList as $isid => $iid ) {
  1845. $sql .= sprintf ( "WHEN %d THEN %d ", $iid, $isid );
  1846. }
  1847. $sql .= "END WHERE iid IN ($iidString)";
  1848. $invoice = new invoice ();
  1849. $invoice->UpdateBatchInvoice ( $sql );
  1850. // 批量更新发票序列号
  1851. $sqlList = array ();
  1852. foreach ( $iida as $value ) {
  1853. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1854. $sqlList [$value] = "#FE" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1855. }else{
  1856. $sqlList [$value] = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1857. }
  1858. }
  1859. $ids = implode ( ',', array_keys ( $sqlList ) );
  1860. $sql = "UPDATE CLD_invoice SET invoiceSerial = CASE iid ";
  1861. foreach ( $sqlList as $id => $ordinal ) {
  1862. $sql .= sprintf ( "WHEN %d THEN '%s' ", $id, $ordinal );
  1863. }
  1864. $sql .= "END WHERE iid IN ($ids)";
  1865. $invoiceStore = new invoiceStore ();
  1866. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1867. // 批量生产操作日志
  1868. Doo::loadModel ( 'invoiceOperationLog' );
  1869. $sqlList = array ();
  1870. foreach ( $iida as $key => $value ) {
  1871. $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 . '"),
  1872. ("' . 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 . '") ';
  1873. array_push ( $sqlList, $sql );
  1874. }
  1875. $iolSql = implode ( ',', $sqlList );
  1876. $sql = "INSERT INTO `CLD_invoiceOperationLog` (`date`, `operation`, `status`, `img`, `username`, `uid`, `category`, `iid`) VALUES " . $iolSql;
  1877. $invoiceOperationLog = new invoiceOperationLog ();
  1878. $invoiceOperationLog->setInvoiceOperationLogBySql ( $sql );
  1879. Doo::loadModel ( 'invoiceTraining' );
  1880. $invoiceTraining = new invoiceTraining ();
  1881. $item = array (
  1882. 'itid' => $trainId,
  1883. 'submitStatus' => 1
  1884. );
  1885. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1886. Doo::loadModel ( 'staff' );
  1887. $staff = new staff ();
  1888. $username2 = $staff->getOne ( array (
  1889. 'select' => 'wxid',
  1890. 'where' => 'sid=' . $pendingApprovalsSid,
  1891. 'asArray' => TRUE
  1892. ) );
  1893. // 发送微信审批通知
  1894. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1895. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1896. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1897. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1898. }else{
  1899. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1900. }
  1901. }
  1902. /**
  1903. */
  1904. function invoiceStoreMailItemSet() {
  1905. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1906. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1907. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1908. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1909. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1910. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1911. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1912. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1913. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1914. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1915. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1916. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1917. Doo::loadClass ( 'XDeode' );
  1918. $XDeode = new XDeode ( 5 );
  1919. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1920. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1921. $isid = $XDeode->decode ( $storeKey );
  1922. $trainId = $XDeode->decode ( $trainKey );
  1923. if (! is_numeric ( $isid ))
  1924. die ( 'illegal request' );
  1925. Doo::loadModel ( 'invoiceStore' );
  1926. $invoiceStore = new invoiceStore ();
  1927. $mailList = array (
  1928. 'mailItems' => $mailItems
  1929. );
  1930. $mailString = '发票x1,备注:' . $mailItems;
  1931. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1932. $mailString = '备注:' . $mailItems;
  1933. }else{
  1934. $mailList += array (
  1935. 'invoice' => 1,
  1936. );
  1937. }
  1938. if (! empty ( $softLock ))
  1939. $mailList += array (
  1940. 'softLock' => $softLockNum
  1941. );
  1942. else
  1943. $mailList += array (
  1944. 'softLock' => 0
  1945. );
  1946. if (! empty ( $contract ))
  1947. $mailList += array (
  1948. 'contract' => $contractNum
  1949. );
  1950. else
  1951. $mailList += array (
  1952. 'contract' => 0
  1953. );
  1954. if (! empty ( $instructions ))
  1955. $mailList += array (
  1956. 'instructions' => $instructionsNum
  1957. );
  1958. else
  1959. $mailList += array (
  1960. 'instructions' => 0
  1961. );
  1962. if (! empty ( $remittance ))
  1963. $mailList += array (
  1964. 'remittance' => $remittance
  1965. );
  1966. else
  1967. $mailList += array (
  1968. 'remittance' => ''
  1969. );
  1970. if (! empty ( $softLock ))
  1971. $mailString .= ',软件锁x' . $softLockNum;
  1972. if (! empty ( $contract ))
  1973. $mailString .= ',合同x' . $contractNum;
  1974. if (! empty ( $instructions ))
  1975. $mailString .= ',说明书x' . $instructionsNum;
  1976. if (! empty ( $remittance ))
  1977. $mailString .= ',汇款账号单';
  1978. $item = array (
  1979. 'isid' => $isid,
  1980. 'doPost' => 1,
  1981. 'mailItems' => $mailString,
  1982. 'mailItemsJson' => json_encode ( $mailList )
  1983. );
  1984. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1985. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1986. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1987. }else{
  1988. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1989. }
  1990. }
  1991. /**
  1992. * 批量设置邮寄物品
  1993. */
  1994. function invoiceStoreBatchMailItemSet() {
  1995. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1996. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1997. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1998. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1999. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  2000. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  2001. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  2002. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  2003. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  2004. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  2005. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  2006. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  2007. Doo::loadClass ( 'XDeode' );
  2008. $XDeode = new XDeode ( 5 );
  2009. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  2010. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  2011. if (empty ( $trainKey ) || empty ( $storeKey ))
  2012. die ( 'illegal request-IdKey' );
  2013. $isidKeyList = explode ( ',', $storeKey );
  2014. $isidList = array ();
  2015. foreach ( $isidKeyList as $value ) {
  2016. $isid = $XDeode->decode ( $value );
  2017. if (! empty ( $isid ) && is_numeric ( $isid ))
  2018. array_push ( $isidList, $isid );
  2019. }
  2020. $isidString = implode ( ',', $isidList );
  2021. $trainId = $XDeode->decode ( $trainKey );
  2022. if (! is_numeric ( $isid ))
  2023. die ( 'illegal request' );
  2024. Doo::loadModel ( 'invoiceStore' );
  2025. $invoiceStore = new invoiceStore ();
  2026. $mailList = array (
  2027. 'mailItems' => $mailItems
  2028. );
  2029. $mailString = '发票x1,备注:' . $mailItems;
  2030. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  2031. $mailString = '备注:' . $mailItems;
  2032. }else{
  2033. $mailList += array (
  2034. 'invoice' => 1,
  2035. );
  2036. }
  2037. if (! empty ( $softLock ))
  2038. $mailList += array (
  2039. 'softLock' => $softLockNum
  2040. );
  2041. else
  2042. $mailList += array (
  2043. 'softLock' => 0
  2044. );
  2045. if (! empty ( $contract ))
  2046. $mailList += array (
  2047. 'contract' => $contractNum
  2048. );
  2049. else
  2050. $mailList += array (
  2051. 'contract' => 0
  2052. );
  2053. if (! empty ( $instructions ))
  2054. $mailList += array (
  2055. 'instructions' => $instructionsNum
  2056. );
  2057. else
  2058. $mailList += array (
  2059. 'instructions' => 0
  2060. );
  2061. if (! empty ( $remittance ))
  2062. $mailList += array (
  2063. 'remittance' => $remittance
  2064. );
  2065. else
  2066. $mailList += array (
  2067. 'remittance' => ''
  2068. );
  2069. if (! empty ( $softLock ))
  2070. $mailString .= ',软件锁x' . $softLockNum;
  2071. if (! empty ( $contract ))
  2072. $mailString .= ',合同x' . $contractNum;
  2073. if (! empty ( $instructions ))
  2074. $mailString .= ',说明书x' . $instructionsNum;
  2075. if (! empty ( $remittance ))
  2076. $mailString .= ',汇款账号单';
  2077. $item = array (
  2078. 'doPost' => 1,
  2079. 'mailItems' => $mailString,
  2080. 'mailItemsJson' => json_encode ( $mailList )
  2081. );
  2082. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  2083. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  2084. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  2085. }else{
  2086. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  2087. }
  2088. }
  2089. /**
  2090. * 废弃
  2091. */
  2092. function ajaxGetMailItemByIstore() {
  2093. Doo::loadClass ( 'XDeode' );
  2094. $XDeode = new XDeode ( 5 );
  2095. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  2096. $isid = $XDeode->decode ( $storeKey );
  2097. if (! is_numeric ( $isid ))
  2098. die ( 'illegal request' );
  2099. Doo::loadModel ( 'invoiceStore' );
  2100. $invoiceStore = new invoiceStore ();
  2101. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid );
  2102. $isDetail ['mailItemsJson'] = json_decode ( $isDetail ['mailItemsJson'], true );
  2103. echo json_encode ( $isDetail ['mailItemsJson'] );
  2104. exit ();
  2105. }
  2106. /**
  2107. * 终止开票
  2108. */
  2109. function invoiceDroppedDo() {
  2110. $droppedIidKey = $this->get_args ( 'droppedIidKey' ) ? $this->get_args ( 'droppedIidKey' ) : '';
  2111. Doo::loadModel ( 'invoice' );
  2112. $invoice = new invoice ();
  2113. Doo::loadModel ( 'invoiceOperationLog' );
  2114. $invoiceOperationLog = new invoiceOperationLog ();
  2115. $iid = $invoice->authcode ( $droppedIidKey );
  2116. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2117. die ( 'illegal request' );
  2118. $item = array (
  2119. 'iid' => $iid,
  2120. 'status' => 4,
  2121. 'updateTime' => date ( "Y-m-d H:i:s" )
  2122. );
  2123. $invoice->setInvoiceByCondition ( $item );
  2124. $item = array (
  2125. 'date' => date ( "Y-m-d H:i:s" ),
  2126. 'operation' => '终止了开票',
  2127. 'status' => 4,
  2128. 'img' => $this->staff [0] ['avatar'],
  2129. 'username' => $this->staff [0] ['username'],
  2130. 'uid' => $this->staff [0] ['sid'],
  2131. 'category' => $this->staff [0] ['category'],
  2132. 'iid' => $iid
  2133. );
  2134. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2135. return "/invoice";
  2136. }
  2137. /**
  2138. * 更新退票的邮寄信息
  2139. */
  2140. function invoiceUntreadMailDo() {
  2141. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  2142. $untreadCompany = $this->get_args ( 'untreadCompany' ) ? $this->get_args ( 'untreadCompany' ) : "";
  2143. $untreadNumber = $this->get_args ( 'untreadNumber' ) ? $this->get_args ( 'untreadNumber' ) : "";
  2144. $untreadItems = $this->get_args ( 'untreadItems' ) ? $this->get_args ( 'untreadItems' ) : "";
  2145. Doo::loadModel ( 'invoice' );
  2146. $invoice = new invoice ();
  2147. $iid = $invoice->authcode ( $untreadIidKey );
  2148. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2149. die ( 'illegal request' );
  2150. $item = array (
  2151. 'iid' => $iid,
  2152. 'untreadCompany' => $untreadCompany,
  2153. 'untreadNumber' => $untreadNumber,
  2154. 'untreadItems' => $untreadItems
  2155. );
  2156. $invoice->setInvoiceByCondition ( $item );
  2157. return "/invoice";
  2158. }
  2159. /**
  2160. * 申请退票 --
  2161. */
  2162. function invoiceUntreadDo() {
  2163. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  2164. $untreadReason = $this->get_args ( 'untreadReason' ) ? $this->get_args ( 'untreadReason' ) : "";
  2165. $untreadPost = $this->get_args ( 'untreadPost' ) ? $this->get_args ( 'untreadPost' ) : 0;
  2166. Doo::loadModel ( 'invoice' );
  2167. $invoice = new invoice ();
  2168. Doo::loadModel ( 'invoiceOperationLog' );
  2169. $invoiceOperationLog = new invoiceOperationLog ();
  2170. Doo::loadModel ( 'invoiceReceivables' );
  2171. $invoiceReceivables = new invoiceReceivables ();
  2172. $iid = $invoice->authcode ( $untreadIidKey );
  2173. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2174. die ( 'illegal request' );
  2175. /*
  2176. * 需求变革 有绑定收款也可以退票 $lt = $invoiceReceivables->getInvoiceReceivablesByIid ( $untreadIidKey ); if (! empty ( $lt )) { header ( 'Content-Type:text/html;charset=utf-8' ); die ( '该发票有收款绑定,请先移除!' ); }
  2177. */
  2178. $item = array (
  2179. 'iid' => $iid,
  2180. 'untreadStatus' => 1,
  2181. 'untreadReason' => $untreadReason,
  2182. 'untreadPost' => $untreadPost,
  2183. 'updateTime' => date ( "Y-m-d H:i:s" )
  2184. );
  2185. $invoice->setInvoiceByCondition ( $item );
  2186. $item = array (
  2187. 'date' => date ( "Y-m-d H:i:s" ),
  2188. 'operation' => '申请退票',
  2189. 'status' => 7,
  2190. 'img' => $this->staff [0] ['avatar'],
  2191. 'username' => $this->staff [0] ['username'],
  2192. 'uid' => $this->staff [0] ['sid'],
  2193. 'category' => $this->staff [0] ['category'],
  2194. 'iid' => $iid
  2195. );
  2196. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2197. return "/invoice";
  2198. }
  2199. /**
  2200. * 删除已终止的开票
  2201. */
  2202. function invoiceDelDo() {
  2203. Doo::loadModel ( 'invoice' );
  2204. $invoice = new invoice ();
  2205. Doo::loadModel ( 'invoiceOperationLog' );
  2206. $invoiceOperationLog = new invoiceOperationLog ();
  2207. Doo::loadClass ( 'XDeode' );
  2208. $XDeode = new XDeode ( 5 );
  2209. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  2210. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  2211. $iid = $XDeode->decode ( $iid );
  2212. Doo::loadModel ( 'invoiceStore' );
  2213. $invoiceStore = new invoiceStore ();
  2214. if (! is_numeric ( $iid ))
  2215. die ( 'illegal request' );
  2216. $invoiceDetail = $invoice->getMyInvoice ( $sid, $iid );
  2217. if (empty ( $invoiceDetail ))
  2218. die ( 'illegal request' );
  2219. $item = array (
  2220. 'iid' => $iid,
  2221. 'isDelete' => 1,
  2222. 'updateTime' => date ( "Y-m-d H:i:s" )
  2223. );
  2224. $invoice->setInvoiceByCondition ( $item );
  2225. $item = array (
  2226. 'date' => date ( "Y-m-d H:i:s" ),
  2227. 'operation' => '删除了已终止的发票',
  2228. 'status' => 4,
  2229. 'img' => $this->staff [0] ['avatar'],
  2230. 'username' => $this->staff [0] ['username'],
  2231. 'uid' => $this->staff [0] ['sid'],
  2232. 'category' => $this->staff [0] ['category'],
  2233. 'iid' => $iid
  2234. );
  2235. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2236. // 删除培训班发票仓库里的发票
  2237. $invoiceStore->delInvoiceStoreByIsid ( $invoiceDetail ['isid'] );
  2238. return "/invoice";
  2239. }
  2240. /**
  2241. */
  2242. function invoiceApproval() {
  2243. Doo::loadModel ( 'invoice' );
  2244. $invoice = new invoice ();
  2245. Doo::loadClass ( 'XDeode' );
  2246. $XDeode = new XDeode ( 5 );
  2247. Doo::loadModel ( 'staff' );
  2248. $staff = new staff ();
  2249. $invoiceList = $invoice->find ( array (
  2250. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  2251. 'desc' => 'iid',
  2252. 'limit' => 10,
  2253. 'asArray' => true
  2254. ) );
  2255. foreach ( $invoiceList as $key => $value ) {
  2256. $invoiceList [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2257. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2258. if (! empty ( $lastApprover )) {
  2259. $lastApproverKey = array_keys ( $lastApprover );
  2260. $lastApprover = end ( $lastApprover );
  2261. $staffDetail = $staff->getOne ( array (
  2262. 'where' => 'sid=' . end ( $lastApproverKey ),
  2263. 'asArray' => true
  2264. ) );
  2265. $lastApprover ['username'] = $staffDetail ['username'];
  2266. }
  2267. $invoiceList [$key] ['lastApprover'] = $lastApprover;
  2268. }
  2269. $ilist = $invoice->getInvoiceByProcessStatus ();
  2270. foreach ( $ilist as $key => $value ) {
  2271. $ilist [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2272. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2273. if (! empty ( $lastApprover )) {
  2274. $lastApproverKey = array_keys ( $lastApprover );
  2275. $lastApprover = end ( $lastApprover );
  2276. $staffDetail = $staff->getOne ( array (
  2277. 'where' => 'sid=' . end ( $lastApproverKey ),
  2278. 'asArray' => true
  2279. ) );
  2280. $lastApprover ['username'] = $staffDetail ['username'];
  2281. }
  2282. $ilist [$key] ['lastApprover'] = $lastApprover;
  2283. }
  2284. // print_r($ilist);
  2285. $this->data ['invoiceList'] = $invoiceList;
  2286. $this->data ['ilist'] = $ilist;
  2287. $this->data ['memu'] = "invoice";
  2288. $this->data ['staff'] = $this->staff;
  2289. $this->data ['receiptMemu'] = 'invoiceApproval';
  2290. $this->render ( "/admin/invoiceApproval", $this->data );
  2291. }
  2292. function invoiceDetail() {
  2293. Doo::loadClass ( 'XDeode' );
  2294. $XDeode = new XDeode ( 5 );
  2295. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  2296. $iid = $XDeode->decode ( $iid );
  2297. if (! is_numeric ( $iid ))
  2298. die ( 'illegal request' );
  2299. Doo::loadModel ( 'invoice' );
  2300. $invoice = new invoice ();
  2301. Doo::loadModel ( 'invoiceOperationLog' );
  2302. $invoiceOperationLog = new invoiceOperationLog ();
  2303. $invoiceDetail = $invoice->getOne ( array (
  2304. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'] . ' and iid=' . $iid,
  2305. 'asArray' => true
  2306. ) );
  2307. if (empty ( $invoiceDetail ))
  2308. die ( 'illegal request' );
  2309. if ($invoiceDetail ['settlementType'] == 1) {
  2310. Doo::loadModel ( 'invoiceTraining' );
  2311. $invoiceTraining = new invoiceTraining ();
  2312. $invoiceDetail ['invoiceTraining'] = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceDetail ['trainId'] );
  2313. }
  2314. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  2315. $this->data ['invoiceDetail'] = $invoiceDetail;
  2316. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  2317. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  2318. $this->data ['memu'] = "invoice";
  2319. $this->data ['staff'] = $this->staff;
  2320. $this->data ['receiptMemu'] = 'invoiceApproval';
  2321. $this->render ( "/admin/invoiceApprovalDetail", $this->data );
  2322. }
  2323. /**
  2324. * 对发票进行审批,其中操作有终止,退回,同意动作。操作成功并记录下操作日志
  2325. *
  2326. * @since 1.0.0
  2327. * @var integer iid 开票ID 已加密
  2328. * @var integer status 发票审批状态
  2329. * @var integer opintion 审批发票的意见
  2330. * @return string 如操作成功返回审批首页
  2331. */
  2332. function invoiceApprovalDo() {
  2333. Doo::loadModel ( 'invoice' );
  2334. $invoice = new invoice ();
  2335. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2336. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  2337. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  2338. $divApproval = $this->get_args ( 'divApproval' ) ? $this->get_args ( 'divApproval' ) : "";
  2339. $iid = $invoice->authcode ( $iid );
  2340. if (! is_numeric ( $iid ))
  2341. die ( 'illegal request' );
  2342. // && ! empty ( $opinion )
  2343. if (! empty ( $iid ) && ! empty ( $status )) {
  2344. if (! ($status == 2 || $status == 3 || $status == 4))
  2345. die ( 'illegal request' );
  2346. Doo::loadModel ( 'invoiceOperationLog' );
  2347. $invoiceOperationLog = new invoiceOperationLog ();
  2348. $invoiceDetail = $invoice->getOne ( array (
  2349. 'where' => 'status=1 and iid=' . $iid . ' and pendingApprovals=' . $this->staff [0] ['sid'],
  2350. 'asArray' => true
  2351. ) );
  2352. if (empty ( $invoiceDetail ))
  2353. die ( 'illegal request' );
  2354. $processApprovals = json_decode ( $invoiceDetail ['processApprovals'], true );
  2355. $invoiceManage = json_decode ( $invoiceDetail ['invoiceManage'], true );
  2356. if ($status == 3) {
  2357. $invoice->status = $status;
  2358. $item = array (
  2359. 'operation' => $opinion
  2360. );
  2361. } else {
  2362. if (empty ( $processApprovals )) {
  2363. $processApprovals = array (
  2364. $this->staff [0] ['sid'] => array (
  2365. 'date' => date ( "Y-m-d H:i:s" ),
  2366. 'opinion' => $opinion,
  2367. 'status' => $status
  2368. )
  2369. );
  2370. // var_dump(next($invoiceManage));
  2371. $nextInvoiceManage = next ( $invoiceManage );
  2372. // print_r($nextInvoiceManage);
  2373. if ($status != 4 && $nextInvoiceManage !== false)
  2374. $invoice->pendingApprovals = $nextInvoiceManage [0];
  2375. $invoice->processApprovals = json_encode ( $processApprovals );
  2376. // var_dump($invoice);
  2377. // print_r($invoiceManage);
  2378. } else {
  2379. $processApprovals [$this->staff [0] ['sid']] = array (
  2380. 'date' => date ( "Y-m-d H:i:s" ),
  2381. 'opinion' => $opinion,
  2382. 'status' => $status
  2383. );
  2384. $pendingApprovals = 0;
  2385. foreach ( $invoiceManage as $key => $value ) {
  2386. if ($value [0] == $this->staff [0] ['sid']) {
  2387. if (isset ( $invoiceManage [$key + 1] ))
  2388. $pendingApprovals = $invoiceManage [$key + 1] [0];
  2389. break;
  2390. }
  2391. }
  2392. if ($status != 4 && ! empty ( $pendingApprovals ))
  2393. $invoice->pendingApprovals = $pendingApprovals;
  2394. $invoice->processApprovals = json_encode ( $processApprovals );
  2395. }
  2396. $item = array (
  2397. 'operation' => $opinion
  2398. );
  2399. if (count ( $processApprovals ) == count ( $invoiceManage ) && $status != 4) {
  2400. $invoice->status = $status;
  2401. $invoice->pendingApprovals = 0;
  2402. $invoice->approvalTime = date ( "Y-m-d H:i:s" );
  2403. } elseif ($status == 4) {
  2404. $invoice->status = $status;
  2405. $item = array (
  2406. 'operation' => $opinion
  2407. );
  2408. }
  2409. }
  2410. $invoice->updateTime = date ( "Y-m-d H:i:s" );
  2411. $invoice->update ( array (
  2412. 'where' => 'iid=' . $iid
  2413. ) );
  2414. $item += array (
  2415. 'date' => date ( "Y-m-d H:i:s" ),
  2416. 'img' => $this->staff [0] ['avatar'],
  2417. 'username' => $this->staff [0] ['username'],
  2418. 'uid' => $this->staff [0] ['sid'],
  2419. 'category' => $this->staff [0] ['category'],
  2420. 'status' => $status,
  2421. 'iid' => $iid
  2422. );
  2423. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2424. if (empty ( $divApproval ))
  2425. return '/invoiceApproval';
  2426. else
  2427. return '/invoiceApprovalAchieve/PEND';
  2428. }
  2429. die ( 'illegal request' );
  2430. }
  2431. /**
  2432. * 展示需要打印的发票数据
  2433. *
  2434. * @since 1.0.0
  2435. */
  2436. function invoicePrint() {
  2437. Doo::loadModel ( 'invoice' );
  2438. $invoice = new invoice ();
  2439. Doo::loadClass ( 'XDeode' );
  2440. $XDeode = new XDeode ( 5 );
  2441. Doo::loadModel ( 'staff' );
  2442. $staff = new staff ();
  2443. $toPrint = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0 );
  2444. $printed = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 1 );
  2445. foreach ( $toPrint as $key => $value ) {
  2446. $toPrint [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2447. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2448. if (! empty ( $lastApprover )) {
  2449. $lastApproverKey = array_keys ( $lastApprover );
  2450. $lastApprover = end ( $lastApprover );
  2451. $staffDetail = $staff->getOne ( array (
  2452. 'where' => 'sid=' . end ( $lastApproverKey ),
  2453. 'asArray' => true
  2454. ) );
  2455. $lastApprover ['username'] = $staffDetail ['username'];
  2456. }
  2457. $toPrint [$key] ['lastApprover'] = $lastApprover;
  2458. }
  2459. foreach ( $printed as $key => $value ) {
  2460. $printed [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2461. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2462. if (! empty ( $lastApprover )) {
  2463. $lastApproverKey = array_keys ( $lastApprover );
  2464. $lastApprover = end ( $lastApprover );
  2465. $staffDetail = $staff->getOne ( array (
  2466. 'where' => 'sid=' . end ( $lastApproverKey ),
  2467. 'asArray' => true
  2468. ) );
  2469. $lastApprover ['username'] = $staffDetail ['username'];
  2470. }
  2471. $printed [$key] ['lastApprover'] = $lastApprover;
  2472. }
  2473. $this->data ['printed'] = $printed;
  2474. $this->data ['toPrint'] = $toPrint;
  2475. $this->data ['memu'] = "invoice";
  2476. $this->data ['staff'] = $this->staff;
  2477. $this->data ['receiptMemu'] = 'invoicePrint';
  2478. $this->render ( "/admin/invoicePrint", $this->data );
  2479. }
  2480. /**
  2481. * 展示发票打印的详情页面
  2482. *
  2483. * @since 1.0.0
  2484. */
  2485. function invoicePrintDetail() {
  2486. Doo::loadClass ( 'XDeode' );
  2487. $XDeode = new XDeode ( 5 );
  2488. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  2489. $iid = $XDeode->decode ( $iid );
  2490. if (! is_numeric ( $iid ))
  2491. die ( 'illegal request' );
  2492. Doo::loadModel ( 'invoice' );
  2493. $invoice = new invoice ();
  2494. Doo::loadModel ( 'invoiceOperationLog' );
  2495. $invoiceOperationLog = new invoiceOperationLog ();
  2496. Doo::loadModel ( 'invoicePaper' );
  2497. $invoicePaper = new invoicePaper ();
  2498. $invoiceDetail = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0, $iid );
  2499. if (empty ( $invoiceDetail ))
  2500. die ( 'illegal request' );
  2501. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $invoiceDetail ['invoiceType'],$invoiceDetail['invoiceForm'] );
  2502. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  2503. if ($invoiceDetail ['settlementType'] == 1) {
  2504. Doo::loadModel ( 'invoiceTraining' );
  2505. $invoiceTraining = new invoiceTraining ();
  2506. $invoiceDetail ['invoiceTraining'] = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceDetail ['trainId'] );
  2507. }
  2508. $this->data ['invoicePaperList'] = $invoicePaperList;
  2509. $this->data ['invoiceDetail'] = $invoiceDetail;
  2510. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  2511. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  2512. $this->data ['memu'] = "invoice";
  2513. $this->data ['staff'] = $this->staff;
  2514. $this->data ['receiptMemu'] = 'invoicePrint';
  2515. $this->render ( "/admin/invoicePrintDetail", $this->data );
  2516. }
  2517. /**
  2518. * 所有待打印 发票
  2519. */
  2520. function invoicePrintStayAchieve() {
  2521. Doo::loadModel ( 'invoice' );
  2522. $invoice = new invoice ();
  2523. Doo::loadClass ( 'XDeode' );
  2524. $XDeode = new XDeode ( 5 );
  2525. Doo::loadModel ( 'staff' );
  2526. $staff = new staff ();
  2527. $MebSea = $this->get_args ( 'MebSea' ) ? urldecode ( $this->get_args ( 'MebSea' ) ) : "";
  2528. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  2529. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  2530. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  2531. Doo::loadModel ( 'invoiceTraining' );
  2532. $invoiceTraining = new invoiceTraining ();
  2533. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  2534. $page_size = 12;
  2535. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2536. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : "ALL";
  2537. // $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : "ALL";
  2538. $get = "/" . $status;
  2539. $con = ' and status=2 ';
  2540. if ($status == 'TOPRINT')
  2541. $con = ' and status=2 and printStatus=0 ';
  2542. elseif ($status == 'PRINTED')
  2543. $con = ' and status=2 and printStatus=1';
  2544. if ($invoiceType == 'ORDINARY')
  2545. $con .= ' and invoiceType=0 ';
  2546. elseif ($invoiceType == 'SPECIAL')
  2547. $con .= ' and invoiceType=1 ';
  2548. if ($invoiceTrain == 'ORDINARY')
  2549. $con .= ' and trainId=0 ';
  2550. elseif ($invoiceTrain == 'TRAIN')
  2551. $con .= ' and trainId!=0 ';
  2552. if ($invoiceTrainName != 'ALL') {
  2553. $trainId = $XDeode->decode ( $invoiceTrainName );
  2554. if (is_numeric ( $trainId ))
  2555. $con .= ' and trainId =' . $trainId;
  2556. }
  2557. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2558. $dateArr = explode ( ':', $date );
  2559. $D1 = '';
  2560. $D2 = '';
  2561. if (! empty ( $date )) {
  2562. $D1 = $dateArr [0];
  2563. $D2 = $dateArr [1];
  2564. }
  2565. if (! empty ( $D1 ) && ! empty ( $D2 ) && ! empty ( $date ))
  2566. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2567. if (! empty ( $MebSea )) {
  2568. $con .= ' and ( invoiceNo like "%' . $MebSea . '%" or invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  2569. }
  2570. $pageinfo ['page'] = array (
  2571. 'previous' => ''
  2572. );
  2573. $get .= "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&invoiceType=" . urlencode ( $invoiceType ) . "&invoiceTrain=" . urlencode ( $invoiceTrain ) . "";
  2574. $sql = " (untreadStatus=0 or untreadStatus=3 or untreadStatus=4) and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  2575. $action = "invoicePrintStayAchieve";
  2576. //echo $sql;
  2577. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2578. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2579. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  2580. $this->data ['trainList'] = $trainList;
  2581. $this->data ['invoiceType'] = $invoiceType;
  2582. $this->data ['invoiceTrain'] = $invoiceTrain;
  2583. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  2584. $this->data ['MebSeaEn'] = $MebSea;
  2585. $this->data ['MebSea'] = urlencode ( $MebSea );
  2586. $this->data ['get'] = $get;
  2587. $this->data ['page'] = $pageinfo;
  2588. $this->data ['date'] = $date;
  2589. $this->data ['status'] = $status;
  2590. $this->data ['invoiceType'] = $invoiceType;
  2591. $this->data ['memu'] = "invoice";
  2592. $this->data ['staff'] = $this->staff;
  2593. foreach ( $list as $key => $value ) {
  2594. $list [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2595. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2596. if (! empty ( $lastApprover )) {
  2597. $lastApproverKey = array_keys ( $lastApprover );
  2598. $lastApprover = end ( $lastApprover );
  2599. $staffDetail = $staff->getOne ( array (
  2600. 'where' => 'sid=' . end ( $lastApproverKey ),
  2601. 'asArray' => true
  2602. ) );
  2603. $lastApprover ['username'] = $staffDetail ['username'];
  2604. }
  2605. $list [$key] ['lastApprover'] = $lastApprover;
  2606. }
  2607. $this->data ['receiptMemu'] = 'invoicePrint';
  2608. $this->data ['list'] = $list;
  2609. $this->render ( "/admin/invoicePrintStayAchieve", $this->data );
  2610. }
  2611. /**
  2612. * 填写票号并完成打印
  2613. * @since 1.0.0
  2614. */
  2615. function invoicePrintDo() {
  2616. Doo::loadModel ( 'invoice' );
  2617. $invoice = new invoice ();
  2618. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2619. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  2620. $invoicePrintType = $this->get_args ( 'invoicePrintType' ) ? $this->get_args ( 'invoicePrintType' ) : "";
  2621. $iid = $invoice->authcode ( $iid );
  2622. if (! is_numeric ( $iid ))
  2623. die ( 'illegal request-iid' );
  2624. if (! empty ( $iid ) && ! empty ( $invoiceNo )) {
  2625. Doo::loadModel ( 'invoiceOperationLog' );
  2626. $invoiceOperationLog = new invoiceOperationLog ();
  2627. Doo::loadModel ( 'invoiceStatistics' );
  2628. $invoiceStatistics = new invoiceStatistics ();
  2629. $XDeode = new XDeode ( 5 );
  2630. Doo::loadModel ( 'invoicePaper' );
  2631. $invoicePaper = new invoicePaper ();
  2632. $invoicePrintDetail = $invoice->getInvoiceByPrint ( $iid );
  2633. if (empty ( $invoicePrintDetail ))
  2634. die ( 'illegal request-data_empty' );
  2635. //
  2636. $ipid = $XDeode->decode ( $invoiceNo );
  2637. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  2638. if (empty ( $paperDetail ))
  2639. die ( 'illegal request-paper_empty' );
  2640. $invoicePaper = new invoicePaper ();
  2641. $item = array (
  2642. 'iid' => $iid,
  2643. 'ipid' => $ipid
  2644. );
  2645. $invoicePaper->setInvoicePaperByCondition ( $item );
  2646. $item = array (
  2647. 'iid' => $iid,
  2648. 'printStatus' => 1,
  2649. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2650. 'printer' => $this->staff [0] ['username'],
  2651. 'printTime' => date ( "Y-m-d H:i:s" ),
  2652. 'invoiceNo' => $paperDetail ['invoiceNo']
  2653. );
  2654. $invoice->setInvoiceByCondition ( $item );
  2655. $item = array (
  2656. 'date' => date ( "Y-m-d H:i:s" ),
  2657. 'operation' => '打印发票号:' . $paperDetail ['invoiceNo'],
  2658. 'status' => 5,
  2659. 'img' => $this->staff [0] ['avatar'],
  2660. 'username' => $this->staff [0] ['username'],
  2661. 'uid' => $this->staff [0] ['sid'],
  2662. 'category' => $this->staff [0] ['category'],
  2663. 'iid' => $iid
  2664. );
  2665. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2666. // 去统计--负票不汇总
  2667. if ($invoicePrintDetail ['untreadStatus'] != 4) {
  2668. $item = array (
  2669. 'date' => date ( "Y-m-d H:i:s" ),
  2670. 'priceClass' => 1,
  2671. 'cid' => $invoicePrintDetail ['cid'],
  2672. 'staff' => $invoicePrintDetail ['sid'],
  2673. 'invoicePrice' => $invoicePrintDetail ['invoicePrice']
  2674. );
  2675. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2676. }
  2677. // 发送通知信息到微信-去除
  2678. // $this->setWXMsg($iid,'PRINT');
  2679. // 发票信息库
  2680. $this->autoUpdateInvoiceInfoBase ( $invoicePrintDetail );
  2681. // 申请人获取微信通知
  2682. Doo::loadModel ( 'staff' );
  2683. $staff = new staff ();
  2684. Doo::loadClass ( 'XDeode' );
  2685. $XDeode = new XDeode ( 5 );
  2686. $username2 = $staff->getOne ( array (
  2687. 'select' => 'wxid',
  2688. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2689. 'asArray' => TRUE
  2690. ) );
  2691. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '完成打印';
  2692. $msg = '';
  2693. $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/' . $XDeode->encode ( $invoicePrintDetail ['iid'] ) . '.html';
  2694. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2695. if (empty ( $invoicePrintType ))
  2696. return "/invoicePrint";
  2697. else
  2698. return "/invoicePrintStayAchieve";
  2699. }
  2700. }
  2701. /**
  2702. * 需要邮寄的发票
  2703. * @since 1.0.0
  2704. */
  2705. function invoicePost() {
  2706. Doo::loadModel ( 'invoice' );
  2707. $invoice = new invoice ();
  2708. Doo::loadModel ( 'express' );
  2709. $express = new express ();
  2710. $invoicePost = $invoice->getPostByInvoice ();
  2711. $invoicePosted = $invoice->getPostByInvoice ( 1 );
  2712. $expressList = $express->getExpressByAll ();
  2713. $invoicePostExpress = "";
  2714. if (isset ( $_COOKIE ["invoicePostExpress"] ))
  2715. $invoicePostExpress = $_COOKIE ["invoicePostExpress"];
  2716. $this->data ['invoicePostExpress'] = $invoicePostExpress;
  2717. $this->data ['expressList'] = $expressList;
  2718. $this->data ['invoicePost'] = $invoicePost;
  2719. $this->data ['invoicePosted'] = $invoicePosted;
  2720. $this->data ['memu'] = "invoice";
  2721. $this->data ['staff'] = $this->staff;
  2722. $this->data ['receiptMemu'] = 'invoicePost';
  2723. $this->render ( "/admin/invoicePost", $this->data );
  2724. }
  2725. /**
  2726. * 添加发票邮寄信息
  2727. */
  2728. function invoiceExpressAddDo() {
  2729. Doo::loadModel ( 'invoice' );
  2730. $invoice = new invoice ();
  2731. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2732. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2733. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2734. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2735. $iid = $iid = $invoice->authcode ( $iid );
  2736. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2737. die ( 'illegal request' );
  2738. $invoicePrintDetail = $invoice->getInvoiceByIid ( $iid );
  2739. setcookie ( 'invoicePostExpress', $expressNumber );
  2740. $item = array (
  2741. 'iid' => $iid,
  2742. 'postStatus' => 1,
  2743. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2744. 'postTime' => date ( "Y-m-d H:i:s" ),
  2745. 'expressCompany' => $expressCompany,
  2746. 'expressNumber' => $expressNumber,
  2747. 'actualItems' => $actualItems,
  2748. 'poster' => $this->staff [0] ['username']
  2749. );
  2750. $invoice->setInvoiceByCondition ( $item );
  2751. // 微信通知-去掉
  2752. // $this->setWXMsg ( $iid );
  2753. Doo::loadModel ( 'staff' );
  2754. $staff = new staff ();
  2755. Doo::loadClass ( 'XDeode' );
  2756. $XDeode = new XDeode ( 5 );
  2757. $username2 = $staff->getOne ( array (
  2758. 'select' => 'wxid',
  2759. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2760. 'asArray' => TRUE
  2761. ) );
  2762. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '已邮寄';
  2763. $expCom = explode ( ":", $invoicePrintDetail ['expressCompany'] );
  2764. if (empty ( $expCom ))
  2765. $expCom [0] = '';
  2766. $msg = $expCom [0] . ':' . $invoicePrintDetail ['expressNumber'] . '';
  2767. $url = 'https://m.kuaidi100.com/result.jsp?nu=' . $invoicePrintDetail ['expressNumber'];
  2768. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2769. return '/invoicePost';
  2770. }
  2771. function invoiceExpressUpdateDo() {
  2772. Doo::loadModel ( 'invoice' );
  2773. $invoice = new invoice ();
  2774. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  2775. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2776. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2777. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2778. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2779. $iid = $invoice->authcode ( $iid );
  2780. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2781. die ( 'illegal request' );
  2782. $item = array (
  2783. 'iid' => $iid,
  2784. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2785. 'expressCompany' => $expressCompany,
  2786. 'expressNumber' => $expressNumber,
  2787. 'actualItems' => $actualItems,
  2788. 'poster' => $this->staff [0] ['username']
  2789. );
  2790. $invoice->setInvoiceByCondition ( $item );
  2791. return $action;
  2792. }
  2793. /**
  2794. * 可退票管理
  2795. */
  2796. function invoiceUntreadIsAchieve() {
  2797. Doo::loadModel ( 'invoice' );
  2798. $invoice = new invoice ();
  2799. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2800. /*
  2801. * 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' => '' );
  2802. */
  2803. if (empty ( $MebSea )) {//
  2804. $con = ' and invoiceNo like "NULL" ';
  2805. } else {
  2806. $con = ' and (invoiceNo like "%' . $MebSea . '%" or invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  2807. }
  2808. // printStatus=1 and
  2809. $sql = " (untreadStatus=0 or untreadStatus=3) and status=2 and sid=" . $this->staff [0] ['sid'] . $con;
  2810. /*
  2811. * $action = "invoiceUntreadIsAchieve"; $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" ); $limit = $pageinfo ['lower'] . ',' . $page_size;
  2812. */
  2813. $limit = '0,50';
  2814. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2815. //print_r($list);
  2816. $this->data ['MebSeaEn'] = $MebSea;
  2817. /*
  2818. * $this->data ['get'] = $get; $this->data ['page'] = $pageinfo; $this->data ['date'] = $date;
  2819. */
  2820. $this->data ['list'] = $list;
  2821. $this->data ['memu'] = "invoice";
  2822. $this->data ['staff'] = $this->staff;
  2823. $this->data ['receiptMemu'] = 'invoice';
  2824. $this->render ( "/admin/invoiceUntreadIsAchieve", $this->data );
  2825. }
  2826. // 已经退票的发票
  2827. function invoiceUntreadED() {
  2828. Doo::loadModel ( 'invoice' );
  2829. $invoice = new invoice ();
  2830. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2831. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "";
  2832. Doo::loadClass ( 'XDeode' );
  2833. $XDeode = new XDeode ( 5 );
  2834. $page_size = 18;
  2835. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2836. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2837. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  2838. $dateArr = explode ( ':', $date );
  2839. $D1 = '';
  2840. $D2 = '';
  2841. if (! empty ( $date )) {
  2842. $D1 = $dateArr [0];
  2843. $D2 = $dateArr [1];
  2844. }
  2845. $con = '';
  2846. if (! empty ( $D1 ) && ! empty ( $D2 )) {
  2847. $con = ' and bindTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2848. }
  2849. // if ($date == 'MONTHO')
  2850. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  2851. // elseif ($date == 'MONTHT')
  2852. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  2853. // elseif ($date == 'MONTHY')
  2854. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  2855. if (! empty ( $MebSea )) {
  2856. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  2857. }
  2858. if ($invoiceType == 'ORDINARY') {
  2859. $con .= ' and invoiceType=0 ';
  2860. } elseif ($invoiceType == 'SPECIAL') {
  2861. $con .= ' and invoiceType=1 ';
  2862. }
  2863. $pageinfo ['page'] = array (
  2864. 'previous' => ''
  2865. );
  2866. // printStatus=1 and
  2867. $sql = " (untreadStatus=2 ) and status=2 and sid=" . $this->staff [0] ['sid'] . $con;
  2868. $action = "invoiceUntreadED";
  2869. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2870. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2871. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2872. // print_r($list);
  2873. $this->data ['MebSeaEn'] = $MebSea;
  2874. $this->data ['get'] = $get;
  2875. $this->data ['page'] = $pageinfo;
  2876. $this->data ['date'] = $date;
  2877. $this->data ['invoiceType'] = $invoiceType;
  2878. $this->data ['list'] = $list;
  2879. $this->data ['memu'] = "invoice";
  2880. $this->data ['staff'] = $this->staff;
  2881. $this->data ['receiptMemu'] = 'invoice';
  2882. $this->render ( "/admin/invoiceUntreadED", $this->data );
  2883. }
  2884. /**
  2885. * 退票处理页面
  2886. */
  2887. function invoiceUntread() {
  2888. Doo::loadModel ( 'invoice' );
  2889. $invoice = new invoice ();
  2890. $untreadInvoice = $invoice->getInvoiceByUntreadStatus ( 1, 0, 50 );
  2891. $establishedInvoice = $invoice->getInvoiceByUntreadStatus ( 2 );
  2892. //print_r($establishedInvoice);
  2893. // foreach ( $establishedInvoice as $key => $value ) {
  2894. // // months
  2895. // $lossDate = strtotime ( "+1 month", strtotime ( $value ['OperationLog'] ['date'] ) );
  2896. // $nowDate = strtotime ( 'now' );
  2897. // $establishedInvoice [$key] ['lossShow'] = false;
  2898. // if ($lossDate < $nowDate)
  2899. // $establishedInvoice [$key] ['lossShow'] = true;
  2900. // }
  2901. $this->data ['untreadInvoice'] = $untreadInvoice;
  2902. $this->data ['establishedInvoice'] = $establishedInvoice;
  2903. $this->data ['memu'] = "invoice";
  2904. $this->data ['staff'] = $this->staff;
  2905. $this->data ['receiptMemu'] = 'invoiceUntread';
  2906. $this->render ( "/admin/invoiceUntread", $this->data );
  2907. }
  2908. /**
  2909. * 确认收到退回的发票,开票状态为退回 //收款状态解绑,公司统计扣除入账额度
  2910. */
  2911. function invoiceUntreadEstablishedDo() {
  2912. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  2913. Doo::loadModel ( 'invoice' );
  2914. $invoice = new invoice ();
  2915. Doo::loadModel ( 'invoiceOperationLog' );
  2916. $invoiceOperationLog = new invoiceOperationLog ();
  2917. Doo::loadModel ( 'invoiceReceivables' );
  2918. Doo::loadModel ( 'invoiceStatistics' );
  2919. $iid = $invoice->authcode ( $untreadIidKey );
  2920. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2921. die ( 'illegal request' );
  2922. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  2923. if ($invoiceDetails ['untreadStatus'] != 1)
  2924. die ( 'illegal request untreadStatus error !=1' );
  2925. $item = array (
  2926. 'iid' => $iid,
  2927. // 'irid'=>'',
  2928. 'untreadStatus' => 2,
  2929. 'untreadTime'=>date ( "Y-m-d H:i:s" ) ,
  2930. 'updateTime' => date ( "Y-m-d H:i:s" )
  2931. );
  2932. $invoice->setInvoiceByCondition ( $item );
  2933. $item = array (
  2934. 'date' => date ( "Y-m-d H:i:s" ),
  2935. 'operation' => '已确认退票',
  2936. 'status' => 6,
  2937. 'img' => $this->staff [0] ['avatar'],
  2938. 'username' => $this->staff [0] ['username'],
  2939. 'uid' => $this->staff [0] ['sid'],
  2940. 'category' => $this->staff [0] ['category'],
  2941. 'iid' => $iid
  2942. );
  2943. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2944. // 收款解绑以及入账扣除 收款扣除
  2945. if (! empty ( $invoiceDetails ['irid'] )) {
  2946. $iridList = explode ( ',', $invoiceDetails ['irid'] );
  2947. foreach ( $iridList as $value ) {
  2948. $invoiceReceivables = new invoiceReceivables ();
  2949. $irDetails = $invoiceReceivables->getOne ( array (
  2950. 'where' => " irid=" . $value . ' ',
  2951. 'asArray' => TRUE
  2952. ) );
  2953. $bindPrice=$irDetails['bindPrice']-$invoiceDetails['invoicePrice'];
  2954. if($bindPrice<0){
  2955. $bindPrice=0;
  2956. }
  2957. $iidExtend = explode ( ',', $irDetails ['iidExtend'] );
  2958. $item = array (
  2959. 'irid' => $value,
  2960. 'bindStatus' => 0,
  2961. 'untreadStatus' => 1,
  2962. 'bindPrice'=>$bindPrice,
  2963. 'untreadStaff' => $invoiceDetails ['userName'],
  2964. 'unbundlingTime' => date ( "Y-m-d H:i:s" ),
  2965. );
  2966. if($irDetails['iid']==$iid){
  2967. $item+=array(
  2968. 'iid' => 0
  2969. );
  2970. }else{
  2971. foreach ($iidExtend as $iek=>$iev){
  2972. if($iev==$iid){
  2973. unset($iidExtend[$iek]);
  2974. break;
  2975. }
  2976. }
  2977. if(empty($iidExtend)){
  2978. $item+=array(
  2979. 'iidExtend' => ''
  2980. );
  2981. }else{
  2982. $iidExtend=implode(",", $iidExtend);
  2983. $item+=array(
  2984. 'iidExtend' => $iidExtend
  2985. );
  2986. }
  2987. }
  2988. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2989. if (! empty ( $irDetails )) {
  2990. // 扣除入账
  2991. $invoiceStatistics = new invoiceStatistics ();
  2992. $item = array (
  2993. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2994. 'priceClass' => 3,
  2995. 'cid' => $invoiceDetails ['cid'],
  2996. 'staff' => $invoiceDetails ['sid'],
  2997. 'accountPrice' => - $irDetails ['receivablesPrice']
  2998. );
  2999. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3000. // 扣除收款
  3001. $invoiceStatistics = new invoiceStatistics ();
  3002. $item = array (
  3003. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  3004. 'priceClass' => 2,
  3005. 'cid' => $invoiceDetails ['cid'],
  3006. 'staff' => $invoiceDetails ['sid'],
  3007. 'irid' => $irDetails ['irid'],
  3008. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  3009. );
  3010. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3011. }
  3012. // 解绑时删除收入流水--退票不删除流水
  3013. // Doo::loadModel ( 'wasteBook' );
  3014. // $wasteBook = new wasteBook ();
  3015. // $wasteBook->delete ( array (
  3016. // 'where' => 'dataID=' . $value . ' and accountType=7',
  3017. // 'limit' => 1
  3018. // ) );
  3019. }
  3020. }
  3021. return "/invoiceUntread";
  3022. }
  3023. function invoiceUntreadRecallDo() {
  3024. $iidKey = isset ( $this->params ['iidKey'] ) ? $this->params ['iidKey'] : "";
  3025. Doo::loadModel ( 'invoice' );
  3026. $invoice = new invoice ();
  3027. Doo::loadClass ( 'XDeode' );
  3028. $XDeode = new XDeode ( 5 );
  3029. Doo::loadModel ( 'invoiceOperationLog' );
  3030. $invoiceOperationLog = new invoiceOperationLog ();
  3031. $iid = $XDeode->decode ( $iidKey );
  3032. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  3033. if (empty ( $invoiceDetail )) {
  3034. die ( 'illegal request-DATANULL' );
  3035. }
  3036. $item = array (
  3037. 'iid' => $iid,
  3038. 'untreadStatus' => 0
  3039. );
  3040. $invoice->setInvoiceByCondition ( $item );
  3041. $item = array (
  3042. 'date' => date ( "Y-m-d H:i:s" ),
  3043. 'operation' => '撤回申请退票',
  3044. 'status' => 13,
  3045. 'img' => $this->staff [0] ['avatar'],
  3046. 'username' => $this->staff [0] ['username'],
  3047. 'uid' => $this->staff [0] ['sid'],
  3048. 'category' => $this->staff [0] ['category'],
  3049. 'iid' => $iid
  3050. );
  3051. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3052. return "/invoiceUntread";
  3053. }
  3054. /**
  3055. * 建立负票,关联原来发票
  3056. */
  3057. function invoiceLossDo() {
  3058. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  3059. if (! empty ( $iidKey )) {
  3060. Doo::loadClass ( 'XDeode' );
  3061. $XDeode = new XDeode ( 5 );
  3062. Doo::loadModel ( 'invoice' );
  3063. $invoice = new invoice ();
  3064. Doo::loadModel ( 'invoiceOperationLog' );
  3065. $invoiceOperationLog = new invoiceOperationLog ();
  3066. $iidKey = $XDeode->decode ( $iidKey );
  3067. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  3068. // 拷贝插入一条发票数据
  3069. $iid = $invoice->setInvoiceLoss ( $iidKey );
  3070. // 更新负票
  3071. if($invoiceDetail['invoiceForm']==1){
  3072. $invoiceSerial = "#FE" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  3073. }else{
  3074. $invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  3075. }
  3076. $invoice = new invoice ();
  3077. $item = array (
  3078. 'iid' => $iid,
  3079. 'sid' => $this->staff [0] ['sid'],
  3080. 'userName' => $this->staff [0] ['username'],
  3081. 'cid' => $this->staff [0] ['cid'],
  3082. 'categoryName' => $this->staff [0] ['category'],
  3083. 'invoiceQuantity' => - $invoiceDetail ['invoiceQuantity'],
  3084. 'invoicePrice' => - $invoiceDetail ['invoicePrice'],
  3085. 'invoiceSerial' => $invoiceSerial,
  3086. 'invoiceNo' => '',
  3087. 'printStatus' => 0,
  3088. 'untreadStatus' => 4,
  3089. // 关联发票号
  3090. 'lossIid' => $invoiceDetail ['iid']
  3091. );
  3092. $invoice->setInvoiceByCondition ( $item );
  3093. // 更新原发票
  3094. $invoice = new invoice ();
  3095. $item = array (
  3096. 'iid' => $invoiceDetail ['iid'],
  3097. 'lossIid' => $iid
  3098. );
  3099. $invoice->setInvoiceByCondition ( $item );
  3100. // 操作日志
  3101. $item = array (
  3102. 'date' => date ( "Y-m-d H:i:s" ),
  3103. 'operation' => "创建负票" . $invoiceSerial,
  3104. 'status' => 12,
  3105. 'img' => $this->staff [0] ['avatar'],
  3106. 'username' => $this->staff [0] ['username'],
  3107. 'uid' => $this->staff [0] ['sid'],
  3108. 'category' => $this->staff [0] ['category'],
  3109. 'iid' => $iid
  3110. );
  3111. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3112. // print_r($invoiceDetail);
  3113. // echo $iid;die;
  3114. }
  3115. return '/invoiceUntread';
  3116. }
  3117. /**
  3118. * 上传银行到账 收款文件
  3119. */
  3120. function invoiceReceivablesBankUpload() {
  3121. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  3122. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  3123. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  3124. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  3125. header ( "HTTP/1.1 500 Internal Server Error" );
  3126. echo "POST exceeded maximum allowed size.";
  3127. exit ( 0 );
  3128. }
  3129. // Settings
  3130. $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)
  3131. $upload_name = "Filedata";
  3132. $file_name = "";
  3133. $nk = time ();
  3134. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  3135. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  3136. echo "文件无法保存.";
  3137. exit ( 0 );
  3138. }
  3139. echo json_encode ( array (
  3140. 'filename' => $file_name,
  3141. 'id' => $nk
  3142. ) );
  3143. exit ( 0 );
  3144. }
  3145. /**
  3146. * 解析银行到账收款execl并导入库中
  3147. */
  3148. function invoiceReceivablesImport() {
  3149. $path = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  3150. if ($path != "") {
  3151. Doo::loadModel ( 'invoiceReceivables' );
  3152. $invoiceReceivables = new invoiceReceivables ();
  3153. Doo::loadClass ( 'invoice.func' );
  3154. Doo::loadModel ( 'invoiceROLog' );
  3155. $invoiceROLog = new invoiceROLog ();
  3156. Doo::loadModel ( 'invoiceStatistics' );
  3157. $invoiceStatistics = new invoiceStatistics ();
  3158. $exlArray = formatExcelToArrayBank ( DOO::conf ()->SITE_PATH . "upload/invoiceReceivablesBank/" . $path );
  3159. $bankBatchNumber = 'BBN_' . time ();
  3160. Doo::db ()->beginTransaction ();
  3161. // 批量存储收款--由于必须获得收款ID,
  3162. $sql = 'INSERT INTO CLD_invoiceReceivables (OriginalPrice,receivablesPrice, receivablesMessage,receivablesSerial,receivablesBank,receivablesDate,inputStaff,date,receivablesCategory,receivablesStaff,bankBatchNumber,recepitTitleMark)
  3163. VALUES ';
  3164. $date = date ( "Y-m-d" );
  3165. $receivablesList = array ();
  3166. foreach ( $exlArray as $key => $value ) {
  3167. $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"] . '")';
  3168. array_push ( $receivablesList, $receivablesSql );
  3169. }
  3170. $sql = $sql . implode ( ',', $receivablesList );
  3171. // echo $sql;
  3172. Doo::db ()->query ( $sql );
  3173. // 批量存储收款统计
  3174. // 获得刚刚导入数据的irid组-缺少办事处和人员
  3175. $iridList = $invoiceReceivables->getInvoiceReceivablesByBBN ( $bankBatchNumber );
  3176. // 没有irid 回滚所有操作
  3177. if (empty ( $iridList )) {
  3178. Doo::db ()->rollBack ();
  3179. header ( 'Content-Type:text/html;charset=utf-8' );
  3180. die ( '文档或数据不正确,请重新<a href="/invoiceReceivables">上传</a>.' );
  3181. }
  3182. $sql = 'INSERT INTO CLD_invoiceStatistics (date, priceClass,irid,receivablesPrice)
  3183. VALUES ';
  3184. $statisticsList = array ();
  3185. foreach ( $iridList as $value ) {
  3186. $statisticsSql = '("' . $date . '",2,' . $value ['irid'] . ',' . $value ["receivablesPrice"] . ')';
  3187. array_push ( $statisticsList, $statisticsSql );
  3188. }
  3189. $sql = $sql . implode ( ',', $statisticsList );
  3190. Doo::db ()->query ( $sql );
  3191. // 批量存储操作日志
  3192. $sql = 'INSERT INTO CLD_invoiceROLog (operation, date,status,img, username,uid,category,irid)
  3193. VALUES ';
  3194. $ROLogList = array ();
  3195. foreach ( $iridList as $value ) {
  3196. $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'] . '")';
  3197. array_push ( $ROLogList, $ROLogSql );
  3198. }
  3199. $sql = $sql . implode ( ',', $ROLogList );
  3200. Doo::db ()->query ( $sql );
  3201. // 批量写入流水
  3202. $sql = 'INSERT INTO CLD_wasteBook (dataID, expensesType,accountType,accountPriceShow, accountPrice,accountBank,category,cid,name,sid,inputDate)
  3203. VALUES ';
  3204. $wasteBookList = array ();
  3205. foreach ( $iridList as $value ) {
  3206. $accountBank = '';
  3207. if ($value ['receivablesBank'] == '纵横广发') {
  3208. $accountBank = 'CGBDeposit';
  3209. } elseif ($value ['receivablesBank'] == '纵横工行') {
  3210. $accountBank = 'ICBCDeposit';
  3211. } elseif ($value ['receivablesBank'] == '华润银行') {
  3212. $accountBank = 'HUADeposit';
  3213. } elseif ($value ['receivablesBank'] == '个人广发') {
  3214. $accountBank = 'PersonalDeposit';
  3215. }
  3216. $wasteBookSql = '("' . $value ['irid'] . ' ",1,7,"' . $value ['receivablesPrice'] . '","' . $value ['receivablesPrice'] . '","' . $accountBank . '",
  3217. "' . $this->staff [0] ['category'] . '","' . $this->staff [0] ['cid'] . '","' . $this->staff [0] ['username'] . '","' . $this->staff [0] ['sid'] . '","' . date ( "Y-m-d H:i:s" ) . '")';
  3218. array_push ( $wasteBookList, $wasteBookSql );
  3219. }
  3220. $sql = $sql . implode ( ',', $wasteBookList );
  3221. Doo::db ()->query ( $sql );
  3222. Doo::db ()->commit ();
  3223. return "/invoiceReceivables";
  3224. }
  3225. echo 'no file';
  3226. }
  3227. function invoiceReceivables() {
  3228. $invoiceTC = $this->get_args ( 'invoiceTC' ) ? $this->get_args ( 'invoiceTC' ) : '';
  3229. Doo::loadModel ( 'L_category' );
  3230. $lCategory = new L_category ();
  3231. Doo::loadModel ( 'staff' );
  3232. $staff = new staff ();
  3233. Doo::loadModel ( 'invoiceReceivables' );
  3234. $invoiceReceivables = new invoiceReceivables ();
  3235. Doo::loadModel ( 'invoice' );
  3236. $invoice = new invoice ();
  3237. Doo::loadClass ( 'XDeode' );
  3238. $XDeode = new XDeode ( 5 );
  3239. $category = $lCategory->getCategory ();
  3240. $staffList = $staff->getStaffByCid ( $this->staff [0] ['cid'] );
  3241. $sql = 'bindStatus=1 and iid!=0';
  3242. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByNew ( 4, $sql );
  3243. // 获取未入账发票
  3244. $invoiceUnAccount = $invoice->getInvoiceByUnAccount ( $invoiceTC );
  3245. $invoiceExistAccount = $invoice->getInvoiceByUnAccount ( '', true );
  3246. foreach ( $invoiceUnAccount as $key => $value ) {
  3247. $invoiceUnAccount [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  3248. $lastApprover = json_decode ( $value ['processApprovals'], true );
  3249. if (! empty ( $lastApprover )) {
  3250. $lastApproverKey = array_keys ( $lastApprover );
  3251. $lastApprover = end ( $lastApprover );
  3252. $staffDetail = $staff->getOne ( array (
  3253. 'where' => 'sid=' . end ( $lastApproverKey ),
  3254. 'asArray' => true
  3255. ) );
  3256. $lastApprover ['username'] = $staffDetail ['username'];
  3257. }
  3258. $invoiceUnAccount [$key] ['lastApprover'] = $lastApprover;
  3259. }
  3260. foreach ( $invoiceExistAccount as $key => $value ) {
  3261. // $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  3262. // if (empty ( $irList ))
  3263. // $irList [0] ['sumPrice'] = 0;
  3264. //$balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  3265. $invoiceExistAccount [$key] ['existAccount'] = $value ['invoicePrice']-$value ['invoiceBalance'];
  3266. //$invoiceExistAccount [$key] ['balance'] = $balance;
  3267. }
  3268. $receivablesInput = $invoiceReceivables->getInvoiceReceivablesByInput ();
  3269. $halfList = $invoiceReceivables->getInvoiceReceivablesByHalf ();
  3270. $this->data ['halfList'] = $halfList;
  3271. $this->data ['halfCount'] = count ( $halfList );
  3272. // print_r($receivablesList);
  3273. $this->data ['receivablesDate'] = date ( "Y-m-d" );
  3274. $this->data ['ieaCount'] = count ( $invoiceExistAccount );
  3275. $this->data ['invoiceExistAccount'] = $invoiceExistAccount;
  3276. $this->data ['receivablesInput'] = $receivablesInput;
  3277. $this->data ['year'] = date ( 'Y' );
  3278. $this->data ['invoiceUnAccount'] = $invoiceUnAccount;
  3279. $this->data ['receivablesList'] = $receivablesList;
  3280. $this->data ['staffList'] = $staffList;
  3281. $this->data ['category'] = $category;
  3282. $this->data ['memu'] = "invoice";
  3283. $this->data ['staff'] = $this->staff;
  3284. $this->data ['receiptMemu'] = 'invoiceReceivables';
  3285. $this->render ( "/admin/invoiceReceivables", $this->data );
  3286. }
  3287. /**
  3288. * 设置收款认领地区
  3289. */
  3290. function setInvoiceReceivablesClaim() {
  3291. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  3292. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3293. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  3294. if (! empty ( $iridKey ) && ! empty ( $receivablesCategory )) {
  3295. Doo::loadModel ( 'invoiceReceivables' );
  3296. $invoiceReceivables = new invoiceReceivables ();
  3297. Doo::loadClass ( 'XDeode' );
  3298. $XDeode = new XDeode ( 5 );
  3299. Doo::loadModel ( 'invoiceROLog' );
  3300. $invoiceROLog = new invoiceROLog ();
  3301. $irid = $XDeode->decode ( $iridKey );
  3302. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  3303. if (empty ( $irDetail ))
  3304. die ( 'illegal request' );
  3305. $item = array (
  3306. 'irid' => $irid,
  3307. 'receivablesCategory' => $receivablesCategory
  3308. );
  3309. if ($receivablesCategory != 'PUBLIC') {
  3310. $item += array (
  3311. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3312. 'inputType' => 1
  3313. );
  3314. }
  3315. $invoiceReceivables = new invoiceReceivables ();
  3316. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3317. // 收款操作日志
  3318. $item = array (
  3319. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 ",
  3320. 'date' => date ( "Y-m-d" ),
  3321. 'status' => 1,
  3322. 'img' => $this->staff [0] ['avatar'],
  3323. 'username' => $this->staff [0] ['username'],
  3324. 'uid' => $this->staff [0] ['sid'],
  3325. 'category' => $this->staff [0] ['category'],
  3326. 'irid' => $irid
  3327. );
  3328. $invoiceROLog->setInvoiceROLog ( $item );
  3329. if (empty ( $action ))
  3330. return '/invoiceReceivables';
  3331. else
  3332. return "/invoiceReceivablesAS";
  3333. }
  3334. die ( 'illegal request' );
  3335. }
  3336. /**
  3337. * 新添加收款直接入账发票
  3338. */
  3339. function invoiceCompareClaimPrice() {
  3340. // 收款录入
  3341. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  3342. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3343. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3344. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3345. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3346. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $iidKey )) {
  3347. Doo::loadModel ( 'invoiceReceivables' );
  3348. $invoiceReceivables = new invoiceReceivables ();
  3349. Doo::loadModel ( 'invoiceROLog' );
  3350. $invoiceROLog = new invoiceROLog ();
  3351. Doo::loadModel ( 'invoiceStatistics' );
  3352. Doo::loadModel ( 'invoice' );
  3353. $invoice = new invoice ();
  3354. Doo::loadModel ( 'bill' );
  3355. $bill = new bill ();
  3356. Doo::loadClass ( 'XDeode' );
  3357. $XDeode = new XDeode ( 5 );
  3358. Doo::loadModel ( 'invoiceOperationLog' );
  3359. $invoiceOperationLog = new invoiceOperationLog ();
  3360. $iidKey = $XDeode->decode ( $iidKey );
  3361. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  3362. if (! ($invoiceDetail ['status'] == 2 && $invoiceDetail ['printStatus'] == 1 && $invoiceDetail ['untreadStatus'] == 0))
  3363. die ( 'illegal request' );
  3364. $receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  3365. // 收款录入 并绑定发票
  3366. Doo::db ()->beginTransaction ();
  3367. //获得发票入账余额
  3368. //$bindInvicePrice=$invoiceReceivables->getSumOfReceivablesPrice ( $invoiceDetail['irid'] );
  3369. //$bindPrice=$invoiceDetail ['invoiceBalance']-$bindInvicePrice;
  3370. $bindStatus = 0;
  3371. $invoiceBalance=$invoiceDetail ['invoicePrice'];
  3372. if($invoiceDetail ['invoiceBalance']!=0){
  3373. $invoiceBalance=$invoiceDetail ['invoiceBalance'];
  3374. }
  3375. if ($receivablesPrice <= $invoiceBalance){
  3376. $bindStatus = 1;
  3377. //$bindPrice=$receivablesPrice;
  3378. }
  3379. $titleMark = $invoiceDetail ['invoiceTitle'];
  3380. if (! empty ( $invoiceDetail ['invoiceCompany'] ))
  3381. $titleMark = $invoiceDetail ['invoiceCompany'];
  3382. $item = array (
  3383. 'recepitTitleMark' => $titleMark,
  3384. 'bindStatus' => $bindStatus,
  3385. 'iid' => $invoiceDetail ['iid'],
  3386. 'bindPrice' => $receivablesPrice,
  3387. 'bindDate' => date ( "Y-m-d H:i:s" ),
  3388. 'receivablesPrice' => $receivablesPrice,
  3389. 'OriginalPrice' => $receivablesPrice,
  3390. 'receivablesMessage' => $receivablesMessage,
  3391. 'receivablesSerial' => $receivablesSerial,
  3392. 'receivablesBank' => $receivablesBank,
  3393. 'receivablesDate' => $receivablesDate,
  3394. 'inputStaff' => $this->staff [0] ['username'],
  3395. 'accountClerk' => $this->staff [0] ['username'],
  3396. 'date' => date ( "Y-m-d" ),
  3397. 'receivablesCategory' => $invoiceDetail ['cid'] . ':' . $invoiceDetail ['categoryName'],
  3398. 'receivablesStaff' => $invoiceDetail ['sid'] . '-' . $invoiceDetail ['userName'],
  3399. 'confirmTime' => date ( "Y-m-d H:i:s" )
  3400. );
  3401. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  3402. $item = array ();
  3403. // 收款操作日志
  3404. $item = array (
  3405. 'operation' => $this->staff [0] ['username'] . " 转入 " . $invoiceDetail ['userName']
  3406. );
  3407. $item += array (
  3408. 'date' => date ( "Y-m-d" ),
  3409. 'status' => 1,
  3410. 'img' => $this->staff [0] ['avatar'],
  3411. 'username' => $this->staff [0] ['username'],
  3412. 'uid' => $this->staff [0] ['sid'],
  3413. 'category' => $this->staff [0] ['category'],
  3414. 'irid' => $irid
  3415. );
  3416. $invoiceROLog->setInvoiceROLog ( $item );
  3417. // 收款统计
  3418. $invoiceStatistics = new invoiceStatistics ();
  3419. $item = array (
  3420. 'date' => $receivablesDate,
  3421. 'priceClass' => 2,
  3422. 'irid' => $irid,
  3423. 'cid' => $invoiceDetail ['cid'],
  3424. 'staff' => $invoiceDetail ['sid'],
  3425. 'receivablesPrice' => $receivablesPrice
  3426. );
  3427. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3428. // 收款 入 发票
  3429. $detail = $invoiceDetail;
  3430. $iridString = "";
  3431. if (empty ( $detail ['irid'] ))
  3432. $iridString = $irid;
  3433. else
  3434. $iridString = $detail ['irid'] . ',' . $irid;
  3435. $item = array (
  3436. 'irid' => $iridString,
  3437. 'bindTime' => date ( "Y-m-d H:i:s" ),
  3438. 'updateTime' => date ( "Y-m-d H:i:s" ),
  3439. 'iid' => $detail ['iid']
  3440. );
  3441. // $invoiceReceivables = new invoiceReceivables ();
  3442. // $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  3443. // $sumBind = $bindInvicePrice;
  3444. // $sumBalance=$invoiceReceivables->balanceOfReceivablesPrice($irid);
  3445. // $sum=$sumBind+$sumBalance;
  3446. // ;
  3447. if ($receivablesPrice>=$invoiceBalance){
  3448. $item += array (
  3449. 'invoiceBalance'=>0,
  3450. 'untreadStatus' => 3
  3451. );
  3452. }else{
  3453. $item += array (
  3454. 'invoiceBalance'=>$invoiceBalance-$receivablesPrice
  3455. );
  3456. }
  3457. $invoice->setInvoiceByCondition ( $item );
  3458. // 操作日志
  3459. $item = array (
  3460. 'date' => date ( "Y-m-d H:i:s" ),
  3461. 'operation' => "收款入账" . $receivablesSerial . "到发票" . $detail ['invoiceSerial'],
  3462. 'status' => 8,
  3463. 'img' => $this->staff [0] ['avatar'],
  3464. 'username' => $this->staff [0] ['username'],
  3465. 'uid' => $this->staff [0] ['sid'],
  3466. 'category' => $this->staff [0] ['category'],
  3467. 'iid' => $detail ['iid']
  3468. );
  3469. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3470. // 入账汇总
  3471. $invoiceStatistics = new invoiceStatistics ();
  3472. // $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $iridString );
  3473. // $accountPrice = 0;
  3474. // foreach ( $list as $key => $value ) {
  3475. // $accountPrice += $value ['receivablesPrice'];
  3476. // }
  3477. $item = array (
  3478. 'date' => $receivablesDate,
  3479. 'priceClass' => 3,
  3480. 'cid' => $invoiceDetail ['cid'],
  3481. 'staff' => $invoiceDetail ['sid'],
  3482. 'accountPrice' => $receivablesPrice
  3483. );
  3484. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3485. //发票入账记录
  3486. $bill->iid=$invoiceDetail['iid'];
  3487. $bill->trainId=$invoiceDetail['trainId'];
  3488. $bill->irid=$irid;
  3489. $bill->create_time=date ( "Y-m-d H:i:s" );
  3490. $bill->price=$invoiceBalance;
  3491. $bill->insert ();
  3492. // 公司流水记录
  3493. Doo::loadModel ( 'wasteBook' );
  3494. $wasteBook = new wasteBook ();
  3495. $abDetail = $wasteBook->getAccountBookByAid ( 1, 7, $irid );
  3496. $accountBank=$wasteBook->_getAccountBankEN($receivablesBank);
  3497. if (empty ( $abDetail )) {
  3498. $item = array (
  3499. 'dataID' => $irid,
  3500. 'expensesType' => 1,
  3501. 'accountType' => 7,
  3502. 'accountPrice' => $receivablesPrice,
  3503. 'accountPriceShow' => $receivablesPrice,
  3504. 'accountBank' => $accountBank,
  3505. 'cid'=>$invoiceDetail['cid'],
  3506. 'category' => $invoiceDetail ['categoryName'],
  3507. 'name' => $this->staff [0] ['username'],
  3508. 'sid' => $this->staff [0] ['sid'],
  3509. 'inputDate' => $receivablesDate//date ( "Y-m-d H:i:s" )
  3510. );
  3511. $wasteBook->setAccountBookStatistics ( $item );
  3512. }
  3513. Doo::db ()->commit ();
  3514. }
  3515. return '/invoiceReceivables';
  3516. }
  3517. /**
  3518. * 录入收款数据
  3519. * @return string
  3520. */
  3521. function invoiceReceivablesDo() {
  3522. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3523. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3524. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3525. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3526. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3527. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  3528. Doo::loadModel ( 'invoiceReceivables' );
  3529. $invoiceReceivables = new invoiceReceivables ();
  3530. Doo::loadModel ( 'invoiceROLog' );
  3531. $invoiceROLog = new invoiceROLog ();
  3532. Doo::loadModel ( 'invoiceStatistics' );
  3533. $invoiceStatistics = new invoiceStatistics ();
  3534. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $receivablesCategory ) && ! empty ( $receivablesStaff )) {
  3535. $item = array (
  3536. 'receivablesPrice' => $receivablesPrice,
  3537. 'OriginalPrice' => $receivablesPrice,
  3538. 'receivablesMessage' => $receivablesMessage,
  3539. 'receivablesSerial' => "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  3540. 'receivablesBank' => $receivablesBank,
  3541. 'receivablesDate' => $receivablesDate,
  3542. 'inputStaff' => $this->staff [0] ['username'],
  3543. 'date' => date ( "Y-m-d" ),
  3544. 'receivablesCategory' => $receivablesCategory,
  3545. 'receivablesStaff' => $receivablesStaff
  3546. );
  3547. if ($receivablesCategory != 'PUBLIC') {
  3548. $item += array (
  3549. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3550. 'inputType' => 1
  3551. );
  3552. }
  3553. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  3554. $item = array ();
  3555. // 收款操作日志
  3556. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3557. $item = array (
  3558. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  3559. );
  3560. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3561. $item = array (
  3562. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  3563. );
  3564. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3565. $receivablesStaff = explode ( '-', $receivablesStaff );
  3566. $item = array (
  3567. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  3568. );
  3569. }
  3570. $item += array (
  3571. 'date' => date ( "Y-m-d" ),
  3572. 'status' => 1,
  3573. 'img' => $this->staff [0] ['avatar'],
  3574. 'username' => $this->staff [0] ['username'],
  3575. 'uid' => $this->staff [0] ['sid'],
  3576. 'category' => $this->staff [0] ['category'],
  3577. 'irid' => $irid
  3578. );
  3579. $invoiceROLog->setInvoiceROLog ( $item );
  3580. $item = array (
  3581. 'date' => $receivablesDate,
  3582. 'priceClass' => 2,
  3583. 'irid' => $irid,
  3584. 'receivablesPrice' => $receivablesPrice
  3585. );
  3586. if ($receivablesCategory != 'PUBLIC') {
  3587. $receivablesCategory = explode ( ":", $receivablesCategory );
  3588. $item += array (
  3589. 'cid' => $receivablesCategory [0]
  3590. );
  3591. }
  3592. if ($receivablesStaff2 != 'PUBLIC') {
  3593. $receivablesStaff = explode ( "-", $receivablesStaff2 );
  3594. $item += array (
  3595. 'staff' => $receivablesStaff [0]
  3596. );
  3597. }
  3598. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3599. $toparty = $this->getWxidByCategory ( $receivablesCategory [1] );
  3600. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  3601. $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  3602. if ($toparty != 0)
  3603. $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  3604. // 公司流水记录
  3605. Doo::loadModel ( 'wasteBook' );
  3606. $wasteBook = new wasteBook ();
  3607. $abDetail = $wasteBook->getAccountBookByAid ( 1, 7, $irid );
  3608. $accountBank=$wasteBook->_getAccountBankEN($receivablesBank);
  3609. $item = array (
  3610. 'dataID' => $irid,
  3611. 'expensesType' => 1,
  3612. 'accountType' => 7,
  3613. 'accountPriceShow' => $receivablesPrice,
  3614. 'accountPrice' => $receivablesPrice,
  3615. 'accountBank' => $accountBank,
  3616. 'category' => $this->staff [0] ['category'],
  3617. 'cid' => $this->staff [0] ['cid'],
  3618. 'name' => $this->staff [0] ['username'],
  3619. 'sid' => $this->staff [0] ['sid'],
  3620. 'inputDate' => $receivablesDate ,
  3621. //'createAt'=>date ( "Y-m-d H:i:s" ) ,
  3622. 'synPaymentDate'=>1
  3623. );
  3624. $wasteBook->setAccountBookStatistics ( $item );
  3625. }
  3626. return "/invoiceReceivables";
  3627. }
  3628. /**
  3629. * 收款认领页面-包括公共认领 办事处认领 最近已认领数据
  3630. */
  3631. function invoiceReceivablesClaim() {
  3632. Doo::loadModel ( 'invoiceReceivables' );
  3633. $invoiceReceivables = new invoiceReceivables ();
  3634. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  3635. $this->data ['receivablesList'] = $receivablesList;
  3636. $this->data ['memu'] = "invoice";
  3637. $this->data ['staff'] = $this->staff;
  3638. $this->data ['receiptMemu'] = 'invoiceReceivablesClaim';
  3639. $this->render ( "/admin/invoiceReceivablesClaim", $this->data );
  3640. }
  3641. function invoiceReceivablesTitleMarkSet() {
  3642. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  3643. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  3644. if (empty ( $iridKey ) || empty ( $recepitTitleMark ))
  3645. die ( 'illegal request' );
  3646. Doo::loadModel ( 'invoiceReceivables' );
  3647. $invoiceReceivables = new invoiceReceivables ();
  3648. Doo::loadClass ( 'XDeode' );
  3649. $XDeode = new XDeode ( 5 );
  3650. $irid = $XDeode->decode ( $iridKey );
  3651. if (! is_numeric ( $irid ))
  3652. die ( 'illegal request' );
  3653. $invoiceReceivables->recepitTitleMark = $recepitTitleMark;
  3654. $invoiceReceivables->update ( array (
  3655. 'where' => 'irid = ' . $irid
  3656. ) );
  3657. return '/invoiceReceivablesClaim';
  3658. }
  3659. /**
  3660. * 更新收款相关数据
  3661. */
  3662. function invoiceReceivablesUpdateClaim() {
  3663. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3664. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3665. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3666. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3667. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3668. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  3669. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  3670. if (empty ( $claimKey ))
  3671. die ( 'illegal request' );
  3672. Doo::loadModel ( 'invoiceReceivables' );
  3673. $invoiceReceivables = new invoiceReceivables ();
  3674. Doo::loadModel ( 'invoiceROLog' );
  3675. $invoiceROLog = new invoiceROLog ();
  3676. $con = ' and iid=0 and bindStatus=0'; // and receivablesCategory!="PUBLIC" and receivablesStaff!="PUBLIC"
  3677. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  3678. if (empty ( $detail ))
  3679. die ( 'illegal request' );
  3680. $invoiceReceivables = new invoiceReceivables ();
  3681. $item = array (
  3682. 'irid' => $detail ['irid']
  3683. );
  3684. if ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3685. $item += array (
  3686. 'confirmTime' => date ( "Y-m-d H:i:s" )
  3687. );
  3688. }
  3689. if (! empty ( $receivablesCategory ))
  3690. $item += array (
  3691. 'receivablesCategory' => $receivablesCategory
  3692. );
  3693. if (! empty ( $receivablesStaff ))
  3694. $item += array (
  3695. 'receivablesStaff' => $receivablesStaff
  3696. );
  3697. if (! empty ( $receivablesPrice ))
  3698. $item += array (
  3699. 'receivablesPrice' => $receivablesPrice
  3700. );
  3701. if (! empty ( $receivablesMessage ))
  3702. $item += array (
  3703. 'receivablesMessage' => $receivablesMessage
  3704. );
  3705. if (! empty ( $receivablesBank ))
  3706. $item += array (
  3707. 'receivablesBank' => $receivablesBank
  3708. );
  3709. if (! empty ( $receivablesDate ))
  3710. $item += array (
  3711. 'receivablesDate' => $receivablesDate
  3712. );
  3713. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3714. // 收款操作日志
  3715. $item = array ();
  3716. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3717. $item = array (
  3718. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  3719. );
  3720. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3721. $item = array (
  3722. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  3723. );
  3724. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3725. $receivablesStaff = explode ( '-', $receivablesStaff );
  3726. $item = array (
  3727. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  3728. );
  3729. }
  3730. $item += array (
  3731. 'date' => date ( "Y-m-d" ),
  3732. 'status' => 1,
  3733. 'img' => $this->staff [0] ['avatar'],
  3734. 'username' => $this->staff [0] ['username'],
  3735. 'uid' => $this->staff [0] ['sid'],
  3736. 'category' => $this->staff [0] ['category'],
  3737. 'irid' => $detail ['irid']
  3738. );
  3739. $invoiceROLog->setInvoiceROLog ( $item );
  3740. return '/invoiceReceivablesAS';
  3741. }
  3742. function invoiceReceivablesDelete() {
  3743. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  3744. $skll = $this->get_args ( 'skll' ) ? $this->get_args ( 'skll' ) : "";
  3745. if ($skll != '删除到款')
  3746. die ( 'illegal request-未填写 删除到款' );
  3747. if (empty ( $claimKey ))
  3748. die ( 'illegal request-收款key不正确' );
  3749. Doo::loadModel ( 'invoiceReceivables' );
  3750. $invoiceReceivables = new invoiceReceivables ();
  3751. $con = ' and bindStatus=0 ';
  3752. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  3753. if (empty ( $detail ))
  3754. die ( 'illegal request-未找到该收款或者未解绑' );
  3755. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  3756. // 扣除收款汇总信息 汇总
  3757. Doo::loadModel ( 'invoiceStatistics' );
  3758. $invoiceStatistics = new invoiceStatistics ();
  3759. $item = array (
  3760. 'date' => $detail ['receivablesDate'],
  3761. 'priceClass' => 2,
  3762. 'irid' => $detail ['irid'],
  3763. 'receivablesPrice' => - $detail ['receivablesPrice']
  3764. );
  3765. if ($detail ['receivablesCategory'] != 'PUBLIC') {
  3766. $receivablesCategory = explode ( ":", $detail ['receivablesCategory'] );
  3767. $item += array (
  3768. 'cid' => $receivablesCategory [0]
  3769. );
  3770. }
  3771. if ($detail ['receivablesStaff'] != 'PUBLIC') {
  3772. $receivablesStaff = explode ( "-", $detail ['receivablesStaff'] );
  3773. $item += array (
  3774. 'staff' => $receivablesStaff [0]
  3775. );
  3776. }
  3777. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3778. // 公司流水-删除时删除流水
  3779. Doo::loadModel ( 'wasteBook' );
  3780. $wasteBook = new wasteBook ();
  3781. $wasteBook->delete ( array (
  3782. 'where' => 'dataID=' . $detail ['irid'] . ' and accountType=7',
  3783. 'limit' => 1
  3784. ) );
  3785. return '/invoiceReceivablesAS';
  3786. }
  3787. /**
  3788. * 管理员录入的收款 ,确认认领到谁的名下.统计收款金额
  3789. */
  3790. function invoiceReceivablesAscription() {
  3791. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  3792. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  3793. Doo::loadModel ( 'invoiceReceivables' );
  3794. $invoiceReceivables = new invoiceReceivables ();
  3795. Doo::loadModel ( 'invoiceROLog' );
  3796. $invoiceROLog = new invoiceROLog ();
  3797. Doo::loadModel ( 'invoiceStatistics' );
  3798. $invoiceStatistics = new invoiceStatistics ();
  3799. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  3800. $irid = $invoiceReceivables->authcode ( $irid );
  3801. if (! empty ( $detail ) && $detail ['receivablesStaff'] == 'PUBLIC' && ! empty ( $recepitTitleMark )) {
  3802. $item = array (
  3803. 'irid' => $detail ['irid'],
  3804. 'receivablesCategory' => $this->staff [0] ['cid'] . ":" . $this->staff [0] ['category'],
  3805. 'receivablesStaff' => $this->staff [0] ['sid'] . "-" . $this->staff [0] ['username'],
  3806. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3807. 'recepitTitleMark' => $recepitTitleMark,
  3808. 'source' => 1
  3809. );
  3810. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3811. $item = array (
  3812. 'date' => date ( "Y-m-d" ),
  3813. 'operation' => $this->staff [0] ['username'] . " 认领 ",
  3814. 'status' => 2,
  3815. 'img' => $this->staff [0] ['avatar'],
  3816. 'username' => $this->staff [0] ['username'],
  3817. 'uid' => $this->staff [0] ['sid'],
  3818. 'category' => $this->staff [0] ['category'],
  3819. 'irid' => $irid
  3820. );
  3821. $invoiceROLog->setInvoiceROLog ( $item );
  3822. $item = array (
  3823. 'cid' => $this->staff [0] ['cid'],
  3824. 'staff' => $this->staff [0] ['sid']
  3825. );
  3826. $invoiceStatistics->updateInvoiceStatisticsByIrid ( $item, $detail ['irid'], 2 );
  3827. //更新流水的办事处
  3828. Doo::loadModel ( 'wasteBook' );
  3829. $wasteBook = new wasteBook ();
  3830. $abDetail = $wasteBook->getAccountBookByAid ( 1, 7, $detail ['irid'] );
  3831. $wasteBook->wid = $abDetail ['wid'];
  3832. $wasteBook->category = $this->staff [0] ['category'];
  3833. $wasteBook->cid = $this->staff [0] ['cid'];
  3834. $wasteBook->update ();
  3835. }
  3836. return "/invoiceReceivablesClaim";
  3837. }
  3838. /**
  3839. */
  3840. function invoiceMyReceivables() {
  3841. Doo::loadModel ( 'invoiceReceivables' );
  3842. $invoiceReceivables = new invoiceReceivables ();
  3843. Doo::loadModel ( 'invoiceStatistics' );
  3844. $invoiceStatistics = new invoiceStatistics ();
  3845. $isMonth = $invoiceStatistics->getStatisticsByMonth ( $this->staff [0] ['sid'] );
  3846. $year = date ( "Y" );
  3847. $tmp_date = date ( "Ym" );
  3848. $tmp_year = substr ( $tmp_date, 0, 4 );
  3849. $tmp_mon = substr ( $tmp_date, 4, 2 );
  3850. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  3851. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  3852. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . ".htm";
  3853. $htm = $this->showCache ( $path );
  3854. $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  3855. $this->data ['isMonth'] = $isMonth;
  3856. $this->data ['htm'] = $htm;
  3857. $this->data ['list'] = $list;
  3858. $this->data ['memu'] = "invoice";
  3859. $this->data ['staff'] = $this->staff;
  3860. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  3861. $this->render ( "/admin/invoiceMyReceivables", $this->data );
  3862. }
  3863. /**
  3864. * 纸票管理
  3865. */
  3866. function invoicePaper() {
  3867. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3868. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3869. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3870. $this->data ['dateString'] = $date;
  3871. $this->data ['status'] = $status;
  3872. $this->data ['invoiceType'] = $invoiceType;
  3873. $this->data ['memu'] = "invoice";
  3874. $this->data ['staff'] = $this->staff;
  3875. $this->data ['receiptMemu'] = 'invoicePaper';
  3876. $this->render ( "/admin/invoicePaper", $this->data );
  3877. }
  3878. /**
  3879. * 电子发票管理
  3880. */
  3881. function invoiceElectronic() {
  3882. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3883. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3884. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3885. $this->data ['dateString'] = $date;
  3886. $this->data ['status'] = $status;
  3887. $this->data ['invoiceType'] = $invoiceType;
  3888. $this->data ['memu'] = "invoice";
  3889. $this->data ['staff'] = $this->staff;
  3890. $this->data ['receiptMemu'] = 'invoicePaper';
  3891. $this->render ( "/invoice/invoiceElectronic", $this->data );
  3892. }
  3893. /**
  3894. * 获得纸票分页数据
  3895. */
  3896. function ajaxGetinvoicePaperAchieve() {
  3897. //include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  3898. Doo::loadModel ( 'invoicePaper' );
  3899. $invoicePaper = new invoicePaper ();
  3900. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3901. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3902. $invoiceForm = $this->get_args ( 'invoiceForm' )&&is_numeric($this->get_args ( 'invoiceForm' )) ? $this->get_args ( 'invoiceForm' ) : "0";
  3903. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ORDINARY";
  3904. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3905. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  3906. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  3907. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  3908. $MebSea = $this->get_args ( 'search' );
  3909. $MebSea = $MebSea ['value'];
  3910. $page_size = $length;
  3911. $con = '';
  3912. if ($status == 'ALL')
  3913. $con = ' where 1 ';
  3914. elseif ($status == 'PRINTED')
  3915. $con = ' where a.iid!=0 '; // $con = ' where b.isDelete=0 and a.iid!=0 and b.status=2 and b.untreadStatus=0 ';
  3916. elseif ($status == 'UNPRINT')
  3917. $con = ' where a.iid=0 '; // $con = ' where b.isDelete=0 and a.iid=0 and b.status=2 and b.untreadStatus=0 ';
  3918. elseif ($status == 'TICKET')
  3919. $con = ' where b.isDelete=0 and b.untreadStatus=2';
  3920. if ($invoiceType == 'ORDINARY')
  3921. $con .= ' and a.invoiceType=0 ';
  3922. elseif ($invoiceType == 'SPECIAL')
  3923. $con .= ' and a.invoiceType=1 ';
  3924. if($invoiceForm==0){
  3925. $con .= ' and a.invoiceForm=0 ';
  3926. }else{
  3927. $con .= ' and a.invoiceForm=1 ';
  3928. }
  3929. $dateArr = explode ( ':', $date );
  3930. $D1 = $dateString = '';
  3931. $D2 = '';
  3932. if (! empty ( $date )) {
  3933. $D1 = $dateArr [0];
  3934. if (isset ( $dateArr [1] ))
  3935. $D2 = $dateArr [1];
  3936. else
  3937. $D2 = '';
  3938. $dateString = $D1 . " : " . $D2;
  3939. }
  3940. if (! empty ( $D1 ) && ! empty ( $D2 ))
  3941. $con .= ' and b.printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  3942. elseif (! empty ( $D1 ) && empty ( $D2 ))
  3943. $con .= ' and b.printTime like "%' . $D1 . '%" ';
  3944. if (! empty ( $MebSea ))
  3945. $con .= ' and ( b.invoiceTitle like "%' . $MebSea . '%" or b.invoiceCompany like "%' . $MebSea . '%" or a.invoiceNo like "%' . $MebSea . '%" )';
  3946. $invoiceTotal = $invoicePaper->getInvoicePaperCount ($invoiceForm);
  3947. $sql = ' ' . $con;
  3948. $limit = $page . ',' . $page_size;
  3949. $list = $invoicePaper->getInvoicePaper ( $limit, $sql, 'desc' );
  3950. $paperList = array ();
  3951. foreach ( $list as $key => $value ) {
  3952. $irDetail = array ();
  3953. if ($value ['iid'] == 0)
  3954. array_push ( $irDetail, '<a href="javascript:if(window.confirm(\'确认删除?\'))window.location=\'/invoicePaperDel/' . $value ['ipidKey'] . '\'" >删除</a>' );
  3955. else
  3956. array_push ( $irDetail, '' );
  3957. array_push ( $irDetail, $value ['invoiceCode'] );
  3958. array_push ( $irDetail, $value ['invoiceNo'] );
  3959. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKey'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  3960. if ($value ['invoiceType'] == 1)
  3961. array_push ( $irDetail, $value ['invoiceCompany'] );
  3962. else
  3963. array_push ( $irDetail, $value ['invoiceTitle'] );
  3964. if ($value ['invoiceType'] == 1)
  3965. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  3966. else
  3967. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  3968. array_push ( $irDetail, $value ['invoiceElement'] );
  3969. array_push ( $irDetail, $value ['categoryName'] . '-' . $value ['userName'] );
  3970. array_push ( $irDetail, $value ['printTime'] );
  3971. array_push ( $paperList, $irDetail );
  3972. }
  3973. // $approvalListJson = json_encode ( $approvalList );
  3974. $recordsFiltered = $invoiceTotal;
  3975. echo json_encode ( array (
  3976. "draw" => intval ( $draw ),
  3977. "recordsTotal" => intval ( $invoiceTotal ),
  3978. "recordsFiltered" => intval ( $recordsFiltered ),
  3979. "data" => $paperList
  3980. ), JSON_UNESCAPED_UNICODE );
  3981. }
  3982. function invoicePaperDel() {
  3983. $ipidKey = isset ( $this->params ['ipidKey'] ) ? $this->params ['ipidKey'] : "";
  3984. $XDeode = new XDeode ( 5 );
  3985. $ipid = $XDeode->decode ( $ipidKey );
  3986. if (empty ( $ipid ))
  3987. die ( 'illegal request' );
  3988. Doo::loadModel ( 'invoicePaper' );
  3989. $invoicePaper = new invoicePaper ();
  3990. $ipdetail=$invoicePaper->getInvoicePaperByIpid($ipid);
  3991. $invoicePaper->delete ( array (
  3992. 'where' => 'ipid=' . $ipid . ' and iid=0',
  3993. 'limit' => 1
  3994. ) );
  3995. if($ipdetail['invoiceForm']==1){
  3996. return '/invoiceElectronic';
  3997. }else{
  3998. return '/invoicePaper';
  3999. }
  4000. }
  4001. /**
  4002. * 添加纸质发票号
  4003. */
  4004. function invoicePaperAdd() {
  4005. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : '0';
  4006. $invoiceCode = $this->get_args ( 'invoiceCode' ) ? $this->get_args ( 'invoiceCode' ) : "";
  4007. $invoiceNoStart = $this->get_args ( 'invoiceNoStart' ) && is_numeric ( $this->get_args ( 'invoiceNoStart' ) ) ? $this->get_args ( 'invoiceNoStart' ) : 0;
  4008. $invoiceNoTotal = $this->get_args ( 'invoiceNoTotal' ) && is_numeric ( $this->get_args ( 'invoiceNoTotal' ) ) ? $this->get_args ( 'invoiceNoTotal' ) : 0;
  4009. $invoiceForm = $this->get_args ( 'invoiceForm' ) && is_numeric ( $this->get_args ( 'invoiceForm' ) ) ? $this->get_args ( 'invoiceForm' ) : 0;
  4010. if ($invoiceType != '' && ! empty ( $invoiceCode ) && ! empty ( $invoiceNoStart ) && ! empty ( $invoiceNoTotal )) {
  4011. $sum = $invoiceNoStart + $invoiceNoTotal;
  4012. if (empty ( $sum ))
  4013. die ( 'illegal request' );
  4014. // echo $invoiceNoStart;
  4015. // echo $sum;
  4016. // echo strlen((int)$invoiceNoStart);
  4017. $sumLenght = strlen ( $invoiceNoStart ) - strlen ( ( int ) $invoiceNoStart );
  4018. if($invoiceType==0||$invoiceType==1){
  4019. }else{
  4020. die ( 'illegal request invoiceType' );
  4021. }
  4022. if($invoiceForm==1){
  4023. $invoiceType=0;
  4024. }
  4025. Doo::db ()->beginTransaction ();
  4026. // 批量存储纸质发票
  4027. $date = date ( "Y-m-d H:i:s" );
  4028. $sql = 'INSERT INTO CLD_invoicePaper (invoiceType, invoiceCode,invoiceNo,date,invoiceForm)
  4029. VALUES ';
  4030. $paperList = array ();
  4031. for($invoiceNoStart; $invoiceNoStart <= $sum - 1; $invoiceNoStart ++) {
  4032. // 数字前面自加0
  4033. $INLENGHT = strlen ( ( int ) $invoiceNoStart ) + $sumLenght;
  4034. $var = sprintf ( "%0" . $INLENGHT . "d", $invoiceNoStart );
  4035. $paperSql = '(' . $invoiceType . ',"' . $invoiceCode . '","' . $var . '","' . $date . '","'.$invoiceForm.'")';
  4036. array_push ( $paperList, $paperSql );
  4037. }
  4038. if (empty ( $paperList ))
  4039. die ( 'illegal request' );
  4040. $sql = $sql . implode ( ',', $paperList );
  4041. Doo::db ()->query ( $sql );
  4042. Doo::db ()->commit ();
  4043. if($invoiceForm==1){
  4044. return 'invoiceElectronic';
  4045. }else{
  4046. return 'invoicePaper';
  4047. }
  4048. }
  4049. die ( 'illegal request' );
  4050. }
  4051. /**
  4052. * 收款绑定发票 ,//一个收款只能绑定一个发票
  4053. */
  4054. function invoiceBindReceivables() {
  4055. $claimKey = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  4056. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  4057. Doo::loadModel ( 'invoice' );
  4058. $invoice = new invoice ();
  4059. Doo::loadModel ( 'invoiceReceivables' );
  4060. $invoiceReceivables = new invoiceReceivables ();
  4061. Doo::loadModel ( 'invoiceOperationLog' );
  4062. $invoiceOperationLog = new invoiceOperationLog ();
  4063. if (empty ( $invoiceKey ) || empty ( $claimKey ))
  4064. die ( 'illegal request' );
  4065. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  4066. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey );
  4067. if (empty ( $detail ) && empty ( $detailM ))
  4068. die ( 'illegal request' );
  4069. if ($detail ['untreadStatus'] == 3)
  4070. die ( 'illegal request' );
  4071. // 修改 绑定状态改为 金额
  4072. $invoiceReceivables = new invoiceReceivables ();
  4073. $invoicePrice = $detail ['invoicePrice'] + $detailM ['bindPrice'];
  4074. $billPrice=0;
  4075. if ($detailM ['receivablesPrice'] > $invoicePrice) {
  4076. $item = array (
  4077. 'bindPrice' => $invoicePrice
  4078. );
  4079. $billPrice=$invoicePrice;
  4080. } elseif ($detailM ['receivablesPrice'] <= $invoicePrice) { //发票金额大于收款金额,绑定金额为收款金额
  4081. $item = array (
  4082. 'bindPrice' => $detailM ['receivablesPrice'],
  4083. 'bindStatus' => 1,
  4084. 'bindDate' => date ( "Y-m-d H:i:s" )
  4085. );
  4086. $billPrice=$detailM ['receivablesPrice'];
  4087. } else {
  4088. die ( 'illegal request' );
  4089. }
  4090. if ($detailM ['iid'] == 0) {
  4091. $item += array (
  4092. 'iid' => $detail ['iid']
  4093. );
  4094. } else {
  4095. $iidExtend = explode ( ',', $detailM ['iidExtend'] );
  4096. array_push ( $iidExtend, $detail ['iid'] );
  4097. $item += array (
  4098. 'iidExtend' => implode ( ',', $iidExtend )
  4099. );
  4100. }
  4101. $titleMark = $detail ['invoiceTitle'];
  4102. if (! empty ( $detail ['invoiceCompany'] ))
  4103. $titleMark = $detail ['invoiceCompany'];
  4104. $item += array (
  4105. 'irid' => $detailM ['irid'],
  4106. 'recepitTitleMark' => $titleMark,
  4107. 'accountClerk' => $this->staff [0] ['username']
  4108. );
  4109. // 如何没有人收款 则自动绑定收款
  4110. if ($detailM ['receivablesCategory'] == 'PUBLIC' || $detailM ['receivablesStaff'] == 'PUBLIC') {
  4111. $item += array (
  4112. 'receivablesCategory' => $detail ['cid'] . ':' . $detail ['categoryName'],
  4113. 'receivablesStaff' => $detail ['sid'] . '-' . $detail ['userName']
  4114. );
  4115. }
  4116. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4117. $iridString = "";
  4118. if (empty ( $detail ['irid'] ))
  4119. $iridString = $detailM ['irid'];
  4120. else
  4121. $iridString = $detail ['irid'] . ',' . $detailM ['irid'];
  4122. // $invoiceReceivables = new invoiceReceivables ();
  4123. // $sumBind = $invoiceReceivables->getSumOfReceivablesPrice ( $detail ['irid'] );
  4124. // //这个收款余额
  4125. // $sumBalance=$invoiceReceivables->balanceOfReceivablesPrice($detailM ['irid']);
  4126. // $sum=$sumBind+$sumBalance;
  4127. //这个收款余额
  4128. $sumBalance=$detailM ['receivablesPrice']-$detailM ['bindPrice'];
  4129. // echo $detailM ['irid'].'/'.$sumBalance.'/'.$detail ['invoicePrice'];
  4130. // die;
  4131. $invoice = new invoice ();
  4132. $item = array (
  4133. 'iid' => $detail ['iid'],
  4134. 'irid' => $iridString
  4135. );
  4136. if ($detail ['invoicePrice'] <= $sumBalance){
  4137. $item += array (
  4138. 'invoiceBalance'=>0,
  4139. 'untreadStatus' => 3,
  4140. 'bindTime' => date ( "Y-m-d H:i:s" )
  4141. );
  4142. }else{
  4143. $item += array (
  4144. 'invoiceBalance'=>$detail ['invoicePrice']-$sumBalance,
  4145. );
  4146. }
  4147. // print_r($item);
  4148. // echo $sum;die;
  4149. $invoice->setInvoiceByCondition ( $item );
  4150. //发票入账记录
  4151. Doo::loadModel ( 'bill' );
  4152. $bill = new bill ();
  4153. $bill->iid=$detail ['iid'];
  4154. $bill->trainId=$detail['trainId'];
  4155. $bill->irid=$detailM ['irid'];
  4156. $bill->create_time=date ( "Y-m-d H:i:s" );
  4157. $bill->price=$billPrice;
  4158. $bill->insert ();
  4159. // 操作日志
  4160. $item = array (
  4161. 'date' => date ( "Y-m-d H:i:s" ),
  4162. 'operation' => "收款" . $detailM ['receivablesSerial'] . "入账到发票" . $detail ['invoiceSerial'],
  4163. 'status' => 8,
  4164. 'img' => $this->staff [0] ['avatar'],
  4165. 'username' => $this->staff [0] ['username'],
  4166. 'uid' => $this->staff [0] ['sid'],
  4167. 'category' => $this->staff [0] ['category'],
  4168. 'iid' => $detail ['iid']
  4169. );
  4170. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  4171. Doo::loadModel ( 'invoiceStatistics' );
  4172. $invoiceStatistics = new invoiceStatistics ();
  4173. $item = array (
  4174. 'date' => $detailM ['receivablesDate'],
  4175. 'priceClass' => 3,
  4176. 'cid' => $detail ['cid'],
  4177. 'staff' => $detail ['sid'],
  4178. 'accountPrice' => $detailM ['receivablesPrice']
  4179. );
  4180. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4181. //TODO
  4182. // 公司流水记录
  4183. // Doo::loadModel ( 'wasteBook' );
  4184. // $wasteBook = new wasteBook ();
  4185. // $abDetail = $wasteBook->getAccountBookByAid (1,8,$detail ['iid'] );
  4186. // $accountBank='';
  4187. // if ($detailM ['receivablesBank']=='纵横广发'){
  4188. // $accountBank='CGBDeposit';
  4189. // }elseif($detailM ['receivablesBank']=='纵横工行'){
  4190. // $accountBank='ICBCDeposit';
  4191. // }elseif($detailM ['receivablesBank']=='华润银行'){
  4192. // $accountBank='HUADeposit';
  4193. // }elseif($detailM ['receivablesBank']=='个人广发'){
  4194. // $accountBank='PersonalDeposit';
  4195. // }
  4196. // if (empty($abDetail)){
  4197. // $item = array (
  4198. // 'dataID' => $detail ['iid'],
  4199. // 'expensesType' => 1,
  4200. // 'accountType' => 8,
  4201. // 'accountPriceShow'=>$detail ['invoicePrice'],
  4202. // 'accountPrice'=>$detail ['invoicePrice'],
  4203. // 'accountBank'=>$accountBank,
  4204. // 'category'=>$this->staff[0]['category'],
  4205. // 'cid'=>$this->staff[0]['cid'],
  4206. // 'name'=>$this->staff[0]['username'],
  4207. // 'sid'=>$this->staff[0]['sid'],
  4208. // 'inputDate'=>date ( "Y-m-d H:i:s" )
  4209. // );
  4210. // $wasteBook->setAccountBookStatistics($item);
  4211. // }
  4212. return "/invoiceReceivables";
  4213. }
  4214. /**
  4215. * 核销 动作,确认入账统计 发票收款完成--需求更变 废弃 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"; }
  4216. */
  4217. function invoiceAggregate() {
  4218. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  4219. Doo::loadModel ( 'invoiceStatistics' );
  4220. $invoiceStatistics = new invoiceStatistics ();
  4221. Doo::loadModel ( 'L_category' );
  4222. $Lcategory = new L_category ();
  4223. $isList = $invoiceStatistics->getInvoiceStatisticsByYear ( $year );
  4224. $LcategoryList = $Lcategory->getCategory ();
  4225. // print_r($isList);
  4226. $html = ""; // $invoicePriceCategory=0;$receivablesPriceCategory=0;$accountPriceCategory=0;
  4227. foreach ( $LcategoryList as $key => $value ) {
  4228. $html .= '<tr><th><a href="/invoiceAggregateCategory/' . $value ['cidKey'] . '">' . $value ['title'] . '</a></th>';
  4229. $month = 1;
  4230. $invoicePriceYear = 0;
  4231. $receivablesPriceYear = 0;
  4232. $accountPriceYear = 0;
  4233. for(; $month <= 12; $month ++) {
  4234. $flag = true;
  4235. foreach ( $isList ['statisticsMonthCid'] as $k => $v ) {
  4236. if ($value ['cid'] == $v ['cid'] && $month == $v ['month']) {
  4237. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  4238. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  4239. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  4240. ';
  4241. $invoicePriceYear += $v ['invoicePrice'];
  4242. $receivablesPriceYear += $v ['receivablesPrice'];
  4243. $accountPriceYear += $v ['accountPrice'];
  4244. $flag = false;
  4245. break;
  4246. }
  4247. }
  4248. if ($flag)
  4249. $html .= '<td class="taR"></td>
  4250. <td class="taR"></td>
  4251. <td class="taR"><b></b></td>
  4252. ';
  4253. }
  4254. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  4255. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  4256. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  4257. ';
  4258. $html .= '</tr>';
  4259. }
  4260. $html .= '<tr><th><b class="colGreen">月合计</b></th>';
  4261. $invoicePriceYear = 0;
  4262. $receivablesPriceYear = 0;
  4263. $accountPriceYear = 0;
  4264. for($month = 1; $month <= 12; $month ++) {
  4265. $flag = true;
  4266. foreach ( $isList ['statisticsMonth'] as $k => $v ) {
  4267. if ($month == $v ['month']) {
  4268. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  4269. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  4270. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  4271. ';
  4272. $invoicePriceYear += $v ['invoicePrice'];
  4273. $receivablesPriceYear += $v ['receivablesPrice'];
  4274. $accountPriceYear += $v ['accountPrice'];
  4275. $flag = false;
  4276. break;
  4277. }
  4278. }
  4279. if ($flag) {
  4280. $html .= '<td class="taR"></td>
  4281. <td class="taR"></td>
  4282. <td class="taR"><b></b></td>
  4283. ';
  4284. }
  4285. }
  4286. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  4287. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  4288. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  4289. ';
  4290. $html .= '</tr>';
  4291. // print_r($isList);
  4292. $this->data ['html'] = $html;
  4293. $this->data ['LcategoryList'] = $LcategoryList;
  4294. $this->data ['isList'] = $isList;
  4295. $this->data ['year'] = $year;
  4296. $this->data ['memu'] = "invoice";
  4297. $this->data ['staff'] = $this->staff;
  4298. $this->data ['receiptMemu'] = 'invoiceAggregate';
  4299. $this->render ( "/admin/invoiceAggregate", $this->data );
  4300. }
  4301. function invoiceAggregateStaff() {
  4302. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  4303. Doo::loadModel ( 'invoiceStatistics' );
  4304. $invoiceStatistics = new invoiceStatistics ();
  4305. Doo::loadModel ( 'L_category' );
  4306. $Lcategory = new L_category ();
  4307. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year );
  4308. $staffList = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year );
  4309. $cStaff = $Lcategory->getCategoryStaff ();
  4310. $html = '';
  4311. foreach ( $cStaff as $key => $value ) {
  4312. $categoryFir = true;
  4313. foreach ( $value ['staff'] as $k => $v ) {
  4314. if ($categoryFir) {
  4315. $width = count ( $value ['staff'] ) + 1;
  4316. $html .= '<tr><th rowspan="' . $width . '">' . $value ['title'] . ' </th>';
  4317. $categoryFir = false;
  4318. } else
  4319. $html .= '<tr>';
  4320. $html .= '<th>' . $v ['username'] . '</th>';
  4321. $invoicePriceStaffYear = 0;
  4322. $receivablesPriceStaffYear = 0;
  4323. $accountPriceStaffYear = 0;
  4324. for($month = 1; $month <= 12; $month ++) {
  4325. $flag = true;
  4326. foreach ( $staffList ['statisticsMonthStaff'] as $sl => $slv ) {
  4327. if ($v ['sid'] == $slv ['staff'] && $month == $slv ['month']) {
  4328. $html .= '<td class="taR">¥' . $slv ['invoicePrice'] . '</td>
  4329. <td class="taR">¥' . $slv ['receivablesPrice'] . '</td>
  4330. <td class="taR"><b>¥' . $slv ['accountPrice'] . '</b></td>
  4331. ';
  4332. $invoicePriceStaffYear += $slv ['invoicePrice'];
  4333. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  4334. $accountPriceStaffYear += $slv ['accountPrice'];
  4335. $flag = false;
  4336. break;
  4337. }
  4338. }
  4339. if ($flag)
  4340. $html .= '<td class="taR"></td>
  4341. <td class="taR"></td>
  4342. <td class="taR"><b></b></td>
  4343. ';
  4344. }
  4345. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  4346. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  4347. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  4348. ';
  4349. }
  4350. $html .= '</tr>';
  4351. // 小计
  4352. if (! empty ( $value ['staff'] )) {
  4353. $html .= '<tr><th class="taR">小计</th>';
  4354. $invoicePriceStaffYear = 0;
  4355. $receivablesPriceStaffYear = 0;
  4356. $accountPriceStaffYear = 0;
  4357. for($month = 1; $month <= 12; $month ++) {
  4358. $flag = true;
  4359. foreach ( $staffList ['statisticsMonthCid'] as $smc => $smcv ) {
  4360. if ($value ['cid'] == $smcv ['cid'] && $month == $slv ['month']) {
  4361. $html .= '<td class="taR">¥' . $smcv ['invoicePrice'] . '</td>
  4362. <td class="taR">¥' . $smcv ['receivablesPrice'] . '</td>
  4363. <td class="taR"><b>¥' . $smcv ['accountPrice'] . '</b></td>
  4364. ';
  4365. $invoicePriceStaffYear += $slv ['invoicePrice'];
  4366. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  4367. $accountPriceStaffYear += $slv ['accountPrice'];
  4368. $flag = false;
  4369. break;
  4370. }
  4371. }
  4372. if ($flag)
  4373. $html .= '<td class="taR"></td>
  4374. <td class="taR"></td>
  4375. <td class="taR"><b></b></td>
  4376. ';
  4377. }
  4378. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  4379. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  4380. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  4381. ';
  4382. $html .= '</tr>';
  4383. }
  4384. }
  4385. $html .= '<tr class="warning"><th colspan="2"><b class="colGreen" >月合计</b></th>';
  4386. $invoicePriceYear = 0;
  4387. $receivablesPriceYear = 0;
  4388. $accountPriceYear = 0;
  4389. for($month = 1; $month <= 12; $month ++) {
  4390. $flag = true;
  4391. foreach ( $staffList ['statisticsMonth'] as $k => $v ) {
  4392. if ($month == $v ['month']) {
  4393. $html .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>
  4394. <td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>
  4395. <td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>
  4396. ';
  4397. $invoicePriceYear += $v ['invoicePrice'];
  4398. $receivablesPriceYear += $v ['receivablesPrice'];
  4399. $accountPriceYear += $v ['accountPrice'];
  4400. $flag = false;
  4401. break;
  4402. }
  4403. }
  4404. if ($flag)
  4405. $html .= '<td class="taR"></td>
  4406. <td class="taR"></td>
  4407. <td class="taR"><b></b></td>
  4408. ';
  4409. }
  4410. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  4411. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  4412. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  4413. ';
  4414. $html .= '</tr>';
  4415. $this->data ['html'] = $html;
  4416. $this->data ['isList'] = $toteList;
  4417. $this->data ['year'] = $year;
  4418. $this->data ['memu'] = "invoice";
  4419. $this->data ['staff'] = $this->staff;
  4420. $this->data ['receiptMemu'] = 'invoiceAggregate';
  4421. $this->render ( "/admin/invoiceAggregateStaff", $this->data );
  4422. }
  4423. function invoiceAggregateCategory() {
  4424. Doo::loadClass ( 'XDeode' );
  4425. $XDeode = new XDeode ( 5 );
  4426. $cid = $cidKey = isset ( $this->params ['cid'] ) ? $this->params ['cid'] : "";
  4427. $cid = $XDeode->decode ( $cid );
  4428. if (! is_numeric ( $cid ))
  4429. die ( 'illegal request' );
  4430. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  4431. Doo::loadModel ( 'invoiceStatistics' );
  4432. $invoiceStatistics = new invoiceStatistics ();
  4433. Doo::loadModel ( 'staff' );
  4434. $staff = new staff ();
  4435. $list = $staff->getStaffByCid ( $cid );
  4436. $isCategory = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year, $cid );
  4437. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year, $cid );
  4438. if (empty ( $list ))
  4439. die ( '该办事处没有成员' );
  4440. $htmlA = $htmlB = $htmlC = $html = '';
  4441. foreach ( $list as $key => $value ) {
  4442. $htmlA = '<tr><th rowspan="3">' . $value ['username'] . '</th><th class="taC">开票</th>';
  4443. $htmlB = '<tr><th class="taC">收款</th>';
  4444. $htmlC = '<tr><th class="taC">入账</th>';
  4445. $invoicePriceStaffYear = 0;
  4446. $receivablesPriceStaffYear = 0;
  4447. $accountPriceStaffYear = 0;
  4448. for($month = 1; $month <= 12; $month ++) {
  4449. $flag = true;
  4450. foreach ( $isCategory ['statisticsMonthStaff'] as $k => $v ) {
  4451. if ($value ['sid'] == $v ['staff'] && $month == $v ['month']) {
  4452. $htmlA .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>';
  4453. $htmlB .= '<td class="taR">¥' . $v ['receivablesPrice'] . '</td>';
  4454. $htmlC .= '<td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>';
  4455. $invoicePriceStaffYear += $v ['invoicePrice'];
  4456. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  4457. $accountPriceStaffYear += $v ['accountPrice'];
  4458. $flag = false;
  4459. break;
  4460. }
  4461. }
  4462. if ($flag) {
  4463. $htmlA .= '<td class="taR">-</td>';
  4464. $htmlB .= '<td class="taR">-</td>';
  4465. $htmlC .= '<td class="taR"><b>-</b></td>';
  4466. }
  4467. }
  4468. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  4469. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  4470. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  4471. $htmlA .= '</tr>';
  4472. $htmlB .= '</tr>';
  4473. $htmlC .= '</tr>';
  4474. $html .= $htmlA . $htmlB . $htmlC;
  4475. }
  4476. $htmlA = $htmlB = $htmlC = "";
  4477. $htmlA = '<tr><th rowspan="3">月合计</th><th class="taC">开票</th>';
  4478. $htmlB = '<tr><th class="taC">收款</th>';
  4479. $htmlC = '<tr><th class="taC">入账</th>';
  4480. $invoicePriceStaffYear = 0;
  4481. $receivablesPriceStaffYear = 0;
  4482. $accountPriceStaffYear = 0;
  4483. for($month = 1; $month <= 12; $month ++) {
  4484. $flag = true;
  4485. foreach ( $isCategory ['statisticsMonth'] as $k => $v ) {
  4486. if ($month == $v ['month']) {
  4487. $htmlA .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>';
  4488. $htmlB .= '<td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>';
  4489. $htmlC .= '<td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>';
  4490. $invoicePriceStaffYear += $v ['invoicePrice'];
  4491. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  4492. $accountPriceStaffYear += $v ['accountPrice'];
  4493. $flag = false;
  4494. break;
  4495. }
  4496. }
  4497. if ($flag) {
  4498. $htmlA .= '<td class="taR">-</td>';
  4499. $htmlB .= '<td class="taR">-</td>';
  4500. $htmlC .= '<td class="taR"><b>-</b></td>';
  4501. }
  4502. }
  4503. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  4504. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  4505. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  4506. $htmlA .= '</tr>';
  4507. $htmlB .= '</tr>';
  4508. $htmlC .= '</tr>';
  4509. $html .= $htmlA . $htmlB . $htmlC;
  4510. $this->data ['html'] = $html;
  4511. $this->data ['cidKey'] = $cidKey;
  4512. $this->data ['slist'] = $list;
  4513. $this->data ['isList'] = $toteList;
  4514. $this->data ['year'] = $year;
  4515. $this->data ['memu'] = "invoice";
  4516. $this->data ['staff'] = $this->staff;
  4517. $this->data ['receiptMemu'] = 'invoiceAggregate';
  4518. $this->render ( "/admin/invoiceAggregateCategory", $this->data );
  4519. }
  4520. /**
  4521. * 办事处汇总信息
  4522. */
  4523. function invoiceAggregateCategoryDetail() {
  4524. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  4525. Doo::loadClass ( 'XDeode' );
  4526. $XDeode = new XDeode ( 5 );
  4527. Doo::loadModel ( 'invoiceStatistics' );
  4528. $invoiceStatistics = new invoiceStatistics ();
  4529. Doo::loadModel ( 'L_category' );
  4530. $category = new L_category ();
  4531. Doo::loadModel ( 'invoice' );
  4532. $invoice = new invoice ();
  4533. Doo::loadModel ( 'staff' );
  4534. $staff = new staff ();
  4535. Doo::loadModel ( "invoiceCategoryManage" );
  4536. $invoiceCategoryManage = new invoiceCategoryManage ();
  4537. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4538. $cidList = array ();
  4539. foreach ( $imcStaff as $key => $value ) {
  4540. array_push ( $cidList, $value ['cid'] );
  4541. if (empty ( $cidKey ))
  4542. $cidKey = $XDeode->encode ( $value ['cid'] );
  4543. }
  4544. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  4545. $cid = $XDeode->decode ( $cidKey );
  4546. $month = date ( "m", strtotime ( "-1 month" ) );
  4547. $YearMonth = date ( "Y-m", strtotime ( "-1 month" ) );
  4548. $redis = new Redis ();
  4549. $redis->connect ( '127.0.0.1', '6379' );
  4550. $redisKey = ''; // date('Y-m-d').'_iacd_'.$cid;
  4551. $redisValue = ''; // $redis->lrange($redisKey, 0, -1);
  4552. if (empty ( $redisValue )) {
  4553. $isMC = $invoiceStatistics->getInvoiceStatistiscsMothByCategory ( $cid );
  4554. $schedule = $invoice->getInvoiceScheduleByCid ( $cid );
  4555. // 获得办事处人员下的汇总
  4556. $slist = $staff->getStaffByCid ( $cid );
  4557. $ismsbMonth = $invoiceStatistics->getISMSByCategoryByMonth ( $cid, $YearMonth ); // 上一个月的汇总
  4558. $ismsb = $invoiceStatistics->getISMSByCategory ( $cid ); // 当月汇总
  4559. $ISAS = $invoiceStatistics->getISASByCategory ( $cid ); // 全部汇总
  4560. $scheduleStaff = $invoice->getInvoiceScheduleByCidGroupSid ( $cid ); // 完成度
  4561. foreach ( $slist as $key => $value ) {
  4562. $slist [$key] ['invoicePrice'] = 0;
  4563. $slist [$key] ['receivablesPrice'] = 0;
  4564. $slist [$key] ['accountPrice'] = 0;
  4565. $slist [$key] ['invoiceAllPrice'] = 0;
  4566. $slist [$key] ['receivablesAllPrice'] = 0;
  4567. $slist [$key] ['accountAllPrice'] = 0;
  4568. $slist [$key] ['schedule'] = 0;
  4569. $slist [$key] ['invoiceMonthPrice'] = 0;
  4570. $slist [$key] ['receivablesMonthPrice'] = 0;
  4571. $slist [$key] ['accountMonthPrice'] = 0;
  4572. foreach ( $ismsbMonth as $y => $l ) {
  4573. if ($value ['sid'] == $l ['staff']) {
  4574. $slist [$key] ['invoiceMonthPrice'] = $l ['invoicePrice'];
  4575. $slist [$key] ['receivablesMonthPrice'] = $l ['receivablesPrice'];
  4576. $slist [$key] ['accountMonthPrice'] = $l ['accountPrice'];
  4577. }
  4578. }
  4579. foreach ( $ismsb as $k => $v ) {
  4580. if ($value ['sid'] == $v ['staff']) {
  4581. $slist [$key] ['invoicePrice'] = $v ['invoicePrice'];
  4582. $slist [$key] ['receivablesPrice'] = $v ['receivablesPrice'];
  4583. $slist [$key] ['accountPrice'] = $v ['accountPrice'];
  4584. }
  4585. }
  4586. foreach ( $ISAS as $e => $a ) {
  4587. if ($value ['sid'] == $a ['staff']) {
  4588. $slist [$key] ['invoiceAllPrice'] = $a ['invoicePrice'];
  4589. $slist [$key] ['receivablesAllPrice'] = $a ['receivablesPrice'];
  4590. $slist [$key] ['accountAllPrice'] = $a ['accountPrice'];
  4591. }
  4592. }
  4593. if (isset ( $scheduleStaff [$value ['sid']] ))
  4594. $slist [$key] ['schedule'] = $scheduleStaff [$value ['sid']];
  4595. }
  4596. $this->data ['cidKey'] = $cidKey;
  4597. $schedule = ( int ) ($schedule * 100);
  4598. $this->data ['slist'] = $slist;
  4599. $this->data ['isMC'] = $isMC;
  4600. $this->data ['schedule'] = $schedule;
  4601. $slist = json_encode ( $slist );
  4602. $isMC = json_encode ( $isMC );
  4603. $schedule = json_encode ( $schedule );
  4604. $redis->lpush ( $redisKey, $slist );
  4605. $redis->lpush ( $redisKey, $isMC );
  4606. $redis->lpush ( $redisKey, $schedule );
  4607. } else {
  4608. $this->data ['cidKey'] = $cidKey;
  4609. $this->data ['slist'] = json_decode ( $redisValue [2], true );
  4610. $this->data ['isMC'] = json_decode ( $redisValue [1], true );
  4611. $this->data ['schedule'] = json_decode ( $redisValue [0], true );
  4612. }
  4613. $this->data ['month'] = $month;
  4614. $this->data ['categoryList'] = $categoryList;
  4615. $this->data ['memu'] = "invoice";
  4616. $this->data ['staff'] = $this->staff;
  4617. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4618. $this->render ( "/admin/invoiceAggregateCategoryDetail", $this->data );
  4619. }
  4620. /**
  4621. * 办事处人员汇总详情
  4622. */
  4623. function invoiceAggregateStaffDetail() {
  4624. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  4625. // $sidKey = isset ( $this->params ['sidKey'] ) ? $this->params ['sidKey'] : '';
  4626. Doo::loadClass ( 'XDeode' );
  4627. $XDeode = new XDeode ( 5 );
  4628. Doo::loadModel ( 'invoice' );
  4629. $invoice = new invoice ();
  4630. Doo::loadModel ( 'staff' );
  4631. $staff = new staff ();
  4632. Doo::loadModel ( "invoiceCategoryManage" );
  4633. $invoiceCategoryManage = new invoiceCategoryManage ();
  4634. $sid = $XDeode->decode ( $sidKey );
  4635. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4636. $cidList = array ();
  4637. foreach ( $imcStaff as $key => $value ) {
  4638. array_push ( $cidList, $value ['cid'] );
  4639. if (empty ( $cidKey ))
  4640. $cidKey = $XDeode->encode ( $value ['cid'] );
  4641. }
  4642. $cidString = implode ( ',', $cidList );
  4643. $staffList = $staff->getStaffInCid ( $cidString );
  4644. $staffDetail = $staff->getStaffBySid ( $sid );
  4645. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4646. $page_size = 18;
  4647. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4648. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4649. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  4650. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  4651. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  4652. $dateArr = explode ( ':', $date );
  4653. $D1 = '';
  4654. $D2 = '';
  4655. if (! empty ( $date )) {
  4656. $D1 = $dateArr [0] . " 00:00:00 ";
  4657. if (isset ( $dateArr [1] ))
  4658. $D2 = $dateArr [1] . " 23:59:59 ";
  4659. else
  4660. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4661. // $D2 = $dateArr [1];
  4662. }
  4663. $con = ' status=2 ';
  4664. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4665. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4666. if ($status == 'UNRECORD')
  4667. $con .= ' and printStatus=1 and untreadStatus=0';
  4668. elseif ($status == 'RECORD')
  4669. $con .= ' and printStatus=1 and untreadStatus=3';
  4670. elseif ($status == 'BOUNCED')
  4671. $con .= ' and untreadStatus=2';
  4672. elseif ($status == 'PARTRECORD')
  4673. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  4674. elseif ($status == 'All') {
  4675. $con .= ' and ( untreadStatus=2 or untreadStatus=0 or untreadStatus=3 )';
  4676. }
  4677. $con .= ' and sid=' . $sid;
  4678. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  4679. if (! empty ( $MebSea )) {
  4680. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  4681. }
  4682. $pageinfo ['page'] = array (
  4683. 'previous' => ''
  4684. );
  4685. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateStaffDetail", $get, "" );
  4686. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4687. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  4688. $this->data ['staffDetail'] = $staffDetail;
  4689. $this->data ['staffList'] = $staffList;
  4690. $this->data ['MebSeaEn'] = $MebSea;
  4691. $this->data ['MebSea'] = urlencode ( $MebSea );
  4692. $this->data ['date'] = $date;
  4693. $this->data ['page'] = $pageinfo;
  4694. $this->data ['get'] = $get;
  4695. $this->data ['list'] = $list;
  4696. $this->data ['status'] = $status;
  4697. $this->data ['sidKey'] = $sidKey;
  4698. $this->data ['memu'] = "invoice";
  4699. $this->data ['staff'] = $this->staff;
  4700. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4701. $this->render ( "/admin/invoiceAggregateStaffDetail", $this->data );
  4702. }
  4703. /**
  4704. * 办事处人员汇总收款情
  4705. */
  4706. function invoiceAggregateStaffReceivablesDetail() {
  4707. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  4708. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  4709. Doo::loadModel ( 'invoiceReceivables' );
  4710. $invoiceReceivables = new invoiceReceivables ();
  4711. Doo::loadModel ( 'staff' );
  4712. $staff = new staff ();
  4713. Doo::loadModel ( "invoiceCategoryManage" );
  4714. $invoiceCategoryManage = new invoiceCategoryManage ();
  4715. Doo::loadClass ( 'XDeode' );
  4716. $XDeode = new XDeode ( 5 );
  4717. $sid = $XDeode->decode ( $sidKey );
  4718. $staffDetail = $staff->getStaffBySid ( $sid );
  4719. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4720. $cidList = array ();
  4721. foreach ( $imcStaff as $key => $value ) {
  4722. array_push ( $cidList, $value ['cid'] );
  4723. if (empty ( $cidKey ))
  4724. $cidKey = $XDeode->encode ( $value ['cid'] );
  4725. }
  4726. $cidString = implode ( ',', $cidList );
  4727. $staffList = $staff->getStaffInCid ( $cidString );
  4728. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4729. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  4730. $page_size = 10;
  4731. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4732. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4733. if ($timeType == "BINDOTP") {
  4734. $status = 'Credited';
  4735. }
  4736. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  4737. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  4738. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  4739. $dateArr = explode ( ':', $date );
  4740. $D1 = '';
  4741. $D2 = '';
  4742. if (! empty ( $date )) {
  4743. $D1 = $dateArr [0] . " 00:00:00 ";
  4744. if (isset ( $dateArr [1] ))
  4745. $D2 = $dateArr [1] . " 23:59:59 ";
  4746. else
  4747. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4748. }
  4749. $con = ' a.receivablesStaff like "%' . $staffDetail ['username'] . '%" ';
  4750. $descField = 'a.bindDate';
  4751. if ($timeType == 'CREATE')
  4752. $descField = 'a.date';
  4753. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4754. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4755. elseif (! empty ( $D1 ) && empty ( $D2 ))
  4756. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  4757. if ($status == 'Unclaimed')
  4758. $con .= ' and a.bindStatus=0';
  4759. elseif ($status == 'Credited')
  4760. $con .= ' and a.bindStatus=1';
  4761. elseif ($status == 'Claim')
  4762. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  4763. elseif ($status == 'BBN')
  4764. $con .= ' and a.bindPrice>a.receivablesPrice';
  4765. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  4766. if (! empty ( $MebSea )) {
  4767. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" )';
  4768. }
  4769. $pageinfo ['page'] = array (
  4770. 'previous' => ''
  4771. );
  4772. // $sql = 'select group_concat(b.invoiceSerial) as invoiceSerial ,group_concat(b.iid) as invoiceId
  4773. // from CLD_invoiceReceivables as a left join CLD_invoice as b on
  4774. // find_in_set(b.iid,a.iidExtend) or a.iid=b.iid
  4775. // where ' . $con . ' group by a.irid ';
  4776. $pageinfo =$this->get_page ( "CLD_invoiceReceivables as a", $con, $page, $page_size, "invoiceAggregateStaffReceivablesDetail", $get, "" );
  4777. //$pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceAggregateStaffReceivablesDetail", $get, "" );
  4778. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4779. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', $descField);
  4780. foreach ( $list as $key => $value ) {
  4781. $list [$key] ['category'] = '';
  4782. if ($value ['receivablesCategory'] != 'PUBLIC') {
  4783. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  4784. $list [$key] ['category'] = $receivablesCategory [1];
  4785. }
  4786. }
  4787. // print_r($list);
  4788. $this->data ['staffDetail'] = $staffDetail;
  4789. $this->data ['sidKey'] = $sidKey;
  4790. $this->data ['staffList'] = $staffList;
  4791. $this->data ['timeType'] = $timeType;
  4792. $this->data ['MebSeaEn'] = $MebSea;
  4793. $this->data ['MebSea'] = urlencode ( $MebSea );
  4794. $this->data ['date'] = $date;
  4795. $this->data ['page'] = $pageinfo;
  4796. $this->data ['get'] = $get;
  4797. $this->data ['list'] = $list;
  4798. $this->data ['status'] = $status;
  4799. $this->data ['memu'] = "invoice";
  4800. $this->data ['staff'] = $this->staff;
  4801. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4802. $this->render ( "/admin/invoiceAggregateStaffReceivablesDetail", $this->data );
  4803. }
  4804. function invoiceAchieve() {
  4805. Doo::loadModel ( 'invoice' );
  4806. $invoice = new invoice ();
  4807. Doo::loadClass ( 'XDeode' );
  4808. $XDeode = new XDeode ( 5 );
  4809. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4810. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4811. $page_size = 18;
  4812. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4813. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4814. $get = "/" . $date;
  4815. $con = '';
  4816. if ($date == 'MONTHO')
  4817. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4818. elseif ($date == 'MONTHT')
  4819. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4820. elseif ($date == 'MONTHY')
  4821. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4822. if (! empty ( $MebSea )) {
  4823. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4824. $get .= "/" . $MebSea;
  4825. }
  4826. $pageinfo ['page'] = array (
  4827. 'previous' => ''
  4828. );
  4829. $sql = 'status=2 and printStatus=1 and irid!="" and ( untreadStatus=3 or untreadStatus=0 ) and sid=' . $sid . $con;
  4830. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceAchieve", $get, "" );
  4831. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4832. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  4833. // print_r($pageinfo);
  4834. $this->data ['MebSeaEn'] = $MebSea;
  4835. $this->data ['MebSea'] = urlencode ( $MebSea );
  4836. $this->data ['get'] = $get;
  4837. $this->data ['page'] = $pageinfo;
  4838. $this->data ['list'] = $list;
  4839. $this->data ['date'] = $date;
  4840. $this->data ['memu'] = "invoice";
  4841. $this->data ['staff'] = $this->staff;
  4842. $this->data ['receiptMemu'] = 'invoice';
  4843. $this->render ( "/admin/invoiceAchieve", $this->data );
  4844. }
  4845. /**
  4846. */
  4847. function invoiceMyUnAccountAchieve() {
  4848. Doo::loadModel ( 'invoice' );
  4849. $invoice = new invoice ();
  4850. Doo::loadClass ( 'XDeode' );
  4851. $XDeode = new XDeode ( 5 );
  4852. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4853. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4854. $page_size = 18;
  4855. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4856. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4857. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4858. $dateArr = explode ( ':', $date );
  4859. $D1 = '';
  4860. $D2 = '';
  4861. if (! empty ( $date )) {
  4862. $D1 = $dateArr [0];
  4863. $D2 = $dateArr [1];
  4864. }
  4865. $con = '';
  4866. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4867. $con = ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4868. if (! empty ( $MebSea )) {
  4869. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4870. }
  4871. $pageinfo ['page'] = array (
  4872. 'previous' => ''
  4873. );
  4874. // and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  4875. $sql = " status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid= " . $sid . $con;
  4876. $action = "invoiceMyUnAccountAchieve";
  4877. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  4878. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4879. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 'desc', 'printTime' );
  4880. Doo::loadModel ( 'express' );
  4881. $express = new express ();
  4882. $expressList = $express->getExpressByAll ();
  4883. $this->data ['expressList'] = $expressList;
  4884. // print_r($list);
  4885. $this->data ['MebSeaEn'] = $MebSea;
  4886. $this->data ['get'] = $get;
  4887. $this->data ['page'] = $pageinfo;
  4888. $this->data ['date'] = $date;
  4889. $this->data ['list'] = $list;
  4890. $this->data ['memu'] = "invoice";
  4891. $this->data ['staff'] = $this->staff;
  4892. $this->data ['receiptMemu'] = 'invoice';
  4893. $this->render ( "/admin/invoiceMyUnAccountAchieve", $this->data );
  4894. }
  4895. function invoiceReceivablesAchieve() {
  4896. Doo::loadModel ( 'invoiceReceivables' );
  4897. $invoiceReceivables = new invoiceReceivables ();
  4898. Doo::loadClass ( 'XDeode' );
  4899. $XDeode = new XDeode ( 5 );
  4900. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4901. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  4902. $page_size = 12;
  4903. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4904. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4905. $get = "/" . $date;
  4906. $con = '';
  4907. if ($date == 'MONTHO')
  4908. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4909. elseif ($date == 'MONTHT')
  4910. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4911. elseif ($date == 'MONTHY')
  4912. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4913. if (! empty ( $MebSea )) {
  4914. $con .= ' and ( receivablesMessage like "%' . $MebSea . '%" or receivablesPrice like "%' . $MebSea . '%" )';
  4915. $get .= "/" . $MebSea;
  4916. }
  4917. $pageinfo ['page'] = array (
  4918. 'previous' => ''
  4919. );
  4920. $sql = " bindStatus=1 and receivablesStaff like '" . $sid . "-%' " . $con;
  4921. $pageinfo = $this->get_page ( "CLD_invoiceReceivables", $sql, $page, $page_size, "invoiceReceivablesAchieve", $get, "" );
  4922. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4923. $list = $invoiceReceivables->getReceivablesByUntreadStatusPage ( $limit, $sql );
  4924. // print_r($pageinfo);
  4925. $this->data ['MebSeaEn'] = $MebSea;
  4926. $this->data ['MebSea'] = urlencode ( $MebSea );
  4927. $this->data ['get'] = $get;
  4928. $this->data ['page'] = $pageinfo;
  4929. $this->data ['list'] = $list;
  4930. $this->data ['date'] = $date;
  4931. $this->data ['memu'] = "invoice";
  4932. $this->data ['staff'] = $this->staff;
  4933. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  4934. $this->render ( "/admin/invoiceReceivablesAchieve", $this->data );
  4935. }
  4936. /**
  4937. * 收款解绑
  4938. */
  4939. function invoiceUnBundLing() {
  4940. $unBundKey = $this->get_args ( 'unBundKey' ) ? $this->get_args ( 'unBundKey' ) : '';
  4941. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  4942. Doo::loadModel ( 'invoice' );
  4943. $invoice = new invoice ();
  4944. Doo::loadModel ( 'invoiceReceivables' );
  4945. $invoiceReceivables = new invoiceReceivables ();
  4946. Doo::loadModel ( 'invoiceOperationLog' );
  4947. $invoiceOperationLog = new invoiceOperationLog ();
  4948. Doo::loadModel ( 'invoiceROLog' );
  4949. $invoiceROLog = new invoiceROLog ();
  4950. Doo::loadModel ( 'invoiceStatistics' );
  4951. Doo::loadClass ( 'XDeode' );
  4952. $XDeode = new XDeode ( 5 );
  4953. if (empty ( $iidKey ) || empty ( $unBundKey ))
  4954. die ( 'illegal request' );
  4955. $iid = $XDeode->decode ( $iidKey );
  4956. $irid = $invoice->authcode ( $unBundKey );
  4957. if ((! empty ( $irid ) && ! is_numeric ( $irid )) || (! empty ( $iid ) && ! is_numeric ( $iid )))
  4958. die ( 'illegal request' );
  4959. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4960. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  4961. if (empty ( $irDetails ) || empty ( $invoiceDetails ) || (empty ( $irDetails ['iid'] ) && empty ( $irDetails ['iidExtend'] )) || $invoiceDetails ['untreadStatus'] == 2)
  4962. die ( 'illegal request' );
  4963. // 收款
  4964. $item = array (
  4965. 'irid' => $irDetails ['irid'],
  4966. 'bindPrice' => $irDetails ['bindPrice'] - $invoiceDetails ['invoicePrice'],
  4967. 'bindStatus' => 0
  4968. );
  4969. if ($irDetails ['iid'] == $iid)
  4970. $item += array (
  4971. 'iid' => 0
  4972. );
  4973. else {
  4974. $iidExtend = explode ( ',', $irDetails ['iidExtend'] );
  4975. foreach ( $iidExtend as $key => $value ) {
  4976. if ($value == $iid)
  4977. unset ( $iidExtend [$key] );
  4978. }
  4979. $iidExtend = implode ( ',', $iidExtend );
  4980. $item += array (
  4981. 'iidExtend' => $iidExtend
  4982. );
  4983. }
  4984. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4985. // 收款操作日志
  4986. $item = array (
  4987. 'operation' => $this->staff [0] ['username'] . " 解绑 " . $irDetails ['receivablesSerial'],
  4988. 'date' => date ( "Y-m-d" ),
  4989. 'status' => 3,
  4990. 'img' => $this->staff [0] ['avatar'],
  4991. 'username' => $this->staff [0] ['username'],
  4992. 'uid' => $this->staff [0] ['sid'],
  4993. 'category' => $this->staff [0] ['category'],
  4994. 'irid' => $irid
  4995. );
  4996. $invoiceROLog->setInvoiceROLog ( $item );
  4997. // 扣除入账统计金额
  4998. $invoiceStatistics = new invoiceStatistics ();
  4999. $item = array (
  5000. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  5001. 'priceClass' => 3,
  5002. 'cid' => $invoiceDetails ['cid'],
  5003. 'staff' => $invoiceDetails ['sid'],
  5004. 'accountPrice' => - $invoiceDetails ['invoicePrice']
  5005. );
  5006. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  5007. // 扣除收款统计金额
  5008. $invoiceStatistics = new invoiceStatistics ();
  5009. $item = array (
  5010. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  5011. 'priceClass' => 2,
  5012. 'cid' => $invoiceDetails ['cid'],
  5013. 'staff' => $invoiceDetails ['sid'],
  5014. 'irid' => $irDetails ['irid'],
  5015. 'receivablesPrice' => - $invoiceDetails ['invoicePrice']
  5016. );
  5017. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  5018. // 发票解绑去收款ID
  5019. $iridString = $invoiceDetails ['irid'];
  5020. if (! empty ( $invoiceDetails ['irid'] )) {
  5021. $list = explode ( ',', $invoiceDetails ['irid'] );
  5022. foreach ( $list as $key => $value ) {
  5023. if ($value == $irDetails ['irid']) {
  5024. unset ( $list [$key] );
  5025. break;
  5026. }
  5027. }
  5028. $iridString = implode ( ",", $list );
  5029. }
  5030. //解绑后余额 加回去
  5031. $invoiceBalance=$invoiceDetails['invoiceBalance']+$irDetails['receivablesPrice'];
  5032. if ($invoiceBalance<0){
  5033. $invoiceBalance=0;
  5034. }
  5035. if($invoiceBalance>$invoiceDetails['invoicePrice']){
  5036. $invoiceBalance=$invoiceDetails['invoicePrice'];
  5037. }
  5038. $item = array (
  5039. 'iid' => $invoiceDetails ['iid'],
  5040. 'irid' => $iridString,
  5041. 'invoiceBalance'=>$invoiceBalance,
  5042. 'updateTime' => date ( "Y-m-d H:i:s" )
  5043. );
  5044. if ($invoiceDetails ['untreadStatus'] == 3)
  5045. $item += array (
  5046. 'untreadStatus' => 0
  5047. );
  5048. $invoice->setInvoiceByCondition ( $item );
  5049. Doo::loadModel ( 'bill' );
  5050. $bill = new bill ();
  5051. $bill->iid=$invoiceDetails ['iid'];
  5052. $bill->trainId=$invoiceDetails['trainId'];
  5053. $bill->irid=$irDetails ['irid'];
  5054. $bill->create_time=date ( "Y-m-d H:i:s" );
  5055. $bill->price=-$invoiceDetails ['invoicePrice'];
  5056. $bill->remark='解绑-扣除入账';
  5057. $bill->insert ();
  5058. $item = array (
  5059. 'date' => date ( "Y-m-d H:i:s" ),
  5060. 'operation' => '解绑 收款 ' . $irDetails ['receivablesSerial'],
  5061. 'status' => 11,
  5062. 'img' => $this->staff [0] ['avatar'],
  5063. 'username' => $this->staff [0] ['username'],
  5064. 'uid' => $this->staff [0] ['sid'],
  5065. 'category' => $this->staff [0] ['category'],
  5066. 'iid' => $invoiceDetails ['iid']
  5067. );
  5068. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  5069. // 公司流水-解绑时删除流水
  5070. // Doo::loadModel ( 'wasteBook' );
  5071. // $wasteBook = new wasteBook ();
  5072. // $wasteBook->delete ( array (
  5073. // 'where' => 'dataID=' . $irDetails ['irid'] . ' and accountType=7',
  5074. // 'limit' => 1
  5075. // ) );
  5076. // 银行
  5077. /*
  5078. * $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); }
  5079. */
  5080. return "/invoiceReceivablesAS";
  5081. }
  5082. /**
  5083. * 或者该收款下的所以发票
  5084. */
  5085. function ajaxGetInvoiceReceivablesByInvoice() {
  5086. $irid = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : '';
  5087. Doo::loadModel ( 'invoice' );
  5088. $invoice = new invoice ();
  5089. Doo::loadModel ( 'invoiceReceivables' );
  5090. $invoiceReceivables = new invoiceReceivables ();
  5091. $irid = $invoice->authcode ( $irid );
  5092. if (! empty ( $irid ) && ! is_numeric ( $irid ))
  5093. die ( 'illegal request' );
  5094. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5095. $iidString = $irDetails ['iid'];
  5096. $iidExtend = array_filter ( explode ( ',', $irDetails ['iidExtend'] ) );
  5097. if (! empty ( $irDetails ['iidExtend'] ))
  5098. $iidString .= ',' . implode ( ',', $iidExtend );
  5099. $invoiceList = $invoice->getInvoiceInIid ( $iidString, 'iid,invoiceSerial,invoicePrice,invoiceTitle,invoiceCompany,invoiceElement' );
  5100. $html = "";
  5101. foreach ( $invoiceList as $key => $value ) {
  5102. $title = $value ['invoiceTitle'];
  5103. if (! empty ( $value ['invoiceCompany'] ))
  5104. $title = $value ['invoiceCompany'];
  5105. $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>';
  5106. }
  5107. echo json_encode ( array (
  5108. 'status' => 1,
  5109. 'html' => $html
  5110. ) );
  5111. }
  5112. /**
  5113. * 发票管理
  5114. */
  5115. function invoiceAS() {
  5116. Doo::loadModel ( 'invoice' );
  5117. $invoice = new invoice ();
  5118. Doo::loadModel ( 'invoiceReceivables' );
  5119. $invoiceReceivables = new invoiceReceivables ();
  5120. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  5121. $page_size = 18;
  5122. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5123. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  5124. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5125. $dateArr = explode ( ':', $date );
  5126. $D1 = '';
  5127. $D2 = '';
  5128. if (! empty ( $date )) {
  5129. $D1 = $dateArr [0] . " 00:00:00 ";
  5130. if (isset ( $dateArr [1] ))
  5131. $D2 = $dateArr [1] . " 23:59:59 ";
  5132. else
  5133. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  5134. // $D2 = $dateArr [1];
  5135. }
  5136. $con = ' status=2 ';
  5137. if (! empty ( $D1 ) && ! empty ( $D2 ))
  5138. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  5139. if ($status == 'UNRECORD')
  5140. $con .= ' and printStatus=1 and untreadStatus=0';
  5141. elseif ($status == 'RECORD')
  5142. $con .= ' and printStatus=1 and untreadStatus=3';
  5143. elseif ($status == 'BOUNCED')
  5144. $con .= ' and untreadStatus=2';
  5145. elseif ($status == 'PARTRECORD')
  5146. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  5147. elseif ($status == 'All') {
  5148. $con .= ' and ( untreadStatus=2 or untreadStatus=1 or untreadStatus=0 or untreadStatus=3 )';
  5149. }
  5150. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  5151. if (! empty ( $MebSea )) {
  5152. $con .= ' and ( invoiceSerial like "%' . $MebSea . '%" or invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  5153. }
  5154. $pageinfo ['page'] = array (
  5155. 'previous' => ''
  5156. );
  5157. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAS", $get, "" );
  5158. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5159. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  5160. $this->data ['MebSeaEn'] = $MebSea;
  5161. $this->data ['MebSea'] = urlencode ( $MebSea );
  5162. $this->data ['date'] = $date;
  5163. $this->data ['page'] = $pageinfo;
  5164. $this->data ['get'] = $get;
  5165. $this->data ['list'] = $list;
  5166. $this->data ['status'] = $status;
  5167. $this->data ['memu'] = "invoice";
  5168. $this->data ['staff'] = $this->staff;
  5169. $this->data ['receiptMemu'] = 'invoiceReceivables';
  5170. $this->render ( "/admin/invoiceAS", $this->data );
  5171. }
  5172. /**
  5173. * 收款管理
  5174. */
  5175. function invoiceReceivablesAS() {
  5176. Doo::loadModel ( 'invoiceReceivables' );
  5177. $invoiceReceivables = new invoiceReceivables ();
  5178. Doo::loadModel ( 'L_category' );
  5179. $lCategory = new L_category ();
  5180. $category = $lCategory->getCategory ();
  5181. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  5182. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  5183. $page_size = 10;
  5184. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5185. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  5186. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5187. $dateArr = explode ( ':', $date );
  5188. $D1 = '';
  5189. $D2 = '';
  5190. if (! empty ( $date )) {
  5191. $D1 = $dateArr [0]; // ." 00:00:00 ";
  5192. if (isset ( $dateArr [1] ))
  5193. $D2 = $dateArr [1]; // ." 23:59:59 ";
  5194. else
  5195. $D2 = $dateArr [0]; // ." 23:59:59 ";//date ( "Y-m-d" );
  5196. }
  5197. $descField = 'a.receivablesDate';
  5198. if ($timeType == 'CREATE')
  5199. $descField = 'a.date';
  5200. $con = ' 1 ';
  5201. if (! empty ( $D1 ) && ! empty ( $D2 ))
  5202. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  5203. elseif (! empty ( $D1 ) && empty ( $D2 ))
  5204. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  5205. if ($status == 'Unclaimed')
  5206. $con .= ' and a.bindStatus=0';
  5207. elseif ($status == 'Credited')
  5208. $con .= ' and a.bindStatus=1';
  5209. elseif ($status == 'Claim')
  5210. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  5211. elseif ($status == 'BBN')
  5212. $con .= ' and a.bankBatchNumber!=""';
  5213. elseif ($status == 'REFUND')
  5214. $con .= ' and ( (a.bindStatus=0 and a.refundLog!="" ) or a.bindStatus=2)';
  5215. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  5216. if (! empty ( $MebSea )) {
  5217. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" or a.receivablesSerial like "%' . $MebSea . '%" )';
  5218. }
  5219. $pageinfo ['page'] = array (
  5220. 'previous' => ''
  5221. );
  5222. // if(!empty($con)){
  5223. // $con=' where 1 '.$con;
  5224. // }
  5225. // $sql = 'select a.iid from CLD_invoiceReceivables as a
  5226. // ' . $con ;
  5227. $pageinfo =$this->get_page ( "CLD_invoiceReceivables as a", $con, $page, $page_size, "invoiceReceivablesAS", $get, "" );
  5228. //echo $sql;
  5229. //$pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceReceivablesAS", $get, "" );
  5230. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5231. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', $descField );
  5232. foreach ( $list as $key => $value ) {
  5233. $list [$key] ['category'] = '';
  5234. if ($value ['receivablesCategory'] != 'PUBLIC') {
  5235. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  5236. $list [$key] ['category'] = $receivablesCategory [1];
  5237. }
  5238. }
  5239. // print_r($list);
  5240. $this->data ['category'] = $category;
  5241. $this->data ['timeType'] = $timeType;
  5242. $this->data ['MebSeaEn'] = $MebSea;
  5243. $this->data ['MebSea'] = urlencode ( $MebSea );
  5244. $this->data ['date'] = $date;
  5245. $this->data ['page'] = $pageinfo;
  5246. $this->data ['get'] = $get;
  5247. $this->data ['list'] = $list;
  5248. $this->data ['status'] = $status;
  5249. $this->data ['memu'] = "invoice";
  5250. $this->data ['staff'] = $this->staff;
  5251. $this->data ['receiptMemu'] = 'invoiceReceivables';
  5252. $this->render ( "/admin/invoiceReceivablesAS", $this->data );
  5253. }
  5254. /**
  5255. * 删除一条收款
  5256. */
  5257. function delInvoiceReceivables() {
  5258. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  5259. if (empty ( $iridKey ))
  5260. die ( 'illegal request' );
  5261. Doo::loadClass ( 'XDeode' );
  5262. $XDeode = new XDeode ( 5 );
  5263. $irid = $XDeode->decode ( $iridKey );
  5264. Doo::loadModel ( 'invoiceReceivables' );
  5265. $invoiceReceivables = new invoiceReceivables ();
  5266. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5267. if (empty ( $detail ))
  5268. die ( 'illegal request' );
  5269. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  5270. // 扣除收款汇总信息 汇总
  5271. Doo::loadModel ( 'invoiceStatistics' );
  5272. $invoiceStatistics = new invoiceStatistics ();
  5273. $item = array (
  5274. 'date' => $detail ['receivablesDate'],
  5275. 'priceClass' => 2,
  5276. 'irid' => $detail ['irid'],
  5277. 'receivablesPrice' => - $detail ['receivablesPrice']
  5278. );
  5279. if ($detail ['receivablesCategory'] != 'PUBLIC') {
  5280. $receivablesCategory = explode ( ":", $detail ['receivablesCategory'] );
  5281. $item += array (
  5282. 'cid' => $receivablesCategory [0]
  5283. );
  5284. }
  5285. if ($detail ['receivablesStaff'] != 'PUBLIC') {
  5286. $receivablesStaff = explode ( "-", $detail ['receivablesStaff'] );
  5287. $item += array (
  5288. 'staff' => $receivablesStaff [0]
  5289. );
  5290. }
  5291. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  5292. return '/invoiceReceivablesAS';
  5293. }
  5294. /**
  5295. * 添加退款信息
  5296. */
  5297. function setInvoiceReceivablesRefund() {
  5298. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5299. $refundType = $this->get_args ( 'refundType' ) && is_numeric ( $this->get_args ( 'refundType' ) ) ? $this->get_args ( 'refundType' ) : '0';
  5300. $refundCompany = $this->get_args ( 'refundCompany' ) ? $this->get_args ( 'refundCompany' ) : "";
  5301. $refundNumber = $this->get_args ( 'refundNumber' ) ? $this->get_args ( 'refundNumber' ) : "";
  5302. $refundPrice = $this->get_args ( 'refundPrice' ) ? $this->get_args ( 'refundPrice' ) : "";
  5303. $refundRemarks = $this->get_args ( 'refundRemarks' ) ? $this->get_args ( 'refundRemarks' ) : "";
  5304. if ($refundPrice < 0)
  5305. die ( 'illegal request' );
  5306. if (! empty ( $iridKey ) && ! empty ( $refundCompany ) && ! empty ( $refundNumber ) && ! empty ( $refundPrice )) {
  5307. Doo::loadModel ( 'invoiceReceivables' );
  5308. $invoiceReceivables = new invoiceReceivables ();
  5309. Doo::loadModel ( 'invoiceRefund' );
  5310. $invoiceRefund = new invoiceRefund ();
  5311. $irid = $invoiceReceivables->authcode ( $iridKey );
  5312. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5313. if ($irDetail ['receivablesPrice'] < $refundPrice)
  5314. die ( 'illegal request' );
  5315. $invoiceReceivables = new invoiceReceivables ();
  5316. $refundLog = $this->staff [0] ['username'] . ' 退款 <b class="colRed">¥' . $refundPrice . '</b>
  5317. <br/><a href="#refunded" onclick="getRefundByDetail(\'' . $iridKey . '\')" data-toggle="modal">退款信息</a> <br/>' . date ( "Y-m-d H:i:s" ) . '
  5318. ';
  5319. $item = array (
  5320. 'irid' => $irid,
  5321. 'refundCompany' => $refundCompany,
  5322. 'refundNumber' => $refundNumber,
  5323. 'refundPrice' => $refundPrice,
  5324. 'refundRemarks' => $refundRemarks,
  5325. 'refundLog' => $refundLog
  5326. );
  5327. if ($refundType == 1) {
  5328. $item += array (
  5329. 'refundType' => $refundType,
  5330. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice,
  5331. 'bindStatus' => 2
  5332. );
  5333. } elseif ($refundType == 0 && $irDetail ['receivablesPrice'] <= $refundPrice) {
  5334. $item += array (
  5335. 'refundType' => 1,
  5336. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice,
  5337. 'bindStatus' => 2
  5338. );
  5339. } else {
  5340. $item += array (
  5341. 'refundType' => $refundType,
  5342. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice
  5343. );
  5344. }
  5345. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  5346. // 添加退款记录
  5347. $item = array (
  5348. 'irid' => $irid,
  5349. 'refundType' => $refundType,
  5350. 'refundCompany' => $refundCompany,
  5351. 'refundNumber' => $refundNumber,
  5352. 'refundPrice' => $refundPrice,
  5353. 'refundLog' => $refundLog,
  5354. 'refundRemarks' => $refundRemarks,
  5355. 'date' => date ( "Y-m-d H:i:s" )
  5356. );
  5357. $invoiceRefund->addInvoiceRefund ( $item );
  5358. // 扣除收款汇总信息 汇总
  5359. Doo::loadModel ( 'invoiceStatistics' );
  5360. $invoiceStatistics = new invoiceStatistics ();
  5361. $item = array (
  5362. 'date' => $irDetail ['receivablesDate'],
  5363. 'priceClass' => 2,
  5364. 'irid' => $irDetail ['irid'],
  5365. 'receivablesPrice' => - $refundPrice
  5366. );
  5367. $receivablesCategory=array(0=>'',1=>'');
  5368. if ($irDetail ['receivablesCategory'] != 'PUBLIC') {
  5369. $receivablesCategory = explode ( ":", $irDetail ['receivablesCategory'] );
  5370. $item += array (
  5371. 'cid' => $receivablesCategory [0]
  5372. );
  5373. }
  5374. if ($irDetail ['receivablesStaff'] != 'PUBLIC') {
  5375. $receivablesStaff = explode ( "-", $irDetail ['receivablesStaff'] );
  5376. $item += array (
  5377. 'staff' => $receivablesStaff [0]
  5378. );
  5379. }
  5380. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  5381. // 公司日常支出流水
  5382. Doo::loadModel ( 'wasteBook' );
  5383. $wasteBook = new wasteBook ();
  5384. $accountBank=$wasteBook->_getAccountBankEN($irDetail ['receivablesBank']);
  5385. $itemWaste = array (
  5386. 'accountPrice' => - $refundPrice,
  5387. 'expensesType' => 2,
  5388. 'accountType' => 11,
  5389. 'accountPriceShow' => $refundPrice,
  5390. 'dataID' => $irid,
  5391. 'accountBank' => $accountBank,
  5392. 'category' => $receivablesCategory[1],
  5393. 'cid' => $receivablesCategory[0],
  5394. 'name' => $this->staff [0] ['username'],
  5395. 'sid' => $this->staff [0] ['sid'],
  5396. 'inputDate' => date ( "Y-m-d H:i:s" )
  5397. );
  5398. $wasteBook->setAccountBookStatistics ( $itemWaste );
  5399. return '/invoiceReceivablesAS';
  5400. }
  5401. die ( 'illegal request' );
  5402. }
  5403. function ajaxCheckInvoiceReceivablesRefund() {
  5404. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5405. $refundPrice = $this->get_args ( 'refundPrice' ) ? $this->get_args ( 'refundPrice' ) : "";
  5406. if ($refundPrice < 0) {
  5407. echo json_encode ( array (
  5408. 'error' => '金额不能为负'
  5409. ) );
  5410. die ();
  5411. }
  5412. if (! empty ( $refundPrice ) && ! empty ( $iridKey )) {
  5413. Doo::loadModel ( 'invoiceReceivables' );
  5414. $invoiceReceivables = new invoiceReceivables ();
  5415. $irid = $invoiceReceivables->authcode ( $iridKey );
  5416. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5417. if ($irDetail ['receivablesPrice'] < $refundPrice) {
  5418. echo json_encode ( array (
  5419. 'error' => '退款金额不能超过收款金额'
  5420. ) );
  5421. die ();
  5422. }
  5423. echo json_encode ( array (
  5424. 'ok' => '可以使用!'
  5425. ) );
  5426. die ();
  5427. }
  5428. }
  5429. /**
  5430. * 获得收款退款信息
  5431. */
  5432. function getRefundByDetail() {
  5433. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5434. Doo::loadModel ( 'invoiceReceivables' );
  5435. $invoiceReceivables = new invoiceReceivables ();
  5436. if (! empty ( $iridKey )) {
  5437. $irid = $invoiceReceivables->authcode ( $iridKey );
  5438. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5439. echo json_encode ( array (
  5440. 'status' => 1,
  5441. 'irDetail' => $irDetail
  5442. ) );
  5443. die ();
  5444. }
  5445. echo json_encode ( array (
  5446. 'status' => 2
  5447. ) );
  5448. }
  5449. /**
  5450. * 根据收款序列号获得收款退款信息
  5451. */
  5452. function ajaxGetInvoiceReceivablesBySerial() {
  5453. $receivablesSerial = $this->get_args ( 'receivablesSerial' ) ? $this->get_args ( 'receivablesSerial' ) : '';
  5454. if (! empty ( $receivablesSerial )) {
  5455. Doo::loadModel ( 'invoiceReceivables' );
  5456. $invoiceReceivables = new invoiceReceivables ();
  5457. // , ' and refundLog=""'
  5458. $irDetail = $invoiceReceivables->getInvoiceReceivablesBySerial ( $receivablesSerial );
  5459. $html = '';
  5460. if (! empty ( $irDetail ))
  5461. $html = '<td><b>¥' . $irDetail ['receivablesPrice'] . '</b></td>
  5462. <td>' . $irDetail ['receivablesMessage'] . '</td>
  5463. <td>' . $irDetail ['receivablesBank'] . '<br>' . $irDetail ['receivablesDate'] . '</td>
  5464. <td>' . $irDetail ['title'] . '-' . $irDetail ['username'] . '<br>' . $irDetail ['confirmTime'] . '</td>
  5465. <td>' . $irDetail ['recepitTitleMark'] . '
  5466. <input type="hidden" name="iridKey" id="iridKey" value="' . $irDetail ['iridKey'] . '">
  5467. </td>';
  5468. echo json_encode ( array (
  5469. 'status' => 1,
  5470. 'html' => $html,
  5471. 'irDetail' => $irDetail
  5472. ) );
  5473. die ();
  5474. }
  5475. echo json_encode ( array (
  5476. 'status' => 2
  5477. ) );
  5478. }
  5479. /**
  5480. * 绑定新收款
  5481. */
  5482. function relationNewInvoiceReceivables() {
  5483. $iridKeyOld = $this->get_args ( 'iridKeyOld' ) ? $this->get_args ( 'iridKeyOld' ) : '';
  5484. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5485. if (! empty ( $iridKeyOld ) && ! empty ( $iridKey )) {
  5486. Doo::loadModel ( 'invoiceReceivables' );
  5487. $invoiceReceivables = new invoiceReceivables ();
  5488. Doo::loadClass ( 'XDeode' );
  5489. $XDeode = new XDeode ( 5 );
  5490. $irid = $XDeode->decode ( $iridKey );
  5491. $iridOld = $invoiceReceivables->authcode ( $iridKeyOld );
  5492. echo $irid . 'bbb' . $iridOld;
  5493. $oldIrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $iridOld );
  5494. $IrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5495. if (empty ( $oldIrDetail ) || empty ( $IrDetail ))
  5496. die ( 'illegal request' );
  5497. $relationLog = $this->staff [0] ['username'] . ' 关联新款 <a href="#billing" onclick="invoiceReceivblesDivShow(\'' . $iridKey . '\',\'receivables\')" data-toggle="modal">' . $IrDetail ['receivablesSerial'] . '</a>
  5498. <br/>' . date ( "Y-m-d H:i:s" ) . '
  5499. ';
  5500. $invoiceReceivables = new invoiceReceivables ();
  5501. $item = array (
  5502. 'irid' => $iridOld,
  5503. 'relationIrid' => $irid,
  5504. 'relationLog' => $relationLog
  5505. );
  5506. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  5507. return '/invoiceReceivablesAS';
  5508. }
  5509. die ( 'illegal request' );
  5510. }
  5511. // function invoiceApprovalAchieve() {
  5512. // Doo::loadModel ( 'invoice' );
  5513. // $invoice = new invoice ();
  5514. // $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  5515. // $page_size = 12;
  5516. // $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5517. // $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  5518. // $get = "/" . $date;
  5519. // $con = '';
  5520. // if ($date == 'MONTHO')
  5521. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  5522. // elseif ($date == 'MONTHT')
  5523. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  5524. // elseif ($date == 'MONTHY')
  5525. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  5526. // if (! empty ( $MebSea )) {
  5527. // $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  5528. // $get .= "/" . $MebSea;
  5529. // }
  5530. // $pageinfo ['page'] = array (
  5531. // 'previous' => ''
  5532. // );
  5533. // $sql = '(status=1 or status=2 or status=3 or status=4) and processApprovals!=""' . $con; // echo $sql;
  5534. // $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", $get, "" );
  5535. // $limit = $pageinfo ['lower'] . ',' . $page_size;
  5536. // $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  5537. // // print_r($list);
  5538. // $this->data ['MebSeaEn'] = $MebSea;
  5539. // $this->data ['MebSea'] = urlencode ( $MebSea );
  5540. // $this->data ['get'] = $get;
  5541. // $this->data ['page'] = $pageinfo;
  5542. // $this->data ['list'] = $list;
  5543. // $this->data ['date'] = $date;
  5544. // $this->data ['memu'] = "invoice";
  5545. // $this->data ['staff'] = $this->staff;
  5546. // $this->data ['receiptMemu'] = 'invoiceApproval';
  5547. // $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  5548. // }
  5549. /**
  5550. * 获得审批发票的信息以及审批页面
  5551. */
  5552. function ajaxGetInvoiceApprovalDetail() {
  5553. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5554. if (empty ( $serial )) {
  5555. echo json_encode ( array (
  5556. 'status' => 2,
  5557. 'msg' => 'illegal request'
  5558. ) );
  5559. die ();
  5560. }
  5561. Doo::loadModel ( 'invoice' );
  5562. $invoice = new invoice ();
  5563. Doo::loadModel ( 'invoiceOperationLog' );
  5564. $invoiceOperationLog = new invoiceOperationLog ();
  5565. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5566. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5567. if (empty ( $detail ))
  5568. $html = '';
  5569. else {
  5570. $html = '
  5571. <form action="/invoiceApprovalDo" method="post" name="invoiceApproval" class="nice-validator n-yellow" novalidate="novalidate">
  5572. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  5573. <input type="hidden" name="status" value="">
  5574. <input type="hidden" name="divApproval" value="divApproval">
  5575. <div class="modal-dialog modal-lg">
  5576. <div class="modal-content"><div class="modal-header"><h3>发票审批详情</h3></div>
  5577. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  5578. <tr>
  5579. <th class="taC" width="150">发票审批</th><td><textarea name="opinion" style="width:98%" placeholder="在这写下您的审批意见,选填。"></textarea></td>
  5580. </tr>
  5581. <tr>
  5582. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5583. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5584. </tr>
  5585. <tr>
  5586. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5587. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5588. </tr>
  5589. <tr>
  5590. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5591. </td>
  5592. </tr>
  5593. <tr>
  5594. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5595. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5596. </tr>
  5597. <tr>
  5598. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5599. </tr></tbody></table>';
  5600. if ($detail ['invoiceType'] == 0)
  5601. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5602. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5603. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5604. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5605. </tr>';
  5606. else
  5607. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5608. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5609. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5610. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5611. ';
  5612. $html .= '<tr>
  5613. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5614. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5615. </tr>
  5616. <tr>
  5617. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5618. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5619. </tr></tbody></table>';
  5620. if ($detail ['doPost'] == 1) {
  5621. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5622. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5623. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5624. </tr><tr>
  5625. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5626. </tr><tr>
  5627. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5628. </tr>
  5629. ';
  5630. if ($detail ['expressCom'] == 'SF')
  5631. $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>';
  5632. else
  5633. $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>';
  5634. $html .= '</tbody></table>';
  5635. }
  5636. if (! empty ( $invoiceOperationLogList )) {
  5637. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  5638. foreach ( $invoiceOperationLogList as $key => $value ) {
  5639. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5640. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5641. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5642. if ($value ['status'] == 2) {
  5643. $html .= '<span class="colGreen">同意</span>';
  5644. } elseif ($value ['status'] == 3) {
  5645. $html .= '<span class="colOrange">退回</span>';
  5646. } elseif ($value ['status'] == 5) {
  5647. $html .= '<span class="colGreen">打印</span>';
  5648. } elseif ($value ['status'] == 4) {
  5649. $html .= '<span class="colRed">终止</span>';
  5650. }
  5651. $html .= $value ['operation'] . '</p></blockquote>';
  5652. }
  5653. }
  5654. $html .= '</td></tr></tbody></table>';
  5655. }
  5656. $html .= '</div><div class="modal-footer">
  5657. <a href="javascript:void(0)" node-approval="approval" diss-data="2" class="button btn-done" data-placement="top" data-toggle="ctooltip" >同意</a>
  5658. <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>
  5659. <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>
  5660. <a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>
  5661. </form>
  5662. <script type="text/javascript">
  5663. $("a[node-approval^=\'approval\']").click(function() {
  5664. $("input[name=\'status\']").val($(this).attr("diss-data"));
  5665. $("form[name=\'invoiceApproval\']").submit();
  5666. });
  5667. </script>
  5668. ';
  5669. }
  5670. echo json_encode ( array (
  5671. 'status' => 1,
  5672. 'html' => $html
  5673. ) );
  5674. die ();
  5675. }
  5676. /**
  5677. * 获得审批发票分页数据
  5678. */
  5679. function ajaxGetinvoiceApprovalAchieve() {
  5680. Doo::loadModel ( 'invoice' );
  5681. $invoice = new invoice ();
  5682. Doo::loadModel ( 'staff' );
  5683. $staff = new staff ();
  5684. Doo::loadClass ( 'XDeode' );
  5685. $XDeode = new XDeode ( 5 );
  5686. Doo::loadModel ( 'invoiceTraining' );
  5687. $invoiceTraining = new invoiceTraining ();
  5688. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  5689. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5690. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5691. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5692. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5693. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  5694. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  5695. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  5696. $MebSea = $this->get_args ( 'search' );
  5697. $MebSea = $MebSea ['value'];
  5698. $page_size = $length;
  5699. $con = '';
  5700. if ($status == 'ALL')
  5701. $con = ' (status=1 or status=2 or status=3 or status=4) and isDelete=0 ';
  5702. elseif ($status == 'PEND')
  5703. $con = ' isDelete=0 and status=1';
  5704. elseif ($status == 'APPROVED')
  5705. $con = ' isDelete=0 and status=2';
  5706. if ($invoiceType == 'ORDINARY')
  5707. $con .= ' and invoiceType=0 ';
  5708. elseif ($invoiceType == 'SPECIAL')
  5709. $con .= ' and invoiceType=1 ';
  5710. if ($invoiceTrain == 'ORDINARY')
  5711. $con .= ' and trainId=0 ';
  5712. elseif ($invoiceTrain == 'TRAIN')
  5713. $con .= ' and trainId!=0 ';
  5714. if ($invoiceTrainName != 'ALL') {
  5715. $trainId = $XDeode->decode ( $invoiceTrainName );
  5716. if (is_numeric ( $trainId ))
  5717. $con .= ' and trainId =' . $trainId;
  5718. }
  5719. $dateArr = explode ( ':', $date );
  5720. $D1 = $dateString = '';
  5721. $D2 = '';
  5722. if (! empty ( $date )) {
  5723. $D1 = $dateArr [0];
  5724. if (isset ( $dateArr [1] ))
  5725. $D2 = $dateArr [1];
  5726. else
  5727. $D2 = '';
  5728. $dateString = $D1 . " : " . $D2;
  5729. }
  5730. if (! empty ( $D1 ) && ! empty ( $D2 ))
  5731. $con .= ' and approvalTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  5732. elseif (! empty ( $D1 ) && empty ( $D2 ))
  5733. $con .= ' and approvalTime like "%' . $D1 . '%" ';
  5734. if (! empty ( $MebSea ))
  5735. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceSerial like "%' . $MebSea . '%" )';
  5736. // /
  5737. $pageinfo ['page'] = array (
  5738. 'previous' => ''
  5739. );
  5740. $sql = ' ' . $con;
  5741. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", '', "" );
  5742. $limit = $page . ',' . $page_size;
  5743. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  5744. $approvalList = array ();
  5745. $html = '<script type="text/javascript">
  5746. </script>';
  5747. // 结算结束不能修改方式
  5748. Doo::loadModel ( 'receipt' );
  5749. $receipt = new receipt ();
  5750. foreach ( $list as $key => $value ) {
  5751. $irDetail = array ();
  5752. // 结算方式
  5753. $receiptDetail = array ();
  5754. if ($value ['trainId'] != 0) {
  5755. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $value ['trainId'] );
  5756. }
  5757. if (! empty ( $receiptDetail )) {
  5758. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9) {
  5759. array_push ( $irDetail, '' );
  5760. } else {
  5761. if ($value ['status'] == 1 && $value ['pendingApprovals'] == $this->staff [0] ['sid']) {
  5762. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoiceApproval(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">审批发票</a>' );
  5763. } elseif ($value ['status'] == 2) {
  5764. array_push ( $irDetail, '<a href="#editPay" class="fnSettlementType" data-iidKey="' . $value ['iidKeyK'] . '" data-toggle="modal">结算方式</a>' );
  5765. } else
  5766. array_push ( $irDetail, '' );
  5767. }
  5768. } else {
  5769. if ($value ['status'] == 2) {
  5770. array_push ( $irDetail, '<a href="#editPay" class="fnSettlementType" data-iidKey="' . $value ['iidKeyK'] . '" data-toggle="modal">结算方式</a>' );
  5771. } else{
  5772. if ($value ['status'] == 1 && $value ['pendingApprovals'] == $this->staff [0] ['sid']) {
  5773. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoiceApproval(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">审批发票</a>' );
  5774. }else{
  5775. array_push ( $irDetail, '' );
  5776. }
  5777. }
  5778. }
  5779. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  5780. if ($value ['invoiceType'] == 1)
  5781. array_push ( $irDetail, $value ['invoiceCompany'] );
  5782. else
  5783. array_push ( $irDetail, $value ['invoiceTitle'] );
  5784. array_push ( $irDetail, $value ['TIN'] );
  5785. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  5786. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  5787. array_push ( $irDetail, $value ['remark'] );
  5788. array_push ( $irDetail, $value ['invoiceElement'] );
  5789. array_push ( $irDetail, $value ['invoiceQuantity'] );
  5790. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  5791. if ($value ['invoiceType'] == 1) {
  5792. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  5793. } else {
  5794. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  5795. }
  5796. if ($value ['settlementType'] == 0) {
  5797. array_push ( $irDetail, '软件销售' );
  5798. } else {
  5799. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $value ['trainId'] );
  5800. array_push ( $irDetail, $itDetail ['trainName'] );
  5801. }
  5802. array_push ( $irDetail, $value ['recipients'] . $value ['recipientsPhone'] );
  5803. array_push ( $irDetail, $value ['recipientsAddress'] );
  5804. array_push ( $irDetail, $value ['mailItems'] );
  5805. array_push ( $irDetail, $value ['userName'] . '&nbsp;' . $value ['date'] );
  5806. $fchtml = $value ['OL'] ['operation'];
  5807. if (count ( $list ) == $page_size)
  5808. $fchtml = $value ['OL'] ['operation'] . $html;
  5809. // 最后的审批意见
  5810. array_push ( $irDetail, $fchtml );
  5811. if ($value ['status'] == 2)
  5812. array_push ( $irDetail, '<span class="colGreen">同意</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5813. elseif ($value ['status'] == 3)
  5814. array_push ( $irDetail, '<span class="colOrange">退回</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5815. elseif ($value ['status'] == 4)
  5816. array_push ( $irDetail, '<span class="colRed">终止</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5817. else
  5818. array_push ( $irDetail, '' );
  5819. array_push ( $approvalList, $irDetail );
  5820. }
  5821. // $approvalListJson = json_encode ( $approvalList );
  5822. $recordsFiltered = $pageinfo ['total_data'];
  5823. echo json_encode ( array (
  5824. "draw" => intval ( $draw ),
  5825. "recordsTotal" => intval ( $pageinfo ['total_data'] ),
  5826. "recordsFiltered" => intval ( $recordsFiltered ),
  5827. "data" => $approvalList
  5828. ), JSON_UNESCAPED_UNICODE );
  5829. }
  5830. /**
  5831. * 审批发票查看更多--重构
  5832. */
  5833. function invoiceApprovalAchieve() {
  5834. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'ALL';
  5835. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5836. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5837. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5838. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5839. Doo::loadModel ( 'invoiceTraining' );
  5840. $invoiceTraining = new invoiceTraining ();
  5841. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  5842. $this->data ['trainList'] = $trainList;
  5843. $this->data ['dateString'] = $date;
  5844. $this->data ['status'] = $status;
  5845. $this->data ['invoiceType'] = $invoiceType;
  5846. $this->data ['invoiceTrain'] = $invoiceTrain;
  5847. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  5848. $this->data ['memu'] = "invoice";
  5849. $this->data ['staff'] = $this->staff;
  5850. $this->data ['receiptMemu'] = 'invoiceApproval';
  5851. $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  5852. }
  5853. function invoiceTAchieve() {
  5854. Doo::loadModel ( 'invoice' );
  5855. $invoice = new invoice ();
  5856. Doo::loadClass ( 'XDeode' );
  5857. $XDeode = new XDeode ( 5 );
  5858. Doo::loadModel ( 'staff' );
  5859. $staff = new staff ();
  5860. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  5861. $page_size = 12;
  5862. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5863. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  5864. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5865. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5866. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5867. Doo::loadModel ( 'invoiceTraining' );
  5868. $invoiceTraining = new invoiceTraining ();
  5869. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  5870. $get = "/" . $date;
  5871. $con = '';
  5872. if ($date == 'MONTHO')
  5873. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  5874. elseif ($date == 'MONTHT')
  5875. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  5876. elseif ($date == 'MONTHY')
  5877. $con = ' and YEAR(updateTime) = YEAR(NOW())'; // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  5878. if ($invoiceType == 'ORDINARY')
  5879. $con .= ' and invoiceType=0 ';
  5880. elseif ($invoiceType == 'SPECIAL')
  5881. $con .= ' and invoiceType=1 ';
  5882. if ($invoiceTrain == 'ORDINARY')
  5883. $con .= ' and trainId=0 ';
  5884. elseif ($invoiceTrain == 'TRAIN')
  5885. $con .= ' and trainId!=0 ';
  5886. if ($invoiceTrainName != 'ALL') {
  5887. $trainId = $XDeode->decode ( $invoiceTrainName );
  5888. if (is_numeric ( $trainId ))
  5889. $con .= ' and trainId =' . $trainId;
  5890. }
  5891. if (! empty ( $MebSea )) {
  5892. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  5893. $get .= "/" . $MebSea;
  5894. }
  5895. $pageinfo ['page'] = array (
  5896. 'previous' => ''
  5897. );
  5898. $sql = "";
  5899. $action = "";
  5900. if ($this->ACTION == 'invoicePrintAchieve') {
  5901. $sql = "status=2 and printStatus=1 and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  5902. $action = "invoicePrintAchieve";
  5903. } elseif ($this->ACTION == 'invoicePostAchieve') {
  5904. // and untreadStatus=0
  5905. $sql = "postStatus=1 and doPost=1 and status=2 and isDelete=0" . $con;
  5906. $action = "invoicePostAchieve";
  5907. } elseif ($this->ACTION == 'invoiceUntreadAchieve') { // printStatus=1 and
  5908. $sql = " untreadStatus=2 and status=2 " . $con;
  5909. $action = "invoiceUntreadAchieve";
  5910. }
  5911. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  5912. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5913. $this->data ['MebSeaEn'] = $MebSea;
  5914. $this->data ['MebSea'] = urlencode ( $MebSea );
  5915. $this->data ['get'] = $get;
  5916. $this->data ['page'] = $pageinfo;
  5917. $this->data ['trainList'] = $trainList;
  5918. $this->data ['invoiceType'] = $invoiceType;
  5919. $this->data ['invoiceTrain'] = $invoiceTrain;
  5920. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  5921. $this->data ['date'] = $date;
  5922. $this->data ['memu'] = "invoice";
  5923. $this->data ['staff'] = $this->staff;
  5924. if ($this->ACTION == 'invoicePrintAchieve') {
  5925. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  5926. $this->data ['receiptMemu'] = 'invoicePrint';
  5927. $this->data ['list'] = $list;
  5928. $this->render ( "/admin/invoicePrintAchieve", $this->data );
  5929. } elseif ($this->ACTION == 'invoicePostAchieve') {
  5930. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  5931. Doo::loadModel ( 'express' );
  5932. $express = new express ();
  5933. $expressList = $express->getExpressByAll ();
  5934. $this->data ['expressList'] = $expressList;
  5935. $this->data ['receiptMemu'] = 'invoicePost';
  5936. $this->data ['list'] = $list;
  5937. $this->render ( "/admin/invoicePostAchieve", $this->data );
  5938. } elseif ($this->ACTION == 'invoiceUntreadAchieve') {
  5939. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql,'desc','desc','untreadTime' );
  5940. $this->data ['receiptMemu'] = 'invoiceUntread';
  5941. $this->data ['list'] = $list;
  5942. $this->render ( "/admin/invoiceUntreadAchieve", $this->data );
  5943. }
  5944. }
  5945. /**
  5946. * 公司应收款
  5947. */
  5948. function invoiceAggregateCompanyDetail() {
  5949. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  5950. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  5951. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : 'ALL';
  5952. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  5953. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  5954. $titleORno = $this->get_args ( 'titleORno' ) ? $this->get_args ( 'titleORno' ) : "";
  5955. Doo::loadClass ( 'XDeode' );
  5956. $XDeode = new XDeode ( 5 );
  5957. Doo::loadModel ( 'invoice' );
  5958. $invoice = new invoice ();
  5959. Doo::loadModel ( 'staff' );
  5960. $staff = new staff ();
  5961. Doo::loadModel ( "invoiceCompanyManage" );
  5962. $invoiceCompanyManage = new invoiceCompanyManage ();
  5963. Doo::loadModel ( 'L_category' );
  5964. $category = new L_category ();
  5965. $sid = '';
  5966. if (! empty ( $sidKey )) {
  5967. $sid = $XDeode->decode ( $sidKey );
  5968. }
  5969. $staffDetail = $staff->getStaffBySid ( $sid );
  5970. $cid = '';
  5971. if (! empty ( $cidKey )) {
  5972. $cid = $XDeode->decode ( $cidKey );
  5973. }
  5974. $imcStaff = $invoiceCompanyManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  5975. $cidList = array ();
  5976. foreach ( $imcStaff as $key => $value ) {
  5977. array_push ( $cidList, $value ['cid'] );
  5978. }
  5979. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  5980. $cidString = implode ( ',', $cidList );
  5981. if (empty ( $cid ))
  5982. $staffList = $staff->getStaffInCid ( $cidString );
  5983. else
  5984. $staffList = $staff->getStaffByCidAll ( $cid ); //
  5985. //$MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  5986. $page_size = 25;
  5987. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5988. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  5989. $con = ' status=2 and untreadStatus!=2 and invalid=0 and isDelete=0 and badDebt=0 ';
  5990. $statisticsCon = '';
  5991. if (! empty ( $year ) && is_numeric ( $year ))
  5992. $con .= ' and Year(printTime)=' . $year . '';
  5993. if (! empty ( $month ) && is_numeric ( $month ))
  5994. $con .= ' and Month(printTime)="' . $month . '" ';
  5995. if ($status == 'UNRECORD')
  5996. $con .= ' and printStatus=1 and untreadStatus=0';
  5997. elseif ($status == 'RECORD')
  5998. $con .= ' and printStatus=1 and untreadStatus=3';
  5999. elseif ($status == 'BOUNCED')
  6000. $con .= ' and untreadStatus=2';
  6001. elseif ($status == 'PARTRECORD')
  6002. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  6003. elseif ($status == 'All') {
  6004. $con .= ' and printStatus=1 and ( untreadStatus=0 or untreadStatus=3 )';
  6005. }
  6006. if (! empty ( $sid ) && is_numeric ( $sid ))
  6007. $con .= ' and sid=' . $sid;
  6008. if (! empty ( $cid ) && is_numeric ( $cid ))
  6009. $con .= ' and cid=' . $cid;
  6010. else
  6011. $con .= ' and cid in (' . $cidString . ')';
  6012. // 开票内容筛选
  6013. if (! empty ( $invoiceElement ) && $invoiceElement != 'ALL') {
  6014. $con .= ' and invoiceElement="' . $invoiceElement . '"';
  6015. }
  6016. $get = "/" . $status . "?cidKey=" . $cidKey . "&sidKey=" . $sidKey . "&year=" . $year . "&month=" . $month
  6017. . "&invoiceElement=" . $invoiceElement."&titleORno=".urlencode ( $titleORno );
  6018. if (! empty ( $titleORno )) {
  6019. $con .= ' and ( invoiceTitle like "%' . $titleORno . '%" or invoiceCompany like "%' . $titleORno . '%" or invoiceNo like "%'.$titleORno.'%" )';
  6020. }
  6021. $pageinfo ['page'] = array (
  6022. 'previous' => ''
  6023. );
  6024. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateCompanyDetail", $get, "" );
  6025. $limit = $pageinfo ['lower'] . ',' . $page_size;
  6026. // 应收款合计
  6027. $ics = $invoice->getInvoiceCompanyStatistics ( $con );
  6028. //,'desc','desc','printTime'
  6029. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  6030. $monthHtml = "";
  6031. if ($year != "ALL") {
  6032. for($i = 1; $i <= 12; $i ++) {
  6033. if ($i == $month)
  6034. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  6035. else
  6036. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  6037. }
  6038. }
  6039. $this->data ['monthHtml'] = $monthHtml;
  6040. $this->data ['year'] = $year;
  6041. $this->data ['month'] = $month;
  6042. $this->data ['ics'] = $ics;
  6043. $this->data ['cidKey'] = $cidKey;
  6044. $this->data ['sid'] = $sid;
  6045. $this->data ['staffDetail'] = $staffDetail;
  6046. $this->data ['staffList'] = $staffList;
  6047. $this->data ['titleORnoEn'] = $titleORno;
  6048. $this->data ['titleORno'] = urlencode ( $titleORno );
  6049. $this->data ['invoiceDetail'] = array (
  6050. 'invoiceElement' => $invoiceElement
  6051. );
  6052. $this->data ['page'] = $pageinfo;
  6053. $this->data ['get'] = $get;
  6054. $this->data ['list'] = $list;
  6055. $this->data ['status'] = $status;
  6056. $this->data ['categoryList'] = $categoryList;
  6057. $this->data ['memu'] = "invoice";
  6058. $this->data ['staff'] = $this->staff;
  6059. $this->data ['receiptMemu'] = 'invoiceAggregateCompanyDetail';
  6060. $this->render ( "/admin/invoiceAggregateCompanyDetail", $this->data );
  6061. }
  6062. /**
  6063. * 获取一条收款信息
  6064. */
  6065. function ajaxGetInvoiceReceivables() {
  6066. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  6067. Doo::loadModel ( 'invoiceReceivables' );
  6068. $invoiceReceivables = new invoiceReceivables ();
  6069. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  6070. echo json_encode ( array (
  6071. 'status' => 1,
  6072. 'detail' => $detail
  6073. ) );
  6074. }
  6075. /**
  6076. * 异步获取办事处用户
  6077. */
  6078. function ajaxGetStaffByCategory() {
  6079. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "";
  6080. Doo::loadModel ( 'staff' );
  6081. $staff = new staff ();
  6082. if ($cid == "PUBLIC") {
  6083. echo json_encode ( array (
  6084. 'status' => 1,
  6085. 'html' => '<option value="PUBLIC">办事处待认领款项</option>'
  6086. ) );
  6087. die ();
  6088. }
  6089. if (! is_numeric ( $cid )) {
  6090. echo json_encode ( array (
  6091. 'status' => 0,
  6092. 'msg' => 'illegal request'
  6093. ) );
  6094. die ();
  6095. }
  6096. $staffList = $staff->getStaffByCid ( $cid );
  6097. $html = '<option value="PUBLIC">办事处待认领款项</option>';
  6098. foreach ( $staffList as $key => $value ) {
  6099. $html .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  6100. }
  6101. echo json_encode ( array (
  6102. 'status' => 1,
  6103. 'html' => $html
  6104. ) );
  6105. }
  6106. /**
  6107. * 异步获取一条发票的邮寄信息
  6108. */
  6109. function ajaxGetInvoicePostDetail() {
  6110. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  6111. Doo::loadModel ( 'invoice' );
  6112. $invoice = new invoice ();
  6113. $iid = $invoice->authcode ( $iid );
  6114. Doo::loadModel ( 'express' );
  6115. $express = new express ();
  6116. $expressList = $express->getExpressByAll ();
  6117. if (! is_numeric ( $iid )) {
  6118. echo json_encode ( array (
  6119. 'status' => 0,
  6120. 'msg' => 'illegal request'
  6121. ) );
  6122. die ();
  6123. }
  6124. $select = "iid,recipients,recipientsPhone,recipientsAddress,mailItems,expressCompany,expressNumber,actualItems";
  6125. $invoiceDetail = $invoice->getInvoiceByIid ( $iid, $select );
  6126. $html = "";
  6127. foreach ( $expressList as $key => $value ) {
  6128. if ($value ['company'] == $invoiceDetail ['expressCompany'])
  6129. $html .= '<option selected value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  6130. else
  6131. $html .= '<option value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  6132. }
  6133. $invoiceDetail ['eaHtml'] = $html;
  6134. echo json_encode ( array (
  6135. 'status' => 1,
  6136. 'invoiceDetail' => $invoiceDetail
  6137. ) );
  6138. }
  6139. /**
  6140. *
  6141. * @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 ) ); }
  6142. */
  6143. /**
  6144. *
  6145. * @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 ) ); }
  6146. */
  6147. /**
  6148. * 我的收款中 选择哪个发票入账,进行金额判断
  6149. */
  6150. function ajaxCompareInvoicePrice() {
  6151. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  6152. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  6153. Doo::loadModel ( 'invoice' );
  6154. $invoice = new invoice ();
  6155. Doo::loadModel ( 'invoiceReceivables' );
  6156. $invoiceReceivables = new invoiceReceivables ();
  6157. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  6158. $keyList = explode ( ';', $claimKey );
  6159. $receivablesPrice = 0;
  6160. foreach ( $keyList as $key => $value ) {
  6161. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $value );
  6162. $receivablesPrice += $detailM ['receivablesPrice'];
  6163. }
  6164. if ($receivablesPrice > $detail ['invoicePrice']) {
  6165. $price = $receivablesPrice - $detail ['invoicePrice'];
  6166. echo json_encode ( array (
  6167. 'status' => 1,
  6168. 'price' => $price
  6169. ) );
  6170. } else
  6171. echo json_encode ( array (
  6172. 'status' => 2
  6173. ) );
  6174. }
  6175. /**
  6176. * 获得打印发票
  6177. */
  6178. function ajaxGetInvoiceInfoByPrint() {
  6179. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  6180. if (empty ( $serial )) {
  6181. echo json_encode ( array (
  6182. 'status' => 2,
  6183. 'msg' => 'illegal request'
  6184. ) );
  6185. die ();
  6186. }
  6187. Doo::loadModel ( 'invoice' );
  6188. $invoice = new invoice ();
  6189. Doo::loadModel ( 'invoiceOperationLog' );
  6190. $invoiceOperationLog = new invoiceOperationLog ();
  6191. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  6192. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  6193. Doo::loadModel ( 'invoicePaper' );
  6194. $invoicePaper = new invoicePaper ();
  6195. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $detail ['invoiceType'] );
  6196. if (empty ( $detail ))
  6197. $html = '';
  6198. else {
  6199. $html = '
  6200. <form action="/invoicePrintDo" method="post" name="invoicePrint" class="nice-validator n-yellow" onSubmit="return checkPrintForm()" novalidate="novalidate">
  6201. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  6202. <input type="hidden" name="invoicePrintType" value="invoicePrintType">
  6203. <div class="modal-dialog modal-lg">
  6204. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  6205. <div class="modal-body saeaList">
  6206. <table class="table table-bordered table-condensed"><tbody>
  6207. <tr>
  6208. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  6209. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  6210. </tr>
  6211. <tr>
  6212. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  6213. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  6214. </tr>
  6215. <tr>
  6216. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  6217. </td>
  6218. </tr>
  6219. <tr>
  6220. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  6221. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  6222. </tr>
  6223. <tr>
  6224. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  6225. </tr></tbody></table>';
  6226. if ($detail ['invoiceType'] == 0)
  6227. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6228. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  6229. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  6230. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  6231. </tr>';
  6232. else
  6233. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6234. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  6235. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  6236. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  6237. ';
  6238. $html .= '<tr>
  6239. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  6240. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  6241. </tr>
  6242. <tr>
  6243. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  6244. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  6245. </tr></tbody></table>';
  6246. if ($detail ['doPost'] == 1)
  6247. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  6248. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  6249. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  6250. </tr><tr>
  6251. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  6252. </tr><tr>
  6253. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  6254. </tr></tbody></table>';
  6255. if (! empty ( $invoiceOperationLogList )) {
  6256. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th><th class="taC">发票打印</th></tr><tr><td>';
  6257. foreach ( $invoiceOperationLogList as $key => $value ) {
  6258. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  6259. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  6260. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  6261. if ($value ['status'] == 2) {
  6262. $html .= '<span class="colGreen">同意</span>';
  6263. } elseif ($value ['status'] == 3) {
  6264. $html .= '<span class="colOrange">退回</span>';
  6265. } elseif ($value ['status'] == 5) {
  6266. $html .= '<span class="colGreen">打印</span>';
  6267. } elseif ($value ['status'] == 4) {
  6268. $html .= '<span class="colRed">终止</span>';
  6269. }
  6270. $html .= $value ['operation'] . '</p></blockquote>';
  6271. }
  6272. }
  6273. $html .= '</td>
  6274. <td><span class="colRed">*</span>
  6275. <select name="invoiceNo" id="invoiceNo" style="width:97%">';
  6276. foreach ( $invoicePaperList as $key => $value ) {
  6277. $html .= '<option value="' . $value ['ipidKey'] . '">No.' . $value ['invoiceNo'] . '</option>';
  6278. }
  6279. $html .= '</select>
  6280. <span class="red" id="p-msg"></span>
  6281. </td>
  6282. </tr></tbody></table>';
  6283. }
  6284. $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>
  6285. </div></div></form>
  6286. <link rel=stylesheet href="' . WEB_SITE_GLOBAL . 'css/jquery.validator.css">
  6287. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/jquery.validator.min.js"></script>
  6288. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/zh-CN.js"></script>
  6289. <script src="' . WEB_SITE_GLOBAL . 'js/invoice.validator.js"></script>
  6290. ';
  6291. }
  6292. echo json_encode ( array (
  6293. 'status' => 1,
  6294. 'html' => $html
  6295. ) );
  6296. die ();
  6297. }
  6298. /**
  6299. * @ 获得与我有关收款数据 --需求变更 废弃 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 ) ); }
  6300. */
  6301. function ajaxGetInvoiceInfoByType() {
  6302. $type = $this->get_args ( 'type' ) ? $this->get_args ( 'type' ) : "";
  6303. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  6304. $loss = $this->get_args ( 'loss' ) ? $this->get_args ( 'loss' ) : false;
  6305. include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  6306. if (empty ( $serial )) {
  6307. echo json_encode ( array (
  6308. 'status' => 2,
  6309. 'msg' => 'illegal request'
  6310. ) );
  6311. die ();
  6312. }
  6313. if ($type == 'INVOICE') {
  6314. Doo::loadModel ( 'invoice' );
  6315. $invoice = new invoice ();
  6316. Doo::loadModel ( 'invoiceOperationLog' );
  6317. $invoiceOperationLog = new invoiceOperationLog ();
  6318. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  6319. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  6320. if (empty ( $detail ))
  6321. $html = '';
  6322. else {
  6323. $html = '
  6324. <div class="modal-dialog modal-lg">
  6325. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  6326. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  6327. <tr>
  6328. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  6329. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  6330. </tr>
  6331. <tr>
  6332. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  6333. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  6334. </tr>
  6335. <tr>
  6336. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  6337. </td>
  6338. </tr>
  6339. <tr>
  6340. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  6341. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  6342. </tr>
  6343. <tr>
  6344. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  6345. </tr>';
  6346. if ($detail ['settlementType'] == 1)
  6347. $html .= '<tr>
  6348. <th class="taC" width="150">结算方式</th><td colspan="3">培训班(<a href="/invoiceTrainingDetail/' . $detail ['invoiceTraining'] ['trainingKey'] . '.html" target="_blank">' . $detail ['invoiceTraining'] ['trainName'] . '</a>)</td>
  6349. </tr>';
  6350. else
  6351. $html .= '<tr>
  6352. <th class="taC" width="150">结算方式</th><td colspan="3">软件销售</td>
  6353. </tr>';
  6354. $html .= ' </tbody></table>';
  6355. if ($detail ['invoiceType'] == 0){
  6356. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6357. <tr><th colspan="4" class="taC">增值税普通发票';
  6358. if($detail ['invoiceForm']==1){
  6359. $html .= '( <span class="colRed">电子发票</span> )';
  6360. }
  6361. $html .= '</th></tr><tr>
  6362. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  6363. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  6364. </tr>';
  6365. }else{
  6366. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6367. <tr><th colspan="4" class="taC">增值税专用发票';
  6368. if($detail ['invoiceForm']==1){
  6369. $html .= '( <span class="colRed">电子发票</span> )';
  6370. }
  6371. $html .= '</th></tr><tr>
  6372. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  6373. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  6374. ';
  6375. }
  6376. $html .= '<tr>
  6377. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  6378. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  6379. </tr>
  6380. <tr>
  6381. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  6382. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  6383. </tr>
  6384. <tr>
  6385. <th class="taC">发票号</th><td>' . $detail ['invoiceNo'] . '</td>
  6386. <th class="taC"></th><td></td>
  6387. </tr>
  6388. </tbody></table>';
  6389. if ($detail ['doPost'] == 1) {
  6390. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  6391. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  6392. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  6393. </tr><tr>
  6394. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  6395. </tr><tr>
  6396. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  6397. </tr>
  6398. ';
  6399. if ($detail ['expressCom'] == 'SF')
  6400. $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>';
  6401. else
  6402. $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>';
  6403. $html .= '</tbody></table>';
  6404. }
  6405. if ($detail ['invoiceForm'] == 1) {
  6406. $html .= '<table class="table table-bordered table-condensed">
  6407. <tbody><tr><th colspan="4" class="taC">电子发票发送方式</th></tr>
  6408. <tr>
  6409. <th class="taC" width="150">收件人手机</th><td>'.$detail ['electronicPhone'].'</td>
  6410. <th class="taC" width="150">收件人邮箱</th><td>'.$detail ['electronicEmail'].'</td>
  6411. </tr></tbody></table>';
  6412. }
  6413. if (! empty ( $invoiceOperationLogList )) {
  6414. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  6415. foreach ( $invoiceOperationLogList as $key => $value ) {
  6416. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  6417. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  6418. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  6419. if ($value ['status'] == 2) {
  6420. $html .= '<span class="colGreen">同意</span>';
  6421. } elseif ($value ['status'] == 3) {
  6422. $html .= '<span class="colOrange">退回</span>';
  6423. } elseif ($value ['status'] == 5) {
  6424. $html .= '<span class="colGreen">打印</span>';
  6425. } elseif ($value ['status'] == 4) {
  6426. $html .= '<span class="colRed">终止</span>';
  6427. }
  6428. $html .= $value ['operation'] . '</p></blockquote>';
  6429. }
  6430. }
  6431. $html .= '</td></tr></tbody></table>';
  6432. }
  6433. $html .= '</div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  6434. }
  6435. echo json_encode ( array (
  6436. 'status' => 1,
  6437. 'html' => $html
  6438. ) );
  6439. die ();
  6440. } elseif ($type == 'RECEIVABLES') {
  6441. Doo::loadModel ( 'invoiceReceivables' );
  6442. $invoiceReceivables = new invoiceReceivables ();
  6443. Doo::loadModel ( 'invoiceRefund' );
  6444. $invoiceRefund = new invoiceRefund ();
  6445. $detail = $invoiceReceivables->getInvoiceReceivablesByIrsid ( $serial );
  6446. $ireList = $invoiceRefund->getInvoiceRefundIrid ( $detail ['irid'] );
  6447. if (empty ( $detail ))
  6448. $html = '';
  6449. else {
  6450. $html = '<div class="modal-dialog modal-lg"><div class="modal-content"><div class="modal-header"><h3>收款单详情</h3></div><div class="modal-body saeaList">
  6451. <table class="table table-bordered table-condensed">
  6452. <tbody><tr>
  6453. <th class="taC">收款流水号</th><td>' . $detail ['receivablesSerial'] . '</td>
  6454. <th class="taC">录入收款</th><td>' . $detail ['inputStaff'] . ' ' . $detail ['date'] . '</td>
  6455. </tr><tr>
  6456. <th class="taC">收款金额</th><td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  6457. <th class="taC">收款信息</th><td>' . $detail ['receivablesMessage'] . '</td>
  6458. </tr>
  6459. <tr>
  6460. <th class="taC">收款银行</th><td>' . $detail ['receivablesBank'] . '</td>
  6461. <th class="taC">银行到账</th><td>' . $detail ['receivablesDate'] . '</td>
  6462. </tr>
  6463. <tr>
  6464. <th class="taC">认领收款</th><td colspan="3">' . $detail ['inputStaff'] . ' 转入 ' . $detail ['username'] . ' ' . $detail ['confirmTime'] . '</td>
  6465. </tr>
  6466. </tbody></table>';
  6467. if (! empty ( $ireList )) {
  6468. $html .= '
  6469. <table class="table table-bordered table-condensed"><tbody><tr><th class="taC" colspan="5">退款记录</th></tr>
  6470. <tr>
  6471. <th class="taC">退款单位名称</th>
  6472. <th class="taC">退款的账号</th>
  6473. <th class="taC">退款金额</th>
  6474. <th class="taC">退款</th>
  6475. <th class="taC">备注</th>
  6476. </tr>
  6477. ';
  6478. foreach ( $ireList as $key => $value ) {
  6479. $refundLogList = explode ( "<br/>", $value ['refundLog'] );
  6480. $html .= '<tr>
  6481. <td>' . $value ['refundCompany'] . '</td>
  6482. <td>' . $value ['refundNumber'] . '</td>
  6483. <td><b class="colRed">¥' . $value ['refundPrice'] . '</b></td>
  6484. <td>' . $refundLogList [0] . $refundLogList [2] . '</td>
  6485. <td>' . $value ['refundRemarks'] . '</td>
  6486. </tr>
  6487. ';
  6488. }
  6489. }
  6490. $html .= '</tbody></table></div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  6491. }
  6492. echo json_encode ( array (
  6493. 'status' => 1,
  6494. 'html' => $html
  6495. ) );
  6496. die ();
  6497. } elseif ($type == 'IRTC') {
  6498. Doo::loadModel ( 'invoice' );
  6499. $invoice = new invoice ();
  6500. Doo::loadModel ( 'invoiceOperationLog' );
  6501. $invoiceOperationLog = new invoiceOperationLog ();
  6502. // Doo::loadModel ( 'invoiceReceivables' );
  6503. // $invoiceReceivables = new invoiceReceivables ();
  6504. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  6505. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  6506. if (empty ( $detail ))
  6507. $html = '';
  6508. else {
  6509. $receivablesPriceedHtml = '';
  6510. $receivablesPrice = $detail ['invoicePrice'];
  6511. if (! empty ( $detail ['irid'] )) {
  6512. // $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $detail ['irid'] );
  6513. // if (empty ( $irList ))
  6514. // $irList [0] ['sumPrice'] = 0;
  6515. // $balance = $detail ['invoicePrice'] - $irList [0] ['sumPrice'];
  6516. $enteredPrice=$detail ['invoicePrice']-$detail ['invoiceBalance'];
  6517. $receivablesPriceedHtml = '<table class="table table-bordered table-condensed"><tbody><tr>
  6518. <th class="taC">已入账金额</th><td><b class="colGreen" style="font-size:18px">¥' . $enteredPrice . '</b></td>
  6519. <th class="taC">剩余入账金额</th><td><b class="colRed" style="font-size:18px">¥' . $detail ['invoiceBalance'] . '</b></td>
  6520. </tr></tbody></table>';
  6521. $receivablesPrice = $detail ['invoiceBalance'];
  6522. }
  6523. if ($loss)
  6524. $detail ['invoicePrice'] = - $detail ['invoicePrice'];
  6525. $html = $receivablesPriceedHtml . '
  6526. <table class="table table-bordered table-condensed"><tbody>
  6527. <tr>
  6528. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  6529. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  6530. </tr>
  6531. <tr>
  6532. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  6533. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  6534. </tr>
  6535. <tr>
  6536. <th class="taC" width="150">发票备注</th><td colspan="3">' . $detail ['remark'] . '</td>
  6537. </tr>
  6538. <tr>
  6539. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  6540. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  6541. </tr>
  6542. <tr>
  6543. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  6544. </tr></tbody></table>';
  6545. if ($detail ['invoiceType'] == 0) {
  6546. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6547. <tr><th colspan="4" class="taC">增值税普通发票';
  6548. if($detail ['invoiceForm']==1){
  6549. $html .= '( <span class="colRed">电子发票</span> )';
  6550. }
  6551. $html.='</th></tr><tr>
  6552. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  6553. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  6554. </tr>';
  6555. $receivablesMessage = $detail ['invoiceTitle'];
  6556. } else {
  6557. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6558. <tr><th colspan="4" class="taC">增值税专用发票';
  6559. if($detail ['invoiceForm']==1){
  6560. $html .= '( <span class="colRed">电子发票</span> )';
  6561. }
  6562. $html .= '</th></tr><tr>
  6563. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  6564. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  6565. ';
  6566. $receivablesMessage = $detail ['invoiceCompany'];
  6567. }
  6568. $html .= '<tr>
  6569. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  6570. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  6571. </tr>
  6572. <tr>
  6573. <th class="taC">开户银行</th><td>' . $detail ['bankAccount'] . '</td>
  6574. <th class="taC">银行账号</th><td>' . $detail ['bank'] . '</td>
  6575. </tr></tbody></table>';
  6576. if ($detail ['doPost'] == 1)
  6577. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  6578. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  6579. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  6580. </tr><tr>
  6581. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  6582. </tr><tr>
  6583. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  6584. </tr></tbody></table>';
  6585. if (! empty ( $invoiceOperationLogList )) {
  6586. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  6587. foreach ( $invoiceOperationLogList as $key => $value ) {
  6588. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  6589. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  6590. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  6591. if ($value ['status'] == 2) {
  6592. $html .= '<span class="colGreen">同意</span>';
  6593. } elseif ($value ['status'] == 3) {
  6594. $html .= '<span class="colOrange">退回</span>';
  6595. } elseif ($value ['status'] == 5) {
  6596. $html .= '<span class="colGreen">打印</span>';
  6597. }
  6598. $html .= $value ['operation'] . '</p></blockquote>';
  6599. }
  6600. }
  6601. $html .= '</td></tr></tbody></table>';
  6602. }
  6603. }
  6604. echo json_encode ( array (
  6605. 'status' => 1,
  6606. 'html' => $html,
  6607. 'receivablesPrice' => $receivablesPrice,
  6608. 'receivablesMessage' => $receivablesMessage,
  6609. 'receivablesDate' => date ( "Y-m-d" ),
  6610. 'iidKey' => $serial
  6611. ) );
  6612. die ();
  6613. }
  6614. }
  6615. function ajaxGetInvoiceReceivablesByStaff() {
  6616. $postData = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : "";
  6617. if (empty ( $postData )) {
  6618. echo json_encode ( array (
  6619. 'status' => 2,
  6620. 'msg' => 'illegal request'
  6621. ) );
  6622. die ();
  6623. }
  6624. Doo::loadModel ( 'invoiceReceivables' );
  6625. $invoiceReceivables = new invoiceReceivables ();
  6626. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $postData );
  6627. if (empty ( $detail )) {
  6628. echo json_encode ( array (
  6629. 'status' => 2,
  6630. 'msg' => 'illegal request'
  6631. ) );
  6632. die ();
  6633. }
  6634. Doo::loadModel ( 'L_category' );
  6635. $lCategory = new L_category ();
  6636. Doo::loadModel ( 'staff' );
  6637. $staff = new staff ();
  6638. $staffList = $staff->getStaffByCid ( $detail ['cid'] );
  6639. $category = $lCategory->getCategory ();
  6640. $categoryHtml = '<option post-data="PUBLIC" value="PUBLIC" >公共待认领款项</option>';
  6641. $staffHtml = '<option value="PUBLIC">办事处待认领款项</option>';
  6642. foreach ( $category as $key => $value ) {
  6643. $categoryHtml .= '<option post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  6644. if ($value ['cid'] == $detail ['cid'])
  6645. $categoryHtml .= '<option selected post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  6646. }
  6647. foreach ( $staffList as $key => $value ) {
  6648. $staffHtml .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  6649. if ($value ['sid'] == $detail ['sid'])
  6650. $staffHtml .= '<option selected value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  6651. }
  6652. $rbankHtml = '<option value="广发银行珠海分行柠溪支行">广发银行珠海分行柠溪支行</option>';
  6653. echo json_encode ( array (
  6654. 'status' => 1,
  6655. 'categoryHtml' => $categoryHtml,
  6656. 'staffHtml' => $staffHtml,
  6657. 'rbankHtml' => $rbankHtml,
  6658. 'detail' => $detail
  6659. ) );
  6660. }
  6661. function ajaxGetInvoiceReceivablesByIrid() {
  6662. $irid = $this->get_args ( 'irid' ) ? $this->get_args ( 'irid' ) : "";
  6663. if (empty ( $irid )) {
  6664. echo json_encode ( array (
  6665. 'status' => 2,
  6666. 'msg' => 'illegal request'
  6667. ) );
  6668. die ();
  6669. }
  6670. Doo::loadModel ( 'invoiceReceivables' );
  6671. $invoiceReceivables = new invoiceReceivables ();
  6672. Doo::loadModel ( 'invoice' );
  6673. $invoice = new invoice ();
  6674. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid ); // 入账完成 待定 and postStatus=1
  6675. $flag = true;
  6676. $invoiceDetail = $invoice->getInvoiceByTitle ( $detail ['recepitTitleMark'], 'EXACTLY', " and status=2 and printStatus=1 and untreadStatus=0 ", $flag ); //
  6677. $bakDetail = array ();
  6678. if ($flag === false) {
  6679. array_push ( $bakDetail, $invoiceDetail );
  6680. $invoiceDetail = $bakDetail;
  6681. }
  6682. $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>
  6683. <tr>
  6684. <td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  6685. <td>' . $detail ['receivablesMessage'] . '</td>
  6686. <td>' . $detail ['receivablesBank'] . '<br>' . $detail ['receivablesDate'] . '</td>
  6687. <td>' . $detail ['title'] . '-' . $detail ['username'] . '<br>' . $detail ['confirmTime'] . '</td>
  6688. <td>' . $detail ['recepitTitleMark'] . '</td>
  6689. </tr></tbody></table>';
  6690. $isInvoice = false;
  6691. $invoiceHtml = '';
  6692. if (empty ( $invoiceDetail )) {
  6693. $isInvoice = true;
  6694. } else {
  6695. $invoiceHtml = '<table class="table table-bordered table-condensed">
  6696. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody>';
  6697. foreach ( $invoiceDetail as $key => $value ) {
  6698. $invoiceHtml .= '<tr>';
  6699. if (! empty ( $value ['invoiceType'] )) {
  6700. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  6701. } else {
  6702. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  6703. }
  6704. if (! empty ( $value ['invoiceType'] )) {
  6705. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  6706. } else {
  6707. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  6708. }
  6709. $invoiceHtml .= '
  6710. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  6711. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  6712. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir" data-ikey="' . $value ['iidKey'] . '" href="javascript:void(0)">入账</a></td>
  6713. </tr>
  6714. ';
  6715. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  6716. if (empty ( $irList ))
  6717. $irList [0] ['sumPrice'] = 0;
  6718. $balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  6719. $priceString = '';
  6720. if ($balance < $detail ['receivablesPrice']) {
  6721. $priceString = '收款金额超过开票金额,';
  6722. }
  6723. if ($balance > $detail ['receivablesPrice']) {
  6724. $priceString = '收款金额低于开票金额,';
  6725. }
  6726. }
  6727. $invoiceHtml .= '
  6728. <script>
  6729. $(\'a[bind-receivables^="ir"]\').click(function() {
  6730. var data = $(this).attr("data-ikey");
  6731. $("input[name=\'invoiceKey\']").val(data);
  6732. var invoiceKey=data;
  6733. if(invoiceKey==""){
  6734. alert("入账错误,请重新刷新页面");
  6735. return false;
  6736. }
  6737. if(window.confirm("' . $priceString . '确定入账吗?")){
  6738. $("#IBR").submit();
  6739. }else{
  6740. return false;
  6741. }
  6742. });
  6743. </script>
  6744. ';
  6745. $invoiceHtml .= '</tbody></table>';
  6746. }
  6747. echo json_encode ( array (
  6748. 'status' => 1,
  6749. 'irkey' => $detail ['iridEn'],
  6750. 'receivablesHtml' => $receivablesHtml,
  6751. 'isInvoice' => $isInvoice,
  6752. 'invoiceHtml' => $invoiceHtml
  6753. ) );
  6754. }
  6755. function ajaxGetInvoiceReceivablesByTitle() {
  6756. $title = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  6757. if (empty ( $title )) {
  6758. echo json_encode ( array (
  6759. 'status' => 2,
  6760. 'msg' => 'illegal request'
  6761. ) );
  6762. die ();
  6763. }
  6764. Doo::loadModel ( 'invoice' );
  6765. $invoice = new invoice ();
  6766. $invoiceDetail = $invoice->getInvoiceByTitle ( $title, 'FUZZY', " and status=2 and printStatus=1 and untreadStatus=0 and (irid='' or irid is null) ", true );
  6767. $invoiceHtml = '';
  6768. if (! empty ( $invoiceDetail )) {
  6769. $invoiceHtml = '<table class="table table-bordered table-condensed">
  6770. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody><tr>';
  6771. foreach ( $invoiceDetail as $key => $value ) {
  6772. if (! empty ( $value ['invoiceType'] )) {
  6773. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  6774. } else {
  6775. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  6776. }
  6777. if (! empty ( $value ['invoiceType'] )) {
  6778. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  6779. } else {
  6780. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  6781. }
  6782. $invoiceHtml .= '
  6783. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  6784. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  6785. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir' . $value ['iidKeyXD'] . '" data-ikey="' . $value ['iidKey'] . '" href="#">入账</a></td>
  6786. </tr>
  6787. ';
  6788. }
  6789. $invoiceHtml .= '</tbody></table>
  6790. <script>
  6791. $(\'a[bind-receivables^="ir"]\').click(function() {
  6792. var data = $(this).attr("data-ikey");
  6793. $("input[name=\'invoiceKey\']").val(data);
  6794. var invoiceKey=$("input[name=\'invoiceKey\']").val();
  6795. if(invoiceKey==""){
  6796. alert("入账错误,请重新刷新页面");
  6797. return false;
  6798. }
  6799. if(window.confirm("确定入账吗?")){
  6800. $("#IBR").submit();
  6801. }else{
  6802. return false;
  6803. }
  6804. });
  6805. </script>
  6806. ';
  6807. }
  6808. echo json_encode ( array (
  6809. 'status' => 1,
  6810. 'invoiceHtml' => $invoiceHtml
  6811. ) );
  6812. }
  6813. function ajaxInvoicePushNotice() {
  6814. Doo::loadModel ( 'invoice' );
  6815. $invoice = new invoice ();
  6816. $approval = $invoice->getOne ( array (
  6817. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  6818. 'desc' => 'iid',
  6819. 'asArray' => true
  6820. ) );
  6821. $isNotice = false;
  6822. if (! empty ( $approval ))
  6823. $isNotice = true;
  6824. $response = array (
  6825. 'error' => 0,
  6826. 'isNotice' => $isNotice
  6827. );
  6828. echo json_encode ( $response );
  6829. exit ();
  6830. }
  6831. public function ajaxCheckInvoiceNoUniqueness() {
  6832. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  6833. Doo::loadModel ( 'invoice' );
  6834. $invoice = new invoice ();
  6835. if (! empty ( $invoiceNo )) {
  6836. Doo::loadModel ( 'invoicePaper' );
  6837. $invoicePaper = new invoicePaper ();
  6838. Doo::loadClass ( 'XDeode' );
  6839. $XDeode = new XDeode ( 5 );
  6840. $ipid = $XDeode->decode ( $invoiceNo );
  6841. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  6842. $info = $invoice->getOne ( array (
  6843. 'where' => "invoiceNo = '" . $paperDetail ['invoiceNo'] . "'",
  6844. 'asArray' => TRUE
  6845. ) );
  6846. if (! empty ( $info )) {
  6847. echo json_encode ( array (
  6848. 'error' => '发票号已存在'
  6849. ) );
  6850. die ();
  6851. } else
  6852. echo json_encode ( array (
  6853. 'ok' => '可以使用!'
  6854. ) );
  6855. die ();
  6856. }
  6857. }
  6858. function ajaxCheckInvoicePrice() {
  6859. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) && is_numeric ( $this->get_args ( 'receivablesPrice' ) ) ? $this->get_args ( 'receivablesPrice' ) : "";
  6860. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  6861. Doo::loadModel ( 'invoice' );
  6862. $invoice = new invoice ();
  6863. Doo::loadModel ( 'invoiceReceivables' );
  6864. $invoiceReceivables = new invoiceReceivables ();
  6865. Doo::loadClass ( 'XDeode' );
  6866. $XDeode = new XDeode ( 5 );
  6867. if (! empty ( $receivablesPrice ) && ! empty ( $iidKey )) {
  6868. $iidKey = $XDeode->decode ( $iidKey );
  6869. $info = $invoice->getInvoiceByIid ( $iidKey );
  6870. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $info ['irid'] );
  6871. if (empty ( $irList ))
  6872. $irList [0] ['sumPrice'] = 0;
  6873. $balance = $info ['invoicePrice'] - $irList [0] ['sumPrice'];
  6874. if ($balance < $receivablesPrice) {
  6875. echo json_encode ( array (
  6876. 'error' => '收款金额超过开票金额。'
  6877. ) );
  6878. die ();
  6879. }
  6880. if ($balance > $receivablesPrice) {
  6881. echo json_encode ( array (
  6882. 'error' => '收款金额低于开票金额。'
  6883. ) );
  6884. die ();
  6885. }
  6886. }
  6887. }
  6888. function ajaxGetInvoiceByNew() {
  6889. Doo::loadModel ( 'invoice' );
  6890. $invoice = new invoice ();
  6891. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );
  6892. echo json_encode ( array (
  6893. 'status' => 1,
  6894. 'detail' => $detail
  6895. ) );
  6896. }
  6897. /**
  6898. * 旧输入导入
  6899. */
  6900. function importInvoice() {
  6901. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  6902. $data ['emsg'] = "";
  6903. if ($emsg != "")
  6904. $data ['emsg'] = "请填写完整的数据";
  6905. $data ['time'] = time ();
  6906. $this->render ( "/admin/invoiceImport", $data );
  6907. }
  6908. function uploadInvoice() {
  6909. // move_uploaded_file($_FILES['Filedata']['tmp_name'], "/upload/".$_FILES['Filedata']['name']);
  6910. if (isset ( $_FILES ['Filedata'] ['name'] )) {
  6911. $file = $_FILES ['Filedata'] ['tmp_name'];
  6912. $error = false;
  6913. if (! is_uploaded_file ( $file )) {
  6914. $error = '400 Bad Request';
  6915. }
  6916. if ($error) {
  6917. header ( 'HTTP/1.0 ' . $error );
  6918. die ( 'Error ' . $error );
  6919. } else {
  6920. include (DOO::conf ()->SITE_PATH . 'protected/plugin/io.han.php');
  6921. $this->IoHandler = new IoHandler ();
  6922. $pics = explode ( '.', $_FILES ['Filedata'] ['name'] );
  6923. // $filedir=$_POST['time'];
  6924. // 调用定义物理路径
  6925. $t = DOO::conf ()->SITE_PATH . "upload/invoice/";
  6926. $this->IoHandler->MakeDir ( $t );
  6927. $filename = $this->_GetFileEXT ( $_FILES ['Filedata'] ['name'] );
  6928. if ($filename != 'xlsx')
  6929. return "";
  6930. // $upload_dir = $t."/".time().rand(10,100).".".$filename;
  6931. $upload_file = iconv ( "UTF-8", "GB2312", $_FILES ["Filedata"] ["name"] );
  6932. $upload_dir = $t . "/" . $upload_file;
  6933. $k = move_uploaded_file ( $file, $upload_dir );
  6934. if ($k) {
  6935. $m = round ( $_FILES ['Filedata'] ['size'] / 1024 / 1024, 2 );
  6936. echo $pics [0] . "." . $filename . "#" . $m . "#" . $_FILES ['Filedata'] ['size'];
  6937. }
  6938. }
  6939. }
  6940. }
  6941. function importInvoiceDo() {
  6942. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  6943. if ($path != "") {
  6944. Doo::loadModel ( 'invoice' );
  6945. Doo::loadModel ( 'staff' );
  6946. $staff = new staff ();
  6947. Doo::loadModel ( 'invoiceStatistics' );
  6948. Doo::loadModel ( 'invoiceOperationLog' );
  6949. echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  6950. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . $path );
  6951. // print_r ( $exlArray );
  6952. // die ();
  6953. // echo json_encode($exlArray);die;
  6954. foreach ( $exlArray as $key => $value ) {
  6955. // 开票
  6956. $invoice = new invoice ();
  6957. $invoice->invoiceNo = $value ['invoiceNo'];
  6958. $invoice->invoiceType = 0;
  6959. if ($value ['invoiceType'] == '专')
  6960. $invoice->invoiceType = 1;
  6961. $invoice->invoicePrice = $value ['invoicePrice'];
  6962. $invoice->invoiceQuantity = 1;
  6963. $invoice->invoiceUnitPrice = $value ['invoicePrice'];
  6964. $invoice->invoiceTitle = $value ['invoiceTitle'];
  6965. if ($value ['invoiceType'] == '专')
  6966. $invoice->invoiceCompany = $value ['invoiceTitle'];
  6967. $invoice->userName = $value ['userName'];
  6968. $sDetail = $staff->getStaffByName ( $value ['userName'] );
  6969. $invoice->sid = $sDetail ['sid'];
  6970. $invoice->cid = $sDetail ['cid'];
  6971. $invoice->categoryName = $sDetail ['category'];
  6972. $invoice->invoiceElement = $value ['invoiceElement'];
  6973. $invoice->remark = $value ['remark'];
  6974. $invoice->date = $value ['date'];
  6975. $invoice->printTime = $value ['date'];
  6976. $invoice->ipSource = 1;
  6977. $invoice->printStatus = 1;
  6978. $invoice->status = 2;
  6979. $invoice->postStatus = 1;
  6980. $invoice->untreadStatus = 0;
  6981. $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  6982. $iid = $invoice->insert ();
  6983. // 汇总
  6984. $invoiceStatistics = new invoiceStatistics ();
  6985. //
  6986. $item = array (
  6987. 'date' => $value ['date'],
  6988. 'priceClass' => 1,
  6989. 'cid' => $sDetail ['cid'],
  6990. 'staff' => $sDetail ['sid'],
  6991. 'invoicePrice' => $value ['invoicePrice']
  6992. );
  6993. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  6994. $invoiceOperationLog = new invoiceOperationLog ();
  6995. $item = array (
  6996. 'date' => date ( "Y-m-d H:i:s" ),
  6997. 'operation' => date ( "Y-m-d" ) . " 导入",
  6998. 'status' => 1,
  6999. 'img' => $sDetail ['avatar'],
  7000. 'username' => $sDetail ['username'],
  7001. 'uid' => $sDetail ['sid'],
  7002. 'category' => $sDetail ['category'],
  7003. 'iid' => $iid
  7004. );
  7005. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  7006. }
  7007. return '/importInvoice?count=' . count ( $exlArray );
  7008. // return "/keyonline";
  7009. }
  7010. echo 'no file';
  7011. }
  7012. function importInvoiceReceivables() {
  7013. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  7014. $data ['emsg'] = "";
  7015. if ($emsg != "")
  7016. $data ['emsg'] = "请填写完整的数据";
  7017. $data ['time'] = time ();
  7018. $this->render ( "/admin/invoiceReceivablesImport", $data );
  7019. }
  7020. // 导入入账数据
  7021. function importInvoiceReceivablesDo() {
  7022. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  7023. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  7024. if ($path != "") {
  7025. Doo::loadModel ( 'invoiceReceivables' );
  7026. Doo::loadModel ( 'invoice' );
  7027. Doo::loadModel ( 'staff' );
  7028. $staff = new staff ();
  7029. Doo::loadModel ( 'invoiceStatistics' );
  7030. // echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  7031. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path ), 'invoiceReceivables' );
  7032. // print_r ( $exlArray );
  7033. // die ();
  7034. // echo json_encode($exlArray);die;
  7035. foreach ( $exlArray as $key => $value ) {
  7036. // 收款
  7037. $invoiceReceivables = new invoiceReceivables ();
  7038. $invoice = new invoice ();
  7039. $invoiceReceivables->bindStatus = 1;
  7040. $invoiceReceivables->receivablesPrice = $value ['receivablesPrice'];
  7041. $invoiceReceivables->receivablesMessage = $value ['receivablesMessage'];
  7042. $invoiceReceivables->receivablesBank = $value ['receivablesBank'];
  7043. $invoiceReceivables->receivablesDate = $value ['receivablesDate'];
  7044. $sDetail = $staff->getStaffByName ( $value ['receivablesStaff'] );
  7045. $invoiceReceivables->receivablesCategory = $sDetail ['cid'] . ':' . $sDetail ['category'];
  7046. $invoiceReceivables->receivablesStaff = $sDetail ['sid'] . '-' . $sDetail ['username'];
  7047. $invoiceReceivables->receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  7048. $invoiceReceivables->sourcePrice = $value ['sourcePrice'];
  7049. $iDetail = $invoice->getInvoiceByInvoiceNo ( $value ['invoiceNo'] );
  7050. $invoiceReceivables->iid = $iDetail ['iid'];
  7051. $irid = $invoiceReceivables->insert ();
  7052. // 发票绑定收款
  7053. $detail = $iDetail;
  7054. $iridString = "";
  7055. if (empty ( $detail ['irid'] ))
  7056. $iridString = $irid;
  7057. else
  7058. $iridString = $detail ['irid'] . ',' . $irid;
  7059. $item = array (
  7060. 'irid' => $iridString,
  7061. 'iid' => $detail ['iid']
  7062. );
  7063. $invoice->setInvoiceByCondition ( $item );
  7064. // 汇总
  7065. $invoiceStatistics = new invoiceStatistics ();
  7066. // 扣除入账统计金额
  7067. $item = array (
  7068. 'date' => $value ['receivablesDate'],
  7069. 'priceClass' => 3,
  7070. 'cid' => $sDetail ['cid'],
  7071. 'staff' => $sDetail ['sid'],
  7072. // 'irid' => $irid,
  7073. 'accountPrice' => $value ['receivablesPrice']
  7074. );
  7075. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  7076. }
  7077. return '/importInvoiceReceivables?count=' . count ( $exlArray );
  7078. echo 'data count ' . count ( $exlArray );
  7079. die ();
  7080. // return "/keyonline";
  7081. }
  7082. echo 'no file';
  7083. }
  7084. function formatExcelToArrayTrain($file_url = "") {
  7085. if (! file_exists ( $file_url )) {
  7086. return array ();
  7087. }
  7088. // Doo::loadClass ( 'PHPExcel' );
  7089. Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  7090. $PHPExcel = new PHPExcel ();
  7091. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  7092. if (! $PHPReader->canRead ( $file_url )) {
  7093. $PHPReader = new PHPExcel_Reader_Excel5 ();
  7094. if (! $PHPReader->canRead ( $file_url )) {
  7095. echo 'no Excel';
  7096. return;
  7097. }
  7098. }
  7099. $PHPExcel = $PHPReader->load ( $file_url );
  7100. /* * 读取excel文件中的第一个工作表 */
  7101. $currentSheet = $PHPExcel->getSheet ( 0 );
  7102. /* * 取得最大的列号 */
  7103. $allColumn = $currentSheet->getHighestColumn ();
  7104. /* * 取得一共有多少行 */
  7105. $allRow = $currentSheet->getHighestRow ();
  7106. $excel_array = array ();
  7107. // die($file_url);
  7108. $conk = 2;
  7109. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  7110. $excel_column = array ();
  7111. // 后期改进
  7112. if ($allColumn == 'AM')
  7113. $allColumn = 'Z';
  7114. /* * 从第A列开始输出 */
  7115. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  7116. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  7117. if ($val instanceof PHPExcel_RichText)
  7118. $val = $val->__toString ();
  7119. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  7120. // $val = "'" . addslashes ( $val ) . "'";
  7121. if ($currentColumn == 'A') {
  7122. $excel_column ['invoiceTitle'] = $val;
  7123. } elseif ($currentColumn == 'B')
  7124. $excel_column ['invoiceType'] = $val;
  7125. elseif ($currentColumn == 'C') {
  7126. $excel_column ['TIN'] = $val;
  7127. } elseif ($currentColumn == 'D') {
  7128. $excel_column ['address'] = $val;
  7129. } elseif ($currentColumn == 'E') {
  7130. $excel_column ['phone'] = $val;
  7131. } elseif ($currentColumn == 'F') {
  7132. $excel_column ['bank'] = $val;
  7133. } elseif ($currentColumn == 'G') {
  7134. $excel_column ['bankAccount'] = $val;
  7135. } elseif ($currentColumn == 'H') {
  7136. $excel_column ['invoiceElement'] = $val;
  7137. } elseif ($currentColumn == 'I') {
  7138. $excel_column ['invoiceQuantity'] = $val;
  7139. } elseif ($currentColumn == 'J') {
  7140. $excel_column ['invoiceUnitPrice'] = $val;
  7141. } elseif ($currentColumn == 'K') {
  7142. $excel_column ['remark'] = $val;
  7143. } elseif ($currentColumn == 'L') {
  7144. $excel_column ['recipientsAddress'] = $val;
  7145. } elseif ($currentColumn == 'M') {
  7146. $excel_column ['recipients'] = $val;
  7147. } elseif ($currentColumn == 'N') {
  7148. $excel_column ['recipientsPhone'] = $val;
  7149. }elseif ($currentColumn == 'O') {
  7150. $excel_column ['electronicPhone'] = $val;
  7151. } elseif ($currentColumn == 'P') {
  7152. $excel_column ['electronicEmail'] = $val;
  7153. }
  7154. }
  7155. if (! empty ( $excel_column ['invoiceTitle'] ) && ! empty ( $excel_column ['invoiceQuantity'] ) && ! empty ( $excel_column ['invoiceUnitPrice'] ))
  7156. array_push ( $excel_array, $excel_column );
  7157. }
  7158. return $excel_array;
  7159. }
  7160. /**
  7161. * 格式化excel文件为数组
  7162. * @param unknown_type $file_url
  7163. * @param unknown_type $mcid
  7164. */
  7165. function _format_excel_to_array($file_url = "", $sType = "") {
  7166. if (! file_exists ( $file_url )) {
  7167. return array ();
  7168. }
  7169. Doo::loadClass ( 'PHPExcel' );
  7170. // Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  7171. $PHPExcel = new PHPExcel ();
  7172. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  7173. if (! $PHPReader->canRead ( $file_url )) {
  7174. $PHPReader = new PHPExcel_Reader_Excel5 ();
  7175. if (! $PHPReader->canRead ( $file_url )) {
  7176. echo 'no Excel';
  7177. return;
  7178. }
  7179. }
  7180. $PHPExcel = $PHPReader->load ( $file_url );
  7181. /* * 读取excel文件中的第一个工作表 */
  7182. $currentSheet = $PHPExcel->getSheet ( 0 );
  7183. /* * 取得最大的列号 */
  7184. $allColumn = $currentSheet->getHighestColumn ();
  7185. /* * 取得一共有多少行 */
  7186. $allRow = $currentSheet->getHighestRow ();
  7187. $excel_array = array ();
  7188. // die($file_url);
  7189. $conk = 2;
  7190. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  7191. $excel_column = array ();
  7192. // 后期改进
  7193. if ($allColumn == 'AM')
  7194. $allColumn = 'Z';
  7195. /* * 从第A列开始输出 */
  7196. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  7197. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  7198. if ($val instanceof PHPExcel_RichText)
  7199. $val = $val->__toString ();
  7200. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  7201. // $val = "'" . addslashes ( $val ) . "'";
  7202. if ($sType == 'invoiceReceivables') {
  7203. if ($currentColumn == 'A')
  7204. $excel_column ['invoiceNo'] = $val;
  7205. elseif ($currentColumn == 'B')
  7206. $excel_column ['receivablesPrice'] = $val;
  7207. elseif ($currentColumn == 'C') {
  7208. $excel_column ['receivablesMessage'] = $val;
  7209. } elseif ($currentColumn == 'D') {
  7210. $excel_column ['receivablesBank'] = $val;
  7211. } elseif ($currentColumn == 'E') {
  7212. $excel_column ['receivablesDate'] = $this->excelTime ( $val );
  7213. } elseif ($currentColumn == 'F') {
  7214. $excel_column ['receivablesStaff'] = $val;
  7215. } elseif ($currentColumn == 'G') {
  7216. $excel_column ['sourcePrice'] = $val;
  7217. }
  7218. } elseif ($sType == "invoiceTrain") {
  7219. if ($currentColumn == 'A') {
  7220. $excel_column ['invoiceTitle'] = $val;
  7221. } elseif ($currentColumn == 'B')
  7222. $excel_column ['invoiceType'] = $val;
  7223. elseif ($currentColumn == 'C') {
  7224. $excel_column ['TIN'] = $val;
  7225. } elseif ($currentColumn == 'D') {
  7226. $excel_column ['address'] = $val;
  7227. } elseif ($currentColumn == 'E') {
  7228. $excel_column ['phone'] = $val;
  7229. } elseif ($currentColumn == 'F') {
  7230. $excel_column ['bank'] = $val;
  7231. } elseif ($currentColumn == 'G') {
  7232. $excel_column ['bankAccount'] = $val;
  7233. } elseif ($currentColumn == 'H') {
  7234. $excel_column ['invoiceElement'] = $val;
  7235. } elseif ($currentColumn == 'I') {
  7236. $excel_column ['invoiceQuantity'] = $val;
  7237. } elseif ($currentColumn == 'J') {
  7238. $excel_column ['invoiceUnitPrice'] = $val;
  7239. } elseif ($currentColumn == 'K') {
  7240. $excel_column ['remark'] = $val;
  7241. } elseif ($currentColumn == 'L') {
  7242. $excel_column ['recipientsAddress'] = $val;
  7243. } elseif ($currentColumn == 'M') {
  7244. $excel_column ['recipients'] = $val;
  7245. } elseif ($currentColumn == 'N') {
  7246. $excel_column ['recipientsPhone'] = $val;
  7247. }
  7248. } else {
  7249. if ($currentColumn == 'A')
  7250. $excel_column ['invoiceNo'] = $val;
  7251. elseif ($currentColumn == 'B')
  7252. $excel_column ['invoiceType'] = $val;
  7253. elseif ($currentColumn == 'C') {
  7254. $excel_column ['invoicePrice'] = $val;
  7255. } elseif ($currentColumn == 'D') {
  7256. $excel_column ['invoiceTitle'] = $val;
  7257. } elseif ($currentColumn == 'E') {
  7258. $excel_column ['userName'] = $val;
  7259. } elseif ($currentColumn == 'F') {
  7260. $excel_column ['categoryName'] = $val;
  7261. } elseif ($currentColumn == 'G') {
  7262. $excel_column ['invoiceElement'] = $val;
  7263. } elseif ($currentColumn == 'H') {
  7264. $excel_column ['remark'] = $val;
  7265. } elseif ($currentColumn == 'I') {
  7266. $excel_column ['date'] = $this->excelTime ( $val );
  7267. }
  7268. }
  7269. }
  7270. array_push ( $excel_array, $excel_column );
  7271. }
  7272. return $excel_array;
  7273. }
  7274. function excelTime($date, $time = false) {
  7275. if (function_exists ( 'GregorianToJD' )) {
  7276. if (is_numeric ( $date )) {
  7277. $jd = GregorianToJD ( 1, 1, 1970 );
  7278. $gregorian = JDToGregorian ( $jd + intval ( $date ) - 25569 );
  7279. $date = explode ( '/', $gregorian );
  7280. $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" : '');
  7281. return $date_str;
  7282. }
  7283. } else {
  7284. $date = $date > 25568 ? $date + 1 : 25569;
  7285. /* There was a bug if Converting date before 1-1-1970 (tstamp 0) */
  7286. $ofs = (70 * 365 + 17 + 2) * 86400;
  7287. $date = date ( "Y-m-d", ($date * 86400) - $ofs ) . ($time ? " 00:00:00" : '');
  7288. }
  7289. return $date;
  7290. }
  7291. /**
  7292. * 旧输入导入
  7293. */
  7294. function _GetFileEXT($filename) {
  7295. $pics = explode ( '.', $filename );
  7296. $num = count ( $pics );
  7297. return $pics [$num - 1];
  7298. }
  7299. function showCache($path = "", $sid = 0) {
  7300. // if (file_exists ( $path )) {
  7301. // $htm = file_get_contents ( $path );
  7302. // } else {
  7303. Doo::loadModel ( 'invoiceStatistics' );
  7304. $invoiceStatistics = new invoiceStatistics ();
  7305. $isBriefly = $invoiceStatistics->getBrieflyStatistics ( $sid );
  7306. $htm = '<tr><th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计开票</th>
  7307. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['invoicePrice'] . '</td>
  7308. <th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计入账</th>
  7309. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['accountPrice'] . '</td></tr>';
  7310. /*
  7311. * '<tr><th class="taC">今年累计开票</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['invoicePrice'] . '</td> <th class="taC">今年累计入账</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['accountPrice'] . '</td></tr>';
  7312. */
  7313. file_put_contents ( $path, $htm );
  7314. // }
  7315. return $htm;
  7316. }
  7317. /**
  7318. * 生成token
  7319. * @return string
  7320. */
  7321. function set_token() {
  7322. $str = md5 ( uniqid ( md5 ( microtime ( true ) ), true ) ); // 生成一个不会重复的字符串
  7323. $str = sha1 ( $str ); // 加密
  7324. return $str;
  7325. }
  7326. /**
  7327. * 获取get或者POST值
  7328. *
  7329. * @param string $name 属性名称
  7330. * @return fixed 值
  7331. */
  7332. function get_args($name) {
  7333. if (isset ( $_GET [$name] )) {
  7334. if (is_array ( $_GET [$name] ))
  7335. return $_GET [$name];
  7336. else
  7337. return addslashes ( $_GET [$name] );
  7338. } elseif (isset ( $_POST [$name] )) {
  7339. if (is_array ( $_POST [$name] ))
  7340. return $_POST [$name];
  7341. else
  7342. return addslashes ( $_POST [$name] );
  7343. } else
  7344. return false;
  7345. }
  7346. function SafeFilter(&$arr) {
  7347. $ra = Array (
  7348. '/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/',
  7349. '/script/',
  7350. '/javascript/',
  7351. '/vbscript/',
  7352. '/expression/',
  7353. '/applet/',
  7354. '/meta/',
  7355. '/xml/',
  7356. '/blink/',
  7357. '/link/',
  7358. '/style/',
  7359. '/embed/',
  7360. '/object/',
  7361. '/frame/',
  7362. '/layer/',
  7363. '/title/',
  7364. '/bgsound/',
  7365. '/base/',
  7366. '/onload/',
  7367. '/onunload/',
  7368. '/onchange/',
  7369. '/onsubmit/',
  7370. '/onreset/',
  7371. '/onselect/',
  7372. '/onblur/',
  7373. '/onfocus/',
  7374. '/onabort/',
  7375. '/onkeydown/',
  7376. '/onkeypress/',
  7377. '/onkeyup/',
  7378. '/onclick/',
  7379. '/ondblclick/',
  7380. '/onmousedown/',
  7381. '/onmousemove/',
  7382. '/onmouseout/',
  7383. '/onmouseover/',
  7384. '/onmouseup/',
  7385. '/onunload/'
  7386. );
  7387. if (is_array ( $arr )) {
  7388. foreach ( $arr as $key => $value ) {
  7389. if (! is_array ( $value )) {
  7390. if (! get_magic_quotes_gpc ()) // 不对magic_quotes_gpc转义过的字符使用addslashes(),避免双重转义。
  7391. {
  7392. $value = addslashes ( $value ); // 给单引号(')、双引号(")、反斜线(\)与 NUL(NULL 字符)加上反斜线转义
  7393. }
  7394. $value = preg_replace ( $ra, '', $value ); // 删除非打印字符,粗暴式过滤xss可疑字符串
  7395. $arr [$key] = htmlentities ( strip_tags ( $value ) ); // 去除 HTML 和 PHP 标记并转换为 HTML 实体
  7396. } else {
  7397. SafeFilter ( $arr [$key] );
  7398. }
  7399. }
  7400. }
  7401. }
  7402. /**
  7403. * Escape String
  7404. *
  7405. * @access public
  7406. * @param string
  7407. * @param bool whether or not the string will be used in a LIKE condition
  7408. * @return string
  7409. */
  7410. function escape_str($str, $like = FALSE) {
  7411. if (is_array ( $str )) {
  7412. foreach ( $str as $key => $val ) {
  7413. $str [$key] = $this->escape_str ( $val, $like );
  7414. }
  7415. return $str;
  7416. }
  7417. var_dump ( Doo::db ()->getDbObject () );
  7418. die ();
  7419. if (function_exists ( 'mysql_real_escape_string' ) and is_resource ( Doo::db ()->getDbObject () )) { // Doo::db ()->getDbObject()
  7420. $str = mysql_real_escape_string ( $str, Doo::db ()->getDbObject () );
  7421. } elseif (function_exists ( 'mysql_escape_string' )) {
  7422. $str = mysql_escape_string ( $str );
  7423. } else {
  7424. $str = addslashes ( $str );
  7425. }
  7426. // escape LIKE condition wildcards
  7427. if ($like === TRUE) {
  7428. $str = str_replace ( array (
  7429. '%',
  7430. '_'
  7431. ), array (
  7432. '\\%',
  7433. '\\_'
  7434. ), $str );
  7435. }
  7436. return $str;
  7437. }
  7438. /**
  7439. * 获得分页数据
  7440. * @param unknown_type $table
  7441. * @param unknown_type $condition
  7442. * @param unknown_type $on_page
  7443. * @param unknown_type $page_size
  7444. */
  7445. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  7446. $page_c = "";
  7447. $page ['previous'] = $this->get_previous ( $on_page );
  7448. $page ['on_page'] = $on_page;
  7449. $total_count = $this->get_table_count ( $table, $condition );
  7450. $total = intval ( $total_count / $page_size );
  7451. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  7452. $page ['total_data'] = $total_count;
  7453. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  7454. $i = 1;
  7455. $page_max = 1;
  7456. $page_width = 3;
  7457. if ($on_page >= $page_width) {
  7458. $page_max = intval ( $on_page / $page_width ) + 1;
  7459. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  7460. }
  7461. for(; $i <= $page ['total_page']; $i ++) {
  7462. if ($i == $on_page)
  7463. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  7464. else
  7465. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  7466. if ($i == ($page_width * $page_max))
  7467. break;
  7468. }
  7469. $page ['page'] = $page_c;
  7470. $page ['lower'] = (-- $on_page) * $page_size;
  7471. return $page;
  7472. }
  7473. /**
  7474. * 获取上一页
  7475. * @param unknown_type $on_page
  7476. */
  7477. function get_previous($on_page = 1) {
  7478. return $on_page != 0 ? $on_page - 1 : $on_page;
  7479. }
  7480. /**
  7481. * 获取总页数
  7482. * @param unknown_type $table
  7483. * @param unknown_type $condition
  7484. */
  7485. public function get_table_count($table = "", $condition = "") {
  7486. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  7487. $sql = "select count(*) as count from " . $table . " where " . $condition;
  7488. // echo $sql;die;
  7489. $query = Doo::db ()->query ( $sql );
  7490. $result = $query->fetch ();
  7491. return $result ['count'];
  7492. }
  7493. function isInvoiceNew($type = "GLOBAL") {
  7494. Doo::loadModel ( 'invoice' );
  7495. $invoice = new invoice ();
  7496. Doo::loadModel ( 'invoiceReceivables' );
  7497. $invoiceReceivables = new invoiceReceivables ();
  7498. Doo::loadModel ( 'staff' );
  7499. $staff = new staff ();
  7500. $st = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  7501. // 我的发票待处理
  7502. $pendingInvoice = $invoice->getOne ( array ( // or (status=2 and printStatus=1 and untreadStatus=0 ) or (status=2 and printStatus=1 and untreadStatus=2 )
  7503. 'where' => "(status=3 or status=4) and isDelete=0 and sid=" . $st [0] ['sid'],
  7504. 'desc' => 'iid',
  7505. 'asArray' => TRUE
  7506. ) );
  7507. // 我的收款待入账
  7508. /*
  7509. * $myClaim = $invoiceReceivables->getOne ( array ( 'where' => " receivablesStaff like '" . $st [0] ['sid'] . "-%' and receivablesCategory like '" . $st [0] ['cid'] . ":%' and bindStatus=0", 'desc' => 'irid', 'asArray' => TRUE ) );
  7510. */
  7511. // 发票审批
  7512. $approval = $invoice->getOne ( array (
  7513. 'where' => 'status=1 and pendingApprovals=' . $st [0] ['sid'],
  7514. 'desc' => 'iid',
  7515. 'asArray' => true
  7516. ) );
  7517. // 发票邮寄
  7518. $post = $invoice->getOne ( array (
  7519. 'where' => "postStatus=0 and printStatus=1 and isDelete=0 and doPost=1 and status=2",
  7520. 'asArray' => TRUE
  7521. ) );
  7522. // 发票打印
  7523. $print = $invoice->getOne ( array (
  7524. 'where' => "status=2 and printStatus=0 and untreadStatus=0 and moldManage like '%[\"" . $st [0] ['sid'] . "\",%'",
  7525. 'desc' => 'iid',
  7526. 'asArray' => TRUE
  7527. ) );
  7528. // 发票退票 printStatus=1 and
  7529. $untread = $invoice->getOne ( array (
  7530. 'where' => " untreadStatus=1 and status=2 ",
  7531. 'asArray' => TRUE
  7532. ) );
  7533. $new = array (
  7534. 'GLOBAL' => FALSE,
  7535. 'pendingInvoice' => FALSE,
  7536. // 'myClaim' => FALSE,
  7537. 'approval' => FALSE,
  7538. 'post' => FALSE,
  7539. 'print' => FALSE,
  7540. 'untread' => FALSE
  7541. );
  7542. // || ! empty ( $myClaim )
  7543. if (! empty ( $pendingInvoice ) || ! empty ( $approval ) || ! empty ( $post ) || ! empty ( $print ) || ! empty ( $untread ))
  7544. $new ['GLOBAL'] = TRUE;
  7545. if (! empty ( $pendingInvoice ))
  7546. $new ['pendingInvoice'] = TRUE;
  7547. // if (! empty ( $myClaim ))
  7548. // $new ['myClaim'] = TRUE;
  7549. if (! empty ( $approval ))
  7550. $new ['approval'] = TRUE;
  7551. if (! empty ( $post ))
  7552. $new ['post'] = TRUE;
  7553. if (! empty ( $print ))
  7554. $new ['print'] = TRUE;
  7555. if (! empty ( $untread ))
  7556. $new ['untread'] = TRUE;
  7557. return $new;
  7558. }
  7559. function setWXMsg($rid, $typeMsg = '') {
  7560. Doo::loadModel ( 'invoice' );
  7561. $invoice = new invoice ();
  7562. $invoiceDetail = $invoice->getOne ( array (
  7563. 'where' => 'iid=' . $rid,
  7564. 'asArray' => true
  7565. ) );
  7566. if (! empty ( $invoiceDetail )) {
  7567. Doo::loadModel ( 'staff' );
  7568. $staff = new staff ();
  7569. $staffmsg = $staff->getOne ( array (
  7570. 'where' => "sid='" . $invoiceDetail ['sid'] . "'",
  7571. 'asArray' => TRUE
  7572. ) );
  7573. if (! empty ( $staffmsg ['wxid'] )) {
  7574. require_once (SITE_PATH . '/protected/class/client.php');
  7575. $client = new client ( 'http://m.cld.smartcost.com.cn/' );
  7576. $user = $staffmsg ['wxid'];
  7577. $expCom = explode ( ":", $invoiceDetail ['expressCompany'] );
  7578. if (empty ( $expCom ))
  7579. $expCom [0] = '';
  7580. $msg = "";
  7581. if (empty ( $typeMsg ))
  7582. $msg = '太好了,您的发票' . $invoiceDetail ['invoiceSerial'] . ' 已邮寄 ' . $expCom [0] . ' ,快递号: <a href="https://m.kuaidi100.com/result.jsp?nu=' . $invoiceDetail ['expressNumber'] . '" >' . $invoiceDetail ['expressNumber'] . '</a>';
  7583. elseif ($typeMsg == "PRINT")
  7584. $msg = '太好了,您的发票已打印完成。';
  7585. $result = $client->SendMsg ( $user, $msg, 'text' );
  7586. }
  7587. }
  7588. }
  7589. /**
  7590. * 获取微信部门
  7591. * @param string $category
  7592. * @return number|mixed
  7593. */
  7594. function getToparty($category = '') {
  7595. $token = $this->getAccessToken (); //
  7596. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token={$token}&id=5" ), true );
  7597. $toparty = 0;
  7598. foreach ( $result ['department'] as $key => $value ) {
  7599. if ($value ['name'] == $category)
  7600. $toparty = $value ['id'];
  7601. }
  7602. return $toparty;
  7603. }
  7604. /**
  7605. * 获得某部门下的用户
  7606. * @param string $toparty
  7607. */
  7608. function getUserByToparty($toparty = '') {
  7609. $token = $this->getAccessToken (); //
  7610. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token={$token}&department_id={$toparty}" ), true );
  7611. $userList = array ();
  7612. foreach ( $result ['userlist'] as $key => $value ) {
  7613. array_push ( $userList, "'" . $value ['userid'] . "'" );
  7614. }
  7615. return $userList;
  7616. }
  7617. function msgSendToparty($msg, $title, $url, $toparty, $text = '') {
  7618. $token = $this->getAccessToken ();
  7619. if ($text == 'text') {
  7620. $data = '{
  7621. "touser": "' . $toparty . '",
  7622. "toparty": "",
  7623. "totag": "",
  7624. "msgtype": "text",
  7625. "agentid": 1000002,
  7626. "text": {
  7627. "content": "' . $msg . '"
  7628. },
  7629. "safe":0
  7630. }';
  7631. }
  7632. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  7633. if ($result->errmsg != 'ok') {
  7634. return 0;
  7635. } else {
  7636. return 1;
  7637. }
  7638. }
  7639. /**
  7640. * 获得可以发送微信用户列表
  7641. * @param string $category
  7642. * @return string
  7643. */
  7644. function getWxidByCategory($category = "") {
  7645. if (empty ( $category ))
  7646. return "";
  7647. Doo::loadModel ( 'staff' );
  7648. $staff = new staff ();
  7649. $toparty = $this->getToparty ( $category );
  7650. $wxList = array ();
  7651. $wxString = "";
  7652. if (! empty ( $toparty )) {
  7653. $userList = $this->getUserByToparty ( $toparty );
  7654. $userCon = implode ( ',', $userList );
  7655. // echo $userCon;
  7656. $sidList = $staff->getStaffByWxid ( $userCon );
  7657. foreach ( $sidList as $key => $value ) {
  7658. $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  7659. if ($falg) {
  7660. array_push ( $wxList, $value ['wxid'] );
  7661. }
  7662. }
  7663. $wxString = implode ( '|', $wxList );
  7664. }
  7665. return $wxString;
  7666. }
  7667. /**
  7668. * 读取发送信息规则判断是否需要发送
  7669. * @param number $sid
  7670. * @param string $sendType
  7671. * @return boolean
  7672. */
  7673. function isSendNotification($sid = 0, $sendType = '') {
  7674. Doo::loadModel ( "notificationConf" );
  7675. $notificationConf = new notificationConf ();
  7676. $detail = $notificationConf->getNotificationConfBySid ( $sid );
  7677. $conf = array ();
  7678. $sendFlag = true;
  7679. if (! empty ( $detail )) {
  7680. $conf = json_decode ( $detail ['conf'], true );
  7681. if (! empty ( $sendType )) {
  7682. if (isset ( $conf [$sendType] )) {
  7683. if ($conf [$sendType] == "CLOSE")
  7684. $sendFlag = false;
  7685. elseif ($conf [$sendType] == "Weekend") {
  7686. $day = date ( "w" );
  7687. if (1 <= $day && 5 >= $day)
  7688. $sendFlag = false;
  7689. } elseif ($conf [$sendType] == "OneToFriday") {
  7690. $day = date ( "w" );
  7691. if (0 == $day || 6 == $day)
  7692. $sendFlag = false;
  7693. }
  7694. }
  7695. } else
  7696. $sendFlag = false;
  7697. }
  7698. return $sendFlag;
  7699. }
  7700. /**
  7701. * 根据规则发送信息
  7702. * @param unknown $msg
  7703. * @param unknown $title
  7704. * @param unknown $url
  7705. * @param unknown $user
  7706. * @param string $text
  7707. * @return number
  7708. */
  7709. private function msgSend($msg, $title, $url, $user, $sid = 0, $sendType = '') {
  7710. $token = $this->getAccessToken ();
  7711. $falg = $this->isSendNotification ( $sid, $sendType );
  7712. // if ($text == 'text') {
  7713. // $data = '{
  7714. // "touser": "' . $user . '",
  7715. // "toparty": "",
  7716. // "totag": "",
  7717. // "msgtype": "text",
  7718. // "agentid": 1000002,
  7719. // "text": {
  7720. // "content": "' . $msg . '"
  7721. // },
  7722. // "safe":0
  7723. // }';
  7724. // } else {
  7725. $data = '{
  7726. "touser": "' . $user . '",
  7727. "toparty": "",
  7728. "totag": "",
  7729. "msgtype": "news",
  7730. "agentid": 1000002,
  7731. "news": {
  7732. "articles":[
  7733. {
  7734. "title": "' . $title . '",
  7735. "description": "' . $msg . '",
  7736. "url": "' . $url . '",
  7737. "picurl": ""
  7738. }
  7739. ]
  7740. }
  7741. }';
  7742. // }
  7743. if ($falg) {
  7744. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  7745. if ($result->errmsg != 'ok') {
  7746. return 0;
  7747. } else {
  7748. return 1;
  7749. }
  7750. } else
  7751. return 0;
  7752. }
  7753. private function getAccessToken() {
  7754. // access_token 应该全局存储与更新,以下代码以写入到文件中做示例
  7755. // $file = './access_token.txt';
  7756. // $data = json_decode ( file_get_contents ( $file ) );
  7757. // if ($data->expire_time < time () or ! $data->expire_time) {
  7758. // 如果是企业号用以下URL获取access_token
  7759. $url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$this->appId&corpsecret=$this->appSecret";
  7760. // $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$this->appId&secret=$this->appSecret";
  7761. $res = json_decode ( $this->httpGet ( $url ) );
  7762. $access_token = $res->access_token;
  7763. // echo $access_token;
  7764. // if ($access_token) {
  7765. // $data->expire_time = time () + 7000;
  7766. // $data->access_token = $access_token;
  7767. // $fp = fopen ( $file, "w" );
  7768. // fwrite ( $fp, json_encode ( $data ) );
  7769. // fclose ( $fp );
  7770. // }
  7771. // } else {
  7772. // $access_token = $data->access_token;
  7773. // }
  7774. return $access_token;
  7775. }
  7776. private function httpGet($url) {
  7777. $curl = curl_init ();
  7778. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  7779. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  7780. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  7781. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  7782. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  7783. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  7784. curl_setopt ( $curl, CURLOPT_URL, $url );
  7785. $res = curl_exec ( $curl );
  7786. curl_close ( $curl );
  7787. return $res;
  7788. }
  7789. private function httpPost($url, $data) {
  7790. $curl = curl_init ();
  7791. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  7792. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  7793. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  7794. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  7795. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  7796. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  7797. curl_setopt ( $curl, CURLOPT_URL, $url );
  7798. curl_setopt ( $curl, CURLOPT_POST, 1 );
  7799. curl_setopt ( $curl, CURLOPT_POSTFIELDS, $data );
  7800. $res = curl_exec ( $curl );
  7801. curl_close ( $curl );
  7802. return $res;
  7803. }
  7804. }
  7805. ?>