InvoiceController.php 328 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036
  1. <?php
  2. /**
  3. * 开票功能控制器
  4. * @author CP
  5. * @version 1.0
  6. * @namespace invoice
  7. * @package invoiceController
  8. */
  9. class InvoiceController extends DooController {
  10. public $staff;
  11. public $NEW;
  12. public $data;
  13. private $INVOICEKEY = "APPROVAL";
  14. private $INVOICECOLLECTPATH = "protected/cache/invoiceCollect/";
  15. private $ACTION = '';
  16. private $appId = 'wx3ee46531947a1384';
  17. private $appSecret = 'awGWzy3J5q_96VXKBLA2BQ9RpiT0LiPXnkMF-xV6h5o'; // awGWzy3J5q_96VXKBLA2BXU6mVCGynPGD-sxUCsdNDE //'PeiQVH8tbQE7pM9pVO4AIPlX9FFNpwu7O6Iy6VFcAVtpjTA3Qn42dbNmktBFkUHo';
  18. public function beforeRun($resource, $action) {
  19. Doo::loadModel ( "invoiceManage" );
  20. $invoiceManage = new invoiceManage ();
  21. Doo::loadClass ( 'XDeode' );
  22. $XDeode = new XDeode ( 5 );
  23. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  24. header ( 'Content-Type:text/html;charset=utf-8' );
  25. $moldList = $invoiceManage->getInvoiceByStaff ( $sid );
  26. if (empty ( $moldList )) {
  27. $flag = false;
  28. $uGroups = 'ordinary';
  29. if (Doo::acl ()->isAllowed ( $uGroups, $resource, $action )) {
  30. $flag = true;
  31. }
  32. } else {
  33. $flag = false;
  34. array_push ( $moldList, array (
  35. 'mold' => 'ordinary'
  36. ) );
  37. // 删除审批人后-加入权限问题-暂时关闭
  38. $fileInvoice = file_get_contents ( "protected/config/invoice/invoice.ini" );
  39. $fiML = json_decode ( $fileInvoice, true );
  40. if (empty ( $fiML ))
  41. $fiML = array ();
  42. foreach ( $fiML as $key => $value ) {
  43. $sidList = explode ( ',', $value );
  44. foreach ( $sidList as $k => $v ) {
  45. if ($v == $sid) {
  46. array_push ( $moldList, array (
  47. 'mold' => $key
  48. ) );
  49. break;
  50. }
  51. }
  52. }
  53. foreach ( $moldList as $value ) {
  54. if (Doo::acl ()->isAllowed ( $value ['mold'], $resource, $action )) {
  55. $flag = true;
  56. break;
  57. }
  58. }
  59. }
  60. /*
  61. * Doo::acl()->isAllowed($uGroups['groups'], $resource, $action);
  62. */
  63. // 单独判断办事处汇总的访问权限 invoiceAggregateCategoryDetail,invoiceAggregateStaffDetail
  64. if ($action == 'invoiceAggregateCategoryDetail' || $action == 'invoiceAggregateStaffDetail') {
  65. Doo::loadModel ( "invoiceCategoryManage" );
  66. $invoiceCategoryManage = new invoiceCategoryManage ();
  67. $icm = $invoiceCategoryManage->getInvoiceCMByStaff ( $sid );
  68. if (empty ( $icm ))
  69. die ( 'illegal request-iacd' );
  70. }
  71. // 单独判断应收款访问权限
  72. if ($action == 'invoiceAggregateCompanyDetail') {
  73. Doo::loadModel ( "invoiceCompanyManage" );
  74. $invoiceCompanyManage = new invoiceCompanyManage ();
  75. $icm = $invoiceCompanyManage->getInvoiceCMByStaff ( $sid );
  76. if (empty ( $icm ))
  77. die ( 'illegal request' );
  78. }
  79. // 主权限获得与判断
  80. Doo::loadModel ( 'staff' );
  81. $staff = new staff ();
  82. $detail = $staff->getStaffBySid ( $_COOKIE ["staff"] );
  83. $accessModular = 'INVOICE';
  84. if (empty ( $detail ['cldAccessArray'] ))
  85. die ( 'illegal request' );
  86. else {
  87. if (in_array ( $accessModular, $detail ['cldAccessArray'] )) {
  88. if (Doo::acl ()->isAllowed ( $accessModular, $resource, $action )) {
  89. $flag = true;
  90. } else {
  91. $flag = false;
  92. }
  93. } else {
  94. die ( 'illegal request' );
  95. }
  96. }
  97. if (! $flag)
  98. die ( 'illegal request' );
  99. }
  100. function __construct() {
  101. //echo $routeRs ['1'];
  102. //die('dd');
  103. if (isset ( $_COOKIE ["staff"] )) {
  104. if (! empty ( $_COOKIE ["staff"] )) {
  105. Doo::loadModel ( 'staff' );
  106. $staff = new staff ();
  107. $uriPartsOrig = explode ( '/', $_SERVER ['REQUEST_URI'] );
  108. $this->ACTION = $uriPartsOrig [1];
  109. $this->data ['new'] = $this->isInvoiceNew ();
  110. $this->staff = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  111. $this->data ['isStaffCompleteMsg'] = false;
  112. $detail = $staff->checkStaffInfoIsComplete ( $_COOKIE ["staff"] );
  113. if (! empty ( $detail ))
  114. $this->data ['isStaffCompleteMsg'] = true;
  115. return "/";
  116. }
  117. }
  118. Doo::loadCore ( 'uri/DooUriRouter' );
  119. $router = new DooUriRouter ();
  120. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  121. if ($routeRs ['1'] != "login") {
  122. header ( 'Content-Type:text/html;charset=utf-8' );
  123. @header ( "Location: /login" );
  124. }
  125. }
  126. function testSend() {
  127. // 测试根据规则发送信息 普通发送
  128. // $pendingApprovalsSid = 41;
  129. // Doo::loadModel ( 'staff' );
  130. // $staff = new staff ();
  131. // $username2 = $staff->getOne ( array ( 'select' => 'wxid', 'where' => 'sid=' . $pendingApprovalsSid, 'asArray' => TRUE ) );
  132. // // 发送微信审批通知
  133. // $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  134. // $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  135. // Doo::loadModel ( 'staff' );
  136. // $staff = new staff ();
  137. // $toparty = $this->getToparty ( '广东办' );
  138. // $wxList = array ();
  139. // if (! empty ( $toparty )) {
  140. // $userList = $this->getUserByToparty ( $toparty );
  141. // $userCon = implode ( ',', $userList );
  142. // // echo $userCon;
  143. // $sidList = $staff->getStaffByWxid ( $userCon );
  144. // foreach ( $sidList as $key => $value ) {
  145. // $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  146. // if ($falg) {
  147. // array_push ( $wxList, $value ['wxid'] );
  148. // }
  149. // }
  150. // $wxString = implode ( '|', $wxList );
  151. // print_r ( $wxList );
  152. // echo $wxString;
  153. // }
  154. // 测试发送
  155. /*
  156. * //$toparty = $this->getWxidByCategory( $receivablesCategory [1] ); $toparty = $this->getToparty ( $receivablesCategory [1] ); $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。'; if ($toparty != 0) $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  157. */
  158. // print_r ( $userList );
  159. // $msTouser='caipin|outaozhen';
  160. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  161. // $title2 = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  162. // $hfreult = $this->msgSend ( '', $title2, '', 'outaozhen' );
  163. // $toparty= $this->getToparty('广东办');
  164. // $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  165. // $toparty = 26;
  166. // $msg = '';
  167. // $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/1.html';
  168. // $hfreult = $this->msgSendToparty ( $msg, '', '', $toparty,'text' );
  169. }
  170. function invoice() {
  171. Doo::loadModel ( 'invoice' );
  172. $invoice = new invoice ();
  173. Doo::loadModel ( 'express' );
  174. $express = new express ();
  175. $expressList = $express->getExpressByAll ();
  176. $this->data ['expressList'] = $expressList;
  177. // Doo::loadModel ( 'invoiceReceivables' );
  178. // $invoiceReceivables = new invoiceReceivables ();
  179. // $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  180. Doo::loadClass ( 'XDeode' );
  181. $XDeode = new XDeode ( 5 );
  182. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  183. Doo::loadModel ( 'invoiceStatistics' );
  184. $invoiceStatistics = new invoiceStatistics ();
  185. $isMonth = $invoiceStatistics->getStatisticsByMonth ( $sid );
  186. // 缓存统计结果
  187. $year = date ( "Y" );
  188. $tmp_date = date ( "Ym" );
  189. $tmp_year = substr ( $tmp_date, 0, 4 );
  190. $tmp_mon = substr ( $tmp_date, 4, 2 );
  191. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  192. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  193. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . "_" . $sid . ".htm";
  194. if (is_file ( $path ))
  195. $htm = file_get_contents ( $path );
  196. else
  197. $htm = $this->showCache ( $path, $sid );
  198. $invoiceList = $invoice->getMyInvoice ( $sid );
  199. $sql = 'status=2 and printStatus=1 and irid!="" and sid=' . $sid;
  200. $list = $invoice->getInvoiceByUntreadStatusPage ( 4, $sql );
  201. // 我的待入账发票 and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  202. $sql = "status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid=" . $sid;
  203. $myInvoiceUnAccount = $invoice->getInvoiceByUntreadStatusPage ( 4, $sql );
  204. // 获得已退票功能
  205. $untreadStatusList = $invoice->getMyInvoiceByUntreadStatus ( 2, 0, 5, $sid );
  206. $this->data ['untreadStatusList'] = $untreadStatusList;
  207. // print_r($untreadStatusList);
  208. $this->data ['isMonth'] = $isMonth;
  209. $this->data ['htm'] = $htm;
  210. $this->data ['invoiceList'] = $invoiceList;
  211. $this->data ['receivablesList'] = $list;
  212. $this->data ['myInvoiceUnAccount'] = $myInvoiceUnAccount;
  213. $this->data ['memu'] = "invoice";
  214. $this->data ['staff'] = $this->staff;
  215. $this->data ['receiptMemu'] = 'invoice';
  216. $this->render ( "/admin/invoice", $this->data );
  217. }
  218. function invoiceExpress() {
  219. $expressCom = isset ( $this->params ['expressCom'] ) ? $this->params ['expressCom'] : "";
  220. $expressNumber = isset ( $this->params ['expressNumber'] ) ? $this->params ['expressNumber'] : "";
  221. $this->data ['expressCom'] = $expressCom;
  222. $this->data ['expressNumber'] = $expressNumber;
  223. $this->render ( "/admin/invoiceExpress", $this->data );
  224. }
  225. function invoiceAdd() {
  226. session_start ();
  227. /*Doo::loadModel ( 'invoice' );
  228. $invoice = new invoice ();
  229. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );*/
  230. Doo::loadModel ( 'L_category' );
  231. $lCategory = new L_category ();
  232. $category = $lCategory->find ( array (
  233. 'asArray' => true
  234. ) );
  235. $this->data ['category'] = $category;
  236. Doo::loadModel ( 'invoiceTraining' );
  237. $invoiceTraining = new invoiceTraining ();
  238. $itList = $invoiceTraining->getInvoiceTrainingByCid ( $this->staff [0] ['cid'] );
  239. Doo::loadModel ( 'receipt' );
  240. $receipt = new receipt ();
  241. foreach ( $itList as $key => $value ) { // 不展示已结算完结的培训班
  242. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $value ['itid'] );
  243. if (! empty ( $receiptDetail )) {
  244. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9) {
  245. unset ( $itList [$key] );
  246. }
  247. }
  248. }
  249. $this->data ['itList'] = $itList;
  250. $token = $this->set_token ();
  251. $tokenTime=time().rand(5, 15);
  252. $_SESSION ['token_' . $this->staff [0] ['sidKey'].'_'.$tokenTime] = $token;
  253. $this->data ['token'] = $token;
  254. $this->data['tokenTime']=$tokenTime;
  255. $this->data ['memu'] = "invoice";
  256. $this->data ['staff'] = $this->staff;
  257. $this->data ['receiptMemu'] = 'invoice';
  258. $this->render ( "/admin/invoiceAdd", $this->data );
  259. }
  260. /**
  261. * 自更新发票信息库
  262. * @param unknown $invoicePrintDetail
  263. */
  264. function autoUpdateInvoiceInfoBase($invoicePrintDetail) {
  265. // 发票信息库
  266. Doo::loadModel ( 'invoiceInfoBase' );
  267. $invoiceInfoBase = new invoiceInfoBase ();
  268. $updateDate = strtotime ( $invoicePrintDetail ['date'] );
  269. $TIN = $invoicePrintDetail ['TIN'];
  270. $invoiceTitle = $invoicePrintDetail ['invoiceTitle'];
  271. if (empty ( $invoiceTitle ))
  272. $invoiceTitle = $invoicePrintDetail ['invoiceCompany'];
  273. $IIBList = $invoiceInfoBase->getInvoiceInfoByTT ( $TIN, $invoiceTitle );
  274. // 确认有该条发票信息
  275. $invoiceInfoBase = new invoiceInfoBase ();
  276. if (! empty ( $IIBList )) {
  277. // 发票库里的信息数量
  278. $IIBListCount = count ( $IIBList );
  279. if ($IIBListCount == 1) { // 更新发票--提交是最新的时间
  280. $item = array (
  281. 'iibID' => $IIBList [0] ['iibID'],
  282. 'invoiceTitle' => $invoiceTitle,
  283. 'TIN' => $TIN
  284. );
  285. if (! empty ( $invoicePrintDetail ['address'] )) {
  286. $item += array (
  287. 'address' => $invoicePrintDetail ['address']
  288. );
  289. }
  290. if (! empty ( $invoicePrintDetail ['phone'] )) {
  291. $item += array (
  292. 'phone' => $invoicePrintDetail ['phone']
  293. );
  294. }
  295. if (! empty ( $invoicePrintDetail ['bank'] )) {
  296. $item += array (
  297. 'bank' => $invoicePrintDetail ['bank']
  298. );
  299. }
  300. if (! empty ( $invoicePrintDetail ['bankAccount'] )) {
  301. $item += array (
  302. 'bankAccount' => $invoicePrintDetail ['bankAccount']
  303. );
  304. }
  305. if ($updateDate >= strtotime ($IIBList [0] ['updateDate'])) {
  306. $item += array (
  307. 'updateDate' => $invoicePrintDetail ['date']
  308. );
  309. $invoiceInfoBase->setInvoiceInfoBaseByCondition ( $item );
  310. }
  311. } else { // 删除多张发票,重新添加发票
  312. $iibIDStr = '';
  313. $iibID = array ();
  314. foreach ( $IIBList as $key => $value ) {
  315. array_push ( $iibID, $value ['iibID'] );
  316. }
  317. $iibIDStr = implode ( ",", $iibID ); // 删除
  318. $invoiceInfoBase->delInvoiceInfoBaseByIibStr ( $iibIDStr );
  319. $item = array (
  320. 'invoiceTitle' => $invoiceTitle,
  321. 'TIN' => $TIN,
  322. 'address' => $invoicePrintDetail ['address'],
  323. 'phone' => $invoicePrintDetail ['phone'],
  324. 'bank' => $invoicePrintDetail ['bank'],
  325. 'bankAccount' => $invoicePrintDetail ['bankAccount'],
  326. 'updateDate' => $invoicePrintDetail ['date']
  327. );
  328. $invoiceInfoBase->addInvoiceInfoBase ( $item );
  329. }
  330. } else { // 没有新增发票信息
  331. $item = array (
  332. 'invoiceTitle' => $invoiceTitle,
  333. 'TIN' => $TIN,
  334. 'address' => $invoicePrintDetail ['address'],
  335. 'phone' => $invoicePrintDetail ['phone'],
  336. 'bank' => $invoicePrintDetail ['bank'],
  337. 'bankAccount' => $invoicePrintDetail ['bankAccount'],
  338. 'updateDate' => $invoicePrintDetail ['date']
  339. );
  340. $invoiceInfoBase->addInvoiceInfoBase ( $item );
  341. }
  342. }
  343. function invoiceAddFill() {
  344. session_start ();
  345. Doo::loadModel ( 'L_category' );
  346. $lCategory = new L_category ();
  347. $category = $lCategory->find ( array (
  348. 'asArray' => true
  349. ) );
  350. $this->data ['category'] = $category;
  351. Doo::loadModel ( 'invoiceTraining' );
  352. $invoiceTraining = new invoiceTraining ();
  353. $itList = $invoiceTraining->getInvoiceTrainingByCid ( $this->staff [0] ['cid'] );
  354. $this->data ['itList'] = $itList;
  355. Doo::loadModel ( 'invoice' );
  356. $invoice = new invoice ();
  357. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );
  358. $detail ['mailItemsArray'] = json_decode ( $detail ['mailItemsJson'], true );
  359. $token = $this->set_token ();
  360. $tokenTime=time().rand(5, 15);
  361. $_SESSION ['token_' . $this->staff [0] ['sidKey'].'_'.$tokenTime] = $token;
  362. $this->data ['token'] = $token;
  363. $this->data['tokenTime']=$tokenTime;
  364. $this->data ['invoiceDetail'] = $detail;
  365. $this->data ['memu'] = "invoice";
  366. $this->data ['staff'] = $this->staff;
  367. $this->data ['receiptMemu'] = 'invoice';
  368. $this->render ( "/admin/invoiceAddFill", $this->data );
  369. }
  370. /**
  371. * 提交一份开票申请,并记录下操作日志
  372. *
  373. * @since 1.0.0
  374. * @var integer cid 办事处ID
  375. * @var integer invoiceType 发票类型
  376. * @var integer doPost 是否邮寄
  377. * @var integer invoicePrice 开票金额
  378. * @var string invoiceElement 开票内容
  379. * @var string invoiceTitle 发票抬头
  380. * @var string invoiceCompany 单位名称
  381. * @var string TIN 纳税人识别码
  382. * @var string address 注册地址
  383. * @var string phone 注册电话
  384. * @var string bank 开户银行
  385. * @var string bankAccount 银行账户
  386. * @var string recipients 收件人
  387. * @var string recipientsPhone 收件人手机/电话
  388. * @var string recipientsAddress 收件地址
  389. * @var string mailItems 邮寄物品
  390. * @var string remark 备注
  391. * @return string 返回跳转开票主页路径
  392. */
  393. function invoiceAddDo() {
  394. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  395. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  396. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  397. // $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  398. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  399. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  400. $invoiceForm = $this->get_args ( 'invoiceForm' ) ? $this->get_args ( 'invoiceForm' ) : "";
  401. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  402. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  403. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  404. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  405. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  406. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  407. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  408. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  409. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  410. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  411. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  412. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  413. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  414. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  415. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  416. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  417. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  418. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  419. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  420. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  421. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  422. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  423. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  424. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  425. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  426. $trainId = $this->get_args ( 'trainId' ) ? $this->get_args ( 'trainId' ) : 0;
  427. $settlementType = $this->get_args ( 'settlementType' ) ? $this->get_args ( 'settlementType' ) : "";
  428. $electronicPhone= $this->get_args ( 'electronicPhone' ) ? $this->get_args ( 'electronicPhone' ) : "";
  429. $electronicEmail = $this->get_args ( 'electronicEmail' ) ? $this->get_args ( 'electronicEmail' ) : "";
  430. /*
  431. * $mailList=array(); array_push($mailList, array('invoice'=>1)); array_push($mailList, array('mailItems'=>$mailItems)); if (!empty($softLock)) array_push($mailList, array('softLock'=>$softLockNum)); if (!empty($contract)) array_push($mailList, array('contract'=>$contractNum)); if (!empty($instructions)) array_push($mailList, array('instructions'=>$instructionsNum)); if (!empty($remittance)) array_push($mailList, array('remittance'=>$remittance)); echo json_encode($mailList) ; print_r($mailList); die;
  432. */
  433. $token = $this->get_args ( 'token' ) ? $this->get_args ( 'token' ) : "";
  434. $tokenTime = $this->get_args ( 'tokenTime' ) ? $this->get_args ( 'tokenTime' ) : "";
  435. if (empty ( $token )) {
  436. die ( 'illegal request-token' );
  437. } else {
  438. session_start ();
  439. $sessionKey='token_' . $this->staff [0] ['sidKey'].'_'.$tokenTime;
  440. header ( 'Content-Type:text/html;charset=utf-8' );
  441. if (!isset($_SESSION [$sessionKey])||empty($_SESSION [$sessionKey])) {
  442. die ( '请重新刷新发票申请页面' );
  443. }elseif($_SESSION [$sessionKey]=='repeat'){
  444. die ( '请勿重复申请发票' );
  445. } else {
  446. if ($_SESSION [$sessionKey] != $token){
  447. die ( '请勿重复申请发票' );
  448. }else{
  449. $_SESSION [$sessionKey] = 'repeat';
  450. }
  451. }
  452. }
  453. if($invoiceForm=='electronic'){
  454. if(empty(trim($electronicPhone))&&empty(trim($electronicEmail))){
  455. die ( '请至少填写一种联系方式--电子发票' );
  456. }
  457. }
  458. if ($invoiceType == 1) {
  459. $temporary = $invoiceQuantity * $invoiceUnitPrice;
  460. if ($temporary > 100001) {
  461. header ( 'Content-Type:text/html;charset=utf-8' );
  462. die ( '专用发票总金额暂时不能超过100000.00(一万)元。' );
  463. // die ( 'illegal request-Please priceError' );
  464. }
  465. }elseif($invoiceType == 0){
  466. }else{
  467. die ( 'illegal request-invoiceType' );
  468. }
  469. if (empty ( $this->staff [0] ))
  470. die ( 'illegal request-Please login' );
  471. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $settlementType )&&!empty($invoiceForm)) {
  472. Doo::loadModel ( 'invoice' );
  473. $invoice = new invoice ();
  474. Doo::loadModel ( 'L_category' );
  475. $lCategory = new L_category ();
  476. Doo::loadModel ( 'invoiceManage' );
  477. $invoiceManage = new invoiceManage ();
  478. Doo::loadModel ( 'invoiceOperationLog' );
  479. $invoiceOperationLog = new invoiceOperationLog ();
  480. Doo::loadClass ( 'XDeode' );
  481. $XDeode = new XDeode ( 5 );
  482. $trainId = $XDeode->decode ( $trainId );
  483. $categoryDetil = $lCategory->getOne ( array (
  484. 'SELECT' => 'title',
  485. 'where' => 'cid=' . $cid,
  486. 'asArray' => true
  487. ) );
  488. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  489. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  490. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  491. // print_r(current($invoiceManageDetail ['staffList']));
  492. // die;
  493. $moldManage = array ();
  494. foreach ( $invoiceManageList as $key => $value ) {
  495. if ($value ['mold'] == '发票打印')
  496. $moldManage [$value ['mold']] = $value ['staffList'];
  497. elseif ($value ['mold'] == '发票邮寄')
  498. $moldManage [$value ['mold']] = $value ['staffList'];
  499. elseif ($value ['mold'] == '发票退票')
  500. $moldManage [$value ['mold']] = $value ['staffList'];
  501. }
  502. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  503. $st = '';
  504. if ($settlementType == 'SOFTWARE') {
  505. $st = 0;
  506. $trainId = 0;
  507. } elseif ($settlementType == 'TRAINING') {
  508. $st = 1;
  509. if (empty ( $trainId ) && ! is_numeric ( $trainId )) {
  510. die ( 'illegal request-trainingIdError' );
  511. }
  512. } else {
  513. die ( 'illegal request-settlementError' );
  514. }
  515. if($invoiceForm=='electronic'){
  516. $invoiceSerial="#FE" . date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
  517. $invoiceForm=1;
  518. $invoiceType=0;
  519. if(!empty($electronicPhone)||!empty($electronicEmail)){
  520. }else{
  521. die ( 'illegal request-electronicContact' );
  522. }
  523. $mailList = array ();
  524. $mailString = '备注:' . $mailItems;
  525. }elseif($invoiceForm=='paper'){
  526. $invoiceSerial="#F" . date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
  527. $invoiceForm=0;
  528. $mailList = array (
  529. 'invoice' => 1,
  530. 'mailItems' => $mailItems
  531. );
  532. $mailString = '发票x1张,备注:' . $mailItems;
  533. }else{
  534. die ( 'illegal request-invoiceForm' );
  535. }
  536. $item = array (
  537. 'cid' => $cid,
  538. 'categoryName' => $categoryDetil ['title'],
  539. 'invoiceElement' => $invoiceElement,
  540. 'invoiceForm'=>$invoiceForm,
  541. 'electronicPhone'=>$electronicPhone,
  542. 'electronicEmail'=>$electronicEmail,
  543. 'invoiceQuantity' => $invoiceQuantity,
  544. 'invoiceUnitPrice' => $invoiceUnitPrice,
  545. 'invoicePrice' => $invoicePrice,
  546. 'invoiceType' => $invoiceType,
  547. 'settlementType' => $st,
  548. 'doPost' => $doPost,
  549. 'status' => 1,
  550. 'invoiceSerial' => $invoiceSerial,
  551. 'date' => date ( "Y-m-d H:i:s" ),
  552. 'updateTime' => date ( "Y-m-d H:i:s" ),
  553. 'sid' => $this->staff [0] ['sid'],
  554. 'userName' => $this->staff [0] ['username'],
  555. 'invoiceManage' => $invoiceManageDetail ['staff'],
  556. 'pendingApprovals' => $pendingApprovalsSid,
  557. 'moldManage' => json_encode ( $moldManage ),
  558. 'remark' => $remark,
  559. 'trainId' => $trainId
  560. );
  561. if ($invoiceType == 0)
  562. $item += array (
  563. 'invoiceTitle' => $invoiceTitle,
  564. 'TIN' => $TINT,
  565. 'address' => $addressT,
  566. 'phone' => $phoneT,
  567. 'bank' => $bankT,
  568. 'bankAccount' => $bankAccountT
  569. );
  570. else {
  571. $item += array (
  572. 'invoiceCompany' => $invoiceCompany,
  573. 'TIN' => $TIN,
  574. 'address' => $address,
  575. 'phone' => $phone,
  576. 'bank' => $bank,
  577. 'bankAccount' => $bankAccount
  578. );
  579. }
  580. if ($doPost == 1) {
  581. if (! empty ( $softLock ))
  582. $mailList += array (
  583. 'softLock' => $softLockNum
  584. );
  585. else
  586. $mailList += array (
  587. 'softLock' => 0
  588. );
  589. if (! empty ( $contract ))
  590. $mailList += array (
  591. 'contract' => $contractNum
  592. );
  593. else
  594. $mailList += array (
  595. 'contract' => 0
  596. );
  597. if (! empty ( $instructions ))
  598. $mailList += array (
  599. 'instructions' => $instructionsNum
  600. );
  601. else
  602. $mailList += array (
  603. 'instructions' => 0
  604. );
  605. if (! empty ( $remittance ))
  606. $mailList += array (
  607. 'remittance' => $remittance
  608. );
  609. else
  610. $mailList += array (
  611. 'remittance' => ''
  612. );
  613. if (! empty ( $softLock ))
  614. $mailString .= ',软件锁x' . $softLockNum . '个';
  615. if (! empty ( $contract ))
  616. $mailString .= ',合同x' . $contractNum . '份';
  617. if (! empty ( $instructions ))
  618. $mailString .= ',说明书x' . $instructionsNum . '本';
  619. if (! empty ( $remittance ))
  620. $mailString .= ',汇款账号单(张)';
  621. $item += array (
  622. 'recipients' => $recipients,
  623. 'recipientsPhone' => $recipientsPhone,
  624. 'recipientsAddress' => $recipientsAddress,
  625. 'mailItems' => $mailString,
  626. 'mailItemsJson' => json_encode ( $mailList )
  627. );
  628. }
  629. $iid = $invoice->addInvoice ( $item );
  630. // 如果是培训班结算 创建培训班发票到培训班备份中
  631. if (! empty ( $st ) && $st == 1) {
  632. Doo::loadModel ( 'invoiceStore' );
  633. $invoiceStore = new invoiceStore ();
  634. Doo::loadModel ( 'invoiceTraining' );
  635. $invoiceTraining = new invoiceTraining ();
  636. $isid = $invoiceStore->setInvoiceToInvoiceStore ( $iid );
  637. $itemIS = array (
  638. 'isid' => $isid,
  639. 'ipSource' => 1,
  640. 'apStatus' => 1,
  641. 'iid' => $iid
  642. );
  643. $invoiceStore->setInvoiceStoreByCondition ( $itemIS );
  644. // 更新培训班总数量
  645. $detailIT = $invoiceTraining->getInvoiceTrainingByItid ( $trainId );
  646. $item = array (
  647. 'itid' => $trainId,
  648. 'invoiceTotal' => $detailIT ['invoiceTotal'] + 1,
  649. 'submitStatus' => 1
  650. );
  651. $itid = $invoiceTraining->setInvoiceTrainByCondition ( $item );
  652. }
  653. // 操作日志
  654. $item = array (
  655. 'date' => date ( "Y-m-d H:i:s" ),
  656. 'operation' => "创建",
  657. 'status' => 1,
  658. 'img' => $this->staff [0] ['avatar'],
  659. 'username' => $this->staff [0] ['username'],
  660. 'uid' => $this->staff [0] ['sid'],
  661. 'category' => $this->staff [0] ['category'],
  662. 'iid' => $iid
  663. );
  664. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  665. $item = array (
  666. 'date' => date ( "Y-m-d H:i:s" ),
  667. 'operation' => "提交审批",
  668. 'status' => 1,
  669. 'img' => $this->staff [0] ['avatar'],
  670. 'username' => $this->staff [0] ['username'],
  671. 'uid' => $this->staff [0] ['sid'],
  672. 'category' => $this->staff [0] ['category'],
  673. 'iid' => $iid
  674. );
  675. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  676. Doo::loadModel ( 'staff' );
  677. $staff = new staff ();
  678. $username2 = $staff->getOne ( array (
  679. 'select' => 'wxid',
  680. 'where' => 'sid=' . $pendingApprovalsSid,
  681. 'asArray' => TRUE
  682. ) );
  683. // 发送微信审批通知
  684. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  685. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  686. }
  687. return "/invoice";
  688. }
  689. function invoiceEdit() {
  690. Doo::loadClass ( 'XDeode' );
  691. $XDeode = new XDeode ( 5 );
  692. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  693. $iid = $XDeode->decode ( $iid );
  694. if (! is_numeric ( $iid ))
  695. die ( 'illegal request' );
  696. Doo::loadModel ( 'invoice' );
  697. $invoice = new invoice ();
  698. Doo::loadModel ( 'invoiceOperationLog' );
  699. $invoiceOperationLog = new invoiceOperationLog ();
  700. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  701. $operation = $invoiceOperationLog->getInvoiceOperationByDropped ( $iid );
  702. $invoiceDetail ['mailItemsJson'] ='';
  703. if(isset($invoiceDetail ['mailItemsJson'])){
  704. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  705. }
  706. $this->data ['operation'] = $operation;
  707. $this->data ['invoiceDetail'] = $invoiceDetail;
  708. $this->data ['memu'] = "invoice";
  709. $this->data ['staff'] = $this->staff;
  710. $this->data ['receiptMemu'] = 'invoice';
  711. $this->render ( "/admin/invoiceEdit", $this->data );
  712. }
  713. /**
  714. * 重新编辑退回的发票
  715. * @return string
  716. */
  717. function invoiceEditDo() {
  718. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  719. Doo::loadModel ( 'invoice' );
  720. $invoice = new invoice ();
  721. $iid = $invoice->authcode ( $iidKey );
  722. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  723. die ( 'illegal request' );
  724. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  725. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  726. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  727. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  728. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  729. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  730. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  731. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  732. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  733. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  734. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  735. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  736. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  737. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  738. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  739. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  740. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  741. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  742. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  743. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  744. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  745. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  746. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  747. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  748. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  749. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  750. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  751. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  752. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  753. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  754. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  755. $electronicPhone = $this->get_args ( 'electronicPhone' ) ? $this->get_args ( 'electronicPhone' ) : "";
  756. $electronicEmail = $this->get_args ( 'electronicEmail' ) ? $this->get_args ( 'electronicEmail' ) : "";
  757. $invoiceForm = $this->get_args ( 'invoiceForm' ) ? $this->get_args ( 'invoiceForm' ) : "";
  758. if ($invoiceType == 1) {
  759. $temporary = $invoiceQuantity * $invoiceUnitPrice;
  760. if ($temporary > 100001)
  761. die ( 'illegal request-Please priceError' );
  762. }
  763. if($invoiceForm=='electronic'){
  764. if(empty(trim($electronicPhone))&&empty(trim($electronicEmail))){
  765. die ( '请至少填写一种联系方式--电子发票' );
  766. }
  767. }
  768. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  769. Doo::loadModel ( 'invoiceManage' );
  770. $invoiceManage = new invoiceManage ();
  771. Doo::loadModel ( 'invoiceOperationLog' );
  772. $invoiceOperationLog = new invoiceOperationLog ();
  773. Doo::loadModel ( 'invoiceStore' );
  774. $invoiceStore = new invoiceStore ();
  775. $cid = explode ( ':', $cid );
  776. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  777. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  778. $moldManage = array ();
  779. foreach ( $invoiceManageList as $key => $value ) {
  780. if ($value ['mold'] == '发票打印')
  781. $moldManage [$value ['mold']] = $value ['staffList'];
  782. elseif ($value ['mold'] == '发票邮寄')
  783. $moldManage [$value ['mold']] = $value ['staffList'];
  784. elseif ($value ['mold'] == '发票打印')
  785. $moldManage [$value ['mold']] = $value ['staffList'];
  786. }
  787. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  788. if($invoiceForm=='electronic'){
  789. $invoiceForm=1;
  790. $invoiceType=0;
  791. if(!empty($electronicPhone)||!empty($electronicEmail)){
  792. }else{
  793. die ( 'illegal request-electronicContact' );
  794. }
  795. $mailList = array ();
  796. $mailString = '备注:' . $mailItems;
  797. }elseif($invoiceForm=='paper'){
  798. $invoiceForm=0;
  799. $mailList = array (
  800. 'invoice' => 1,
  801. 'mailItems' => $mailItems
  802. );
  803. $mailString = '发票x1张,备注:' . $mailItems;
  804. }else{
  805. die ( 'illegal request-invoiceForm' );
  806. }
  807. $item = array (
  808. 'iid' => $iid,
  809. 'cid' => $cid [0],
  810. 'categoryName' => $cid [1],
  811. 'invoiceElement' => $invoiceElement,
  812. 'invoiceForm'=>$invoiceForm,
  813. 'electronicPhone'=>$electronicPhone,
  814. 'electronicEmail'=>$electronicEmail,
  815. 'invoiceQuantity' => $invoiceQuantity,
  816. 'invoiceUnitPrice' => $invoiceUnitPrice,
  817. 'invoicePrice' => $invoicePrice,
  818. 'invoiceType' => $invoiceType,
  819. 'doPost' => $doPost,
  820. 'status' => 1,
  821. 'updateTime' => date ( "Y-m-d H:i:s" ),
  822. 'remark' => $remark
  823. );
  824. if ($invoiceType == 0)
  825. $item += array (
  826. 'invoiceTitle' => $invoiceTitle,
  827. 'TIN' => $TINT,
  828. 'address' => $addressT,
  829. 'phone' => $phoneT,
  830. 'bank' => $bankT,
  831. 'bankAccount' => $bankAccountT
  832. );
  833. else {
  834. $item += array (
  835. 'invoiceCompany' => $invoiceCompany,
  836. 'TIN' => $TIN,
  837. 'address' => $address,
  838. 'phone' => $phone,
  839. 'bank' => $bank,
  840. 'bankAccount' => $bankAccount
  841. );
  842. }
  843. if ($doPost == 1) {
  844. if (! empty ( $softLock ))
  845. $mailList += array (
  846. 'softLock' => $softLockNum
  847. );
  848. else
  849. $mailList += array (
  850. 'softLock' => '0'
  851. );
  852. if (! empty ( $contract ))
  853. $mailList += array (
  854. 'contract' => $contractNum
  855. );
  856. else
  857. $mailList += array (
  858. 'contract' => '0'
  859. );
  860. if (! empty ( $instructions ))
  861. $mailList += array (
  862. 'instructions' => $instructionsNum
  863. );
  864. else
  865. $mailList += array (
  866. 'instructions' => '0'
  867. );
  868. if (! empty ( $remittance ))
  869. $mailList += array (
  870. 'remittance' => $remittance
  871. );
  872. else
  873. $mailList += array (
  874. 'remittance' => ''
  875. );
  876. if (! empty ( $softLock ))
  877. $mailString .= ',软件锁x' . $softLockNum;
  878. if (! empty ( $contract ))
  879. $mailString .= ',合同x' . $contractNum;
  880. if (! empty ( $instructions ))
  881. $mailString .= ',说明书x' . $instructionsNum;
  882. if (! empty ( $remittance ))
  883. $mailString .= ',汇款账号单';
  884. $item += array (
  885. 'recipients' => $recipients,
  886. 'recipientsPhone' => $recipientsPhone,
  887. 'recipientsAddress' => $recipientsAddress,
  888. 'mailItems' => $mailString,
  889. 'mailItemsJson' => json_encode ( $mailList )
  890. );
  891. }
  892. $invoice->setInvoiceByCondition ( $item );
  893. // 更新培训班仓库里的发票
  894. $detail = $invoice->getInvoiceByIid ( $iid );
  895. if (! empty ( $detail ['isid'] )) {
  896. $invoiceStore->isid = $detail ['isid'];
  897. $invoiceStore->invoiceQuantity = $invoiceQuantity;
  898. $invoiceStore->invoiceUnitPrice = $invoiceUnitPrice;
  899. $invoiceStore->invoicePrice = $invoicePrice;
  900. $invoiceStore->update ();
  901. }
  902. $item = array (
  903. 'date' => date ( "Y-m-d H:i:s" ),
  904. 'operation' => "重新提交审批",
  905. 'status' => 1,
  906. 'img' => $this->staff [0] ['avatar'],
  907. 'username' => $this->staff [0] ['username'],
  908. 'uid' => $this->staff [0] ['sid'],
  909. 'category' => $this->staff [0] ['category'],
  910. 'iid' => $iid
  911. );
  912. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  913. }
  914. return "/invoice";
  915. }
  916. /**
  917. * 培训班
  918. */
  919. function invoiceTraining() {
  920. Doo::loadModel ( 'L_category' );
  921. $lCategory = new L_category ();
  922. Doo::loadModel ( 'invoiceTraining' );
  923. $invoiceTraining = new invoiceTraining ();
  924. Doo::loadModel ( 'invoiceTrainManage' );
  925. $invoiceTrainManage = new invoiceTrainManage ();
  926. $imcStaff = $invoiceTrainManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  927. $cidList = array ();
  928. foreach ( $imcStaff as $key => $value ) {
  929. array_push ( $cidList, $value ['cid'] );
  930. }
  931. if (empty ( $cidList )) {
  932. $cidString = $this->staff [0] ['cid'];
  933. } else {
  934. $cidString = implode ( ',', $cidList );
  935. $cidString .= $cidString . ',' . $this->staff [0] ['cid'];
  936. }
  937. $itTodoList = $invoiceTraining->getInvoiceTrainingByTodo ( '', $cidString, $this->staff [0] ['sid'] );
  938. $itedList = $invoiceTraining->getInvoiceTrainingByStatus ( 2, '', $cidString, $this->staff [0] ['sid'] );
  939. $category = $lCategory->getCategory ();
  940. $itid = array ();
  941. foreach ( $itTodoList as $key => $value ) {
  942. array_push ( $itid, $value ['itid'] );
  943. // 如果入账100%更新为已完成
  944. if ($itTodoList [$key] ['arriveSchedule'] >= 100) {
  945. $invoiceTraining = new invoiceTraining ();
  946. $invoiceTraining->itid = $value ['itid'];
  947. $invoiceTraining->status = 2;
  948. $invoiceTraining->update ();
  949. }
  950. }
  951. foreach ( $itedList as $value ) {
  952. array_push ( $itid, $value ['itid'] );
  953. }
  954. $itid = implode ( ',', $itid );
  955. $this->data ['itStatist'] = $invoiceTraining->getInvoiceTrainStatistics ( $itid );
  956. // print_r($itTodoList);
  957. $this->data ['trainCount'] = count ( $itTodoList ) + count ( $itedList );
  958. $this->data ['itTodoList'] = $itTodoList;
  959. $this->data ['itedList'] = $itedList;
  960. $this->data ['category'] = $category;
  961. $this->data ['memu'] = "invoice";
  962. $this->data ['staff'] = $this->staff;
  963. $this->data ['receiptMemu'] = 'invoiceTraining';
  964. $this->render ( "/admin/invoiceTraining", $this->data );
  965. }
  966. /**
  967. * 创建培训班
  968. */
  969. function invoiceTrainingAdd() {
  970. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  971. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  972. $trainDate = $this->get_args ( 'trainDate' ) ? $this->get_args ( 'trainDate' ) : "";
  973. if (empty ( $this->staff [0] ))
  974. die ( 'illegal request' );
  975. if (! empty ( $cid ) && ! empty ( $trainName ) && ! empty ( $trainDate )) {
  976. Doo::loadModel ( 'invoiceTraining' );
  977. $invoiceTraining = new invoiceTraining ();
  978. Doo::loadModel ( 'invoice' );
  979. $invoice = new invoice ();
  980. Doo::loadModel ( 'L_category' );
  981. $lCategory = new L_category ();
  982. Doo::loadModel ( 'invoiceManage' );
  983. $invoiceManage = new invoiceManage ();
  984. Doo::loadModel ( 'invoiceOperationLog' );
  985. $invoiceOperationLog = new invoiceOperationLog ();
  986. $item = array (
  987. 'cid' => $cid,
  988. 'trainName' => $trainName,
  989. 'trainDate' => $trainDate,
  990. 'creator' => $this->staff [0] ['sid'],
  991. 'creatorDate' => date ( "Y-m-d H:i:s" )
  992. );
  993. $itid = $invoiceTraining->addInvoiceTraining ( $item );
  994. }
  995. return "/invoiceTraining";
  996. }
  997. /**
  998. * 删除培训班
  999. */
  1000. function invoiceTrainingDelDo() {
  1001. $itid = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  1002. if (! empty ( $itid )) {
  1003. Doo::loadModel ( 'invoiceTraining' );
  1004. $invoiceTraining = new invoiceTraining ();
  1005. $invoiceTraining->delInvoiceTrainingByItid ( $itid );
  1006. }
  1007. return "/invoiceTraining";
  1008. }
  1009. /**
  1010. * 培训班详情
  1011. */
  1012. function invoiceTrainingDetail() {
  1013. $trainStatus = $this->get_args ( 'trainStatus' ) ? $this->get_args ( 'trainStatus' ) : "ALL";
  1014. $itid = isset ( $this->params ['trainingKey'] ) ? $this->params ['trainingKey'] : "";
  1015. Doo::loadModel ( 'invoiceTraining' );
  1016. $invoiceTraining = new invoiceTraining ();
  1017. Doo::loadModel ( 'invoiceStore' );
  1018. $invoiceStore = new invoiceStore ();
  1019. if (empty ( $itid ))
  1020. die ( 'illegal request' );
  1021. $con = '(b.untreadStatus is null or b.untreadStatus!=2) and ';
  1022. if ($trainStatus == "SUBED")
  1023. $con = ' (b.untreadStatus is null ) and ';
  1024. elseif ($trainStatus == "APPROVAL")
  1025. $con = ' ( b.status=1 and b.untreadStatus!=2 ) and ';
  1026. elseif ($trainStatus == "TICKET")
  1027. $con = ' (b.printStatus=1 and b.status=2 and b.untreadStatus!=2) and ';
  1028. elseif ($trainStatus == "TICKETING") {
  1029. $con = ' (b.status=2 and b.untreadStatus=1) and ';
  1030. }
  1031. $con.=' a.invoiceForm=0 and ';
  1032. $detail = $invoiceTraining->getInvoiceTrainingByItid ( $itid );
  1033. $isList = $invoiceStore->getinvoiceStoreByItid ( $itid, $con,0 );
  1034. //print_r($isList);
  1035. $trainlistJson=$this->_trainList($isList);
  1036. if (empty ( $detail ))
  1037. die ( 'illegal request' );
  1038. // 培训班结算是否有和是否已经结算完成
  1039. Doo::loadModel ( 'receipt' );
  1040. $receipt = new receipt ();
  1041. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $itid );
  1042. $this->data ['receiptDetail'] = $receiptDetail;
  1043. $this->data ['trainStatus'] = $trainStatus;
  1044. $this->data ['itid'] = $itid;
  1045. $this->data ['trainlistJson'] = $trainlistJson;
  1046. $this->data ['iTrainDetail'] = $detail;
  1047. $this->data ['memu'] = "invoice";
  1048. $this->data ['staff'] = $this->staff;
  1049. $this->data ['receiptMemu'] = 'invoiceTraining';
  1050. $this->render ( "/admin/invoiceTrainingDetail", $this->data );
  1051. }
  1052. function invoiceTrainingElectronicDetail(){
  1053. $trainStatus = $this->get_args ( 'trainStatus' ) ? $this->get_args ( 'trainStatus' ) : "ALL";
  1054. $itid = isset ( $this->params ['trainingKey'] ) ? $this->params ['trainingKey'] : "";
  1055. Doo::loadModel ( 'invoiceTraining' );
  1056. $invoiceTraining = new invoiceTraining ();
  1057. Doo::loadModel ( 'invoiceStore' );
  1058. $invoiceStore = new invoiceStore ();
  1059. if (empty ( $itid ))
  1060. die ( 'illegal request' );
  1061. $con = ' (b.untreadStatus is null or b.untreadStatus!=2) and ';
  1062. if ($trainStatus == "SUBED")
  1063. $con = ' (b.untreadStatus is null ) and ';
  1064. elseif ($trainStatus == "APPROVAL")
  1065. $con = ' ( b.status=1 and b.untreadStatus!=2 ) and ';
  1066. elseif ($trainStatus == "TICKET")
  1067. $con = ' (b.printStatus=1 and b.status=2 and b.untreadStatus!=2) and ';
  1068. elseif ($trainStatus == "TICKETING") {
  1069. $con = ' (b.status=2 and b.untreadStatus=1) and ';
  1070. }
  1071. $con.=' a.invoiceForm=1 and ';
  1072. $detail = $invoiceTraining->getInvoiceTrainingByItid ( $itid );
  1073. $isList = $invoiceStore->getinvoiceStoreByItid ( $itid, $con,1 );
  1074. //print_r($isList);
  1075. if (empty ( $detail )){
  1076. die ( 'illegal request' );
  1077. }
  1078. $trainlistJson=$this->_trainList($isList,1);
  1079. // 培训班结算是否有和是否已经结算完成
  1080. Doo::loadModel ( 'receipt' );
  1081. $receipt = new receipt ();
  1082. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $itid );
  1083. $this->data ['receiptDetail'] = $receiptDetail;
  1084. $this->data ['trainStatus'] = $trainStatus;
  1085. $this->data ['itid'] = $itid;
  1086. $this->data ['trainlistJson'] = $trainlistJson;
  1087. $this->data ['iTrainDetail'] = $detail;
  1088. $this->data ['memu'] = "invoice";
  1089. $this->data ['staff'] = $this->staff;
  1090. $this->data ['receiptMemu'] = 'invoiceTraining';
  1091. $this->render ( "/invoice/invoiceTrainingElectronicDetail", $this->data );
  1092. }
  1093. function _trainList($isList,$type=0){
  1094. $trainlist = array ();
  1095. foreach ( $isList as $key => $value ) {
  1096. $irDetail = array ();
  1097. if ($value ['apStatus'] == 1) {
  1098. // array_push ( $irDetail, '' );
  1099. array_push ( $irDetail, '<input disabled type="checkbox" style="display:none" >' );
  1100. } else {
  1101. array_push ( $irDetail, '<input type="checkbox" class="hide" id="' . $value ['storeKey'] . '" name="isBox" value="' . $value ['storeKey'] . '" > <a href="/invoiceStoreEdit/' . $value ['storeKey'] . '.html">编辑</a>
  1102. <a href="#confirm" onclick="invoiceStoreApproval(\'' . $value ['storeKey'] . '\')" data-toggle="modal">提交审批</a>
  1103. <a href="#del" node-iStore="del" data-key="' . $value ['storeKey'] . '" onclick="invoiceStoreDel(\'' . $value ['storeKey'] . '\')" data-toggle="modal" class="colRed">移除</a>' );
  1104. }
  1105. array_push ( $irDetail, $value ['invoiceSerial'] );
  1106. if ($value ['invoiceType'] == 1)
  1107. array_push ( $irDetail, $value ['invoiceCompany'] );
  1108. else
  1109. array_push ( $irDetail, $value ['invoiceTitle'] );
  1110. array_push ( $irDetail, $value ['TIN'] );
  1111. array_push ( $irDetail, $value ['userName'] );
  1112. if (empty ( $value ['mailItems'] ) && $value ['apStatus'] != 1) {
  1113. array_push ( $irDetail, '<a href="#confirm-erro" onclick="invoiceStoreMail(\'' . $value ['storeKey'] . '\')" data-toggle="modal">设置邮寄物品</a>' );
  1114. } else
  1115. array_push ( $irDetail, $value ['mailItems'] );
  1116. array_push ( $irDetail, $value ['recipientsAddress'] . $value ['recipients'] . $value ['recipientsPhone'] );
  1117. if($type==1){
  1118. array_push ( $irDetail, $value ['electronicPhone'] );
  1119. array_push ( $irDetail, $value ['electronicEmail'] );
  1120. }
  1121. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  1122. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  1123. array_push ( $irDetail, $value ['invoiceElement'] );
  1124. array_push ( $irDetail, $value ['invoiceQuantity'] );
  1125. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  1126. if ($value ['invoiceType'] == 1)
  1127. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  1128. else
  1129. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  1130. array_push ( $irDetail, $value ['remark'] );
  1131. if ($value ['status'] == 1)
  1132. array_push ( $irDetail, '审批中' );
  1133. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1)
  1134. array_push ( $irDetail, '已出票' );
  1135. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1 && $value ['printStatus'] != 'irid' && ($value ['untreadStatus'] == 3 || $value ['untreadStatus'] == 0))
  1136. array_push ( $irDetail, '已入账' );
  1137. else
  1138. array_push ( $irDetail, '' );
  1139. array_push ( $irDetail, $value ['invoiceNo'] );
  1140. array_push ( $irDetail, $value ['printTime'] );
  1141. $html = '';
  1142. foreach ( $value ['invoiceReceivables'] as $v ) {
  1143. $html .= '&nbsp;<a href="#billing" node-invoice="INFO" data-type="receivables" data-iskey="' . $v [2] . '" data-toggle="modal">' . $v [1] . '</a>';
  1144. }
  1145. array_push ( $irDetail, $html );
  1146. array_push ( $trainlist, $irDetail );
  1147. }
  1148. $trainlistJson = json_encode ( $trainlist );
  1149. return $trainlistJson;
  1150. }
  1151. /**
  1152. * 上传培训班发票
  1153. * @return string
  1154. */
  1155. function invoiceTrainingUpload() {
  1156. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  1157. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  1158. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  1159. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  1160. header ( "HTTP/1.1 500 Internal Server Error" );
  1161. echo "POST exceeded maximum allowed size.";
  1162. exit ( 0 );
  1163. }
  1164. // Settings
  1165. $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)
  1166. $upload_name = "Filedata";
  1167. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  1168. $extension_whitelist = array (
  1169. "doc",
  1170. "txt",
  1171. "jpg",
  1172. "gif",
  1173. "png"
  1174. ); // Allowed file extensions
  1175. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  1176. // Other variables
  1177. $MAX_FILENAME_LENGTH = 260;
  1178. $file_name = "";
  1179. $file_extension = "";
  1180. $uploadErrors = array (
  1181. 0 => "文件上传成功",
  1182. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  1183. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  1184. 3 => "上传的文件仅为部分文件",
  1185. 4 => "没有文件上传",
  1186. 6 => "缺少临时文件夹"
  1187. );
  1188. $nk = time ();
  1189. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  1190. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  1191. echo "文件无法保存.";
  1192. exit ( 0 );
  1193. }
  1194. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  1195. echo json_encode ( array (
  1196. 'filename' => $file_name,
  1197. 'id' => $nk
  1198. ) );
  1199. exit ( 0 );
  1200. }
  1201. /**
  1202. * 导入发票临时仓库
  1203. */
  1204. function invoiceStoreImport() {
  1205. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  1206. $trainingKey = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  1207. $path = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  1208. if ($path != "" && ! empty ( $trainingKey )) {
  1209. Doo::loadModel ( 'invoiceStore' );
  1210. Doo::loadModel ( 'staff' );
  1211. $staff = new staff ();
  1212. Doo::loadModel ( 'invoiceTraining' );
  1213. $invoiceTraining = new invoiceTraining ();
  1214. Doo::loadClass ( 'XDeode' );
  1215. $XDeode = new XDeode ( 5 );
  1216. $itid = $XDeode->decode ( $trainingKey );
  1217. // 培训班结算是否有和是否已经结算完成
  1218. Doo::loadModel ( 'receipt' );
  1219. $receipt = new receipt ();
  1220. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $itid );
  1221. if (! empty ( $receiptDetail )) {
  1222. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9)
  1223. die ( 'illegal request--status' );
  1224. }
  1225. $exlArray = $this->formatExcelToArrayTrain ( DOO::conf ()->SITE_PATH . "upload/invoiceTraining/" . $path );
  1226. $userName = $this->staff [0] ['username'];
  1227. $sDetail = $staff->getStaffByName ( $userName );
  1228. //print_r($exlArray);die;
  1229. // die('sdd');
  1230. // 可以优化
  1231. foreach ( $exlArray as $key => $value ) {
  1232. // 开票
  1233. $invoice = new invoiceStore ();
  1234. $invoice->trainId = $itid;
  1235. $invoice->invoiceType = 0;
  1236. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  1237. $invoice->invoiceType = 1;
  1238. elseif($value ['invoiceType'] == '电子'){
  1239. $invoice->invoiceType = 0;
  1240. $invoice->invoiceForm=1;
  1241. }
  1242. $invoice->invoiceQuantity = $value ['invoiceQuantity'];
  1243. $invoice->invoiceUnitPrice = $value ['invoiceUnitPrice'];
  1244. $invoice->invoicePrice = $value ['invoiceQuantity'] * $value ['invoiceUnitPrice'];
  1245. $invoice->invoiceTitle = $value ['invoiceTitle'];
  1246. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  1247. $invoice->invoiceCompany = $value ['invoiceTitle'];
  1248. $invoice->userName = $userName;
  1249. $invoice->sid = $sDetail ['sid'];
  1250. $invoice->cid = $sDetail ['cid'];
  1251. $invoice->categoryName = $sDetail ['category'];
  1252. $invoice->invoiceElement = $value ['invoiceElement'];
  1253. $invoice->remark = $value ['remark'];
  1254. // $invoice->date = $value ['date'];
  1255. // $invoice->printTime = $value ['date'];
  1256. $invoice->ipSource = 1;
  1257. $invoice->printStatus = 0;
  1258. $invoice->status = 0;
  1259. $invoice->postStatus = 1;
  1260. $invoice->untreadStatus = 0;
  1261. // $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1262. $invoice->TIN = $value ['TIN'];
  1263. $invoice->address = $value ['address'];
  1264. $invoice->phone = $value ['phone'];
  1265. $invoice->bank = $value ['bank'];
  1266. $invoice->bankAccount = $value ['bankAccount'];
  1267. $invoice->recipientsAddress = $value ['recipientsAddress'];
  1268. $invoice->recipients = $value ['recipients'];
  1269. $invoice->recipientsPhone = $value ['recipientsPhone'];
  1270. $invoice->electronicPhone = $value ['electronicPhone'];
  1271. $invoice->electronicEmail = $value ['electronicEmail'];
  1272. $iid = $invoice->insert ();
  1273. }
  1274. // 加入发票总数量
  1275. $item = array (
  1276. 'itid' => $itid,
  1277. 'invoiceTotal' => count ( $exlArray )
  1278. );
  1279. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1280. return '/invoiceTrainingDetail/' . $trainingKey . ".html";
  1281. }
  1282. echo 'no file';
  1283. }
  1284. /**
  1285. * 编辑仓库里的发票
  1286. */
  1287. function invoiceStoreEdit() {
  1288. Doo::loadClass ( 'XDeode' );
  1289. $XDeode = new XDeode ( 5 );
  1290. $iid = isset ( $this->params ['storeKey'] ) ? $this->params ['storeKey'] : "";
  1291. $iid = $XDeode->decode ( $iid );
  1292. if (! is_numeric ( $iid ))
  1293. die ( 'illegal request' );
  1294. Doo::loadModel ( 'invoiceStore' );
  1295. $invoiceStore = new invoiceStore ();
  1296. $invoiceDetail = $invoiceStore->getInvoiceStoreByIsid ( $iid );
  1297. // print_r($invoiceDetail);
  1298. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  1299. $this->data ['invoiceDetail'] = $invoiceDetail;
  1300. $this->data ['memu'] = "invoice";
  1301. $this->data ['staff'] = $this->staff;
  1302. $this->data ['receiptMemu'] = 'invoiceTraining';
  1303. $this->render ( "/admin/invoiceStoreEdit", $this->data );
  1304. }
  1305. function invoiceStoreEditDo() {
  1306. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1307. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1308. Doo::loadModel ( 'invoiceStore' );
  1309. $invoice = new invoiceStore ();
  1310. Doo::loadClass ( 'XDeode' );
  1311. $XDeode = new XDeode ( 5 );
  1312. $iid = $XDeode->decode ( $storeKey );
  1313. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1314. die ( 'illegal request' );
  1315. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  1316. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  1317. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  1318. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  1319. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  1320. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  1321. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  1322. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  1323. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  1324. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  1325. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  1326. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  1327. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  1328. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  1329. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1330. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1331. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1332. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1333. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  1334. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  1335. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  1336. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  1337. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  1338. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  1339. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1340. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1341. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1342. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1343. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1344. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1345. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1346. $electronicPhone = $this->get_args ( 'electronicPhone' ) ? $this->get_args ( 'electronicPhone' ) : "";
  1347. $electronicEmail = $this->get_args ( 'electronicEmail' ) ? $this->get_args ( 'electronicEmail' ) : "";
  1348. $invoiceForm = $this->get_args ( 'invoiceForm' ) ? $this->get_args ( 'invoiceForm' ) : "";
  1349. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  1350. $cid = explode ( ':', $cid );
  1351. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  1352. $item = array (
  1353. 'isid' => $iid,
  1354. 'cid' => $cid [0],
  1355. 'categoryName' => $cid [1],
  1356. 'invoiceElement' => $invoiceElement,
  1357. 'invoiceQuantity' => $invoiceQuantity,
  1358. 'invoiceUnitPrice' => $invoiceUnitPrice,
  1359. 'invoicePrice' => $invoicePrice,
  1360. 'invoiceType' => $invoiceType,
  1361. 'doPost' => $doPost,
  1362. 'status' => 1,
  1363. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1364. 'remark' => $remark
  1365. );
  1366. if ($invoiceType == 0)
  1367. $item += array (
  1368. 'invoiceTitle' => $invoiceTitle,
  1369. 'TIN' => $TINT,
  1370. 'address' => $addressT,
  1371. 'phone' => $phoneT,
  1372. 'bank' => $bankT,
  1373. 'bankAccount' => $bankAccountT
  1374. );
  1375. else {
  1376. $item += array (
  1377. 'invoiceCompany' => $invoiceCompany,
  1378. 'TIN' => $TIN,
  1379. 'address' => $address,
  1380. 'phone' => $phone,
  1381. 'bank' => $bank,
  1382. 'bankAccount' => $bankAccount
  1383. );
  1384. }
  1385. if($invoiceForm=='paper'){
  1386. $item += array (
  1387. 'invoiceForm' => 0
  1388. );
  1389. }elseif($invoiceForm=='electronic'){
  1390. $item += array (
  1391. 'invoiceForm' => 1,
  1392. 'electronicPhone' => $electronicPhone,
  1393. 'electronicEmail' => $electronicEmail,
  1394. );
  1395. }
  1396. if ($doPost == 1) {
  1397. $mailList = array (
  1398. 'invoice' => 1,
  1399. 'mailItems' => $mailItems
  1400. );
  1401. if (! empty ( $softLock ))
  1402. $mailList += array (
  1403. 'softLock' => $softLockNum
  1404. );
  1405. else
  1406. $mailList += array (
  1407. 'softLock' => '0'
  1408. );
  1409. if (! empty ( $contract ))
  1410. $mailList += array (
  1411. 'contract' => $contractNum
  1412. );
  1413. else
  1414. $mailList += array (
  1415. 'contract' => '0'
  1416. );
  1417. if (! empty ( $instructions ))
  1418. $mailList += array (
  1419. 'instructions' => $instructionsNum
  1420. );
  1421. else
  1422. $mailList += array (
  1423. 'instructions' => '0'
  1424. );
  1425. if (! empty ( $remittance ))
  1426. $mailList += array (
  1427. 'remittance' => $remittance
  1428. );
  1429. else
  1430. $mailList += array (
  1431. 'remittance' => ''
  1432. );
  1433. $mailString = '发票x1,备注:' . $mailItems;
  1434. if (! empty ( $softLock ))
  1435. $mailString .= ',软件锁x' . $softLockNum;
  1436. if (! empty ( $contract ))
  1437. $mailString .= ',合同x' . $contractNum;
  1438. if (! empty ( $instructions ))
  1439. $mailString .= ',说明书x' . $instructionsNum;
  1440. if (! empty ( $remittance ))
  1441. $mailString .= ',汇款账号单';
  1442. $item += array (
  1443. 'recipients' => $recipients,
  1444. 'recipientsPhone' => $recipientsPhone,
  1445. 'recipientsAddress' => $recipientsAddress,
  1446. 'mailItems' => $mailString,
  1447. 'mailItemsJson' => json_encode ( $mailList )
  1448. );
  1449. }
  1450. $invoice->setInvoiceStoreByCondition ( $item );
  1451. }
  1452. if(!empty($invoiceForm)&&$invoiceForm=='electronic'){
  1453. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1454. }else{
  1455. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1456. }
  1457. }
  1458. /**
  1459. *
  1460. * @return string
  1461. */
  1462. function invoiceStoreDelete() {
  1463. Doo::loadClass ( 'XDeode' );
  1464. $XDeode = new XDeode ( 5 );
  1465. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1466. $iStoreKey = $this->get_args ( 'iStoreKey' ) ? $this->get_args ( 'iStoreKey' ) : 0;
  1467. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1468. $isid = $XDeode->decode ( $iStoreKey );
  1469. $itid = $XDeode->decode ( $trainKey );
  1470. if (! is_numeric ( $isid ))
  1471. die ( 'illegal request' );
  1472. Doo::loadModel ( 'invoiceStore' );
  1473. $invoiceStore = new invoiceStore ();
  1474. $invoiceStore->delete ( array (
  1475. 'where' => 'isid=' . $isid,
  1476. 'limit' => 1
  1477. ) );
  1478. Doo::loadModel ( 'invoiceTraining' );
  1479. $invoiceTraining = new invoiceTraining ();
  1480. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1481. $item = array (
  1482. 'itid' => $itid,
  1483. 'invoiceTotal' => $itDetail ['invoiceTotal'] - 1
  1484. );
  1485. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1486. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1487. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1488. }else{
  1489. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1490. }
  1491. }
  1492. /**
  1493. * 批量删除库里发票
  1494. */
  1495. function invoiceStoreBatchDelete() {
  1496. Doo::loadClass ( 'XDeode' );
  1497. $XDeode = new XDeode ( 5 );
  1498. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1499. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1500. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1501. if (empty ( $trainKey ) || empty ( $storeKey ))
  1502. die ( 'illegal request-IdKey' );
  1503. $tid = $XDeode->decode ( $trainKey );
  1504. if (! is_numeric ( $tid ) && ! empty ( $storeKey ))
  1505. die ( 'illegal request' );
  1506. Doo::loadModel ( 'invoiceStore' );
  1507. $isidKeyList = explode ( ',', $storeKey );
  1508. $isidList = array ();
  1509. foreach ( $isidKeyList as $value ) {
  1510. $isid = $XDeode->decode ( $value );
  1511. if (! empty ( $isid ) && is_numeric ( $isid ))
  1512. array_push ( $isidList, $isid );
  1513. }
  1514. $isidString = implode ( ',', $isidList );
  1515. $invoiceStore = new invoiceStore ();
  1516. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,apStatus' );
  1517. $isidList = array ();
  1518. foreach ( $isList as $key => $value ) {
  1519. if ($value ['apStatus'] == 0)
  1520. array_push ( $isidList, $value ['isid'] );
  1521. }
  1522. $isidString = implode ( ',', $isidList );
  1523. // print_r($isList);
  1524. // echo $isidString;
  1525. $invoiceStore = new invoiceStore ();
  1526. $invoiceStore->delete ( array (
  1527. 'where' => "isid in ( " . $isidString . ")",
  1528. 'asArray' => TRUE
  1529. ) );
  1530. Doo::loadModel ( 'invoiceTraining' );
  1531. $invoiceTraining = new invoiceTraining ();
  1532. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1533. $item = array (
  1534. 'itid' => $tid,
  1535. 'invoiceTotal' => $itDetail ['invoiceTotal'] - count ( $isidList )
  1536. );
  1537. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1538. // echo $tid;
  1539. // echo $storeKey;
  1540. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1541. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1542. }else{
  1543. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1544. }
  1545. }
  1546. function invoiceStoreBatchElectronicPhone(){
  1547. $electronicPhone = $this->get_args ( 'electronicPhone' ) ? $this->get_args ( 'electronicPhone' ) : '';
  1548. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1549. Doo::loadClass ( 'XDeode' );
  1550. $XDeode = new XDeode ( 5 );
  1551. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1552. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1553. if (empty ( $trainKey ) || empty ( $storeKey ))
  1554. die ( 'illegal request-IdKey' );
  1555. $isidKeyList = explode ( ',', $storeKey );
  1556. $isidList = array ();
  1557. foreach ( $isidKeyList as $value ) {
  1558. $isid = $XDeode->decode ( $value );
  1559. if (! empty ( $isid ) && is_numeric ( $isid ))
  1560. array_push ( $isidList, $isid );
  1561. }
  1562. $isidString = implode ( ',', $isidList );
  1563. $trainId = $XDeode->decode ( $trainKey );
  1564. if (! is_numeric ( $isid ))
  1565. die ( 'illegal request--isid' );
  1566. Doo::loadModel ( 'invoiceStore' );
  1567. $invoiceStore = new invoiceStore ();
  1568. $item = array (
  1569. 'electronicPhone' => $electronicPhone
  1570. );
  1571. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1572. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1573. }
  1574. function invoiceStoreBatchElectronicEmail(){
  1575. $electronicEmail = $this->get_args ( 'electronicEmail' ) ? $this->get_args ( 'electronicEmail' ) : '';
  1576. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1577. Doo::loadClass ( 'XDeode' );
  1578. $XDeode = new XDeode ( 5 );
  1579. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1580. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1581. if (empty ( $trainKey ) || empty ( $storeKey ))
  1582. die ( 'illegal request-IdKey' );
  1583. $isidKeyList = explode ( ',', $storeKey );
  1584. $isidList = array ();
  1585. foreach ( $isidKeyList as $value ) {
  1586. $isid = $XDeode->decode ( $value );
  1587. if (! empty ( $isid ) && is_numeric ( $isid ))
  1588. array_push ( $isidList, $isid );
  1589. }
  1590. $isidString = implode ( ',', $isidList );
  1591. $trainId = $XDeode->decode ( $trainKey );
  1592. if (! is_numeric ( $isid ))
  1593. die ( 'illegal request' );
  1594. Doo::loadModel ( 'invoiceStore' );
  1595. $invoiceStore = new invoiceStore ();
  1596. $item = array (
  1597. 'electronicEmail' => $electronicEmail
  1598. );
  1599. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1600. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1601. }
  1602. /**
  1603. * 仓库发票提交审批
  1604. * @return string
  1605. */
  1606. function invoiceStoreApproval() {
  1607. Doo::loadClass ( 'XDeode' );
  1608. $XDeode = new XDeode ( 5 );
  1609. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1610. $iStoreKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1611. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1612. $isid = $XDeode->decode ( $iStoreKey );
  1613. $trainId = $XDeode->decode ( $trainKey );
  1614. if (! is_numeric ( $isid ))
  1615. die ( 'illegal request' );
  1616. Doo::loadModel ( 'invoiceStore' );
  1617. Doo::loadModel ( 'invoice' );
  1618. $invoice = new invoice ();
  1619. // 加入限制必须填写入开票内容和邮寄物品
  1620. $invoiceStore = new invoiceStore ();
  1621. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid, 'isid,trainId ,invoiceElement,mailItemsJson,electronicPhone,electronicEmail' );
  1622. if (empty ( $isDetail ['invoiceElement'] ) || empty ( $isDetail ['mailItemsJson'] )) {
  1623. header ( 'Content-Type:text/html;charset=utf-8' );
  1624. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1625. }
  1626. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1627. if (empty ( $isDetail ['electronicPhone'] ) && empty ( $isDetail ['electronicEmail'] )) {
  1628. header ( 'Content-Type:text/html;charset=utf-8' );
  1629. die ( 'illegal request! 请设置电子开票的收件人手机或者邮箱' );
  1630. }
  1631. }
  1632. // 拷贝插入一条发票数据
  1633. $invoiceStore = new invoiceStore ();
  1634. $iid = $invoiceStore->setInvoiceStoreToApproval ( $isid );
  1635. $invoiceStore = new invoiceStore ();
  1636. $item = array (
  1637. 'isid' => $isid,
  1638. 'iid' => $iid,
  1639. 'apStatus' => 1
  1640. );
  1641. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1642. Doo::loadModel ( 'invoiceManage' );
  1643. $invoiceManage = new invoiceManage ();
  1644. Doo::loadModel ( 'invoiceOperationLog' );
  1645. $invoiceOperationLog = new invoiceOperationLog ();
  1646. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1647. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1648. $moldManage = array ();
  1649. foreach ( $invoiceManageList as $key => $value ) {
  1650. if ($value ['mold'] == '发票打印')
  1651. $moldManage [$value ['mold']] = $value ['staffList'];
  1652. elseif ($value ['mold'] == '发票邮寄')
  1653. $moldManage [$value ['mold']] = $value ['staffList'];
  1654. elseif ($value ['mold'] == '发票退票')
  1655. $moldManage [$value ['mold']] = $value ['staffList'];
  1656. }
  1657. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1658. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1659. $invoiceSerial="#FE" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1660. }else{
  1661. $invoiceSerial="#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1662. }
  1663. $item = array (
  1664. 'iid' => $iid,
  1665. 'isid' => $isid,
  1666. 'invoiceSerial' => $invoiceSerial,
  1667. 'date' => date ( "Y-m-d H:i:s" ),
  1668. 'status' => 1,
  1669. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1670. 'trainId' => $trainId,
  1671. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1672. 'moldManage' => json_encode ( $moldManage ),
  1673. 'settlementType' => 1,
  1674. 'pendingApprovals' => $pendingApprovalsSid
  1675. );
  1676. $invoice->setInvoiceByCondition ( $item );
  1677. Doo::loadModel ( 'invoiceTraining' );
  1678. $invoiceTraining = new invoiceTraining ();
  1679. $item = array (
  1680. 'itid' => $trainId,
  1681. 'submitStatus' => 1
  1682. );
  1683. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1684. $item = array (
  1685. 'date' => date ( "Y-m-d H:i:s" ),
  1686. 'operation' => "创建",
  1687. 'status' => 1,
  1688. 'img' => $this->staff [0] ['avatar'],
  1689. 'username' => $this->staff [0] ['username'],
  1690. 'uid' => $this->staff [0] ['sid'],
  1691. 'category' => $this->staff [0] ['category'],
  1692. 'iid' => $iid
  1693. );
  1694. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1695. $item = array (
  1696. 'date' => date ( "Y-m-d H:i:s" ),
  1697. 'operation' => "提交审批",
  1698. 'status' => 1,
  1699. 'img' => $this->staff [0] ['avatar'],
  1700. 'username' => $this->staff [0] ['username'],
  1701. 'uid' => $this->staff [0] ['sid'],
  1702. 'category' => $this->staff [0] ['category'],
  1703. 'iid' => $iid
  1704. );
  1705. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1706. Doo::loadModel ( 'staff' );
  1707. $staff = new staff ();
  1708. $username2 = $staff->getOne ( array (
  1709. 'select' => 'wxid',
  1710. 'where' => 'sid=' . $pendingApprovalsSid,
  1711. 'asArray' => TRUE
  1712. ) );
  1713. // 发送微信审批通知
  1714. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1715. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1716. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1717. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1718. }else{
  1719. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1720. }
  1721. }
  1722. /**
  1723. * 批量提交发票
  1724. * @return string
  1725. */
  1726. function invoiceStoreBatchApproval() {
  1727. Doo::loadClass ( 'XDeode' );
  1728. $XDeode = new XDeode ( 5 );
  1729. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1730. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1731. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : '';
  1732. if (empty ( $trainKey ) || empty ( $storeKey ))
  1733. die ( 'illegal request-IdKey' );
  1734. $trainId = $XDeode->decode ( $trainKey );
  1735. $isidKeyList = explode ( ',', $storeKey );
  1736. $isidList = array ();
  1737. foreach ( $isidKeyList as $value ) {
  1738. $isid = $XDeode->decode ( $value );
  1739. if (! empty ( $isid ) && is_numeric ( $isid ))
  1740. array_push ( $isidList, $isid );
  1741. }
  1742. $isidString = implode ( ',', $isidList );
  1743. if (! is_numeric ( $trainId ))
  1744. die ( 'illegal request' );
  1745. Doo::loadModel ( 'invoiceStore' );
  1746. Doo::loadModel ( 'invoice' );
  1747. // 判断哪些已经加入审批过
  1748. // 加入限制必须填写入开票内容和邮寄物品
  1749. $invoiceStore = new invoiceStore ();
  1750. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,trainId ,invoiceElement,mailItemsJson,electronicPhone,electronicEmail,invoiceForm' );
  1751. foreach ( $isList as $key => $value ) {
  1752. if (empty ( $value ['invoiceElement'] ) || empty ( $value ['mailItemsJson'] )) {
  1753. header ( 'Content-Type:text/html;charset=utf-8' );
  1754. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1755. }
  1756. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic' ){
  1757. $value ['electronicPhone']=trim($value ['electronicPhone']);
  1758. $value ['electronicEmail']=trim($value ['electronicEmail']);
  1759. if(empty ( $value ['electronicPhone'] )&&empty ( $value ['electronicEmail'] )){
  1760. header ( 'Content-Type:text/html;charset=utf-8' );
  1761. die ( 'illegal request! 请设置电子开票的收件人手机或者邮箱' );
  1762. }
  1763. }
  1764. }
  1765. // 拷贝插入一条发票数据
  1766. $invoiceStore = new invoiceStore ();
  1767. $invoiceStore->setInvoiceStoreBatchToApproval ( $isidString );
  1768. $invoiceStore = new invoiceStore ();
  1769. $item = array (
  1770. 'apStatus' => 1
  1771. );
  1772. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1773. // 获得正式发票ID
  1774. $invoice = new invoice ();
  1775. $iidList = $invoice->getInvoiceByIstoreid ( $isidString, 'iid,isid' );
  1776. $sqlList = array ();
  1777. $iidString = '';
  1778. $iida = array ();
  1779. foreach ( $iidList as $key => $value ) {
  1780. $sqlList [$value ['isid']] = $value ['iid'];
  1781. array_push ( $iida, $value ['iid'] );
  1782. }
  1783. $iidString = implode ( ',', $iida );
  1784. $ids = implode ( ',', array_keys ( $sqlList ) );
  1785. $sql = "UPDATE CLD_invoiceStore SET iid = CASE isid ";
  1786. foreach ( $sqlList as $id => $ordinal ) {
  1787. $sql .= sprintf ( "WHEN %d THEN %d ", $id, $ordinal );
  1788. }
  1789. $sql .= "END WHERE isid IN ($ids)";
  1790. $invoiceStore = new invoiceStore ();
  1791. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1792. Doo::loadModel ( 'invoiceManage' );
  1793. $invoiceManage = new invoiceManage ();
  1794. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1795. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1796. $moldManage = array ();
  1797. foreach ( $invoiceManageList as $key => $value ) {
  1798. if ($value ['mold'] == '发票打印')
  1799. $moldManage [$value ['mold']] = $value ['staffList'];
  1800. elseif ($value ['mold'] == '发票邮寄')
  1801. $moldManage [$value ['mold']] = $value ['staffList'];
  1802. elseif ($value ['mold'] == '发票退票')
  1803. $moldManage [$value ['mold']] = $value ['staffList'];
  1804. }
  1805. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1806. // 批量更新发票信息
  1807. $item = array (
  1808. 'date' => date ( "Y-m-d H:i:s" ),
  1809. 'status' => 1,
  1810. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1811. 'trainId' => $trainId,
  1812. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1813. 'moldManage' => json_encode ( $moldManage ),
  1814. 'settlementType' => 1,
  1815. 'pendingApprovals' => $pendingApprovalsSid
  1816. );
  1817. $invoice = new invoice ();
  1818. $invoice->BatchInvoiceByCondition ( $item, $iidString );
  1819. // 批量更新发票中仓库isid
  1820. $sql = "UPDATE CLD_invoiceStore SET isid = CASE iid ";
  1821. foreach ( $sqlList as $isid => $iid ) {
  1822. $sql .= sprintf ( "WHEN %d THEN %d ", $iid, $isid );
  1823. }
  1824. $sql .= "END WHERE iid IN ($iidString)";
  1825. $invoice = new invoice ();
  1826. $invoice->UpdateBatchInvoice ( $sql );
  1827. // 批量更新发票序列号
  1828. $sqlList = array ();
  1829. foreach ( $iida as $value ) {
  1830. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1831. $sqlList [$value] = "#FE" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1832. }else{
  1833. $sqlList [$value] = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1834. }
  1835. }
  1836. $ids = implode ( ',', array_keys ( $sqlList ) );
  1837. $sql = "UPDATE CLD_invoice SET invoiceSerial = CASE iid ";
  1838. foreach ( $sqlList as $id => $ordinal ) {
  1839. $sql .= sprintf ( "WHEN %d THEN '%s' ", $id, $ordinal );
  1840. }
  1841. $sql .= "END WHERE iid IN ($ids)";
  1842. $invoiceStore = new invoiceStore ();
  1843. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1844. // 批量生产操作日志
  1845. Doo::loadModel ( 'invoiceOperationLog' );
  1846. $sqlList = array ();
  1847. foreach ( $iida as $key => $value ) {
  1848. $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 . '"),
  1849. ("' . 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 . '") ';
  1850. array_push ( $sqlList, $sql );
  1851. }
  1852. $iolSql = implode ( ',', $sqlList );
  1853. $sql = "INSERT INTO `CLD_invoiceOperationLog` (`date`, `operation`, `status`, `img`, `username`, `uid`, `category`, `iid`) VALUES " . $iolSql;
  1854. $invoiceOperationLog = new invoiceOperationLog ();
  1855. $invoiceOperationLog->setInvoiceOperationLogBySql ( $sql );
  1856. Doo::loadModel ( 'invoiceTraining' );
  1857. $invoiceTraining = new invoiceTraining ();
  1858. $item = array (
  1859. 'itid' => $trainId,
  1860. 'submitStatus' => 1
  1861. );
  1862. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1863. Doo::loadModel ( 'staff' );
  1864. $staff = new staff ();
  1865. $username2 = $staff->getOne ( array (
  1866. 'select' => 'wxid',
  1867. 'where' => 'sid=' . $pendingApprovalsSid,
  1868. 'asArray' => TRUE
  1869. ) );
  1870. // 发送微信审批通知
  1871. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1872. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1873. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1874. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1875. }else{
  1876. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1877. }
  1878. }
  1879. /**
  1880. */
  1881. function invoiceStoreMailItemSet() {
  1882. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1883. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1884. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1885. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1886. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1887. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1888. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1889. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1890. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1891. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1892. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1893. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1894. Doo::loadClass ( 'XDeode' );
  1895. $XDeode = new XDeode ( 5 );
  1896. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1897. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1898. $isid = $XDeode->decode ( $storeKey );
  1899. $trainId = $XDeode->decode ( $trainKey );
  1900. if (! is_numeric ( $isid ))
  1901. die ( 'illegal request' );
  1902. Doo::loadModel ( 'invoiceStore' );
  1903. $invoiceStore = new invoiceStore ();
  1904. $mailList = array (
  1905. 'mailItems' => $mailItems
  1906. );
  1907. $mailString = '发票x1,备注:' . $mailItems;
  1908. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1909. $mailString = '备注:' . $mailItems;
  1910. }else{
  1911. $mailList += array (
  1912. 'invoice' => 1,
  1913. );
  1914. }
  1915. if (! empty ( $softLock ))
  1916. $mailList += array (
  1917. 'softLock' => $softLockNum
  1918. );
  1919. else
  1920. $mailList += array (
  1921. 'softLock' => 0
  1922. );
  1923. if (! empty ( $contract ))
  1924. $mailList += array (
  1925. 'contract' => $contractNum
  1926. );
  1927. else
  1928. $mailList += array (
  1929. 'contract' => 0
  1930. );
  1931. if (! empty ( $instructions ))
  1932. $mailList += array (
  1933. 'instructions' => $instructionsNum
  1934. );
  1935. else
  1936. $mailList += array (
  1937. 'instructions' => 0
  1938. );
  1939. if (! empty ( $remittance ))
  1940. $mailList += array (
  1941. 'remittance' => $remittance
  1942. );
  1943. else
  1944. $mailList += array (
  1945. 'remittance' => ''
  1946. );
  1947. if (! empty ( $softLock ))
  1948. $mailString .= ',软件锁x' . $softLockNum;
  1949. if (! empty ( $contract ))
  1950. $mailString .= ',合同x' . $contractNum;
  1951. if (! empty ( $instructions ))
  1952. $mailString .= ',说明书x' . $instructionsNum;
  1953. if (! empty ( $remittance ))
  1954. $mailString .= ',汇款账号单';
  1955. $item = array (
  1956. 'isid' => $isid,
  1957. 'doPost' => 1,
  1958. 'mailItems' => $mailString,
  1959. 'mailItemsJson' => json_encode ( $mailList )
  1960. );
  1961. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1962. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1963. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1964. }else{
  1965. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1966. }
  1967. }
  1968. /**
  1969. * 批量设置邮寄物品
  1970. */
  1971. function invoiceStoreBatchMailItemSet() {
  1972. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1973. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1974. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1975. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1976. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1977. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1978. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1979. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1980. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1981. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1982. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1983. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1984. Doo::loadClass ( 'XDeode' );
  1985. $XDeode = new XDeode ( 5 );
  1986. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1987. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1988. if (empty ( $trainKey ) || empty ( $storeKey ))
  1989. die ( 'illegal request-IdKey' );
  1990. $isidKeyList = explode ( ',', $storeKey );
  1991. $isidList = array ();
  1992. foreach ( $isidKeyList as $value ) {
  1993. $isid = $XDeode->decode ( $value );
  1994. if (! empty ( $isid ) && is_numeric ( $isid ))
  1995. array_push ( $isidList, $isid );
  1996. }
  1997. $isidString = implode ( ',', $isidList );
  1998. $trainId = $XDeode->decode ( $trainKey );
  1999. if (! is_numeric ( $isid ))
  2000. die ( 'illegal request' );
  2001. Doo::loadModel ( 'invoiceStore' );
  2002. $invoiceStore = new invoiceStore ();
  2003. $mailList = array (
  2004. 'mailItems' => $mailItems
  2005. );
  2006. $mailString = '发票x1,备注:' . $mailItems;
  2007. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  2008. $mailString = '备注:' . $mailItems;
  2009. }else{
  2010. $mailList += array (
  2011. 'invoice' => 1,
  2012. );
  2013. }
  2014. if (! empty ( $softLock ))
  2015. $mailList += array (
  2016. 'softLock' => $softLockNum
  2017. );
  2018. else
  2019. $mailList += array (
  2020. 'softLock' => 0
  2021. );
  2022. if (! empty ( $contract ))
  2023. $mailList += array (
  2024. 'contract' => $contractNum
  2025. );
  2026. else
  2027. $mailList += array (
  2028. 'contract' => 0
  2029. );
  2030. if (! empty ( $instructions ))
  2031. $mailList += array (
  2032. 'instructions' => $instructionsNum
  2033. );
  2034. else
  2035. $mailList += array (
  2036. 'instructions' => 0
  2037. );
  2038. if (! empty ( $remittance ))
  2039. $mailList += array (
  2040. 'remittance' => $remittance
  2041. );
  2042. else
  2043. $mailList += array (
  2044. 'remittance' => ''
  2045. );
  2046. if (! empty ( $softLock ))
  2047. $mailString .= ',软件锁x' . $softLockNum;
  2048. if (! empty ( $contract ))
  2049. $mailString .= ',合同x' . $contractNum;
  2050. if (! empty ( $instructions ))
  2051. $mailString .= ',说明书x' . $instructionsNum;
  2052. if (! empty ( $remittance ))
  2053. $mailString .= ',汇款账号单';
  2054. $item = array (
  2055. 'doPost' => 1,
  2056. 'mailItems' => $mailString,
  2057. 'mailItemsJson' => json_encode ( $mailList )
  2058. );
  2059. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  2060. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  2061. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  2062. }else{
  2063. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  2064. }
  2065. }
  2066. /**
  2067. * 废弃
  2068. */
  2069. function ajaxGetMailItemByIstore() {
  2070. Doo::loadClass ( 'XDeode' );
  2071. $XDeode = new XDeode ( 5 );
  2072. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  2073. $isid = $XDeode->decode ( $storeKey );
  2074. if (! is_numeric ( $isid ))
  2075. die ( 'illegal request' );
  2076. Doo::loadModel ( 'invoiceStore' );
  2077. $invoiceStore = new invoiceStore ();
  2078. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid );
  2079. $isDetail ['mailItemsJson'] = json_decode ( $isDetail ['mailItemsJson'], true );
  2080. echo json_encode ( $isDetail ['mailItemsJson'] );
  2081. exit ();
  2082. }
  2083. /**
  2084. * 终止开票
  2085. */
  2086. function invoiceDroppedDo() {
  2087. $droppedIidKey = $this->get_args ( 'droppedIidKey' ) ? $this->get_args ( 'droppedIidKey' ) : '';
  2088. Doo::loadModel ( 'invoice' );
  2089. $invoice = new invoice ();
  2090. Doo::loadModel ( 'invoiceOperationLog' );
  2091. $invoiceOperationLog = new invoiceOperationLog ();
  2092. $iid = $invoice->authcode ( $droppedIidKey );
  2093. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2094. die ( 'illegal request' );
  2095. $item = array (
  2096. 'iid' => $iid,
  2097. 'status' => 4,
  2098. 'updateTime' => date ( "Y-m-d H:i:s" )
  2099. );
  2100. $invoice->setInvoiceByCondition ( $item );
  2101. $item = array (
  2102. 'date' => date ( "Y-m-d H:i:s" ),
  2103. 'operation' => '终止了开票',
  2104. 'status' => 4,
  2105. 'img' => $this->staff [0] ['avatar'],
  2106. 'username' => $this->staff [0] ['username'],
  2107. 'uid' => $this->staff [0] ['sid'],
  2108. 'category' => $this->staff [0] ['category'],
  2109. 'iid' => $iid
  2110. );
  2111. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2112. return "/invoice";
  2113. }
  2114. /**
  2115. * 更新退票的邮寄信息
  2116. */
  2117. function invoiceUntreadMailDo() {
  2118. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  2119. $untreadCompany = $this->get_args ( 'untreadCompany' ) ? $this->get_args ( 'untreadCompany' ) : "";
  2120. $untreadNumber = $this->get_args ( 'untreadNumber' ) ? $this->get_args ( 'untreadNumber' ) : "";
  2121. $untreadItems = $this->get_args ( 'untreadItems' ) ? $this->get_args ( 'untreadItems' ) : "";
  2122. Doo::loadModel ( 'invoice' );
  2123. $invoice = new invoice ();
  2124. $iid = $invoice->authcode ( $untreadIidKey );
  2125. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2126. die ( 'illegal request' );
  2127. $item = array (
  2128. 'iid' => $iid,
  2129. 'untreadCompany' => $untreadCompany,
  2130. 'untreadNumber' => $untreadNumber,
  2131. 'untreadItems' => $untreadItems
  2132. );
  2133. $invoice->setInvoiceByCondition ( $item );
  2134. return "/invoice";
  2135. }
  2136. /**
  2137. * 申请退票 --
  2138. */
  2139. function invoiceUntreadDo() {
  2140. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  2141. $untreadReason = $this->get_args ( 'untreadReason' ) ? $this->get_args ( 'untreadReason' ) : "";
  2142. $untreadPost = $this->get_args ( 'untreadPost' ) ? $this->get_args ( 'untreadPost' ) : "";
  2143. Doo::loadModel ( 'invoice' );
  2144. $invoice = new invoice ();
  2145. Doo::loadModel ( 'invoiceOperationLog' );
  2146. $invoiceOperationLog = new invoiceOperationLog ();
  2147. Doo::loadModel ( 'invoiceReceivables' );
  2148. $invoiceReceivables = new invoiceReceivables ();
  2149. $iid = $invoice->authcode ( $untreadIidKey );
  2150. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2151. die ( 'illegal request' );
  2152. /*
  2153. * 需求变革 有绑定收款也可以退票 $lt = $invoiceReceivables->getInvoiceReceivablesByIid ( $untreadIidKey ); if (! empty ( $lt )) { header ( 'Content-Type:text/html;charset=utf-8' ); die ( '该发票有收款绑定,请先移除!' ); }
  2154. */
  2155. $item = array (
  2156. 'iid' => $iid,
  2157. 'untreadStatus' => 1,
  2158. 'untreadReason' => $untreadReason,
  2159. 'untreadPost' => $untreadPost,
  2160. 'updateTime' => date ( "Y-m-d H:i:s" )
  2161. );
  2162. $invoice->setInvoiceByCondition ( $item );
  2163. $item = array (
  2164. 'date' => date ( "Y-m-d H:i:s" ),
  2165. 'operation' => '申请退票',
  2166. 'status' => 7,
  2167. 'img' => $this->staff [0] ['avatar'],
  2168. 'username' => $this->staff [0] ['username'],
  2169. 'uid' => $this->staff [0] ['sid'],
  2170. 'category' => $this->staff [0] ['category'],
  2171. 'iid' => $iid
  2172. );
  2173. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2174. return "/invoice";
  2175. }
  2176. /**
  2177. * 删除已终止的开票
  2178. */
  2179. function invoiceDelDo() {
  2180. Doo::loadModel ( 'invoice' );
  2181. $invoice = new invoice ();
  2182. Doo::loadModel ( 'invoiceOperationLog' );
  2183. $invoiceOperationLog = new invoiceOperationLog ();
  2184. Doo::loadClass ( 'XDeode' );
  2185. $XDeode = new XDeode ( 5 );
  2186. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  2187. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  2188. $iid = $XDeode->decode ( $iid );
  2189. Doo::loadModel ( 'invoiceStore' );
  2190. $invoiceStore = new invoiceStore ();
  2191. if (! is_numeric ( $iid ))
  2192. die ( 'illegal request' );
  2193. $invoiceDetail = $invoice->getMyInvoice ( $sid, $iid );
  2194. if (empty ( $invoiceDetail ))
  2195. die ( 'illegal request' );
  2196. $item = array (
  2197. 'iid' => $iid,
  2198. 'isDelete' => 1,
  2199. 'updateTime' => date ( "Y-m-d H:i:s" )
  2200. );
  2201. $invoice->setInvoiceByCondition ( $item );
  2202. $item = array (
  2203. 'date' => date ( "Y-m-d H:i:s" ),
  2204. 'operation' => '删除了已终止的发票',
  2205. 'status' => 4,
  2206. 'img' => $this->staff [0] ['avatar'],
  2207. 'username' => $this->staff [0] ['username'],
  2208. 'uid' => $this->staff [0] ['sid'],
  2209. 'category' => $this->staff [0] ['category'],
  2210. 'iid' => $iid
  2211. );
  2212. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2213. // 删除培训班发票仓库里的发票
  2214. $invoiceStore->delInvoiceStoreByIsid ( $invoiceDetail ['isid'] );
  2215. return "/invoice";
  2216. }
  2217. /**
  2218. */
  2219. function invoiceApproval() {
  2220. Doo::loadModel ( 'invoice' );
  2221. $invoice = new invoice ();
  2222. Doo::loadClass ( 'XDeode' );
  2223. $XDeode = new XDeode ( 5 );
  2224. Doo::loadModel ( 'staff' );
  2225. $staff = new staff ();
  2226. $invoiceList = $invoice->find ( array (
  2227. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  2228. 'desc' => 'iid',
  2229. 'limit' => 10,
  2230. 'asArray' => true
  2231. ) );
  2232. foreach ( $invoiceList as $key => $value ) {
  2233. $invoiceList [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2234. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2235. if (! empty ( $lastApprover )) {
  2236. $lastApproverKey = array_keys ( $lastApprover );
  2237. $lastApprover = end ( $lastApprover );
  2238. $staffDetail = $staff->getOne ( array (
  2239. 'where' => 'sid=' . end ( $lastApproverKey ),
  2240. 'asArray' => true
  2241. ) );
  2242. $lastApprover ['username'] = $staffDetail ['username'];
  2243. }
  2244. $invoiceList [$key] ['lastApprover'] = $lastApprover;
  2245. }
  2246. $ilist = $invoice->getInvoiceByProcessStatus ();
  2247. foreach ( $ilist as $key => $value ) {
  2248. $ilist [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2249. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2250. if (! empty ( $lastApprover )) {
  2251. $lastApproverKey = array_keys ( $lastApprover );
  2252. $lastApprover = end ( $lastApprover );
  2253. $staffDetail = $staff->getOne ( array (
  2254. 'where' => 'sid=' . end ( $lastApproverKey ),
  2255. 'asArray' => true
  2256. ) );
  2257. $lastApprover ['username'] = $staffDetail ['username'];
  2258. }
  2259. $ilist [$key] ['lastApprover'] = $lastApprover;
  2260. }
  2261. // print_r($ilist);
  2262. $this->data ['invoiceList'] = $invoiceList;
  2263. $this->data ['ilist'] = $ilist;
  2264. $this->data ['memu'] = "invoice";
  2265. $this->data ['staff'] = $this->staff;
  2266. $this->data ['receiptMemu'] = 'invoiceApproval';
  2267. $this->render ( "/admin/invoiceApproval", $this->data );
  2268. }
  2269. function invoiceDetail() {
  2270. Doo::loadClass ( 'XDeode' );
  2271. $XDeode = new XDeode ( 5 );
  2272. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  2273. $iid = $XDeode->decode ( $iid );
  2274. if (! is_numeric ( $iid ))
  2275. die ( 'illegal request' );
  2276. Doo::loadModel ( 'invoice' );
  2277. $invoice = new invoice ();
  2278. Doo::loadModel ( 'invoiceOperationLog' );
  2279. $invoiceOperationLog = new invoiceOperationLog ();
  2280. $invoiceDetail = $invoice->getOne ( array (
  2281. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'] . ' and iid=' . $iid,
  2282. 'asArray' => true
  2283. ) );
  2284. if (empty ( $invoiceDetail ))
  2285. die ( 'illegal request' );
  2286. if ($invoiceDetail ['settlementType'] == 1) {
  2287. Doo::loadModel ( 'invoiceTraining' );
  2288. $invoiceTraining = new invoiceTraining ();
  2289. $invoiceDetail ['invoiceTraining'] = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceDetail ['trainId'] );
  2290. }
  2291. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  2292. $this->data ['invoiceDetail'] = $invoiceDetail;
  2293. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  2294. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  2295. $this->data ['memu'] = "invoice";
  2296. $this->data ['staff'] = $this->staff;
  2297. $this->data ['receiptMemu'] = 'invoiceApproval';
  2298. $this->render ( "/admin/invoiceApprovalDetail", $this->data );
  2299. }
  2300. /**
  2301. * 对发票进行审批,其中操作有终止,退回,同意动作。操作成功并记录下操作日志
  2302. *
  2303. * @since 1.0.0
  2304. * @var integer iid 开票ID 已加密
  2305. * @var integer status 发票审批状态
  2306. * @var integer opintion 审批发票的意见
  2307. * @return string 如操作成功返回审批首页
  2308. */
  2309. function invoiceApprovalDo() {
  2310. Doo::loadModel ( 'invoice' );
  2311. $invoice = new invoice ();
  2312. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2313. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  2314. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  2315. $divApproval = $this->get_args ( 'divApproval' ) ? $this->get_args ( 'divApproval' ) : "";
  2316. $iid = $invoice->authcode ( $iid );
  2317. if (! is_numeric ( $iid ))
  2318. die ( 'illegal request' );
  2319. // && ! empty ( $opinion )
  2320. if (! empty ( $iid ) && ! empty ( $status )) {
  2321. if (! ($status == 2 || $status == 3 || $status == 4))
  2322. die ( 'illegal request' );
  2323. Doo::loadModel ( 'invoiceOperationLog' );
  2324. $invoiceOperationLog = new invoiceOperationLog ();
  2325. $invoiceDetail = $invoice->getOne ( array (
  2326. 'where' => 'status=1 and iid=' . $iid . ' and pendingApprovals=' . $this->staff [0] ['sid'],
  2327. 'asArray' => true
  2328. ) );
  2329. if (empty ( $invoiceDetail ))
  2330. die ( 'illegal request' );
  2331. $processApprovals = json_decode ( $invoiceDetail ['processApprovals'], true );
  2332. $invoiceManage = json_decode ( $invoiceDetail ['invoiceManage'], true );
  2333. if ($status == 3) {
  2334. $invoice->status = $status;
  2335. $item = array (
  2336. 'operation' => $opinion
  2337. );
  2338. } else {
  2339. if (empty ( $processApprovals )) {
  2340. $processApprovals = array (
  2341. $this->staff [0] ['sid'] => array (
  2342. 'date' => date ( "Y-m-d H:i:s" ),
  2343. 'opinion' => $opinion,
  2344. 'status' => $status
  2345. )
  2346. );
  2347. // var_dump(next($invoiceManage));
  2348. $nextInvoiceManage = next ( $invoiceManage );
  2349. // print_r($nextInvoiceManage);
  2350. if ($status != 4 && $nextInvoiceManage !== false)
  2351. $invoice->pendingApprovals = $nextInvoiceManage [0];
  2352. $invoice->processApprovals = json_encode ( $processApprovals );
  2353. // var_dump($invoice);
  2354. // print_r($invoiceManage);
  2355. } else {
  2356. $processApprovals [$this->staff [0] ['sid']] = array (
  2357. 'date' => date ( "Y-m-d H:i:s" ),
  2358. 'opinion' => $opinion,
  2359. 'status' => $status
  2360. );
  2361. $pendingApprovals = 0;
  2362. foreach ( $invoiceManage as $key => $value ) {
  2363. if ($value [0] == $this->staff [0] ['sid']) {
  2364. if (isset ( $invoiceManage [$key + 1] ))
  2365. $pendingApprovals = $invoiceManage [$key + 1] [0];
  2366. break;
  2367. }
  2368. }
  2369. if ($status != 4 && ! empty ( $pendingApprovals ))
  2370. $invoice->pendingApprovals = $pendingApprovals;
  2371. $invoice->processApprovals = json_encode ( $processApprovals );
  2372. }
  2373. $item = array (
  2374. 'operation' => $opinion
  2375. );
  2376. if (count ( $processApprovals ) == count ( $invoiceManage ) && $status != 4) {
  2377. $invoice->status = $status;
  2378. $invoice->pendingApprovals = 0;
  2379. $invoice->approvalTime = date ( "Y-m-d H:i:s" );
  2380. } elseif ($status == 4) {
  2381. $invoice->status = $status;
  2382. $item = array (
  2383. 'operation' => $opinion
  2384. );
  2385. }
  2386. }
  2387. $invoice->updateTime = date ( "Y-m-d H:i:s" );
  2388. $invoice->update ( array (
  2389. 'where' => 'iid=' . $iid
  2390. ) );
  2391. $item += array (
  2392. 'date' => date ( "Y-m-d H:i:s" ),
  2393. 'img' => $this->staff [0] ['avatar'],
  2394. 'username' => $this->staff [0] ['username'],
  2395. 'uid' => $this->staff [0] ['sid'],
  2396. 'category' => $this->staff [0] ['category'],
  2397. 'status' => $status,
  2398. 'iid' => $iid
  2399. );
  2400. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2401. if (empty ( $divApproval ))
  2402. return '/invoiceApproval';
  2403. else
  2404. return '/invoiceApprovalAchieve/PEND';
  2405. }
  2406. die ( 'illegal request' );
  2407. }
  2408. /**
  2409. * 展示需要打印的发票数据
  2410. *
  2411. * @since 1.0.0
  2412. */
  2413. function invoicePrint() {
  2414. Doo::loadModel ( 'invoice' );
  2415. $invoice = new invoice ();
  2416. Doo::loadClass ( 'XDeode' );
  2417. $XDeode = new XDeode ( 5 );
  2418. Doo::loadModel ( 'staff' );
  2419. $staff = new staff ();
  2420. $toPrint = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0 );
  2421. $printed = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 1 );
  2422. foreach ( $toPrint as $key => $value ) {
  2423. $toPrint [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2424. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2425. if (! empty ( $lastApprover )) {
  2426. $lastApproverKey = array_keys ( $lastApprover );
  2427. $lastApprover = end ( $lastApprover );
  2428. $staffDetail = $staff->getOne ( array (
  2429. 'where' => 'sid=' . end ( $lastApproverKey ),
  2430. 'asArray' => true
  2431. ) );
  2432. $lastApprover ['username'] = $staffDetail ['username'];
  2433. }
  2434. $toPrint [$key] ['lastApprover'] = $lastApprover;
  2435. }
  2436. foreach ( $printed as $key => $value ) {
  2437. $printed [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2438. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2439. if (! empty ( $lastApprover )) {
  2440. $lastApproverKey = array_keys ( $lastApprover );
  2441. $lastApprover = end ( $lastApprover );
  2442. $staffDetail = $staff->getOne ( array (
  2443. 'where' => 'sid=' . end ( $lastApproverKey ),
  2444. 'asArray' => true
  2445. ) );
  2446. $lastApprover ['username'] = $staffDetail ['username'];
  2447. }
  2448. $printed [$key] ['lastApprover'] = $lastApprover;
  2449. }
  2450. $this->data ['printed'] = $printed;
  2451. $this->data ['toPrint'] = $toPrint;
  2452. $this->data ['memu'] = "invoice";
  2453. $this->data ['staff'] = $this->staff;
  2454. $this->data ['receiptMemu'] = 'invoicePrint';
  2455. $this->render ( "/admin/invoicePrint", $this->data );
  2456. }
  2457. /**
  2458. * 展示发票打印的详情页面
  2459. *
  2460. * @since 1.0.0
  2461. */
  2462. function invoicePrintDetail() {
  2463. Doo::loadClass ( 'XDeode' );
  2464. $XDeode = new XDeode ( 5 );
  2465. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  2466. $iid = $XDeode->decode ( $iid );
  2467. if (! is_numeric ( $iid ))
  2468. die ( 'illegal request' );
  2469. Doo::loadModel ( 'invoice' );
  2470. $invoice = new invoice ();
  2471. Doo::loadModel ( 'invoiceOperationLog' );
  2472. $invoiceOperationLog = new invoiceOperationLog ();
  2473. Doo::loadModel ( 'invoicePaper' );
  2474. $invoicePaper = new invoicePaper ();
  2475. $invoiceDetail = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0, $iid );
  2476. if (empty ( $invoiceDetail ))
  2477. die ( 'illegal request' );
  2478. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $invoiceDetail ['invoiceType'],$invoiceDetail['invoiceForm'] );
  2479. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  2480. if ($invoiceDetail ['settlementType'] == 1) {
  2481. Doo::loadModel ( 'invoiceTraining' );
  2482. $invoiceTraining = new invoiceTraining ();
  2483. $invoiceDetail ['invoiceTraining'] = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceDetail ['trainId'] );
  2484. }
  2485. $this->data ['invoicePaperList'] = $invoicePaperList;
  2486. $this->data ['invoiceDetail'] = $invoiceDetail;
  2487. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  2488. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  2489. $this->data ['memu'] = "invoice";
  2490. $this->data ['staff'] = $this->staff;
  2491. $this->data ['receiptMemu'] = 'invoicePrint';
  2492. $this->render ( "/admin/invoicePrintDetail", $this->data );
  2493. }
  2494. /**
  2495. * 所有待打印 发票
  2496. */
  2497. function invoicePrintStayAchieve() {
  2498. Doo::loadModel ( 'invoice' );
  2499. $invoice = new invoice ();
  2500. Doo::loadClass ( 'XDeode' );
  2501. $XDeode = new XDeode ( 5 );
  2502. Doo::loadModel ( 'staff' );
  2503. $staff = new staff ();
  2504. $MebSea = $this->get_args ( 'MebSea' ) ? urldecode ( $this->get_args ( 'MebSea' ) ) : "";
  2505. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  2506. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  2507. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  2508. Doo::loadModel ( 'invoiceTraining' );
  2509. $invoiceTraining = new invoiceTraining ();
  2510. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  2511. $page_size = 12;
  2512. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2513. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : "ALL";
  2514. // $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : "ALL";
  2515. $get = "/" . $status;
  2516. $con = ' and status=2 ';
  2517. if ($status == 'TOPRINT')
  2518. $con = ' and status=2 and printStatus=0 ';
  2519. elseif ($status == 'PRINTED')
  2520. $con = ' and status=2 and printStatus=1';
  2521. if ($invoiceType == 'ORDINARY')
  2522. $con .= ' and invoiceType=0 ';
  2523. elseif ($invoiceType == 'SPECIAL')
  2524. $con .= ' and invoiceType=1 ';
  2525. if ($invoiceTrain == 'ORDINARY')
  2526. $con .= ' and trainId=0 ';
  2527. elseif ($invoiceTrain == 'TRAIN')
  2528. $con .= ' and trainId!=0 ';
  2529. if ($invoiceTrainName != 'ALL') {
  2530. $trainId = $XDeode->decode ( $invoiceTrainName );
  2531. if (is_numeric ( $trainId ))
  2532. $con .= ' and trainId =' . $trainId;
  2533. }
  2534. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2535. $dateArr = explode ( ':', $date );
  2536. $D1 = '';
  2537. $D2 = '';
  2538. if (! empty ( $date )) {
  2539. $D1 = $dateArr [0];
  2540. $D2 = $dateArr [1];
  2541. }
  2542. if (! empty ( $D1 ) && ! empty ( $D2 ) && ! empty ( $date ))
  2543. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2544. if (! empty ( $MebSea )) {
  2545. $con .= ' and ( invoiceNo like "%' . $MebSea . '%" or invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  2546. }
  2547. $pageinfo ['page'] = array (
  2548. 'previous' => ''
  2549. );
  2550. $get .= "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&invoiceType=" . urlencode ( $invoiceType ) . "&invoiceTrain=" . urlencode ( $invoiceTrain ) . "";
  2551. $sql = " (untreadStatus=0 or untreadStatus=3) and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  2552. $action = "invoicePrintStayAchieve";
  2553. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2554. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2555. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  2556. $this->data ['trainList'] = $trainList;
  2557. $this->data ['invoiceType'] = $invoiceType;
  2558. $this->data ['invoiceTrain'] = $invoiceTrain;
  2559. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  2560. $this->data ['MebSeaEn'] = $MebSea;
  2561. $this->data ['MebSea'] = urlencode ( $MebSea );
  2562. $this->data ['get'] = $get;
  2563. $this->data ['page'] = $pageinfo;
  2564. $this->data ['date'] = $date;
  2565. $this->data ['status'] = $status;
  2566. $this->data ['invoiceType'] = $invoiceType;
  2567. $this->data ['memu'] = "invoice";
  2568. $this->data ['staff'] = $this->staff;
  2569. foreach ( $list as $key => $value ) {
  2570. $list [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2571. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2572. if (! empty ( $lastApprover )) {
  2573. $lastApproverKey = array_keys ( $lastApprover );
  2574. $lastApprover = end ( $lastApprover );
  2575. $staffDetail = $staff->getOne ( array (
  2576. 'where' => 'sid=' . end ( $lastApproverKey ),
  2577. 'asArray' => true
  2578. ) );
  2579. $lastApprover ['username'] = $staffDetail ['username'];
  2580. }
  2581. $list [$key] ['lastApprover'] = $lastApprover;
  2582. }
  2583. $this->data ['receiptMemu'] = 'invoicePrint';
  2584. $this->data ['list'] = $list;
  2585. $this->render ( "/admin/invoicePrintStayAchieve", $this->data );
  2586. }
  2587. /**
  2588. * 填写票号并完成打印
  2589. * @since 1.0.0
  2590. */
  2591. function invoicePrintDo() {
  2592. Doo::loadModel ( 'invoice' );
  2593. $invoice = new invoice ();
  2594. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2595. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  2596. $invoicePrintType = $this->get_args ( 'invoicePrintType' ) ? $this->get_args ( 'invoicePrintType' ) : "";
  2597. $iid = $invoice->authcode ( $iid );
  2598. if (! is_numeric ( $iid ))
  2599. die ( 'illegal request' );
  2600. if (! empty ( $iid ) && ! empty ( $invoiceNo )) {
  2601. Doo::loadModel ( 'invoiceOperationLog' );
  2602. $invoiceOperationLog = new invoiceOperationLog ();
  2603. Doo::loadModel ( 'invoiceStatistics' );
  2604. $invoiceStatistics = new invoiceStatistics ();
  2605. $XDeode = new XDeode ( 5 );
  2606. Doo::loadModel ( 'invoicePaper' );
  2607. $invoicePaper = new invoicePaper ();
  2608. $invoicePrintDetail = $invoice->getInvoiceByPrint ( $iid );
  2609. if (empty ( $invoicePrintDetail ))
  2610. die ( 'illegal request' );
  2611. //
  2612. $ipid = $XDeode->decode ( $invoiceNo );
  2613. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  2614. if (empty ( $paperDetail ))
  2615. die ( 'illegal request' );
  2616. $invoicePaper = new invoicePaper ();
  2617. $item = array (
  2618. 'iid' => $iid,
  2619. 'ipid' => $ipid
  2620. );
  2621. $invoicePaper->setInvoicePaperByCondition ( $item );
  2622. $item = array (
  2623. 'iid' => $iid,
  2624. 'printStatus' => 1,
  2625. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2626. 'printer' => $this->staff [0] ['username'],
  2627. 'printTime' => date ( "Y-m-d H:i:s" ),
  2628. 'invoiceNo' => $paperDetail ['invoiceNo']
  2629. );
  2630. $invoice->setInvoiceByCondition ( $item );
  2631. $item = array (
  2632. 'date' => date ( "Y-m-d H:i:s" ),
  2633. 'operation' => '打印发票号:' . $paperDetail ['invoiceNo'],
  2634. 'status' => 5,
  2635. 'img' => $this->staff [0] ['avatar'],
  2636. 'username' => $this->staff [0] ['username'],
  2637. 'uid' => $this->staff [0] ['sid'],
  2638. 'category' => $this->staff [0] ['category'],
  2639. 'iid' => $iid
  2640. );
  2641. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2642. // 去统计--负票不汇总
  2643. if ($invoicePrintDetail ['untreadStatus'] != 4) {
  2644. $item = array (
  2645. 'date' => date ( "Y-m-d H:i:s" ),
  2646. 'priceClass' => 1,
  2647. 'cid' => $invoicePrintDetail ['cid'],
  2648. 'staff' => $invoicePrintDetail ['sid'],
  2649. 'invoicePrice' => $invoicePrintDetail ['invoicePrice']
  2650. );
  2651. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2652. }
  2653. // 发送通知信息到微信-去除
  2654. // $this->setWXMsg($iid,'PRINT');
  2655. // 发票信息库
  2656. $this->autoUpdateInvoiceInfoBase ( $invoicePrintDetail );
  2657. // 申请人获取微信通知
  2658. Doo::loadModel ( 'staff' );
  2659. $staff = new staff ();
  2660. Doo::loadClass ( 'XDeode' );
  2661. $XDeode = new XDeode ( 5 );
  2662. $username2 = $staff->getOne ( array (
  2663. 'select' => 'wxid',
  2664. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2665. 'asArray' => TRUE
  2666. ) );
  2667. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '完成打印';
  2668. $msg = '';
  2669. $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/' . $XDeode->encode ( $invoicePrintDetail ['iid'] ) . '.html';
  2670. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2671. if (empty ( $invoicePrintType ))
  2672. return "/invoicePrint";
  2673. else
  2674. return "/invoicePrintStayAchieve";
  2675. }
  2676. }
  2677. /**
  2678. * 需要邮寄的发票
  2679. * @since 1.0.0
  2680. */
  2681. function invoicePost() {
  2682. Doo::loadModel ( 'invoice' );
  2683. $invoice = new invoice ();
  2684. Doo::loadModel ( 'express' );
  2685. $express = new express ();
  2686. $invoicePost = $invoice->getPostByInvoice ();
  2687. $invoicePosted = $invoice->getPostByInvoice ( 1 );
  2688. $expressList = $express->getExpressByAll ();
  2689. $invoicePostExpress = "";
  2690. if (isset ( $_COOKIE ["invoicePostExpress"] ))
  2691. $invoicePostExpress = $_COOKIE ["invoicePostExpress"];
  2692. $this->data ['invoicePostExpress'] = $invoicePostExpress;
  2693. $this->data ['expressList'] = $expressList;
  2694. $this->data ['invoicePost'] = $invoicePost;
  2695. $this->data ['invoicePosted'] = $invoicePosted;
  2696. $this->data ['memu'] = "invoice";
  2697. $this->data ['staff'] = $this->staff;
  2698. $this->data ['receiptMemu'] = 'invoicePost';
  2699. $this->render ( "/admin/invoicePost", $this->data );
  2700. }
  2701. /**
  2702. * 添加发票邮寄信息
  2703. */
  2704. function invoiceExpressAddDo() {
  2705. Doo::loadModel ( 'invoice' );
  2706. $invoice = new invoice ();
  2707. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2708. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2709. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2710. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2711. $iid = $iid = $invoice->authcode ( $iid );
  2712. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2713. die ( 'illegal request' );
  2714. $invoicePrintDetail = $invoice->getInvoiceByIid ( $iid );
  2715. setcookie ( 'invoicePostExpress', $expressNumber );
  2716. $item = array (
  2717. 'iid' => $iid,
  2718. 'postStatus' => 1,
  2719. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2720. 'postTime' => date ( "Y-m-d H:i:s" ),
  2721. 'expressCompany' => $expressCompany,
  2722. 'expressNumber' => $expressNumber,
  2723. 'actualItems' => $actualItems,
  2724. 'poster' => $this->staff [0] ['username']
  2725. );
  2726. $invoice->setInvoiceByCondition ( $item );
  2727. // 微信通知-去掉
  2728. // $this->setWXMsg ( $iid );
  2729. Doo::loadModel ( 'staff' );
  2730. $staff = new staff ();
  2731. Doo::loadClass ( 'XDeode' );
  2732. $XDeode = new XDeode ( 5 );
  2733. $username2 = $staff->getOne ( array (
  2734. 'select' => 'wxid',
  2735. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2736. 'asArray' => TRUE
  2737. ) );
  2738. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '已邮寄';
  2739. $expCom = explode ( ":", $invoicePrintDetail ['expressCompany'] );
  2740. if (empty ( $expCom ))
  2741. $expCom [0] = '';
  2742. $msg = $expCom [0] . ':' . $invoicePrintDetail ['expressNumber'] . '';
  2743. $url = 'https://m.kuaidi100.com/result.jsp?nu=' . $invoicePrintDetail ['expressNumber'];
  2744. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2745. return '/invoicePost';
  2746. }
  2747. function invoiceExpressUpdateDo() {
  2748. Doo::loadModel ( 'invoice' );
  2749. $invoice = new invoice ();
  2750. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  2751. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2752. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2753. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2754. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2755. $iid = $invoice->authcode ( $iid );
  2756. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2757. die ( 'illegal request' );
  2758. $item = array (
  2759. 'iid' => $iid,
  2760. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2761. 'expressCompany' => $expressCompany,
  2762. 'expressNumber' => $expressNumber,
  2763. 'actualItems' => $actualItems,
  2764. 'poster' => $this->staff [0] ['username']
  2765. );
  2766. $invoice->setInvoiceByCondition ( $item );
  2767. return $action;
  2768. }
  2769. /**
  2770. * 可退票管理
  2771. */
  2772. function invoiceUntreadIsAchieve() {
  2773. Doo::loadModel ( 'invoice' );
  2774. $invoice = new invoice ();
  2775. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2776. /*
  2777. * 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' => '' );
  2778. */
  2779. if (empty ( $MebSea )) {//
  2780. $con = ' and invoiceNo like "NULL" ';
  2781. } else {
  2782. $con = ' and (invoiceNo like "%' . $MebSea . '%" or invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  2783. }
  2784. // printStatus=1 and
  2785. $sql = " (untreadStatus=0 or untreadStatus=3) and status=2 and sid=" . $this->staff [0] ['sid'] . $con;
  2786. /*
  2787. * $action = "invoiceUntreadIsAchieve"; $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" ); $limit = $pageinfo ['lower'] . ',' . $page_size;
  2788. */
  2789. $limit = '0,20';
  2790. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2791. //print_r($list);
  2792. $this->data ['MebSeaEn'] = $MebSea;
  2793. /*
  2794. * $this->data ['get'] = $get; $this->data ['page'] = $pageinfo; $this->data ['date'] = $date;
  2795. */
  2796. $this->data ['list'] = $list;
  2797. $this->data ['memu'] = "invoice";
  2798. $this->data ['staff'] = $this->staff;
  2799. $this->data ['receiptMemu'] = 'invoice';
  2800. $this->render ( "/admin/invoiceUntreadIsAchieve", $this->data );
  2801. }
  2802. // 已经退票的发票
  2803. function invoiceUntreadED() {
  2804. Doo::loadModel ( 'invoice' );
  2805. $invoice = new invoice ();
  2806. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2807. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "";
  2808. Doo::loadClass ( 'XDeode' );
  2809. $XDeode = new XDeode ( 5 );
  2810. $page_size = 18;
  2811. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2812. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2813. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  2814. $dateArr = explode ( ':', $date );
  2815. $D1 = '';
  2816. $D2 = '';
  2817. if (! empty ( $date )) {
  2818. $D1 = $dateArr [0];
  2819. $D2 = $dateArr [1];
  2820. }
  2821. $con = '';
  2822. if (! empty ( $D1 ) && ! empty ( $D2 )) {
  2823. $con = ' and bindTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2824. }
  2825. // if ($date == 'MONTHO')
  2826. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  2827. // elseif ($date == 'MONTHT')
  2828. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  2829. // elseif ($date == 'MONTHY')
  2830. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  2831. if (! empty ( $MebSea )) {
  2832. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  2833. }
  2834. if ($invoiceType == 'ORDINARY') {
  2835. $con .= ' and invoiceType=0 ';
  2836. } elseif ($invoiceType == 'SPECIAL') {
  2837. $con .= ' and invoiceType=1 ';
  2838. }
  2839. $pageinfo ['page'] = array (
  2840. 'previous' => ''
  2841. );
  2842. // printStatus=1 and
  2843. $sql = " (untreadStatus=2 ) and status=2 and sid=" . $this->staff [0] ['sid'] . $con;
  2844. $action = "invoiceUntreadED";
  2845. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2846. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2847. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2848. // print_r($list);
  2849. $this->data ['MebSeaEn'] = $MebSea;
  2850. $this->data ['get'] = $get;
  2851. $this->data ['page'] = $pageinfo;
  2852. $this->data ['date'] = $date;
  2853. $this->data ['invoiceType'] = $invoiceType;
  2854. $this->data ['list'] = $list;
  2855. $this->data ['memu'] = "invoice";
  2856. $this->data ['staff'] = $this->staff;
  2857. $this->data ['receiptMemu'] = 'invoice';
  2858. $this->render ( "/admin/invoiceUntreadED", $this->data );
  2859. }
  2860. /**
  2861. * 退票处理页面
  2862. */
  2863. function invoiceUntread() {
  2864. Doo::loadModel ( 'invoice' );
  2865. $invoice = new invoice ();
  2866. $untreadInvoice = $invoice->getInvoiceByUntreadStatus ( 1, 0, 50 );
  2867. $establishedInvoice = $invoice->getInvoiceByUntreadStatus ( 2 );
  2868. foreach ( $establishedInvoice as $key => $value ) {
  2869. // months
  2870. $lossDate = strtotime ( "+1 month", strtotime ( $value ['OperationLog'] ['date'] ) );
  2871. $nowDate = strtotime ( 'now' );
  2872. $establishedInvoice [$key] ['lossShow'] = false;
  2873. if ($lossDate < $nowDate)
  2874. $establishedInvoice [$key] ['lossShow'] = true;
  2875. }
  2876. $this->data ['untreadInvoice'] = $untreadInvoice;
  2877. $this->data ['establishedInvoice'] = $establishedInvoice;
  2878. $this->data ['memu'] = "invoice";
  2879. $this->data ['staff'] = $this->staff;
  2880. $this->data ['receiptMemu'] = 'invoiceUntread';
  2881. $this->render ( "/admin/invoiceUntread", $this->data );
  2882. }
  2883. /**
  2884. * 确认收到退回的发票,开票状态为退回 //收款状态解绑,公司统计扣除入账额度
  2885. */
  2886. function invoiceUntreadEstablishedDo() {
  2887. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  2888. Doo::loadModel ( 'invoice' );
  2889. $invoice = new invoice ();
  2890. Doo::loadModel ( 'invoiceOperationLog' );
  2891. $invoiceOperationLog = new invoiceOperationLog ();
  2892. Doo::loadModel ( 'invoiceReceivables' );
  2893. Doo::loadModel ( 'invoiceStatistics' );
  2894. $iid = $invoice->authcode ( $untreadIidKey );
  2895. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2896. die ( 'illegal request' );
  2897. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  2898. if ($invoiceDetails ['untreadStatus'] != 1)
  2899. die ( 'illegal request untreadStatus error !=1' );
  2900. $item = array (
  2901. 'iid' => $iid,
  2902. // 'irid'=>'',
  2903. 'untreadStatus' => 2,
  2904. 'updateTime' => date ( "Y-m-d H:i:s" )
  2905. );
  2906. $invoice->setInvoiceByCondition ( $item );
  2907. $item = array (
  2908. 'date' => date ( "Y-m-d H:i:s" ),
  2909. 'operation' => '已确认退票',
  2910. 'status' => 6,
  2911. 'img' => $this->staff [0] ['avatar'],
  2912. 'username' => $this->staff [0] ['username'],
  2913. 'uid' => $this->staff [0] ['sid'],
  2914. 'category' => $this->staff [0] ['category'],
  2915. 'iid' => $iid
  2916. );
  2917. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2918. // 收款解绑以及入账扣除 收款扣除
  2919. if (! empty ( $invoiceDetails ['irid'] )) {
  2920. $iridList = explode ( ',', $invoiceDetails ['irid'] );
  2921. foreach ( $iridList as $value ) {
  2922. $invoiceReceivables = new invoiceReceivables ();
  2923. $irDetails = $invoiceReceivables->getOne ( array (
  2924. 'where' => " irid=" . $value . ' and bindStatus=1',
  2925. 'asArray' => TRUE
  2926. ) );
  2927. $item = array (
  2928. 'irid' => $value,
  2929. 'bindStatus' => 0,
  2930. 'untreadStatus' => 1,
  2931. 'untreadStaff' => $invoiceDetails ['userName'],
  2932. 'unbundlingTime' => date ( "Y-m-d H:i:s" ),
  2933. 'iid' => 0
  2934. );
  2935. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2936. if (! empty ( $irDetails )) {
  2937. // 扣除入账
  2938. $invoiceStatistics = new invoiceStatistics ();
  2939. $item = array (
  2940. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2941. 'priceClass' => 3,
  2942. 'cid' => $invoiceDetails ['cid'],
  2943. 'staff' => $invoiceDetails ['sid'],
  2944. 'accountPrice' => - $irDetails ['receivablesPrice']
  2945. );
  2946. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2947. // 扣除收款
  2948. $invoiceStatistics = new invoiceStatistics ();
  2949. $item = array (
  2950. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2951. 'priceClass' => 2,
  2952. 'cid' => $invoiceDetails ['cid'],
  2953. 'staff' => $invoiceDetails ['sid'],
  2954. 'irid' => $irDetails ['irid'],
  2955. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  2956. );
  2957. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2958. }
  2959. // 解绑时删除收入流水
  2960. Doo::loadModel ( 'wasteBook' );
  2961. $wasteBook = new wasteBook ();
  2962. $wasteBook->delete ( array (
  2963. 'where' => 'dataID=' . $value . ' and accountType=7',
  2964. 'limit' => 1
  2965. ) );
  2966. }
  2967. }
  2968. return "/invoiceUntread";
  2969. }
  2970. function invoiceUntreadRecallDo() {
  2971. $iidKey = isset ( $this->params ['iidKey'] ) ? $this->params ['iidKey'] : "";
  2972. Doo::loadModel ( 'invoice' );
  2973. $invoice = new invoice ();
  2974. Doo::loadClass ( 'XDeode' );
  2975. $XDeode = new XDeode ( 5 );
  2976. Doo::loadModel ( 'invoiceOperationLog' );
  2977. $invoiceOperationLog = new invoiceOperationLog ();
  2978. $iid = $XDeode->decode ( $iidKey );
  2979. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  2980. if (empty ( $invoiceDetail )) {
  2981. die ( 'illegal request-DATANULL' );
  2982. }
  2983. $item = array (
  2984. 'iid' => $iid,
  2985. 'untreadStatus' => 0
  2986. );
  2987. $invoice->setInvoiceByCondition ( $item );
  2988. $item = array (
  2989. 'date' => date ( "Y-m-d H:i:s" ),
  2990. 'operation' => '撤回申请退票',
  2991. 'status' => 13,
  2992. 'img' => $this->staff [0] ['avatar'],
  2993. 'username' => $this->staff [0] ['username'],
  2994. 'uid' => $this->staff [0] ['sid'],
  2995. 'category' => $this->staff [0] ['category'],
  2996. 'iid' => $iid
  2997. );
  2998. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2999. return "/invoiceUntread";
  3000. }
  3001. /**
  3002. * 建立负票,关联原来发票
  3003. */
  3004. function invoiceLossDo() {
  3005. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  3006. if (! empty ( $iidKey )) {
  3007. Doo::loadClass ( 'XDeode' );
  3008. $XDeode = new XDeode ( 5 );
  3009. Doo::loadModel ( 'invoice' );
  3010. $invoice = new invoice ();
  3011. Doo::loadModel ( 'invoiceOperationLog' );
  3012. $invoiceOperationLog = new invoiceOperationLog ();
  3013. $iidKey = $XDeode->decode ( $iidKey );
  3014. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  3015. // 拷贝插入一条发票数据
  3016. $iid = $invoice->setInvoiceLoss ( $iidKey );
  3017. // 更新负票
  3018. $invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  3019. $invoice = new invoice ();
  3020. $item = array (
  3021. 'iid' => $iid,
  3022. 'sid' => $this->staff [0] ['sid'],
  3023. 'userName' => $this->staff [0] ['username'],
  3024. 'cid' => $this->staff [0] ['cid'],
  3025. 'categoryName' => $this->staff [0] ['category'],
  3026. 'invoiceQuantity' => - $invoiceDetail ['invoiceQuantity'],
  3027. 'invoicePrice' => - $invoiceDetail ['invoicePrice'],
  3028. 'invoiceSerial' => $invoiceSerial,
  3029. 'invoiceNo' => '',
  3030. 'printStatus' => 0,
  3031. 'untreadStatus' => 4,
  3032. // 关联发票号
  3033. 'lossIid' => $invoiceDetail ['iid']
  3034. );
  3035. $invoice->setInvoiceByCondition ( $item );
  3036. // 更新原发票
  3037. $invoice = new invoice ();
  3038. $item = array (
  3039. 'iid' => $invoiceDetail ['iid'],
  3040. 'lossIid' => $iid
  3041. );
  3042. $invoice->setInvoiceByCondition ( $item );
  3043. // 操作日志
  3044. $item = array (
  3045. 'date' => date ( "Y-m-d H:i:s" ),
  3046. 'operation' => "创建负票" . $invoiceSerial,
  3047. 'status' => 12,
  3048. 'img' => $this->staff [0] ['avatar'],
  3049. 'username' => $this->staff [0] ['username'],
  3050. 'uid' => $this->staff [0] ['sid'],
  3051. 'category' => $this->staff [0] ['category'],
  3052. 'iid' => $iid
  3053. );
  3054. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3055. // print_r($invoiceDetail);
  3056. // echo $iid;die;
  3057. }
  3058. return '/invoiceUntread';
  3059. }
  3060. /**
  3061. * 上传银行到账 收款文件
  3062. */
  3063. function invoiceReceivablesBankUpload() {
  3064. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  3065. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  3066. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  3067. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  3068. header ( "HTTP/1.1 500 Internal Server Error" );
  3069. echo "POST exceeded maximum allowed size.";
  3070. exit ( 0 );
  3071. }
  3072. // Settings
  3073. $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)
  3074. $upload_name = "Filedata";
  3075. $file_name = "";
  3076. $nk = time ();
  3077. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  3078. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  3079. echo "文件无法保存.";
  3080. exit ( 0 );
  3081. }
  3082. echo json_encode ( array (
  3083. 'filename' => $file_name,
  3084. 'id' => $nk
  3085. ) );
  3086. exit ( 0 );
  3087. }
  3088. /**
  3089. * 解析银行到账收款execl并导入库中
  3090. */
  3091. function invoiceReceivablesImport() {
  3092. $path = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  3093. if ($path != "") {
  3094. Doo::loadModel ( 'invoiceReceivables' );
  3095. $invoiceReceivables = new invoiceReceivables ();
  3096. Doo::loadClass ( 'invoice.func' );
  3097. Doo::loadModel ( 'invoiceROLog' );
  3098. $invoiceROLog = new invoiceROLog ();
  3099. Doo::loadModel ( 'invoiceStatistics' );
  3100. $invoiceStatistics = new invoiceStatistics ();
  3101. $exlArray = formatExcelToArrayBank ( DOO::conf ()->SITE_PATH . "upload/invoiceReceivablesBank/" . $path );
  3102. $bankBatchNumber = 'BBN_' . time ();
  3103. Doo::db ()->beginTransaction ();
  3104. // 批量存储收款--由于必须获得收款ID,
  3105. $sql = 'INSERT INTO CLD_invoiceReceivables (OriginalPrice,receivablesPrice, receivablesMessage,receivablesSerial,receivablesBank,receivablesDate,inputStaff,date,receivablesCategory,receivablesStaff,bankBatchNumber,recepitTitleMark)
  3106. VALUES ';
  3107. $date = date ( "Y-m-d" );
  3108. $receivablesList = array ();
  3109. foreach ( $exlArray as $key => $value ) {
  3110. $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"] . '")';
  3111. array_push ( $receivablesList, $receivablesSql );
  3112. }
  3113. $sql = $sql . implode ( ',', $receivablesList );
  3114. // echo $sql;
  3115. Doo::db ()->query ( $sql );
  3116. // 批量存储收款统计
  3117. // 获得刚刚导入数据的irid组-缺少办事处和人员
  3118. $iridList = $invoiceReceivables->getInvoiceReceivablesByBBN ( $bankBatchNumber );
  3119. // 没有irid 回滚所有操作
  3120. if (empty ( $iridList )) {
  3121. Doo::db ()->rollBack ();
  3122. header ( 'Content-Type:text/html;charset=utf-8' );
  3123. die ( '文档或数据不正确,请重新<a href="/invoiceReceivables">上传</a>.' );
  3124. }
  3125. $sql = 'INSERT INTO CLD_invoiceStatistics (date, priceClass,irid,receivablesPrice)
  3126. VALUES ';
  3127. $statisticsList = array ();
  3128. foreach ( $iridList as $value ) {
  3129. $statisticsSql = '("' . $date . '",2,' . $value ['irid'] . ',' . $value ["receivablesPrice"] . ')';
  3130. array_push ( $statisticsList, $statisticsSql );
  3131. }
  3132. $sql = $sql . implode ( ',', $statisticsList );
  3133. Doo::db ()->query ( $sql );
  3134. // 批量存储操作日志
  3135. $sql = 'INSERT INTO CLD_invoiceROLog (operation, date,status,img, username,uid,category,irid)
  3136. VALUES ';
  3137. $ROLogList = array ();
  3138. foreach ( $iridList as $value ) {
  3139. $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'] . '")';
  3140. array_push ( $ROLogList, $ROLogSql );
  3141. }
  3142. $sql = $sql . implode ( ',', $ROLogList );
  3143. Doo::db ()->query ( $sql );
  3144. // 批量写入流水
  3145. $sql = 'INSERT INTO CLD_wasteBook (dataID, expensesType,accountType,accountPriceShow, accountPrice,accountBank,category,cid,name,sid,inputDate)
  3146. VALUES ';
  3147. $wasteBookList = array ();
  3148. foreach ( $iridList as $value ) {
  3149. $accountBank = '';
  3150. if ($value ['receivablesBank'] == '纵横广发') {
  3151. $accountBank = 'CGBDeposit';
  3152. } elseif ($value ['receivablesBank'] == '纵横工行') {
  3153. $accountBank = 'ICBCDeposit';
  3154. } elseif ($value ['receivablesBank'] == '华润银行') {
  3155. $accountBank = 'HUADeposit';
  3156. } elseif ($value ['receivablesBank'] == '个人广发') {
  3157. $accountBank = 'PersonalDeposit';
  3158. }
  3159. $wasteBookSql = '("' . $value ['irid'] . ' ",1,7,"' . $value ['receivablesPrice'] . '","' . $value ['receivablesPrice'] . '","' . $accountBank . '",
  3160. "' . $this->staff [0] ['category'] . '","' . $this->staff [0] ['cid'] . '","' . $this->staff [0] ['username'] . '","' . $this->staff [0] ['sid'] . '","' . date ( "Y-m-d H:i:s" ) . '")';
  3161. array_push ( $wasteBookList, $wasteBookSql );
  3162. }
  3163. $sql = $sql . implode ( ',', $wasteBookList );
  3164. Doo::db ()->query ( $sql );
  3165. Doo::db ()->commit ();
  3166. return "/invoiceReceivables";
  3167. }
  3168. echo 'no file';
  3169. }
  3170. function invoiceReceivables() {
  3171. $invoiceTC = $this->get_args ( 'invoiceTC' ) ? $this->get_args ( 'invoiceTC' ) : '';
  3172. Doo::loadModel ( 'L_category' );
  3173. $lCategory = new L_category ();
  3174. Doo::loadModel ( 'staff' );
  3175. $staff = new staff ();
  3176. Doo::loadModel ( 'invoiceReceivables' );
  3177. $invoiceReceivables = new invoiceReceivables ();
  3178. Doo::loadModel ( 'invoice' );
  3179. $invoice = new invoice ();
  3180. Doo::loadClass ( 'XDeode' );
  3181. $XDeode = new XDeode ( 5 );
  3182. $category = $lCategory->getCategory ();
  3183. $staffList = $staff->getStaffByCid ( $this->staff [0] ['cid'] );
  3184. $sql = 'bindStatus=1 and iid!=0';
  3185. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByNew ( 4, $sql );
  3186. // 获取未入账发票
  3187. $invoiceUnAccount = $invoice->getInvoiceByUnAccount ( $invoiceTC );
  3188. $invoiceExistAccount = $invoice->getInvoiceByUnAccount ( '', true );
  3189. foreach ( $invoiceUnAccount as $key => $value ) {
  3190. $invoiceUnAccount [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  3191. $lastApprover = json_decode ( $value ['processApprovals'], true );
  3192. if (! empty ( $lastApprover )) {
  3193. $lastApproverKey = array_keys ( $lastApprover );
  3194. $lastApprover = end ( $lastApprover );
  3195. $staffDetail = $staff->getOne ( array (
  3196. 'where' => 'sid=' . end ( $lastApproverKey ),
  3197. 'asArray' => true
  3198. ) );
  3199. $lastApprover ['username'] = $staffDetail ['username'];
  3200. }
  3201. $invoiceUnAccount [$key] ['lastApprover'] = $lastApprover;
  3202. }
  3203. foreach ( $invoiceExistAccount as $key => $value ) {
  3204. // $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  3205. // if (empty ( $irList ))
  3206. // $irList [0] ['sumPrice'] = 0;
  3207. //$balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  3208. $invoiceExistAccount [$key] ['existAccount'] = $value ['invoicePrice']-$value ['invoiceBalance'];
  3209. //$invoiceExistAccount [$key] ['balance'] = $balance;
  3210. }
  3211. $receivablesInput = $invoiceReceivables->getInvoiceReceivablesByInput ();
  3212. $halfList = $invoiceReceivables->getInvoiceReceivablesByHalf ();
  3213. $this->data ['halfList'] = $halfList;
  3214. $this->data ['halfCount'] = count ( $halfList );
  3215. // print_r($receivablesList);
  3216. $this->data ['receivablesDate'] = date ( "Y-m-d" );
  3217. $this->data ['ieaCount'] = count ( $invoiceExistAccount );
  3218. $this->data ['invoiceExistAccount'] = $invoiceExistAccount;
  3219. $this->data ['receivablesInput'] = $receivablesInput;
  3220. $this->data ['year'] = date ( 'Y' );
  3221. $this->data ['invoiceUnAccount'] = $invoiceUnAccount;
  3222. $this->data ['receivablesList'] = $receivablesList;
  3223. $this->data ['staffList'] = $staffList;
  3224. $this->data ['category'] = $category;
  3225. $this->data ['memu'] = "invoice";
  3226. $this->data ['staff'] = $this->staff;
  3227. $this->data ['receiptMemu'] = 'invoiceReceivables';
  3228. $this->render ( "/admin/invoiceReceivables", $this->data );
  3229. }
  3230. /**
  3231. * 设置收款认领地区
  3232. */
  3233. function setInvoiceReceivablesClaim() {
  3234. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  3235. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3236. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  3237. if (! empty ( $iridKey ) && ! empty ( $receivablesCategory )) {
  3238. Doo::loadModel ( 'invoiceReceivables' );
  3239. $invoiceReceivables = new invoiceReceivables ();
  3240. Doo::loadClass ( 'XDeode' );
  3241. $XDeode = new XDeode ( 5 );
  3242. Doo::loadModel ( 'invoiceROLog' );
  3243. $invoiceROLog = new invoiceROLog ();
  3244. $irid = $XDeode->decode ( $iridKey );
  3245. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  3246. if (empty ( $irDetail ))
  3247. die ( 'illegal request' );
  3248. $item = array (
  3249. 'irid' => $irid,
  3250. 'receivablesCategory' => $receivablesCategory
  3251. );
  3252. if ($receivablesCategory != 'PUBLIC') {
  3253. $item += array (
  3254. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3255. 'inputType' => 1
  3256. );
  3257. }
  3258. $invoiceReceivables = new invoiceReceivables ();
  3259. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3260. // 收款操作日志
  3261. $item = array (
  3262. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 ",
  3263. 'date' => date ( "Y-m-d" ),
  3264. 'status' => 1,
  3265. 'img' => $this->staff [0] ['avatar'],
  3266. 'username' => $this->staff [0] ['username'],
  3267. 'uid' => $this->staff [0] ['sid'],
  3268. 'category' => $this->staff [0] ['category'],
  3269. 'irid' => $irid
  3270. );
  3271. $invoiceROLog->setInvoiceROLog ( $item );
  3272. if (empty ( $action ))
  3273. return '/invoiceReceivables';
  3274. else
  3275. return "/invoiceReceivablesAS";
  3276. }
  3277. die ( 'illegal request' );
  3278. }
  3279. /**
  3280. * 新添加收款直接入账发票
  3281. */
  3282. function invoiceCompareClaimPrice() {
  3283. // 收款录入
  3284. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  3285. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3286. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3287. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3288. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3289. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $iidKey )) {
  3290. Doo::loadModel ( 'invoiceReceivables' );
  3291. $invoiceReceivables = new invoiceReceivables ();
  3292. Doo::loadModel ( 'invoiceROLog' );
  3293. $invoiceROLog = new invoiceROLog ();
  3294. Doo::loadModel ( 'invoiceStatistics' );
  3295. Doo::loadModel ( 'invoice' );
  3296. $invoice = new invoice ();
  3297. Doo::loadClass ( 'XDeode' );
  3298. $XDeode = new XDeode ( 5 );
  3299. Doo::loadModel ( 'invoiceOperationLog' );
  3300. $invoiceOperationLog = new invoiceOperationLog ();
  3301. $iidKey = $XDeode->decode ( $iidKey );
  3302. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  3303. if (! ($invoiceDetail ['status'] == 2 && $invoiceDetail ['printStatus'] == 1 && $invoiceDetail ['untreadStatus'] == 0))
  3304. die ( 'illegal request' );
  3305. $receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  3306. // 收款录入 并绑定发票
  3307. Doo::db ()->beginTransaction ();
  3308. //获得发票入账余额
  3309. //$bindInvicePrice=$invoiceReceivables->getSumOfReceivablesPrice ( $invoiceDetail['irid'] );
  3310. //$bindPrice=$invoiceDetail ['invoiceBalance']-$bindInvicePrice;
  3311. $bindStatus = 0;
  3312. $invoiceBalance=$invoiceDetail ['invoicePrice'];
  3313. if($invoiceDetail ['invoiceBalance']!=0){
  3314. $invoiceBalance=$invoiceDetail ['invoiceBalance'];
  3315. }
  3316. if ($receivablesPrice <= $invoiceBalance){
  3317. $bindStatus = 1;
  3318. //$bindPrice=$receivablesPrice;
  3319. }
  3320. $titleMark = $invoiceDetail ['invoiceTitle'];
  3321. if (! empty ( $invoiceDetail ['invoiceCompany'] ))
  3322. $titleMark = $invoiceDetail ['invoiceCompany'];
  3323. $item = array (
  3324. 'recepitTitleMark' => $titleMark,
  3325. 'bindStatus' => $bindStatus,
  3326. 'iid' => $invoiceDetail ['iid'],
  3327. 'bindPrice' => $receivablesPrice,
  3328. 'bindDate' => date ( "Y-m-d H:i:s" ),
  3329. 'receivablesPrice' => $receivablesPrice,
  3330. 'OriginalPrice' => $receivablesPrice,
  3331. 'receivablesMessage' => $receivablesMessage,
  3332. 'receivablesSerial' => $receivablesSerial,
  3333. 'receivablesBank' => $receivablesBank,
  3334. 'receivablesDate' => $receivablesDate,
  3335. 'inputStaff' => $this->staff [0] ['username'],
  3336. 'accountClerk' => $this->staff [0] ['username'],
  3337. 'date' => date ( "Y-m-d" ),
  3338. 'receivablesCategory' => $invoiceDetail ['cid'] . ':' . $invoiceDetail ['categoryName'],
  3339. 'receivablesStaff' => $invoiceDetail ['sid'] . '-' . $invoiceDetail ['userName'],
  3340. 'confirmTime' => date ( "Y-m-d H:i:s" )
  3341. );
  3342. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  3343. $item = array ();
  3344. // 收款操作日志
  3345. $item = array (
  3346. 'operation' => $this->staff [0] ['username'] . " 转入 " . $invoiceDetail ['userName']
  3347. );
  3348. $item += array (
  3349. 'date' => date ( "Y-m-d" ),
  3350. 'status' => 1,
  3351. 'img' => $this->staff [0] ['avatar'],
  3352. 'username' => $this->staff [0] ['username'],
  3353. 'uid' => $this->staff [0] ['sid'],
  3354. 'category' => $this->staff [0] ['category'],
  3355. 'irid' => $irid
  3356. );
  3357. $invoiceROLog->setInvoiceROLog ( $item );
  3358. // 收款统计
  3359. $invoiceStatistics = new invoiceStatistics ();
  3360. $item = array (
  3361. 'date' => $receivablesDate,
  3362. 'priceClass' => 2,
  3363. 'irid' => $irid,
  3364. 'cid' => $invoiceDetail ['cid'],
  3365. 'staff' => $invoiceDetail ['sid'],
  3366. 'receivablesPrice' => $receivablesPrice
  3367. );
  3368. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3369. // 收款 入 发票
  3370. $detail = $invoiceDetail;
  3371. $iridString = "";
  3372. if (empty ( $detail ['irid'] ))
  3373. $iridString = $irid;
  3374. else
  3375. $iridString = $detail ['irid'] . ',' . $irid;
  3376. $item = array (
  3377. 'irid' => $iridString,
  3378. 'bindTime' => date ( "Y-m-d H:i:s" ),
  3379. 'updateTime' => date ( "Y-m-d H:i:s" ),
  3380. 'iid' => $detail ['iid']
  3381. );
  3382. // $invoiceReceivables = new invoiceReceivables ();
  3383. // $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  3384. // $sumBind = $bindInvicePrice;
  3385. // $sumBalance=$invoiceReceivables->balanceOfReceivablesPrice($irid);
  3386. // $sum=$sumBind+$sumBalance;
  3387. // ;
  3388. if ($receivablesPrice>=$invoiceBalance){
  3389. $item += array (
  3390. 'invoiceBalance'=>0,
  3391. 'untreadStatus' => 3
  3392. );
  3393. }else{
  3394. $item += array (
  3395. 'invoiceBalance'=>$invoiceBalance-$receivablesPrice
  3396. );
  3397. }
  3398. $invoice->setInvoiceByCondition ( $item );
  3399. // 操作日志
  3400. $item = array (
  3401. 'date' => date ( "Y-m-d H:i:s" ),
  3402. 'operation' => "收款入账" . $receivablesSerial . "到发票" . $detail ['invoiceSerial'],
  3403. 'status' => 8,
  3404. 'img' => $this->staff [0] ['avatar'],
  3405. 'username' => $this->staff [0] ['username'],
  3406. 'uid' => $this->staff [0] ['sid'],
  3407. 'category' => $this->staff [0] ['category'],
  3408. 'iid' => $detail ['iid']
  3409. );
  3410. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3411. // 入账汇总
  3412. $invoiceStatistics = new invoiceStatistics ();
  3413. // $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $iridString );
  3414. // $accountPrice = 0;
  3415. // foreach ( $list as $key => $value ) {
  3416. // $accountPrice += $value ['receivablesPrice'];
  3417. // }
  3418. $item = array (
  3419. 'date' => $receivablesDate,
  3420. 'priceClass' => 3,
  3421. 'cid' => $invoiceDetail ['cid'],
  3422. 'staff' => $invoiceDetail ['sid'],
  3423. 'accountPrice' => $receivablesPrice
  3424. );
  3425. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3426. // 公司流水记录
  3427. Doo::loadModel ( 'wasteBook' );
  3428. $wasteBook = new wasteBook ();
  3429. $abDetail = $wasteBook->getAccountBookByAid ( 2, 7, $irid );
  3430. $accountBank = '';
  3431. if ($receivablesBank == '纵横广发') {
  3432. $accountBank = 'CGBDeposit';
  3433. } elseif ($receivablesBank == '纵横工行') {
  3434. $accountBank = 'ICBCDeposit';
  3435. } elseif ($receivablesBank == '华润银行') {
  3436. $accountBank = 'HUADeposit';
  3437. } elseif ($receivablesBank == '个人广发') {
  3438. $accountBank = 'PersonalDeposit';
  3439. }
  3440. if (empty ( $abDetail )) {
  3441. $item = array (
  3442. 'dataID' => $irid,
  3443. 'expensesType' => 1,
  3444. 'accountType' => 7,
  3445. 'accountPrice' => $receivablesPrice,
  3446. 'accountPriceShow' => $receivablesPrice,
  3447. 'accountBank' => $accountBank,
  3448. 'category' => $this->staff [0] ['category'],
  3449. 'cid' => $this->staff [0] ['cid'],
  3450. 'name' => $this->staff [0] ['username'],
  3451. 'sid' => $this->staff [0] ['sid'],
  3452. 'inputDate' => date ( "Y-m-d H:i:s" )
  3453. );
  3454. $wasteBook->setAccountBookStatistics ( $item );
  3455. }
  3456. Doo::db ()->commit ();
  3457. }
  3458. return '/invoiceReceivables';
  3459. }
  3460. /**
  3461. * 录入收款数据
  3462. * @return string
  3463. */
  3464. function invoiceReceivablesDo() {
  3465. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3466. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3467. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3468. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3469. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3470. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  3471. Doo::loadModel ( 'invoiceReceivables' );
  3472. $invoiceReceivables = new invoiceReceivables ();
  3473. Doo::loadModel ( 'invoiceROLog' );
  3474. $invoiceROLog = new invoiceROLog ();
  3475. Doo::loadModel ( 'invoiceStatistics' );
  3476. $invoiceStatistics = new invoiceStatistics ();
  3477. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $receivablesCategory ) && ! empty ( $receivablesStaff )) {
  3478. $item = array (
  3479. 'receivablesPrice' => $receivablesPrice,
  3480. 'OriginalPrice' => $receivablesPrice,
  3481. 'receivablesMessage' => $receivablesMessage,
  3482. 'receivablesSerial' => "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  3483. 'receivablesBank' => $receivablesBank,
  3484. 'receivablesDate' => $receivablesDate,
  3485. 'inputStaff' => $this->staff [0] ['username'],
  3486. 'date' => date ( "Y-m-d" ),
  3487. 'receivablesCategory' => $receivablesCategory,
  3488. 'receivablesStaff' => $receivablesStaff
  3489. );
  3490. if ($receivablesCategory != 'PUBLIC') {
  3491. $item += array (
  3492. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3493. 'inputType' => 1
  3494. );
  3495. }
  3496. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  3497. $item = array ();
  3498. // 收款操作日志
  3499. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3500. $item = array (
  3501. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  3502. );
  3503. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3504. $item = array (
  3505. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  3506. );
  3507. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3508. $receivablesStaff = explode ( '-', $receivablesStaff );
  3509. $item = array (
  3510. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  3511. );
  3512. }
  3513. $item += array (
  3514. 'date' => date ( "Y-m-d" ),
  3515. 'status' => 1,
  3516. 'img' => $this->staff [0] ['avatar'],
  3517. 'username' => $this->staff [0] ['username'],
  3518. 'uid' => $this->staff [0] ['sid'],
  3519. 'category' => $this->staff [0] ['category'],
  3520. 'irid' => $irid
  3521. );
  3522. $invoiceROLog->setInvoiceROLog ( $item );
  3523. $item = array (
  3524. 'date' => $receivablesDate,
  3525. 'priceClass' => 2,
  3526. 'irid' => $irid,
  3527. 'receivablesPrice' => $receivablesPrice
  3528. );
  3529. if ($receivablesCategory != 'PUBLIC') {
  3530. $receivablesCategory = explode ( ":", $receivablesCategory );
  3531. $item += array (
  3532. 'cid' => $receivablesCategory [0]
  3533. );
  3534. }
  3535. if ($receivablesStaff2 != 'PUBLIC') {
  3536. $receivablesStaff = explode ( "-", $receivablesStaff2 );
  3537. $item += array (
  3538. 'staff' => $receivablesStaff [0]
  3539. );
  3540. }
  3541. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3542. $toparty = $this->getWxidByCategory ( $receivablesCategory [1] );
  3543. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  3544. $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  3545. if ($toparty != 0)
  3546. $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  3547. // 公司流水记录
  3548. Doo::loadModel ( 'wasteBook' );
  3549. $wasteBook = new wasteBook ();
  3550. $abDetail = $wasteBook->getAccountBookByAid ( 1, 7, $irid );
  3551. $accountBank = '';
  3552. if ($receivablesBank == '纵横广发') {
  3553. $accountBank = 'CGBDeposit';
  3554. } elseif ($receivablesBank == '纵横工行') {
  3555. $accountBank = 'ICBCDeposit';
  3556. } elseif ($receivablesBank == '华润银行') {
  3557. $accountBank = 'HUADeposit';
  3558. } elseif ($receivablesBank == '个人广发') {
  3559. $accountBank = 'PersonalDeposit';
  3560. }
  3561. $item = array (
  3562. 'dataID' => $irid,
  3563. 'expensesType' => 1,
  3564. 'accountType' => 7,
  3565. 'accountPriceShow' => $receivablesPrice,
  3566. 'accountPrice' => $receivablesPrice,
  3567. 'accountBank' => $accountBank,
  3568. 'category' => $this->staff [0] ['category'],
  3569. 'cid' => $this->staff [0] ['cid'],
  3570. 'name' => $this->staff [0] ['username'],
  3571. 'sid' => $this->staff [0] ['sid'],
  3572. 'inputDate' => date ( "Y-m-d H:i:s" )
  3573. );
  3574. $wasteBook->setAccountBookStatistics ( $item );
  3575. }
  3576. return "/invoiceReceivables";
  3577. }
  3578. /**
  3579. * 收款认领页面-包括公共认领 办事处认领 最近已认领数据
  3580. */
  3581. function invoiceReceivablesClaim() {
  3582. Doo::loadModel ( 'invoiceReceivables' );
  3583. $invoiceReceivables = new invoiceReceivables ();
  3584. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  3585. $this->data ['receivablesList'] = $receivablesList;
  3586. $this->data ['memu'] = "invoice";
  3587. $this->data ['staff'] = $this->staff;
  3588. $this->data ['receiptMemu'] = 'invoiceReceivablesClaim';
  3589. $this->render ( "/admin/invoiceReceivablesClaim", $this->data );
  3590. }
  3591. function invoiceReceivablesTitleMarkSet() {
  3592. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  3593. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  3594. if (empty ( $iridKey ) || empty ( $recepitTitleMark ))
  3595. die ( 'illegal request' );
  3596. Doo::loadModel ( 'invoiceReceivables' );
  3597. $invoiceReceivables = new invoiceReceivables ();
  3598. Doo::loadClass ( 'XDeode' );
  3599. $XDeode = new XDeode ( 5 );
  3600. $irid = $XDeode->decode ( $iridKey );
  3601. if (! is_numeric ( $irid ))
  3602. die ( 'illegal request' );
  3603. $invoiceReceivables->recepitTitleMark = $recepitTitleMark;
  3604. $invoiceReceivables->update ( array (
  3605. 'where' => 'irid = ' . $irid
  3606. ) );
  3607. return '/invoiceReceivablesClaim';
  3608. }
  3609. /**
  3610. * 更新收款相关数据
  3611. */
  3612. function invoiceReceivablesUpdateClaim() {
  3613. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3614. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3615. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3616. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3617. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3618. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  3619. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  3620. if (empty ( $claimKey ))
  3621. die ( 'illegal request' );
  3622. Doo::loadModel ( 'invoiceReceivables' );
  3623. $invoiceReceivables = new invoiceReceivables ();
  3624. Doo::loadModel ( 'invoiceROLog' );
  3625. $invoiceROLog = new invoiceROLog ();
  3626. $con = ' and iid=0 and bindStatus=0'; // and receivablesCategory!="PUBLIC" and receivablesStaff!="PUBLIC"
  3627. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  3628. if (empty ( $detail ))
  3629. die ( 'illegal request' );
  3630. $invoiceReceivables = new invoiceReceivables ();
  3631. $item = array (
  3632. 'irid' => $detail ['irid']
  3633. );
  3634. if ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3635. $item += array (
  3636. 'confirmTime' => date ( "Y-m-d H:i:s" )
  3637. );
  3638. }
  3639. if (! empty ( $receivablesCategory ))
  3640. $item += array (
  3641. 'receivablesCategory' => $receivablesCategory
  3642. );
  3643. if (! empty ( $receivablesStaff ))
  3644. $item += array (
  3645. 'receivablesStaff' => $receivablesStaff
  3646. );
  3647. if (! empty ( $receivablesPrice ))
  3648. $item += array (
  3649. 'receivablesPrice' => $receivablesPrice
  3650. );
  3651. if (! empty ( $receivablesMessage ))
  3652. $item += array (
  3653. 'receivablesMessage' => $receivablesMessage
  3654. );
  3655. if (! empty ( $receivablesBank ))
  3656. $item += array (
  3657. 'receivablesBank' => $receivablesBank
  3658. );
  3659. if (! empty ( $receivablesDate ))
  3660. $item += array (
  3661. 'receivablesDate' => $receivablesDate
  3662. );
  3663. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3664. // 收款操作日志
  3665. $item = array ();
  3666. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3667. $item = array (
  3668. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  3669. );
  3670. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3671. $item = array (
  3672. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  3673. );
  3674. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3675. $receivablesStaff = explode ( '-', $receivablesStaff );
  3676. $item = array (
  3677. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  3678. );
  3679. }
  3680. $item += array (
  3681. 'date' => date ( "Y-m-d" ),
  3682. 'status' => 1,
  3683. 'img' => $this->staff [0] ['avatar'],
  3684. 'username' => $this->staff [0] ['username'],
  3685. 'uid' => $this->staff [0] ['sid'],
  3686. 'category' => $this->staff [0] ['category'],
  3687. 'irid' => $detail ['irid']
  3688. );
  3689. $invoiceROLog->setInvoiceROLog ( $item );
  3690. return '/invoiceReceivablesAS';
  3691. }
  3692. function invoiceReceivablesDelete() {
  3693. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  3694. $skll = $this->get_args ( 'skll' ) ? $this->get_args ( 'skll' ) : "";
  3695. if ($skll != '删除到款')
  3696. die ( 'illegal request' );
  3697. if (empty ( $claimKey ))
  3698. die ( 'illegal request' );
  3699. Doo::loadModel ( 'invoiceReceivables' );
  3700. $invoiceReceivables = new invoiceReceivables ();
  3701. $con = ' and bindStatus=0 ';
  3702. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  3703. if (empty ( $detail ))
  3704. die ( 'illegal request' );
  3705. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  3706. // 扣除收款汇总信息 汇总
  3707. Doo::loadModel ( 'invoiceStatistics' );
  3708. $invoiceStatistics = new invoiceStatistics ();
  3709. $item = array (
  3710. 'date' => $detail ['receivablesDate'],
  3711. 'priceClass' => 2,
  3712. 'irid' => $detail ['irid'],
  3713. 'receivablesPrice' => - $detail ['receivablesPrice']
  3714. );
  3715. if ($detail ['receivablesCategory'] != 'PUBLIC') {
  3716. $receivablesCategory = explode ( ":", $detail ['receivablesCategory'] );
  3717. $item += array (
  3718. 'cid' => $receivablesCategory [0]
  3719. );
  3720. }
  3721. if ($detail ['receivablesStaff'] != 'PUBLIC') {
  3722. $receivablesStaff = explode ( "-", $detail ['receivablesStaff'] );
  3723. $item += array (
  3724. 'staff' => $receivablesStaff [0]
  3725. );
  3726. }
  3727. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3728. // 公司流水-删除时删除流水
  3729. Doo::loadModel ( 'wasteBook' );
  3730. $wasteBook = new wasteBook ();
  3731. $wasteBook->delete ( array (
  3732. 'where' => 'dataID=' . $detail ['irid'] . ' and accountType=7',
  3733. 'limit' => 1
  3734. ) );
  3735. return '/invoiceReceivablesAS';
  3736. }
  3737. /**
  3738. * 管理员录入的收款 ,确认认领到谁的名下.统计收款金额
  3739. */
  3740. function invoiceReceivablesAscription() {
  3741. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  3742. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  3743. Doo::loadModel ( 'invoiceReceivables' );
  3744. $invoiceReceivables = new invoiceReceivables ();
  3745. Doo::loadModel ( 'invoiceROLog' );
  3746. $invoiceROLog = new invoiceROLog ();
  3747. Doo::loadModel ( 'invoiceStatistics' );
  3748. $invoiceStatistics = new invoiceStatistics ();
  3749. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  3750. $irid = $invoiceReceivables->authcode ( $irid );
  3751. if (! empty ( $detail ) && $detail ['receivablesStaff'] == 'PUBLIC' && ! empty ( $recepitTitleMark )) {
  3752. $item = array (
  3753. 'irid' => $detail ['irid'],
  3754. 'receivablesCategory' => $this->staff [0] ['cid'] . ":" . $this->staff [0] ['category'],
  3755. 'receivablesStaff' => $this->staff [0] ['sid'] . "-" . $this->staff [0] ['username'],
  3756. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3757. 'recepitTitleMark' => $recepitTitleMark,
  3758. 'source' => 1
  3759. );
  3760. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3761. $item = array (
  3762. 'date' => date ( "Y-m-d" ),
  3763. 'operation' => $this->staff [0] ['username'] . " 认领 ",
  3764. 'status' => 2,
  3765. 'img' => $this->staff [0] ['avatar'],
  3766. 'username' => $this->staff [0] ['username'],
  3767. 'uid' => $this->staff [0] ['sid'],
  3768. 'category' => $this->staff [0] ['category'],
  3769. 'irid' => $irid
  3770. );
  3771. $invoiceROLog->setInvoiceROLog ( $item );
  3772. $item = array (
  3773. 'cid' => $this->staff [0] ['cid'],
  3774. 'staff' => $this->staff [0] ['sid']
  3775. );
  3776. $invoiceStatistics->updateInvoiceStatisticsByIrid ( $item, $detail ['irid'], 2 );
  3777. }
  3778. return "/invoiceReceivablesClaim";
  3779. }
  3780. /**
  3781. */
  3782. function invoiceMyReceivables() {
  3783. Doo::loadModel ( 'invoiceReceivables' );
  3784. $invoiceReceivables = new invoiceReceivables ();
  3785. Doo::loadModel ( 'invoiceStatistics' );
  3786. $invoiceStatistics = new invoiceStatistics ();
  3787. $isMonth = $invoiceStatistics->getStatisticsByMonth ( $this->staff [0] ['sid'] );
  3788. $year = date ( "Y" );
  3789. $tmp_date = date ( "Ym" );
  3790. $tmp_year = substr ( $tmp_date, 0, 4 );
  3791. $tmp_mon = substr ( $tmp_date, 4, 2 );
  3792. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  3793. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  3794. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . ".htm";
  3795. $htm = $this->showCache ( $path );
  3796. $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  3797. $this->data ['isMonth'] = $isMonth;
  3798. $this->data ['htm'] = $htm;
  3799. $this->data ['list'] = $list;
  3800. $this->data ['memu'] = "invoice";
  3801. $this->data ['staff'] = $this->staff;
  3802. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  3803. $this->render ( "/admin/invoiceMyReceivables", $this->data );
  3804. }
  3805. /**
  3806. * 纸票管理
  3807. */
  3808. function invoicePaper() {
  3809. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3810. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3811. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3812. $this->data ['dateString'] = $date;
  3813. $this->data ['status'] = $status;
  3814. $this->data ['invoiceType'] = $invoiceType;
  3815. $this->data ['memu'] = "invoice";
  3816. $this->data ['staff'] = $this->staff;
  3817. $this->data ['receiptMemu'] = 'invoicePaper';
  3818. $this->render ( "/admin/invoicePaper", $this->data );
  3819. }
  3820. /**
  3821. * 电子发票管理
  3822. */
  3823. function invoiceElectronic() {
  3824. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3825. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3826. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3827. $this->data ['dateString'] = $date;
  3828. $this->data ['status'] = $status;
  3829. $this->data ['invoiceType'] = $invoiceType;
  3830. $this->data ['memu'] = "invoice";
  3831. $this->data ['staff'] = $this->staff;
  3832. $this->data ['receiptMemu'] = 'invoicePaper';
  3833. $this->render ( "/invoice/invoiceElectronic", $this->data );
  3834. }
  3835. /**
  3836. * 获得纸票分页数据
  3837. */
  3838. function ajaxGetinvoicePaperAchieve() {
  3839. //include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  3840. Doo::loadModel ( 'invoicePaper' );
  3841. $invoicePaper = new invoicePaper ();
  3842. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3843. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3844. $invoiceForm = $this->get_args ( 'invoiceForm' )&&is_numeric($this->get_args ( 'invoiceForm' )) ? $this->get_args ( 'invoiceForm' ) : "0";
  3845. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ORDINARY";
  3846. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3847. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  3848. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  3849. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  3850. $MebSea = $this->get_args ( 'search' );
  3851. $MebSea = $MebSea ['value'];
  3852. $page_size = $length;
  3853. $con = '';
  3854. if ($status == 'ALL')
  3855. $con = ' where 1 ';
  3856. elseif ($status == 'PRINTED')
  3857. $con = ' where a.iid!=0 '; // $con = ' where b.isDelete=0 and a.iid!=0 and b.status=2 and b.untreadStatus=0 ';
  3858. elseif ($status == 'UNPRINT')
  3859. $con = ' where a.iid=0 '; // $con = ' where b.isDelete=0 and a.iid=0 and b.status=2 and b.untreadStatus=0 ';
  3860. elseif ($status == 'TICKET')
  3861. $con = ' where b.isDelete=0 and b.untreadStatus=2';
  3862. if ($invoiceType == 'ORDINARY')
  3863. $con .= ' and a.invoiceType=0 ';
  3864. elseif ($invoiceType == 'SPECIAL')
  3865. $con .= ' and a.invoiceType=1 ';
  3866. if($invoiceForm==0){
  3867. $con .= ' and a.invoiceForm=0 ';
  3868. }else{
  3869. $con .= ' and a.invoiceForm=1 ';
  3870. }
  3871. $dateArr = explode ( ':', $date );
  3872. $D1 = $dateString = '';
  3873. $D2 = '';
  3874. if (! empty ( $date )) {
  3875. $D1 = $dateArr [0];
  3876. if (isset ( $dateArr [1] ))
  3877. $D2 = $dateArr [1];
  3878. else
  3879. $D2 = '';
  3880. $dateString = $D1 . " : " . $D2;
  3881. }
  3882. if (! empty ( $D1 ) && ! empty ( $D2 ))
  3883. $con .= ' and b.printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  3884. elseif (! empty ( $D1 ) && empty ( $D2 ))
  3885. $con .= ' and b.printTime like "%' . $D1 . '%" ';
  3886. if (! empty ( $MebSea ))
  3887. $con .= ' and ( b.invoiceTitle like "%' . $MebSea . '%" or b.invoiceCompany like "%' . $MebSea . '%" or a.invoiceNo like "%' . $MebSea . '%" )';
  3888. $invoiceTotal = $invoicePaper->getInvoicePaperCount ($invoiceForm);
  3889. $sql = ' ' . $con;
  3890. $limit = $page . ',' . $page_size;
  3891. $list = $invoicePaper->getInvoicePaper ( $limit, $sql, 'desc' );
  3892. $paperList = array ();
  3893. foreach ( $list as $key => $value ) {
  3894. $irDetail = array ();
  3895. if ($value ['iid'] == 0)
  3896. array_push ( $irDetail, '<a href="javascript:if(window.confirm(\'确认删除?\'))window.location=\'/invoicePaperDel/' . $value ['ipidKey'] . '\'" >删除</a>' );
  3897. else
  3898. array_push ( $irDetail, '' );
  3899. array_push ( $irDetail, $value ['invoiceCode'] );
  3900. array_push ( $irDetail, $value ['invoiceNo'] );
  3901. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKey'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  3902. if ($value ['invoiceType'] == 1)
  3903. array_push ( $irDetail, $value ['invoiceCompany'] );
  3904. else
  3905. array_push ( $irDetail, $value ['invoiceTitle'] );
  3906. if ($value ['invoiceType'] == 1)
  3907. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  3908. else
  3909. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  3910. array_push ( $irDetail, $value ['invoiceElement'] );
  3911. array_push ( $irDetail, $value ['categoryName'] . '-' . $value ['userName'] );
  3912. array_push ( $irDetail, $value ['printTime'] );
  3913. array_push ( $paperList, $irDetail );
  3914. }
  3915. // $approvalListJson = json_encode ( $approvalList );
  3916. $recordsFiltered = $invoiceTotal;
  3917. echo json_encode ( array (
  3918. "draw" => intval ( $draw ),
  3919. "recordsTotal" => intval ( $invoiceTotal ),
  3920. "recordsFiltered" => intval ( $recordsFiltered ),
  3921. "data" => $paperList
  3922. ), JSON_UNESCAPED_UNICODE );
  3923. }
  3924. function invoicePaperDel() {
  3925. $ipidKey = isset ( $this->params ['ipidKey'] ) ? $this->params ['ipidKey'] : "";
  3926. $XDeode = new XDeode ( 5 );
  3927. $ipid = $XDeode->decode ( $ipidKey );
  3928. if (empty ( $ipid ))
  3929. die ( 'illegal request' );
  3930. Doo::loadModel ( 'invoicePaper' );
  3931. $invoicePaper = new invoicePaper ();
  3932. $ipdetail=$invoicePaper->getInvoicePaperByIpid($ipid);
  3933. $invoicePaper->delete ( array (
  3934. 'where' => 'ipid=' . $ipid . ' and iid=0',
  3935. 'limit' => 1
  3936. ) );
  3937. if($ipdetail['invoiceForm']==1){
  3938. return '/invoiceElectronic';
  3939. }else{
  3940. return '/invoicePaper';
  3941. }
  3942. }
  3943. /**
  3944. * 添加纸质发票号
  3945. */
  3946. function invoicePaperAdd() {
  3947. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : '0';
  3948. $invoiceCode = $this->get_args ( 'invoiceCode' ) ? $this->get_args ( 'invoiceCode' ) : "";
  3949. $invoiceNoStart = $this->get_args ( 'invoiceNoStart' ) && is_numeric ( $this->get_args ( 'invoiceNoStart' ) ) ? $this->get_args ( 'invoiceNoStart' ) : 0;
  3950. $invoiceNoTotal = $this->get_args ( 'invoiceNoTotal' ) && is_numeric ( $this->get_args ( 'invoiceNoTotal' ) ) ? $this->get_args ( 'invoiceNoTotal' ) : 0;
  3951. $invoiceForm = $this->get_args ( 'invoiceForm' ) && is_numeric ( $this->get_args ( 'invoiceForm' ) ) ? $this->get_args ( 'invoiceForm' ) : 0;
  3952. if ($invoiceType != '' && ! empty ( $invoiceCode ) && ! empty ( $invoiceNoStart ) && ! empty ( $invoiceNoTotal )) {
  3953. $sum = $invoiceNoStart + $invoiceNoTotal;
  3954. if (empty ( $sum ))
  3955. die ( 'illegal request' );
  3956. // echo $invoiceNoStart;
  3957. // echo $sum;
  3958. // echo strlen((int)$invoiceNoStart);
  3959. $sumLenght = strlen ( $invoiceNoStart ) - strlen ( ( int ) $invoiceNoStart );
  3960. if($invoiceType==0||$invoiceType==1){
  3961. }else{
  3962. die ( 'illegal request invoiceType' );
  3963. }
  3964. if($invoiceForm==1){
  3965. $invoiceType=0;
  3966. }
  3967. Doo::db ()->beginTransaction ();
  3968. // 批量存储纸质发票
  3969. $date = date ( "Y-m-d H:i:s" );
  3970. $sql = 'INSERT INTO CLD_invoicePaper (invoiceType, invoiceCode,invoiceNo,date,invoiceForm)
  3971. VALUES ';
  3972. $paperList = array ();
  3973. for($invoiceNoStart; $invoiceNoStart <= $sum - 1; $invoiceNoStart ++) {
  3974. // 数字前面自加0
  3975. $INLENGHT = strlen ( ( int ) $invoiceNoStart ) + $sumLenght;
  3976. $var = sprintf ( "%0" . $INLENGHT . "d", $invoiceNoStart );
  3977. $paperSql = '(' . $invoiceType . ',"' . $invoiceCode . '","' . $var . '","' . $date . '","'.$invoiceForm.'")';
  3978. array_push ( $paperList, $paperSql );
  3979. }
  3980. if (empty ( $paperList ))
  3981. die ( 'illegal request' );
  3982. $sql = $sql . implode ( ',', $paperList );
  3983. Doo::db ()->query ( $sql );
  3984. Doo::db ()->commit ();
  3985. if($invoiceForm==1){
  3986. return 'invoiceElectronic';
  3987. }else{
  3988. return 'invoicePaper';
  3989. }
  3990. }
  3991. die ( 'illegal request' );
  3992. }
  3993. /**
  3994. * 收款绑定发票 ,//一个收款只能绑定一个发票
  3995. */
  3996. function invoiceBindReceivables() {
  3997. $claimKey = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  3998. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  3999. Doo::loadModel ( 'invoice' );
  4000. $invoice = new invoice ();
  4001. Doo::loadModel ( 'invoiceReceivables' );
  4002. $invoiceReceivables = new invoiceReceivables ();
  4003. Doo::loadModel ( 'invoiceOperationLog' );
  4004. $invoiceOperationLog = new invoiceOperationLog ();
  4005. if (empty ( $invoiceKey ) || empty ( $claimKey ))
  4006. die ( 'illegal request' );
  4007. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  4008. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey );
  4009. if (empty ( $detail ) && empty ( $detailM ))
  4010. die ( 'illegal request' );
  4011. if ($detail ['untreadStatus'] == 3)
  4012. die ( 'illegal request' );
  4013. // 修改 绑定状态改为 金额
  4014. $invoiceReceivables = new invoiceReceivables ();
  4015. //有BUG-需修改
  4016. $invoicePrice = $detail ['invoicePrice'] + $detailM ['bindPrice'];
  4017. if ($detailM ['receivablesPrice'] > $invoicePrice) {
  4018. $item = array (
  4019. 'bindPrice' => $invoicePrice
  4020. );
  4021. } elseif ($detailM ['receivablesPrice'] <= $invoicePrice) {//发票金额大于收款金额,绑定金额为收款金额
  4022. $item = array (
  4023. 'bindPrice' => $detailM ['receivablesPrice'],
  4024. 'bindStatus' => 1,
  4025. 'bindDate' => date ( "Y-m-d H:i:s" )
  4026. );
  4027. } else {
  4028. die ( 'illegal request' );
  4029. }
  4030. if ($detailM ['iid'] == 0) {
  4031. $item += array (
  4032. 'iid' => $detail ['iid']
  4033. );
  4034. } else {
  4035. $iidExtend = explode ( ',', $detailM ['iidExtend'] );
  4036. array_push ( $iidExtend, $detail ['iid'] );
  4037. $item += array (
  4038. 'iidExtend' => implode ( ',', $iidExtend )
  4039. );
  4040. }
  4041. $titleMark = $detail ['invoiceTitle'];
  4042. if (! empty ( $detail ['invoiceCompany'] ))
  4043. $titleMark = $detail ['invoiceCompany'];
  4044. $item += array (
  4045. 'irid' => $detailM ['irid'],
  4046. 'recepitTitleMark' => $titleMark,
  4047. 'accountClerk' => $this->staff [0] ['username']
  4048. );
  4049. // 如何没有人收款 则自动绑定收款
  4050. if ($detailM ['receivablesCategory'] == 'PUBLIC' || $detailM ['receivablesStaff'] == 'PUBLIC') {
  4051. $item += array (
  4052. 'receivablesCategory' => $detail ['cid'] . ':' . $detail ['categoryName'],
  4053. 'receivablesStaff' => $detail ['sid'] . '-' . $detail ['userName']
  4054. );
  4055. }
  4056. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4057. $iridString = "";
  4058. if (empty ( $detail ['irid'] ))
  4059. $iridString = $detailM ['irid'];
  4060. else
  4061. $iridString = $detail ['irid'] . ',' . $detailM ['irid'];
  4062. // $invoiceReceivables = new invoiceReceivables ();
  4063. // $sumBind = $invoiceReceivables->getSumOfReceivablesPrice ( $detail ['irid'] );
  4064. // //这个收款余额
  4065. // $sumBalance=$invoiceReceivables->balanceOfReceivablesPrice($detailM ['irid']);
  4066. // $sum=$sumBind+$sumBalance;
  4067. //这个收款余额
  4068. $sumBalance=$detailM ['receivablesPrice']-$detailM ['bindPrice'];
  4069. // echo $detailM ['irid'].'/'.$sumBalance.'/'.$detail ['invoicePrice'];
  4070. // die;
  4071. $item = array (
  4072. 'iid' => $detail ['iid'],
  4073. 'irid' => $iridString
  4074. );
  4075. if ($detail ['invoicePrice'] <= $sumBalance){
  4076. $item += array (
  4077. 'invoiceBalance'=>0,
  4078. 'untreadStatus' => 3,
  4079. 'bindTime' => date ( "Y-m-d H:i:s" )
  4080. );
  4081. }else{
  4082. $item += array (
  4083. 'invoiceBalance'=>$detail ['invoicePrice']-$sumBalance,
  4084. );
  4085. }
  4086. // print_r($item);
  4087. // echo $sum;die;
  4088. $invoice->setInvoiceByCondition ( $item );
  4089. // 操作日志
  4090. $item = array (
  4091. 'date' => date ( "Y-m-d H:i:s" ),
  4092. 'operation' => "收款" . $detailM ['receivablesSerial'] . "入账到发票" . $detail ['invoiceSerial'],
  4093. 'status' => 8,
  4094. 'img' => $this->staff [0] ['avatar'],
  4095. 'username' => $this->staff [0] ['username'],
  4096. 'uid' => $this->staff [0] ['sid'],
  4097. 'category' => $this->staff [0] ['category'],
  4098. 'iid' => $detail ['iid']
  4099. );
  4100. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  4101. Doo::loadModel ( 'invoiceStatistics' );
  4102. $invoiceStatistics = new invoiceStatistics ();
  4103. $item = array (
  4104. 'date' => $detailM ['receivablesDate'],
  4105. 'priceClass' => 3,
  4106. 'cid' => $detail ['cid'],
  4107. 'staff' => $detail ['sid'],
  4108. 'accountPrice' => $detailM ['receivablesPrice']
  4109. );
  4110. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4111. // 公司流水记录
  4112. // Doo::loadModel ( 'wasteBook' );
  4113. // $wasteBook = new wasteBook ();
  4114. // $abDetail = $wasteBook->getAccountBookByAid (1,8,$detail ['iid'] );
  4115. // $accountBank='';
  4116. // if ($detailM ['receivablesBank']=='纵横广发'){
  4117. // $accountBank='CGBDeposit';
  4118. // }elseif($detailM ['receivablesBank']=='纵横工行'){
  4119. // $accountBank='ICBCDeposit';
  4120. // }elseif($detailM ['receivablesBank']=='华润银行'){
  4121. // $accountBank='HUADeposit';
  4122. // }elseif($detailM ['receivablesBank']=='个人广发'){
  4123. // $accountBank='PersonalDeposit';
  4124. // }
  4125. // if (empty($abDetail)){
  4126. // $item = array (
  4127. // 'dataID' => $detail ['iid'],
  4128. // 'expensesType' => 1,
  4129. // 'accountType' => 8,
  4130. // 'accountPriceShow'=>$detail ['invoicePrice'],
  4131. // 'accountPrice'=>$detail ['invoicePrice'],
  4132. // 'accountBank'=>$accountBank,
  4133. // 'category'=>$this->staff[0]['category'],
  4134. // 'cid'=>$this->staff[0]['cid'],
  4135. // 'name'=>$this->staff[0]['username'],
  4136. // 'sid'=>$this->staff[0]['sid'],
  4137. // 'inputDate'=>date ( "Y-m-d H:i:s" )
  4138. // );
  4139. // $wasteBook->setAccountBookStatistics($item);
  4140. // }
  4141. return "/invoiceReceivables";
  4142. }
  4143. /**
  4144. * 核销 动作,确认入账统计 发票收款完成--需求更变 废弃 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"; }
  4145. */
  4146. function invoiceAggregate() {
  4147. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  4148. Doo::loadModel ( 'invoiceStatistics' );
  4149. $invoiceStatistics = new invoiceStatistics ();
  4150. Doo::loadModel ( 'L_category' );
  4151. $Lcategory = new L_category ();
  4152. $isList = $invoiceStatistics->getInvoiceStatisticsByYear ( $year );
  4153. $LcategoryList = $Lcategory->getCategory ();
  4154. // print_r($isList);
  4155. $html = ""; // $invoicePriceCategory=0;$receivablesPriceCategory=0;$accountPriceCategory=0;
  4156. foreach ( $LcategoryList as $key => $value ) {
  4157. $html .= '<tr><th><a href="/invoiceAggregateCategory/' . $value ['cidKey'] . '">' . $value ['title'] . '</a></th>';
  4158. $month = 1;
  4159. $invoicePriceYear = 0;
  4160. $receivablesPriceYear = 0;
  4161. $accountPriceYear = 0;
  4162. for(; $month <= 12; $month ++) {
  4163. $flag = true;
  4164. foreach ( $isList ['statisticsMonthCid'] as $k => $v ) {
  4165. if ($value ['cid'] == $v ['cid'] && $month == $v ['month']) {
  4166. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  4167. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  4168. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  4169. ';
  4170. $invoicePriceYear += $v ['invoicePrice'];
  4171. $receivablesPriceYear += $v ['receivablesPrice'];
  4172. $accountPriceYear += $v ['accountPrice'];
  4173. $flag = false;
  4174. break;
  4175. }
  4176. }
  4177. if ($flag)
  4178. $html .= '<td class="taR"></td>
  4179. <td class="taR"></td>
  4180. <td class="taR"><b></b></td>
  4181. ';
  4182. }
  4183. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  4184. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  4185. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  4186. ';
  4187. $html .= '</tr>';
  4188. }
  4189. $html .= '<tr><th><b class="colGreen">月合计</b></th>';
  4190. $invoicePriceYear = 0;
  4191. $receivablesPriceYear = 0;
  4192. $accountPriceYear = 0;
  4193. for($month = 1; $month <= 12; $month ++) {
  4194. $flag = true;
  4195. foreach ( $isList ['statisticsMonth'] as $k => $v ) {
  4196. if ($month == $v ['month']) {
  4197. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  4198. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  4199. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  4200. ';
  4201. $invoicePriceYear += $v ['invoicePrice'];
  4202. $receivablesPriceYear += $v ['receivablesPrice'];
  4203. $accountPriceYear += $v ['accountPrice'];
  4204. $flag = false;
  4205. break;
  4206. }
  4207. }
  4208. if ($flag) {
  4209. $html .= '<td class="taR"></td>
  4210. <td class="taR"></td>
  4211. <td class="taR"><b></b></td>
  4212. ';
  4213. }
  4214. }
  4215. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  4216. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  4217. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  4218. ';
  4219. $html .= '</tr>';
  4220. // print_r($isList);
  4221. $this->data ['html'] = $html;
  4222. $this->data ['LcategoryList'] = $LcategoryList;
  4223. $this->data ['isList'] = $isList;
  4224. $this->data ['year'] = $year;
  4225. $this->data ['memu'] = "invoice";
  4226. $this->data ['staff'] = $this->staff;
  4227. $this->data ['receiptMemu'] = 'invoiceAggregate';
  4228. $this->render ( "/admin/invoiceAggregate", $this->data );
  4229. }
  4230. function invoiceAggregateStaff() {
  4231. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  4232. Doo::loadModel ( 'invoiceStatistics' );
  4233. $invoiceStatistics = new invoiceStatistics ();
  4234. Doo::loadModel ( 'L_category' );
  4235. $Lcategory = new L_category ();
  4236. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year );
  4237. $staffList = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year );
  4238. $cStaff = $Lcategory->getCategoryStaff ();
  4239. $html = '';
  4240. foreach ( $cStaff as $key => $value ) {
  4241. $categoryFir = true;
  4242. foreach ( $value ['staff'] as $k => $v ) {
  4243. if ($categoryFir) {
  4244. $width = count ( $value ['staff'] ) + 1;
  4245. $html .= '<tr><th rowspan="' . $width . '">' . $value ['title'] . ' </th>';
  4246. $categoryFir = false;
  4247. } else
  4248. $html .= '<tr>';
  4249. $html .= '<th>' . $v ['username'] . '</th>';
  4250. $invoicePriceStaffYear = 0;
  4251. $receivablesPriceStaffYear = 0;
  4252. $accountPriceStaffYear = 0;
  4253. for($month = 1; $month <= 12; $month ++) {
  4254. $flag = true;
  4255. foreach ( $staffList ['statisticsMonthStaff'] as $sl => $slv ) {
  4256. if ($v ['sid'] == $slv ['staff'] && $month == $slv ['month']) {
  4257. $html .= '<td class="taR">¥' . $slv ['invoicePrice'] . '</td>
  4258. <td class="taR">¥' . $slv ['receivablesPrice'] . '</td>
  4259. <td class="taR"><b>¥' . $slv ['accountPrice'] . '</b></td>
  4260. ';
  4261. $invoicePriceStaffYear += $slv ['invoicePrice'];
  4262. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  4263. $accountPriceStaffYear += $slv ['accountPrice'];
  4264. $flag = false;
  4265. break;
  4266. }
  4267. }
  4268. if ($flag)
  4269. $html .= '<td class="taR"></td>
  4270. <td class="taR"></td>
  4271. <td class="taR"><b></b></td>
  4272. ';
  4273. }
  4274. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  4275. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  4276. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  4277. ';
  4278. }
  4279. $html .= '</tr>';
  4280. // 小计
  4281. if (! empty ( $value ['staff'] )) {
  4282. $html .= '<tr><th class="taR">小计</th>';
  4283. $invoicePriceStaffYear = 0;
  4284. $receivablesPriceStaffYear = 0;
  4285. $accountPriceStaffYear = 0;
  4286. for($month = 1; $month <= 12; $month ++) {
  4287. $flag = true;
  4288. foreach ( $staffList ['statisticsMonthCid'] as $smc => $smcv ) {
  4289. if ($value ['cid'] == $smcv ['cid'] && $month == $slv ['month']) {
  4290. $html .= '<td class="taR">¥' . $smcv ['invoicePrice'] . '</td>
  4291. <td class="taR">¥' . $smcv ['receivablesPrice'] . '</td>
  4292. <td class="taR"><b>¥' . $smcv ['accountPrice'] . '</b></td>
  4293. ';
  4294. $invoicePriceStaffYear += $slv ['invoicePrice'];
  4295. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  4296. $accountPriceStaffYear += $slv ['accountPrice'];
  4297. $flag = false;
  4298. break;
  4299. }
  4300. }
  4301. if ($flag)
  4302. $html .= '<td class="taR"></td>
  4303. <td class="taR"></td>
  4304. <td class="taR"><b></b></td>
  4305. ';
  4306. }
  4307. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  4308. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  4309. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  4310. ';
  4311. $html .= '</tr>';
  4312. }
  4313. }
  4314. $html .= '<tr class="warning"><th colspan="2"><b class="colGreen" >月合计</b></th>';
  4315. $invoicePriceYear = 0;
  4316. $receivablesPriceYear = 0;
  4317. $accountPriceYear = 0;
  4318. for($month = 1; $month <= 12; $month ++) {
  4319. $flag = true;
  4320. foreach ( $staffList ['statisticsMonth'] as $k => $v ) {
  4321. if ($month == $v ['month']) {
  4322. $html .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>
  4323. <td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>
  4324. <td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>
  4325. ';
  4326. $invoicePriceYear += $v ['invoicePrice'];
  4327. $receivablesPriceYear += $v ['receivablesPrice'];
  4328. $accountPriceYear += $v ['accountPrice'];
  4329. $flag = false;
  4330. break;
  4331. }
  4332. }
  4333. if ($flag)
  4334. $html .= '<td class="taR"></td>
  4335. <td class="taR"></td>
  4336. <td class="taR"><b></b></td>
  4337. ';
  4338. }
  4339. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  4340. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  4341. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  4342. ';
  4343. $html .= '</tr>';
  4344. $this->data ['html'] = $html;
  4345. $this->data ['isList'] = $toteList;
  4346. $this->data ['year'] = $year;
  4347. $this->data ['memu'] = "invoice";
  4348. $this->data ['staff'] = $this->staff;
  4349. $this->data ['receiptMemu'] = 'invoiceAggregate';
  4350. $this->render ( "/admin/invoiceAggregateStaff", $this->data );
  4351. }
  4352. function invoiceAggregateCategory() {
  4353. Doo::loadClass ( 'XDeode' );
  4354. $XDeode = new XDeode ( 5 );
  4355. $cid = $cidKey = isset ( $this->params ['cid'] ) ? $this->params ['cid'] : "";
  4356. $cid = $XDeode->decode ( $cid );
  4357. if (! is_numeric ( $cid ))
  4358. die ( 'illegal request' );
  4359. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  4360. Doo::loadModel ( 'invoiceStatistics' );
  4361. $invoiceStatistics = new invoiceStatistics ();
  4362. Doo::loadModel ( 'staff' );
  4363. $staff = new staff ();
  4364. $list = $staff->getStaffByCid ( $cid );
  4365. $isCategory = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year, $cid );
  4366. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year, $cid );
  4367. if (empty ( $list ))
  4368. die ( '该办事处没有成员' );
  4369. $htmlA = $htmlB = $htmlC = $html = '';
  4370. foreach ( $list as $key => $value ) {
  4371. $htmlA = '<tr><th rowspan="3">' . $value ['username'] . '</th><th class="taC">开票</th>';
  4372. $htmlB = '<tr><th class="taC">收款</th>';
  4373. $htmlC = '<tr><th class="taC">入账</th>';
  4374. $invoicePriceStaffYear = 0;
  4375. $receivablesPriceStaffYear = 0;
  4376. $accountPriceStaffYear = 0;
  4377. for($month = 1; $month <= 12; $month ++) {
  4378. $flag = true;
  4379. foreach ( $isCategory ['statisticsMonthStaff'] as $k => $v ) {
  4380. if ($value ['sid'] == $v ['staff'] && $month == $v ['month']) {
  4381. $htmlA .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>';
  4382. $htmlB .= '<td class="taR">¥' . $v ['receivablesPrice'] . '</td>';
  4383. $htmlC .= '<td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>';
  4384. $invoicePriceStaffYear += $v ['invoicePrice'];
  4385. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  4386. $accountPriceStaffYear += $v ['accountPrice'];
  4387. $flag = false;
  4388. break;
  4389. }
  4390. }
  4391. if ($flag) {
  4392. $htmlA .= '<td class="taR">-</td>';
  4393. $htmlB .= '<td class="taR">-</td>';
  4394. $htmlC .= '<td class="taR"><b>-</b></td>';
  4395. }
  4396. }
  4397. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  4398. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  4399. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  4400. $htmlA .= '</tr>';
  4401. $htmlB .= '</tr>';
  4402. $htmlC .= '</tr>';
  4403. $html .= $htmlA . $htmlB . $htmlC;
  4404. }
  4405. $htmlA = $htmlB = $htmlC = "";
  4406. $htmlA = '<tr><th rowspan="3">月合计</th><th class="taC">开票</th>';
  4407. $htmlB = '<tr><th class="taC">收款</th>';
  4408. $htmlC = '<tr><th class="taC">入账</th>';
  4409. $invoicePriceStaffYear = 0;
  4410. $receivablesPriceStaffYear = 0;
  4411. $accountPriceStaffYear = 0;
  4412. for($month = 1; $month <= 12; $month ++) {
  4413. $flag = true;
  4414. foreach ( $isCategory ['statisticsMonth'] as $k => $v ) {
  4415. if ($month == $v ['month']) {
  4416. $htmlA .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>';
  4417. $htmlB .= '<td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>';
  4418. $htmlC .= '<td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>';
  4419. $invoicePriceStaffYear += $v ['invoicePrice'];
  4420. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  4421. $accountPriceStaffYear += $v ['accountPrice'];
  4422. $flag = false;
  4423. break;
  4424. }
  4425. }
  4426. if ($flag) {
  4427. $htmlA .= '<td class="taR">-</td>';
  4428. $htmlB .= '<td class="taR">-</td>';
  4429. $htmlC .= '<td class="taR"><b>-</b></td>';
  4430. }
  4431. }
  4432. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  4433. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  4434. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  4435. $htmlA .= '</tr>';
  4436. $htmlB .= '</tr>';
  4437. $htmlC .= '</tr>';
  4438. $html .= $htmlA . $htmlB . $htmlC;
  4439. $this->data ['html'] = $html;
  4440. $this->data ['cidKey'] = $cidKey;
  4441. $this->data ['slist'] = $list;
  4442. $this->data ['isList'] = $toteList;
  4443. $this->data ['year'] = $year;
  4444. $this->data ['memu'] = "invoice";
  4445. $this->data ['staff'] = $this->staff;
  4446. $this->data ['receiptMemu'] = 'invoiceAggregate';
  4447. $this->render ( "/admin/invoiceAggregateCategory", $this->data );
  4448. }
  4449. /**
  4450. * 办事处汇总信息
  4451. */
  4452. function invoiceAggregateCategoryDetail() {
  4453. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  4454. Doo::loadClass ( 'XDeode' );
  4455. $XDeode = new XDeode ( 5 );
  4456. Doo::loadModel ( 'invoiceStatistics' );
  4457. $invoiceStatistics = new invoiceStatistics ();
  4458. Doo::loadModel ( 'L_category' );
  4459. $category = new L_category ();
  4460. Doo::loadModel ( 'invoice' );
  4461. $invoice = new invoice ();
  4462. Doo::loadModel ( 'staff' );
  4463. $staff = new staff ();
  4464. Doo::loadModel ( "invoiceCategoryManage" );
  4465. $invoiceCategoryManage = new invoiceCategoryManage ();
  4466. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4467. $cidList = array ();
  4468. foreach ( $imcStaff as $key => $value ) {
  4469. array_push ( $cidList, $value ['cid'] );
  4470. if (empty ( $cidKey ))
  4471. $cidKey = $XDeode->encode ( $value ['cid'] );
  4472. }
  4473. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  4474. $cid = $XDeode->decode ( $cidKey );
  4475. $month = date ( "m", strtotime ( "-1 month" ) );
  4476. $YearMonth = date ( "Y-m", strtotime ( "-1 month" ) );
  4477. $redis = new Redis ();
  4478. $redis->connect ( '127.0.0.1', '6379' );
  4479. $redisKey = ''; // date('Y-m-d').'_iacd_'.$cid;
  4480. $redisValue = ''; // $redis->lrange($redisKey, 0, -1);
  4481. if (empty ( $redisValue )) {
  4482. $isMC = $invoiceStatistics->getInvoiceStatistiscsMothByCategory ( $cid );
  4483. $schedule = $invoice->getInvoiceScheduleByCid ( $cid );
  4484. // 获得办事处人员下的汇总
  4485. $slist = $staff->getStaffByCid ( $cid );
  4486. $ismsbMonth = $invoiceStatistics->getISMSByCategoryByMonth ( $cid, $YearMonth ); // 上一个月的汇总
  4487. $ismsb = $invoiceStatistics->getISMSByCategory ( $cid ); // 当月汇总
  4488. $ISAS = $invoiceStatistics->getISASByCategory ( $cid ); // 全部汇总
  4489. $scheduleStaff = $invoice->getInvoiceScheduleByCidGroupSid ( $cid ); // 完成度
  4490. foreach ( $slist as $key => $value ) {
  4491. $slist [$key] ['invoicePrice'] = 0;
  4492. $slist [$key] ['receivablesPrice'] = 0;
  4493. $slist [$key] ['accountPrice'] = 0;
  4494. $slist [$key] ['invoiceAllPrice'] = 0;
  4495. $slist [$key] ['receivablesAllPrice'] = 0;
  4496. $slist [$key] ['accountAllPrice'] = 0;
  4497. $slist [$key] ['schedule'] = 0;
  4498. $slist [$key] ['invoiceMonthPrice'] = 0;
  4499. $slist [$key] ['receivablesMonthPrice'] = 0;
  4500. $slist [$key] ['accountMonthPrice'] = 0;
  4501. foreach ( $ismsbMonth as $y => $l ) {
  4502. if ($value ['sid'] == $l ['staff']) {
  4503. $slist [$key] ['invoiceMonthPrice'] = $l ['invoicePrice'];
  4504. $slist [$key] ['receivablesMonthPrice'] = $l ['receivablesPrice'];
  4505. $slist [$key] ['accountMonthPrice'] = $l ['accountPrice'];
  4506. }
  4507. }
  4508. foreach ( $ismsb as $k => $v ) {
  4509. if ($value ['sid'] == $v ['staff']) {
  4510. $slist [$key] ['invoicePrice'] = $v ['invoicePrice'];
  4511. $slist [$key] ['receivablesPrice'] = $v ['receivablesPrice'];
  4512. $slist [$key] ['accountPrice'] = $v ['accountPrice'];
  4513. }
  4514. }
  4515. foreach ( $ISAS as $e => $a ) {
  4516. if ($value ['sid'] == $a ['staff']) {
  4517. $slist [$key] ['invoiceAllPrice'] = $a ['invoicePrice'];
  4518. $slist [$key] ['receivablesAllPrice'] = $a ['receivablesPrice'];
  4519. $slist [$key] ['accountAllPrice'] = $a ['accountPrice'];
  4520. }
  4521. }
  4522. if (isset ( $scheduleStaff [$value ['sid']] ))
  4523. $slist [$key] ['schedule'] = $scheduleStaff [$value ['sid']];
  4524. }
  4525. $this->data ['cidKey'] = $cidKey;
  4526. $schedule = ( int ) ($schedule * 100);
  4527. $this->data ['slist'] = $slist;
  4528. $this->data ['isMC'] = $isMC;
  4529. $this->data ['schedule'] = $schedule;
  4530. $slist = json_encode ( $slist );
  4531. $isMC = json_encode ( $isMC );
  4532. $schedule = json_encode ( $schedule );
  4533. $redis->lpush ( $redisKey, $slist );
  4534. $redis->lpush ( $redisKey, $isMC );
  4535. $redis->lpush ( $redisKey, $schedule );
  4536. } else {
  4537. $this->data ['cidKey'] = $cidKey;
  4538. $this->data ['slist'] = json_decode ( $redisValue [2], true );
  4539. $this->data ['isMC'] = json_decode ( $redisValue [1], true );
  4540. $this->data ['schedule'] = json_decode ( $redisValue [0], true );
  4541. }
  4542. $this->data ['month'] = $month;
  4543. $this->data ['categoryList'] = $categoryList;
  4544. $this->data ['memu'] = "invoice";
  4545. $this->data ['staff'] = $this->staff;
  4546. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4547. $this->render ( "/admin/invoiceAggregateCategoryDetail", $this->data );
  4548. }
  4549. /**
  4550. * 办事处人员汇总详情
  4551. */
  4552. function invoiceAggregateStaffDetail() {
  4553. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  4554. // $sidKey = isset ( $this->params ['sidKey'] ) ? $this->params ['sidKey'] : '';
  4555. Doo::loadClass ( 'XDeode' );
  4556. $XDeode = new XDeode ( 5 );
  4557. Doo::loadModel ( 'invoice' );
  4558. $invoice = new invoice ();
  4559. Doo::loadModel ( 'staff' );
  4560. $staff = new staff ();
  4561. Doo::loadModel ( "invoiceCategoryManage" );
  4562. $invoiceCategoryManage = new invoiceCategoryManage ();
  4563. $sid = $XDeode->decode ( $sidKey );
  4564. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4565. $cidList = array ();
  4566. foreach ( $imcStaff as $key => $value ) {
  4567. array_push ( $cidList, $value ['cid'] );
  4568. if (empty ( $cidKey ))
  4569. $cidKey = $XDeode->encode ( $value ['cid'] );
  4570. }
  4571. $cidString = implode ( ',', $cidList );
  4572. $staffList = $staff->getStaffInCid ( $cidString );
  4573. $staffDetail = $staff->getStaffBySid ( $sid );
  4574. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4575. $page_size = 18;
  4576. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4577. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4578. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  4579. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  4580. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  4581. $dateArr = explode ( ':', $date );
  4582. $D1 = '';
  4583. $D2 = '';
  4584. if (! empty ( $date )) {
  4585. $D1 = $dateArr [0] . " 00:00:00 ";
  4586. if (isset ( $dateArr [1] ))
  4587. $D2 = $dateArr [1] . " 23:59:59 ";
  4588. else
  4589. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4590. // $D2 = $dateArr [1];
  4591. }
  4592. $con = ' status=2 ';
  4593. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4594. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4595. if ($status == 'UNRECORD')
  4596. $con .= ' and printStatus=1 and untreadStatus=0';
  4597. elseif ($status == 'RECORD')
  4598. $con .= ' and printStatus=1 and untreadStatus=3';
  4599. elseif ($status == 'BOUNCED')
  4600. $con .= ' and untreadStatus=2';
  4601. elseif ($status == 'PARTRECORD')
  4602. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  4603. elseif ($status == 'All') {
  4604. $con .= ' and ( untreadStatus=2 or untreadStatus=0 or untreadStatus=3 )';
  4605. }
  4606. $con .= ' and sid=' . $sid;
  4607. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  4608. if (! empty ( $MebSea )) {
  4609. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  4610. }
  4611. $pageinfo ['page'] = array (
  4612. 'previous' => ''
  4613. );
  4614. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateStaffDetail", $get, "" );
  4615. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4616. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  4617. $this->data ['staffDetail'] = $staffDetail;
  4618. $this->data ['staffList'] = $staffList;
  4619. $this->data ['MebSeaEn'] = $MebSea;
  4620. $this->data ['MebSea'] = urlencode ( $MebSea );
  4621. $this->data ['date'] = $date;
  4622. $this->data ['page'] = $pageinfo;
  4623. $this->data ['get'] = $get;
  4624. $this->data ['list'] = $list;
  4625. $this->data ['status'] = $status;
  4626. $this->data ['sidKey'] = $sidKey;
  4627. $this->data ['memu'] = "invoice";
  4628. $this->data ['staff'] = $this->staff;
  4629. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4630. $this->render ( "/admin/invoiceAggregateStaffDetail", $this->data );
  4631. }
  4632. /**
  4633. * 办事处人员汇总收款情
  4634. */
  4635. function invoiceAggregateStaffReceivablesDetail() {
  4636. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  4637. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  4638. Doo::loadModel ( 'invoiceReceivables' );
  4639. $invoiceReceivables = new invoiceReceivables ();
  4640. Doo::loadModel ( 'staff' );
  4641. $staff = new staff ();
  4642. Doo::loadModel ( "invoiceCategoryManage" );
  4643. $invoiceCategoryManage = new invoiceCategoryManage ();
  4644. Doo::loadClass ( 'XDeode' );
  4645. $XDeode = new XDeode ( 5 );
  4646. $sid = $XDeode->decode ( $sidKey );
  4647. $staffDetail = $staff->getStaffBySid ( $sid );
  4648. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4649. $cidList = array ();
  4650. foreach ( $imcStaff as $key => $value ) {
  4651. array_push ( $cidList, $value ['cid'] );
  4652. if (empty ( $cidKey ))
  4653. $cidKey = $XDeode->encode ( $value ['cid'] );
  4654. }
  4655. $cidString = implode ( ',', $cidList );
  4656. $staffList = $staff->getStaffInCid ( $cidString );
  4657. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4658. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  4659. $page_size = 10;
  4660. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4661. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4662. if ($timeType == "BINDOTP") {
  4663. $status = 'Credited';
  4664. }
  4665. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  4666. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  4667. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  4668. $dateArr = explode ( ':', $date );
  4669. $D1 = '';
  4670. $D2 = '';
  4671. if (! empty ( $date )) {
  4672. $D1 = $dateArr [0] . " 00:00:00 ";
  4673. if (isset ( $dateArr [1] ))
  4674. $D2 = $dateArr [1] . " 23:59:59 ";
  4675. else
  4676. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4677. }
  4678. $con = ' a.receivablesStaff like "%' . $staffDetail ['username'] . '%" ';
  4679. $descField = 'a.bindDate';
  4680. if ($timeType == 'CREATE')
  4681. $descField = 'a.date';
  4682. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4683. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4684. elseif (! empty ( $D1 ) && empty ( $D2 ))
  4685. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  4686. if ($status == 'Unclaimed')
  4687. $con .= ' and a.bindStatus=0';
  4688. elseif ($status == 'Credited')
  4689. $con .= ' and a.bindStatus=1';
  4690. elseif ($status == 'Claim')
  4691. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  4692. elseif ($status == 'BBN')
  4693. $con .= ' and a.bindPrice>a.receivablesPrice';
  4694. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  4695. if (! empty ( $MebSea )) {
  4696. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" )';
  4697. }
  4698. $pageinfo ['page'] = array (
  4699. 'previous' => ''
  4700. );
  4701. // $sql = 'select group_concat(b.invoiceSerial) as invoiceSerial ,group_concat(b.iid) as invoiceId
  4702. // from CLD_invoiceReceivables as a left join CLD_invoice as b on
  4703. // find_in_set(b.iid,a.iidExtend) or a.iid=b.iid
  4704. // where ' . $con . ' group by a.irid ';
  4705. $pageinfo =$this->get_page ( "CLD_invoiceReceivables as a", $con, $page, $page_size, "invoiceAggregateStaffReceivablesDetail", $get, "" );
  4706. //$pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceAggregateStaffReceivablesDetail", $get, "" );
  4707. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4708. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', $descField);
  4709. foreach ( $list as $key => $value ) {
  4710. $list [$key] ['category'] = '';
  4711. if ($value ['receivablesCategory'] != 'PUBLIC') {
  4712. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  4713. $list [$key] ['category'] = $receivablesCategory [1];
  4714. }
  4715. }
  4716. // print_r($list);
  4717. $this->data ['staffDetail'] = $staffDetail;
  4718. $this->data ['sidKey'] = $sidKey;
  4719. $this->data ['staffList'] = $staffList;
  4720. $this->data ['timeType'] = $timeType;
  4721. $this->data ['MebSeaEn'] = $MebSea;
  4722. $this->data ['MebSea'] = urlencode ( $MebSea );
  4723. $this->data ['date'] = $date;
  4724. $this->data ['page'] = $pageinfo;
  4725. $this->data ['get'] = $get;
  4726. $this->data ['list'] = $list;
  4727. $this->data ['status'] = $status;
  4728. $this->data ['memu'] = "invoice";
  4729. $this->data ['staff'] = $this->staff;
  4730. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4731. $this->render ( "/admin/invoiceAggregateStaffReceivablesDetail", $this->data );
  4732. }
  4733. function invoiceAchieve() {
  4734. Doo::loadModel ( 'invoice' );
  4735. $invoice = new invoice ();
  4736. Doo::loadClass ( 'XDeode' );
  4737. $XDeode = new XDeode ( 5 );
  4738. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4739. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4740. $page_size = 18;
  4741. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4742. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4743. $get = "/" . $date;
  4744. $con = '';
  4745. if ($date == 'MONTHO')
  4746. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4747. elseif ($date == 'MONTHT')
  4748. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4749. elseif ($date == 'MONTHY')
  4750. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4751. if (! empty ( $MebSea )) {
  4752. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4753. $get .= "/" . $MebSea;
  4754. }
  4755. $pageinfo ['page'] = array (
  4756. 'previous' => ''
  4757. );
  4758. $sql = 'status=2 and printStatus=1 and irid!="" and ( untreadStatus=3 or untreadStatus=0 ) and sid=' . $sid . $con;
  4759. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceAchieve", $get, "" );
  4760. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4761. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  4762. // print_r($pageinfo);
  4763. $this->data ['MebSeaEn'] = $MebSea;
  4764. $this->data ['MebSea'] = urlencode ( $MebSea );
  4765. $this->data ['get'] = $get;
  4766. $this->data ['page'] = $pageinfo;
  4767. $this->data ['list'] = $list;
  4768. $this->data ['date'] = $date;
  4769. $this->data ['memu'] = "invoice";
  4770. $this->data ['staff'] = $this->staff;
  4771. $this->data ['receiptMemu'] = 'invoice';
  4772. $this->render ( "/admin/invoiceAchieve", $this->data );
  4773. }
  4774. /**
  4775. */
  4776. function invoiceMyUnAccountAchieve() {
  4777. Doo::loadModel ( 'invoice' );
  4778. $invoice = new invoice ();
  4779. Doo::loadClass ( 'XDeode' );
  4780. $XDeode = new XDeode ( 5 );
  4781. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4782. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4783. $page_size = 18;
  4784. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4785. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4786. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4787. $dateArr = explode ( ':', $date );
  4788. $D1 = '';
  4789. $D2 = '';
  4790. if (! empty ( $date )) {
  4791. $D1 = $dateArr [0];
  4792. $D2 = $dateArr [1];
  4793. }
  4794. $con = '';
  4795. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4796. $con = ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4797. if (! empty ( $MebSea )) {
  4798. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4799. }
  4800. $pageinfo ['page'] = array (
  4801. 'previous' => ''
  4802. );
  4803. // and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  4804. $sql = " status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid= " . $sid . $con;
  4805. $action = "invoiceMyUnAccountAchieve";
  4806. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  4807. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4808. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 'desc', 'printTime' );
  4809. Doo::loadModel ( 'express' );
  4810. $express = new express ();
  4811. $expressList = $express->getExpressByAll ();
  4812. $this->data ['expressList'] = $expressList;
  4813. // print_r($list);
  4814. $this->data ['MebSeaEn'] = $MebSea;
  4815. $this->data ['get'] = $get;
  4816. $this->data ['page'] = $pageinfo;
  4817. $this->data ['date'] = $date;
  4818. $this->data ['list'] = $list;
  4819. $this->data ['memu'] = "invoice";
  4820. $this->data ['staff'] = $this->staff;
  4821. $this->data ['receiptMemu'] = 'invoice';
  4822. $this->render ( "/admin/invoiceMyUnAccountAchieve", $this->data );
  4823. }
  4824. function invoiceReceivablesAchieve() {
  4825. Doo::loadModel ( 'invoiceReceivables' );
  4826. $invoiceReceivables = new invoiceReceivables ();
  4827. Doo::loadClass ( 'XDeode' );
  4828. $XDeode = new XDeode ( 5 );
  4829. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4830. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  4831. $page_size = 12;
  4832. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4833. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4834. $get = "/" . $date;
  4835. $con = '';
  4836. if ($date == 'MONTHO')
  4837. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4838. elseif ($date == 'MONTHT')
  4839. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4840. elseif ($date == 'MONTHY')
  4841. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4842. if (! empty ( $MebSea )) {
  4843. $con .= ' and ( receivablesMessage like "%' . $MebSea . '%" or receivablesPrice like "%' . $MebSea . '%" )';
  4844. $get .= "/" . $MebSea;
  4845. }
  4846. $pageinfo ['page'] = array (
  4847. 'previous' => ''
  4848. );
  4849. $sql = " bindStatus=1 and receivablesStaff like '" . $sid . "-%' " . $con;
  4850. $pageinfo = $this->get_page ( "CLD_invoiceReceivables", $sql, $page, $page_size, "invoiceReceivablesAchieve", $get, "" );
  4851. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4852. $list = $invoiceReceivables->getReceivablesByUntreadStatusPage ( $limit, $sql );
  4853. // print_r($pageinfo);
  4854. $this->data ['MebSeaEn'] = $MebSea;
  4855. $this->data ['MebSea'] = urlencode ( $MebSea );
  4856. $this->data ['get'] = $get;
  4857. $this->data ['page'] = $pageinfo;
  4858. $this->data ['list'] = $list;
  4859. $this->data ['date'] = $date;
  4860. $this->data ['memu'] = "invoice";
  4861. $this->data ['staff'] = $this->staff;
  4862. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  4863. $this->render ( "/admin/invoiceReceivablesAchieve", $this->data );
  4864. }
  4865. /**
  4866. * 收款解绑
  4867. */
  4868. function invoiceUnBundLing() {
  4869. $unBundKey = $this->get_args ( 'unBundKey' ) ? $this->get_args ( 'unBundKey' ) : '';
  4870. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  4871. Doo::loadModel ( 'invoice' );
  4872. $invoice = new invoice ();
  4873. Doo::loadModel ( 'invoiceReceivables' );
  4874. $invoiceReceivables = new invoiceReceivables ();
  4875. Doo::loadModel ( 'invoiceOperationLog' );
  4876. $invoiceOperationLog = new invoiceOperationLog ();
  4877. Doo::loadModel ( 'invoiceROLog' );
  4878. $invoiceROLog = new invoiceROLog ();
  4879. Doo::loadModel ( 'invoiceStatistics' );
  4880. Doo::loadClass ( 'XDeode' );
  4881. $XDeode = new XDeode ( 5 );
  4882. if (empty ( $iidKey ) || empty ( $unBundKey ))
  4883. die ( 'illegal request' );
  4884. $iid = $XDeode->decode ( $iidKey );
  4885. $irid = $invoice->authcode ( $unBundKey );
  4886. if ((! empty ( $irid ) && ! is_numeric ( $irid )) || (! empty ( $iid ) && ! is_numeric ( $iid )))
  4887. die ( 'illegal request' );
  4888. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4889. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  4890. if (empty ( $irDetails ) || empty ( $invoiceDetails ) || (empty ( $irDetails ['iid'] ) && empty ( $irDetails ['iidExtend'] )) || $invoiceDetails ['untreadStatus'] == 2)
  4891. die ( 'illegal request' );
  4892. // 收款
  4893. $item = array (
  4894. 'irid' => $irDetails ['irid'],
  4895. 'bindPrice' => $irDetails ['bindPrice'] - $invoiceDetails ['invoicePrice'],
  4896. 'bindStatus' => 0
  4897. );
  4898. if ($irDetails ['iid'] == $iid)
  4899. $item += array (
  4900. 'iid' => 0
  4901. );
  4902. else {
  4903. $iidExtend = explode ( ',', $irDetails ['iidExtend'] );
  4904. foreach ( $iidExtend as $key => $value ) {
  4905. if ($value == $iid)
  4906. unset ( $iidExtend [$key] );
  4907. }
  4908. $iidExtend = implode ( ',', $iidExtend );
  4909. $item += array (
  4910. 'iidExtend' => $iidExtend
  4911. );
  4912. }
  4913. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4914. // 收款操作日志
  4915. $item = array (
  4916. 'operation' => $this->staff [0] ['username'] . " 解绑 " . $irDetails ['receivablesSerial'],
  4917. 'date' => date ( "Y-m-d" ),
  4918. 'status' => 3,
  4919. 'img' => $this->staff [0] ['avatar'],
  4920. 'username' => $this->staff [0] ['username'],
  4921. 'uid' => $this->staff [0] ['sid'],
  4922. 'category' => $this->staff [0] ['category'],
  4923. 'irid' => $irid
  4924. );
  4925. $invoiceROLog->setInvoiceROLog ( $item );
  4926. // 扣除入账统计金额
  4927. $invoiceStatistics = new invoiceStatistics ();
  4928. $item = array (
  4929. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  4930. 'priceClass' => 3,
  4931. 'cid' => $invoiceDetails ['cid'],
  4932. 'staff' => $invoiceDetails ['sid'],
  4933. 'accountPrice' => - $irDetails ['receivablesPrice']
  4934. );
  4935. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4936. // 扣除收款统计金额
  4937. $invoiceStatistics = new invoiceStatistics ();
  4938. $item = array (
  4939. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  4940. 'priceClass' => 2,
  4941. 'cid' => $invoiceDetails ['cid'],
  4942. 'staff' => $invoiceDetails ['sid'],
  4943. 'irid' => $irDetails ['irid'],
  4944. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  4945. );
  4946. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4947. // 发票解绑去收款ID
  4948. $iridString = $invoiceDetails ['irid'];
  4949. if (! empty ( $invoiceDetails ['irid'] )) {
  4950. $list = explode ( ',', $invoiceDetails ['irid'] );
  4951. foreach ( $list as $key => $value ) {
  4952. if ($value == $irDetails ['irid']) {
  4953. unset ( $list [$key] );
  4954. break;
  4955. }
  4956. }
  4957. $iridString = implode ( ",", $list );
  4958. }
  4959. $item = array (
  4960. 'iid' => $invoiceDetails ['iid'],
  4961. 'irid' => $iridString,
  4962. 'updateTime' => date ( "Y-m-d H:i:s" )
  4963. );
  4964. if ($invoiceDetails ['untreadStatus'] == 3)
  4965. $item += array (
  4966. 'untreadStatus' => 0
  4967. );
  4968. $invoice->setInvoiceByCondition ( $item );
  4969. $item = array (
  4970. 'date' => date ( "Y-m-d H:i:s" ),
  4971. 'operation' => '解绑 收款 ' . $irDetails ['receivablesSerial'],
  4972. 'status' => 11,
  4973. 'img' => $this->staff [0] ['avatar'],
  4974. 'username' => $this->staff [0] ['username'],
  4975. 'uid' => $this->staff [0] ['sid'],
  4976. 'category' => $this->staff [0] ['category'],
  4977. 'iid' => $invoiceDetails ['iid']
  4978. );
  4979. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  4980. // 公司流水-解绑时删除流水
  4981. Doo::loadModel ( 'wasteBook' );
  4982. $wasteBook = new wasteBook ();
  4983. // $wasteBook->delete ( array (
  4984. // 'where' => 'dataID=' . $irDetails ['irid'] . ' and accountType=7',
  4985. // 'limit' => 1
  4986. // ) );
  4987. // 银行
  4988. /*
  4989. * $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); }
  4990. */
  4991. return "/invoiceReceivablesAS";
  4992. }
  4993. /**
  4994. * 或者该收款下的所以发票
  4995. */
  4996. function ajaxGetInvoiceReceivablesByInvoice() {
  4997. $irid = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : '';
  4998. Doo::loadModel ( 'invoice' );
  4999. $invoice = new invoice ();
  5000. Doo::loadModel ( 'invoiceReceivables' );
  5001. $invoiceReceivables = new invoiceReceivables ();
  5002. $irid = $invoice->authcode ( $irid );
  5003. if (! empty ( $irid ) && ! is_numeric ( $irid ))
  5004. die ( 'illegal request' );
  5005. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5006. $iidString = $irDetails ['iid'];
  5007. $iidExtend = array_filter ( explode ( ',', $irDetails ['iidExtend'] ) );
  5008. if (! empty ( $irDetails ['iidExtend'] ))
  5009. $iidString .= ',' . implode ( ',', $iidExtend );
  5010. $invoiceList = $invoice->getInvoiceInIid ( $iidString, 'iid,invoiceSerial,invoicePrice,invoiceTitle,invoiceCompany,invoiceElement' );
  5011. $html = "";
  5012. foreach ( $invoiceList as $key => $value ) {
  5013. $title = $value ['invoiceTitle'];
  5014. if (! empty ( $value ['invoiceCompany'] ))
  5015. $title = $value ['invoiceCompany'];
  5016. $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>';
  5017. }
  5018. echo json_encode ( array (
  5019. 'status' => 1,
  5020. 'html' => $html
  5021. ) );
  5022. }
  5023. /**
  5024. * 发票管理
  5025. */
  5026. function invoiceAS() {
  5027. Doo::loadModel ( 'invoice' );
  5028. $invoice = new invoice ();
  5029. Doo::loadModel ( 'invoiceReceivables' );
  5030. $invoiceReceivables = new invoiceReceivables ();
  5031. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  5032. $page_size = 18;
  5033. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5034. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  5035. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5036. $dateArr = explode ( ':', $date );
  5037. $D1 = '';
  5038. $D2 = '';
  5039. if (! empty ( $date )) {
  5040. $D1 = $dateArr [0] . " 00:00:00 ";
  5041. if (isset ( $dateArr [1] ))
  5042. $D2 = $dateArr [1] . " 23:59:59 ";
  5043. else
  5044. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  5045. // $D2 = $dateArr [1];
  5046. }
  5047. $con = ' status=2 ';
  5048. if (! empty ( $D1 ) && ! empty ( $D2 ))
  5049. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  5050. if ($status == 'UNRECORD')
  5051. $con .= ' and printStatus=1 and untreadStatus=0';
  5052. elseif ($status == 'RECORD')
  5053. $con .= ' and printStatus=1 and untreadStatus=3';
  5054. elseif ($status == 'BOUNCED')
  5055. $con .= ' and untreadStatus=2';
  5056. elseif ($status == 'PARTRECORD')
  5057. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  5058. elseif ($status == 'All') {
  5059. $con .= ' and ( untreadStatus=2 or untreadStatus=1 or untreadStatus=0 or untreadStatus=3 )';
  5060. }
  5061. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  5062. if (! empty ( $MebSea )) {
  5063. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  5064. }
  5065. $pageinfo ['page'] = array (
  5066. 'previous' => ''
  5067. );
  5068. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAS", $get, "" );
  5069. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5070. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  5071. $this->data ['MebSeaEn'] = $MebSea;
  5072. $this->data ['MebSea'] = urlencode ( $MebSea );
  5073. $this->data ['date'] = $date;
  5074. $this->data ['page'] = $pageinfo;
  5075. $this->data ['get'] = $get;
  5076. $this->data ['list'] = $list;
  5077. $this->data ['status'] = $status;
  5078. $this->data ['memu'] = "invoice";
  5079. $this->data ['staff'] = $this->staff;
  5080. $this->data ['receiptMemu'] = 'invoiceReceivables';
  5081. $this->render ( "/admin/invoiceAS", $this->data );
  5082. }
  5083. /**
  5084. * 收款管理
  5085. */
  5086. function invoiceReceivablesAS() {
  5087. Doo::loadModel ( 'invoiceReceivables' );
  5088. $invoiceReceivables = new invoiceReceivables ();
  5089. Doo::loadModel ( 'L_category' );
  5090. $lCategory = new L_category ();
  5091. $category = $lCategory->getCategory ();
  5092. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  5093. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  5094. $page_size = 10;
  5095. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5096. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  5097. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5098. $dateArr = explode ( ':', $date );
  5099. $D1 = '';
  5100. $D2 = '';
  5101. if (! empty ( $date )) {
  5102. $D1 = $dateArr [0]; // ." 00:00:00 ";
  5103. if (isset ( $dateArr [1] ))
  5104. $D2 = $dateArr [1]; // ." 23:59:59 ";
  5105. else
  5106. $D2 = $dateArr [0]; // ." 23:59:59 ";//date ( "Y-m-d" );
  5107. }
  5108. $descField = 'a.receivablesDate';
  5109. if ($timeType == 'CREATE')
  5110. $descField = 'a.date';
  5111. $con = ' 1 ';
  5112. if (! empty ( $D1 ) && ! empty ( $D2 ))
  5113. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  5114. elseif (! empty ( $D1 ) && empty ( $D2 ))
  5115. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  5116. if ($status == 'Unclaimed')
  5117. $con .= ' and a.bindStatus=0';
  5118. elseif ($status == 'Credited')
  5119. $con .= ' and a.bindStatus=1';
  5120. elseif ($status == 'Claim')
  5121. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  5122. elseif ($status == 'BBN')
  5123. $con .= ' and a.bankBatchNumber!=""';
  5124. elseif ($status == 'REFUND')
  5125. $con .= ' and ( (a.bindStatus=0 and a.refundLog!="" ) or a.bindStatus=2)';
  5126. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  5127. if (! empty ( $MebSea )) {
  5128. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" or a.receivablesSerial like "%' . $MebSea . '%" )';
  5129. }
  5130. $pageinfo ['page'] = array (
  5131. 'previous' => ''
  5132. );
  5133. // if(!empty($con)){
  5134. // $con=' where 1 '.$con;
  5135. // }
  5136. // $sql = 'select a.iid from CLD_invoiceReceivables as a
  5137. // ' . $con ;
  5138. $pageinfo =$this->get_page ( "CLD_invoiceReceivables as a", $con, $page, $page_size, "invoiceReceivablesAS", $get, "" );
  5139. //echo $sql;
  5140. //$pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceReceivablesAS", $get, "" );
  5141. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5142. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', $descField );
  5143. foreach ( $list as $key => $value ) {
  5144. $list [$key] ['category'] = '';
  5145. if ($value ['receivablesCategory'] != 'PUBLIC') {
  5146. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  5147. $list [$key] ['category'] = $receivablesCategory [1];
  5148. }
  5149. }
  5150. // print_r($list);
  5151. $this->data ['category'] = $category;
  5152. $this->data ['timeType'] = $timeType;
  5153. $this->data ['MebSeaEn'] = $MebSea;
  5154. $this->data ['MebSea'] = urlencode ( $MebSea );
  5155. $this->data ['date'] = $date;
  5156. $this->data ['page'] = $pageinfo;
  5157. $this->data ['get'] = $get;
  5158. $this->data ['list'] = $list;
  5159. $this->data ['status'] = $status;
  5160. $this->data ['memu'] = "invoice";
  5161. $this->data ['staff'] = $this->staff;
  5162. $this->data ['receiptMemu'] = 'invoiceReceivables';
  5163. $this->render ( "/admin/invoiceReceivablesAS", $this->data );
  5164. }
  5165. /**
  5166. * 删除一条收款
  5167. */
  5168. function delInvoiceReceivables() {
  5169. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  5170. if (empty ( $iridKey ))
  5171. die ( 'illegal request' );
  5172. Doo::loadClass ( 'XDeode' );
  5173. $XDeode = new XDeode ( 5 );
  5174. $irid = $XDeode->decode ( $iridKey );
  5175. Doo::loadModel ( 'invoiceReceivables' );
  5176. $invoiceReceivables = new invoiceReceivables ();
  5177. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5178. if (empty ( $detail ))
  5179. die ( 'illegal request' );
  5180. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  5181. // 扣除收款汇总信息 汇总
  5182. Doo::loadModel ( 'invoiceStatistics' );
  5183. $invoiceStatistics = new invoiceStatistics ();
  5184. $item = array (
  5185. 'date' => $detail ['receivablesDate'],
  5186. 'priceClass' => 2,
  5187. 'irid' => $detail ['irid'],
  5188. 'receivablesPrice' => - $detail ['receivablesPrice']
  5189. );
  5190. if ($detail ['receivablesCategory'] != 'PUBLIC') {
  5191. $receivablesCategory = explode ( ":", $detail ['receivablesCategory'] );
  5192. $item += array (
  5193. 'cid' => $receivablesCategory [0]
  5194. );
  5195. }
  5196. if ($detail ['receivablesStaff'] != 'PUBLIC') {
  5197. $receivablesStaff = explode ( "-", $detail ['receivablesStaff'] );
  5198. $item += array (
  5199. 'staff' => $receivablesStaff [0]
  5200. );
  5201. }
  5202. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  5203. return '/invoiceReceivablesAS';
  5204. }
  5205. /**
  5206. * 添加退款信息
  5207. */
  5208. function setInvoiceReceivablesRefund() {
  5209. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5210. $refundType = $this->get_args ( 'refundType' ) && is_numeric ( $this->get_args ( 'refundType' ) ) ? $this->get_args ( 'refundType' ) : '0';
  5211. $refundCompany = $this->get_args ( 'refundCompany' ) ? $this->get_args ( 'refundCompany' ) : "";
  5212. $refundNumber = $this->get_args ( 'refundNumber' ) ? $this->get_args ( 'refundNumber' ) : "";
  5213. $refundPrice = $this->get_args ( 'refundPrice' ) ? $this->get_args ( 'refundPrice' ) : "";
  5214. $refundRemarks = $this->get_args ( 'refundRemarks' ) ? $this->get_args ( 'refundRemarks' ) : "";
  5215. if ($refundPrice < 0)
  5216. die ( 'illegal request' );
  5217. if (! empty ( $iridKey ) && ! empty ( $refundCompany ) && ! empty ( $refundNumber ) && ! empty ( $refundPrice )) {
  5218. Doo::loadModel ( 'invoiceReceivables' );
  5219. $invoiceReceivables = new invoiceReceivables ();
  5220. Doo::loadModel ( 'invoiceRefund' );
  5221. $invoiceRefund = new invoiceRefund ();
  5222. $irid = $invoiceReceivables->authcode ( $iridKey );
  5223. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5224. if ($irDetail ['receivablesPrice'] < $refundPrice)
  5225. die ( 'illegal request' );
  5226. $invoiceReceivables = new invoiceReceivables ();
  5227. $refundLog = $this->staff [0] ['username'] . ' 退款 <b class="colRed">¥' . $refundPrice . '</b>
  5228. <br/><a href="#refunded" onclick="getRefundByDetail(\'' . $iridKey . '\')" data-toggle="modal">退款信息</a> <br/>' . date ( "Y-m-d H:i:s" ) . '
  5229. ';
  5230. $item = array (
  5231. 'irid' => $irid,
  5232. 'refundCompany' => $refundCompany,
  5233. 'refundNumber' => $refundNumber,
  5234. 'refundPrice' => $refundPrice,
  5235. 'refundRemarks' => $refundRemarks,
  5236. 'refundLog' => $refundLog
  5237. );
  5238. if ($refundType == 1) {
  5239. $item += array (
  5240. 'refundType' => $refundType,
  5241. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice,
  5242. 'bindStatus' => 2
  5243. );
  5244. } elseif ($refundType == 0 && $irDetail ['receivablesPrice'] <= $refundPrice) {
  5245. $item += array (
  5246. 'refundType' => 1,
  5247. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice,
  5248. 'bindStatus' => 2
  5249. );
  5250. } else {
  5251. $item += array (
  5252. 'refundType' => $refundType,
  5253. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice
  5254. );
  5255. }
  5256. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  5257. // 添加退款记录
  5258. $item = array (
  5259. 'irid' => $irid,
  5260. 'refundType' => $refundType,
  5261. 'refundCompany' => $refundCompany,
  5262. 'refundNumber' => $refundNumber,
  5263. 'refundPrice' => $refundPrice,
  5264. 'refundLog' => $refundLog,
  5265. 'refundRemarks' => $refundRemarks,
  5266. 'date' => date ( "Y-m-d H:i:s" )
  5267. );
  5268. $invoiceRefund->addInvoiceRefund ( $item );
  5269. // 扣除收款汇总信息 汇总
  5270. Doo::loadModel ( 'invoiceStatistics' );
  5271. $invoiceStatistics = new invoiceStatistics ();
  5272. $item = array (
  5273. 'date' => $irDetail ['receivablesDate'],
  5274. 'priceClass' => 2,
  5275. 'irid' => $irDetail ['irid'],
  5276. 'receivablesPrice' => - $refundPrice
  5277. );
  5278. if ($irDetail ['receivablesCategory'] != 'PUBLIC') {
  5279. $receivablesCategory = explode ( ":", $irDetail ['receivablesCategory'] );
  5280. $item += array (
  5281. 'cid' => $receivablesCategory [0]
  5282. );
  5283. }
  5284. if ($irDetail ['receivablesStaff'] != 'PUBLIC') {
  5285. $receivablesStaff = explode ( "-", $irDetail ['receivablesStaff'] );
  5286. $item += array (
  5287. 'staff' => $receivablesStaff [0]
  5288. );
  5289. }
  5290. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  5291. // 公司日常支出流水
  5292. Doo::loadModel ( 'wasteBook' );
  5293. $wasteBook = new wasteBook ();
  5294. $accountBank = '';
  5295. if ($irDetail ['receivablesBank'] == '纵横广发') {
  5296. $accountBank = 'CGBDeposit';
  5297. } elseif ($irDetail ['receivablesBank'] == '纵横工行') {
  5298. $accountBank = 'ICBCDeposit';
  5299. } elseif ($irDetail ['receivablesBank'] == '华润银行') {
  5300. $accountBank = 'HUADeposit';
  5301. } elseif ($irDetail ['receivablesBank'] == '个人广发') {
  5302. $accountBank = 'PersonalDeposit';
  5303. }
  5304. $itemWaste = array (
  5305. 'accountPrice' => - $refundPrice,
  5306. 'expensesType' => 2,
  5307. 'accountType' => 11,
  5308. 'accountPriceShow' => $refundPrice,
  5309. 'dataID' => $irid,
  5310. 'accountBank' => $accountBank,
  5311. 'category' => $this->staff [0] ['category'],
  5312. 'cid' => $this->staff [0] ['cid'],
  5313. 'name' => $this->staff [0] ['username'],
  5314. 'sid' => $this->staff [0] ['sid'],
  5315. 'inputDate' => date ( "Y-m-d H:i:s" )
  5316. );
  5317. $wasteBook->setAccountBookStatistics ( $itemWaste );
  5318. return '/invoiceReceivablesAS';
  5319. }
  5320. die ( 'illegal request' );
  5321. }
  5322. function ajaxCheckInvoiceReceivablesRefund() {
  5323. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5324. $refundPrice = $this->get_args ( 'refundPrice' ) ? $this->get_args ( 'refundPrice' ) : "";
  5325. if ($refundPrice < 0) {
  5326. echo json_encode ( array (
  5327. 'error' => '金额不能为负'
  5328. ) );
  5329. die ();
  5330. }
  5331. if (! empty ( $refundPrice ) && ! empty ( $iridKey )) {
  5332. Doo::loadModel ( 'invoiceReceivables' );
  5333. $invoiceReceivables = new invoiceReceivables ();
  5334. $irid = $invoiceReceivables->authcode ( $iridKey );
  5335. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5336. if ($irDetail ['receivablesPrice'] < $refundPrice) {
  5337. echo json_encode ( array (
  5338. 'error' => '退款金额不能超过收款金额'
  5339. ) );
  5340. die ();
  5341. }
  5342. echo json_encode ( array (
  5343. 'ok' => '可以使用!'
  5344. ) );
  5345. die ();
  5346. }
  5347. }
  5348. /**
  5349. * 获得收款退款信息
  5350. */
  5351. function getRefundByDetail() {
  5352. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5353. Doo::loadModel ( 'invoiceReceivables' );
  5354. $invoiceReceivables = new invoiceReceivables ();
  5355. if (! empty ( $iridKey )) {
  5356. $irid = $invoiceReceivables->authcode ( $iridKey );
  5357. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5358. echo json_encode ( array (
  5359. 'status' => 1,
  5360. 'irDetail' => $irDetail
  5361. ) );
  5362. die ();
  5363. }
  5364. echo json_encode ( array (
  5365. 'status' => 2
  5366. ) );
  5367. }
  5368. /**
  5369. * 根据收款序列号获得收款退款信息
  5370. */
  5371. function ajaxGetInvoiceReceivablesBySerial() {
  5372. $receivablesSerial = $this->get_args ( 'receivablesSerial' ) ? $this->get_args ( 'receivablesSerial' ) : '';
  5373. if (! empty ( $receivablesSerial )) {
  5374. Doo::loadModel ( 'invoiceReceivables' );
  5375. $invoiceReceivables = new invoiceReceivables ();
  5376. // , ' and refundLog=""'
  5377. $irDetail = $invoiceReceivables->getInvoiceReceivablesBySerial ( $receivablesSerial );
  5378. $html = '';
  5379. if (! empty ( $irDetail ))
  5380. $html = '<td><b>¥' . $irDetail ['receivablesPrice'] . '</b></td>
  5381. <td>' . $irDetail ['receivablesMessage'] . '</td>
  5382. <td>' . $irDetail ['receivablesBank'] . '<br>' . $irDetail ['receivablesDate'] . '</td>
  5383. <td>' . $irDetail ['title'] . '-' . $irDetail ['username'] . '<br>' . $irDetail ['confirmTime'] . '</td>
  5384. <td>' . $irDetail ['recepitTitleMark'] . '
  5385. <input type="hidden" name="iridKey" id="iridKey" value="' . $irDetail ['iridKey'] . '">
  5386. </td>';
  5387. echo json_encode ( array (
  5388. 'status' => 1,
  5389. 'html' => $html,
  5390. 'irDetail' => $irDetail
  5391. ) );
  5392. die ();
  5393. }
  5394. echo json_encode ( array (
  5395. 'status' => 2
  5396. ) );
  5397. }
  5398. /**
  5399. * 绑定新收款
  5400. */
  5401. function relationNewInvoiceReceivables() {
  5402. $iridKeyOld = $this->get_args ( 'iridKeyOld' ) ? $this->get_args ( 'iridKeyOld' ) : '';
  5403. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5404. if (! empty ( $iridKeyOld ) && ! empty ( $iridKey )) {
  5405. Doo::loadModel ( 'invoiceReceivables' );
  5406. $invoiceReceivables = new invoiceReceivables ();
  5407. Doo::loadClass ( 'XDeode' );
  5408. $XDeode = new XDeode ( 5 );
  5409. $irid = $XDeode->decode ( $iridKey );
  5410. $iridOld = $invoiceReceivables->authcode ( $iridKeyOld );
  5411. echo $irid . 'bbb' . $iridOld;
  5412. $oldIrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $iridOld );
  5413. $IrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5414. if (empty ( $oldIrDetail ) || empty ( $IrDetail ))
  5415. die ( 'illegal request' );
  5416. $relationLog = $this->staff [0] ['username'] . ' 关联新款 <a href="#billing" onclick="invoiceReceivblesDivShow(\'' . $iridKey . '\',\'receivables\')" data-toggle="modal">' . $IrDetail ['receivablesSerial'] . '</a>
  5417. <br/>' . date ( "Y-m-d H:i:s" ) . '
  5418. ';
  5419. $invoiceReceivables = new invoiceReceivables ();
  5420. $item = array (
  5421. 'irid' => $iridOld,
  5422. 'relationIrid' => $irid,
  5423. 'relationLog' => $relationLog
  5424. );
  5425. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  5426. return '/invoiceReceivablesAS';
  5427. }
  5428. die ( 'illegal request' );
  5429. }
  5430. // function invoiceApprovalAchieve() {
  5431. // Doo::loadModel ( 'invoice' );
  5432. // $invoice = new invoice ();
  5433. // $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  5434. // $page_size = 12;
  5435. // $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5436. // $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  5437. // $get = "/" . $date;
  5438. // $con = '';
  5439. // if ($date == 'MONTHO')
  5440. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  5441. // elseif ($date == 'MONTHT')
  5442. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  5443. // elseif ($date == 'MONTHY')
  5444. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  5445. // if (! empty ( $MebSea )) {
  5446. // $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  5447. // $get .= "/" . $MebSea;
  5448. // }
  5449. // $pageinfo ['page'] = array (
  5450. // 'previous' => ''
  5451. // );
  5452. // $sql = '(status=1 or status=2 or status=3 or status=4) and processApprovals!=""' . $con; // echo $sql;
  5453. // $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", $get, "" );
  5454. // $limit = $pageinfo ['lower'] . ',' . $page_size;
  5455. // $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  5456. // // print_r($list);
  5457. // $this->data ['MebSeaEn'] = $MebSea;
  5458. // $this->data ['MebSea'] = urlencode ( $MebSea );
  5459. // $this->data ['get'] = $get;
  5460. // $this->data ['page'] = $pageinfo;
  5461. // $this->data ['list'] = $list;
  5462. // $this->data ['date'] = $date;
  5463. // $this->data ['memu'] = "invoice";
  5464. // $this->data ['staff'] = $this->staff;
  5465. // $this->data ['receiptMemu'] = 'invoiceApproval';
  5466. // $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  5467. // }
  5468. /**
  5469. * 获得审批发票的信息以及审批页面
  5470. */
  5471. function ajaxGetInvoiceApprovalDetail() {
  5472. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5473. if (empty ( $serial )) {
  5474. echo json_encode ( array (
  5475. 'status' => 2,
  5476. 'msg' => 'illegal request'
  5477. ) );
  5478. die ();
  5479. }
  5480. Doo::loadModel ( 'invoice' );
  5481. $invoice = new invoice ();
  5482. Doo::loadModel ( 'invoiceOperationLog' );
  5483. $invoiceOperationLog = new invoiceOperationLog ();
  5484. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5485. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5486. if (empty ( $detail ))
  5487. $html = '';
  5488. else {
  5489. $html = '
  5490. <form action="/invoiceApprovalDo" method="post" name="invoiceApproval" class="nice-validator n-yellow" novalidate="novalidate">
  5491. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  5492. <input type="hidden" name="status" value="">
  5493. <input type="hidden" name="divApproval" value="divApproval">
  5494. <div class="modal-dialog modal-lg">
  5495. <div class="modal-content"><div class="modal-header"><h3>发票审批详情</h3></div>
  5496. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  5497. <tr>
  5498. <th class="taC" width="150">发票审批</th><td><textarea name="opinion" style="width:98%" placeholder="在这写下您的审批意见,选填。"></textarea></td>
  5499. </tr>
  5500. <tr>
  5501. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5502. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5503. </tr>
  5504. <tr>
  5505. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5506. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5507. </tr>
  5508. <tr>
  5509. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5510. </td>
  5511. </tr>
  5512. <tr>
  5513. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5514. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5515. </tr>
  5516. <tr>
  5517. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5518. </tr></tbody></table>';
  5519. if ($detail ['invoiceType'] == 0)
  5520. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5521. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5522. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5523. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5524. </tr>';
  5525. else
  5526. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5527. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5528. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5529. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5530. ';
  5531. $html .= '<tr>
  5532. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5533. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5534. </tr>
  5535. <tr>
  5536. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5537. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5538. </tr></tbody></table>';
  5539. if ($detail ['doPost'] == 1) {
  5540. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5541. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5542. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5543. </tr><tr>
  5544. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5545. </tr><tr>
  5546. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5547. </tr>
  5548. ';
  5549. if ($detail ['expressCom'] == 'SF')
  5550. $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>';
  5551. else
  5552. $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>';
  5553. $html .= '</tbody></table>';
  5554. }
  5555. if (! empty ( $invoiceOperationLogList )) {
  5556. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  5557. foreach ( $invoiceOperationLogList as $key => $value ) {
  5558. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5559. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5560. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5561. if ($value ['status'] == 2) {
  5562. $html .= '<span class="colGreen">同意</span>';
  5563. } elseif ($value ['status'] == 3) {
  5564. $html .= '<span class="colOrange">退回</span>';
  5565. } elseif ($value ['status'] == 5) {
  5566. $html .= '<span class="colGreen">打印</span>';
  5567. } elseif ($value ['status'] == 4) {
  5568. $html .= '<span class="colRed">终止</span>';
  5569. }
  5570. $html .= $value ['operation'] . '</p></blockquote>';
  5571. }
  5572. }
  5573. $html .= '</td></tr></tbody></table>';
  5574. }
  5575. $html .= '</div><div class="modal-footer">
  5576. <a href="javascript:void(0)" node-approval="approval" diss-data="2" class="button btn-done" data-placement="top" data-toggle="ctooltip" >同意</a>
  5577. <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>
  5578. <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>
  5579. <a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>
  5580. </form>
  5581. <script type="text/javascript">
  5582. $("a[node-approval^=\'approval\']").click(function() {
  5583. $("input[name=\'status\']").val($(this).attr("diss-data"));
  5584. $("form[name=\'invoiceApproval\']").submit();
  5585. });
  5586. </script>
  5587. ';
  5588. }
  5589. echo json_encode ( array (
  5590. 'status' => 1,
  5591. 'html' => $html
  5592. ) );
  5593. die ();
  5594. }
  5595. /**
  5596. * 获得审批发票分页数据
  5597. */
  5598. function ajaxGetinvoiceApprovalAchieve() {
  5599. Doo::loadModel ( 'invoice' );
  5600. $invoice = new invoice ();
  5601. Doo::loadModel ( 'staff' );
  5602. $staff = new staff ();
  5603. Doo::loadClass ( 'XDeode' );
  5604. $XDeode = new XDeode ( 5 );
  5605. Doo::loadModel ( 'invoiceTraining' );
  5606. $invoiceTraining = new invoiceTraining ();
  5607. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  5608. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5609. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5610. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5611. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5612. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  5613. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  5614. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  5615. $MebSea = $this->get_args ( 'search' );
  5616. $MebSea = $MebSea ['value'];
  5617. $page_size = $length;
  5618. $con = '';
  5619. if ($status == 'ALL')
  5620. $con = ' (status=1 or status=2 or status=3 or status=4) and isDelete=0 ';
  5621. elseif ($status == 'PEND')
  5622. $con = ' isDelete=0 and status=1';
  5623. elseif ($status == 'APPROVED')
  5624. $con = ' isDelete=0 and status=2';
  5625. if ($invoiceType == 'ORDINARY')
  5626. $con .= ' and invoiceType=0 ';
  5627. elseif ($invoiceType == 'SPECIAL')
  5628. $con .= ' and invoiceType=1 ';
  5629. if ($invoiceTrain == 'ORDINARY')
  5630. $con .= ' and trainId=0 ';
  5631. elseif ($invoiceTrain == 'TRAIN')
  5632. $con .= ' and trainId!=0 ';
  5633. if ($invoiceTrainName != 'ALL') {
  5634. $trainId = $XDeode->decode ( $invoiceTrainName );
  5635. if (is_numeric ( $trainId ))
  5636. $con .= ' and trainId =' . $trainId;
  5637. }
  5638. $dateArr = explode ( ':', $date );
  5639. $D1 = $dateString = '';
  5640. $D2 = '';
  5641. if (! empty ( $date )) {
  5642. $D1 = $dateArr [0];
  5643. if (isset ( $dateArr [1] ))
  5644. $D2 = $dateArr [1];
  5645. else
  5646. $D2 = '';
  5647. $dateString = $D1 . " : " . $D2;
  5648. }
  5649. if (! empty ( $D1 ) && ! empty ( $D2 ))
  5650. $con .= ' and approvalTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  5651. elseif (! empty ( $D1 ) && empty ( $D2 ))
  5652. $con .= ' and approvalTime like "%' . $D1 . '%" ';
  5653. if (! empty ( $MebSea ))
  5654. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceSerial like "%' . $MebSea . '%" )';
  5655. // /
  5656. $pageinfo ['page'] = array (
  5657. 'previous' => ''
  5658. );
  5659. $sql = ' ' . $con;
  5660. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", '', "" );
  5661. $limit = $page . ',' . $page_size;
  5662. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  5663. $approvalList = array ();
  5664. $html = '<script type="text/javascript">
  5665. </script>';
  5666. // 结算结束不能修改方式
  5667. Doo::loadModel ( 'receipt' );
  5668. $receipt = new receipt ();
  5669. foreach ( $list as $key => $value ) {
  5670. $irDetail = array ();
  5671. // 结算方式
  5672. $receiptDetail = array ();
  5673. if ($value ['trainId'] != 0) {
  5674. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $value ['trainId'] );
  5675. }
  5676. if (! empty ( $receiptDetail )) {
  5677. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9) {
  5678. array_push ( $irDetail, '' );
  5679. } else {
  5680. if ($value ['status'] == 1 && $value ['pendingApprovals'] == $this->staff [0] ['sid']) {
  5681. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoiceApproval(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">审批发票</a>' );
  5682. } elseif ($value ['status'] == 2) {
  5683. array_push ( $irDetail, '<a href="#editPay" class="fnSettlementType" data-iidKey="' . $value ['iidKeyK'] . '" data-toggle="modal">结算方式</a>' );
  5684. } else
  5685. array_push ( $irDetail, '' );
  5686. }
  5687. } else {
  5688. if ($value ['status'] == 2) {
  5689. array_push ( $irDetail, '<a href="#editPay" class="fnSettlementType" data-iidKey="' . $value ['iidKeyK'] . '" data-toggle="modal">结算方式</a>' );
  5690. } else
  5691. array_push ( $irDetail, '' );
  5692. }
  5693. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  5694. if ($value ['invoiceType'] == 1)
  5695. array_push ( $irDetail, $value ['invoiceCompany'] );
  5696. else
  5697. array_push ( $irDetail, $value ['invoiceTitle'] );
  5698. array_push ( $irDetail, $value ['TIN'] );
  5699. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  5700. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  5701. array_push ( $irDetail, $value ['remark'] );
  5702. array_push ( $irDetail, $value ['invoiceElement'] );
  5703. array_push ( $irDetail, $value ['invoiceQuantity'] );
  5704. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  5705. if ($value ['invoiceType'] == 1) {
  5706. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  5707. } else {
  5708. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  5709. }
  5710. if ($value ['settlementType'] == 0) {
  5711. array_push ( $irDetail, '软件销售' );
  5712. } else {
  5713. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $value ['trainId'] );
  5714. array_push ( $irDetail, $itDetail ['trainName'] );
  5715. }
  5716. array_push ( $irDetail, $value ['recipients'] . $value ['recipientsPhone'] );
  5717. array_push ( $irDetail, $value ['recipientsAddress'] );
  5718. array_push ( $irDetail, $value ['mailItems'] );
  5719. array_push ( $irDetail, $value ['userName'] . '&nbsp;' . $value ['date'] );
  5720. $fchtml = $value ['OL'] ['operation'];
  5721. if (count ( $list ) == $page_size)
  5722. $fchtml = $value ['OL'] ['operation'] . $html;
  5723. // 最后的审批意见
  5724. array_push ( $irDetail, $fchtml );
  5725. if ($value ['status'] == 2)
  5726. array_push ( $irDetail, '<span class="colGreen">同意</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5727. elseif ($value ['status'] == 3)
  5728. array_push ( $irDetail, '<span class="colOrange">退回</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5729. elseif ($value ['status'] == 4)
  5730. array_push ( $irDetail, '<span class="colRed">终止</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5731. else
  5732. array_push ( $irDetail, '' );
  5733. array_push ( $approvalList, $irDetail );
  5734. }
  5735. // $approvalListJson = json_encode ( $approvalList );
  5736. $recordsFiltered = $pageinfo ['total_data'];
  5737. echo json_encode ( array (
  5738. "draw" => intval ( $draw ),
  5739. "recordsTotal" => intval ( $pageinfo ['total_data'] ),
  5740. "recordsFiltered" => intval ( $recordsFiltered ),
  5741. "data" => $approvalList
  5742. ), JSON_UNESCAPED_UNICODE );
  5743. }
  5744. /**
  5745. * 审批发票查看更多--重构
  5746. */
  5747. function invoiceApprovalAchieve() {
  5748. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'ALL';
  5749. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5750. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5751. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5752. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5753. Doo::loadModel ( 'invoiceTraining' );
  5754. $invoiceTraining = new invoiceTraining ();
  5755. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  5756. $this->data ['trainList'] = $trainList;
  5757. $this->data ['dateString'] = $date;
  5758. $this->data ['status'] = $status;
  5759. $this->data ['invoiceType'] = $invoiceType;
  5760. $this->data ['invoiceTrain'] = $invoiceTrain;
  5761. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  5762. $this->data ['memu'] = "invoice";
  5763. $this->data ['staff'] = $this->staff;
  5764. $this->data ['receiptMemu'] = 'invoiceApproval';
  5765. $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  5766. }
  5767. function invoiceTAchieve() {
  5768. Doo::loadModel ( 'invoice' );
  5769. $invoice = new invoice ();
  5770. Doo::loadClass ( 'XDeode' );
  5771. $XDeode = new XDeode ( 5 );
  5772. Doo::loadModel ( 'staff' );
  5773. $staff = new staff ();
  5774. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  5775. $page_size = 12;
  5776. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5777. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  5778. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5779. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5780. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5781. Doo::loadModel ( 'invoiceTraining' );
  5782. $invoiceTraining = new invoiceTraining ();
  5783. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  5784. $get = "/" . $date;
  5785. $con = '';
  5786. if ($date == 'MONTHO')
  5787. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  5788. elseif ($date == 'MONTHT')
  5789. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  5790. elseif ($date == 'MONTHY')
  5791. $con = ' and YEAR(updateTime) = YEAR(NOW())'; // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  5792. if ($invoiceType == 'ORDINARY')
  5793. $con .= ' and invoiceType=0 ';
  5794. elseif ($invoiceType == 'SPECIAL')
  5795. $con .= ' and invoiceType=1 ';
  5796. if ($invoiceTrain == 'ORDINARY')
  5797. $con .= ' and trainId=0 ';
  5798. elseif ($invoiceTrain == 'TRAIN')
  5799. $con .= ' and trainId!=0 ';
  5800. if ($invoiceTrainName != 'ALL') {
  5801. $trainId = $XDeode->decode ( $invoiceTrainName );
  5802. if (is_numeric ( $trainId ))
  5803. $con .= ' and trainId =' . $trainId;
  5804. }
  5805. if (! empty ( $MebSea )) {
  5806. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  5807. $get .= "/" . $MebSea;
  5808. }
  5809. $pageinfo ['page'] = array (
  5810. 'previous' => ''
  5811. );
  5812. $sql = "";
  5813. $action = "";
  5814. if ($this->ACTION == 'invoicePrintAchieve') {
  5815. $sql = "status=2 and printStatus=1 and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  5816. $action = "invoicePrintAchieve";
  5817. } elseif ($this->ACTION == 'invoicePostAchieve') {
  5818. // and untreadStatus=0
  5819. $sql = "postStatus=1 and doPost=1 and status=2 and isDelete=0" . $con;
  5820. $action = "invoicePostAchieve";
  5821. } elseif ($this->ACTION == 'invoiceUntreadAchieve') { // printStatus=1 and
  5822. $sql = " untreadStatus=2 and status=2 " . $con;
  5823. $action = "invoiceUntreadAchieve";
  5824. }
  5825. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  5826. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5827. $this->data ['MebSeaEn'] = $MebSea;
  5828. $this->data ['MebSea'] = urlencode ( $MebSea );
  5829. $this->data ['get'] = $get;
  5830. $this->data ['page'] = $pageinfo;
  5831. $this->data ['trainList'] = $trainList;
  5832. $this->data ['invoiceType'] = $invoiceType;
  5833. $this->data ['invoiceTrain'] = $invoiceTrain;
  5834. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  5835. $this->data ['date'] = $date;
  5836. $this->data ['memu'] = "invoice";
  5837. $this->data ['staff'] = $this->staff;
  5838. if ($this->ACTION == 'invoicePrintAchieve') {
  5839. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  5840. $this->data ['receiptMemu'] = 'invoicePrint';
  5841. $this->data ['list'] = $list;
  5842. $this->render ( "/admin/invoicePrintAchieve", $this->data );
  5843. } elseif ($this->ACTION == 'invoicePostAchieve') {
  5844. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  5845. Doo::loadModel ( 'express' );
  5846. $express = new express ();
  5847. $expressList = $express->getExpressByAll ();
  5848. $this->data ['expressList'] = $expressList;
  5849. $this->data ['receiptMemu'] = 'invoicePost';
  5850. $this->data ['list'] = $list;
  5851. $this->render ( "/admin/invoicePostAchieve", $this->data );
  5852. } elseif ($this->ACTION == 'invoiceUntreadAchieve') {
  5853. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  5854. $this->data ['receiptMemu'] = 'invoiceUntread';
  5855. $this->data ['list'] = $list;
  5856. $this->render ( "/admin/invoiceUntreadAchieve", $this->data );
  5857. }
  5858. }
  5859. /**
  5860. * 公司应收款
  5861. */
  5862. function invoiceAggregateCompanyDetail() {
  5863. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  5864. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  5865. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : 'ALL';
  5866. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  5867. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  5868. $titleORno = $this->get_args ( 'titleORno' ) ? $this->get_args ( 'titleORno' ) : "";
  5869. Doo::loadClass ( 'XDeode' );
  5870. $XDeode = new XDeode ( 5 );
  5871. Doo::loadModel ( 'invoice' );
  5872. $invoice = new invoice ();
  5873. Doo::loadModel ( 'staff' );
  5874. $staff = new staff ();
  5875. Doo::loadModel ( "invoiceCompanyManage" );
  5876. $invoiceCompanyManage = new invoiceCompanyManage ();
  5877. Doo::loadModel ( 'L_category' );
  5878. $category = new L_category ();
  5879. $sid = '';
  5880. if (! empty ( $sidKey )) {
  5881. $sid = $XDeode->decode ( $sidKey );
  5882. }
  5883. $staffDetail = $staff->getStaffBySid ( $sid );
  5884. $cid = '';
  5885. if (! empty ( $cidKey )) {
  5886. $cid = $XDeode->decode ( $cidKey );
  5887. }
  5888. $imcStaff = $invoiceCompanyManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  5889. $cidList = array ();
  5890. foreach ( $imcStaff as $key => $value ) {
  5891. array_push ( $cidList, $value ['cid'] );
  5892. }
  5893. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  5894. $cidString = implode ( ',', $cidList );
  5895. if (empty ( $cid ))
  5896. $staffList = $staff->getStaffInCid ( $cidString );
  5897. else
  5898. $staffList = $staff->getStaffByCidAll ( $cid ); //
  5899. //$MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  5900. $page_size = 25;
  5901. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5902. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  5903. $con = ' status=2 and untreadStatus!=2 ';
  5904. $statisticsCon = '';
  5905. if (! empty ( $year ) && is_numeric ( $year ))
  5906. $con .= ' and Year(printTime)=' . $year . '';
  5907. if (! empty ( $month ) && is_numeric ( $month ))
  5908. $con .= ' and Month(printTime)="' . $month . '" ';
  5909. if ($status == 'UNRECORD')
  5910. $con .= ' and printStatus=1 and untreadStatus=0';
  5911. elseif ($status == 'RECORD')
  5912. $con .= ' and printStatus=1 and untreadStatus=3';
  5913. elseif ($status == 'BOUNCED')
  5914. $con .= ' and untreadStatus=2';
  5915. elseif ($status == 'PARTRECORD')
  5916. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  5917. elseif ($status == 'All') {
  5918. $con .= ' and printStatus=1 and ( untreadStatus=0 or untreadStatus=3 )';
  5919. }
  5920. if (! empty ( $sid ) && is_numeric ( $sid ))
  5921. $con .= ' and sid=' . $sid;
  5922. if (! empty ( $cid ) && is_numeric ( $cid ))
  5923. $con .= ' and cid=' . $cid;
  5924. else
  5925. $con .= ' and cid in (' . $cidString . ')';
  5926. // 开票内容筛选
  5927. if (! empty ( $invoiceElement ) && $invoiceElement != 'ALL') {
  5928. $con .= ' and invoiceElement="' . $invoiceElement . '"';
  5929. }
  5930. $get = "/" . $status . "?cidKey=" . $cidKey . "&sidKey=" . $sidKey . "&year=" . $year . "&month=" . $month
  5931. . "&invoiceElement=" . $invoiceElement."&titleORno=".urlencode ( $titleORno );
  5932. if (! empty ( $titleORno )) {
  5933. $con .= ' and ( invoiceTitle like "%' . $titleORno . '%" or invoiceCompany like "%' . $titleORno . '%" or invoiceNo like "%'.$titleORno.'%" )';
  5934. }
  5935. $pageinfo ['page'] = array (
  5936. 'previous' => ''
  5937. );
  5938. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateCompanyDetail", $get, "" );
  5939. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5940. // 应收款合计
  5941. $ics = $invoice->getInvoiceCompanyStatistics ( $con );
  5942. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  5943. $monthHtml = "";
  5944. if ($year != "ALL") {
  5945. for($i = 1; $i <= 12; $i ++) {
  5946. if ($i == $month)
  5947. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  5948. else
  5949. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  5950. }
  5951. }
  5952. $this->data ['monthHtml'] = $monthHtml;
  5953. $this->data ['year'] = $year;
  5954. $this->data ['month'] = $month;
  5955. $this->data ['ics'] = $ics;
  5956. $this->data ['cidKey'] = $cidKey;
  5957. $this->data ['sid'] = $sid;
  5958. $this->data ['staffDetail'] = $staffDetail;
  5959. $this->data ['staffList'] = $staffList;
  5960. $this->data ['titleORnoEn'] = $titleORno;
  5961. $this->data ['titleORno'] = urlencode ( $titleORno );
  5962. $this->data ['invoiceDetail'] = array (
  5963. 'invoiceElement' => $invoiceElement
  5964. );
  5965. $this->data ['page'] = $pageinfo;
  5966. $this->data ['get'] = $get;
  5967. $this->data ['list'] = $list;
  5968. $this->data ['status'] = $status;
  5969. $this->data ['categoryList'] = $categoryList;
  5970. $this->data ['memu'] = "invoice";
  5971. $this->data ['staff'] = $this->staff;
  5972. $this->data ['receiptMemu'] = 'invoiceAggregateCompanyDetail';
  5973. $this->render ( "/admin/invoiceAggregateCompanyDetail", $this->data );
  5974. }
  5975. /**
  5976. * 获取一条收款信息
  5977. */
  5978. function ajaxGetInvoiceReceivables() {
  5979. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  5980. Doo::loadModel ( 'invoiceReceivables' );
  5981. $invoiceReceivables = new invoiceReceivables ();
  5982. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5983. echo json_encode ( array (
  5984. 'status' => 1,
  5985. 'detail' => $detail
  5986. ) );
  5987. }
  5988. /**
  5989. * 异步获取办事处用户
  5990. */
  5991. function ajaxGetStaffByCategory() {
  5992. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "";
  5993. Doo::loadModel ( 'staff' );
  5994. $staff = new staff ();
  5995. if ($cid == "PUBLIC") {
  5996. echo json_encode ( array (
  5997. 'status' => 1,
  5998. 'html' => '<option value="PUBLIC">办事处待认领款项</option>'
  5999. ) );
  6000. die ();
  6001. }
  6002. if (! is_numeric ( $cid )) {
  6003. echo json_encode ( array (
  6004. 'status' => 0,
  6005. 'msg' => 'illegal request'
  6006. ) );
  6007. die ();
  6008. }
  6009. $staffList = $staff->getStaffByCid ( $cid );
  6010. $html = '<option value="PUBLIC">办事处待认领款项</option>';
  6011. foreach ( $staffList as $key => $value ) {
  6012. $html .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  6013. }
  6014. echo json_encode ( array (
  6015. 'status' => 1,
  6016. 'html' => $html
  6017. ) );
  6018. }
  6019. /**
  6020. * 异步获取一条发票的邮寄信息
  6021. */
  6022. function ajaxGetInvoicePostDetail() {
  6023. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  6024. Doo::loadModel ( 'invoice' );
  6025. $invoice = new invoice ();
  6026. $iid = $invoice->authcode ( $iid );
  6027. Doo::loadModel ( 'express' );
  6028. $express = new express ();
  6029. $expressList = $express->getExpressByAll ();
  6030. if (! is_numeric ( $iid )) {
  6031. echo json_encode ( array (
  6032. 'status' => 0,
  6033. 'msg' => 'illegal request'
  6034. ) );
  6035. die ();
  6036. }
  6037. $select = "iid,recipients,recipientsPhone,recipientsAddress,mailItems,expressCompany,expressNumber,actualItems";
  6038. $invoiceDetail = $invoice->getInvoiceByIid ( $iid, $select );
  6039. $html = "";
  6040. foreach ( $expressList as $key => $value ) {
  6041. if ($value ['company'] == $invoiceDetail ['expressCompany'])
  6042. $html .= '<option selected value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  6043. else
  6044. $html .= '<option value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  6045. }
  6046. $invoiceDetail ['eaHtml'] = $html;
  6047. echo json_encode ( array (
  6048. 'status' => 1,
  6049. 'invoiceDetail' => $invoiceDetail
  6050. ) );
  6051. }
  6052. /**
  6053. *
  6054. * @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 ) ); }
  6055. */
  6056. /**
  6057. *
  6058. * @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 ) ); }
  6059. */
  6060. /**
  6061. * 我的收款中 选择哪个发票入账,进行金额判断
  6062. */
  6063. function ajaxCompareInvoicePrice() {
  6064. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  6065. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  6066. Doo::loadModel ( 'invoice' );
  6067. $invoice = new invoice ();
  6068. Doo::loadModel ( 'invoiceReceivables' );
  6069. $invoiceReceivables = new invoiceReceivables ();
  6070. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  6071. $keyList = explode ( ';', $claimKey );
  6072. $receivablesPrice = 0;
  6073. foreach ( $keyList as $key => $value ) {
  6074. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $value );
  6075. $receivablesPrice += $detailM ['receivablesPrice'];
  6076. }
  6077. if ($receivablesPrice > $detail ['invoicePrice']) {
  6078. $price = $receivablesPrice - $detail ['invoicePrice'];
  6079. echo json_encode ( array (
  6080. 'status' => 1,
  6081. 'price' => $price
  6082. ) );
  6083. } else
  6084. echo json_encode ( array (
  6085. 'status' => 2
  6086. ) );
  6087. }
  6088. /**
  6089. * 获得打印发票
  6090. */
  6091. function ajaxGetInvoiceInfoByPrint() {
  6092. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  6093. if (empty ( $serial )) {
  6094. echo json_encode ( array (
  6095. 'status' => 2,
  6096. 'msg' => 'illegal request'
  6097. ) );
  6098. die ();
  6099. }
  6100. Doo::loadModel ( 'invoice' );
  6101. $invoice = new invoice ();
  6102. Doo::loadModel ( 'invoiceOperationLog' );
  6103. $invoiceOperationLog = new invoiceOperationLog ();
  6104. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  6105. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  6106. Doo::loadModel ( 'invoicePaper' );
  6107. $invoicePaper = new invoicePaper ();
  6108. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $detail ['invoiceType'] );
  6109. if (empty ( $detail ))
  6110. $html = '';
  6111. else {
  6112. $html = '
  6113. <form action="/invoicePrintDo" method="post" name="invoicePrint" class="nice-validator n-yellow" onSubmit="return checkPrintForm()" novalidate="novalidate">
  6114. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  6115. <input type="hidden" name="invoicePrintType" value="invoicePrintType">
  6116. <div class="modal-dialog modal-lg">
  6117. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  6118. <div class="modal-body saeaList">
  6119. <table class="table table-bordered table-condensed"><tbody>
  6120. <tr>
  6121. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  6122. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  6123. </tr>
  6124. <tr>
  6125. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  6126. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  6127. </tr>
  6128. <tr>
  6129. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  6130. </td>
  6131. </tr>
  6132. <tr>
  6133. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  6134. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  6135. </tr>
  6136. <tr>
  6137. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  6138. </tr></tbody></table>';
  6139. if ($detail ['invoiceType'] == 0)
  6140. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6141. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  6142. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  6143. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  6144. </tr>';
  6145. else
  6146. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6147. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  6148. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  6149. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  6150. ';
  6151. $html .= '<tr>
  6152. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  6153. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  6154. </tr>
  6155. <tr>
  6156. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  6157. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  6158. </tr></tbody></table>';
  6159. if ($detail ['doPost'] == 1)
  6160. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  6161. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  6162. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  6163. </tr><tr>
  6164. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  6165. </tr><tr>
  6166. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  6167. </tr></tbody></table>';
  6168. if (! empty ( $invoiceOperationLogList )) {
  6169. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th><th class="taC">发票打印</th></tr><tr><td>';
  6170. foreach ( $invoiceOperationLogList as $key => $value ) {
  6171. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  6172. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  6173. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  6174. if ($value ['status'] == 2) {
  6175. $html .= '<span class="colGreen">同意</span>';
  6176. } elseif ($value ['status'] == 3) {
  6177. $html .= '<span class="colOrange">退回</span>';
  6178. } elseif ($value ['status'] == 5) {
  6179. $html .= '<span class="colGreen">打印</span>';
  6180. } elseif ($value ['status'] == 4) {
  6181. $html .= '<span class="colRed">终止</span>';
  6182. }
  6183. $html .= $value ['operation'] . '</p></blockquote>';
  6184. }
  6185. }
  6186. $html .= '</td>
  6187. <td><span class="colRed">*</span>
  6188. <select name="invoiceNo" id="invoiceNo" style="width:97%">';
  6189. foreach ( $invoicePaperList as $key => $value ) {
  6190. $html .= '<option value="' . $value ['ipidKey'] . '">No.' . $value ['invoiceNo'] . '</option>';
  6191. }
  6192. $html .= '</select>
  6193. <span class="red" id="p-msg"></span>
  6194. </td>
  6195. </tr></tbody></table>';
  6196. }
  6197. $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>
  6198. </div></div></form>
  6199. <link rel=stylesheet href="' . WEB_SITE_GLOBAL . 'css/jquery.validator.css">
  6200. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/jquery.validator.min.js"></script>
  6201. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/zh-CN.js"></script>
  6202. <script src="' . WEB_SITE_GLOBAL . 'js/invoice.validator.js"></script>
  6203. ';
  6204. }
  6205. echo json_encode ( array (
  6206. 'status' => 1,
  6207. 'html' => $html
  6208. ) );
  6209. die ();
  6210. }
  6211. /**
  6212. * @ 获得与我有关收款数据 --需求变更 废弃 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 ) ); }
  6213. */
  6214. function ajaxGetInvoiceInfoByType() {
  6215. $type = $this->get_args ( 'type' ) ? $this->get_args ( 'type' ) : "";
  6216. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  6217. $loss = $this->get_args ( 'loss' ) ? $this->get_args ( 'loss' ) : false;
  6218. if (empty ( $serial )) {
  6219. echo json_encode ( array (
  6220. 'status' => 2,
  6221. 'msg' => 'illegal request'
  6222. ) );
  6223. die ();
  6224. }
  6225. if ($type == 'INVOICE') {
  6226. Doo::loadModel ( 'invoice' );
  6227. $invoice = new invoice ();
  6228. Doo::loadModel ( 'invoiceOperationLog' );
  6229. $invoiceOperationLog = new invoiceOperationLog ();
  6230. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  6231. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  6232. if (empty ( $detail ))
  6233. $html = '';
  6234. else {
  6235. $html = '
  6236. <div class="modal-dialog modal-lg">
  6237. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  6238. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  6239. <tr>
  6240. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  6241. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  6242. </tr>
  6243. <tr>
  6244. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  6245. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  6246. </tr>
  6247. <tr>
  6248. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  6249. </td>
  6250. </tr>
  6251. <tr>
  6252. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  6253. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  6254. </tr>
  6255. <tr>
  6256. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  6257. </tr>';
  6258. if ($detail ['settlementType'] == 1)
  6259. $html .= '<tr>
  6260. <th class="taC" width="150">结算方式</th><td colspan="3">培训班(<a href="/invoiceTrainingDetail/' . $detail ['invoiceTraining'] ['trainingKey'] . '.html" target="_blank">' . $detail ['invoiceTraining'] ['trainName'] . '</a>)</td>
  6261. </tr>';
  6262. else
  6263. $html .= '<tr>
  6264. <th class="taC" width="150">结算方式</th><td colspan="3">软件销售</td>
  6265. </tr>';
  6266. $html .= ' </tbody></table>';
  6267. if ($detail ['invoiceType'] == 0){
  6268. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6269. <tr><th colspan="4" class="taC">增值税普通发票';
  6270. if($detail ['invoiceForm']==1){
  6271. $html .= '( <span class="colRed">电子发票</span> )';
  6272. }
  6273. $html .= '</th></tr><tr>
  6274. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  6275. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  6276. </tr>';
  6277. }else{
  6278. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6279. <tr><th colspan="4" class="taC">增值税专用发票';
  6280. if($detail ['invoiceForm']==1){
  6281. $html .= '( <span class="colRed">电子发票</span> )';
  6282. }
  6283. $html .= '</th></tr><tr>
  6284. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  6285. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  6286. ';
  6287. }
  6288. $html .= '<tr>
  6289. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  6290. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  6291. </tr>
  6292. <tr>
  6293. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  6294. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  6295. </tr></tbody></table>';
  6296. if ($detail ['doPost'] == 1) {
  6297. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  6298. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  6299. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  6300. </tr><tr>
  6301. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  6302. </tr><tr>
  6303. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  6304. </tr>
  6305. ';
  6306. if ($detail ['expressCom'] == 'SF')
  6307. $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>';
  6308. else
  6309. $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>';
  6310. $html .= '</tbody></table>';
  6311. }
  6312. if ($detail ['invoiceForm'] == 1) {
  6313. $html .= '<table class="table table-bordered table-condensed">
  6314. <tbody><tr><th colspan="4" class="taC">电子发票发送方式</th></tr>
  6315. <tr>
  6316. <th class="taC" width="150">收件人手机</th><td>'.$detail ['electronicPhone'].'</td>
  6317. <th class="taC" width="150">收件人邮箱</th><td>'.$detail ['electronicEmail'].'</td>
  6318. </tr></tbody></table>';
  6319. }
  6320. if (! empty ( $invoiceOperationLogList )) {
  6321. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  6322. foreach ( $invoiceOperationLogList as $key => $value ) {
  6323. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  6324. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  6325. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  6326. if ($value ['status'] == 2) {
  6327. $html .= '<span class="colGreen">同意</span>';
  6328. } elseif ($value ['status'] == 3) {
  6329. $html .= '<span class="colOrange">退回</span>';
  6330. } elseif ($value ['status'] == 5) {
  6331. $html .= '<span class="colGreen">打印</span>';
  6332. } elseif ($value ['status'] == 4) {
  6333. $html .= '<span class="colRed">终止</span>';
  6334. }
  6335. $html .= $value ['operation'] . '</p></blockquote>';
  6336. }
  6337. }
  6338. $html .= '</td></tr></tbody></table>';
  6339. }
  6340. $html .= '</div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  6341. }
  6342. echo json_encode ( array (
  6343. 'status' => 1,
  6344. 'html' => $html
  6345. ) );
  6346. die ();
  6347. } elseif ($type == 'RECEIVABLES') {
  6348. Doo::loadModel ( 'invoiceReceivables' );
  6349. $invoiceReceivables = new invoiceReceivables ();
  6350. Doo::loadModel ( 'invoiceRefund' );
  6351. $invoiceRefund = new invoiceRefund ();
  6352. $detail = $invoiceReceivables->getInvoiceReceivablesByIrsid ( $serial );
  6353. $ireList = $invoiceRefund->getInvoiceRefundIrid ( $detail ['irid'] );
  6354. if (empty ( $detail ))
  6355. $html = '';
  6356. else {
  6357. $html = '<div class="modal-dialog modal-lg"><div class="modal-content"><div class="modal-header"><h3>收款单详情</h3></div><div class="modal-body saeaList">
  6358. <table class="table table-bordered table-condensed">
  6359. <tbody><tr>
  6360. <th class="taC">收款流水号</th><td>' . $detail ['receivablesSerial'] . '</td>
  6361. <th class="taC">录入收款</th><td>' . $detail ['inputStaff'] . ' ' . $detail ['date'] . '</td>
  6362. </tr><tr>
  6363. <th class="taC">收款金额</th><td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  6364. <th class="taC">收款信息</th><td>' . $detail ['receivablesMessage'] . '</td>
  6365. </tr>
  6366. <tr>
  6367. <th class="taC">收款银行</th><td>' . $detail ['receivablesBank'] . '</td>
  6368. <th class="taC">银行到账</th><td>' . $detail ['receivablesDate'] . '</td>
  6369. </tr>
  6370. <tr>
  6371. <th class="taC">认领收款</th><td colspan="3">' . $detail ['inputStaff'] . ' 转入 ' . $detail ['username'] . ' ' . $detail ['confirmTime'] . '</td>
  6372. </tr>
  6373. </tbody></table>';
  6374. if (! empty ( $ireList )) {
  6375. $html .= '
  6376. <table class="table table-bordered table-condensed"><tbody><tr><th class="taC" colspan="5">退款记录</th></tr>
  6377. <tr>
  6378. <th class="taC">退款单位名称</th>
  6379. <th class="taC">退款的账号</th>
  6380. <th class="taC">退款金额</th>
  6381. <th class="taC">退款</th>
  6382. <th class="taC">备注</th>
  6383. </tr>
  6384. ';
  6385. foreach ( $ireList as $key => $value ) {
  6386. $refundLogList = explode ( "<br/>", $value ['refundLog'] );
  6387. $html .= '<tr>
  6388. <td>' . $value ['refundCompany'] . '</td>
  6389. <td>' . $value ['refundNumber'] . '</td>
  6390. <td><b class="colRed">¥' . $value ['refundPrice'] . '</b></td>
  6391. <td>' . $refundLogList [0] . $refundLogList [2] . '</td>
  6392. <td>' . $value ['refundRemarks'] . '</td>
  6393. </tr>
  6394. ';
  6395. }
  6396. }
  6397. $html .= '</tbody></table></div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  6398. }
  6399. echo json_encode ( array (
  6400. 'status' => 1,
  6401. 'html' => $html
  6402. ) );
  6403. die ();
  6404. } elseif ($type == 'IRTC') {
  6405. Doo::loadModel ( 'invoice' );
  6406. $invoice = new invoice ();
  6407. Doo::loadModel ( 'invoiceOperationLog' );
  6408. $invoiceOperationLog = new invoiceOperationLog ();
  6409. // Doo::loadModel ( 'invoiceReceivables' );
  6410. // $invoiceReceivables = new invoiceReceivables ();
  6411. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  6412. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  6413. if (empty ( $detail ))
  6414. $html = '';
  6415. else {
  6416. $receivablesPriceedHtml = '';
  6417. $receivablesPrice = $detail ['invoicePrice'];
  6418. if (! empty ( $detail ['irid'] )) {
  6419. // $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $detail ['irid'] );
  6420. // if (empty ( $irList ))
  6421. // $irList [0] ['sumPrice'] = 0;
  6422. // $balance = $detail ['invoicePrice'] - $irList [0] ['sumPrice'];
  6423. $enteredPrice=$detail ['invoicePrice']-$detail ['invoiceBalance'];
  6424. $receivablesPriceedHtml = '<table class="table table-bordered table-condensed"><tbody><tr>
  6425. <th class="taC">已入账金额</th><td><b class="colGreen" style="font-size:18px">¥' . $enteredPrice . '</b></td>
  6426. <th class="taC">剩余入账金额</th><td><b class="colRed" style="font-size:18px">¥' . $detail ['invoiceBalance'] . '</b></td>
  6427. </tr></tbody></table>';
  6428. $receivablesPrice = $detail ['invoiceBalance'];
  6429. }
  6430. if ($loss)
  6431. $detail ['invoicePrice'] = - $detail ['invoicePrice'];
  6432. $html = $receivablesPriceedHtml . '
  6433. <table class="table table-bordered table-condensed"><tbody>
  6434. <tr>
  6435. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  6436. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  6437. </tr>
  6438. <tr>
  6439. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  6440. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  6441. </tr>
  6442. <tr>
  6443. <th class="taC" width="150">发票备注</th><td colspan="3">' . $detail ['remark'] . '</td>
  6444. </tr>
  6445. <tr>
  6446. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  6447. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  6448. </tr>
  6449. <tr>
  6450. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  6451. </tr></tbody></table>';
  6452. if ($detail ['invoiceType'] == 0) {
  6453. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6454. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  6455. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  6456. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  6457. </tr>';
  6458. $receivablesMessage = $detail ['invoiceTitle'];
  6459. } else {
  6460. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6461. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  6462. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  6463. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  6464. ';
  6465. $receivablesMessage = $detail ['invoiceCompany'];
  6466. }
  6467. $html .= '<tr>
  6468. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  6469. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  6470. </tr>
  6471. <tr>
  6472. <th class="taC">开户银行</th><td>' . $detail ['bankAccount'] . '</td>
  6473. <th class="taC">银行账号</th><td>' . $detail ['bank'] . '</td>
  6474. </tr></tbody></table>';
  6475. if ($detail ['doPost'] == 1)
  6476. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  6477. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  6478. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  6479. </tr><tr>
  6480. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  6481. </tr><tr>
  6482. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  6483. </tr></tbody></table>';
  6484. if (! empty ( $invoiceOperationLogList )) {
  6485. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  6486. foreach ( $invoiceOperationLogList as $key => $value ) {
  6487. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  6488. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  6489. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  6490. if ($value ['status'] == 2) {
  6491. $html .= '<span class="colGreen">同意</span>';
  6492. } elseif ($value ['status'] == 3) {
  6493. $html .= '<span class="colOrange">退回</span>';
  6494. } elseif ($value ['status'] == 5) {
  6495. $html .= '<span class="colGreen">打印</span>';
  6496. }
  6497. $html .= $value ['operation'] . '</p></blockquote>';
  6498. }
  6499. }
  6500. $html .= '</td></tr></tbody></table>';
  6501. }
  6502. }
  6503. echo json_encode ( array (
  6504. 'status' => 1,
  6505. 'html' => $html,
  6506. 'receivablesPrice' => $receivablesPrice,
  6507. 'receivablesMessage' => $receivablesMessage,
  6508. 'receivablesDate' => date ( "Y-m-d" ),
  6509. 'iidKey' => $serial
  6510. ) );
  6511. die ();
  6512. }
  6513. }
  6514. function ajaxGetInvoiceReceivablesByStaff() {
  6515. $postData = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : "";
  6516. if (empty ( $postData )) {
  6517. echo json_encode ( array (
  6518. 'status' => 2,
  6519. 'msg' => 'illegal request'
  6520. ) );
  6521. die ();
  6522. }
  6523. Doo::loadModel ( 'invoiceReceivables' );
  6524. $invoiceReceivables = new invoiceReceivables ();
  6525. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $postData );
  6526. if (empty ( $detail )) {
  6527. echo json_encode ( array (
  6528. 'status' => 2,
  6529. 'msg' => 'illegal request'
  6530. ) );
  6531. die ();
  6532. }
  6533. Doo::loadModel ( 'L_category' );
  6534. $lCategory = new L_category ();
  6535. Doo::loadModel ( 'staff' );
  6536. $staff = new staff ();
  6537. $staffList = $staff->getStaffByCid ( $detail ['cid'] );
  6538. $category = $lCategory->getCategory ();
  6539. $categoryHtml = '<option post-data="PUBLIC" value="PUBLIC" >公共待认领款项</option>';
  6540. $staffHtml = '<option value="PUBLIC">办事处待认领款项</option>';
  6541. foreach ( $category as $key => $value ) {
  6542. $categoryHtml .= '<option post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  6543. if ($value ['cid'] == $detail ['cid'])
  6544. $categoryHtml .= '<option selected post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  6545. }
  6546. foreach ( $staffList as $key => $value ) {
  6547. $staffHtml .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  6548. if ($value ['sid'] == $detail ['sid'])
  6549. $staffHtml .= '<option selected value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  6550. }
  6551. $rbankHtml = '<option value="广发银行珠海分行柠溪支行">广发银行珠海分行柠溪支行</option>';
  6552. echo json_encode ( array (
  6553. 'status' => 1,
  6554. 'categoryHtml' => $categoryHtml,
  6555. 'staffHtml' => $staffHtml,
  6556. 'rbankHtml' => $rbankHtml,
  6557. 'detail' => $detail
  6558. ) );
  6559. }
  6560. function ajaxGetInvoiceReceivablesByIrid() {
  6561. $irid = $this->get_args ( 'irid' ) ? $this->get_args ( 'irid' ) : "";
  6562. if (empty ( $irid )) {
  6563. echo json_encode ( array (
  6564. 'status' => 2,
  6565. 'msg' => 'illegal request'
  6566. ) );
  6567. die ();
  6568. }
  6569. Doo::loadModel ( 'invoiceReceivables' );
  6570. $invoiceReceivables = new invoiceReceivables ();
  6571. Doo::loadModel ( 'invoice' );
  6572. $invoice = new invoice ();
  6573. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid ); // 入账完成 待定 and postStatus=1
  6574. $flag = true;
  6575. $invoiceDetail = $invoice->getInvoiceByTitle ( $detail ['recepitTitleMark'], 'EXACTLY', " and status=2 and printStatus=1 and untreadStatus=0 ", $flag ); //
  6576. $bakDetail = array ();
  6577. if ($flag === false) {
  6578. array_push ( $bakDetail, $invoiceDetail );
  6579. $invoiceDetail = $bakDetail;
  6580. }
  6581. $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>
  6582. <tr>
  6583. <td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  6584. <td>' . $detail ['receivablesMessage'] . '</td>
  6585. <td>' . $detail ['receivablesBank'] . '<br>' . $detail ['receivablesDate'] . '</td>
  6586. <td>' . $detail ['title'] . '-' . $detail ['username'] . '<br>' . $detail ['confirmTime'] . '</td>
  6587. <td>' . $detail ['recepitTitleMark'] . '</td>
  6588. </tr></tbody></table>';
  6589. $isInvoice = false;
  6590. $invoiceHtml = '';
  6591. if (empty ( $invoiceDetail )) {
  6592. $isInvoice = true;
  6593. } else {
  6594. $invoiceHtml = '<table class="table table-bordered table-condensed">
  6595. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody>';
  6596. foreach ( $invoiceDetail as $key => $value ) {
  6597. $invoiceHtml .= '<tr>';
  6598. if (! empty ( $value ['invoiceType'] )) {
  6599. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  6600. } else {
  6601. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  6602. }
  6603. if (! empty ( $value ['invoiceType'] )) {
  6604. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  6605. } else {
  6606. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  6607. }
  6608. $invoiceHtml .= '
  6609. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  6610. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  6611. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir" data-ikey="' . $value ['iidKey'] . '" href="javascript:void(0)">入账</a></td>
  6612. </tr>
  6613. ';
  6614. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  6615. if (empty ( $irList ))
  6616. $irList [0] ['sumPrice'] = 0;
  6617. $balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  6618. $priceString = '';
  6619. if ($balance < $detail ['receivablesPrice']) {
  6620. $priceString = '收款金额超过开票金额,';
  6621. }
  6622. if ($balance > $detail ['receivablesPrice']) {
  6623. $priceString = '收款金额低于开票金额,';
  6624. }
  6625. }
  6626. $invoiceHtml .= '
  6627. <script>
  6628. $(\'a[bind-receivables^="ir"]\').click(function() {
  6629. var data = $(this).attr("data-ikey");
  6630. $("input[name=\'invoiceKey\']").val(data);
  6631. var invoiceKey=data;
  6632. if(invoiceKey==""){
  6633. alert("入账错误,请重新刷新页面");
  6634. return false;
  6635. }
  6636. if(window.confirm("' . $priceString . '确定入账吗?")){
  6637. $("#IBR").submit();
  6638. }else{
  6639. return false;
  6640. }
  6641. });
  6642. </script>
  6643. ';
  6644. $invoiceHtml .= '</tbody></table>';
  6645. }
  6646. echo json_encode ( array (
  6647. 'status' => 1,
  6648. 'irkey' => $detail ['iridEn'],
  6649. 'receivablesHtml' => $receivablesHtml,
  6650. 'isInvoice' => $isInvoice,
  6651. 'invoiceHtml' => $invoiceHtml
  6652. ) );
  6653. }
  6654. function ajaxGetInvoiceReceivablesByTitle() {
  6655. $title = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  6656. if (empty ( $title )) {
  6657. echo json_encode ( array (
  6658. 'status' => 2,
  6659. 'msg' => 'illegal request'
  6660. ) );
  6661. die ();
  6662. }
  6663. Doo::loadModel ( 'invoice' );
  6664. $invoice = new invoice ();
  6665. $invoiceDetail = $invoice->getInvoiceByTitle ( $title, 'FUZZY', " and status=2 and printStatus=1 and untreadStatus=0 and (irid='' or irid is null) ", true );
  6666. $invoiceHtml = '';
  6667. if (! empty ( $invoiceDetail )) {
  6668. $invoiceHtml = '<table class="table table-bordered table-condensed">
  6669. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody><tr>';
  6670. foreach ( $invoiceDetail as $key => $value ) {
  6671. if (! empty ( $value ['invoiceType'] )) {
  6672. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  6673. } else {
  6674. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  6675. }
  6676. if (! empty ( $value ['invoiceType'] )) {
  6677. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  6678. } else {
  6679. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  6680. }
  6681. $invoiceHtml .= '
  6682. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  6683. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  6684. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir' . $value ['iidKeyXD'] . '" data-ikey="' . $value ['iidKey'] . '" href="#">入账</a></td>
  6685. </tr>
  6686. ';
  6687. }
  6688. $invoiceHtml .= '</tbody></table>
  6689. <script>
  6690. $(\'a[bind-receivables^="ir"]\').click(function() {
  6691. var data = $(this).attr("data-ikey");
  6692. $("input[name=\'invoiceKey\']").val(data);
  6693. var invoiceKey=$("input[name=\'invoiceKey\']").val();
  6694. if(invoiceKey==""){
  6695. alert("入账错误,请重新刷新页面");
  6696. return false;
  6697. }
  6698. if(window.confirm("确定入账吗?")){
  6699. $("#IBR").submit();
  6700. }else{
  6701. return false;
  6702. }
  6703. });
  6704. </script>
  6705. ';
  6706. }
  6707. echo json_encode ( array (
  6708. 'status' => 1,
  6709. 'invoiceHtml' => $invoiceHtml
  6710. ) );
  6711. }
  6712. function ajaxInvoicePushNotice() {
  6713. Doo::loadModel ( 'invoice' );
  6714. $invoice = new invoice ();
  6715. $approval = $invoice->getOne ( array (
  6716. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  6717. 'desc' => 'iid',
  6718. 'asArray' => true
  6719. ) );
  6720. $isNotice = false;
  6721. if (! empty ( $approval ))
  6722. $isNotice = true;
  6723. $response = array (
  6724. 'error' => 0,
  6725. 'isNotice' => $isNotice
  6726. );
  6727. echo json_encode ( $response );
  6728. exit ();
  6729. }
  6730. public function ajaxCheckInvoiceNoUniqueness() {
  6731. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  6732. Doo::loadModel ( 'invoice' );
  6733. $invoice = new invoice ();
  6734. if (! empty ( $invoiceNo )) {
  6735. Doo::loadModel ( 'invoicePaper' );
  6736. $invoicePaper = new invoicePaper ();
  6737. Doo::loadClass ( 'XDeode' );
  6738. $XDeode = new XDeode ( 5 );
  6739. $ipid = $XDeode->decode ( $invoiceNo );
  6740. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  6741. $info = $invoice->getOne ( array (
  6742. 'where' => "invoiceNo = '" . $paperDetail ['invoiceNo'] . "'",
  6743. 'asArray' => TRUE
  6744. ) );
  6745. if (! empty ( $info )) {
  6746. echo json_encode ( array (
  6747. 'error' => '发票号已存在'
  6748. ) );
  6749. die ();
  6750. } else
  6751. echo json_encode ( array (
  6752. 'ok' => '可以使用!'
  6753. ) );
  6754. die ();
  6755. }
  6756. }
  6757. function ajaxCheckInvoicePrice() {
  6758. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) && is_numeric ( $this->get_args ( 'receivablesPrice' ) ) ? $this->get_args ( 'receivablesPrice' ) : "";
  6759. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  6760. Doo::loadModel ( 'invoice' );
  6761. $invoice = new invoice ();
  6762. Doo::loadModel ( 'invoiceReceivables' );
  6763. $invoiceReceivables = new invoiceReceivables ();
  6764. Doo::loadClass ( 'XDeode' );
  6765. $XDeode = new XDeode ( 5 );
  6766. if (! empty ( $receivablesPrice ) && ! empty ( $iidKey )) {
  6767. $iidKey = $XDeode->decode ( $iidKey );
  6768. $info = $invoice->getInvoiceByIid ( $iidKey );
  6769. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $info ['irid'] );
  6770. if (empty ( $irList ))
  6771. $irList [0] ['sumPrice'] = 0;
  6772. $balance = $info ['invoicePrice'] - $irList [0] ['sumPrice'];
  6773. if ($balance < $receivablesPrice) {
  6774. echo json_encode ( array (
  6775. 'error' => '收款金额超过开票金额。'
  6776. ) );
  6777. die ();
  6778. }
  6779. if ($balance > $receivablesPrice) {
  6780. echo json_encode ( array (
  6781. 'error' => '收款金额低于开票金额。'
  6782. ) );
  6783. die ();
  6784. }
  6785. }
  6786. }
  6787. function ajaxGetInvoiceByNew() {
  6788. Doo::loadModel ( 'invoice' );
  6789. $invoice = new invoice ();
  6790. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );
  6791. echo json_encode ( array (
  6792. 'status' => 1,
  6793. 'detail' => $detail
  6794. ) );
  6795. }
  6796. /**
  6797. * 旧输入导入
  6798. */
  6799. function importInvoice() {
  6800. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  6801. $data ['emsg'] = "";
  6802. if ($emsg != "")
  6803. $data ['emsg'] = "请填写完整的数据";
  6804. $data ['time'] = time ();
  6805. $this->render ( "/admin/invoiceImport", $data );
  6806. }
  6807. function uploadInvoice() {
  6808. // move_uploaded_file($_FILES['Filedata']['tmp_name'], "/upload/".$_FILES['Filedata']['name']);
  6809. if (isset ( $_FILES ['Filedata'] ['name'] )) {
  6810. $file = $_FILES ['Filedata'] ['tmp_name'];
  6811. $error = false;
  6812. if (! is_uploaded_file ( $file )) {
  6813. $error = '400 Bad Request';
  6814. }
  6815. if ($error) {
  6816. header ( 'HTTP/1.0 ' . $error );
  6817. die ( 'Error ' . $error );
  6818. } else {
  6819. include (DOO::conf ()->SITE_PATH . 'protected/plugin/io.han.php');
  6820. $this->IoHandler = new IoHandler ();
  6821. $pics = explode ( '.', $_FILES ['Filedata'] ['name'] );
  6822. // $filedir=$_POST['time'];
  6823. // 调用定义物理路径
  6824. $t = DOO::conf ()->SITE_PATH . "upload/invoice/";
  6825. $this->IoHandler->MakeDir ( $t );
  6826. $filename = $this->_GetFileEXT ( $_FILES ['Filedata'] ['name'] );
  6827. if ($filename != 'xlsx')
  6828. return "";
  6829. // $upload_dir = $t."/".time().rand(10,100).".".$filename;
  6830. $upload_file = iconv ( "UTF-8", "GB2312", $_FILES ["Filedata"] ["name"] );
  6831. $upload_dir = $t . "/" . $upload_file;
  6832. $k = move_uploaded_file ( $file, $upload_dir );
  6833. if ($k) {
  6834. $m = round ( $_FILES ['Filedata'] ['size'] / 1024 / 1024, 2 );
  6835. echo $pics [0] . "." . $filename . "#" . $m . "#" . $_FILES ['Filedata'] ['size'];
  6836. }
  6837. }
  6838. }
  6839. }
  6840. function importInvoiceDo() {
  6841. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  6842. if ($path != "") {
  6843. Doo::loadModel ( 'invoice' );
  6844. Doo::loadModel ( 'staff' );
  6845. $staff = new staff ();
  6846. Doo::loadModel ( 'invoiceStatistics' );
  6847. Doo::loadModel ( 'invoiceOperationLog' );
  6848. echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  6849. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . $path );
  6850. // print_r ( $exlArray );
  6851. // die ();
  6852. // echo json_encode($exlArray);die;
  6853. foreach ( $exlArray as $key => $value ) {
  6854. // 开票
  6855. $invoice = new invoice ();
  6856. $invoice->invoiceNo = $value ['invoiceNo'];
  6857. $invoice->invoiceType = 0;
  6858. if ($value ['invoiceType'] == '专')
  6859. $invoice->invoiceType = 1;
  6860. $invoice->invoicePrice = $value ['invoicePrice'];
  6861. $invoice->invoiceQuantity = 1;
  6862. $invoice->invoiceUnitPrice = $value ['invoicePrice'];
  6863. $invoice->invoiceTitle = $value ['invoiceTitle'];
  6864. if ($value ['invoiceType'] == '专')
  6865. $invoice->invoiceCompany = $value ['invoiceTitle'];
  6866. $invoice->userName = $value ['userName'];
  6867. $sDetail = $staff->getStaffByName ( $value ['userName'] );
  6868. $invoice->sid = $sDetail ['sid'];
  6869. $invoice->cid = $sDetail ['cid'];
  6870. $invoice->categoryName = $sDetail ['category'];
  6871. $invoice->invoiceElement = $value ['invoiceElement'];
  6872. $invoice->remark = $value ['remark'];
  6873. $invoice->date = $value ['date'];
  6874. $invoice->printTime = $value ['date'];
  6875. $invoice->ipSource = 1;
  6876. $invoice->printStatus = 1;
  6877. $invoice->status = 2;
  6878. $invoice->postStatus = 1;
  6879. $invoice->untreadStatus = 0;
  6880. $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  6881. $iid = $invoice->insert ();
  6882. // 汇总
  6883. $invoiceStatistics = new invoiceStatistics ();
  6884. //
  6885. $item = array (
  6886. 'date' => $value ['date'],
  6887. 'priceClass' => 1,
  6888. 'cid' => $sDetail ['cid'],
  6889. 'staff' => $sDetail ['sid'],
  6890. 'invoicePrice' => $value ['invoicePrice']
  6891. );
  6892. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  6893. $invoiceOperationLog = new invoiceOperationLog ();
  6894. $item = array (
  6895. 'date' => date ( "Y-m-d H:i:s" ),
  6896. 'operation' => date ( "Y-m-d" ) . " 导入",
  6897. 'status' => 1,
  6898. 'img' => $sDetail ['avatar'],
  6899. 'username' => $sDetail ['username'],
  6900. 'uid' => $sDetail ['sid'],
  6901. 'category' => $sDetail ['category'],
  6902. 'iid' => $iid
  6903. );
  6904. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  6905. }
  6906. return '/importInvoice?count=' . count ( $exlArray );
  6907. // return "/keyonline";
  6908. }
  6909. echo 'no file';
  6910. }
  6911. function importInvoiceReceivables() {
  6912. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  6913. $data ['emsg'] = "";
  6914. if ($emsg != "")
  6915. $data ['emsg'] = "请填写完整的数据";
  6916. $data ['time'] = time ();
  6917. $this->render ( "/admin/invoiceReceivablesImport", $data );
  6918. }
  6919. // 导入入账数据
  6920. function importInvoiceReceivablesDo() {
  6921. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  6922. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  6923. if ($path != "") {
  6924. Doo::loadModel ( 'invoiceReceivables' );
  6925. Doo::loadModel ( 'invoice' );
  6926. Doo::loadModel ( 'staff' );
  6927. $staff = new staff ();
  6928. Doo::loadModel ( 'invoiceStatistics' );
  6929. // echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  6930. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path ), 'invoiceReceivables' );
  6931. // print_r ( $exlArray );
  6932. // die ();
  6933. // echo json_encode($exlArray);die;
  6934. foreach ( $exlArray as $key => $value ) {
  6935. // 收款
  6936. $invoiceReceivables = new invoiceReceivables ();
  6937. $invoice = new invoice ();
  6938. $invoiceReceivables->bindStatus = 1;
  6939. $invoiceReceivables->receivablesPrice = $value ['receivablesPrice'];
  6940. $invoiceReceivables->receivablesMessage = $value ['receivablesMessage'];
  6941. $invoiceReceivables->receivablesBank = $value ['receivablesBank'];
  6942. $invoiceReceivables->receivablesDate = $value ['receivablesDate'];
  6943. $sDetail = $staff->getStaffByName ( $value ['receivablesStaff'] );
  6944. $invoiceReceivables->receivablesCategory = $sDetail ['cid'] . ':' . $sDetail ['category'];
  6945. $invoiceReceivables->receivablesStaff = $sDetail ['sid'] . '-' . $sDetail ['username'];
  6946. $invoiceReceivables->receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  6947. $invoiceReceivables->sourcePrice = $value ['sourcePrice'];
  6948. $iDetail = $invoice->getInvoiceByInvoiceNo ( $value ['invoiceNo'] );
  6949. $invoiceReceivables->iid = $iDetail ['iid'];
  6950. $irid = $invoiceReceivables->insert ();
  6951. // 发票绑定收款
  6952. $detail = $iDetail;
  6953. $iridString = "";
  6954. if (empty ( $detail ['irid'] ))
  6955. $iridString = $irid;
  6956. else
  6957. $iridString = $detail ['irid'] . ',' . $irid;
  6958. $item = array (
  6959. 'irid' => $iridString,
  6960. 'iid' => $detail ['iid']
  6961. );
  6962. $invoice->setInvoiceByCondition ( $item );
  6963. // 汇总
  6964. $invoiceStatistics = new invoiceStatistics ();
  6965. // 扣除入账统计金额
  6966. $item = array (
  6967. 'date' => $value ['receivablesDate'],
  6968. 'priceClass' => 3,
  6969. 'cid' => $sDetail ['cid'],
  6970. 'staff' => $sDetail ['sid'],
  6971. // 'irid' => $irid,
  6972. 'accountPrice' => $value ['receivablesPrice']
  6973. );
  6974. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  6975. }
  6976. return '/importInvoiceReceivables?count=' . count ( $exlArray );
  6977. echo 'data count ' . count ( $exlArray );
  6978. die ();
  6979. // return "/keyonline";
  6980. }
  6981. echo 'no file';
  6982. }
  6983. function formatExcelToArrayTrain($file_url = "") {
  6984. if (! file_exists ( $file_url )) {
  6985. return array ();
  6986. }
  6987. // Doo::loadClass ( 'PHPExcel' );
  6988. Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  6989. $PHPExcel = new PHPExcel ();
  6990. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  6991. if (! $PHPReader->canRead ( $file_url )) {
  6992. $PHPReader = new PHPExcel_Reader_Excel5 ();
  6993. if (! $PHPReader->canRead ( $file_url )) {
  6994. echo 'no Excel';
  6995. return;
  6996. }
  6997. }
  6998. $PHPExcel = $PHPReader->load ( $file_url );
  6999. /* * 读取excel文件中的第一个工作表 */
  7000. $currentSheet = $PHPExcel->getSheet ( 0 );
  7001. /* * 取得最大的列号 */
  7002. $allColumn = $currentSheet->getHighestColumn ();
  7003. /* * 取得一共有多少行 */
  7004. $allRow = $currentSheet->getHighestRow ();
  7005. $excel_array = array ();
  7006. // die($file_url);
  7007. $conk = 2;
  7008. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  7009. $excel_column = array ();
  7010. // 后期改进
  7011. if ($allColumn == 'AM')
  7012. $allColumn = 'Z';
  7013. /* * 从第A列开始输出 */
  7014. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  7015. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  7016. if ($val instanceof PHPExcel_RichText)
  7017. $val = $val->__toString ();
  7018. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  7019. // $val = "'" . addslashes ( $val ) . "'";
  7020. if ($currentColumn == 'A') {
  7021. $excel_column ['invoiceTitle'] = $val;
  7022. } elseif ($currentColumn == 'B')
  7023. $excel_column ['invoiceType'] = $val;
  7024. elseif ($currentColumn == 'C') {
  7025. $excel_column ['TIN'] = $val;
  7026. } elseif ($currentColumn == 'D') {
  7027. $excel_column ['address'] = $val;
  7028. } elseif ($currentColumn == 'E') {
  7029. $excel_column ['phone'] = $val;
  7030. } elseif ($currentColumn == 'F') {
  7031. $excel_column ['bank'] = $val;
  7032. } elseif ($currentColumn == 'G') {
  7033. $excel_column ['bankAccount'] = $val;
  7034. } elseif ($currentColumn == 'H') {
  7035. $excel_column ['invoiceElement'] = $val;
  7036. } elseif ($currentColumn == 'I') {
  7037. $excel_column ['invoiceQuantity'] = $val;
  7038. } elseif ($currentColumn == 'J') {
  7039. $excel_column ['invoiceUnitPrice'] = $val;
  7040. } elseif ($currentColumn == 'K') {
  7041. $excel_column ['remark'] = $val;
  7042. } elseif ($currentColumn == 'L') {
  7043. $excel_column ['recipientsAddress'] = $val;
  7044. } elseif ($currentColumn == 'M') {
  7045. $excel_column ['recipients'] = $val;
  7046. } elseif ($currentColumn == 'N') {
  7047. $excel_column ['recipientsPhone'] = $val;
  7048. }elseif ($currentColumn == 'O') {
  7049. $excel_column ['electronicPhone'] = $val;
  7050. } elseif ($currentColumn == 'P') {
  7051. $excel_column ['electronicEmail'] = $val;
  7052. }
  7053. }
  7054. if (! empty ( $excel_column ['invoiceTitle'] ) && ! empty ( $excel_column ['invoiceQuantity'] ) && ! empty ( $excel_column ['invoiceUnitPrice'] ))
  7055. array_push ( $excel_array, $excel_column );
  7056. }
  7057. return $excel_array;
  7058. }
  7059. /**
  7060. * 格式化excel文件为数组
  7061. * @param unknown_type $file_url
  7062. * @param unknown_type $mcid
  7063. */
  7064. function _format_excel_to_array($file_url = "", $sType = "") {
  7065. if (! file_exists ( $file_url )) {
  7066. return array ();
  7067. }
  7068. Doo::loadClass ( 'PHPExcel' );
  7069. // Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  7070. $PHPExcel = new PHPExcel ();
  7071. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  7072. if (! $PHPReader->canRead ( $file_url )) {
  7073. $PHPReader = new PHPExcel_Reader_Excel5 ();
  7074. if (! $PHPReader->canRead ( $file_url )) {
  7075. echo 'no Excel';
  7076. return;
  7077. }
  7078. }
  7079. $PHPExcel = $PHPReader->load ( $file_url );
  7080. /* * 读取excel文件中的第一个工作表 */
  7081. $currentSheet = $PHPExcel->getSheet ( 0 );
  7082. /* * 取得最大的列号 */
  7083. $allColumn = $currentSheet->getHighestColumn ();
  7084. /* * 取得一共有多少行 */
  7085. $allRow = $currentSheet->getHighestRow ();
  7086. $excel_array = array ();
  7087. // die($file_url);
  7088. $conk = 2;
  7089. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  7090. $excel_column = array ();
  7091. // 后期改进
  7092. if ($allColumn == 'AM')
  7093. $allColumn = 'Z';
  7094. /* * 从第A列开始输出 */
  7095. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  7096. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  7097. if ($val instanceof PHPExcel_RichText)
  7098. $val = $val->__toString ();
  7099. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  7100. // $val = "'" . addslashes ( $val ) . "'";
  7101. if ($sType == 'invoiceReceivables') {
  7102. if ($currentColumn == 'A')
  7103. $excel_column ['invoiceNo'] = $val;
  7104. elseif ($currentColumn == 'B')
  7105. $excel_column ['receivablesPrice'] = $val;
  7106. elseif ($currentColumn == 'C') {
  7107. $excel_column ['receivablesMessage'] = $val;
  7108. } elseif ($currentColumn == 'D') {
  7109. $excel_column ['receivablesBank'] = $val;
  7110. } elseif ($currentColumn == 'E') {
  7111. $excel_column ['receivablesDate'] = $this->excelTime ( $val );
  7112. } elseif ($currentColumn == 'F') {
  7113. $excel_column ['receivablesStaff'] = $val;
  7114. } elseif ($currentColumn == 'G') {
  7115. $excel_column ['sourcePrice'] = $val;
  7116. }
  7117. } elseif ($sType == "invoiceTrain") {
  7118. if ($currentColumn == 'A') {
  7119. $excel_column ['invoiceTitle'] = $val;
  7120. } elseif ($currentColumn == 'B')
  7121. $excel_column ['invoiceType'] = $val;
  7122. elseif ($currentColumn == 'C') {
  7123. $excel_column ['TIN'] = $val;
  7124. } elseif ($currentColumn == 'D') {
  7125. $excel_column ['address'] = $val;
  7126. } elseif ($currentColumn == 'E') {
  7127. $excel_column ['phone'] = $val;
  7128. } elseif ($currentColumn == 'F') {
  7129. $excel_column ['bank'] = $val;
  7130. } elseif ($currentColumn == 'G') {
  7131. $excel_column ['bankAccount'] = $val;
  7132. } elseif ($currentColumn == 'H') {
  7133. $excel_column ['invoiceElement'] = $val;
  7134. } elseif ($currentColumn == 'I') {
  7135. $excel_column ['invoiceQuantity'] = $val;
  7136. } elseif ($currentColumn == 'J') {
  7137. $excel_column ['invoiceUnitPrice'] = $val;
  7138. } elseif ($currentColumn == 'K') {
  7139. $excel_column ['remark'] = $val;
  7140. } elseif ($currentColumn == 'L') {
  7141. $excel_column ['recipientsAddress'] = $val;
  7142. } elseif ($currentColumn == 'M') {
  7143. $excel_column ['recipients'] = $val;
  7144. } elseif ($currentColumn == 'N') {
  7145. $excel_column ['recipientsPhone'] = $val;
  7146. }
  7147. } else {
  7148. if ($currentColumn == 'A')
  7149. $excel_column ['invoiceNo'] = $val;
  7150. elseif ($currentColumn == 'B')
  7151. $excel_column ['invoiceType'] = $val;
  7152. elseif ($currentColumn == 'C') {
  7153. $excel_column ['invoicePrice'] = $val;
  7154. } elseif ($currentColumn == 'D') {
  7155. $excel_column ['invoiceTitle'] = $val;
  7156. } elseif ($currentColumn == 'E') {
  7157. $excel_column ['userName'] = $val;
  7158. } elseif ($currentColumn == 'F') {
  7159. $excel_column ['categoryName'] = $val;
  7160. } elseif ($currentColumn == 'G') {
  7161. $excel_column ['invoiceElement'] = $val;
  7162. } elseif ($currentColumn == 'H') {
  7163. $excel_column ['remark'] = $val;
  7164. } elseif ($currentColumn == 'I') {
  7165. $excel_column ['date'] = $this->excelTime ( $val );
  7166. }
  7167. }
  7168. }
  7169. array_push ( $excel_array, $excel_column );
  7170. }
  7171. return $excel_array;
  7172. }
  7173. function excelTime($date, $time = false) {
  7174. if (function_exists ( 'GregorianToJD' )) {
  7175. if (is_numeric ( $date )) {
  7176. $jd = GregorianToJD ( 1, 1, 1970 );
  7177. $gregorian = JDToGregorian ( $jd + intval ( $date ) - 25569 );
  7178. $date = explode ( '/', $gregorian );
  7179. $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" : '');
  7180. return $date_str;
  7181. }
  7182. } else {
  7183. $date = $date > 25568 ? $date + 1 : 25569;
  7184. /* There was a bug if Converting date before 1-1-1970 (tstamp 0) */
  7185. $ofs = (70 * 365 + 17 + 2) * 86400;
  7186. $date = date ( "Y-m-d", ($date * 86400) - $ofs ) . ($time ? " 00:00:00" : '');
  7187. }
  7188. return $date;
  7189. }
  7190. /**
  7191. * 旧输入导入
  7192. */
  7193. function _GetFileEXT($filename) {
  7194. $pics = explode ( '.', $filename );
  7195. $num = count ( $pics );
  7196. return $pics [$num - 1];
  7197. }
  7198. function showCache($path = "", $sid = 0) {
  7199. // if (file_exists ( $path )) {
  7200. // $htm = file_get_contents ( $path );
  7201. // } else {
  7202. Doo::loadModel ( 'invoiceStatistics' );
  7203. $invoiceStatistics = new invoiceStatistics ();
  7204. $isBriefly = $invoiceStatistics->getBrieflyStatistics ( $sid );
  7205. $htm = '<tr><th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计开票</th>
  7206. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['invoicePrice'] . '</td>
  7207. <th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计入账</th>
  7208. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['accountPrice'] . '</td></tr>';
  7209. /*
  7210. * '<tr><th class="taC">今年累计开票</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['invoicePrice'] . '</td> <th class="taC">今年累计入账</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['accountPrice'] . '</td></tr>';
  7211. */
  7212. file_put_contents ( $path, $htm );
  7213. // }
  7214. return $htm;
  7215. }
  7216. /**
  7217. * 生成token
  7218. * @return string
  7219. */
  7220. function set_token() {
  7221. $str = md5 ( uniqid ( md5 ( microtime ( true ) ), true ) ); // 生成一个不会重复的字符串
  7222. $str = sha1 ( $str ); // 加密
  7223. return $str;
  7224. }
  7225. /**
  7226. * 获取get或者POST值
  7227. *
  7228. * @param string $name 属性名称
  7229. * @return fixed 值
  7230. */
  7231. function get_args($name) {
  7232. if (isset ( $_GET [$name] )) {
  7233. if (is_array ( $_GET [$name] ))
  7234. return $_GET [$name];
  7235. else
  7236. return addslashes ( $_GET [$name] );
  7237. } elseif (isset ( $_POST [$name] )) {
  7238. if (is_array ( $_POST [$name] ))
  7239. return $_POST [$name];
  7240. else
  7241. return addslashes ( $_POST [$name] );
  7242. } else
  7243. return false;
  7244. }
  7245. function SafeFilter(&$arr) {
  7246. $ra = Array (
  7247. '/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/',
  7248. '/script/',
  7249. '/javascript/',
  7250. '/vbscript/',
  7251. '/expression/',
  7252. '/applet/',
  7253. '/meta/',
  7254. '/xml/',
  7255. '/blink/',
  7256. '/link/',
  7257. '/style/',
  7258. '/embed/',
  7259. '/object/',
  7260. '/frame/',
  7261. '/layer/',
  7262. '/title/',
  7263. '/bgsound/',
  7264. '/base/',
  7265. '/onload/',
  7266. '/onunload/',
  7267. '/onchange/',
  7268. '/onsubmit/',
  7269. '/onreset/',
  7270. '/onselect/',
  7271. '/onblur/',
  7272. '/onfocus/',
  7273. '/onabort/',
  7274. '/onkeydown/',
  7275. '/onkeypress/',
  7276. '/onkeyup/',
  7277. '/onclick/',
  7278. '/ondblclick/',
  7279. '/onmousedown/',
  7280. '/onmousemove/',
  7281. '/onmouseout/',
  7282. '/onmouseover/',
  7283. '/onmouseup/',
  7284. '/onunload/'
  7285. );
  7286. if (is_array ( $arr )) {
  7287. foreach ( $arr as $key => $value ) {
  7288. if (! is_array ( $value )) {
  7289. if (! get_magic_quotes_gpc ()) // 不对magic_quotes_gpc转义过的字符使用addslashes(),避免双重转义。
  7290. {
  7291. $value = addslashes ( $value ); // 给单引号(')、双引号(")、反斜线(\)与 NUL(NULL 字符)加上反斜线转义
  7292. }
  7293. $value = preg_replace ( $ra, '', $value ); // 删除非打印字符,粗暴式过滤xss可疑字符串
  7294. $arr [$key] = htmlentities ( strip_tags ( $value ) ); // 去除 HTML 和 PHP 标记并转换为 HTML 实体
  7295. } else {
  7296. SafeFilter ( $arr [$key] );
  7297. }
  7298. }
  7299. }
  7300. }
  7301. /**
  7302. * Escape String
  7303. *
  7304. * @access public
  7305. * @param string
  7306. * @param bool whether or not the string will be used in a LIKE condition
  7307. * @return string
  7308. */
  7309. function escape_str($str, $like = FALSE) {
  7310. if (is_array ( $str )) {
  7311. foreach ( $str as $key => $val ) {
  7312. $str [$key] = $this->escape_str ( $val, $like );
  7313. }
  7314. return $str;
  7315. }
  7316. var_dump ( Doo::db ()->getDbObject () );
  7317. die ();
  7318. if (function_exists ( 'mysql_real_escape_string' ) and is_resource ( Doo::db ()->getDbObject () )) { // Doo::db ()->getDbObject()
  7319. $str = mysql_real_escape_string ( $str, Doo::db ()->getDbObject () );
  7320. } elseif (function_exists ( 'mysql_escape_string' )) {
  7321. $str = mysql_escape_string ( $str );
  7322. } else {
  7323. $str = addslashes ( $str );
  7324. }
  7325. // escape LIKE condition wildcards
  7326. if ($like === TRUE) {
  7327. $str = str_replace ( array (
  7328. '%',
  7329. '_'
  7330. ), array (
  7331. '\\%',
  7332. '\\_'
  7333. ), $str );
  7334. }
  7335. return $str;
  7336. }
  7337. /**
  7338. * 获得分页数据
  7339. * @param unknown_type $table
  7340. * @param unknown_type $condition
  7341. * @param unknown_type $on_page
  7342. * @param unknown_type $page_size
  7343. */
  7344. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  7345. $page_c = "";
  7346. $page ['previous'] = $this->get_previous ( $on_page );
  7347. $page ['on_page'] = $on_page;
  7348. $total_count = $this->get_table_count ( $table, $condition );
  7349. $total = intval ( $total_count / $page_size );
  7350. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  7351. $page ['total_data'] = $total_count;
  7352. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  7353. $i = 1;
  7354. $page_max = 1;
  7355. $page_width = 3;
  7356. if ($on_page >= $page_width) {
  7357. $page_max = intval ( $on_page / $page_width ) + 1;
  7358. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  7359. }
  7360. for(; $i <= $page ['total_page']; $i ++) {
  7361. if ($i == $on_page)
  7362. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  7363. else
  7364. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  7365. if ($i == ($page_width * $page_max))
  7366. break;
  7367. }
  7368. $page ['page'] = $page_c;
  7369. $page ['lower'] = (-- $on_page) * $page_size;
  7370. return $page;
  7371. }
  7372. /**
  7373. * 获取上一页
  7374. * @param unknown_type $on_page
  7375. */
  7376. function get_previous($on_page = 1) {
  7377. return $on_page != 0 ? $on_page - 1 : $on_page;
  7378. }
  7379. /**
  7380. * 获取总页数
  7381. * @param unknown_type $table
  7382. * @param unknown_type $condition
  7383. */
  7384. public function get_table_count($table = "", $condition = "") {
  7385. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  7386. $sql = "select count(*) as count from " . $table . " where " . $condition;
  7387. // echo $sql;die;
  7388. $query = Doo::db ()->query ( $sql );
  7389. $result = $query->fetch ();
  7390. return $result ['count'];
  7391. }
  7392. function isInvoiceNew($type = "GLOBAL") {
  7393. Doo::loadModel ( 'invoice' );
  7394. $invoice = new invoice ();
  7395. Doo::loadModel ( 'invoiceReceivables' );
  7396. $invoiceReceivables = new invoiceReceivables ();
  7397. Doo::loadModel ( 'staff' );
  7398. $staff = new staff ();
  7399. $st = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  7400. // 我的发票待处理
  7401. $pendingInvoice = $invoice->getOne ( array ( // or (status=2 and printStatus=1 and untreadStatus=0 ) or (status=2 and printStatus=1 and untreadStatus=2 )
  7402. 'where' => "(status=3 or status=4) and isDelete=0 and sid=" . $st [0] ['sid'],
  7403. 'desc' => 'iid',
  7404. 'asArray' => TRUE
  7405. ) );
  7406. // 我的收款待入账
  7407. /*
  7408. * $myClaim = $invoiceReceivables->getOne ( array ( 'where' => " receivablesStaff like '" . $st [0] ['sid'] . "-%' and receivablesCategory like '" . $st [0] ['cid'] . ":%' and bindStatus=0", 'desc' => 'irid', 'asArray' => TRUE ) );
  7409. */
  7410. // 发票审批
  7411. $approval = $invoice->getOne ( array (
  7412. 'where' => 'status=1 and pendingApprovals=' . $st [0] ['sid'],
  7413. 'desc' => 'iid',
  7414. 'asArray' => true
  7415. ) );
  7416. // 发票邮寄
  7417. $post = $invoice->getOne ( array (
  7418. 'where' => "postStatus=0 and printStatus=1 and isDelete=0 and doPost=1 and status=2",
  7419. 'asArray' => TRUE
  7420. ) );
  7421. // 发票打印
  7422. $print = $invoice->getOne ( array (
  7423. 'where' => "status=2 and printStatus=0 and untreadStatus=0 and moldManage like '%[\"" . $st [0] ['sid'] . "\",%'",
  7424. 'desc' => 'iid',
  7425. 'asArray' => TRUE
  7426. ) );
  7427. // 发票退票 printStatus=1 and
  7428. $untread = $invoice->getOne ( array (
  7429. 'where' => " untreadStatus=1 and status=2 ",
  7430. 'asArray' => TRUE
  7431. ) );
  7432. $new = array (
  7433. 'GLOBAL' => FALSE,
  7434. 'pendingInvoice' => FALSE,
  7435. // 'myClaim' => FALSE,
  7436. 'approval' => FALSE,
  7437. 'post' => FALSE,
  7438. 'print' => FALSE,
  7439. 'untread' => FALSE
  7440. );
  7441. // || ! empty ( $myClaim )
  7442. if (! empty ( $pendingInvoice ) || ! empty ( $approval ) || ! empty ( $post ) || ! empty ( $print ) || ! empty ( $untread ))
  7443. $new ['GLOBAL'] = TRUE;
  7444. if (! empty ( $pendingInvoice ))
  7445. $new ['pendingInvoice'] = TRUE;
  7446. // if (! empty ( $myClaim ))
  7447. // $new ['myClaim'] = TRUE;
  7448. if (! empty ( $approval ))
  7449. $new ['approval'] = TRUE;
  7450. if (! empty ( $post ))
  7451. $new ['post'] = TRUE;
  7452. if (! empty ( $print ))
  7453. $new ['print'] = TRUE;
  7454. if (! empty ( $untread ))
  7455. $new ['untread'] = TRUE;
  7456. return $new;
  7457. }
  7458. function setWXMsg($rid, $typeMsg = '') {
  7459. Doo::loadModel ( 'invoice' );
  7460. $invoice = new invoice ();
  7461. $invoiceDetail = $invoice->getOne ( array (
  7462. 'where' => 'iid=' . $rid,
  7463. 'asArray' => true
  7464. ) );
  7465. if (! empty ( $invoiceDetail )) {
  7466. Doo::loadModel ( 'staff' );
  7467. $staff = new staff ();
  7468. $staffmsg = $staff->getOne ( array (
  7469. 'where' => "sid='" . $invoiceDetail ['sid'] . "'",
  7470. 'asArray' => TRUE
  7471. ) );
  7472. if (! empty ( $staffmsg ['wxid'] )) {
  7473. require_once (SITE_PATH . '/protected/class/client.php');
  7474. $client = new client ( 'http://m.cld.smartcost.com.cn/' );
  7475. $user = $staffmsg ['wxid'];
  7476. $expCom = explode ( ":", $invoiceDetail ['expressCompany'] );
  7477. if (empty ( $expCom ))
  7478. $expCom [0] = '';
  7479. $msg = "";
  7480. if (empty ( $typeMsg ))
  7481. $msg = '太好了,您的发票' . $invoiceDetail ['invoiceSerial'] . ' 已邮寄 ' . $expCom [0] . ' ,快递号: <a href="https://m.kuaidi100.com/result.jsp?nu=' . $invoiceDetail ['expressNumber'] . '" >' . $invoiceDetail ['expressNumber'] . '</a>';
  7482. elseif ($typeMsg == "PRINT")
  7483. $msg = '太好了,您的发票已打印完成。';
  7484. $result = $client->SendMsg ( $user, $msg, 'text' );
  7485. }
  7486. }
  7487. }
  7488. /**
  7489. * 获取微信部门
  7490. * @param string $category
  7491. * @return number|mixed
  7492. */
  7493. function getToparty($category = '') {
  7494. $token = $this->getAccessToken (); //
  7495. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token={$token}&id=5" ), true );
  7496. $toparty = 0;
  7497. foreach ( $result ['department'] as $key => $value ) {
  7498. if ($value ['name'] == $category)
  7499. $toparty = $value ['id'];
  7500. }
  7501. return $toparty;
  7502. }
  7503. /**
  7504. * 获得某部门下的用户
  7505. * @param string $toparty
  7506. */
  7507. function getUserByToparty($toparty = '') {
  7508. $token = $this->getAccessToken (); //
  7509. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token={$token}&department_id={$toparty}" ), true );
  7510. $userList = array ();
  7511. foreach ( $result ['userlist'] as $key => $value ) {
  7512. array_push ( $userList, "'" . $value ['userid'] . "'" );
  7513. }
  7514. return $userList;
  7515. }
  7516. function msgSendToparty($msg, $title, $url, $toparty, $text = '') {
  7517. $token = $this->getAccessToken ();
  7518. if ($text == 'text') {
  7519. $data = '{
  7520. "touser": "' . $toparty . '",
  7521. "toparty": "",
  7522. "totag": "",
  7523. "msgtype": "text",
  7524. "agentid": 1000002,
  7525. "text": {
  7526. "content": "' . $msg . '"
  7527. },
  7528. "safe":0
  7529. }';
  7530. }
  7531. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  7532. if ($result->errmsg != 'ok') {
  7533. return 0;
  7534. } else {
  7535. return 1;
  7536. }
  7537. }
  7538. /**
  7539. * 获得可以发送微信用户列表
  7540. * @param string $category
  7541. * @return string
  7542. */
  7543. function getWxidByCategory($category = "") {
  7544. if (empty ( $category ))
  7545. return "";
  7546. Doo::loadModel ( 'staff' );
  7547. $staff = new staff ();
  7548. $toparty = $this->getToparty ( $category );
  7549. $wxList = array ();
  7550. $wxString = "";
  7551. if (! empty ( $toparty )) {
  7552. $userList = $this->getUserByToparty ( $toparty );
  7553. $userCon = implode ( ',', $userList );
  7554. // echo $userCon;
  7555. $sidList = $staff->getStaffByWxid ( $userCon );
  7556. foreach ( $sidList as $key => $value ) {
  7557. $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  7558. if ($falg) {
  7559. array_push ( $wxList, $value ['wxid'] );
  7560. }
  7561. }
  7562. $wxString = implode ( '|', $wxList );
  7563. }
  7564. return $wxString;
  7565. }
  7566. /**
  7567. * 读取发送信息规则判断是否需要发送
  7568. * @param number $sid
  7569. * @param string $sendType
  7570. * @return boolean
  7571. */
  7572. function isSendNotification($sid = 0, $sendType = '') {
  7573. Doo::loadModel ( "notificationConf" );
  7574. $notificationConf = new notificationConf ();
  7575. $detail = $notificationConf->getNotificationConfBySid ( $sid );
  7576. $conf = array ();
  7577. $sendFlag = true;
  7578. if (! empty ( $detail )) {
  7579. $conf = json_decode ( $detail ['conf'], true );
  7580. if (! empty ( $sendType )) {
  7581. if (isset ( $conf [$sendType] )) {
  7582. if ($conf [$sendType] == "CLOSE")
  7583. $sendFlag = false;
  7584. elseif ($conf [$sendType] == "Weekend") {
  7585. $day = date ( "w" );
  7586. if (1 <= $day && 5 >= $day)
  7587. $sendFlag = false;
  7588. } elseif ($conf [$sendType] == "OneToFriday") {
  7589. $day = date ( "w" );
  7590. if (0 == $day || 6 == $day)
  7591. $sendFlag = false;
  7592. }
  7593. }
  7594. } else
  7595. $sendFlag = false;
  7596. }
  7597. return $sendFlag;
  7598. }
  7599. /**
  7600. * 根据规则发送信息
  7601. * @param unknown $msg
  7602. * @param unknown $title
  7603. * @param unknown $url
  7604. * @param unknown $user
  7605. * @param string $text
  7606. * @return number
  7607. */
  7608. private function msgSend($msg, $title, $url, $user, $sid = 0, $sendType = '') {
  7609. $token = $this->getAccessToken ();
  7610. $falg = $this->isSendNotification ( $sid, $sendType );
  7611. // if ($text == 'text') {
  7612. // $data = '{
  7613. // "touser": "' . $user . '",
  7614. // "toparty": "",
  7615. // "totag": "",
  7616. // "msgtype": "text",
  7617. // "agentid": 1000002,
  7618. // "text": {
  7619. // "content": "' . $msg . '"
  7620. // },
  7621. // "safe":0
  7622. // }';
  7623. // } else {
  7624. $data = '{
  7625. "touser": "' . $user . '",
  7626. "toparty": "",
  7627. "totag": "",
  7628. "msgtype": "news",
  7629. "agentid": 1000002,
  7630. "news": {
  7631. "articles":[
  7632. {
  7633. "title": "' . $title . '",
  7634. "description": "' . $msg . '",
  7635. "url": "' . $url . '",
  7636. "picurl": ""
  7637. }
  7638. ]
  7639. }
  7640. }';
  7641. // }
  7642. if ($falg) {
  7643. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  7644. if ($result->errmsg != 'ok') {
  7645. return 0;
  7646. } else {
  7647. return 1;
  7648. }
  7649. } else
  7650. return 0;
  7651. }
  7652. private function getAccessToken() {
  7653. // access_token 应该全局存储与更新,以下代码以写入到文件中做示例
  7654. // $file = './access_token.txt';
  7655. // $data = json_decode ( file_get_contents ( $file ) );
  7656. // if ($data->expire_time < time () or ! $data->expire_time) {
  7657. // 如果是企业号用以下URL获取access_token
  7658. $url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$this->appId&corpsecret=$this->appSecret";
  7659. // $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$this->appId&secret=$this->appSecret";
  7660. $res = json_decode ( $this->httpGet ( $url ) );
  7661. $access_token = $res->access_token;
  7662. // echo $access_token;
  7663. // if ($access_token) {
  7664. // $data->expire_time = time () + 7000;
  7665. // $data->access_token = $access_token;
  7666. // $fp = fopen ( $file, "w" );
  7667. // fwrite ( $fp, json_encode ( $data ) );
  7668. // fclose ( $fp );
  7669. // }
  7670. // } else {
  7671. // $access_token = $data->access_token;
  7672. // }
  7673. return $access_token;
  7674. }
  7675. private function httpGet($url) {
  7676. $curl = curl_init ();
  7677. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  7678. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  7679. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  7680. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  7681. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  7682. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  7683. curl_setopt ( $curl, CURLOPT_URL, $url );
  7684. $res = curl_exec ( $curl );
  7685. curl_close ( $curl );
  7686. return $res;
  7687. }
  7688. private function httpPost($url, $data) {
  7689. $curl = curl_init ();
  7690. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  7691. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  7692. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  7693. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  7694. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  7695. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  7696. curl_setopt ( $curl, CURLOPT_URL, $url );
  7697. curl_setopt ( $curl, CURLOPT_POST, 1 );
  7698. curl_setopt ( $curl, CURLOPT_POSTFIELDS, $data );
  7699. $res = curl_exec ( $curl );
  7700. curl_close ( $curl );
  7701. return $res;
  7702. }
  7703. }
  7704. ?>