InvoiceController.php 331 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144
  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->findAll( array (
  239. 'where' => " cid=" . $this->staff [0] ['cid'].' or creator ='.$this->staff [0]['sid'],
  240. 'desc'=>'itid',
  241. 'asArray' => TRUE
  242. ) );
  243. //$itList = $invoiceTraining->getInvoiceTrainingByCid ( $this->staff [0] ['cid'] );
  244. Doo::loadModel ( 'receipt' );
  245. $receipt = new receipt ();
  246. foreach ( $itList as $key => $value ) { // 不展示已结算完结的培训班
  247. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $value ['itid'] );
  248. if (! empty ( $receiptDetail )) {
  249. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9) {
  250. unset ( $itList [$key] );
  251. }
  252. }
  253. }
  254. $this->data ['itList'] = $itList;
  255. $token = $this->set_token ();
  256. $tokenTime=time().rand(5, 15);
  257. $_SESSION ['token_' . $this->staff [0] ['sidKey'].'_'.$tokenTime] = $token;
  258. $this->data ['token'] = $token;
  259. $this->data['tokenTime']=$tokenTime;
  260. $this->data ['memu'] = "invoice";
  261. $this->data ['staff'] = $this->staff;
  262. $this->data ['receiptMemu'] = 'invoice';
  263. $this->render ( "/admin/invoiceAdd", $this->data );
  264. }
  265. /**
  266. * 自更新发票信息库
  267. * @param unknown $invoicePrintDetail
  268. */
  269. function autoUpdateInvoiceInfoBase($invoicePrintDetail) {
  270. // 发票信息库
  271. Doo::loadModel ( 'invoiceInfoBase' );
  272. $invoiceInfoBase = new invoiceInfoBase ();
  273. $updateDate = strtotime ( $invoicePrintDetail ['date'] );
  274. $TIN = $invoicePrintDetail ['TIN'];
  275. $invoiceTitle = $invoicePrintDetail ['invoiceTitle'];
  276. if (empty ( $invoiceTitle ))
  277. $invoiceTitle = $invoicePrintDetail ['invoiceCompany'];
  278. $IIBList = $invoiceInfoBase->getInvoiceInfoByTT ( $TIN, $invoiceTitle );
  279. // 确认有该条发票信息
  280. $invoiceInfoBase = new invoiceInfoBase ();
  281. if (! empty ( $IIBList )) {
  282. // 发票库里的信息数量
  283. $IIBListCount = count ( $IIBList );
  284. if ($IIBListCount == 1) { // 更新发票--提交是最新的时间
  285. $item = array (
  286. 'iibID' => $IIBList [0] ['iibID'],
  287. 'invoiceTitle' => $invoiceTitle,
  288. 'TIN' => $TIN
  289. );
  290. if (! empty ( $invoicePrintDetail ['address'] )) {
  291. $item += array (
  292. 'address' => $invoicePrintDetail ['address']
  293. );
  294. }
  295. if (! empty ( $invoicePrintDetail ['phone'] )) {
  296. $item += array (
  297. 'phone' => $invoicePrintDetail ['phone']
  298. );
  299. }
  300. if (! empty ( $invoicePrintDetail ['bank'] )) {
  301. $item += array (
  302. 'bank' => $invoicePrintDetail ['bank']
  303. );
  304. }
  305. if (! empty ( $invoicePrintDetail ['bankAccount'] )) {
  306. $item += array (
  307. 'bankAccount' => $invoicePrintDetail ['bankAccount']
  308. );
  309. }
  310. if ($updateDate >= strtotime ($IIBList [0] ['updateDate'])) {
  311. $item += array (
  312. 'updateDate' => $invoicePrintDetail ['date']
  313. );
  314. $invoiceInfoBase->setInvoiceInfoBaseByCondition ( $item );
  315. }
  316. } else { // 删除多张发票,重新添加发票
  317. $iibIDStr = '';
  318. $iibID = array ();
  319. foreach ( $IIBList as $key => $value ) {
  320. array_push ( $iibID, $value ['iibID'] );
  321. }
  322. $iibIDStr = implode ( ",", $iibID ); // 删除
  323. $invoiceInfoBase->delInvoiceInfoBaseByIibStr ( $iibIDStr );
  324. $item = array (
  325. 'invoiceTitle' => $invoiceTitle,
  326. 'TIN' => $TIN,
  327. 'address' => $invoicePrintDetail ['address'],
  328. 'phone' => $invoicePrintDetail ['phone'],
  329. 'bank' => $invoicePrintDetail ['bank'],
  330. 'bankAccount' => $invoicePrintDetail ['bankAccount'],
  331. 'updateDate' => $invoicePrintDetail ['date']
  332. );
  333. $invoiceInfoBase->addInvoiceInfoBase ( $item );
  334. }
  335. } else { // 没有新增发票信息
  336. $item = array (
  337. 'invoiceTitle' => $invoiceTitle,
  338. 'TIN' => $TIN,
  339. 'address' => $invoicePrintDetail ['address'],
  340. 'phone' => $invoicePrintDetail ['phone'],
  341. 'bank' => $invoicePrintDetail ['bank'],
  342. 'bankAccount' => $invoicePrintDetail ['bankAccount'],
  343. 'updateDate' => $invoicePrintDetail ['date']
  344. );
  345. $invoiceInfoBase->addInvoiceInfoBase ( $item );
  346. }
  347. }
  348. function invoiceAddFill() {
  349. session_start ();
  350. Doo::loadModel ( 'L_category' );
  351. $lCategory = new L_category ();
  352. $category = $lCategory->find ( array (
  353. 'asArray' => true
  354. ) );
  355. $this->data ['category'] = $category;
  356. Doo::loadModel ( 'invoiceTraining' );
  357. $invoiceTraining = new invoiceTraining ();
  358. $itList = $invoiceTraining->getInvoiceTrainingByCid ( $this->staff [0] ['cid'] );
  359. $this->data ['itList'] = $itList;
  360. Doo::loadModel ( 'invoice' );
  361. $invoice = new invoice ();
  362. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );
  363. $detail ['mailItemsArray'] = json_decode ( $detail ['mailItemsJson'], true );
  364. $token = $this->set_token ();
  365. $tokenTime=time().rand(5, 15);
  366. $_SESSION ['token_' . $this->staff [0] ['sidKey'].'_'.$tokenTime] = $token;
  367. $this->data ['token'] = $token;
  368. $this->data['tokenTime']=$tokenTime;
  369. $this->data ['invoiceDetail'] = $detail;
  370. $this->data ['memu'] = "invoice";
  371. $this->data ['staff'] = $this->staff;
  372. $this->data ['receiptMemu'] = 'invoice';
  373. $this->render ( "/admin/invoiceAddFill", $this->data );
  374. }
  375. /**
  376. * 提交一份开票申请,并记录下操作日志
  377. *
  378. * @since 1.0.0
  379. * @var integer cid 办事处ID
  380. * @var integer invoiceType 发票类型
  381. * @var integer doPost 是否邮寄
  382. * @var integer invoicePrice 开票金额
  383. * @var string invoiceElement 开票内容
  384. * @var string invoiceTitle 发票抬头
  385. * @var string invoiceCompany 单位名称
  386. * @var string TIN 纳税人识别码
  387. * @var string address 注册地址
  388. * @var string phone 注册电话
  389. * @var string bank 开户银行
  390. * @var string bankAccount 银行账户
  391. * @var string recipients 收件人
  392. * @var string recipientsPhone 收件人手机/电话
  393. * @var string recipientsAddress 收件地址
  394. * @var string mailItems 邮寄物品
  395. * @var string remark 备注
  396. * @return string 返回跳转开票主页路径
  397. */
  398. function invoiceAddDo() {
  399. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  400. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  401. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  402. // $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  403. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  404. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  405. $invoiceForm = $this->get_args ( 'invoiceForm' ) ? $this->get_args ( 'invoiceForm' ) : "";
  406. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  407. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  408. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  409. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  410. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  411. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  412. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  413. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  414. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  415. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  416. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  417. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  418. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  419. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  420. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  421. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  422. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  423. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  424. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  425. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  426. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  427. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  428. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  429. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  430. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  431. $trainId = $this->get_args ( 'trainId' ) ? $this->get_args ( 'trainId' ) : 0;
  432. $settlementType = $this->get_args ( 'settlementType' ) ? $this->get_args ( 'settlementType' ) : "";
  433. $electronicPhone= $this->get_args ( 'electronicPhone' ) ? $this->get_args ( 'electronicPhone' ) : "";
  434. $electronicEmail = $this->get_args ( 'electronicEmail' ) ? $this->get_args ( 'electronicEmail' ) : "";
  435. /*
  436. * $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;
  437. */
  438. $token = $this->get_args ( 'token' ) ? $this->get_args ( 'token' ) : "";
  439. $tokenTime = $this->get_args ( 'tokenTime' ) ? $this->get_args ( 'tokenTime' ) : "";
  440. if (empty ( $token )) {
  441. die ( 'illegal request-token' );
  442. } else {
  443. session_start ();
  444. $sessionKey='token_' . $this->staff [0] ['sidKey'].'_'.$tokenTime;
  445. header ( 'Content-Type:text/html;charset=utf-8' );
  446. if (!isset($_SESSION [$sessionKey])||empty($_SESSION [$sessionKey])) {
  447. die ( '请重新刷新发票申请页面' );
  448. }elseif($_SESSION [$sessionKey]=='repeat'){
  449. die ( '请勿重复申请发票' );
  450. } else {
  451. if ($_SESSION [$sessionKey] != $token){
  452. die ( '请勿重复申请发票' );
  453. }else{
  454. $_SESSION [$sessionKey] = 'repeat';
  455. }
  456. }
  457. }
  458. if($invoiceForm=='electronic'){
  459. if(empty(trim($electronicPhone))&&empty(trim($electronicEmail))){
  460. die ( '请至少填写一种联系方式--电子发票' );
  461. }
  462. }
  463. if ($invoiceType == 1) {
  464. $temporary = $invoiceQuantity * $invoiceUnitPrice;
  465. if ($temporary > 100001) {
  466. header ( 'Content-Type:text/html;charset=utf-8' );
  467. die ( '专用发票总金额暂时不能超过100000.00(十万)元。' );
  468. }
  469. }elseif($invoiceType == 0){
  470. $temporary = $invoiceQuantity * $invoiceUnitPrice;
  471. if ($temporary > 100001) {
  472. header ( 'Content-Type:text/html;charset=utf-8' );
  473. die ( '专用发票总金额暂时不能超过100000.00(十万)元。' );
  474. }
  475. }else{
  476. die ( 'illegal request-invoiceType' );
  477. }
  478. if (empty ( $this->staff [0] ))
  479. die ( 'illegal request-Please login' );
  480. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $settlementType )&&!empty($invoiceForm)) {
  481. Doo::loadModel ( 'invoice' );
  482. $invoice = new invoice ();
  483. Doo::loadModel ( 'L_category' );
  484. $lCategory = new L_category ();
  485. Doo::loadModel ( 'invoiceManage' );
  486. $invoiceManage = new invoiceManage ();
  487. Doo::loadModel ( 'invoiceOperationLog' );
  488. $invoiceOperationLog = new invoiceOperationLog ();
  489. Doo::loadClass ( 'XDeode' );
  490. $XDeode = new XDeode ( 5 );
  491. $trainId = $XDeode->decode ( $trainId );
  492. $categoryDetil = $lCategory->getOne ( array (
  493. 'SELECT' => 'title',
  494. 'where' => 'cid=' . $cid,
  495. 'asArray' => true
  496. ) );
  497. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  498. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  499. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  500. // print_r(current($invoiceManageDetail ['staffList']));
  501. // die;
  502. $moldManage = array ();
  503. foreach ( $invoiceManageList as $key => $value ) {
  504. if ($value ['mold'] == '发票打印')
  505. $moldManage [$value ['mold']] = $value ['staffList'];
  506. elseif ($value ['mold'] == '发票邮寄')
  507. $moldManage [$value ['mold']] = $value ['staffList'];
  508. elseif ($value ['mold'] == '发票退票')
  509. $moldManage [$value ['mold']] = $value ['staffList'];
  510. }
  511. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  512. $st = '';
  513. if ($settlementType == 'SOFTWARE') {
  514. $st = 0;
  515. $trainId = 0;
  516. } elseif ($settlementType == 'TRAINING') {
  517. $st = 1;
  518. if (empty ( $trainId ) && ! is_numeric ( $trainId )) {
  519. die ( 'illegal request-trainingIdError' );
  520. }
  521. } else {
  522. die ( 'illegal request-settlementError' );
  523. }
  524. if($invoiceForm=='electronic'){
  525. $invoiceSerial="#FE" . date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
  526. $invoiceForm=1;
  527. $invoiceType=0;
  528. if(!empty($electronicPhone)||!empty($electronicEmail)){
  529. }else{
  530. die ( 'illegal request-electronicContact' );
  531. }
  532. $mailList = array ();
  533. $mailString = '备注:' . $mailItems;
  534. }elseif($invoiceForm=='paper'){
  535. $invoiceSerial="#F" . date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
  536. $invoiceForm=0;
  537. $mailList = array (
  538. 'invoice' => 1,
  539. 'mailItems' => $mailItems
  540. );
  541. $mailString = '发票x1张,备注:' . $mailItems;
  542. }else{
  543. die ( 'illegal request-invoiceForm' );
  544. }
  545. $item = array (
  546. 'cid' => $cid,
  547. 'categoryName' => $categoryDetil ['title'],
  548. 'invoiceElement' => $invoiceElement,
  549. 'invoiceForm'=>$invoiceForm,
  550. 'electronicPhone'=>$electronicPhone,
  551. 'electronicEmail'=>$electronicEmail,
  552. 'invoiceQuantity' => $invoiceQuantity,
  553. 'invoiceUnitPrice' => $invoiceUnitPrice,
  554. 'invoicePrice' => $invoicePrice,
  555. 'invoiceType' => $invoiceType,
  556. 'settlementType' => $st,
  557. 'doPost' => $doPost,
  558. 'status' => 1,
  559. 'invoiceSerial' => $invoiceSerial,
  560. 'date' => date ( "Y-m-d H:i:s" ),
  561. 'updateTime' => date ( "Y-m-d H:i:s" ),
  562. 'sid' => $this->staff [0] ['sid'],
  563. 'userName' => $this->staff [0] ['username'],
  564. 'invoiceManage' => $invoiceManageDetail ['staff'],
  565. 'pendingApprovals' => $pendingApprovalsSid,
  566. 'moldManage' => json_encode ( $moldManage ),
  567. 'remark' => $remark,
  568. 'trainId' => $trainId
  569. );
  570. if ($invoiceType == 0)
  571. $item += array (
  572. 'invoiceTitle' => $invoiceTitle,
  573. 'TIN' => $TINT,
  574. 'address' => $addressT,
  575. 'phone' => $phoneT,
  576. 'bank' => $bankT,
  577. 'bankAccount' => $bankAccountT
  578. );
  579. else {
  580. $item += array (
  581. 'invoiceCompany' => $invoiceCompany,
  582. 'TIN' => $TIN,
  583. 'address' => $address,
  584. 'phone' => $phone,
  585. 'bank' => $bank,
  586. 'bankAccount' => $bankAccount
  587. );
  588. }
  589. if ($doPost == 1) {
  590. if (! empty ( $softLock ))
  591. $mailList += array (
  592. 'softLock' => $softLockNum
  593. );
  594. else
  595. $mailList += array (
  596. 'softLock' => 0
  597. );
  598. if (! empty ( $contract ))
  599. $mailList += array (
  600. 'contract' => $contractNum
  601. );
  602. else
  603. $mailList += array (
  604. 'contract' => 0
  605. );
  606. if (! empty ( $instructions ))
  607. $mailList += array (
  608. 'instructions' => $instructionsNum
  609. );
  610. else
  611. $mailList += array (
  612. 'instructions' => 0
  613. );
  614. if (! empty ( $remittance ))
  615. $mailList += array (
  616. 'remittance' => $remittance
  617. );
  618. else
  619. $mailList += array (
  620. 'remittance' => ''
  621. );
  622. if (! empty ( $softLock ))
  623. $mailString .= ',软件锁x' . $softLockNum . '个';
  624. if (! empty ( $contract ))
  625. $mailString .= ',合同x' . $contractNum . '份';
  626. if (! empty ( $instructions ))
  627. $mailString .= ',说明书x' . $instructionsNum . '本';
  628. if (! empty ( $remittance ))
  629. $mailString .= ',汇款账号单(张)';
  630. $item += array (
  631. 'recipients' => $recipients,
  632. 'recipientsPhone' => $recipientsPhone,
  633. 'recipientsAddress' => $recipientsAddress,
  634. 'mailItems' => $mailString,
  635. 'mailItemsJson' => json_encode ( $mailList )
  636. );
  637. }
  638. $iid = $invoice->addInvoice ( $item );
  639. // 如果是培训班结算 创建培训班发票到培训班备份中
  640. if (! empty ( $st ) && $st == 1) {
  641. Doo::loadModel ( 'invoiceStore' );
  642. $invoiceStore = new invoiceStore ();
  643. Doo::loadModel ( 'invoiceTraining' );
  644. $invoiceTraining = new invoiceTraining ();
  645. $isid = $invoiceStore->setInvoiceToInvoiceStore ( $iid );
  646. $itemIS = array (
  647. 'isid' => $isid,
  648. 'ipSource' => 1,
  649. 'apStatus' => 1,
  650. 'iid' => $iid
  651. );
  652. $invoiceStore->setInvoiceStoreByCondition ( $itemIS );
  653. // 更新培训班总数量
  654. $detailIT = $invoiceTraining->getInvoiceTrainingByItid ( $trainId );
  655. $item = array (
  656. 'itid' => $trainId,
  657. 'invoiceTotal' => $detailIT ['invoiceTotal'] + 1,
  658. 'submitStatus' => 1
  659. );
  660. $itid = $invoiceTraining->setInvoiceTrainByCondition ( $item );
  661. }
  662. // 操作日志
  663. $item = array (
  664. 'date' => date ( "Y-m-d H:i:s" ),
  665. 'operation' => "创建",
  666. 'status' => 1,
  667. 'img' => $this->staff [0] ['avatar'],
  668. 'username' => $this->staff [0] ['username'],
  669. 'uid' => $this->staff [0] ['sid'],
  670. 'category' => $this->staff [0] ['category'],
  671. 'iid' => $iid
  672. );
  673. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  674. $item = array (
  675. 'date' => date ( "Y-m-d H:i:s" ),
  676. 'operation' => "提交审批",
  677. 'status' => 1,
  678. 'img' => $this->staff [0] ['avatar'],
  679. 'username' => $this->staff [0] ['username'],
  680. 'uid' => $this->staff [0] ['sid'],
  681. 'category' => $this->staff [0] ['category'],
  682. 'iid' => $iid
  683. );
  684. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  685. Doo::loadModel ( 'staff' );
  686. $staff = new staff ();
  687. $username2 = $staff->getOne ( array (
  688. 'select' => 'wxid',
  689. 'where' => 'sid=' . $pendingApprovalsSid,
  690. 'asArray' => TRUE
  691. ) );
  692. // 发送微信审批通知
  693. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  694. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  695. }
  696. return "/invoice";
  697. }
  698. function invoiceEdit() {
  699. Doo::loadClass ( 'XDeode' );
  700. $XDeode = new XDeode ( 5 );
  701. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  702. $iid = $XDeode->decode ( $iid );
  703. if (! is_numeric ( $iid ))
  704. die ( 'illegal request' );
  705. Doo::loadModel ( 'invoice' );
  706. $invoice = new invoice ();
  707. Doo::loadModel ( 'invoiceOperationLog' );
  708. $invoiceOperationLog = new invoiceOperationLog ();
  709. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  710. $operation = $invoiceOperationLog->getInvoiceOperationByDropped ( $iid );
  711. $invoiceDetail ['mailItemsJson'] ='';
  712. if(isset($invoiceDetail ['mailItemsJson'])){
  713. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  714. }
  715. $this->data ['operation'] = $operation;
  716. $this->data ['invoiceDetail'] = $invoiceDetail;
  717. $this->data ['memu'] = "invoice";
  718. $this->data ['staff'] = $this->staff;
  719. $this->data ['receiptMemu'] = 'invoice';
  720. $this->render ( "/admin/invoiceEdit", $this->data );
  721. }
  722. /**
  723. * 重新编辑退回的发票
  724. * @return string
  725. */
  726. function invoiceEditDo() {
  727. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  728. Doo::loadModel ( 'invoice' );
  729. $invoice = new invoice ();
  730. $iid = $invoice->authcode ( $iidKey );
  731. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  732. die ( 'illegal request' );
  733. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  734. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  735. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  736. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  737. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  738. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  739. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  740. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  741. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  742. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  743. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  744. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  745. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  746. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  747. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  748. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  749. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  750. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  751. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  752. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  753. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  754. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  755. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  756. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  757. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  758. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  759. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  760. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  761. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  762. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  763. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  764. $electronicPhone = $this->get_args ( 'electronicPhone' ) ? $this->get_args ( 'electronicPhone' ) : "";
  765. $electronicEmail = $this->get_args ( 'electronicEmail' ) ? $this->get_args ( 'electronicEmail' ) : "";
  766. $invoiceForm = $this->get_args ( 'invoiceForm' ) ? $this->get_args ( 'invoiceForm' ) : "";
  767. if ($invoiceType == 1) {
  768. $temporary = $invoiceQuantity * $invoiceUnitPrice;
  769. if ($temporary > 100001)
  770. die ( 'illegal request-Please priceError' );
  771. }
  772. if($invoiceForm=='electronic'){
  773. if(empty(trim($electronicPhone))&&empty(trim($electronicEmail))){
  774. die ( '请至少填写一种联系方式--电子发票' );
  775. }
  776. }
  777. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  778. Doo::loadModel ( 'invoiceManage' );
  779. $invoiceManage = new invoiceManage ();
  780. Doo::loadModel ( 'invoiceOperationLog' );
  781. $invoiceOperationLog = new invoiceOperationLog ();
  782. Doo::loadModel ( 'invoiceStore' );
  783. $invoiceStore = new invoiceStore ();
  784. $cid = explode ( ':', $cid );
  785. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  786. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  787. $moldManage = array ();
  788. foreach ( $invoiceManageList as $key => $value ) {
  789. if ($value ['mold'] == '发票打印')
  790. $moldManage [$value ['mold']] = $value ['staffList'];
  791. elseif ($value ['mold'] == '发票邮寄')
  792. $moldManage [$value ['mold']] = $value ['staffList'];
  793. elseif ($value ['mold'] == '发票打印')
  794. $moldManage [$value ['mold']] = $value ['staffList'];
  795. }
  796. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  797. if($invoiceForm=='electronic'){
  798. $invoiceForm=1;
  799. $invoiceType=0;
  800. if(!empty($electronicPhone)||!empty($electronicEmail)){
  801. }else{
  802. die ( 'illegal request-electronicContact' );
  803. }
  804. $mailList = array ();
  805. $mailString = '备注:' . $mailItems;
  806. }elseif($invoiceForm=='paper'){
  807. $invoiceForm=0;
  808. $mailList = array (
  809. 'invoice' => 1,
  810. 'mailItems' => $mailItems
  811. );
  812. $mailString = '发票x1张,备注:' . $mailItems;
  813. }else{
  814. die ( 'illegal request-invoiceForm' );
  815. }
  816. $item = array (
  817. 'iid' => $iid,
  818. 'cid' => $cid [0],
  819. 'categoryName' => $cid [1],
  820. 'invoiceElement' => $invoiceElement,
  821. 'invoiceForm'=>$invoiceForm,
  822. 'electronicPhone'=>$electronicPhone,
  823. 'electronicEmail'=>$electronicEmail,
  824. 'invoiceQuantity' => $invoiceQuantity,
  825. 'invoiceUnitPrice' => $invoiceUnitPrice,
  826. 'invoicePrice' => $invoicePrice,
  827. 'invoiceType' => $invoiceType,
  828. 'doPost' => $doPost,
  829. 'status' => 1,
  830. 'updateTime' => date ( "Y-m-d H:i:s" ),
  831. 'remark' => $remark
  832. );
  833. if ($invoiceType == 0)
  834. $item += array (
  835. 'invoiceTitle' => $invoiceTitle,
  836. 'TIN' => $TINT,
  837. 'address' => $addressT,
  838. 'phone' => $phoneT,
  839. 'bank' => $bankT,
  840. 'bankAccount' => $bankAccountT
  841. );
  842. else {
  843. $item += array (
  844. 'invoiceCompany' => $invoiceCompany,
  845. 'TIN' => $TIN,
  846. 'address' => $address,
  847. 'phone' => $phone,
  848. 'bank' => $bank,
  849. 'bankAccount' => $bankAccount
  850. );
  851. }
  852. if ($doPost == 1) {
  853. if (! empty ( $softLock ))
  854. $mailList += array (
  855. 'softLock' => $softLockNum
  856. );
  857. else
  858. $mailList += array (
  859. 'softLock' => '0'
  860. );
  861. if (! empty ( $contract ))
  862. $mailList += array (
  863. 'contract' => $contractNum
  864. );
  865. else
  866. $mailList += array (
  867. 'contract' => '0'
  868. );
  869. if (! empty ( $instructions ))
  870. $mailList += array (
  871. 'instructions' => $instructionsNum
  872. );
  873. else
  874. $mailList += array (
  875. 'instructions' => '0'
  876. );
  877. if (! empty ( $remittance ))
  878. $mailList += array (
  879. 'remittance' => $remittance
  880. );
  881. else
  882. $mailList += array (
  883. 'remittance' => ''
  884. );
  885. if (! empty ( $softLock ))
  886. $mailString .= ',软件锁x' . $softLockNum;
  887. if (! empty ( $contract ))
  888. $mailString .= ',合同x' . $contractNum;
  889. if (! empty ( $instructions ))
  890. $mailString .= ',说明书x' . $instructionsNum;
  891. if (! empty ( $remittance ))
  892. $mailString .= ',汇款账号单';
  893. $item += array (
  894. 'recipients' => $recipients,
  895. 'recipientsPhone' => $recipientsPhone,
  896. 'recipientsAddress' => $recipientsAddress,
  897. 'mailItems' => $mailString,
  898. 'mailItemsJson' => json_encode ( $mailList )
  899. );
  900. }
  901. $invoice->setInvoiceByCondition ( $item );
  902. // 更新培训班仓库里的发票
  903. $detail = $invoice->getInvoiceByIid ( $iid );
  904. if (! empty ( $detail ['isid'] )) {
  905. $invoiceStore->isid = $detail ['isid'];
  906. $invoiceStore->invoiceQuantity = $invoiceQuantity;
  907. $invoiceStore->invoiceUnitPrice = $invoiceUnitPrice;
  908. $invoiceStore->invoicePrice = $invoicePrice;
  909. $invoiceStore->update ();
  910. }
  911. $item = array (
  912. 'date' => date ( "Y-m-d H:i:s" ),
  913. 'operation' => "重新提交审批",
  914. 'status' => 1,
  915. 'img' => $this->staff [0] ['avatar'],
  916. 'username' => $this->staff [0] ['username'],
  917. 'uid' => $this->staff [0] ['sid'],
  918. 'category' => $this->staff [0] ['category'],
  919. 'iid' => $iid
  920. );
  921. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  922. }
  923. return "/invoice";
  924. }
  925. /**
  926. * 培训班
  927. */
  928. function invoiceTraining() {
  929. Doo::loadModel ( 'L_category' );
  930. $lCategory = new L_category ();
  931. Doo::loadModel ( 'invoiceTraining' );
  932. $invoiceTraining = new invoiceTraining ();
  933. Doo::loadModel ( 'invoiceTrainManage' );
  934. $invoiceTrainManage = new invoiceTrainManage ();
  935. $imcStaff = $invoiceTrainManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  936. $cidList = array ();
  937. foreach ( $imcStaff as $key => $value ) {
  938. array_push ( $cidList, $value ['cid'] );
  939. }
  940. if (empty ( $cidList )) {
  941. $cidString = $this->staff [0] ['cid'];
  942. } else {
  943. $cidString = implode ( ',', $cidList );
  944. $cidString .= $cidString . ',' . $this->staff [0] ['cid'];
  945. }
  946. $itTodoList = $invoiceTraining->getInvoiceTrainingByTodo ( '', $cidString, $this->staff [0] ['sid'] );
  947. $itedList = $invoiceTraining->getInvoiceTrainingByStatus ( 2, '', $cidString, $this->staff [0] ['sid'] );
  948. $category = $lCategory->getCategory ();
  949. $itid = array ();
  950. foreach ( $itTodoList as $key => $value ) {
  951. array_push ( $itid, $value ['itid'] );
  952. // 如果入账100%更新为已完成
  953. if ($itTodoList [$key] ['arriveSchedule'] >= 100) {
  954. $invoiceTraining = new invoiceTraining ();
  955. $invoiceTraining->itid = $value ['itid'];
  956. $invoiceTraining->status = 2;
  957. $invoiceTraining->update ();
  958. }
  959. }
  960. foreach ( $itedList as $value ) {
  961. array_push ( $itid, $value ['itid'] );
  962. }
  963. $itid = implode ( ',', $itid );
  964. $this->data ['itStatist'] = $invoiceTraining->getInvoiceTrainStatistics ( $itid );
  965. // print_r($itTodoList);
  966. $this->data ['trainCount'] = count ( $itTodoList ) + count ( $itedList );
  967. $this->data ['itTodoList'] = $itTodoList;
  968. $this->data ['itedList'] = $itedList;
  969. $this->data ['category'] = $category;
  970. $this->data ['memu'] = "invoice";
  971. $this->data ['staff'] = $this->staff;
  972. $this->data ['receiptMemu'] = 'invoiceTraining';
  973. $this->render ( "/admin/invoiceTraining", $this->data );
  974. }
  975. /**
  976. * 创建培训班
  977. */
  978. function invoiceTrainingAdd() {
  979. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  980. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  981. $trainDate = $this->get_args ( 'trainDate' ) ? $this->get_args ( 'trainDate' ) : "";
  982. if (empty ( $this->staff [0] ))
  983. die ( 'illegal request' );
  984. if (! empty ( $cid ) && ! empty ( $trainName ) && ! empty ( $trainDate )) {
  985. Doo::loadModel ( 'invoiceTraining' );
  986. $invoiceTraining = new invoiceTraining ();
  987. Doo::loadModel ( 'invoice' );
  988. $invoice = new invoice ();
  989. Doo::loadModel ( 'L_category' );
  990. $lCategory = new L_category ();
  991. Doo::loadModel ( 'invoiceManage' );
  992. $invoiceManage = new invoiceManage ();
  993. Doo::loadModel ( 'invoiceOperationLog' );
  994. $invoiceOperationLog = new invoiceOperationLog ();
  995. $item = array (
  996. 'cid' => $cid,
  997. 'trainName' => $trainName,
  998. 'trainDate' => $trainDate,
  999. 'creator' => $this->staff [0] ['sid'],
  1000. 'creatorDate' => date ( "Y-m-d H:i:s" )
  1001. );
  1002. $itid = $invoiceTraining->addInvoiceTraining ( $item );
  1003. }
  1004. return "/invoiceTraining";
  1005. }
  1006. /**
  1007. * 删除培训班
  1008. */
  1009. function invoiceTrainingDelDo() {
  1010. $itid = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  1011. if (! empty ( $itid )) {
  1012. Doo::loadModel ( 'invoiceTraining' );
  1013. $invoiceTraining = new invoiceTraining ();
  1014. $invoiceTraining->delInvoiceTrainingByItid ( $itid );
  1015. }
  1016. return "/invoiceTraining";
  1017. }
  1018. /**
  1019. * 培训班详情
  1020. */
  1021. function invoiceTrainingDetail() {
  1022. $trainStatus = $this->get_args ( 'trainStatus' ) ? $this->get_args ( 'trainStatus' ) : "ALL";
  1023. $itid = isset ( $this->params ['trainingKey'] ) ? $this->params ['trainingKey'] : "";
  1024. Doo::loadModel ( 'invoiceTraining' );
  1025. $invoiceTraining = new invoiceTraining ();
  1026. Doo::loadModel ( 'invoiceStore' );
  1027. $invoiceStore = new invoiceStore ();
  1028. if (empty ( $itid ))
  1029. die ( 'illegal request' );
  1030. $con = '(b.untreadStatus is null or b.untreadStatus!=2) and ';
  1031. if ($trainStatus == "SUBED")
  1032. $con = ' (b.untreadStatus is null ) and ';
  1033. elseif ($trainStatus == "APPROVAL")
  1034. $con = ' ( b.status=1 and b.untreadStatus!=2 ) and ';
  1035. elseif ($trainStatus == "TICKET")
  1036. $con = ' (b.printStatus=1 and b.status=2 and b.untreadStatus!=2) and ';
  1037. elseif ($trainStatus == "TICKETING") {
  1038. $con = ' (b.status=2 and b.untreadStatus=1) and ';
  1039. }
  1040. $con.=' a.invoiceForm=0 and ';
  1041. $detail = $invoiceTraining->getInvoiceTrainingByItid ( $itid );
  1042. $isList = $invoiceStore->getinvoiceStoreByItid ( $itid, $con,0 );
  1043. //print_r($isList);
  1044. $trainlistJson=$this->_trainList($isList);
  1045. if (empty ( $detail ))
  1046. die ( 'illegal request' );
  1047. // 培训班结算是否有和是否已经结算完成
  1048. Doo::loadModel ( 'receipt' );
  1049. $receipt = new receipt ();
  1050. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $itid );
  1051. $this->data ['receiptDetail'] = $receiptDetail;
  1052. $this->data ['trainStatus'] = $trainStatus;
  1053. $this->data ['itid'] = $itid;
  1054. $this->data ['trainlistJson'] = $trainlistJson;
  1055. $this->data ['iTrainDetail'] = $detail;
  1056. $this->data ['memu'] = "invoice";
  1057. $this->data ['staff'] = $this->staff;
  1058. $this->data ['receiptMemu'] = 'invoiceTraining';
  1059. $this->render ( "/admin/invoiceTrainingDetail", $this->data );
  1060. }
  1061. function invoiceTrainingElectronicDetail(){
  1062. $trainStatus = $this->get_args ( 'trainStatus' ) ? $this->get_args ( 'trainStatus' ) : "ALL";
  1063. $itid = isset ( $this->params ['trainingKey'] ) ? $this->params ['trainingKey'] : "";
  1064. Doo::loadModel ( 'invoiceTraining' );
  1065. $invoiceTraining = new invoiceTraining ();
  1066. Doo::loadModel ( 'invoiceStore' );
  1067. $invoiceStore = new invoiceStore ();
  1068. if (empty ( $itid ))
  1069. die ( 'illegal request' );
  1070. $con = ' (b.untreadStatus is null or b.untreadStatus!=2) and ';
  1071. if ($trainStatus == "SUBED")
  1072. $con = ' (b.untreadStatus is null ) and ';
  1073. elseif ($trainStatus == "APPROVAL")
  1074. $con = ' ( b.status=1 and b.untreadStatus!=2 ) and ';
  1075. elseif ($trainStatus == "TICKET")
  1076. $con = ' (b.printStatus=1 and b.status=2 and b.untreadStatus!=2) and ';
  1077. elseif ($trainStatus == "TICKETING") {
  1078. $con = ' (b.status=2 and b.untreadStatus=1) and ';
  1079. }
  1080. $con.=' a.invoiceForm=1 and ';
  1081. $detail = $invoiceTraining->getInvoiceTrainingByItid ( $itid );
  1082. $isList = $invoiceStore->getinvoiceStoreByItid ( $itid, $con,1 );
  1083. //print_r($isList);
  1084. if (empty ( $detail )){
  1085. die ( 'illegal request' );
  1086. }
  1087. $trainlistJson=$this->_trainList($isList,1);
  1088. // 培训班结算是否有和是否已经结算完成
  1089. Doo::loadModel ( 'receipt' );
  1090. $receipt = new receipt ();
  1091. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $itid );
  1092. $this->data ['receiptDetail'] = $receiptDetail;
  1093. $this->data ['trainStatus'] = $trainStatus;
  1094. $this->data ['itid'] = $itid;
  1095. $this->data ['trainlistJson'] = $trainlistJson;
  1096. $this->data ['iTrainDetail'] = $detail;
  1097. $this->data ['memu'] = "invoice";
  1098. $this->data ['staff'] = $this->staff;
  1099. $this->data ['receiptMemu'] = 'invoiceTraining';
  1100. $this->render ( "/invoice/invoiceTrainingElectronicDetail", $this->data );
  1101. }
  1102. function _trainList($isList,$type=0){
  1103. $trainlist = array ();
  1104. foreach ( $isList as $key => $value ) {
  1105. $irDetail = array ();
  1106. if ($value ['apStatus'] == 1) {
  1107. // array_push ( $irDetail, '' );
  1108. array_push ( $irDetail, '<input disabled type="checkbox" style="display:none" >' );
  1109. } else {
  1110. array_push ( $irDetail, '<input type="checkbox" class="hide" id="' . $value ['storeKey'] . '" name="isBox" value="' . $value ['storeKey'] . '" > <a href="/invoiceStoreEdit/' . $value ['storeKey'] . '.html">编辑</a>
  1111. <a href="#confirm" onclick="invoiceStoreApproval(\'' . $value ['storeKey'] . '\')" data-toggle="modal">提交审批</a>
  1112. <a href="#del" node-iStore="del" data-key="' . $value ['storeKey'] . '" onclick="invoiceStoreDel(\'' . $value ['storeKey'] . '\')" data-toggle="modal" class="colRed">移除</a>' );
  1113. }
  1114. array_push ( $irDetail, $value ['invoiceSerial'] );
  1115. if ($value ['invoiceType'] == 1)
  1116. array_push ( $irDetail, $value ['invoiceCompany'] );
  1117. else
  1118. array_push ( $irDetail, $value ['invoiceTitle'] );
  1119. array_push ( $irDetail, $value ['TIN'] );
  1120. array_push ( $irDetail, $value ['userName'] );
  1121. if (empty ( $value ['mailItems'] ) && $value ['apStatus'] != 1) {
  1122. array_push ( $irDetail, '<a href="#confirm-erro" onclick="invoiceStoreMail(\'' . $value ['storeKey'] . '\')" data-toggle="modal">设置邮寄物品</a>' );
  1123. } else
  1124. array_push ( $irDetail, $value ['mailItems'] );
  1125. array_push ( $irDetail, $value ['recipientsAddress'] . $value ['recipients'] . $value ['recipientsPhone'] );
  1126. if($type==1){
  1127. array_push ( $irDetail, $value ['electronicPhone'] );
  1128. array_push ( $irDetail, $value ['electronicEmail'] );
  1129. }
  1130. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  1131. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  1132. array_push ( $irDetail, $value ['invoiceElement'] );
  1133. array_push ( $irDetail, $value ['invoiceQuantity'] );
  1134. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  1135. if ($value ['invoiceType'] == 1)
  1136. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  1137. else
  1138. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  1139. array_push ( $irDetail, $value ['remark'] );
  1140. if ($value ['status'] == 1)
  1141. array_push ( $irDetail, '审批中' );
  1142. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1)
  1143. array_push ( $irDetail, '已出票' );
  1144. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1 && $value ['printStatus'] != 'irid' && ($value ['untreadStatus'] == 3 || $value ['untreadStatus'] == 0))
  1145. array_push ( $irDetail, '已入账' );
  1146. else
  1147. array_push ( $irDetail, '' );
  1148. array_push ( $irDetail, $value ['invoiceNo'] );
  1149. array_push ( $irDetail, $value ['printTime'] );
  1150. $html = '';
  1151. foreach ( $value ['invoiceReceivables'] as $v ) {
  1152. $html .= '&nbsp;<a href="#billing" node-invoice="INFO" data-type="receivables" data-iskey="' . $v [2] . '" data-toggle="modal">' . $v [1] . '</a>';
  1153. }
  1154. array_push ( $irDetail, $html );
  1155. array_push ( $trainlist, $irDetail );
  1156. }
  1157. $trainlistJson = json_encode ( $trainlist );
  1158. return $trainlistJson;
  1159. }
  1160. /**
  1161. * 上传培训班发票
  1162. * @return string
  1163. */
  1164. function invoiceTrainingUpload() {
  1165. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  1166. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  1167. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  1168. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  1169. header ( "HTTP/1.1 500 Internal Server Error" );
  1170. echo "POST exceeded maximum allowed size.";
  1171. exit ( 0 );
  1172. }
  1173. // Settings
  1174. $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)
  1175. $upload_name = "Filedata";
  1176. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  1177. $extension_whitelist = array (
  1178. "doc",
  1179. "txt",
  1180. "jpg",
  1181. "gif",
  1182. "png"
  1183. ); // Allowed file extensions
  1184. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  1185. // Other variables
  1186. $MAX_FILENAME_LENGTH = 260;
  1187. $file_name = "";
  1188. $file_extension = "";
  1189. $uploadErrors = array (
  1190. 0 => "文件上传成功",
  1191. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  1192. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  1193. 3 => "上传的文件仅为部分文件",
  1194. 4 => "没有文件上传",
  1195. 6 => "缺少临时文件夹"
  1196. );
  1197. $nk = time ();
  1198. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  1199. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  1200. echo "文件无法保存.";
  1201. exit ( 0 );
  1202. }
  1203. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  1204. echo json_encode ( array (
  1205. 'filename' => $file_name,
  1206. 'id' => $nk
  1207. ) );
  1208. exit ( 0 );
  1209. }
  1210. /**
  1211. * 导入发票临时仓库
  1212. */
  1213. function invoiceStoreImport() {
  1214. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  1215. $trainingKey = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  1216. $path = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  1217. if ($path != "" && ! empty ( $trainingKey )) {
  1218. Doo::loadModel ( 'invoiceStore' );
  1219. Doo::loadModel ( 'staff' );
  1220. $staff = new staff ();
  1221. Doo::loadModel ( 'invoiceTraining' );
  1222. $invoiceTraining = new invoiceTraining ();
  1223. Doo::loadClass ( 'XDeode' );
  1224. $XDeode = new XDeode ( 5 );
  1225. $itid = $XDeode->decode ( $trainingKey );
  1226. // 培训班结算是否有和是否已经结算完成
  1227. Doo::loadModel ( 'receipt' );
  1228. $receipt = new receipt ();
  1229. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $itid );
  1230. if (! empty ( $receiptDetail )) {
  1231. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9)
  1232. die ( 'illegal request--status' );
  1233. }
  1234. $exlArray = $this->formatExcelToArrayTrain ( DOO::conf ()->SITE_PATH . "upload/invoiceTraining/" . $path );
  1235. $userName = $this->staff [0] ['username'];
  1236. $sDetail = $staff->getStaffByName ( $userName );
  1237. //print_r($exlArray);die;
  1238. // die('sdd');
  1239. // 可以优化
  1240. foreach ( $exlArray as $key => $value ) {
  1241. // 开票
  1242. $invoice = new invoiceStore ();
  1243. $invoice->trainId = $itid;
  1244. $invoice->invoiceType = 0;
  1245. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  1246. $invoice->invoiceType = 1;
  1247. elseif($value ['invoiceType'] == '电子'){
  1248. $invoice->invoiceType = 0;
  1249. $invoice->invoiceForm=1;
  1250. }
  1251. $invoice->invoiceQuantity = $value ['invoiceQuantity'];
  1252. $invoice->invoiceUnitPrice = $value ['invoiceUnitPrice'];
  1253. $invoice->invoicePrice = $value ['invoiceQuantity'] * $value ['invoiceUnitPrice'];
  1254. $invoice->invoiceTitle = $value ['invoiceTitle'];
  1255. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  1256. $invoice->invoiceCompany = $value ['invoiceTitle'];
  1257. $invoice->userName = $userName;
  1258. $invoice->sid = $sDetail ['sid'];
  1259. $invoice->cid = $sDetail ['cid'];
  1260. $invoice->categoryName = $sDetail ['category'];
  1261. $invoice->invoiceElement = $value ['invoiceElement'];
  1262. $invoice->remark = $value ['remark'];
  1263. // $invoice->date = $value ['date'];
  1264. // $invoice->printTime = $value ['date'];
  1265. $invoice->ipSource = 1;
  1266. $invoice->printStatus = 0;
  1267. $invoice->status = 0;
  1268. $invoice->postStatus = 1;
  1269. $invoice->untreadStatus = 0;
  1270. // $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1271. $invoice->TIN = $value ['TIN'];
  1272. $invoice->address = $value ['address'];
  1273. $invoice->phone = $value ['phone'];
  1274. $invoice->bank = $value ['bank'];
  1275. $invoice->bankAccount = $value ['bankAccount'];
  1276. $invoice->recipientsAddress = $value ['recipientsAddress'];
  1277. $invoice->recipients = $value ['recipients'];
  1278. $invoice->recipientsPhone = $value ['recipientsPhone'];
  1279. $invoice->electronicPhone = $value ['electronicPhone'];
  1280. $invoice->electronicEmail = $value ['electronicEmail'];
  1281. $iid = $invoice->insert ();
  1282. }
  1283. // 加入发票总数量
  1284. $item = array (
  1285. 'itid' => $itid,
  1286. 'invoiceTotal' => count ( $exlArray )
  1287. );
  1288. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1289. return '/invoiceTrainingDetail/' . $trainingKey . ".html";
  1290. }
  1291. echo 'no file';
  1292. }
  1293. /**
  1294. * 编辑仓库里的发票
  1295. */
  1296. function invoiceStoreEdit() {
  1297. Doo::loadClass ( 'XDeode' );
  1298. $XDeode = new XDeode ( 5 );
  1299. $iid = isset ( $this->params ['storeKey'] ) ? $this->params ['storeKey'] : "";
  1300. $iid = $XDeode->decode ( $iid );
  1301. if (! is_numeric ( $iid ))
  1302. die ( 'illegal request' );
  1303. Doo::loadModel ( 'invoiceStore' );
  1304. $invoiceStore = new invoiceStore ();
  1305. $invoiceDetail = $invoiceStore->getInvoiceStoreByIsid ( $iid );
  1306. // print_r($invoiceDetail);
  1307. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  1308. $this->data ['invoiceDetail'] = $invoiceDetail;
  1309. $this->data ['memu'] = "invoice";
  1310. $this->data ['staff'] = $this->staff;
  1311. $this->data ['receiptMemu'] = 'invoiceTraining';
  1312. $this->render ( "/admin/invoiceStoreEdit", $this->data );
  1313. }
  1314. function invoiceStoreEditDo() {
  1315. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1316. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1317. Doo::loadModel ( 'invoiceStore' );
  1318. $invoice = new invoiceStore ();
  1319. Doo::loadClass ( 'XDeode' );
  1320. $XDeode = new XDeode ( 5 );
  1321. $iid = $XDeode->decode ( $storeKey );
  1322. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1323. die ( 'illegal request' );
  1324. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  1325. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  1326. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  1327. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  1328. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  1329. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  1330. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  1331. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  1332. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  1333. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  1334. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  1335. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  1336. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  1337. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  1338. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1339. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1340. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1341. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1342. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  1343. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  1344. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  1345. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  1346. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  1347. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  1348. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1349. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1350. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1351. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1352. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1353. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1354. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1355. $electronicPhone = $this->get_args ( 'electronicPhone' ) ? $this->get_args ( 'electronicPhone' ) : "";
  1356. $electronicEmail = $this->get_args ( 'electronicEmail' ) ? $this->get_args ( 'electronicEmail' ) : "";
  1357. $invoiceForm = $this->get_args ( 'invoiceForm' ) ? $this->get_args ( 'invoiceForm' ) : "";
  1358. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  1359. $cid = explode ( ':', $cid );
  1360. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  1361. $item = array (
  1362. 'isid' => $iid,
  1363. 'cid' => $cid [0],
  1364. 'categoryName' => $cid [1],
  1365. 'invoiceElement' => $invoiceElement,
  1366. 'invoiceQuantity' => $invoiceQuantity,
  1367. 'invoiceUnitPrice' => $invoiceUnitPrice,
  1368. 'invoicePrice' => $invoicePrice,
  1369. 'invoiceType' => $invoiceType,
  1370. 'doPost' => $doPost,
  1371. 'status' => 1,
  1372. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1373. 'remark' => $remark
  1374. );
  1375. if ($invoiceType == 0)
  1376. $item += array (
  1377. 'invoiceTitle' => $invoiceTitle,
  1378. 'TIN' => $TINT,
  1379. 'address' => $addressT,
  1380. 'phone' => $phoneT,
  1381. 'bank' => $bankT,
  1382. 'bankAccount' => $bankAccountT
  1383. );
  1384. else {
  1385. $item += array (
  1386. 'invoiceCompany' => $invoiceCompany,
  1387. 'TIN' => $TIN,
  1388. 'address' => $address,
  1389. 'phone' => $phone,
  1390. 'bank' => $bank,
  1391. 'bankAccount' => $bankAccount
  1392. );
  1393. }
  1394. if($invoiceForm=='paper'){
  1395. $item += array (
  1396. 'invoiceForm' => 0
  1397. );
  1398. }elseif($invoiceForm=='electronic'){
  1399. $item += array (
  1400. 'invoiceForm' => 1,
  1401. 'electronicPhone' => $electronicPhone,
  1402. 'electronicEmail' => $electronicEmail,
  1403. );
  1404. }
  1405. if ($doPost == 1) {
  1406. $mailList = array (
  1407. 'invoice' => 1,
  1408. 'mailItems' => $mailItems
  1409. );
  1410. if (! empty ( $softLock ))
  1411. $mailList += array (
  1412. 'softLock' => $softLockNum
  1413. );
  1414. else
  1415. $mailList += array (
  1416. 'softLock' => '0'
  1417. );
  1418. if (! empty ( $contract ))
  1419. $mailList += array (
  1420. 'contract' => $contractNum
  1421. );
  1422. else
  1423. $mailList += array (
  1424. 'contract' => '0'
  1425. );
  1426. if (! empty ( $instructions ))
  1427. $mailList += array (
  1428. 'instructions' => $instructionsNum
  1429. );
  1430. else
  1431. $mailList += array (
  1432. 'instructions' => '0'
  1433. );
  1434. if (! empty ( $remittance ))
  1435. $mailList += array (
  1436. 'remittance' => $remittance
  1437. );
  1438. else
  1439. $mailList += array (
  1440. 'remittance' => ''
  1441. );
  1442. $mailString = '发票x1,备注:' . $mailItems;
  1443. if (! empty ( $softLock ))
  1444. $mailString .= ',软件锁x' . $softLockNum;
  1445. if (! empty ( $contract ))
  1446. $mailString .= ',合同x' . $contractNum;
  1447. if (! empty ( $instructions ))
  1448. $mailString .= ',说明书x' . $instructionsNum;
  1449. if (! empty ( $remittance ))
  1450. $mailString .= ',汇款账号单';
  1451. $item += array (
  1452. 'recipients' => $recipients,
  1453. 'recipientsPhone' => $recipientsPhone,
  1454. 'recipientsAddress' => $recipientsAddress,
  1455. 'mailItems' => $mailString,
  1456. 'mailItemsJson' => json_encode ( $mailList )
  1457. );
  1458. }
  1459. $invoice->setInvoiceStoreByCondition ( $item );
  1460. }
  1461. if(!empty($invoiceForm)&&$invoiceForm=='electronic'){
  1462. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1463. }else{
  1464. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1465. }
  1466. }
  1467. /**
  1468. *
  1469. * @return string
  1470. */
  1471. function invoiceStoreDelete() {
  1472. Doo::loadClass ( 'XDeode' );
  1473. $XDeode = new XDeode ( 5 );
  1474. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1475. $iStoreKey = $this->get_args ( 'iStoreKey' ) ? $this->get_args ( 'iStoreKey' ) : 0;
  1476. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1477. $isid = $XDeode->decode ( $iStoreKey );
  1478. $itid = $XDeode->decode ( $trainKey );
  1479. if (! is_numeric ( $isid ))
  1480. die ( 'illegal request' );
  1481. Doo::loadModel ( 'invoiceStore' );
  1482. $invoiceStore = new invoiceStore ();
  1483. $invoiceStore->delete ( array (
  1484. 'where' => 'isid=' . $isid,
  1485. 'limit' => 1
  1486. ) );
  1487. Doo::loadModel ( 'invoiceTraining' );
  1488. $invoiceTraining = new invoiceTraining ();
  1489. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1490. $item = array (
  1491. 'itid' => $itid,
  1492. 'invoiceTotal' => $itDetail ['invoiceTotal'] - 1
  1493. );
  1494. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1495. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1496. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1497. }else{
  1498. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1499. }
  1500. }
  1501. /**
  1502. * 批量删除库里发票
  1503. */
  1504. function invoiceStoreBatchDelete() {
  1505. Doo::loadClass ( 'XDeode' );
  1506. $XDeode = new XDeode ( 5 );
  1507. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1508. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1509. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1510. if (empty ( $trainKey ) || empty ( $storeKey ))
  1511. die ( 'illegal request-IdKey' );
  1512. $tid = $XDeode->decode ( $trainKey );
  1513. if (! is_numeric ( $tid ) && ! empty ( $storeKey ))
  1514. die ( 'illegal request' );
  1515. Doo::loadModel ( 'invoiceStore' );
  1516. $isidKeyList = explode ( ',', $storeKey );
  1517. $isidList = array ();
  1518. foreach ( $isidKeyList as $value ) {
  1519. $isid = $XDeode->decode ( $value );
  1520. if (! empty ( $isid ) && is_numeric ( $isid ))
  1521. array_push ( $isidList, $isid );
  1522. }
  1523. $isidString = implode ( ',', $isidList );
  1524. $invoiceStore = new invoiceStore ();
  1525. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,apStatus' );
  1526. $isidList = array ();
  1527. foreach ( $isList as $key => $value ) {
  1528. if ($value ['apStatus'] == 0)
  1529. array_push ( $isidList, $value ['isid'] );
  1530. }
  1531. $isidString = implode ( ',', $isidList );
  1532. // print_r($isList);
  1533. // echo $isidString;
  1534. $invoiceStore = new invoiceStore ();
  1535. $invoiceStore->delete ( array (
  1536. 'where' => "isid in ( " . $isidString . ")",
  1537. 'asArray' => TRUE
  1538. ) );
  1539. Doo::loadModel ( 'invoiceTraining' );
  1540. $invoiceTraining = new invoiceTraining ();
  1541. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1542. $item = array (
  1543. 'itid' => $tid,
  1544. 'invoiceTotal' => $itDetail ['invoiceTotal'] - count ( $isidList )
  1545. );
  1546. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1547. // echo $tid;
  1548. // echo $storeKey;
  1549. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1550. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1551. }else{
  1552. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1553. }
  1554. }
  1555. function invoiceStoreBatchElectronicPhone(){
  1556. $electronicPhone = $this->get_args ( 'electronicPhone' ) ? $this->get_args ( 'electronicPhone' ) : '';
  1557. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1558. Doo::loadClass ( 'XDeode' );
  1559. $XDeode = new XDeode ( 5 );
  1560. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1561. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1562. if (empty ( $trainKey ) || empty ( $storeKey ))
  1563. die ( 'illegal request-IdKey' );
  1564. $isidKeyList = explode ( ',', $storeKey );
  1565. $isidList = array ();
  1566. foreach ( $isidKeyList as $value ) {
  1567. $isid = $XDeode->decode ( $value );
  1568. if (! empty ( $isid ) && is_numeric ( $isid ))
  1569. array_push ( $isidList, $isid );
  1570. }
  1571. $isidString = implode ( ',', $isidList );
  1572. $trainId = $XDeode->decode ( $trainKey );
  1573. if (! is_numeric ( $isid ))
  1574. die ( 'illegal request--isid' );
  1575. Doo::loadModel ( 'invoiceStore' );
  1576. $invoiceStore = new invoiceStore ();
  1577. $item = array (
  1578. 'electronicPhone' => $electronicPhone
  1579. );
  1580. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1581. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1582. }
  1583. function invoiceStoreBatchElectronicEmail(){
  1584. $electronicEmail = $this->get_args ( 'electronicEmail' ) ? $this->get_args ( 'electronicEmail' ) : '';
  1585. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1586. Doo::loadClass ( 'XDeode' );
  1587. $XDeode = new XDeode ( 5 );
  1588. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1589. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1590. if (empty ( $trainKey ) || empty ( $storeKey ))
  1591. die ( 'illegal request-IdKey' );
  1592. $isidKeyList = explode ( ',', $storeKey );
  1593. $isidList = array ();
  1594. foreach ( $isidKeyList as $value ) {
  1595. $isid = $XDeode->decode ( $value );
  1596. if (! empty ( $isid ) && is_numeric ( $isid ))
  1597. array_push ( $isidList, $isid );
  1598. }
  1599. $isidString = implode ( ',', $isidList );
  1600. $trainId = $XDeode->decode ( $trainKey );
  1601. if (! is_numeric ( $isid ))
  1602. die ( 'illegal request' );
  1603. Doo::loadModel ( 'invoiceStore' );
  1604. $invoiceStore = new invoiceStore ();
  1605. $item = array (
  1606. 'electronicEmail' => $electronicEmail
  1607. );
  1608. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1609. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1610. }
  1611. /**
  1612. * 仓库发票提交审批
  1613. * @return string
  1614. */
  1615. function invoiceStoreApproval() {
  1616. Doo::loadClass ( 'XDeode' );
  1617. $XDeode = new XDeode ( 5 );
  1618. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1619. $iStoreKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1620. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1621. $isid = $XDeode->decode ( $iStoreKey );
  1622. $trainId = $XDeode->decode ( $trainKey );
  1623. if (! is_numeric ( $isid ))
  1624. die ( 'illegal request' );
  1625. Doo::loadModel ( 'invoiceStore' );
  1626. Doo::loadModel ( 'invoice' );
  1627. $invoice = new invoice ();
  1628. // 加入限制必须填写入开票内容和邮寄物品
  1629. $invoiceStore = new invoiceStore ();
  1630. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid, 'isid,trainId ,invoiceElement,mailItemsJson,electronicPhone,electronicEmail' );
  1631. if (empty ( $isDetail ['invoiceElement'] ) || empty ( $isDetail ['mailItemsJson'] )) {
  1632. header ( 'Content-Type:text/html;charset=utf-8' );
  1633. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1634. }
  1635. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1636. if (empty ( $isDetail ['electronicPhone'] ) && empty ( $isDetail ['electronicEmail'] )) {
  1637. header ( 'Content-Type:text/html;charset=utf-8' );
  1638. die ( 'illegal request! 请设置电子开票的收件人手机或者邮箱' );
  1639. }
  1640. }
  1641. // 拷贝插入一条发票数据
  1642. $invoiceStore = new invoiceStore ();
  1643. $iid = $invoiceStore->setInvoiceStoreToApproval ( $isid );
  1644. $invoiceStore = new invoiceStore ();
  1645. $item = array (
  1646. 'isid' => $isid,
  1647. 'iid' => $iid,
  1648. 'apStatus' => 1
  1649. );
  1650. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1651. Doo::loadModel ( 'invoiceManage' );
  1652. $invoiceManage = new invoiceManage ();
  1653. Doo::loadModel ( 'invoiceOperationLog' );
  1654. $invoiceOperationLog = new invoiceOperationLog ();
  1655. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1656. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1657. $moldManage = array ();
  1658. foreach ( $invoiceManageList as $key => $value ) {
  1659. if ($value ['mold'] == '发票打印')
  1660. $moldManage [$value ['mold']] = $value ['staffList'];
  1661. elseif ($value ['mold'] == '发票邮寄')
  1662. $moldManage [$value ['mold']] = $value ['staffList'];
  1663. elseif ($value ['mold'] == '发票退票')
  1664. $moldManage [$value ['mold']] = $value ['staffList'];
  1665. }
  1666. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1667. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1668. $invoiceSerial="#FE" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1669. }else{
  1670. $invoiceSerial="#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1671. }
  1672. $item = array (
  1673. 'iid' => $iid,
  1674. 'isid' => $isid,
  1675. 'invoiceSerial' => $invoiceSerial,
  1676. 'date' => date ( "Y-m-d H:i:s" ),
  1677. 'status' => 1,
  1678. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1679. 'trainId' => $trainId,
  1680. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1681. 'moldManage' => json_encode ( $moldManage ),
  1682. 'settlementType' => 1,
  1683. 'pendingApprovals' => $pendingApprovalsSid
  1684. );
  1685. $invoice->setInvoiceByCondition ( $item );
  1686. Doo::loadModel ( 'invoiceTraining' );
  1687. $invoiceTraining = new invoiceTraining ();
  1688. $item = array (
  1689. 'itid' => $trainId,
  1690. 'submitStatus' => 1
  1691. );
  1692. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1693. $item = array (
  1694. 'date' => date ( "Y-m-d H:i:s" ),
  1695. 'operation' => "创建",
  1696. 'status' => 1,
  1697. 'img' => $this->staff [0] ['avatar'],
  1698. 'username' => $this->staff [0] ['username'],
  1699. 'uid' => $this->staff [0] ['sid'],
  1700. 'category' => $this->staff [0] ['category'],
  1701. 'iid' => $iid
  1702. );
  1703. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1704. $item = array (
  1705. 'date' => date ( "Y-m-d H:i:s" ),
  1706. 'operation' => "提交审批",
  1707. 'status' => 1,
  1708. 'img' => $this->staff [0] ['avatar'],
  1709. 'username' => $this->staff [0] ['username'],
  1710. 'uid' => $this->staff [0] ['sid'],
  1711. 'category' => $this->staff [0] ['category'],
  1712. 'iid' => $iid
  1713. );
  1714. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1715. Doo::loadModel ( 'staff' );
  1716. $staff = new staff ();
  1717. $username2 = $staff->getOne ( array (
  1718. 'select' => 'wxid',
  1719. 'where' => 'sid=' . $pendingApprovalsSid,
  1720. 'asArray' => TRUE
  1721. ) );
  1722. // 发送微信审批通知
  1723. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1724. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1725. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1726. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1727. }else{
  1728. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1729. }
  1730. }
  1731. /**
  1732. * 批量提交发票
  1733. * @return string
  1734. */
  1735. function invoiceStoreBatchApproval() {
  1736. Doo::loadClass ( 'XDeode' );
  1737. $XDeode = new XDeode ( 5 );
  1738. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1739. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1740. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : '';
  1741. if (empty ( $trainKey ) || empty ( $storeKey ))
  1742. die ( 'illegal request-IdKey' );
  1743. $trainId = $XDeode->decode ( $trainKey );
  1744. $isidKeyList = explode ( ',', $storeKey );
  1745. $isidList = array ();
  1746. foreach ( $isidKeyList as $value ) {
  1747. $isid = $XDeode->decode ( $value );
  1748. if (! empty ( $isid ) && is_numeric ( $isid ))
  1749. array_push ( $isidList, $isid );
  1750. }
  1751. $isidString = implode ( ',', $isidList );
  1752. if (! is_numeric ( $trainId ))
  1753. die ( 'illegal request' );
  1754. Doo::loadModel ( 'invoiceStore' );
  1755. Doo::loadModel ( 'invoice' );
  1756. // 判断哪些已经加入审批过
  1757. // 加入限制必须填写入开票内容和邮寄物品
  1758. $invoiceStore = new invoiceStore ();
  1759. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,trainId ,invoiceElement,mailItemsJson,electronicPhone,electronicEmail,invoiceForm' );
  1760. foreach ( $isList as $key => $value ) {
  1761. if (empty ( $value ['invoiceElement'] ) || empty ( $value ['mailItemsJson'] )) {
  1762. header ( 'Content-Type:text/html;charset=utf-8' );
  1763. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1764. }
  1765. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic' ){
  1766. $value ['electronicPhone']=trim($value ['electronicPhone']);
  1767. $value ['electronicEmail']=trim($value ['electronicEmail']);
  1768. if(empty ( $value ['electronicPhone'] )&&empty ( $value ['electronicEmail'] )){
  1769. header ( 'Content-Type:text/html;charset=utf-8' );
  1770. die ( 'illegal request! 请设置电子开票的收件人手机或者邮箱' );
  1771. }
  1772. }
  1773. }
  1774. // 拷贝插入一条发票数据
  1775. $invoiceStore = new invoiceStore ();
  1776. $invoiceStore->setInvoiceStoreBatchToApproval ( $isidString );
  1777. $invoiceStore = new invoiceStore ();
  1778. $item = array (
  1779. 'apStatus' => 1
  1780. );
  1781. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1782. // 获得正式发票ID
  1783. $invoice = new invoice ();
  1784. $iidList = $invoice->getInvoiceByIstoreid ( $isidString, 'iid,isid' );
  1785. $sqlList = array ();
  1786. $iidString = '';
  1787. $iida = array ();
  1788. foreach ( $iidList as $key => $value ) {
  1789. $sqlList [$value ['isid']] = $value ['iid'];
  1790. array_push ( $iida, $value ['iid'] );
  1791. }
  1792. $iidString = implode ( ',', $iida );
  1793. $ids = implode ( ',', array_keys ( $sqlList ) );
  1794. $sql = "UPDATE CLD_invoiceStore SET iid = CASE isid ";
  1795. foreach ( $sqlList as $id => $ordinal ) {
  1796. $sql .= sprintf ( "WHEN %d THEN %d ", $id, $ordinal );
  1797. }
  1798. $sql .= "END WHERE isid IN ($ids)";
  1799. $invoiceStore = new invoiceStore ();
  1800. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1801. Doo::loadModel ( 'invoiceManage' );
  1802. $invoiceManage = new invoiceManage ();
  1803. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1804. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1805. $moldManage = array ();
  1806. foreach ( $invoiceManageList as $key => $value ) {
  1807. if ($value ['mold'] == '发票打印')
  1808. $moldManage [$value ['mold']] = $value ['staffList'];
  1809. elseif ($value ['mold'] == '发票邮寄')
  1810. $moldManage [$value ['mold']] = $value ['staffList'];
  1811. elseif ($value ['mold'] == '发票退票')
  1812. $moldManage [$value ['mold']] = $value ['staffList'];
  1813. }
  1814. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1815. // 批量更新发票信息
  1816. $item = array (
  1817. 'date' => date ( "Y-m-d H:i:s" ),
  1818. 'status' => 1,
  1819. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1820. 'trainId' => $trainId,
  1821. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1822. 'moldManage' => json_encode ( $moldManage ),
  1823. 'settlementType' => 1,
  1824. 'pendingApprovals' => $pendingApprovalsSid
  1825. );
  1826. $invoice = new invoice ();
  1827. $invoice->BatchInvoiceByCondition ( $item, $iidString );
  1828. // 批量更新发票中仓库isid
  1829. $sql = "UPDATE CLD_invoiceStore SET isid = CASE iid ";
  1830. foreach ( $sqlList as $isid => $iid ) {
  1831. $sql .= sprintf ( "WHEN %d THEN %d ", $iid, $isid );
  1832. }
  1833. $sql .= "END WHERE iid IN ($iidString)";
  1834. $invoice = new invoice ();
  1835. $invoice->UpdateBatchInvoice ( $sql );
  1836. // 批量更新发票序列号
  1837. $sqlList = array ();
  1838. foreach ( $iida as $value ) {
  1839. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1840. $sqlList [$value] = "#FE" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1841. }else{
  1842. $sqlList [$value] = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1843. }
  1844. }
  1845. $ids = implode ( ',', array_keys ( $sqlList ) );
  1846. $sql = "UPDATE CLD_invoice SET invoiceSerial = CASE iid ";
  1847. foreach ( $sqlList as $id => $ordinal ) {
  1848. $sql .= sprintf ( "WHEN %d THEN '%s' ", $id, $ordinal );
  1849. }
  1850. $sql .= "END WHERE iid IN ($ids)";
  1851. $invoiceStore = new invoiceStore ();
  1852. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1853. // 批量生产操作日志
  1854. Doo::loadModel ( 'invoiceOperationLog' );
  1855. $sqlList = array ();
  1856. foreach ( $iida as $key => $value ) {
  1857. $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 . '"),
  1858. ("' . 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 . '") ';
  1859. array_push ( $sqlList, $sql );
  1860. }
  1861. $iolSql = implode ( ',', $sqlList );
  1862. $sql = "INSERT INTO `CLD_invoiceOperationLog` (`date`, `operation`, `status`, `img`, `username`, `uid`, `category`, `iid`) VALUES " . $iolSql;
  1863. $invoiceOperationLog = new invoiceOperationLog ();
  1864. $invoiceOperationLog->setInvoiceOperationLogBySql ( $sql );
  1865. Doo::loadModel ( 'invoiceTraining' );
  1866. $invoiceTraining = new invoiceTraining ();
  1867. $item = array (
  1868. 'itid' => $trainId,
  1869. 'submitStatus' => 1
  1870. );
  1871. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1872. Doo::loadModel ( 'staff' );
  1873. $staff = new staff ();
  1874. $username2 = $staff->getOne ( array (
  1875. 'select' => 'wxid',
  1876. 'where' => 'sid=' . $pendingApprovalsSid,
  1877. 'asArray' => TRUE
  1878. ) );
  1879. // 发送微信审批通知
  1880. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1881. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1882. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1883. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1884. }else{
  1885. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1886. }
  1887. }
  1888. /**
  1889. */
  1890. function invoiceStoreMailItemSet() {
  1891. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1892. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1893. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1894. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1895. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1896. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1897. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1898. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1899. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1900. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1901. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1902. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1903. Doo::loadClass ( 'XDeode' );
  1904. $XDeode = new XDeode ( 5 );
  1905. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1906. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1907. $isid = $XDeode->decode ( $storeKey );
  1908. $trainId = $XDeode->decode ( $trainKey );
  1909. if (! is_numeric ( $isid ))
  1910. die ( 'illegal request' );
  1911. Doo::loadModel ( 'invoiceStore' );
  1912. $invoiceStore = new invoiceStore ();
  1913. $mailList = array (
  1914. 'mailItems' => $mailItems
  1915. );
  1916. $mailString = '发票x1,备注:' . $mailItems;
  1917. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1918. $mailString = '备注:' . $mailItems;
  1919. }else{
  1920. $mailList += array (
  1921. 'invoice' => 1,
  1922. );
  1923. }
  1924. if (! empty ( $softLock ))
  1925. $mailList += array (
  1926. 'softLock' => $softLockNum
  1927. );
  1928. else
  1929. $mailList += array (
  1930. 'softLock' => 0
  1931. );
  1932. if (! empty ( $contract ))
  1933. $mailList += array (
  1934. 'contract' => $contractNum
  1935. );
  1936. else
  1937. $mailList += array (
  1938. 'contract' => 0
  1939. );
  1940. if (! empty ( $instructions ))
  1941. $mailList += array (
  1942. 'instructions' => $instructionsNum
  1943. );
  1944. else
  1945. $mailList += array (
  1946. 'instructions' => 0
  1947. );
  1948. if (! empty ( $remittance ))
  1949. $mailList += array (
  1950. 'remittance' => $remittance
  1951. );
  1952. else
  1953. $mailList += array (
  1954. 'remittance' => ''
  1955. );
  1956. if (! empty ( $softLock ))
  1957. $mailString .= ',软件锁x' . $softLockNum;
  1958. if (! empty ( $contract ))
  1959. $mailString .= ',合同x' . $contractNum;
  1960. if (! empty ( $instructions ))
  1961. $mailString .= ',说明书x' . $instructionsNum;
  1962. if (! empty ( $remittance ))
  1963. $mailString .= ',汇款账号单';
  1964. $item = array (
  1965. 'isid' => $isid,
  1966. 'doPost' => 1,
  1967. 'mailItems' => $mailString,
  1968. 'mailItemsJson' => json_encode ( $mailList )
  1969. );
  1970. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1971. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1972. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1973. }else{
  1974. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1975. }
  1976. }
  1977. /**
  1978. * 批量设置邮寄物品
  1979. */
  1980. function invoiceStoreBatchMailItemSet() {
  1981. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1982. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1983. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1984. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1985. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1986. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1987. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1988. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1989. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1990. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1991. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1992. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1993. Doo::loadClass ( 'XDeode' );
  1994. $XDeode = new XDeode ( 5 );
  1995. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1996. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1997. if (empty ( $trainKey ) || empty ( $storeKey ))
  1998. die ( 'illegal request-IdKey' );
  1999. $isidKeyList = explode ( ',', $storeKey );
  2000. $isidList = array ();
  2001. foreach ( $isidKeyList as $value ) {
  2002. $isid = $XDeode->decode ( $value );
  2003. if (! empty ( $isid ) && is_numeric ( $isid ))
  2004. array_push ( $isidList, $isid );
  2005. }
  2006. $isidString = implode ( ',', $isidList );
  2007. $trainId = $XDeode->decode ( $trainKey );
  2008. if (! is_numeric ( $isid ))
  2009. die ( 'illegal request' );
  2010. Doo::loadModel ( 'invoiceStore' );
  2011. $invoiceStore = new invoiceStore ();
  2012. $mailList = array (
  2013. 'mailItems' => $mailItems
  2014. );
  2015. $mailString = '发票x1,备注:' . $mailItems;
  2016. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  2017. $mailString = '备注:' . $mailItems;
  2018. }else{
  2019. $mailList += array (
  2020. 'invoice' => 1,
  2021. );
  2022. }
  2023. if (! empty ( $softLock ))
  2024. $mailList += array (
  2025. 'softLock' => $softLockNum
  2026. );
  2027. else
  2028. $mailList += array (
  2029. 'softLock' => 0
  2030. );
  2031. if (! empty ( $contract ))
  2032. $mailList += array (
  2033. 'contract' => $contractNum
  2034. );
  2035. else
  2036. $mailList += array (
  2037. 'contract' => 0
  2038. );
  2039. if (! empty ( $instructions ))
  2040. $mailList += array (
  2041. 'instructions' => $instructionsNum
  2042. );
  2043. else
  2044. $mailList += array (
  2045. 'instructions' => 0
  2046. );
  2047. if (! empty ( $remittance ))
  2048. $mailList += array (
  2049. 'remittance' => $remittance
  2050. );
  2051. else
  2052. $mailList += array (
  2053. 'remittance' => ''
  2054. );
  2055. if (! empty ( $softLock ))
  2056. $mailString .= ',软件锁x' . $softLockNum;
  2057. if (! empty ( $contract ))
  2058. $mailString .= ',合同x' . $contractNum;
  2059. if (! empty ( $instructions ))
  2060. $mailString .= ',说明书x' . $instructionsNum;
  2061. if (! empty ( $remittance ))
  2062. $mailString .= ',汇款账号单';
  2063. $item = array (
  2064. 'doPost' => 1,
  2065. 'mailItems' => $mailString,
  2066. 'mailItemsJson' => json_encode ( $mailList )
  2067. );
  2068. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  2069. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  2070. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  2071. }else{
  2072. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  2073. }
  2074. }
  2075. /**
  2076. * 废弃
  2077. */
  2078. function ajaxGetMailItemByIstore() {
  2079. Doo::loadClass ( 'XDeode' );
  2080. $XDeode = new XDeode ( 5 );
  2081. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  2082. $isid = $XDeode->decode ( $storeKey );
  2083. if (! is_numeric ( $isid ))
  2084. die ( 'illegal request' );
  2085. Doo::loadModel ( 'invoiceStore' );
  2086. $invoiceStore = new invoiceStore ();
  2087. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid );
  2088. $isDetail ['mailItemsJson'] = json_decode ( $isDetail ['mailItemsJson'], true );
  2089. echo json_encode ( $isDetail ['mailItemsJson'] );
  2090. exit ();
  2091. }
  2092. /**
  2093. * 终止开票
  2094. */
  2095. function invoiceDroppedDo() {
  2096. $droppedIidKey = $this->get_args ( 'droppedIidKey' ) ? $this->get_args ( 'droppedIidKey' ) : '';
  2097. Doo::loadModel ( 'invoice' );
  2098. $invoice = new invoice ();
  2099. Doo::loadModel ( 'invoiceOperationLog' );
  2100. $invoiceOperationLog = new invoiceOperationLog ();
  2101. $iid = $invoice->authcode ( $droppedIidKey );
  2102. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2103. die ( 'illegal request' );
  2104. $item = array (
  2105. 'iid' => $iid,
  2106. 'status' => 4,
  2107. 'updateTime' => date ( "Y-m-d H:i:s" )
  2108. );
  2109. $invoice->setInvoiceByCondition ( $item );
  2110. $item = array (
  2111. 'date' => date ( "Y-m-d H:i:s" ),
  2112. 'operation' => '终止了开票',
  2113. 'status' => 4,
  2114. 'img' => $this->staff [0] ['avatar'],
  2115. 'username' => $this->staff [0] ['username'],
  2116. 'uid' => $this->staff [0] ['sid'],
  2117. 'category' => $this->staff [0] ['category'],
  2118. 'iid' => $iid
  2119. );
  2120. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2121. return "/invoice";
  2122. }
  2123. /**
  2124. * 更新退票的邮寄信息
  2125. */
  2126. function invoiceUntreadMailDo() {
  2127. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  2128. $untreadCompany = $this->get_args ( 'untreadCompany' ) ? $this->get_args ( 'untreadCompany' ) : "";
  2129. $untreadNumber = $this->get_args ( 'untreadNumber' ) ? $this->get_args ( 'untreadNumber' ) : "";
  2130. $untreadItems = $this->get_args ( 'untreadItems' ) ? $this->get_args ( 'untreadItems' ) : "";
  2131. Doo::loadModel ( 'invoice' );
  2132. $invoice = new invoice ();
  2133. $iid = $invoice->authcode ( $untreadIidKey );
  2134. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2135. die ( 'illegal request' );
  2136. $item = array (
  2137. 'iid' => $iid,
  2138. 'untreadCompany' => $untreadCompany,
  2139. 'untreadNumber' => $untreadNumber,
  2140. 'untreadItems' => $untreadItems
  2141. );
  2142. $invoice->setInvoiceByCondition ( $item );
  2143. return "/invoice";
  2144. }
  2145. /**
  2146. * 申请退票 --
  2147. */
  2148. function invoiceUntreadDo() {
  2149. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  2150. $untreadReason = $this->get_args ( 'untreadReason' ) ? $this->get_args ( 'untreadReason' ) : "";
  2151. $untreadPost = $this->get_args ( 'untreadPost' ) ? $this->get_args ( 'untreadPost' ) : 0;
  2152. Doo::loadModel ( 'invoice' );
  2153. $invoice = new invoice ();
  2154. Doo::loadModel ( 'invoiceOperationLog' );
  2155. $invoiceOperationLog = new invoiceOperationLog ();
  2156. Doo::loadModel ( 'invoiceReceivables' );
  2157. $invoiceReceivables = new invoiceReceivables ();
  2158. $iid = $invoice->authcode ( $untreadIidKey );
  2159. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2160. die ( 'illegal request' );
  2161. /*
  2162. * 需求变革 有绑定收款也可以退票 $lt = $invoiceReceivables->getInvoiceReceivablesByIid ( $untreadIidKey ); if (! empty ( $lt )) { header ( 'Content-Type:text/html;charset=utf-8' ); die ( '该发票有收款绑定,请先移除!' ); }
  2163. */
  2164. $item = array (
  2165. 'iid' => $iid,
  2166. 'untreadStatus' => 1,
  2167. 'untreadReason' => $untreadReason,
  2168. 'untreadPost' => $untreadPost,
  2169. 'updateTime' => date ( "Y-m-d H:i:s" )
  2170. );
  2171. $invoice->setInvoiceByCondition ( $item );
  2172. $item = array (
  2173. 'date' => date ( "Y-m-d H:i:s" ),
  2174. 'operation' => '申请退票',
  2175. 'status' => 7,
  2176. 'img' => $this->staff [0] ['avatar'],
  2177. 'username' => $this->staff [0] ['username'],
  2178. 'uid' => $this->staff [0] ['sid'],
  2179. 'category' => $this->staff [0] ['category'],
  2180. 'iid' => $iid
  2181. );
  2182. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2183. return "/invoice";
  2184. }
  2185. /**
  2186. * 删除已终止的开票
  2187. */
  2188. function invoiceDelDo() {
  2189. Doo::loadModel ( 'invoice' );
  2190. $invoice = new invoice ();
  2191. Doo::loadModel ( 'invoiceOperationLog' );
  2192. $invoiceOperationLog = new invoiceOperationLog ();
  2193. Doo::loadClass ( 'XDeode' );
  2194. $XDeode = new XDeode ( 5 );
  2195. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  2196. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  2197. $iid = $XDeode->decode ( $iid );
  2198. Doo::loadModel ( 'invoiceStore' );
  2199. $invoiceStore = new invoiceStore ();
  2200. if (! is_numeric ( $iid ))
  2201. die ( 'illegal request' );
  2202. $invoiceDetail = $invoice->getMyInvoice ( $sid, $iid );
  2203. if (empty ( $invoiceDetail ))
  2204. die ( 'illegal request' );
  2205. $item = array (
  2206. 'iid' => $iid,
  2207. 'isDelete' => 1,
  2208. 'updateTime' => date ( "Y-m-d H:i:s" )
  2209. );
  2210. $invoice->setInvoiceByCondition ( $item );
  2211. $item = array (
  2212. 'date' => date ( "Y-m-d H:i:s" ),
  2213. 'operation' => '删除了已终止的发票',
  2214. 'status' => 4,
  2215. 'img' => $this->staff [0] ['avatar'],
  2216. 'username' => $this->staff [0] ['username'],
  2217. 'uid' => $this->staff [0] ['sid'],
  2218. 'category' => $this->staff [0] ['category'],
  2219. 'iid' => $iid
  2220. );
  2221. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2222. // 删除培训班发票仓库里的发票
  2223. $invoiceStore->delInvoiceStoreByIsid ( $invoiceDetail ['isid'] );
  2224. return "/invoice";
  2225. }
  2226. /**
  2227. */
  2228. function invoiceApproval() {
  2229. Doo::loadModel ( 'invoice' );
  2230. $invoice = new invoice ();
  2231. Doo::loadClass ( 'XDeode' );
  2232. $XDeode = new XDeode ( 5 );
  2233. Doo::loadModel ( 'staff' );
  2234. $staff = new staff ();
  2235. $invoiceList = $invoice->find ( array (
  2236. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  2237. 'desc' => 'iid',
  2238. 'limit' => 10,
  2239. 'asArray' => true
  2240. ) );
  2241. foreach ( $invoiceList as $key => $value ) {
  2242. $invoiceList [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2243. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2244. if (! empty ( $lastApprover )) {
  2245. $lastApproverKey = array_keys ( $lastApprover );
  2246. $lastApprover = end ( $lastApprover );
  2247. $staffDetail = $staff->getOne ( array (
  2248. 'where' => 'sid=' . end ( $lastApproverKey ),
  2249. 'asArray' => true
  2250. ) );
  2251. $lastApprover ['username'] = $staffDetail ['username'];
  2252. }
  2253. $invoiceList [$key] ['lastApprover'] = $lastApprover;
  2254. }
  2255. $ilist = $invoice->getInvoiceByProcessStatus ();
  2256. foreach ( $ilist as $key => $value ) {
  2257. $ilist [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2258. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2259. if (! empty ( $lastApprover )) {
  2260. $lastApproverKey = array_keys ( $lastApprover );
  2261. $lastApprover = end ( $lastApprover );
  2262. $staffDetail = $staff->getOne ( array (
  2263. 'where' => 'sid=' . end ( $lastApproverKey ),
  2264. 'asArray' => true
  2265. ) );
  2266. $lastApprover ['username'] = $staffDetail ['username'];
  2267. }
  2268. $ilist [$key] ['lastApprover'] = $lastApprover;
  2269. }
  2270. // print_r($ilist);
  2271. $this->data ['invoiceList'] = $invoiceList;
  2272. $this->data ['ilist'] = $ilist;
  2273. $this->data ['memu'] = "invoice";
  2274. $this->data ['staff'] = $this->staff;
  2275. $this->data ['receiptMemu'] = 'invoiceApproval';
  2276. $this->render ( "/admin/invoiceApproval", $this->data );
  2277. }
  2278. function invoiceDetail() {
  2279. Doo::loadClass ( 'XDeode' );
  2280. $XDeode = new XDeode ( 5 );
  2281. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  2282. $iid = $XDeode->decode ( $iid );
  2283. if (! is_numeric ( $iid ))
  2284. die ( 'illegal request' );
  2285. Doo::loadModel ( 'invoice' );
  2286. $invoice = new invoice ();
  2287. Doo::loadModel ( 'invoiceOperationLog' );
  2288. $invoiceOperationLog = new invoiceOperationLog ();
  2289. $invoiceDetail = $invoice->getOne ( array (
  2290. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'] . ' and iid=' . $iid,
  2291. 'asArray' => true
  2292. ) );
  2293. if (empty ( $invoiceDetail ))
  2294. die ( 'illegal request' );
  2295. if ($invoiceDetail ['settlementType'] == 1) {
  2296. Doo::loadModel ( 'invoiceTraining' );
  2297. $invoiceTraining = new invoiceTraining ();
  2298. $invoiceDetail ['invoiceTraining'] = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceDetail ['trainId'] );
  2299. }
  2300. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  2301. $this->data ['invoiceDetail'] = $invoiceDetail;
  2302. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  2303. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  2304. $this->data ['memu'] = "invoice";
  2305. $this->data ['staff'] = $this->staff;
  2306. $this->data ['receiptMemu'] = 'invoiceApproval';
  2307. $this->render ( "/admin/invoiceApprovalDetail", $this->data );
  2308. }
  2309. /**
  2310. * 对发票进行审批,其中操作有终止,退回,同意动作。操作成功并记录下操作日志
  2311. *
  2312. * @since 1.0.0
  2313. * @var integer iid 开票ID 已加密
  2314. * @var integer status 发票审批状态
  2315. * @var integer opintion 审批发票的意见
  2316. * @return string 如操作成功返回审批首页
  2317. */
  2318. function invoiceApprovalDo() {
  2319. Doo::loadModel ( 'invoice' );
  2320. $invoice = new invoice ();
  2321. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2322. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  2323. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  2324. $divApproval = $this->get_args ( 'divApproval' ) ? $this->get_args ( 'divApproval' ) : "";
  2325. $iid = $invoice->authcode ( $iid );
  2326. if (! is_numeric ( $iid ))
  2327. die ( 'illegal request' );
  2328. // && ! empty ( $opinion )
  2329. if (! empty ( $iid ) && ! empty ( $status )) {
  2330. if (! ($status == 2 || $status == 3 || $status == 4))
  2331. die ( 'illegal request' );
  2332. Doo::loadModel ( 'invoiceOperationLog' );
  2333. $invoiceOperationLog = new invoiceOperationLog ();
  2334. $invoiceDetail = $invoice->getOne ( array (
  2335. 'where' => 'status=1 and iid=' . $iid . ' and pendingApprovals=' . $this->staff [0] ['sid'],
  2336. 'asArray' => true
  2337. ) );
  2338. if (empty ( $invoiceDetail ))
  2339. die ( 'illegal request' );
  2340. $processApprovals = json_decode ( $invoiceDetail ['processApprovals'], true );
  2341. $invoiceManage = json_decode ( $invoiceDetail ['invoiceManage'], true );
  2342. if ($status == 3) {
  2343. $invoice->status = $status;
  2344. $item = array (
  2345. 'operation' => $opinion
  2346. );
  2347. } else {
  2348. if (empty ( $processApprovals )) {
  2349. $processApprovals = array (
  2350. $this->staff [0] ['sid'] => array (
  2351. 'date' => date ( "Y-m-d H:i:s" ),
  2352. 'opinion' => $opinion,
  2353. 'status' => $status
  2354. )
  2355. );
  2356. // var_dump(next($invoiceManage));
  2357. $nextInvoiceManage = next ( $invoiceManage );
  2358. // print_r($nextInvoiceManage);
  2359. if ($status != 4 && $nextInvoiceManage !== false)
  2360. $invoice->pendingApprovals = $nextInvoiceManage [0];
  2361. $invoice->processApprovals = json_encode ( $processApprovals );
  2362. // var_dump($invoice);
  2363. // print_r($invoiceManage);
  2364. } else {
  2365. $processApprovals [$this->staff [0] ['sid']] = array (
  2366. 'date' => date ( "Y-m-d H:i:s" ),
  2367. 'opinion' => $opinion,
  2368. 'status' => $status
  2369. );
  2370. $pendingApprovals = 0;
  2371. foreach ( $invoiceManage as $key => $value ) {
  2372. if ($value [0] == $this->staff [0] ['sid']) {
  2373. if (isset ( $invoiceManage [$key + 1] ))
  2374. $pendingApprovals = $invoiceManage [$key + 1] [0];
  2375. break;
  2376. }
  2377. }
  2378. if ($status != 4 && ! empty ( $pendingApprovals ))
  2379. $invoice->pendingApprovals = $pendingApprovals;
  2380. $invoice->processApprovals = json_encode ( $processApprovals );
  2381. }
  2382. $item = array (
  2383. 'operation' => $opinion
  2384. );
  2385. if (count ( $processApprovals ) == count ( $invoiceManage ) && $status != 4) {
  2386. $invoice->status = $status;
  2387. $invoice->pendingApprovals = 0;
  2388. $invoice->approvalTime = date ( "Y-m-d H:i:s" );
  2389. } elseif ($status == 4) {
  2390. $invoice->status = $status;
  2391. $item = array (
  2392. 'operation' => $opinion
  2393. );
  2394. }
  2395. }
  2396. $invoice->updateTime = date ( "Y-m-d H:i:s" );
  2397. $invoice->update ( array (
  2398. 'where' => 'iid=' . $iid
  2399. ) );
  2400. $item += array (
  2401. 'date' => date ( "Y-m-d H:i:s" ),
  2402. 'img' => $this->staff [0] ['avatar'],
  2403. 'username' => $this->staff [0] ['username'],
  2404. 'uid' => $this->staff [0] ['sid'],
  2405. 'category' => $this->staff [0] ['category'],
  2406. 'status' => $status,
  2407. 'iid' => $iid
  2408. );
  2409. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2410. if (empty ( $divApproval ))
  2411. return '/invoiceApproval';
  2412. else
  2413. return '/invoiceApprovalAchieve/PEND';
  2414. }
  2415. die ( 'illegal request' );
  2416. }
  2417. /**
  2418. * 展示需要打印的发票数据
  2419. *
  2420. * @since 1.0.0
  2421. */
  2422. function invoicePrint() {
  2423. Doo::loadModel ( 'invoice' );
  2424. $invoice = new invoice ();
  2425. Doo::loadClass ( 'XDeode' );
  2426. $XDeode = new XDeode ( 5 );
  2427. Doo::loadModel ( 'staff' );
  2428. $staff = new staff ();
  2429. $toPrint = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0 );
  2430. $printed = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 1 );
  2431. foreach ( $toPrint as $key => $value ) {
  2432. $toPrint [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2433. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2434. if (! empty ( $lastApprover )) {
  2435. $lastApproverKey = array_keys ( $lastApprover );
  2436. $lastApprover = end ( $lastApprover );
  2437. $staffDetail = $staff->getOne ( array (
  2438. 'where' => 'sid=' . end ( $lastApproverKey ),
  2439. 'asArray' => true
  2440. ) );
  2441. $lastApprover ['username'] = $staffDetail ['username'];
  2442. }
  2443. $toPrint [$key] ['lastApprover'] = $lastApprover;
  2444. }
  2445. foreach ( $printed as $key => $value ) {
  2446. $printed [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2447. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2448. if (! empty ( $lastApprover )) {
  2449. $lastApproverKey = array_keys ( $lastApprover );
  2450. $lastApprover = end ( $lastApprover );
  2451. $staffDetail = $staff->getOne ( array (
  2452. 'where' => 'sid=' . end ( $lastApproverKey ),
  2453. 'asArray' => true
  2454. ) );
  2455. $lastApprover ['username'] = $staffDetail ['username'];
  2456. }
  2457. $printed [$key] ['lastApprover'] = $lastApprover;
  2458. }
  2459. $this->data ['printed'] = $printed;
  2460. $this->data ['toPrint'] = $toPrint;
  2461. $this->data ['memu'] = "invoice";
  2462. $this->data ['staff'] = $this->staff;
  2463. $this->data ['receiptMemu'] = 'invoicePrint';
  2464. $this->render ( "/admin/invoicePrint", $this->data );
  2465. }
  2466. /**
  2467. * 展示发票打印的详情页面
  2468. *
  2469. * @since 1.0.0
  2470. */
  2471. function invoicePrintDetail() {
  2472. Doo::loadClass ( 'XDeode' );
  2473. $XDeode = new XDeode ( 5 );
  2474. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  2475. $iid = $XDeode->decode ( $iid );
  2476. if (! is_numeric ( $iid ))
  2477. die ( 'illegal request' );
  2478. Doo::loadModel ( 'invoice' );
  2479. $invoice = new invoice ();
  2480. Doo::loadModel ( 'invoiceOperationLog' );
  2481. $invoiceOperationLog = new invoiceOperationLog ();
  2482. Doo::loadModel ( 'invoicePaper' );
  2483. $invoicePaper = new invoicePaper ();
  2484. $invoiceDetail = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0, $iid );
  2485. if (empty ( $invoiceDetail ))
  2486. die ( 'illegal request' );
  2487. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $invoiceDetail ['invoiceType'],$invoiceDetail['invoiceForm'] );
  2488. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  2489. if ($invoiceDetail ['settlementType'] == 1) {
  2490. Doo::loadModel ( 'invoiceTraining' );
  2491. $invoiceTraining = new invoiceTraining ();
  2492. $invoiceDetail ['invoiceTraining'] = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceDetail ['trainId'] );
  2493. }
  2494. $this->data ['invoicePaperList'] = $invoicePaperList;
  2495. $this->data ['invoiceDetail'] = $invoiceDetail;
  2496. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  2497. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  2498. $this->data ['memu'] = "invoice";
  2499. $this->data ['staff'] = $this->staff;
  2500. $this->data ['receiptMemu'] = 'invoicePrint';
  2501. $this->render ( "/admin/invoicePrintDetail", $this->data );
  2502. }
  2503. /**
  2504. * 所有待打印 发票
  2505. */
  2506. function invoicePrintStayAchieve() {
  2507. Doo::loadModel ( 'invoice' );
  2508. $invoice = new invoice ();
  2509. Doo::loadClass ( 'XDeode' );
  2510. $XDeode = new XDeode ( 5 );
  2511. Doo::loadModel ( 'staff' );
  2512. $staff = new staff ();
  2513. $MebSea = $this->get_args ( 'MebSea' ) ? urldecode ( $this->get_args ( 'MebSea' ) ) : "";
  2514. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  2515. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  2516. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  2517. Doo::loadModel ( 'invoiceTraining' );
  2518. $invoiceTraining = new invoiceTraining ();
  2519. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  2520. $page_size = 12;
  2521. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2522. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : "ALL";
  2523. // $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : "ALL";
  2524. $get = "/" . $status;
  2525. $con = ' and status=2 ';
  2526. if ($status == 'TOPRINT')
  2527. $con = ' and status=2 and printStatus=0 ';
  2528. elseif ($status == 'PRINTED')
  2529. $con = ' and status=2 and printStatus=1';
  2530. if ($invoiceType == 'ORDINARY')
  2531. $con .= ' and invoiceType=0 ';
  2532. elseif ($invoiceType == 'SPECIAL')
  2533. $con .= ' and invoiceType=1 ';
  2534. if ($invoiceTrain == 'ORDINARY')
  2535. $con .= ' and trainId=0 ';
  2536. elseif ($invoiceTrain == 'TRAIN')
  2537. $con .= ' and trainId!=0 ';
  2538. if ($invoiceTrainName != 'ALL') {
  2539. $trainId = $XDeode->decode ( $invoiceTrainName );
  2540. if (is_numeric ( $trainId ))
  2541. $con .= ' and trainId =' . $trainId;
  2542. }
  2543. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2544. $dateArr = explode ( ':', $date );
  2545. $D1 = '';
  2546. $D2 = '';
  2547. if (! empty ( $date )) {
  2548. $D1 = $dateArr [0];
  2549. $D2 = $dateArr [1];
  2550. }
  2551. if (! empty ( $D1 ) && ! empty ( $D2 ) && ! empty ( $date ))
  2552. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2553. if (! empty ( $MebSea )) {
  2554. $con .= ' and ( invoiceNo like "%' . $MebSea . '%" or invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  2555. }
  2556. $pageinfo ['page'] = array (
  2557. 'previous' => ''
  2558. );
  2559. $get .= "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&invoiceType=" . urlencode ( $invoiceType ) . "&invoiceTrain=" . urlencode ( $invoiceTrain ) . "";
  2560. $sql = " (untreadStatus=0 or untreadStatus=3 or untreadStatus=4) and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  2561. $action = "invoicePrintStayAchieve";
  2562. //echo $sql;
  2563. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2564. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2565. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  2566. $this->data ['trainList'] = $trainList;
  2567. $this->data ['invoiceType'] = $invoiceType;
  2568. $this->data ['invoiceTrain'] = $invoiceTrain;
  2569. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  2570. $this->data ['MebSeaEn'] = $MebSea;
  2571. $this->data ['MebSea'] = urlencode ( $MebSea );
  2572. $this->data ['get'] = $get;
  2573. $this->data ['page'] = $pageinfo;
  2574. $this->data ['date'] = $date;
  2575. $this->data ['status'] = $status;
  2576. $this->data ['invoiceType'] = $invoiceType;
  2577. $this->data ['memu'] = "invoice";
  2578. $this->data ['staff'] = $this->staff;
  2579. foreach ( $list as $key => $value ) {
  2580. $list [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2581. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2582. if (! empty ( $lastApprover )) {
  2583. $lastApproverKey = array_keys ( $lastApprover );
  2584. $lastApprover = end ( $lastApprover );
  2585. $staffDetail = $staff->getOne ( array (
  2586. 'where' => 'sid=' . end ( $lastApproverKey ),
  2587. 'asArray' => true
  2588. ) );
  2589. $lastApprover ['username'] = $staffDetail ['username'];
  2590. }
  2591. $list [$key] ['lastApprover'] = $lastApprover;
  2592. }
  2593. $this->data ['receiptMemu'] = 'invoicePrint';
  2594. $this->data ['list'] = $list;
  2595. $this->render ( "/admin/invoicePrintStayAchieve", $this->data );
  2596. }
  2597. /**
  2598. * 填写票号并完成打印
  2599. * @since 1.0.0
  2600. */
  2601. function invoicePrintDo() {
  2602. Doo::loadModel ( 'invoice' );
  2603. $invoice = new invoice ();
  2604. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2605. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  2606. $invoicePrintType = $this->get_args ( 'invoicePrintType' ) ? $this->get_args ( 'invoicePrintType' ) : "";
  2607. $iid = $invoice->authcode ( $iid );
  2608. if (! is_numeric ( $iid ))
  2609. die ( 'illegal request-iid' );
  2610. if (! empty ( $iid ) && ! empty ( $invoiceNo )) {
  2611. Doo::loadModel ( 'invoiceOperationLog' );
  2612. $invoiceOperationLog = new invoiceOperationLog ();
  2613. Doo::loadModel ( 'invoiceStatistics' );
  2614. $invoiceStatistics = new invoiceStatistics ();
  2615. $XDeode = new XDeode ( 5 );
  2616. Doo::loadModel ( 'invoicePaper' );
  2617. $invoicePaper = new invoicePaper ();
  2618. $invoicePrintDetail = $invoice->getInvoiceByPrint ( $iid );
  2619. if (empty ( $invoicePrintDetail ))
  2620. die ( 'illegal request-data_empty' );
  2621. //
  2622. $ipid = $XDeode->decode ( $invoiceNo );
  2623. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  2624. if (empty ( $paperDetail ))
  2625. die ( 'illegal request-paper_empty' );
  2626. $invoicePaper = new invoicePaper ();
  2627. $item = array (
  2628. 'iid' => $iid,
  2629. 'ipid' => $ipid
  2630. );
  2631. $invoicePaper->setInvoicePaperByCondition ( $item );
  2632. $item = array (
  2633. 'iid' => $iid,
  2634. 'printStatus' => 1,
  2635. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2636. 'printer' => $this->staff [0] ['username'],
  2637. 'printTime' => date ( "Y-m-d H:i:s" ),
  2638. 'invoiceNo' => $paperDetail ['invoiceNo']
  2639. );
  2640. $invoice->setInvoiceByCondition ( $item );
  2641. $item = array (
  2642. 'date' => date ( "Y-m-d H:i:s" ),
  2643. 'operation' => '打印发票号:' . $paperDetail ['invoiceNo'],
  2644. 'status' => 5,
  2645. 'img' => $this->staff [0] ['avatar'],
  2646. 'username' => $this->staff [0] ['username'],
  2647. 'uid' => $this->staff [0] ['sid'],
  2648. 'category' => $this->staff [0] ['category'],
  2649. 'iid' => $iid
  2650. );
  2651. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2652. // 去统计--负票不汇总
  2653. if ($invoicePrintDetail ['untreadStatus'] != 4) {
  2654. $item = array (
  2655. 'date' => date ( "Y-m-d H:i:s" ),
  2656. 'priceClass' => 1,
  2657. 'cid' => $invoicePrintDetail ['cid'],
  2658. 'staff' => $invoicePrintDetail ['sid'],
  2659. 'invoicePrice' => $invoicePrintDetail ['invoicePrice']
  2660. );
  2661. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2662. }
  2663. // 发送通知信息到微信-去除
  2664. // $this->setWXMsg($iid,'PRINT');
  2665. // 发票信息库
  2666. $this->autoUpdateInvoiceInfoBase ( $invoicePrintDetail );
  2667. // 申请人获取微信通知
  2668. Doo::loadModel ( 'staff' );
  2669. $staff = new staff ();
  2670. Doo::loadClass ( 'XDeode' );
  2671. $XDeode = new XDeode ( 5 );
  2672. $username2 = $staff->getOne ( array (
  2673. 'select' => 'wxid',
  2674. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2675. 'asArray' => TRUE
  2676. ) );
  2677. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '完成打印';
  2678. $msg = '';
  2679. $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/' . $XDeode->encode ( $invoicePrintDetail ['iid'] ) . '.html';
  2680. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2681. if (empty ( $invoicePrintType ))
  2682. return "/invoicePrint";
  2683. else
  2684. return "/invoicePrintStayAchieve";
  2685. }
  2686. }
  2687. /**
  2688. * 需要邮寄的发票
  2689. * @since 1.0.0
  2690. */
  2691. function invoicePost() {
  2692. Doo::loadModel ( 'invoice' );
  2693. $invoice = new invoice ();
  2694. Doo::loadModel ( 'express' );
  2695. $express = new express ();
  2696. $invoicePost = $invoice->getPostByInvoice ();
  2697. $invoicePosted = $invoice->getPostByInvoice ( 1 );
  2698. $expressList = $express->getExpressByAll ();
  2699. $invoicePostExpress = "";
  2700. if (isset ( $_COOKIE ["invoicePostExpress"] ))
  2701. $invoicePostExpress = $_COOKIE ["invoicePostExpress"];
  2702. $this->data ['invoicePostExpress'] = $invoicePostExpress;
  2703. $this->data ['expressList'] = $expressList;
  2704. $this->data ['invoicePost'] = $invoicePost;
  2705. $this->data ['invoicePosted'] = $invoicePosted;
  2706. $this->data ['memu'] = "invoice";
  2707. $this->data ['staff'] = $this->staff;
  2708. $this->data ['receiptMemu'] = 'invoicePost';
  2709. $this->render ( "/admin/invoicePost", $this->data );
  2710. }
  2711. /**
  2712. * 添加发票邮寄信息
  2713. */
  2714. function invoiceExpressAddDo() {
  2715. Doo::loadModel ( 'invoice' );
  2716. $invoice = new invoice ();
  2717. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2718. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2719. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2720. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2721. $iid = $iid = $invoice->authcode ( $iid );
  2722. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2723. die ( 'illegal request' );
  2724. $invoicePrintDetail = $invoice->getInvoiceByIid ( $iid );
  2725. setcookie ( 'invoicePostExpress', $expressNumber );
  2726. $item = array (
  2727. 'iid' => $iid,
  2728. 'postStatus' => 1,
  2729. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2730. 'postTime' => date ( "Y-m-d H:i:s" ),
  2731. 'expressCompany' => $expressCompany,
  2732. 'expressNumber' => $expressNumber,
  2733. 'actualItems' => $actualItems,
  2734. 'poster' => $this->staff [0] ['username']
  2735. );
  2736. $invoice->setInvoiceByCondition ( $item );
  2737. // 微信通知-去掉
  2738. // $this->setWXMsg ( $iid );
  2739. Doo::loadModel ( 'staff' );
  2740. $staff = new staff ();
  2741. Doo::loadClass ( 'XDeode' );
  2742. $XDeode = new XDeode ( 5 );
  2743. $username2 = $staff->getOne ( array (
  2744. 'select' => 'wxid',
  2745. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2746. 'asArray' => TRUE
  2747. ) );
  2748. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '已邮寄';
  2749. $expCom = explode ( ":", $invoicePrintDetail ['expressCompany'] );
  2750. if (empty ( $expCom ))
  2751. $expCom [0] = '';
  2752. $msg = $expCom [0] . ':' . $invoicePrintDetail ['expressNumber'] . '';
  2753. $url = 'https://m.kuaidi100.com/result.jsp?nu=' . $invoicePrintDetail ['expressNumber'];
  2754. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2755. return '/invoicePost';
  2756. }
  2757. function invoiceExpressUpdateDo() {
  2758. Doo::loadModel ( 'invoice' );
  2759. $invoice = new invoice ();
  2760. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  2761. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2762. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2763. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2764. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2765. $iid = $invoice->authcode ( $iid );
  2766. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2767. die ( 'illegal request' );
  2768. $item = array (
  2769. 'iid' => $iid,
  2770. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2771. 'expressCompany' => $expressCompany,
  2772. 'expressNumber' => $expressNumber,
  2773. 'actualItems' => $actualItems,
  2774. 'poster' => $this->staff [0] ['username']
  2775. );
  2776. $invoice->setInvoiceByCondition ( $item );
  2777. return $action;
  2778. }
  2779. /**
  2780. * 可退票管理
  2781. */
  2782. function invoiceUntreadIsAchieve() {
  2783. Doo::loadModel ( 'invoice' );
  2784. $invoice = new invoice ();
  2785. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2786. /*
  2787. * 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' => '' );
  2788. */
  2789. if (empty ( $MebSea )) {//
  2790. $con = ' and invoiceNo like "NULL" ';
  2791. } else {
  2792. $con = ' and (invoiceNo like "%' . $MebSea . '%" or invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  2793. }
  2794. // printStatus=1 and
  2795. $sql = " (untreadStatus=0 or untreadStatus=3) and status=2 and sid=" . $this->staff [0] ['sid'] . $con;
  2796. /*
  2797. * $action = "invoiceUntreadIsAchieve"; $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" ); $limit = $pageinfo ['lower'] . ',' . $page_size;
  2798. */
  2799. $limit = '0,50';
  2800. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2801. //print_r($list);
  2802. $this->data ['MebSeaEn'] = $MebSea;
  2803. /*
  2804. * $this->data ['get'] = $get; $this->data ['page'] = $pageinfo; $this->data ['date'] = $date;
  2805. */
  2806. $this->data ['list'] = $list;
  2807. $this->data ['memu'] = "invoice";
  2808. $this->data ['staff'] = $this->staff;
  2809. $this->data ['receiptMemu'] = 'invoice';
  2810. $this->render ( "/admin/invoiceUntreadIsAchieve", $this->data );
  2811. }
  2812. // 已经退票的发票
  2813. function invoiceUntreadED() {
  2814. Doo::loadModel ( 'invoice' );
  2815. $invoice = new invoice ();
  2816. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2817. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "";
  2818. Doo::loadClass ( 'XDeode' );
  2819. $XDeode = new XDeode ( 5 );
  2820. $page_size = 18;
  2821. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2822. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2823. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  2824. $dateArr = explode ( ':', $date );
  2825. $D1 = '';
  2826. $D2 = '';
  2827. if (! empty ( $date )) {
  2828. $D1 = $dateArr [0];
  2829. $D2 = $dateArr [1];
  2830. }
  2831. $con = '';
  2832. if (! empty ( $D1 ) && ! empty ( $D2 )) {
  2833. $con = ' and bindTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2834. }
  2835. // if ($date == 'MONTHO')
  2836. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  2837. // elseif ($date == 'MONTHT')
  2838. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  2839. // elseif ($date == 'MONTHY')
  2840. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  2841. if (! empty ( $MebSea )) {
  2842. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  2843. }
  2844. if ($invoiceType == 'ORDINARY') {
  2845. $con .= ' and invoiceType=0 ';
  2846. } elseif ($invoiceType == 'SPECIAL') {
  2847. $con .= ' and invoiceType=1 ';
  2848. }
  2849. $pageinfo ['page'] = array (
  2850. 'previous' => ''
  2851. );
  2852. // printStatus=1 and
  2853. $sql = " (untreadStatus=2 ) and status=2 and sid=" . $this->staff [0] ['sid'] . $con;
  2854. $action = "invoiceUntreadED";
  2855. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2856. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2857. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2858. // print_r($list);
  2859. $this->data ['MebSeaEn'] = $MebSea;
  2860. $this->data ['get'] = $get;
  2861. $this->data ['page'] = $pageinfo;
  2862. $this->data ['date'] = $date;
  2863. $this->data ['invoiceType'] = $invoiceType;
  2864. $this->data ['list'] = $list;
  2865. $this->data ['memu'] = "invoice";
  2866. $this->data ['staff'] = $this->staff;
  2867. $this->data ['receiptMemu'] = 'invoice';
  2868. $this->render ( "/admin/invoiceUntreadED", $this->data );
  2869. }
  2870. /**
  2871. * 退票处理页面
  2872. */
  2873. function invoiceUntread() {
  2874. Doo::loadModel ( 'invoice' );
  2875. $invoice = new invoice ();
  2876. $untreadInvoice = $invoice->getInvoiceByUntreadStatus ( 1, 0, 50 );
  2877. $establishedInvoice = $invoice->getInvoiceByUntreadStatus ( 2 );
  2878. //print_r($establishedInvoice);
  2879. // foreach ( $establishedInvoice as $key => $value ) {
  2880. // // months
  2881. // $lossDate = strtotime ( "+1 month", strtotime ( $value ['OperationLog'] ['date'] ) );
  2882. // $nowDate = strtotime ( 'now' );
  2883. // $establishedInvoice [$key] ['lossShow'] = false;
  2884. // if ($lossDate < $nowDate)
  2885. // $establishedInvoice [$key] ['lossShow'] = true;
  2886. // }
  2887. $this->data ['untreadInvoice'] = $untreadInvoice;
  2888. $this->data ['establishedInvoice'] = $establishedInvoice;
  2889. $this->data ['memu'] = "invoice";
  2890. $this->data ['staff'] = $this->staff;
  2891. $this->data ['receiptMemu'] = 'invoiceUntread';
  2892. $this->render ( "/admin/invoiceUntread", $this->data );
  2893. }
  2894. /**
  2895. * 确认收到退回的发票,开票状态为退回 //收款状态解绑,公司统计扣除入账额度
  2896. */
  2897. function invoiceUntreadEstablishedDo() {
  2898. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  2899. Doo::loadModel ( 'invoice' );
  2900. $invoice = new invoice ();
  2901. Doo::loadModel ( 'invoiceOperationLog' );
  2902. $invoiceOperationLog = new invoiceOperationLog ();
  2903. Doo::loadModel ( 'invoiceReceivables' );
  2904. Doo::loadModel ( 'invoiceStatistics' );
  2905. $iid = $invoice->authcode ( $untreadIidKey );
  2906. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2907. die ( 'illegal request' );
  2908. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  2909. if ($invoiceDetails ['untreadStatus'] != 1)
  2910. die ( 'illegal request untreadStatus error !=1' );
  2911. $item = array (
  2912. 'iid' => $iid,
  2913. // 'irid'=>'',
  2914. 'untreadStatus' => 2,
  2915. 'untreadTime'=>date ( "Y-m-d H:i:s" ) ,
  2916. 'updateTime' => date ( "Y-m-d H:i:s" )
  2917. );
  2918. $invoice->setInvoiceByCondition ( $item );
  2919. $item = array (
  2920. 'date' => date ( "Y-m-d H:i:s" ),
  2921. 'operation' => '已确认退票',
  2922. 'status' => 6,
  2923. 'img' => $this->staff [0] ['avatar'],
  2924. 'username' => $this->staff [0] ['username'],
  2925. 'uid' => $this->staff [0] ['sid'],
  2926. 'category' => $this->staff [0] ['category'],
  2927. 'iid' => $iid
  2928. );
  2929. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2930. // 收款解绑以及入账扣除 收款扣除
  2931. if (! empty ( $invoiceDetails ['irid'] )) {
  2932. $iridList = explode ( ',', $invoiceDetails ['irid'] );
  2933. foreach ( $iridList as $value ) {
  2934. $invoiceReceivables = new invoiceReceivables ();
  2935. $irDetails = $invoiceReceivables->getOne ( array (
  2936. 'where' => " irid=" . $value . ' ',
  2937. 'asArray' => TRUE
  2938. ) );
  2939. $bindPrice=$irDetails['bindPrice']-$invoiceDetails['invoicePrice'];
  2940. if($bindPrice<0){
  2941. $bindPrice=0;
  2942. }
  2943. $iidExtend = explode ( ',', $irDetails ['iidExtend'] );
  2944. $item = array (
  2945. 'irid' => $value,
  2946. 'bindStatus' => 0,
  2947. 'untreadStatus' => 1,
  2948. 'bindPrice'=>$bindPrice,
  2949. 'untreadStaff' => $invoiceDetails ['userName'],
  2950. 'unbundlingTime' => date ( "Y-m-d H:i:s" ),
  2951. );
  2952. if($irDetails['iid']==$iid){
  2953. $item+=array(
  2954. 'iid' => 0
  2955. );
  2956. }else{
  2957. foreach ($iidExtend as $iek=>$iev){
  2958. if($iev==$iid){
  2959. unset($iidExtend[$iek]);
  2960. break;
  2961. }
  2962. }
  2963. if(empty($iidExtend)){
  2964. $item+=array(
  2965. 'iidExtend' => ''
  2966. );
  2967. }else{
  2968. $iidExtend=implode(",", $iidExtend);
  2969. $item+=array(
  2970. 'iidExtend' => $iidExtend
  2971. );
  2972. }
  2973. }
  2974. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2975. if (! empty ( $irDetails )) {
  2976. // 扣除入账
  2977. $invoiceStatistics = new invoiceStatistics ();
  2978. $item = array (
  2979. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2980. 'priceClass' => 3,
  2981. 'cid' => $invoiceDetails ['cid'],
  2982. 'staff' => $invoiceDetails ['sid'],
  2983. 'accountPrice' => - $irDetails ['receivablesPrice']
  2984. );
  2985. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2986. // 扣除收款
  2987. $invoiceStatistics = new invoiceStatistics ();
  2988. $item = array (
  2989. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2990. 'priceClass' => 2,
  2991. 'cid' => $invoiceDetails ['cid'],
  2992. 'staff' => $invoiceDetails ['sid'],
  2993. 'irid' => $irDetails ['irid'],
  2994. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  2995. );
  2996. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2997. }
  2998. // 解绑时删除收入流水--退票不删除流水
  2999. // Doo::loadModel ( 'wasteBook' );
  3000. // $wasteBook = new wasteBook ();
  3001. // $wasteBook->delete ( array (
  3002. // 'where' => 'dataID=' . $value . ' and accountType=7',
  3003. // 'limit' => 1
  3004. // ) );
  3005. }
  3006. }
  3007. return "/invoiceUntread";
  3008. }
  3009. function invoiceUntreadRecallDo() {
  3010. $iidKey = isset ( $this->params ['iidKey'] ) ? $this->params ['iidKey'] : "";
  3011. Doo::loadModel ( 'invoice' );
  3012. $invoice = new invoice ();
  3013. Doo::loadClass ( 'XDeode' );
  3014. $XDeode = new XDeode ( 5 );
  3015. Doo::loadModel ( 'invoiceOperationLog' );
  3016. $invoiceOperationLog = new invoiceOperationLog ();
  3017. $iid = $XDeode->decode ( $iidKey );
  3018. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  3019. if (empty ( $invoiceDetail )) {
  3020. die ( 'illegal request-DATANULL' );
  3021. }
  3022. $item = array (
  3023. 'iid' => $iid,
  3024. 'untreadStatus' => 0
  3025. );
  3026. $invoice->setInvoiceByCondition ( $item );
  3027. $item = array (
  3028. 'date' => date ( "Y-m-d H:i:s" ),
  3029. 'operation' => '撤回申请退票',
  3030. 'status' => 13,
  3031. 'img' => $this->staff [0] ['avatar'],
  3032. 'username' => $this->staff [0] ['username'],
  3033. 'uid' => $this->staff [0] ['sid'],
  3034. 'category' => $this->staff [0] ['category'],
  3035. 'iid' => $iid
  3036. );
  3037. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3038. return "/invoiceUntread";
  3039. }
  3040. /**
  3041. * 建立负票,关联原来发票
  3042. */
  3043. function invoiceLossDo() {
  3044. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  3045. if (! empty ( $iidKey )) {
  3046. Doo::loadClass ( 'XDeode' );
  3047. $XDeode = new XDeode ( 5 );
  3048. Doo::loadModel ( 'invoice' );
  3049. $invoice = new invoice ();
  3050. Doo::loadModel ( 'invoiceOperationLog' );
  3051. $invoiceOperationLog = new invoiceOperationLog ();
  3052. $iidKey = $XDeode->decode ( $iidKey );
  3053. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  3054. // 拷贝插入一条发票数据
  3055. $iid = $invoice->setInvoiceLoss ( $iidKey );
  3056. // 更新负票
  3057. if($invoiceDetail['invoiceForm']==1){
  3058. $invoiceSerial = "#FE" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  3059. }else{
  3060. $invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  3061. }
  3062. $invoice = new invoice ();
  3063. $item = array (
  3064. 'iid' => $iid,
  3065. 'sid' => $this->staff [0] ['sid'],
  3066. 'userName' => $this->staff [0] ['username'],
  3067. 'cid' => $this->staff [0] ['cid'],
  3068. 'categoryName' => $this->staff [0] ['category'],
  3069. 'invoiceQuantity' => - $invoiceDetail ['invoiceQuantity'],
  3070. 'invoicePrice' => - $invoiceDetail ['invoicePrice'],
  3071. 'invoiceSerial' => $invoiceSerial,
  3072. 'invoiceNo' => '',
  3073. 'printStatus' => 0,
  3074. 'untreadStatus' => 4,
  3075. // 关联发票号
  3076. 'lossIid' => $invoiceDetail ['iid']
  3077. );
  3078. $invoice->setInvoiceByCondition ( $item );
  3079. // 更新原发票
  3080. $invoice = new invoice ();
  3081. $item = array (
  3082. 'iid' => $invoiceDetail ['iid'],
  3083. 'lossIid' => $iid
  3084. );
  3085. $invoice->setInvoiceByCondition ( $item );
  3086. // 操作日志
  3087. $item = array (
  3088. 'date' => date ( "Y-m-d H:i:s" ),
  3089. 'operation' => "创建负票" . $invoiceSerial,
  3090. 'status' => 12,
  3091. 'img' => $this->staff [0] ['avatar'],
  3092. 'username' => $this->staff [0] ['username'],
  3093. 'uid' => $this->staff [0] ['sid'],
  3094. 'category' => $this->staff [0] ['category'],
  3095. 'iid' => $iid
  3096. );
  3097. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3098. // print_r($invoiceDetail);
  3099. // echo $iid;die;
  3100. }
  3101. return '/invoiceUntread';
  3102. }
  3103. /**
  3104. * 上传银行到账 收款文件
  3105. */
  3106. function invoiceReceivablesBankUpload() {
  3107. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  3108. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  3109. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  3110. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  3111. header ( "HTTP/1.1 500 Internal Server Error" );
  3112. echo "POST exceeded maximum allowed size.";
  3113. exit ( 0 );
  3114. }
  3115. // Settings
  3116. $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)
  3117. $upload_name = "Filedata";
  3118. $file_name = "";
  3119. $nk = time ();
  3120. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  3121. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  3122. echo "文件无法保存.";
  3123. exit ( 0 );
  3124. }
  3125. echo json_encode ( array (
  3126. 'filename' => $file_name,
  3127. 'id' => $nk
  3128. ) );
  3129. exit ( 0 );
  3130. }
  3131. /**
  3132. * 解析银行到账收款execl并导入库中
  3133. */
  3134. function invoiceReceivablesImport() {
  3135. $path = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  3136. if ($path != "") {
  3137. Doo::loadModel ( 'invoiceReceivables' );
  3138. $invoiceReceivables = new invoiceReceivables ();
  3139. Doo::loadClass ( 'invoice.func' );
  3140. Doo::loadModel ( 'invoiceROLog' );
  3141. $invoiceROLog = new invoiceROLog ();
  3142. Doo::loadModel ( 'invoiceStatistics' );
  3143. $invoiceStatistics = new invoiceStatistics ();
  3144. $exlArray = formatExcelToArrayBank ( DOO::conf ()->SITE_PATH . "upload/invoiceReceivablesBank/" . $path );
  3145. $bankBatchNumber = 'BBN_' . time ();
  3146. Doo::db ()->beginTransaction ();
  3147. // 批量存储收款--由于必须获得收款ID,
  3148. $sql = 'INSERT INTO CLD_invoiceReceivables (OriginalPrice,receivablesPrice, receivablesMessage,receivablesSerial,receivablesBank,receivablesDate,inputStaff,date,receivablesCategory,receivablesStaff,bankBatchNumber,recepitTitleMark)
  3149. VALUES ';
  3150. $date = date ( "Y-m-d" );
  3151. $receivablesList = array ();
  3152. foreach ( $exlArray as $key => $value ) {
  3153. $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"] . '")';
  3154. array_push ( $receivablesList, $receivablesSql );
  3155. }
  3156. $sql = $sql . implode ( ',', $receivablesList );
  3157. // echo $sql;
  3158. Doo::db ()->query ( $sql );
  3159. // 批量存储收款统计
  3160. // 获得刚刚导入数据的irid组-缺少办事处和人员
  3161. $iridList = $invoiceReceivables->getInvoiceReceivablesByBBN ( $bankBatchNumber );
  3162. // 没有irid 回滚所有操作
  3163. if (empty ( $iridList )) {
  3164. Doo::db ()->rollBack ();
  3165. header ( 'Content-Type:text/html;charset=utf-8' );
  3166. die ( '文档或数据不正确,请重新<a href="/invoiceReceivables">上传</a>.' );
  3167. }
  3168. $sql = 'INSERT INTO CLD_invoiceStatistics (date, priceClass,irid,receivablesPrice)
  3169. VALUES ';
  3170. $statisticsList = array ();
  3171. foreach ( $iridList as $value ) {
  3172. $statisticsSql = '("' . $date . '",2,' . $value ['irid'] . ',' . $value ["receivablesPrice"] . ')';
  3173. array_push ( $statisticsList, $statisticsSql );
  3174. }
  3175. $sql = $sql . implode ( ',', $statisticsList );
  3176. Doo::db ()->query ( $sql );
  3177. // 批量存储操作日志
  3178. $sql = 'INSERT INTO CLD_invoiceROLog (operation, date,status,img, username,uid,category,irid)
  3179. VALUES ';
  3180. $ROLogList = array ();
  3181. foreach ( $iridList as $value ) {
  3182. $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'] . '")';
  3183. array_push ( $ROLogList, $ROLogSql );
  3184. }
  3185. $sql = $sql . implode ( ',', $ROLogList );
  3186. Doo::db ()->query ( $sql );
  3187. // 批量写入流水
  3188. $sql = 'INSERT INTO CLD_wasteBook (dataID, expensesType,accountType,accountPriceShow, accountPrice,accountBank,category,cid,name,sid,inputDate)
  3189. VALUES ';
  3190. $wasteBookList = array ();
  3191. foreach ( $iridList as $value ) {
  3192. $accountBank = '';
  3193. if ($value ['receivablesBank'] == '纵横广发') {
  3194. $accountBank = 'CGBDeposit';
  3195. } elseif ($value ['receivablesBank'] == '纵横工行') {
  3196. $accountBank = 'ICBCDeposit';
  3197. } elseif ($value ['receivablesBank'] == '华润银行') {
  3198. $accountBank = 'HUADeposit';
  3199. } elseif ($value ['receivablesBank'] == '个人广发') {
  3200. $accountBank = 'PersonalDeposit';
  3201. }
  3202. $wasteBookSql = '("' . $value ['irid'] . ' ",1,7,"' . $value ['receivablesPrice'] . '","' . $value ['receivablesPrice'] . '","' . $accountBank . '",
  3203. "' . $this->staff [0] ['category'] . '","' . $this->staff [0] ['cid'] . '","' . $this->staff [0] ['username'] . '","' . $this->staff [0] ['sid'] . '","' . date ( "Y-m-d H:i:s" ) . '")';
  3204. array_push ( $wasteBookList, $wasteBookSql );
  3205. }
  3206. $sql = $sql . implode ( ',', $wasteBookList );
  3207. Doo::db ()->query ( $sql );
  3208. Doo::db ()->commit ();
  3209. return "/invoiceReceivables";
  3210. }
  3211. echo 'no file';
  3212. }
  3213. function invoiceReceivables() {
  3214. $invoiceTC = $this->get_args ( 'invoiceTC' ) ? $this->get_args ( 'invoiceTC' ) : '';
  3215. Doo::loadModel ( 'L_category' );
  3216. $lCategory = new L_category ();
  3217. Doo::loadModel ( 'staff' );
  3218. $staff = new staff ();
  3219. Doo::loadModel ( 'invoiceReceivables' );
  3220. $invoiceReceivables = new invoiceReceivables ();
  3221. Doo::loadModel ( 'invoice' );
  3222. $invoice = new invoice ();
  3223. Doo::loadClass ( 'XDeode' );
  3224. $XDeode = new XDeode ( 5 );
  3225. $category = $lCategory->getCategory ();
  3226. $staffList = $staff->getStaffByCid ( $this->staff [0] ['cid'] );
  3227. $sql = 'bindStatus=1 and iid!=0';
  3228. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByNew ( 4, $sql );
  3229. // 获取未入账发票
  3230. $invoiceUnAccount = $invoice->getInvoiceByUnAccount ( $invoiceTC );
  3231. $invoiceExistAccount = $invoice->getInvoiceByUnAccount ( '', true );
  3232. foreach ( $invoiceUnAccount as $key => $value ) {
  3233. $invoiceUnAccount [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  3234. $lastApprover = json_decode ( $value ['processApprovals'], true );
  3235. if (! empty ( $lastApprover )) {
  3236. $lastApproverKey = array_keys ( $lastApprover );
  3237. $lastApprover = end ( $lastApprover );
  3238. $staffDetail = $staff->getOne ( array (
  3239. 'where' => 'sid=' . end ( $lastApproverKey ),
  3240. 'asArray' => true
  3241. ) );
  3242. $lastApprover ['username'] = $staffDetail ['username'];
  3243. }
  3244. $invoiceUnAccount [$key] ['lastApprover'] = $lastApprover;
  3245. }
  3246. foreach ( $invoiceExistAccount as $key => $value ) {
  3247. // $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  3248. // if (empty ( $irList ))
  3249. // $irList [0] ['sumPrice'] = 0;
  3250. //$balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  3251. $invoiceExistAccount [$key] ['existAccount'] = $value ['invoicePrice']-$value ['invoiceBalance'];
  3252. //$invoiceExistAccount [$key] ['balance'] = $balance;
  3253. }
  3254. $receivablesInput = $invoiceReceivables->getInvoiceReceivablesByInput ();
  3255. $halfList = $invoiceReceivables->getInvoiceReceivablesByHalf ();
  3256. $this->data ['halfList'] = $halfList;
  3257. $this->data ['halfCount'] = count ( $halfList );
  3258. // print_r($receivablesList);
  3259. $this->data ['receivablesDate'] = date ( "Y-m-d" );
  3260. $this->data ['ieaCount'] = count ( $invoiceExistAccount );
  3261. $this->data ['invoiceExistAccount'] = $invoiceExistAccount;
  3262. $this->data ['receivablesInput'] = $receivablesInput;
  3263. $this->data ['year'] = date ( 'Y' );
  3264. $this->data ['invoiceUnAccount'] = $invoiceUnAccount;
  3265. $this->data ['receivablesList'] = $receivablesList;
  3266. $this->data ['staffList'] = $staffList;
  3267. $this->data ['category'] = $category;
  3268. $this->data ['memu'] = "invoice";
  3269. $this->data ['staff'] = $this->staff;
  3270. $this->data ['receiptMemu'] = 'invoiceReceivables';
  3271. $this->render ( "/admin/invoiceReceivables", $this->data );
  3272. }
  3273. /**
  3274. * 设置收款认领地区
  3275. */
  3276. function setInvoiceReceivablesClaim() {
  3277. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  3278. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3279. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  3280. if (! empty ( $iridKey ) && ! empty ( $receivablesCategory )) {
  3281. Doo::loadModel ( 'invoiceReceivables' );
  3282. $invoiceReceivables = new invoiceReceivables ();
  3283. Doo::loadClass ( 'XDeode' );
  3284. $XDeode = new XDeode ( 5 );
  3285. Doo::loadModel ( 'invoiceROLog' );
  3286. $invoiceROLog = new invoiceROLog ();
  3287. $irid = $XDeode->decode ( $iridKey );
  3288. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  3289. if (empty ( $irDetail ))
  3290. die ( 'illegal request' );
  3291. $item = array (
  3292. 'irid' => $irid,
  3293. 'receivablesCategory' => $receivablesCategory
  3294. );
  3295. if ($receivablesCategory != 'PUBLIC') {
  3296. $item += array (
  3297. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3298. 'inputType' => 1
  3299. );
  3300. }
  3301. $invoiceReceivables = new invoiceReceivables ();
  3302. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3303. // 收款操作日志
  3304. $item = array (
  3305. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 ",
  3306. 'date' => date ( "Y-m-d" ),
  3307. 'status' => 1,
  3308. 'img' => $this->staff [0] ['avatar'],
  3309. 'username' => $this->staff [0] ['username'],
  3310. 'uid' => $this->staff [0] ['sid'],
  3311. 'category' => $this->staff [0] ['category'],
  3312. 'irid' => $irid
  3313. );
  3314. $invoiceROLog->setInvoiceROLog ( $item );
  3315. if (empty ( $action ))
  3316. return '/invoiceReceivables';
  3317. else
  3318. return "/invoiceReceivablesAS";
  3319. }
  3320. die ( 'illegal request' );
  3321. }
  3322. /**
  3323. * 新添加收款直接入账发票
  3324. */
  3325. function invoiceCompareClaimPrice() {
  3326. // 收款录入
  3327. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  3328. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3329. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3330. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3331. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3332. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $iidKey )) {
  3333. Doo::loadModel ( 'invoiceReceivables' );
  3334. $invoiceReceivables = new invoiceReceivables ();
  3335. Doo::loadModel ( 'invoiceROLog' );
  3336. $invoiceROLog = new invoiceROLog ();
  3337. Doo::loadModel ( 'invoiceStatistics' );
  3338. Doo::loadModel ( 'invoice' );
  3339. $invoice = new invoice ();
  3340. Doo::loadModel ( 'bill' );
  3341. $bill = new bill ();
  3342. Doo::loadClass ( 'XDeode' );
  3343. $XDeode = new XDeode ( 5 );
  3344. Doo::loadModel ( 'invoiceOperationLog' );
  3345. $invoiceOperationLog = new invoiceOperationLog ();
  3346. $iidKey = $XDeode->decode ( $iidKey );
  3347. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  3348. if (! ($invoiceDetail ['status'] == 2 && $invoiceDetail ['printStatus'] == 1 && $invoiceDetail ['untreadStatus'] == 0))
  3349. die ( 'illegal request' );
  3350. $receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  3351. // 收款录入 并绑定发票
  3352. Doo::db ()->beginTransaction ();
  3353. //获得发票入账余额
  3354. //$bindInvicePrice=$invoiceReceivables->getSumOfReceivablesPrice ( $invoiceDetail['irid'] );
  3355. //$bindPrice=$invoiceDetail ['invoiceBalance']-$bindInvicePrice;
  3356. $bindStatus = 0;
  3357. $invoiceBalance=$invoiceDetail ['invoicePrice'];
  3358. if($invoiceDetail ['invoiceBalance']!=0){
  3359. $invoiceBalance=$invoiceDetail ['invoiceBalance'];
  3360. }
  3361. if ($receivablesPrice <= $invoiceBalance){
  3362. $bindStatus = 1;
  3363. //$bindPrice=$receivablesPrice;
  3364. }
  3365. $titleMark = $invoiceDetail ['invoiceTitle'];
  3366. if (! empty ( $invoiceDetail ['invoiceCompany'] ))
  3367. $titleMark = $invoiceDetail ['invoiceCompany'];
  3368. $item = array (
  3369. 'recepitTitleMark' => $titleMark,
  3370. 'bindStatus' => $bindStatus,
  3371. 'iid' => $invoiceDetail ['iid'],
  3372. 'bindPrice' => $receivablesPrice,
  3373. 'bindDate' => date ( "Y-m-d H:i:s" ),
  3374. 'receivablesPrice' => $receivablesPrice,
  3375. 'OriginalPrice' => $receivablesPrice,
  3376. 'receivablesMessage' => $receivablesMessage,
  3377. 'receivablesSerial' => $receivablesSerial,
  3378. 'receivablesBank' => $receivablesBank,
  3379. 'receivablesDate' => $receivablesDate,
  3380. 'inputStaff' => $this->staff [0] ['username'],
  3381. 'accountClerk' => $this->staff [0] ['username'],
  3382. 'date' => date ( "Y-m-d" ),
  3383. 'receivablesCategory' => $invoiceDetail ['cid'] . ':' . $invoiceDetail ['categoryName'],
  3384. 'receivablesStaff' => $invoiceDetail ['sid'] . '-' . $invoiceDetail ['userName'],
  3385. 'confirmTime' => date ( "Y-m-d H:i:s" )
  3386. );
  3387. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  3388. $item = array ();
  3389. // 收款操作日志
  3390. $item = array (
  3391. 'operation' => $this->staff [0] ['username'] . " 转入 " . $invoiceDetail ['userName']
  3392. );
  3393. $item += array (
  3394. 'date' => date ( "Y-m-d" ),
  3395. 'status' => 1,
  3396. 'img' => $this->staff [0] ['avatar'],
  3397. 'username' => $this->staff [0] ['username'],
  3398. 'uid' => $this->staff [0] ['sid'],
  3399. 'category' => $this->staff [0] ['category'],
  3400. 'irid' => $irid
  3401. );
  3402. $invoiceROLog->setInvoiceROLog ( $item );
  3403. // 收款统计
  3404. $invoiceStatistics = new invoiceStatistics ();
  3405. $item = array (
  3406. 'date' => $receivablesDate,
  3407. 'priceClass' => 2,
  3408. 'irid' => $irid,
  3409. 'cid' => $invoiceDetail ['cid'],
  3410. 'staff' => $invoiceDetail ['sid'],
  3411. 'receivablesPrice' => $receivablesPrice
  3412. );
  3413. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3414. // 收款 入 发票
  3415. $detail = $invoiceDetail;
  3416. $iridString = "";
  3417. if (empty ( $detail ['irid'] ))
  3418. $iridString = $irid;
  3419. else
  3420. $iridString = $detail ['irid'] . ',' . $irid;
  3421. $item = array (
  3422. 'irid' => $iridString,
  3423. 'bindTime' => date ( "Y-m-d H:i:s" ),
  3424. 'updateTime' => date ( "Y-m-d H:i:s" ),
  3425. 'iid' => $detail ['iid']
  3426. );
  3427. // $invoiceReceivables = new invoiceReceivables ();
  3428. // $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  3429. // $sumBind = $bindInvicePrice;
  3430. // $sumBalance=$invoiceReceivables->balanceOfReceivablesPrice($irid);
  3431. // $sum=$sumBind+$sumBalance;
  3432. // ;
  3433. if ($receivablesPrice>=$invoiceBalance){
  3434. $item += array (
  3435. 'invoiceBalance'=>0,
  3436. 'untreadStatus' => 3
  3437. );
  3438. }else{
  3439. $item += array (
  3440. 'invoiceBalance'=>$invoiceBalance-$receivablesPrice
  3441. );
  3442. }
  3443. $invoice->setInvoiceByCondition ( $item );
  3444. // 操作日志
  3445. $item = array (
  3446. 'date' => date ( "Y-m-d H:i:s" ),
  3447. 'operation' => "收款入账" . $receivablesSerial . "到发票" . $detail ['invoiceSerial'],
  3448. 'status' => 8,
  3449. 'img' => $this->staff [0] ['avatar'],
  3450. 'username' => $this->staff [0] ['username'],
  3451. 'uid' => $this->staff [0] ['sid'],
  3452. 'category' => $this->staff [0] ['category'],
  3453. 'iid' => $detail ['iid']
  3454. );
  3455. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3456. // 入账汇总
  3457. $invoiceStatistics = new invoiceStatistics ();
  3458. // $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $iridString );
  3459. // $accountPrice = 0;
  3460. // foreach ( $list as $key => $value ) {
  3461. // $accountPrice += $value ['receivablesPrice'];
  3462. // }
  3463. $item = array (
  3464. 'date' => $receivablesDate,
  3465. 'priceClass' => 3,
  3466. 'cid' => $invoiceDetail ['cid'],
  3467. 'staff' => $invoiceDetail ['sid'],
  3468. 'accountPrice' => $receivablesPrice
  3469. );
  3470. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3471. //发票入账记录
  3472. $bill->iid=$invoiceDetail['iid'];
  3473. $bill->trainId=$invoiceDetail['trainId'];
  3474. $bill->irid=$irid;
  3475. $bill->create_time=date ( "Y-m-d H:i:s" );
  3476. $bill->price=$invoiceBalance;
  3477. $bill->insert ();
  3478. // 公司流水记录
  3479. Doo::loadModel ( 'wasteBook' );
  3480. $wasteBook = new wasteBook ();
  3481. $abDetail = $wasteBook->getAccountBookByAid ( 1, 7, $irid );
  3482. $accountBank=$wasteBook->_getAccountBankEN($receivablesBank);
  3483. if (empty ( $abDetail )) {
  3484. $item = array (
  3485. 'dataID' => $irid,
  3486. 'expensesType' => 1,
  3487. 'accountType' => 7,
  3488. 'accountPrice' => $receivablesPrice,
  3489. 'accountPriceShow' => $receivablesPrice,
  3490. 'accountBank' => $accountBank,
  3491. 'cid'=>$invoiceDetail['cid'],
  3492. 'category' => $invoiceDetail ['categoryName'],
  3493. 'name' => $this->staff [0] ['username'],
  3494. 'sid' => $this->staff [0] ['sid'],
  3495. 'inputDate' => $receivablesDate//date ( "Y-m-d H:i:s" )
  3496. );
  3497. $wasteBook->setAccountBookStatistics ( $item );
  3498. }
  3499. Doo::db ()->commit ();
  3500. }
  3501. return '/invoiceReceivables';
  3502. }
  3503. /**
  3504. * 录入收款数据
  3505. * @return string
  3506. */
  3507. function invoiceReceivablesDo() {
  3508. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3509. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3510. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3511. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3512. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3513. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  3514. Doo::loadModel ( 'invoiceReceivables' );
  3515. $invoiceReceivables = new invoiceReceivables ();
  3516. Doo::loadModel ( 'invoiceROLog' );
  3517. $invoiceROLog = new invoiceROLog ();
  3518. Doo::loadModel ( 'invoiceStatistics' );
  3519. $invoiceStatistics = new invoiceStatistics ();
  3520. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $receivablesCategory ) && ! empty ( $receivablesStaff )) {
  3521. $item = array (
  3522. 'receivablesPrice' => $receivablesPrice,
  3523. 'OriginalPrice' => $receivablesPrice,
  3524. 'receivablesMessage' => $receivablesMessage,
  3525. 'receivablesSerial' => "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  3526. 'receivablesBank' => $receivablesBank,
  3527. 'receivablesDate' => $receivablesDate,
  3528. 'inputStaff' => $this->staff [0] ['username'],
  3529. 'date' => date ( "Y-m-d" ),
  3530. 'receivablesCategory' => $receivablesCategory,
  3531. 'receivablesStaff' => $receivablesStaff
  3532. );
  3533. if ($receivablesCategory != 'PUBLIC') {
  3534. $item += array (
  3535. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3536. 'inputType' => 1
  3537. );
  3538. }
  3539. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  3540. $item = array ();
  3541. // 收款操作日志
  3542. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3543. $item = array (
  3544. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  3545. );
  3546. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3547. $item = array (
  3548. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  3549. );
  3550. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3551. $receivablesStaff = explode ( '-', $receivablesStaff );
  3552. $item = array (
  3553. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  3554. );
  3555. }
  3556. $item += array (
  3557. 'date' => date ( "Y-m-d" ),
  3558. 'status' => 1,
  3559. 'img' => $this->staff [0] ['avatar'],
  3560. 'username' => $this->staff [0] ['username'],
  3561. 'uid' => $this->staff [0] ['sid'],
  3562. 'category' => $this->staff [0] ['category'],
  3563. 'irid' => $irid
  3564. );
  3565. $invoiceROLog->setInvoiceROLog ( $item );
  3566. $item = array (
  3567. 'date' => $receivablesDate,
  3568. 'priceClass' => 2,
  3569. 'irid' => $irid,
  3570. 'receivablesPrice' => $receivablesPrice
  3571. );
  3572. if ($receivablesCategory != 'PUBLIC') {
  3573. $receivablesCategory = explode ( ":", $receivablesCategory );
  3574. $item += array (
  3575. 'cid' => $receivablesCategory [0]
  3576. );
  3577. }
  3578. if ($receivablesStaff2 != 'PUBLIC') {
  3579. $receivablesStaff = explode ( "-", $receivablesStaff2 );
  3580. $item += array (
  3581. 'staff' => $receivablesStaff [0]
  3582. );
  3583. }
  3584. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3585. $toparty = $this->getWxidByCategory ( $receivablesCategory [1] );
  3586. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  3587. $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  3588. if ($toparty != 0)
  3589. $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  3590. // 公司流水记录
  3591. Doo::loadModel ( 'wasteBook' );
  3592. $wasteBook = new wasteBook ();
  3593. $abDetail = $wasteBook->getAccountBookByAid ( 1, 7, $irid );
  3594. $accountBank=$wasteBook->_getAccountBankEN($receivablesBank);
  3595. $item = array (
  3596. 'dataID' => $irid,
  3597. 'expensesType' => 1,
  3598. 'accountType' => 7,
  3599. 'accountPriceShow' => $receivablesPrice,
  3600. 'accountPrice' => $receivablesPrice,
  3601. 'accountBank' => $accountBank,
  3602. 'category' => $this->staff [0] ['category'],
  3603. 'cid' => $this->staff [0] ['cid'],
  3604. 'name' => $this->staff [0] ['username'],
  3605. 'sid' => $this->staff [0] ['sid'],
  3606. 'inputDate' => $receivablesDate ,
  3607. //'createAt'=>date ( "Y-m-d H:i:s" ) ,
  3608. 'synPaymentDate'=>1
  3609. );
  3610. $wasteBook->setAccountBookStatistics ( $item );
  3611. }
  3612. return "/invoiceReceivables";
  3613. }
  3614. /**
  3615. * 收款认领页面-包括公共认领 办事处认领 最近已认领数据
  3616. */
  3617. function invoiceReceivablesClaim() {
  3618. Doo::loadModel ( 'invoiceReceivables' );
  3619. $invoiceReceivables = new invoiceReceivables ();
  3620. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  3621. $this->data ['receivablesList'] = $receivablesList;
  3622. $this->data ['memu'] = "invoice";
  3623. $this->data ['staff'] = $this->staff;
  3624. $this->data ['receiptMemu'] = 'invoiceReceivablesClaim';
  3625. $this->render ( "/admin/invoiceReceivablesClaim", $this->data );
  3626. }
  3627. function invoiceReceivablesTitleMarkSet() {
  3628. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  3629. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  3630. if (empty ( $iridKey ) || empty ( $recepitTitleMark ))
  3631. die ( 'illegal request' );
  3632. Doo::loadModel ( 'invoiceReceivables' );
  3633. $invoiceReceivables = new invoiceReceivables ();
  3634. Doo::loadClass ( 'XDeode' );
  3635. $XDeode = new XDeode ( 5 );
  3636. $irid = $XDeode->decode ( $iridKey );
  3637. if (! is_numeric ( $irid ))
  3638. die ( 'illegal request' );
  3639. $invoiceReceivables->recepitTitleMark = $recepitTitleMark;
  3640. $invoiceReceivables->update ( array (
  3641. 'where' => 'irid = ' . $irid
  3642. ) );
  3643. return '/invoiceReceivablesClaim';
  3644. }
  3645. /**
  3646. * 更新收款相关数据
  3647. */
  3648. function invoiceReceivablesUpdateClaim() {
  3649. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3650. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3651. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3652. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3653. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3654. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  3655. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  3656. if (empty ( $claimKey ))
  3657. die ( 'illegal request' );
  3658. Doo::loadModel ( 'invoiceReceivables' );
  3659. $invoiceReceivables = new invoiceReceivables ();
  3660. Doo::loadModel ( 'invoiceROLog' );
  3661. $invoiceROLog = new invoiceROLog ();
  3662. $con = ' and iid=0 and bindStatus=0'; // and receivablesCategory!="PUBLIC" and receivablesStaff!="PUBLIC"
  3663. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  3664. if (empty ( $detail ))
  3665. die ( 'illegal request' );
  3666. $invoiceReceivables = new invoiceReceivables ();
  3667. $item = array (
  3668. 'irid' => $detail ['irid']
  3669. );
  3670. if ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3671. $item += array (
  3672. 'confirmTime' => date ( "Y-m-d H:i:s" )
  3673. );
  3674. }
  3675. if (! empty ( $receivablesCategory ))
  3676. $item += array (
  3677. 'receivablesCategory' => $receivablesCategory
  3678. );
  3679. if (! empty ( $receivablesStaff ))
  3680. $item += array (
  3681. 'receivablesStaff' => $receivablesStaff
  3682. );
  3683. if (! empty ( $receivablesPrice ))
  3684. $item += array (
  3685. 'receivablesPrice' => $receivablesPrice
  3686. );
  3687. if (! empty ( $receivablesMessage ))
  3688. $item += array (
  3689. 'receivablesMessage' => $receivablesMessage
  3690. );
  3691. if (! empty ( $receivablesBank ))
  3692. $item += array (
  3693. 'receivablesBank' => $receivablesBank
  3694. );
  3695. if (! empty ( $receivablesDate ))
  3696. $item += array (
  3697. 'receivablesDate' => $receivablesDate
  3698. );
  3699. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3700. // 收款操作日志
  3701. $item = array ();
  3702. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3703. $item = array (
  3704. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  3705. );
  3706. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3707. $item = array (
  3708. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  3709. );
  3710. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3711. $receivablesStaff = explode ( '-', $receivablesStaff );
  3712. $item = array (
  3713. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  3714. );
  3715. }
  3716. $item += array (
  3717. 'date' => date ( "Y-m-d" ),
  3718. 'status' => 1,
  3719. 'img' => $this->staff [0] ['avatar'],
  3720. 'username' => $this->staff [0] ['username'],
  3721. 'uid' => $this->staff [0] ['sid'],
  3722. 'category' => $this->staff [0] ['category'],
  3723. 'irid' => $detail ['irid']
  3724. );
  3725. $invoiceROLog->setInvoiceROLog ( $item );
  3726. return '/invoiceReceivablesAS';
  3727. }
  3728. function invoiceReceivablesDelete() {
  3729. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  3730. $skll = $this->get_args ( 'skll' ) ? $this->get_args ( 'skll' ) : "";
  3731. if ($skll != '删除到款')
  3732. die ( 'illegal request-未填写 删除到款' );
  3733. if (empty ( $claimKey ))
  3734. die ( 'illegal request-收款key不正确' );
  3735. Doo::loadModel ( 'invoiceReceivables' );
  3736. $invoiceReceivables = new invoiceReceivables ();
  3737. $con = ' and bindStatus=0 ';
  3738. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  3739. if (empty ( $detail ))
  3740. die ( 'illegal request-未找到该收款或者未解绑' );
  3741. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  3742. // 扣除收款汇总信息 汇总
  3743. Doo::loadModel ( 'invoiceStatistics' );
  3744. $invoiceStatistics = new invoiceStatistics ();
  3745. $item = array (
  3746. 'date' => $detail ['receivablesDate'],
  3747. 'priceClass' => 2,
  3748. 'irid' => $detail ['irid'],
  3749. 'receivablesPrice' => - $detail ['receivablesPrice']
  3750. );
  3751. if ($detail ['receivablesCategory'] != 'PUBLIC') {
  3752. $receivablesCategory = explode ( ":", $detail ['receivablesCategory'] );
  3753. $item += array (
  3754. 'cid' => $receivablesCategory [0]
  3755. );
  3756. }
  3757. if ($detail ['receivablesStaff'] != 'PUBLIC') {
  3758. $receivablesStaff = explode ( "-", $detail ['receivablesStaff'] );
  3759. $item += array (
  3760. 'staff' => $receivablesStaff [0]
  3761. );
  3762. }
  3763. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3764. // 公司流水-删除时删除流水
  3765. Doo::loadModel ( 'wasteBook' );
  3766. $wasteBook = new wasteBook ();
  3767. $wasteBook->delete ( array (
  3768. 'where' => 'dataID=' . $detail ['irid'] . ' and accountType=7',
  3769. 'limit' => 1
  3770. ) );
  3771. return '/invoiceReceivablesAS';
  3772. }
  3773. /**
  3774. * 管理员录入的收款 ,确认认领到谁的名下.统计收款金额
  3775. */
  3776. function invoiceReceivablesAscription() {
  3777. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  3778. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  3779. Doo::loadModel ( 'invoiceReceivables' );
  3780. $invoiceReceivables = new invoiceReceivables ();
  3781. Doo::loadModel ( 'invoiceROLog' );
  3782. $invoiceROLog = new invoiceROLog ();
  3783. Doo::loadModel ( 'invoiceStatistics' );
  3784. $invoiceStatistics = new invoiceStatistics ();
  3785. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  3786. $irid = $invoiceReceivables->authcode ( $irid );
  3787. if (! empty ( $detail ) && $detail ['receivablesStaff'] == 'PUBLIC' && ! empty ( $recepitTitleMark )) {
  3788. $item = array (
  3789. 'irid' => $detail ['irid'],
  3790. 'receivablesCategory' => $this->staff [0] ['cid'] . ":" . $this->staff [0] ['category'],
  3791. 'receivablesStaff' => $this->staff [0] ['sid'] . "-" . $this->staff [0] ['username'],
  3792. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3793. 'recepitTitleMark' => $recepitTitleMark,
  3794. 'source' => 1
  3795. );
  3796. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3797. $item = array (
  3798. 'date' => date ( "Y-m-d" ),
  3799. 'operation' => $this->staff [0] ['username'] . " 认领 ",
  3800. 'status' => 2,
  3801. 'img' => $this->staff [0] ['avatar'],
  3802. 'username' => $this->staff [0] ['username'],
  3803. 'uid' => $this->staff [0] ['sid'],
  3804. 'category' => $this->staff [0] ['category'],
  3805. 'irid' => $irid
  3806. );
  3807. $invoiceROLog->setInvoiceROLog ( $item );
  3808. $item = array (
  3809. 'cid' => $this->staff [0] ['cid'],
  3810. 'staff' => $this->staff [0] ['sid']
  3811. );
  3812. $invoiceStatistics->updateInvoiceStatisticsByIrid ( $item, $detail ['irid'], 2 );
  3813. //更新流水的办事处
  3814. Doo::loadModel ( 'wasteBook' );
  3815. $wasteBook = new wasteBook ();
  3816. $abDetail = $wasteBook->getAccountBookByAid ( 1, 7, $detail ['irid'] );
  3817. $wasteBook->wid = $abDetail ['wid'];
  3818. $wasteBook->category = $this->staff [0] ['category'];
  3819. $wasteBook->cid = $this->staff [0] ['cid'];
  3820. $wasteBook->update ();
  3821. }
  3822. return "/invoiceReceivablesClaim";
  3823. }
  3824. /**
  3825. */
  3826. function invoiceMyReceivables() {
  3827. Doo::loadModel ( 'invoiceReceivables' );
  3828. $invoiceReceivables = new invoiceReceivables ();
  3829. Doo::loadModel ( 'invoiceStatistics' );
  3830. $invoiceStatistics = new invoiceStatistics ();
  3831. $isMonth = $invoiceStatistics->getStatisticsByMonth ( $this->staff [0] ['sid'] );
  3832. $year = date ( "Y" );
  3833. $tmp_date = date ( "Ym" );
  3834. $tmp_year = substr ( $tmp_date, 0, 4 );
  3835. $tmp_mon = substr ( $tmp_date, 4, 2 );
  3836. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  3837. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  3838. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . ".htm";
  3839. $htm = $this->showCache ( $path );
  3840. $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  3841. $this->data ['isMonth'] = $isMonth;
  3842. $this->data ['htm'] = $htm;
  3843. $this->data ['list'] = $list;
  3844. $this->data ['memu'] = "invoice";
  3845. $this->data ['staff'] = $this->staff;
  3846. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  3847. $this->render ( "/admin/invoiceMyReceivables", $this->data );
  3848. }
  3849. /**
  3850. * 纸票管理
  3851. */
  3852. function invoicePaper() {
  3853. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3854. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3855. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3856. $this->data ['dateString'] = $date;
  3857. $this->data ['status'] = $status;
  3858. $this->data ['invoiceType'] = $invoiceType;
  3859. $this->data ['memu'] = "invoice";
  3860. $this->data ['staff'] = $this->staff;
  3861. $this->data ['receiptMemu'] = 'invoicePaper';
  3862. $this->render ( "/admin/invoicePaper", $this->data );
  3863. }
  3864. /**
  3865. * 电子发票管理
  3866. */
  3867. function invoiceElectronic() {
  3868. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3869. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3870. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3871. $this->data ['dateString'] = $date;
  3872. $this->data ['status'] = $status;
  3873. $this->data ['invoiceType'] = $invoiceType;
  3874. $this->data ['memu'] = "invoice";
  3875. $this->data ['staff'] = $this->staff;
  3876. $this->data ['receiptMemu'] = 'invoicePaper';
  3877. $this->render ( "/invoice/invoiceElectronic", $this->data );
  3878. }
  3879. /**
  3880. * 获得纸票分页数据
  3881. */
  3882. function ajaxGetinvoicePaperAchieve() {
  3883. //include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  3884. Doo::loadModel ( 'invoicePaper' );
  3885. $invoicePaper = new invoicePaper ();
  3886. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3887. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3888. $invoiceForm = $this->get_args ( 'invoiceForm' )&&is_numeric($this->get_args ( 'invoiceForm' )) ? $this->get_args ( 'invoiceForm' ) : "0";
  3889. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ORDINARY";
  3890. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3891. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  3892. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  3893. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  3894. $MebSea = $this->get_args ( 'search' );
  3895. $MebSea = $MebSea ['value'];
  3896. $page_size = $length;
  3897. $con = '';
  3898. if ($status == 'ALL')
  3899. $con = ' where 1 ';
  3900. elseif ($status == 'PRINTED')
  3901. $con = ' where a.iid!=0 '; // $con = ' where b.isDelete=0 and a.iid!=0 and b.status=2 and b.untreadStatus=0 ';
  3902. elseif ($status == 'UNPRINT')
  3903. $con = ' where a.iid=0 '; // $con = ' where b.isDelete=0 and a.iid=0 and b.status=2 and b.untreadStatus=0 ';
  3904. elseif ($status == 'TICKET')
  3905. $con = ' where b.isDelete=0 and b.untreadStatus=2';
  3906. if ($invoiceType == 'ORDINARY')
  3907. $con .= ' and a.invoiceType=0 ';
  3908. elseif ($invoiceType == 'SPECIAL')
  3909. $con .= ' and a.invoiceType=1 ';
  3910. if($invoiceForm==0){
  3911. $con .= ' and a.invoiceForm=0 ';
  3912. }else{
  3913. $con .= ' and a.invoiceForm=1 ';
  3914. }
  3915. $dateArr = explode ( ':', $date );
  3916. $D1 = $dateString = '';
  3917. $D2 = '';
  3918. if (! empty ( $date )) {
  3919. $D1 = $dateArr [0];
  3920. if (isset ( $dateArr [1] ))
  3921. $D2 = $dateArr [1];
  3922. else
  3923. $D2 = '';
  3924. $dateString = $D1 . " : " . $D2;
  3925. }
  3926. if (! empty ( $D1 ) && ! empty ( $D2 ))
  3927. $con .= ' and b.printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  3928. elseif (! empty ( $D1 ) && empty ( $D2 ))
  3929. $con .= ' and b.printTime like "%' . $D1 . '%" ';
  3930. if (! empty ( $MebSea ))
  3931. $con .= ' and ( b.invoiceTitle like "%' . $MebSea . '%" or b.invoiceCompany like "%' . $MebSea . '%" or a.invoiceNo like "%' . $MebSea . '%" )';
  3932. $invoiceTotal = $invoicePaper->getInvoicePaperCount ($invoiceForm);
  3933. $sql = ' ' . $con;
  3934. $limit = $page . ',' . $page_size;
  3935. $list = $invoicePaper->getInvoicePaper ( $limit, $sql, 'desc' );
  3936. $paperList = array ();
  3937. foreach ( $list as $key => $value ) {
  3938. $irDetail = array ();
  3939. if ($value ['iid'] == 0)
  3940. array_push ( $irDetail, '<a href="javascript:if(window.confirm(\'确认删除?\'))window.location=\'/invoicePaperDel/' . $value ['ipidKey'] . '\'" >删除</a>' );
  3941. else
  3942. array_push ( $irDetail, '' );
  3943. array_push ( $irDetail, $value ['invoiceCode'] );
  3944. array_push ( $irDetail, $value ['invoiceNo'] );
  3945. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKey'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  3946. if ($value ['invoiceType'] == 1)
  3947. array_push ( $irDetail, $value ['invoiceCompany'] );
  3948. else
  3949. array_push ( $irDetail, $value ['invoiceTitle'] );
  3950. if ($value ['invoiceType'] == 1)
  3951. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  3952. else
  3953. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  3954. array_push ( $irDetail, $value ['invoiceElement'] );
  3955. array_push ( $irDetail, $value ['categoryName'] . '-' . $value ['userName'] );
  3956. array_push ( $irDetail, $value ['printTime'] );
  3957. array_push ( $paperList, $irDetail );
  3958. }
  3959. // $approvalListJson = json_encode ( $approvalList );
  3960. $recordsFiltered = $invoiceTotal;
  3961. echo json_encode ( array (
  3962. "draw" => intval ( $draw ),
  3963. "recordsTotal" => intval ( $invoiceTotal ),
  3964. "recordsFiltered" => intval ( $recordsFiltered ),
  3965. "data" => $paperList
  3966. ), JSON_UNESCAPED_UNICODE );
  3967. }
  3968. function invoicePaperDel() {
  3969. $ipidKey = isset ( $this->params ['ipidKey'] ) ? $this->params ['ipidKey'] : "";
  3970. $XDeode = new XDeode ( 5 );
  3971. $ipid = $XDeode->decode ( $ipidKey );
  3972. if (empty ( $ipid ))
  3973. die ( 'illegal request' );
  3974. Doo::loadModel ( 'invoicePaper' );
  3975. $invoicePaper = new invoicePaper ();
  3976. $ipdetail=$invoicePaper->getInvoicePaperByIpid($ipid);
  3977. $invoicePaper->delete ( array (
  3978. 'where' => 'ipid=' . $ipid . ' and iid=0',
  3979. 'limit' => 1
  3980. ) );
  3981. if($ipdetail['invoiceForm']==1){
  3982. return '/invoiceElectronic';
  3983. }else{
  3984. return '/invoicePaper';
  3985. }
  3986. }
  3987. /**
  3988. * 添加纸质发票号
  3989. */
  3990. function invoicePaperAdd() {
  3991. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : '0';
  3992. $invoiceCode = $this->get_args ( 'invoiceCode' ) ? $this->get_args ( 'invoiceCode' ) : "";
  3993. $invoiceNoStart = $this->get_args ( 'invoiceNoStart' ) && is_numeric ( $this->get_args ( 'invoiceNoStart' ) ) ? $this->get_args ( 'invoiceNoStart' ) : 0;
  3994. $invoiceNoTotal = $this->get_args ( 'invoiceNoTotal' ) && is_numeric ( $this->get_args ( 'invoiceNoTotal' ) ) ? $this->get_args ( 'invoiceNoTotal' ) : 0;
  3995. $invoiceForm = $this->get_args ( 'invoiceForm' ) && is_numeric ( $this->get_args ( 'invoiceForm' ) ) ? $this->get_args ( 'invoiceForm' ) : 0;
  3996. if ($invoiceType != '' && ! empty ( $invoiceCode ) && ! empty ( $invoiceNoStart ) && ! empty ( $invoiceNoTotal )) {
  3997. $sum = $invoiceNoStart + $invoiceNoTotal;
  3998. if (empty ( $sum ))
  3999. die ( 'illegal request' );
  4000. // echo $invoiceNoStart;
  4001. // echo $sum;
  4002. // echo strlen((int)$invoiceNoStart);
  4003. $sumLenght = strlen ( $invoiceNoStart ) - strlen ( ( int ) $invoiceNoStart );
  4004. if($invoiceType==0||$invoiceType==1){
  4005. }else{
  4006. die ( 'illegal request invoiceType' );
  4007. }
  4008. if($invoiceForm==1){
  4009. $invoiceType=0;
  4010. }
  4011. Doo::db ()->beginTransaction ();
  4012. // 批量存储纸质发票
  4013. $date = date ( "Y-m-d H:i:s" );
  4014. $sql = 'INSERT INTO CLD_invoicePaper (invoiceType, invoiceCode,invoiceNo,date,invoiceForm)
  4015. VALUES ';
  4016. $paperList = array ();
  4017. for($invoiceNoStart; $invoiceNoStart <= $sum - 1; $invoiceNoStart ++) {
  4018. // 数字前面自加0
  4019. $INLENGHT = strlen ( ( int ) $invoiceNoStart ) + $sumLenght;
  4020. $var = sprintf ( "%0" . $INLENGHT . "d", $invoiceNoStart );
  4021. $paperSql = '(' . $invoiceType . ',"' . $invoiceCode . '","' . $var . '","' . $date . '","'.$invoiceForm.'")';
  4022. array_push ( $paperList, $paperSql );
  4023. }
  4024. if (empty ( $paperList ))
  4025. die ( 'illegal request' );
  4026. $sql = $sql . implode ( ',', $paperList );
  4027. Doo::db ()->query ( $sql );
  4028. Doo::db ()->commit ();
  4029. if($invoiceForm==1){
  4030. return 'invoiceElectronic';
  4031. }else{
  4032. return 'invoicePaper';
  4033. }
  4034. }
  4035. die ( 'illegal request' );
  4036. }
  4037. /**
  4038. * 收款绑定发票 ,//一个收款只能绑定一个发票
  4039. */
  4040. function invoiceBindReceivables() {
  4041. $claimKey = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  4042. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  4043. Doo::loadModel ( 'invoice' );
  4044. $invoice = new invoice ();
  4045. Doo::loadModel ( 'invoiceReceivables' );
  4046. $invoiceReceivables = new invoiceReceivables ();
  4047. Doo::loadModel ( 'invoiceOperationLog' );
  4048. $invoiceOperationLog = new invoiceOperationLog ();
  4049. if (empty ( $invoiceKey ) || empty ( $claimKey ))
  4050. die ( 'illegal request' );
  4051. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  4052. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey );
  4053. if (empty ( $detail ) && empty ( $detailM ))
  4054. die ( 'illegal request' );
  4055. if ($detail ['untreadStatus'] == 3)
  4056. die ( 'illegal request' );
  4057. // 修改 绑定状态改为 金额
  4058. $invoiceReceivables = new invoiceReceivables ();
  4059. $invoicePrice = $detail ['invoicePrice'] + $detailM ['bindPrice'];
  4060. $billPrice=0;
  4061. if ($detailM ['receivablesPrice'] > $invoicePrice) {
  4062. $item = array (
  4063. 'bindPrice' => $invoicePrice
  4064. );
  4065. $billPrice=$invoicePrice;
  4066. } elseif ($detailM ['receivablesPrice'] <= $invoicePrice) { //发票金额大于收款金额,绑定金额为收款金额
  4067. $item = array (
  4068. 'bindPrice' => $detailM ['receivablesPrice'],
  4069. 'bindStatus' => 1,
  4070. 'bindDate' => date ( "Y-m-d H:i:s" )
  4071. );
  4072. $billPrice=$detailM ['receivablesPrice'];
  4073. } else {
  4074. die ( 'illegal request' );
  4075. }
  4076. if ($detailM ['iid'] == 0) {
  4077. $item += array (
  4078. 'iid' => $detail ['iid']
  4079. );
  4080. } else {
  4081. $iidExtend = explode ( ',', $detailM ['iidExtend'] );
  4082. array_push ( $iidExtend, $detail ['iid'] );
  4083. $item += array (
  4084. 'iidExtend' => implode ( ',', $iidExtend )
  4085. );
  4086. }
  4087. $titleMark = $detail ['invoiceTitle'];
  4088. if (! empty ( $detail ['invoiceCompany'] ))
  4089. $titleMark = $detail ['invoiceCompany'];
  4090. $item += array (
  4091. 'irid' => $detailM ['irid'],
  4092. 'recepitTitleMark' => $titleMark,
  4093. 'accountClerk' => $this->staff [0] ['username']
  4094. );
  4095. // 如何没有人收款 则自动绑定收款
  4096. if ($detailM ['receivablesCategory'] == 'PUBLIC' || $detailM ['receivablesStaff'] == 'PUBLIC') {
  4097. $item += array (
  4098. 'receivablesCategory' => $detail ['cid'] . ':' . $detail ['categoryName'],
  4099. 'receivablesStaff' => $detail ['sid'] . '-' . $detail ['userName']
  4100. );
  4101. }
  4102. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4103. $iridString = "";
  4104. if (empty ( $detail ['irid'] ))
  4105. $iridString = $detailM ['irid'];
  4106. else
  4107. $iridString = $detail ['irid'] . ',' . $detailM ['irid'];
  4108. // $invoiceReceivables = new invoiceReceivables ();
  4109. // $sumBind = $invoiceReceivables->getSumOfReceivablesPrice ( $detail ['irid'] );
  4110. // //这个收款余额
  4111. // $sumBalance=$invoiceReceivables->balanceOfReceivablesPrice($detailM ['irid']);
  4112. // $sum=$sumBind+$sumBalance;
  4113. //这个收款余额
  4114. $sumBalance=$detailM ['receivablesPrice']-$detailM ['bindPrice'];
  4115. // echo $detailM ['irid'].'/'.$sumBalance.'/'.$detail ['invoicePrice'];
  4116. // die;
  4117. $invoice = new invoice ();
  4118. $item = array (
  4119. 'iid' => $detail ['iid'],
  4120. 'irid' => $iridString
  4121. );
  4122. if ($detail ['invoicePrice'] <= $sumBalance){
  4123. $item += array (
  4124. 'invoiceBalance'=>0,
  4125. 'untreadStatus' => 3,
  4126. 'bindTime' => date ( "Y-m-d H:i:s" )
  4127. );
  4128. }else{
  4129. $item += array (
  4130. 'invoiceBalance'=>$detail ['invoicePrice']-$sumBalance,
  4131. );
  4132. }
  4133. // print_r($item);
  4134. // echo $sum;die;
  4135. $invoice->setInvoiceByCondition ( $item );
  4136. //发票入账记录
  4137. Doo::loadModel ( 'bill' );
  4138. $bill = new bill ();
  4139. $bill->iid=$detail ['iid'];
  4140. $bill->trainId=$detail['trainId'];
  4141. $bill->irid=$detailM ['irid'];
  4142. $bill->create_time=date ( "Y-m-d H:i:s" );
  4143. $bill->price=$billPrice;
  4144. $bill->insert ();
  4145. // 操作日志
  4146. $item = array (
  4147. 'date' => date ( "Y-m-d H:i:s" ),
  4148. 'operation' => "收款" . $detailM ['receivablesSerial'] . "入账到发票" . $detail ['invoiceSerial'],
  4149. 'status' => 8,
  4150. 'img' => $this->staff [0] ['avatar'],
  4151. 'username' => $this->staff [0] ['username'],
  4152. 'uid' => $this->staff [0] ['sid'],
  4153. 'category' => $this->staff [0] ['category'],
  4154. 'iid' => $detail ['iid']
  4155. );
  4156. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  4157. Doo::loadModel ( 'invoiceStatistics' );
  4158. $invoiceStatistics = new invoiceStatistics ();
  4159. $item = array (
  4160. 'date' => $detailM ['receivablesDate'],
  4161. 'priceClass' => 3,
  4162. 'cid' => $detail ['cid'],
  4163. 'staff' => $detail ['sid'],
  4164. 'accountPrice' => $detailM ['receivablesPrice']
  4165. );
  4166. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4167. //TODO
  4168. // 公司流水记录
  4169. // Doo::loadModel ( 'wasteBook' );
  4170. // $wasteBook = new wasteBook ();
  4171. // $abDetail = $wasteBook->getAccountBookByAid (1,8,$detail ['iid'] );
  4172. // $accountBank='';
  4173. // if ($detailM ['receivablesBank']=='纵横广发'){
  4174. // $accountBank='CGBDeposit';
  4175. // }elseif($detailM ['receivablesBank']=='纵横工行'){
  4176. // $accountBank='ICBCDeposit';
  4177. // }elseif($detailM ['receivablesBank']=='华润银行'){
  4178. // $accountBank='HUADeposit';
  4179. // }elseif($detailM ['receivablesBank']=='个人广发'){
  4180. // $accountBank='PersonalDeposit';
  4181. // }
  4182. // if (empty($abDetail)){
  4183. // $item = array (
  4184. // 'dataID' => $detail ['iid'],
  4185. // 'expensesType' => 1,
  4186. // 'accountType' => 8,
  4187. // 'accountPriceShow'=>$detail ['invoicePrice'],
  4188. // 'accountPrice'=>$detail ['invoicePrice'],
  4189. // 'accountBank'=>$accountBank,
  4190. // 'category'=>$this->staff[0]['category'],
  4191. // 'cid'=>$this->staff[0]['cid'],
  4192. // 'name'=>$this->staff[0]['username'],
  4193. // 'sid'=>$this->staff[0]['sid'],
  4194. // 'inputDate'=>date ( "Y-m-d H:i:s" )
  4195. // );
  4196. // $wasteBook->setAccountBookStatistics($item);
  4197. // }
  4198. return "/invoiceReceivables";
  4199. }
  4200. /**
  4201. * 核销 动作,确认入账统计 发票收款完成--需求更变 废弃 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"; }
  4202. */
  4203. function invoiceAggregate() {
  4204. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  4205. Doo::loadModel ( 'invoiceStatistics' );
  4206. $invoiceStatistics = new invoiceStatistics ();
  4207. Doo::loadModel ( 'L_category' );
  4208. $Lcategory = new L_category ();
  4209. $isList = $invoiceStatistics->getInvoiceStatisticsByYear ( $year );
  4210. $LcategoryList = $Lcategory->getCategory ();
  4211. // print_r($isList);
  4212. $html = ""; // $invoicePriceCategory=0;$receivablesPriceCategory=0;$accountPriceCategory=0;
  4213. foreach ( $LcategoryList as $key => $value ) {
  4214. $html .= '<tr><th><a href="/invoiceAggregateCategory/' . $value ['cidKey'] . '">' . $value ['title'] . '</a></th>';
  4215. $month = 1;
  4216. $invoicePriceYear = 0;
  4217. $receivablesPriceYear = 0;
  4218. $accountPriceYear = 0;
  4219. for(; $month <= 12; $month ++) {
  4220. $flag = true;
  4221. foreach ( $isList ['statisticsMonthCid'] as $k => $v ) {
  4222. if ($value ['cid'] == $v ['cid'] && $month == $v ['month']) {
  4223. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  4224. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  4225. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  4226. ';
  4227. $invoicePriceYear += $v ['invoicePrice'];
  4228. $receivablesPriceYear += $v ['receivablesPrice'];
  4229. $accountPriceYear += $v ['accountPrice'];
  4230. $flag = false;
  4231. break;
  4232. }
  4233. }
  4234. if ($flag)
  4235. $html .= '<td class="taR"></td>
  4236. <td class="taR"></td>
  4237. <td class="taR"><b></b></td>
  4238. ';
  4239. }
  4240. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  4241. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  4242. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  4243. ';
  4244. $html .= '</tr>';
  4245. }
  4246. $html .= '<tr><th><b class="colGreen">月合计</b></th>';
  4247. $invoicePriceYear = 0;
  4248. $receivablesPriceYear = 0;
  4249. $accountPriceYear = 0;
  4250. for($month = 1; $month <= 12; $month ++) {
  4251. $flag = true;
  4252. foreach ( $isList ['statisticsMonth'] as $k => $v ) {
  4253. if ($month == $v ['month']) {
  4254. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  4255. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  4256. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  4257. ';
  4258. $invoicePriceYear += $v ['invoicePrice'];
  4259. $receivablesPriceYear += $v ['receivablesPrice'];
  4260. $accountPriceYear += $v ['accountPrice'];
  4261. $flag = false;
  4262. break;
  4263. }
  4264. }
  4265. if ($flag) {
  4266. $html .= '<td class="taR"></td>
  4267. <td class="taR"></td>
  4268. <td class="taR"><b></b></td>
  4269. ';
  4270. }
  4271. }
  4272. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  4273. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  4274. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  4275. ';
  4276. $html .= '</tr>';
  4277. // print_r($isList);
  4278. $this->data ['html'] = $html;
  4279. $this->data ['LcategoryList'] = $LcategoryList;
  4280. $this->data ['isList'] = $isList;
  4281. $this->data ['year'] = $year;
  4282. $this->data ['memu'] = "invoice";
  4283. $this->data ['staff'] = $this->staff;
  4284. $this->data ['receiptMemu'] = 'invoiceAggregate';
  4285. $this->render ( "/admin/invoiceAggregate", $this->data );
  4286. }
  4287. function invoiceAggregateStaff() {
  4288. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  4289. Doo::loadModel ( 'invoiceStatistics' );
  4290. $invoiceStatistics = new invoiceStatistics ();
  4291. Doo::loadModel ( 'L_category' );
  4292. $Lcategory = new L_category ();
  4293. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year );
  4294. $staffList = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year );
  4295. $cStaff = $Lcategory->getCategoryStaff ();
  4296. $html = '';
  4297. foreach ( $cStaff as $key => $value ) {
  4298. $categoryFir = true;
  4299. foreach ( $value ['staff'] as $k => $v ) {
  4300. if ($categoryFir) {
  4301. $width = count ( $value ['staff'] ) + 1;
  4302. $html .= '<tr><th rowspan="' . $width . '">' . $value ['title'] . ' </th>';
  4303. $categoryFir = false;
  4304. } else
  4305. $html .= '<tr>';
  4306. $html .= '<th>' . $v ['username'] . '</th>';
  4307. $invoicePriceStaffYear = 0;
  4308. $receivablesPriceStaffYear = 0;
  4309. $accountPriceStaffYear = 0;
  4310. for($month = 1; $month <= 12; $month ++) {
  4311. $flag = true;
  4312. foreach ( $staffList ['statisticsMonthStaff'] as $sl => $slv ) {
  4313. if ($v ['sid'] == $slv ['staff'] && $month == $slv ['month']) {
  4314. $html .= '<td class="taR">¥' . $slv ['invoicePrice'] . '</td>
  4315. <td class="taR">¥' . $slv ['receivablesPrice'] . '</td>
  4316. <td class="taR"><b>¥' . $slv ['accountPrice'] . '</b></td>
  4317. ';
  4318. $invoicePriceStaffYear += $slv ['invoicePrice'];
  4319. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  4320. $accountPriceStaffYear += $slv ['accountPrice'];
  4321. $flag = false;
  4322. break;
  4323. }
  4324. }
  4325. if ($flag)
  4326. $html .= '<td class="taR"></td>
  4327. <td class="taR"></td>
  4328. <td class="taR"><b></b></td>
  4329. ';
  4330. }
  4331. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  4332. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  4333. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  4334. ';
  4335. }
  4336. $html .= '</tr>';
  4337. // 小计
  4338. if (! empty ( $value ['staff'] )) {
  4339. $html .= '<tr><th class="taR">小计</th>';
  4340. $invoicePriceStaffYear = 0;
  4341. $receivablesPriceStaffYear = 0;
  4342. $accountPriceStaffYear = 0;
  4343. for($month = 1; $month <= 12; $month ++) {
  4344. $flag = true;
  4345. foreach ( $staffList ['statisticsMonthCid'] as $smc => $smcv ) {
  4346. if ($value ['cid'] == $smcv ['cid'] && $month == $slv ['month']) {
  4347. $html .= '<td class="taR">¥' . $smcv ['invoicePrice'] . '</td>
  4348. <td class="taR">¥' . $smcv ['receivablesPrice'] . '</td>
  4349. <td class="taR"><b>¥' . $smcv ['accountPrice'] . '</b></td>
  4350. ';
  4351. $invoicePriceStaffYear += $slv ['invoicePrice'];
  4352. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  4353. $accountPriceStaffYear += $slv ['accountPrice'];
  4354. $flag = false;
  4355. break;
  4356. }
  4357. }
  4358. if ($flag)
  4359. $html .= '<td class="taR"></td>
  4360. <td class="taR"></td>
  4361. <td class="taR"><b></b></td>
  4362. ';
  4363. }
  4364. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  4365. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  4366. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  4367. ';
  4368. $html .= '</tr>';
  4369. }
  4370. }
  4371. $html .= '<tr class="warning"><th colspan="2"><b class="colGreen" >月合计</b></th>';
  4372. $invoicePriceYear = 0;
  4373. $receivablesPriceYear = 0;
  4374. $accountPriceYear = 0;
  4375. for($month = 1; $month <= 12; $month ++) {
  4376. $flag = true;
  4377. foreach ( $staffList ['statisticsMonth'] as $k => $v ) {
  4378. if ($month == $v ['month']) {
  4379. $html .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>
  4380. <td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>
  4381. <td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>
  4382. ';
  4383. $invoicePriceYear += $v ['invoicePrice'];
  4384. $receivablesPriceYear += $v ['receivablesPrice'];
  4385. $accountPriceYear += $v ['accountPrice'];
  4386. $flag = false;
  4387. break;
  4388. }
  4389. }
  4390. if ($flag)
  4391. $html .= '<td class="taR"></td>
  4392. <td class="taR"></td>
  4393. <td class="taR"><b></b></td>
  4394. ';
  4395. }
  4396. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  4397. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  4398. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  4399. ';
  4400. $html .= '</tr>';
  4401. $this->data ['html'] = $html;
  4402. $this->data ['isList'] = $toteList;
  4403. $this->data ['year'] = $year;
  4404. $this->data ['memu'] = "invoice";
  4405. $this->data ['staff'] = $this->staff;
  4406. $this->data ['receiptMemu'] = 'invoiceAggregate';
  4407. $this->render ( "/admin/invoiceAggregateStaff", $this->data );
  4408. }
  4409. function invoiceAggregateCategory() {
  4410. Doo::loadClass ( 'XDeode' );
  4411. $XDeode = new XDeode ( 5 );
  4412. $cid = $cidKey = isset ( $this->params ['cid'] ) ? $this->params ['cid'] : "";
  4413. $cid = $XDeode->decode ( $cid );
  4414. if (! is_numeric ( $cid ))
  4415. die ( 'illegal request' );
  4416. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  4417. Doo::loadModel ( 'invoiceStatistics' );
  4418. $invoiceStatistics = new invoiceStatistics ();
  4419. Doo::loadModel ( 'staff' );
  4420. $staff = new staff ();
  4421. $list = $staff->getStaffByCid ( $cid );
  4422. $isCategory = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year, $cid );
  4423. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year, $cid );
  4424. if (empty ( $list ))
  4425. die ( '该办事处没有成员' );
  4426. $htmlA = $htmlB = $htmlC = $html = '';
  4427. foreach ( $list as $key => $value ) {
  4428. $htmlA = '<tr><th rowspan="3">' . $value ['username'] . '</th><th class="taC">开票</th>';
  4429. $htmlB = '<tr><th class="taC">收款</th>';
  4430. $htmlC = '<tr><th class="taC">入账</th>';
  4431. $invoicePriceStaffYear = 0;
  4432. $receivablesPriceStaffYear = 0;
  4433. $accountPriceStaffYear = 0;
  4434. for($month = 1; $month <= 12; $month ++) {
  4435. $flag = true;
  4436. foreach ( $isCategory ['statisticsMonthStaff'] as $k => $v ) {
  4437. if ($value ['sid'] == $v ['staff'] && $month == $v ['month']) {
  4438. $htmlA .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>';
  4439. $htmlB .= '<td class="taR">¥' . $v ['receivablesPrice'] . '</td>';
  4440. $htmlC .= '<td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>';
  4441. $invoicePriceStaffYear += $v ['invoicePrice'];
  4442. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  4443. $accountPriceStaffYear += $v ['accountPrice'];
  4444. $flag = false;
  4445. break;
  4446. }
  4447. }
  4448. if ($flag) {
  4449. $htmlA .= '<td class="taR">-</td>';
  4450. $htmlB .= '<td class="taR">-</td>';
  4451. $htmlC .= '<td class="taR"><b>-</b></td>';
  4452. }
  4453. }
  4454. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  4455. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  4456. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  4457. $htmlA .= '</tr>';
  4458. $htmlB .= '</tr>';
  4459. $htmlC .= '</tr>';
  4460. $html .= $htmlA . $htmlB . $htmlC;
  4461. }
  4462. $htmlA = $htmlB = $htmlC = "";
  4463. $htmlA = '<tr><th rowspan="3">月合计</th><th class="taC">开票</th>';
  4464. $htmlB = '<tr><th class="taC">收款</th>';
  4465. $htmlC = '<tr><th class="taC">入账</th>';
  4466. $invoicePriceStaffYear = 0;
  4467. $receivablesPriceStaffYear = 0;
  4468. $accountPriceStaffYear = 0;
  4469. for($month = 1; $month <= 12; $month ++) {
  4470. $flag = true;
  4471. foreach ( $isCategory ['statisticsMonth'] as $k => $v ) {
  4472. if ($month == $v ['month']) {
  4473. $htmlA .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>';
  4474. $htmlB .= '<td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>';
  4475. $htmlC .= '<td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>';
  4476. $invoicePriceStaffYear += $v ['invoicePrice'];
  4477. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  4478. $accountPriceStaffYear += $v ['accountPrice'];
  4479. $flag = false;
  4480. break;
  4481. }
  4482. }
  4483. if ($flag) {
  4484. $htmlA .= '<td class="taR">-</td>';
  4485. $htmlB .= '<td class="taR">-</td>';
  4486. $htmlC .= '<td class="taR"><b>-</b></td>';
  4487. }
  4488. }
  4489. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  4490. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  4491. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  4492. $htmlA .= '</tr>';
  4493. $htmlB .= '</tr>';
  4494. $htmlC .= '</tr>';
  4495. $html .= $htmlA . $htmlB . $htmlC;
  4496. $this->data ['html'] = $html;
  4497. $this->data ['cidKey'] = $cidKey;
  4498. $this->data ['slist'] = $list;
  4499. $this->data ['isList'] = $toteList;
  4500. $this->data ['year'] = $year;
  4501. $this->data ['memu'] = "invoice";
  4502. $this->data ['staff'] = $this->staff;
  4503. $this->data ['receiptMemu'] = 'invoiceAggregate';
  4504. $this->render ( "/admin/invoiceAggregateCategory", $this->data );
  4505. }
  4506. /**
  4507. * 办事处汇总信息
  4508. */
  4509. function invoiceAggregateCategoryDetail() {
  4510. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  4511. Doo::loadClass ( 'XDeode' );
  4512. $XDeode = new XDeode ( 5 );
  4513. Doo::loadModel ( 'invoiceStatistics' );
  4514. $invoiceStatistics = new invoiceStatistics ();
  4515. Doo::loadModel ( 'L_category' );
  4516. $category = new L_category ();
  4517. Doo::loadModel ( 'invoice' );
  4518. $invoice = new invoice ();
  4519. Doo::loadModel ( 'staff' );
  4520. $staff = new staff ();
  4521. Doo::loadModel ( "invoiceCategoryManage" );
  4522. $invoiceCategoryManage = new invoiceCategoryManage ();
  4523. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4524. $cidList = array ();
  4525. foreach ( $imcStaff as $key => $value ) {
  4526. array_push ( $cidList, $value ['cid'] );
  4527. if (empty ( $cidKey ))
  4528. $cidKey = $XDeode->encode ( $value ['cid'] );
  4529. }
  4530. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  4531. $cid = $XDeode->decode ( $cidKey );
  4532. $month = date ( "m", strtotime ( "-1 month" ) );
  4533. $YearMonth = date ( "Y-m", strtotime ( "-1 month" ) );
  4534. $redis = new Redis ();
  4535. $redis->connect ( '127.0.0.1', '6379' );
  4536. $redisKey = ''; // date('Y-m-d').'_iacd_'.$cid;
  4537. $redisValue = ''; // $redis->lrange($redisKey, 0, -1);
  4538. if (empty ( $redisValue )) {
  4539. $isMC = $invoiceStatistics->getInvoiceStatistiscsMothByCategory ( $cid );
  4540. $schedule = $invoice->getInvoiceScheduleByCid ( $cid );
  4541. // 获得办事处人员下的汇总
  4542. $slist = $staff->getStaffByCid ( $cid );
  4543. $ismsbMonth = $invoiceStatistics->getISMSByCategoryByMonth ( $cid, $YearMonth ); // 上一个月的汇总
  4544. $ismsb = $invoiceStatistics->getISMSByCategory ( $cid ); // 当月汇总
  4545. $ISAS = $invoiceStatistics->getISASByCategory ( $cid ); // 全部汇总
  4546. $scheduleStaff = $invoice->getInvoiceScheduleByCidGroupSid ( $cid ); // 完成度
  4547. foreach ( $slist as $key => $value ) {
  4548. $slist [$key] ['invoicePrice'] = 0;
  4549. $slist [$key] ['receivablesPrice'] = 0;
  4550. $slist [$key] ['accountPrice'] = 0;
  4551. $slist [$key] ['invoiceAllPrice'] = 0;
  4552. $slist [$key] ['receivablesAllPrice'] = 0;
  4553. $slist [$key] ['accountAllPrice'] = 0;
  4554. $slist [$key] ['schedule'] = 0;
  4555. $slist [$key] ['invoiceMonthPrice'] = 0;
  4556. $slist [$key] ['receivablesMonthPrice'] = 0;
  4557. $slist [$key] ['accountMonthPrice'] = 0;
  4558. foreach ( $ismsbMonth as $y => $l ) {
  4559. if ($value ['sid'] == $l ['staff']) {
  4560. $slist [$key] ['invoiceMonthPrice'] = $l ['invoicePrice'];
  4561. $slist [$key] ['receivablesMonthPrice'] = $l ['receivablesPrice'];
  4562. $slist [$key] ['accountMonthPrice'] = $l ['accountPrice'];
  4563. }
  4564. }
  4565. foreach ( $ismsb as $k => $v ) {
  4566. if ($value ['sid'] == $v ['staff']) {
  4567. $slist [$key] ['invoicePrice'] = $v ['invoicePrice'];
  4568. $slist [$key] ['receivablesPrice'] = $v ['receivablesPrice'];
  4569. $slist [$key] ['accountPrice'] = $v ['accountPrice'];
  4570. }
  4571. }
  4572. foreach ( $ISAS as $e => $a ) {
  4573. if ($value ['sid'] == $a ['staff']) {
  4574. $slist [$key] ['invoiceAllPrice'] = $a ['invoicePrice'];
  4575. $slist [$key] ['receivablesAllPrice'] = $a ['receivablesPrice'];
  4576. $slist [$key] ['accountAllPrice'] = $a ['accountPrice'];
  4577. }
  4578. }
  4579. if (isset ( $scheduleStaff [$value ['sid']] ))
  4580. $slist [$key] ['schedule'] = $scheduleStaff [$value ['sid']];
  4581. }
  4582. $this->data ['cidKey'] = $cidKey;
  4583. $schedule = ( int ) ($schedule * 100);
  4584. $this->data ['slist'] = $slist;
  4585. $this->data ['isMC'] = $isMC;
  4586. $this->data ['schedule'] = $schedule;
  4587. $slist = json_encode ( $slist );
  4588. $isMC = json_encode ( $isMC );
  4589. $schedule = json_encode ( $schedule );
  4590. $redis->lpush ( $redisKey, $slist );
  4591. $redis->lpush ( $redisKey, $isMC );
  4592. $redis->lpush ( $redisKey, $schedule );
  4593. } else {
  4594. $this->data ['cidKey'] = $cidKey;
  4595. $this->data ['slist'] = json_decode ( $redisValue [2], true );
  4596. $this->data ['isMC'] = json_decode ( $redisValue [1], true );
  4597. $this->data ['schedule'] = json_decode ( $redisValue [0], true );
  4598. }
  4599. $this->data ['month'] = $month;
  4600. $this->data ['categoryList'] = $categoryList;
  4601. $this->data ['memu'] = "invoice";
  4602. $this->data ['staff'] = $this->staff;
  4603. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4604. $this->render ( "/admin/invoiceAggregateCategoryDetail", $this->data );
  4605. }
  4606. /**
  4607. * 办事处人员汇总详情
  4608. */
  4609. function invoiceAggregateStaffDetail() {
  4610. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  4611. // $sidKey = isset ( $this->params ['sidKey'] ) ? $this->params ['sidKey'] : '';
  4612. Doo::loadClass ( 'XDeode' );
  4613. $XDeode = new XDeode ( 5 );
  4614. Doo::loadModel ( 'invoice' );
  4615. $invoice = new invoice ();
  4616. Doo::loadModel ( 'staff' );
  4617. $staff = new staff ();
  4618. Doo::loadModel ( "invoiceCategoryManage" );
  4619. $invoiceCategoryManage = new invoiceCategoryManage ();
  4620. $sid = $XDeode->decode ( $sidKey );
  4621. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4622. $cidList = array ();
  4623. foreach ( $imcStaff as $key => $value ) {
  4624. array_push ( $cidList, $value ['cid'] );
  4625. if (empty ( $cidKey ))
  4626. $cidKey = $XDeode->encode ( $value ['cid'] );
  4627. }
  4628. $cidString = implode ( ',', $cidList );
  4629. $staffList = $staff->getStaffInCid ( $cidString );
  4630. $staffDetail = $staff->getStaffBySid ( $sid );
  4631. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4632. $page_size = 18;
  4633. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4634. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4635. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  4636. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  4637. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  4638. $dateArr = explode ( ':', $date );
  4639. $D1 = '';
  4640. $D2 = '';
  4641. if (! empty ( $date )) {
  4642. $D1 = $dateArr [0] . " 00:00:00 ";
  4643. if (isset ( $dateArr [1] ))
  4644. $D2 = $dateArr [1] . " 23:59:59 ";
  4645. else
  4646. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4647. // $D2 = $dateArr [1];
  4648. }
  4649. $con = ' status=2 ';
  4650. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4651. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4652. if ($status == 'UNRECORD')
  4653. $con .= ' and printStatus=1 and untreadStatus=0';
  4654. elseif ($status == 'RECORD')
  4655. $con .= ' and printStatus=1 and untreadStatus=3';
  4656. elseif ($status == 'BOUNCED')
  4657. $con .= ' and untreadStatus=2';
  4658. elseif ($status == 'PARTRECORD')
  4659. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  4660. elseif ($status == 'All') {
  4661. $con .= ' and ( untreadStatus=2 or untreadStatus=0 or untreadStatus=3 )';
  4662. }
  4663. $con .= ' and sid=' . $sid;
  4664. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  4665. if (! empty ( $MebSea )) {
  4666. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  4667. }
  4668. $pageinfo ['page'] = array (
  4669. 'previous' => ''
  4670. );
  4671. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateStaffDetail", $get, "" );
  4672. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4673. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  4674. $this->data ['staffDetail'] = $staffDetail;
  4675. $this->data ['staffList'] = $staffList;
  4676. $this->data ['MebSeaEn'] = $MebSea;
  4677. $this->data ['MebSea'] = urlencode ( $MebSea );
  4678. $this->data ['date'] = $date;
  4679. $this->data ['page'] = $pageinfo;
  4680. $this->data ['get'] = $get;
  4681. $this->data ['list'] = $list;
  4682. $this->data ['status'] = $status;
  4683. $this->data ['sidKey'] = $sidKey;
  4684. $this->data ['memu'] = "invoice";
  4685. $this->data ['staff'] = $this->staff;
  4686. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4687. $this->render ( "/admin/invoiceAggregateStaffDetail", $this->data );
  4688. }
  4689. /**
  4690. * 办事处人员汇总收款情
  4691. */
  4692. function invoiceAggregateStaffReceivablesDetail() {
  4693. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  4694. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  4695. Doo::loadModel ( 'invoiceReceivables' );
  4696. $invoiceReceivables = new invoiceReceivables ();
  4697. Doo::loadModel ( 'staff' );
  4698. $staff = new staff ();
  4699. Doo::loadModel ( "invoiceCategoryManage" );
  4700. $invoiceCategoryManage = new invoiceCategoryManage ();
  4701. Doo::loadClass ( 'XDeode' );
  4702. $XDeode = new XDeode ( 5 );
  4703. $sid = $XDeode->decode ( $sidKey );
  4704. $staffDetail = $staff->getStaffBySid ( $sid );
  4705. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4706. $cidList = array ();
  4707. foreach ( $imcStaff as $key => $value ) {
  4708. array_push ( $cidList, $value ['cid'] );
  4709. if (empty ( $cidKey ))
  4710. $cidKey = $XDeode->encode ( $value ['cid'] );
  4711. }
  4712. $cidString = implode ( ',', $cidList );
  4713. $staffList = $staff->getStaffInCid ( $cidString );
  4714. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4715. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  4716. $page_size = 10;
  4717. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4718. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4719. if ($timeType == "BINDOTP") {
  4720. $status = 'Credited';
  4721. }
  4722. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  4723. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  4724. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  4725. $dateArr = explode ( ':', $date );
  4726. $D1 = '';
  4727. $D2 = '';
  4728. if (! empty ( $date )) {
  4729. $D1 = $dateArr [0] . " 00:00:00 ";
  4730. if (isset ( $dateArr [1] ))
  4731. $D2 = $dateArr [1] . " 23:59:59 ";
  4732. else
  4733. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4734. }
  4735. $con = ' a.receivablesStaff like "%' . $staffDetail ['username'] . '%" ';
  4736. $descField = 'a.bindDate';
  4737. if ($timeType == 'CREATE')
  4738. $descField = 'a.date';
  4739. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4740. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4741. elseif (! empty ( $D1 ) && empty ( $D2 ))
  4742. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  4743. if ($status == 'Unclaimed')
  4744. $con .= ' and a.bindStatus=0';
  4745. elseif ($status == 'Credited')
  4746. $con .= ' and a.bindStatus=1';
  4747. elseif ($status == 'Claim')
  4748. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  4749. elseif ($status == 'BBN')
  4750. $con .= ' and a.bindPrice>a.receivablesPrice';
  4751. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  4752. if (! empty ( $MebSea )) {
  4753. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" )';
  4754. }
  4755. $pageinfo ['page'] = array (
  4756. 'previous' => ''
  4757. );
  4758. // $sql = 'select group_concat(b.invoiceSerial) as invoiceSerial ,group_concat(b.iid) as invoiceId
  4759. // from CLD_invoiceReceivables as a left join CLD_invoice as b on
  4760. // find_in_set(b.iid,a.iidExtend) or a.iid=b.iid
  4761. // where ' . $con . ' group by a.irid ';
  4762. $pageinfo =$this->get_page ( "CLD_invoiceReceivables as a", $con, $page, $page_size, "invoiceAggregateStaffReceivablesDetail", $get, "" );
  4763. //$pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceAggregateStaffReceivablesDetail", $get, "" );
  4764. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4765. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', $descField);
  4766. foreach ( $list as $key => $value ) {
  4767. $list [$key] ['category'] = '';
  4768. if ($value ['receivablesCategory'] != 'PUBLIC') {
  4769. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  4770. $list [$key] ['category'] = $receivablesCategory [1];
  4771. }
  4772. }
  4773. // print_r($list);
  4774. $this->data ['staffDetail'] = $staffDetail;
  4775. $this->data ['sidKey'] = $sidKey;
  4776. $this->data ['staffList'] = $staffList;
  4777. $this->data ['timeType'] = $timeType;
  4778. $this->data ['MebSeaEn'] = $MebSea;
  4779. $this->data ['MebSea'] = urlencode ( $MebSea );
  4780. $this->data ['date'] = $date;
  4781. $this->data ['page'] = $pageinfo;
  4782. $this->data ['get'] = $get;
  4783. $this->data ['list'] = $list;
  4784. $this->data ['status'] = $status;
  4785. $this->data ['memu'] = "invoice";
  4786. $this->data ['staff'] = $this->staff;
  4787. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4788. $this->render ( "/admin/invoiceAggregateStaffReceivablesDetail", $this->data );
  4789. }
  4790. function invoiceAchieve() {
  4791. Doo::loadModel ( 'invoice' );
  4792. $invoice = new invoice ();
  4793. Doo::loadClass ( 'XDeode' );
  4794. $XDeode = new XDeode ( 5 );
  4795. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4796. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4797. $page_size = 18;
  4798. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4799. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4800. $get = "/" . $date;
  4801. $con = '';
  4802. if ($date == 'MONTHO')
  4803. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4804. elseif ($date == 'MONTHT')
  4805. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4806. elseif ($date == 'MONTHY')
  4807. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4808. if (! empty ( $MebSea )) {
  4809. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4810. $get .= "/" . $MebSea;
  4811. }
  4812. $pageinfo ['page'] = array (
  4813. 'previous' => ''
  4814. );
  4815. $sql = 'status=2 and printStatus=1 and irid!="" and ( untreadStatus=3 or untreadStatus=0 ) and sid=' . $sid . $con;
  4816. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceAchieve", $get, "" );
  4817. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4818. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  4819. // print_r($pageinfo);
  4820. $this->data ['MebSeaEn'] = $MebSea;
  4821. $this->data ['MebSea'] = urlencode ( $MebSea );
  4822. $this->data ['get'] = $get;
  4823. $this->data ['page'] = $pageinfo;
  4824. $this->data ['list'] = $list;
  4825. $this->data ['date'] = $date;
  4826. $this->data ['memu'] = "invoice";
  4827. $this->data ['staff'] = $this->staff;
  4828. $this->data ['receiptMemu'] = 'invoice';
  4829. $this->render ( "/admin/invoiceAchieve", $this->data );
  4830. }
  4831. /**
  4832. */
  4833. function invoiceMyUnAccountAchieve() {
  4834. Doo::loadModel ( 'invoice' );
  4835. $invoice = new invoice ();
  4836. Doo::loadClass ( 'XDeode' );
  4837. $XDeode = new XDeode ( 5 );
  4838. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4839. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4840. $page_size = 18;
  4841. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4842. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4843. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4844. $dateArr = explode ( ':', $date );
  4845. $D1 = '';
  4846. $D2 = '';
  4847. if (! empty ( $date )) {
  4848. $D1 = $dateArr [0];
  4849. $D2 = $dateArr [1];
  4850. }
  4851. $con = '';
  4852. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4853. $con = ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4854. if (! empty ( $MebSea )) {
  4855. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4856. }
  4857. $pageinfo ['page'] = array (
  4858. 'previous' => ''
  4859. );
  4860. // and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  4861. $sql = " status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid= " . $sid . $con;
  4862. $action = "invoiceMyUnAccountAchieve";
  4863. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  4864. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4865. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 'desc', 'printTime' );
  4866. Doo::loadModel ( 'express' );
  4867. $express = new express ();
  4868. $expressList = $express->getExpressByAll ();
  4869. $this->data ['expressList'] = $expressList;
  4870. // print_r($list);
  4871. $this->data ['MebSeaEn'] = $MebSea;
  4872. $this->data ['get'] = $get;
  4873. $this->data ['page'] = $pageinfo;
  4874. $this->data ['date'] = $date;
  4875. $this->data ['list'] = $list;
  4876. $this->data ['memu'] = "invoice";
  4877. $this->data ['staff'] = $this->staff;
  4878. $this->data ['receiptMemu'] = 'invoice';
  4879. $this->render ( "/admin/invoiceMyUnAccountAchieve", $this->data );
  4880. }
  4881. function invoiceReceivablesAchieve() {
  4882. Doo::loadModel ( 'invoiceReceivables' );
  4883. $invoiceReceivables = new invoiceReceivables ();
  4884. Doo::loadClass ( 'XDeode' );
  4885. $XDeode = new XDeode ( 5 );
  4886. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4887. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  4888. $page_size = 12;
  4889. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4890. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4891. $get = "/" . $date;
  4892. $con = '';
  4893. if ($date == 'MONTHO')
  4894. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4895. elseif ($date == 'MONTHT')
  4896. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4897. elseif ($date == 'MONTHY')
  4898. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4899. if (! empty ( $MebSea )) {
  4900. $con .= ' and ( receivablesMessage like "%' . $MebSea . '%" or receivablesPrice like "%' . $MebSea . '%" )';
  4901. $get .= "/" . $MebSea;
  4902. }
  4903. $pageinfo ['page'] = array (
  4904. 'previous' => ''
  4905. );
  4906. $sql = " bindStatus=1 and receivablesStaff like '" . $sid . "-%' " . $con;
  4907. $pageinfo = $this->get_page ( "CLD_invoiceReceivables", $sql, $page, $page_size, "invoiceReceivablesAchieve", $get, "" );
  4908. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4909. $list = $invoiceReceivables->getReceivablesByUntreadStatusPage ( $limit, $sql );
  4910. // print_r($pageinfo);
  4911. $this->data ['MebSeaEn'] = $MebSea;
  4912. $this->data ['MebSea'] = urlencode ( $MebSea );
  4913. $this->data ['get'] = $get;
  4914. $this->data ['page'] = $pageinfo;
  4915. $this->data ['list'] = $list;
  4916. $this->data ['date'] = $date;
  4917. $this->data ['memu'] = "invoice";
  4918. $this->data ['staff'] = $this->staff;
  4919. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  4920. $this->render ( "/admin/invoiceReceivablesAchieve", $this->data );
  4921. }
  4922. /**
  4923. * 收款解绑
  4924. */
  4925. function invoiceUnBundLing() {
  4926. $unBundKey = $this->get_args ( 'unBundKey' ) ? $this->get_args ( 'unBundKey' ) : '';
  4927. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  4928. Doo::loadModel ( 'invoice' );
  4929. $invoice = new invoice ();
  4930. Doo::loadModel ( 'invoiceReceivables' );
  4931. $invoiceReceivables = new invoiceReceivables ();
  4932. Doo::loadModel ( 'invoiceOperationLog' );
  4933. $invoiceOperationLog = new invoiceOperationLog ();
  4934. Doo::loadModel ( 'invoiceROLog' );
  4935. $invoiceROLog = new invoiceROLog ();
  4936. Doo::loadModel ( 'invoiceStatistics' );
  4937. Doo::loadClass ( 'XDeode' );
  4938. $XDeode = new XDeode ( 5 );
  4939. if (empty ( $iidKey ) || empty ( $unBundKey ))
  4940. die ( 'illegal request' );
  4941. $iid = $XDeode->decode ( $iidKey );
  4942. $irid = $invoice->authcode ( $unBundKey );
  4943. if ((! empty ( $irid ) && ! is_numeric ( $irid )) || (! empty ( $iid ) && ! is_numeric ( $iid )))
  4944. die ( 'illegal request' );
  4945. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4946. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  4947. if (empty ( $irDetails ) || empty ( $invoiceDetails ) || (empty ( $irDetails ['iid'] ) && empty ( $irDetails ['iidExtend'] )) || $invoiceDetails ['untreadStatus'] == 2)
  4948. die ( 'illegal request' );
  4949. // 收款
  4950. $item = array (
  4951. 'irid' => $irDetails ['irid'],
  4952. 'bindPrice' => $irDetails ['bindPrice'] - $invoiceDetails ['invoicePrice'],
  4953. 'bindStatus' => 0
  4954. );
  4955. if ($irDetails ['iid'] == $iid)
  4956. $item += array (
  4957. 'iid' => 0
  4958. );
  4959. else {
  4960. $iidExtend = explode ( ',', $irDetails ['iidExtend'] );
  4961. foreach ( $iidExtend as $key => $value ) {
  4962. if ($value == $iid)
  4963. unset ( $iidExtend [$key] );
  4964. }
  4965. $iidExtend = implode ( ',', $iidExtend );
  4966. $item += array (
  4967. 'iidExtend' => $iidExtend
  4968. );
  4969. }
  4970. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4971. // 收款操作日志
  4972. $item = array (
  4973. 'operation' => $this->staff [0] ['username'] . " 解绑 " . $irDetails ['receivablesSerial'],
  4974. 'date' => date ( "Y-m-d" ),
  4975. 'status' => 3,
  4976. 'img' => $this->staff [0] ['avatar'],
  4977. 'username' => $this->staff [0] ['username'],
  4978. 'uid' => $this->staff [0] ['sid'],
  4979. 'category' => $this->staff [0] ['category'],
  4980. 'irid' => $irid
  4981. );
  4982. $invoiceROLog->setInvoiceROLog ( $item );
  4983. // 扣除入账统计金额
  4984. $invoiceStatistics = new invoiceStatistics ();
  4985. $item = array (
  4986. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  4987. 'priceClass' => 3,
  4988. 'cid' => $invoiceDetails ['cid'],
  4989. 'staff' => $invoiceDetails ['sid'],
  4990. 'accountPrice' => - $invoiceDetails ['invoicePrice']
  4991. );
  4992. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4993. // 扣除收款统计金额
  4994. $invoiceStatistics = new invoiceStatistics ();
  4995. $item = array (
  4996. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  4997. 'priceClass' => 2,
  4998. 'cid' => $invoiceDetails ['cid'],
  4999. 'staff' => $invoiceDetails ['sid'],
  5000. 'irid' => $irDetails ['irid'],
  5001. 'receivablesPrice' => - $invoiceDetails ['invoicePrice']
  5002. );
  5003. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  5004. // 发票解绑去收款ID
  5005. $iridString = $invoiceDetails ['irid'];
  5006. if (! empty ( $invoiceDetails ['irid'] )) {
  5007. $list = explode ( ',', $invoiceDetails ['irid'] );
  5008. foreach ( $list as $key => $value ) {
  5009. if ($value == $irDetails ['irid']) {
  5010. unset ( $list [$key] );
  5011. break;
  5012. }
  5013. }
  5014. $iridString = implode ( ",", $list );
  5015. }
  5016. //解绑后余额 加回去
  5017. $invoiceBalance=$invoiceDetails['invoiceBalance']+$irDetails['receivablesPrice'];
  5018. if ($invoiceBalance<0){
  5019. $invoiceBalance=0;
  5020. }
  5021. if($invoiceBalance>$invoiceDetails['invoicePrice']){
  5022. $invoiceBalance=$invoiceDetails['invoicePrice'];
  5023. }
  5024. $item = array (
  5025. 'iid' => $invoiceDetails ['iid'],
  5026. 'irid' => $iridString,
  5027. 'invoiceBalance'=>$invoiceBalance,
  5028. 'updateTime' => date ( "Y-m-d H:i:s" )
  5029. );
  5030. if ($invoiceDetails ['untreadStatus'] == 3)
  5031. $item += array (
  5032. 'untreadStatus' => 0
  5033. );
  5034. $invoice->setInvoiceByCondition ( $item );
  5035. Doo::loadModel ( 'bill' );
  5036. $bill = new bill ();
  5037. $bill->iid=$invoiceDetails ['iid'];
  5038. $bill->trainId=$invoiceDetails['trainId'];
  5039. $bill->irid=$irDetails ['irid'];
  5040. $bill->create_time=date ( "Y-m-d H:i:s" );
  5041. $bill->price=-$invoiceDetails ['invoicePrice'];
  5042. $bill->remark='解绑-扣除入账';
  5043. $bill->insert ();
  5044. $item = array (
  5045. 'date' => date ( "Y-m-d H:i:s" ),
  5046. 'operation' => '解绑 收款 ' . $irDetails ['receivablesSerial'],
  5047. 'status' => 11,
  5048. 'img' => $this->staff [0] ['avatar'],
  5049. 'username' => $this->staff [0] ['username'],
  5050. 'uid' => $this->staff [0] ['sid'],
  5051. 'category' => $this->staff [0] ['category'],
  5052. 'iid' => $invoiceDetails ['iid']
  5053. );
  5054. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  5055. // 公司流水-解绑时删除流水
  5056. // Doo::loadModel ( 'wasteBook' );
  5057. // $wasteBook = new wasteBook ();
  5058. // $wasteBook->delete ( array (
  5059. // 'where' => 'dataID=' . $irDetails ['irid'] . ' and accountType=7',
  5060. // 'limit' => 1
  5061. // ) );
  5062. // 银行
  5063. /*
  5064. * $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); }
  5065. */
  5066. return "/invoiceReceivablesAS";
  5067. }
  5068. /**
  5069. * 或者该收款下的所以发票
  5070. */
  5071. function ajaxGetInvoiceReceivablesByInvoice() {
  5072. $irid = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : '';
  5073. Doo::loadModel ( 'invoice' );
  5074. $invoice = new invoice ();
  5075. Doo::loadModel ( 'invoiceReceivables' );
  5076. $invoiceReceivables = new invoiceReceivables ();
  5077. $irid = $invoice->authcode ( $irid );
  5078. if (! empty ( $irid ) && ! is_numeric ( $irid ))
  5079. die ( 'illegal request' );
  5080. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5081. $iidString = $irDetails ['iid'];
  5082. $iidExtend = array_filter ( explode ( ',', $irDetails ['iidExtend'] ) );
  5083. if (! empty ( $irDetails ['iidExtend'] ))
  5084. $iidString .= ',' . implode ( ',', $iidExtend );
  5085. $invoiceList = $invoice->getInvoiceInIid ( $iidString, 'iid,invoiceSerial,invoicePrice,invoiceTitle,invoiceCompany,invoiceElement' );
  5086. $html = "";
  5087. foreach ( $invoiceList as $key => $value ) {
  5088. $title = $value ['invoiceTitle'];
  5089. if (! empty ( $value ['invoiceCompany'] ))
  5090. $title = $value ['invoiceCompany'];
  5091. $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>';
  5092. }
  5093. echo json_encode ( array (
  5094. 'status' => 1,
  5095. 'html' => $html
  5096. ) );
  5097. }
  5098. /**
  5099. * 发票管理
  5100. */
  5101. function invoiceAS() {
  5102. Doo::loadModel ( 'invoice' );
  5103. $invoice = new invoice ();
  5104. Doo::loadModel ( 'invoiceReceivables' );
  5105. $invoiceReceivables = new invoiceReceivables ();
  5106. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  5107. $page_size = 18;
  5108. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5109. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  5110. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5111. $dateArr = explode ( ':', $date );
  5112. $D1 = '';
  5113. $D2 = '';
  5114. if (! empty ( $date )) {
  5115. $D1 = $dateArr [0] . " 00:00:00 ";
  5116. if (isset ( $dateArr [1] ))
  5117. $D2 = $dateArr [1] . " 23:59:59 ";
  5118. else
  5119. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  5120. // $D2 = $dateArr [1];
  5121. }
  5122. $con = ' status=2 ';
  5123. if (! empty ( $D1 ) && ! empty ( $D2 ))
  5124. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  5125. if ($status == 'UNRECORD')
  5126. $con .= ' and printStatus=1 and untreadStatus=0';
  5127. elseif ($status == 'RECORD')
  5128. $con .= ' and printStatus=1 and untreadStatus=3';
  5129. elseif ($status == 'BOUNCED')
  5130. $con .= ' and untreadStatus=2';
  5131. elseif ($status == 'PARTRECORD')
  5132. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  5133. elseif ($status == 'All') {
  5134. $con .= ' and ( untreadStatus=2 or untreadStatus=1 or untreadStatus=0 or untreadStatus=3 )';
  5135. }
  5136. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  5137. if (! empty ( $MebSea )) {
  5138. $con .= ' and ( invoiceSerial like "%' . $MebSea . '%" or invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  5139. }
  5140. $pageinfo ['page'] = array (
  5141. 'previous' => ''
  5142. );
  5143. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAS", $get, "" );
  5144. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5145. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  5146. $this->data ['MebSeaEn'] = $MebSea;
  5147. $this->data ['MebSea'] = urlencode ( $MebSea );
  5148. $this->data ['date'] = $date;
  5149. $this->data ['page'] = $pageinfo;
  5150. $this->data ['get'] = $get;
  5151. $this->data ['list'] = $list;
  5152. $this->data ['status'] = $status;
  5153. $this->data ['memu'] = "invoice";
  5154. $this->data ['staff'] = $this->staff;
  5155. $this->data ['receiptMemu'] = 'invoiceReceivables';
  5156. $this->render ( "/admin/invoiceAS", $this->data );
  5157. }
  5158. /**
  5159. * 收款管理
  5160. */
  5161. function invoiceReceivablesAS() {
  5162. Doo::loadModel ( 'invoiceReceivables' );
  5163. $invoiceReceivables = new invoiceReceivables ();
  5164. Doo::loadModel ( 'L_category' );
  5165. $lCategory = new L_category ();
  5166. $category = $lCategory->getCategory ();
  5167. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  5168. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  5169. $page_size = 10;
  5170. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5171. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  5172. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5173. $dateArr = explode ( ':', $date );
  5174. $D1 = '';
  5175. $D2 = '';
  5176. if (! empty ( $date )) {
  5177. $D1 = $dateArr [0]; // ." 00:00:00 ";
  5178. if (isset ( $dateArr [1] ))
  5179. $D2 = $dateArr [1]; // ." 23:59:59 ";
  5180. else
  5181. $D2 = $dateArr [0]; // ." 23:59:59 ";//date ( "Y-m-d" );
  5182. }
  5183. $descField = 'a.receivablesDate';
  5184. if ($timeType == 'CREATE')
  5185. $descField = 'a.date';
  5186. $con = ' 1 ';
  5187. if (! empty ( $D1 ) && ! empty ( $D2 ))
  5188. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  5189. elseif (! empty ( $D1 ) && empty ( $D2 ))
  5190. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  5191. if ($status == 'Unclaimed')
  5192. $con .= ' and a.bindStatus=0';
  5193. elseif ($status == 'Credited')
  5194. $con .= ' and a.bindStatus=1';
  5195. elseif ($status == 'Claim')
  5196. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  5197. elseif ($status == 'BBN')
  5198. $con .= ' and a.bankBatchNumber!=""';
  5199. elseif ($status == 'REFUND')
  5200. $con .= ' and ( (a.bindStatus=0 and a.refundLog!="" ) or a.bindStatus=2)';
  5201. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  5202. if (! empty ( $MebSea )) {
  5203. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" or a.receivablesSerial like "%' . $MebSea . '%" )';
  5204. }
  5205. $pageinfo ['page'] = array (
  5206. 'previous' => ''
  5207. );
  5208. // if(!empty($con)){
  5209. // $con=' where 1 '.$con;
  5210. // }
  5211. // $sql = 'select a.iid from CLD_invoiceReceivables as a
  5212. // ' . $con ;
  5213. $pageinfo =$this->get_page ( "CLD_invoiceReceivables as a", $con, $page, $page_size, "invoiceReceivablesAS", $get, "" );
  5214. //echo $sql;
  5215. //$pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceReceivablesAS", $get, "" );
  5216. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5217. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', $descField );
  5218. foreach ( $list as $key => $value ) {
  5219. $list [$key] ['category'] = '';
  5220. if ($value ['receivablesCategory'] != 'PUBLIC') {
  5221. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  5222. $list [$key] ['category'] = $receivablesCategory [1];
  5223. }
  5224. }
  5225. // print_r($list);
  5226. $this->data ['category'] = $category;
  5227. $this->data ['timeType'] = $timeType;
  5228. $this->data ['MebSeaEn'] = $MebSea;
  5229. $this->data ['MebSea'] = urlencode ( $MebSea );
  5230. $this->data ['date'] = $date;
  5231. $this->data ['page'] = $pageinfo;
  5232. $this->data ['get'] = $get;
  5233. $this->data ['list'] = $list;
  5234. $this->data ['status'] = $status;
  5235. $this->data ['memu'] = "invoice";
  5236. $this->data ['staff'] = $this->staff;
  5237. $this->data ['receiptMemu'] = 'invoiceReceivables';
  5238. $this->render ( "/admin/invoiceReceivablesAS", $this->data );
  5239. }
  5240. /**
  5241. * 删除一条收款
  5242. */
  5243. function delInvoiceReceivables() {
  5244. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  5245. if (empty ( $iridKey ))
  5246. die ( 'illegal request' );
  5247. Doo::loadClass ( 'XDeode' );
  5248. $XDeode = new XDeode ( 5 );
  5249. $irid = $XDeode->decode ( $iridKey );
  5250. Doo::loadModel ( 'invoiceReceivables' );
  5251. $invoiceReceivables = new invoiceReceivables ();
  5252. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5253. if (empty ( $detail ))
  5254. die ( 'illegal request' );
  5255. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  5256. // 扣除收款汇总信息 汇总
  5257. Doo::loadModel ( 'invoiceStatistics' );
  5258. $invoiceStatistics = new invoiceStatistics ();
  5259. $item = array (
  5260. 'date' => $detail ['receivablesDate'],
  5261. 'priceClass' => 2,
  5262. 'irid' => $detail ['irid'],
  5263. 'receivablesPrice' => - $detail ['receivablesPrice']
  5264. );
  5265. if ($detail ['receivablesCategory'] != 'PUBLIC') {
  5266. $receivablesCategory = explode ( ":", $detail ['receivablesCategory'] );
  5267. $item += array (
  5268. 'cid' => $receivablesCategory [0]
  5269. );
  5270. }
  5271. if ($detail ['receivablesStaff'] != 'PUBLIC') {
  5272. $receivablesStaff = explode ( "-", $detail ['receivablesStaff'] );
  5273. $item += array (
  5274. 'staff' => $receivablesStaff [0]
  5275. );
  5276. }
  5277. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  5278. return '/invoiceReceivablesAS';
  5279. }
  5280. /**
  5281. * 添加退款信息
  5282. */
  5283. function setInvoiceReceivablesRefund() {
  5284. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5285. $refundType = $this->get_args ( 'refundType' ) && is_numeric ( $this->get_args ( 'refundType' ) ) ? $this->get_args ( 'refundType' ) : '0';
  5286. $refundCompany = $this->get_args ( 'refundCompany' ) ? $this->get_args ( 'refundCompany' ) : "";
  5287. $refundNumber = $this->get_args ( 'refundNumber' ) ? $this->get_args ( 'refundNumber' ) : "";
  5288. $refundPrice = $this->get_args ( 'refundPrice' ) ? $this->get_args ( 'refundPrice' ) : "";
  5289. $refundRemarks = $this->get_args ( 'refundRemarks' ) ? $this->get_args ( 'refundRemarks' ) : "";
  5290. if ($refundPrice < 0)
  5291. die ( 'illegal request' );
  5292. if (! empty ( $iridKey ) && ! empty ( $refundCompany ) && ! empty ( $refundNumber ) && ! empty ( $refundPrice )) {
  5293. Doo::loadModel ( 'invoiceReceivables' );
  5294. $invoiceReceivables = new invoiceReceivables ();
  5295. Doo::loadModel ( 'invoiceRefund' );
  5296. $invoiceRefund = new invoiceRefund ();
  5297. $irid = $invoiceReceivables->authcode ( $iridKey );
  5298. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5299. if ($irDetail ['receivablesPrice'] < $refundPrice)
  5300. die ( 'illegal request' );
  5301. $invoiceReceivables = new invoiceReceivables ();
  5302. $refundLog = $this->staff [0] ['username'] . ' 退款 <b class="colRed">¥' . $refundPrice . '</b>
  5303. <br/><a href="#refunded" onclick="getRefundByDetail(\'' . $iridKey . '\')" data-toggle="modal">退款信息</a> <br/>' . date ( "Y-m-d H:i:s" ) . '
  5304. ';
  5305. $item = array (
  5306. 'irid' => $irid,
  5307. 'refundCompany' => $refundCompany,
  5308. 'refundNumber' => $refundNumber,
  5309. 'refundPrice' => $refundPrice,
  5310. 'refundRemarks' => $refundRemarks,
  5311. 'refundLog' => $refundLog
  5312. );
  5313. if ($refundType == 1) {
  5314. $item += array (
  5315. 'refundType' => $refundType,
  5316. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice,
  5317. 'bindStatus' => 2
  5318. );
  5319. } elseif ($refundType == 0 && $irDetail ['receivablesPrice'] <= $refundPrice) {
  5320. $item += array (
  5321. 'refundType' => 1,
  5322. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice,
  5323. 'bindStatus' => 2
  5324. );
  5325. } else {
  5326. $item += array (
  5327. 'refundType' => $refundType,
  5328. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice
  5329. );
  5330. }
  5331. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  5332. // 添加退款记录
  5333. $item = array (
  5334. 'irid' => $irid,
  5335. 'refundType' => $refundType,
  5336. 'refundCompany' => $refundCompany,
  5337. 'refundNumber' => $refundNumber,
  5338. 'refundPrice' => $refundPrice,
  5339. 'refundLog' => $refundLog,
  5340. 'refundRemarks' => $refundRemarks,
  5341. 'date' => date ( "Y-m-d H:i:s" )
  5342. );
  5343. $invoiceRefund->addInvoiceRefund ( $item );
  5344. // 扣除收款汇总信息 汇总
  5345. Doo::loadModel ( 'invoiceStatistics' );
  5346. $invoiceStatistics = new invoiceStatistics ();
  5347. $item = array (
  5348. 'date' => $irDetail ['receivablesDate'],
  5349. 'priceClass' => 2,
  5350. 'irid' => $irDetail ['irid'],
  5351. 'receivablesPrice' => - $refundPrice
  5352. );
  5353. $receivablesCategory=array(0=>'',1=>'');
  5354. if ($irDetail ['receivablesCategory'] != 'PUBLIC') {
  5355. $receivablesCategory = explode ( ":", $irDetail ['receivablesCategory'] );
  5356. $item += array (
  5357. 'cid' => $receivablesCategory [0]
  5358. );
  5359. }
  5360. if ($irDetail ['receivablesStaff'] != 'PUBLIC') {
  5361. $receivablesStaff = explode ( "-", $irDetail ['receivablesStaff'] );
  5362. $item += array (
  5363. 'staff' => $receivablesStaff [0]
  5364. );
  5365. }
  5366. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  5367. // 公司日常支出流水
  5368. Doo::loadModel ( 'wasteBook' );
  5369. $wasteBook = new wasteBook ();
  5370. $accountBank=$wasteBook->_getAccountBankEN($irDetail ['receivablesBank']);
  5371. $itemWaste = array (
  5372. 'accountPrice' => - $refundPrice,
  5373. 'expensesType' => 2,
  5374. 'accountType' => 11,
  5375. 'accountPriceShow' => $refundPrice,
  5376. 'dataID' => $irid,
  5377. 'accountBank' => $accountBank,
  5378. 'category' => $receivablesCategory[1],
  5379. 'cid' => $receivablesCategory[0],
  5380. 'name' => $this->staff [0] ['username'],
  5381. 'sid' => $this->staff [0] ['sid'],
  5382. 'inputDate' => date ( "Y-m-d H:i:s" )
  5383. );
  5384. $wasteBook->setAccountBookStatistics ( $itemWaste );
  5385. return '/invoiceReceivablesAS';
  5386. }
  5387. die ( 'illegal request' );
  5388. }
  5389. function ajaxCheckInvoiceReceivablesRefund() {
  5390. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5391. $refundPrice = $this->get_args ( 'refundPrice' ) ? $this->get_args ( 'refundPrice' ) : "";
  5392. if ($refundPrice < 0) {
  5393. echo json_encode ( array (
  5394. 'error' => '金额不能为负'
  5395. ) );
  5396. die ();
  5397. }
  5398. if (! empty ( $refundPrice ) && ! empty ( $iridKey )) {
  5399. Doo::loadModel ( 'invoiceReceivables' );
  5400. $invoiceReceivables = new invoiceReceivables ();
  5401. $irid = $invoiceReceivables->authcode ( $iridKey );
  5402. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5403. if ($irDetail ['receivablesPrice'] < $refundPrice) {
  5404. echo json_encode ( array (
  5405. 'error' => '退款金额不能超过收款金额'
  5406. ) );
  5407. die ();
  5408. }
  5409. echo json_encode ( array (
  5410. 'ok' => '可以使用!'
  5411. ) );
  5412. die ();
  5413. }
  5414. }
  5415. /**
  5416. * 获得收款退款信息
  5417. */
  5418. function getRefundByDetail() {
  5419. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5420. Doo::loadModel ( 'invoiceReceivables' );
  5421. $invoiceReceivables = new invoiceReceivables ();
  5422. if (! empty ( $iridKey )) {
  5423. $irid = $invoiceReceivables->authcode ( $iridKey );
  5424. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5425. echo json_encode ( array (
  5426. 'status' => 1,
  5427. 'irDetail' => $irDetail
  5428. ) );
  5429. die ();
  5430. }
  5431. echo json_encode ( array (
  5432. 'status' => 2
  5433. ) );
  5434. }
  5435. /**
  5436. * 根据收款序列号获得收款退款信息
  5437. */
  5438. function ajaxGetInvoiceReceivablesBySerial() {
  5439. $receivablesSerial = $this->get_args ( 'receivablesSerial' ) ? $this->get_args ( 'receivablesSerial' ) : '';
  5440. if (! empty ( $receivablesSerial )) {
  5441. Doo::loadModel ( 'invoiceReceivables' );
  5442. $invoiceReceivables = new invoiceReceivables ();
  5443. // , ' and refundLog=""'
  5444. $irDetail = $invoiceReceivables->getInvoiceReceivablesBySerial ( $receivablesSerial );
  5445. $html = '';
  5446. if (! empty ( $irDetail ))
  5447. $html = '<td><b>¥' . $irDetail ['receivablesPrice'] . '</b></td>
  5448. <td>' . $irDetail ['receivablesMessage'] . '</td>
  5449. <td>' . $irDetail ['receivablesBank'] . '<br>' . $irDetail ['receivablesDate'] . '</td>
  5450. <td>' . $irDetail ['title'] . '-' . $irDetail ['username'] . '<br>' . $irDetail ['confirmTime'] . '</td>
  5451. <td>' . $irDetail ['recepitTitleMark'] . '
  5452. <input type="hidden" name="iridKey" id="iridKey" value="' . $irDetail ['iridKey'] . '">
  5453. </td>';
  5454. echo json_encode ( array (
  5455. 'status' => 1,
  5456. 'html' => $html,
  5457. 'irDetail' => $irDetail
  5458. ) );
  5459. die ();
  5460. }
  5461. echo json_encode ( array (
  5462. 'status' => 2
  5463. ) );
  5464. }
  5465. /**
  5466. * 绑定新收款
  5467. */
  5468. function relationNewInvoiceReceivables() {
  5469. $iridKeyOld = $this->get_args ( 'iridKeyOld' ) ? $this->get_args ( 'iridKeyOld' ) : '';
  5470. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5471. if (! empty ( $iridKeyOld ) && ! empty ( $iridKey )) {
  5472. Doo::loadModel ( 'invoiceReceivables' );
  5473. $invoiceReceivables = new invoiceReceivables ();
  5474. Doo::loadClass ( 'XDeode' );
  5475. $XDeode = new XDeode ( 5 );
  5476. $irid = $XDeode->decode ( $iridKey );
  5477. $iridOld = $invoiceReceivables->authcode ( $iridKeyOld );
  5478. echo $irid . 'bbb' . $iridOld;
  5479. $oldIrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $iridOld );
  5480. $IrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5481. if (empty ( $oldIrDetail ) || empty ( $IrDetail ))
  5482. die ( 'illegal request' );
  5483. $relationLog = $this->staff [0] ['username'] . ' 关联新款 <a href="#billing" onclick="invoiceReceivblesDivShow(\'' . $iridKey . '\',\'receivables\')" data-toggle="modal">' . $IrDetail ['receivablesSerial'] . '</a>
  5484. <br/>' . date ( "Y-m-d H:i:s" ) . '
  5485. ';
  5486. $invoiceReceivables = new invoiceReceivables ();
  5487. $item = array (
  5488. 'irid' => $iridOld,
  5489. 'relationIrid' => $irid,
  5490. 'relationLog' => $relationLog
  5491. );
  5492. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  5493. return '/invoiceReceivablesAS';
  5494. }
  5495. die ( 'illegal request' );
  5496. }
  5497. // function invoiceApprovalAchieve() {
  5498. // Doo::loadModel ( 'invoice' );
  5499. // $invoice = new invoice ();
  5500. // $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  5501. // $page_size = 12;
  5502. // $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5503. // $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  5504. // $get = "/" . $date;
  5505. // $con = '';
  5506. // if ($date == 'MONTHO')
  5507. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  5508. // elseif ($date == 'MONTHT')
  5509. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  5510. // elseif ($date == 'MONTHY')
  5511. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  5512. // if (! empty ( $MebSea )) {
  5513. // $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  5514. // $get .= "/" . $MebSea;
  5515. // }
  5516. // $pageinfo ['page'] = array (
  5517. // 'previous' => ''
  5518. // );
  5519. // $sql = '(status=1 or status=2 or status=3 or status=4) and processApprovals!=""' . $con; // echo $sql;
  5520. // $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", $get, "" );
  5521. // $limit = $pageinfo ['lower'] . ',' . $page_size;
  5522. // $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  5523. // // print_r($list);
  5524. // $this->data ['MebSeaEn'] = $MebSea;
  5525. // $this->data ['MebSea'] = urlencode ( $MebSea );
  5526. // $this->data ['get'] = $get;
  5527. // $this->data ['page'] = $pageinfo;
  5528. // $this->data ['list'] = $list;
  5529. // $this->data ['date'] = $date;
  5530. // $this->data ['memu'] = "invoice";
  5531. // $this->data ['staff'] = $this->staff;
  5532. // $this->data ['receiptMemu'] = 'invoiceApproval';
  5533. // $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  5534. // }
  5535. /**
  5536. * 获得审批发票的信息以及审批页面
  5537. */
  5538. function ajaxGetInvoiceApprovalDetail() {
  5539. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5540. if (empty ( $serial )) {
  5541. echo json_encode ( array (
  5542. 'status' => 2,
  5543. 'msg' => 'illegal request'
  5544. ) );
  5545. die ();
  5546. }
  5547. Doo::loadModel ( 'invoice' );
  5548. $invoice = new invoice ();
  5549. Doo::loadModel ( 'invoiceOperationLog' );
  5550. $invoiceOperationLog = new invoiceOperationLog ();
  5551. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5552. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5553. if (empty ( $detail ))
  5554. $html = '';
  5555. else {
  5556. $html = '
  5557. <form action="/invoiceApprovalDo" method="post" name="invoiceApproval" class="nice-validator n-yellow" novalidate="novalidate">
  5558. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  5559. <input type="hidden" name="status" value="">
  5560. <input type="hidden" name="divApproval" value="divApproval">
  5561. <div class="modal-dialog modal-lg">
  5562. <div class="modal-content"><div class="modal-header"><h3>发票审批详情</h3></div>
  5563. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  5564. <tr>
  5565. <th class="taC" width="150">发票审批</th><td><textarea name="opinion" style="width:98%" placeholder="在这写下您的审批意见,选填。"></textarea></td>
  5566. </tr>
  5567. <tr>
  5568. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5569. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5570. </tr>
  5571. <tr>
  5572. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5573. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5574. </tr>
  5575. <tr>
  5576. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5577. </td>
  5578. </tr>
  5579. <tr>
  5580. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5581. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5582. </tr>
  5583. <tr>
  5584. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5585. </tr></tbody></table>';
  5586. if ($detail ['invoiceType'] == 0)
  5587. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5588. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5589. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5590. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5591. </tr>';
  5592. else
  5593. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5594. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5595. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5596. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5597. ';
  5598. $html .= '<tr>
  5599. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5600. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5601. </tr>
  5602. <tr>
  5603. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5604. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5605. </tr></tbody></table>';
  5606. if ($detail ['doPost'] == 1) {
  5607. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5608. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5609. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5610. </tr><tr>
  5611. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5612. </tr><tr>
  5613. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5614. </tr>
  5615. ';
  5616. if ($detail ['expressCom'] == 'SF')
  5617. $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>';
  5618. else
  5619. $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>';
  5620. $html .= '</tbody></table>';
  5621. }
  5622. if (! empty ( $invoiceOperationLogList )) {
  5623. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  5624. foreach ( $invoiceOperationLogList as $key => $value ) {
  5625. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5626. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5627. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5628. if ($value ['status'] == 2) {
  5629. $html .= '<span class="colGreen">同意</span>';
  5630. } elseif ($value ['status'] == 3) {
  5631. $html .= '<span class="colOrange">退回</span>';
  5632. } elseif ($value ['status'] == 5) {
  5633. $html .= '<span class="colGreen">打印</span>';
  5634. } elseif ($value ['status'] == 4) {
  5635. $html .= '<span class="colRed">终止</span>';
  5636. }
  5637. $html .= $value ['operation'] . '</p></blockquote>';
  5638. }
  5639. }
  5640. $html .= '</td></tr></tbody></table>';
  5641. }
  5642. $html .= '</div><div class="modal-footer">
  5643. <a href="javascript:void(0)" node-approval="approval" diss-data="2" class="button btn-done" data-placement="top" data-toggle="ctooltip" >同意</a>
  5644. <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>
  5645. <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>
  5646. <a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>
  5647. </form>
  5648. <script type="text/javascript">
  5649. $("a[node-approval^=\'approval\']").click(function() {
  5650. $("input[name=\'status\']").val($(this).attr("diss-data"));
  5651. $("form[name=\'invoiceApproval\']").submit();
  5652. });
  5653. </script>
  5654. ';
  5655. }
  5656. echo json_encode ( array (
  5657. 'status' => 1,
  5658. 'html' => $html
  5659. ) );
  5660. die ();
  5661. }
  5662. /**
  5663. * 获得审批发票分页数据
  5664. */
  5665. function ajaxGetinvoiceApprovalAchieve() {
  5666. Doo::loadModel ( 'invoice' );
  5667. $invoice = new invoice ();
  5668. Doo::loadModel ( 'staff' );
  5669. $staff = new staff ();
  5670. Doo::loadClass ( 'XDeode' );
  5671. $XDeode = new XDeode ( 5 );
  5672. Doo::loadModel ( 'invoiceTraining' );
  5673. $invoiceTraining = new invoiceTraining ();
  5674. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  5675. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5676. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5677. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5678. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5679. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  5680. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  5681. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  5682. $MebSea = $this->get_args ( 'search' );
  5683. $MebSea = $MebSea ['value'];
  5684. $page_size = $length;
  5685. $con = '';
  5686. if ($status == 'ALL')
  5687. $con = ' (status=1 or status=2 or status=3 or status=4) and isDelete=0 ';
  5688. elseif ($status == 'PEND')
  5689. $con = ' isDelete=0 and status=1';
  5690. elseif ($status == 'APPROVED')
  5691. $con = ' isDelete=0 and status=2';
  5692. if ($invoiceType == 'ORDINARY')
  5693. $con .= ' and invoiceType=0 ';
  5694. elseif ($invoiceType == 'SPECIAL')
  5695. $con .= ' and invoiceType=1 ';
  5696. if ($invoiceTrain == 'ORDINARY')
  5697. $con .= ' and trainId=0 ';
  5698. elseif ($invoiceTrain == 'TRAIN')
  5699. $con .= ' and trainId!=0 ';
  5700. if ($invoiceTrainName != 'ALL') {
  5701. $trainId = $XDeode->decode ( $invoiceTrainName );
  5702. if (is_numeric ( $trainId ))
  5703. $con .= ' and trainId =' . $trainId;
  5704. }
  5705. $dateArr = explode ( ':', $date );
  5706. $D1 = $dateString = '';
  5707. $D2 = '';
  5708. if (! empty ( $date )) {
  5709. $D1 = $dateArr [0];
  5710. if (isset ( $dateArr [1] ))
  5711. $D2 = $dateArr [1];
  5712. else
  5713. $D2 = '';
  5714. $dateString = $D1 . " : " . $D2;
  5715. }
  5716. if (! empty ( $D1 ) && ! empty ( $D2 ))
  5717. $con .= ' and approvalTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  5718. elseif (! empty ( $D1 ) && empty ( $D2 ))
  5719. $con .= ' and approvalTime like "%' . $D1 . '%" ';
  5720. if (! empty ( $MebSea ))
  5721. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceSerial like "%' . $MebSea . '%" )';
  5722. // /
  5723. $pageinfo ['page'] = array (
  5724. 'previous' => ''
  5725. );
  5726. $sql = ' ' . $con;
  5727. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", '', "" );
  5728. $limit = $page . ',' . $page_size;
  5729. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  5730. $approvalList = array ();
  5731. $html = '<script type="text/javascript">
  5732. </script>';
  5733. // 结算结束不能修改方式
  5734. Doo::loadModel ( 'receipt' );
  5735. $receipt = new receipt ();
  5736. foreach ( $list as $key => $value ) {
  5737. $irDetail = array ();
  5738. // 结算方式
  5739. $receiptDetail = array ();
  5740. if ($value ['trainId'] != 0) {
  5741. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $value ['trainId'] );
  5742. }
  5743. if (! empty ( $receiptDetail )) {
  5744. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9) {
  5745. array_push ( $irDetail, '' );
  5746. } else {
  5747. if ($value ['status'] == 1 && $value ['pendingApprovals'] == $this->staff [0] ['sid']) {
  5748. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoiceApproval(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">审批发票</a>' );
  5749. } elseif ($value ['status'] == 2) {
  5750. array_push ( $irDetail, '<a href="#editPay" class="fnSettlementType" data-iidKey="' . $value ['iidKeyK'] . '" data-toggle="modal">结算方式</a>' );
  5751. } else
  5752. array_push ( $irDetail, '' );
  5753. }
  5754. } else {
  5755. if ($value ['status'] == 2) {
  5756. array_push ( $irDetail, '<a href="#editPay" class="fnSettlementType" data-iidKey="' . $value ['iidKeyK'] . '" data-toggle="modal">结算方式</a>' );
  5757. } else{
  5758. if ($value ['status'] == 1 && $value ['pendingApprovals'] == $this->staff [0] ['sid']) {
  5759. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoiceApproval(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">审批发票</a>' );
  5760. }else{
  5761. array_push ( $irDetail, '' );
  5762. }
  5763. }
  5764. }
  5765. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  5766. if ($value ['invoiceType'] == 1)
  5767. array_push ( $irDetail, $value ['invoiceCompany'] );
  5768. else
  5769. array_push ( $irDetail, $value ['invoiceTitle'] );
  5770. array_push ( $irDetail, $value ['TIN'] );
  5771. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  5772. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  5773. array_push ( $irDetail, $value ['remark'] );
  5774. array_push ( $irDetail, $value ['invoiceElement'] );
  5775. array_push ( $irDetail, $value ['invoiceQuantity'] );
  5776. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  5777. if ($value ['invoiceType'] == 1) {
  5778. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  5779. } else {
  5780. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  5781. }
  5782. if ($value ['settlementType'] == 0) {
  5783. array_push ( $irDetail, '软件销售' );
  5784. } else {
  5785. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $value ['trainId'] );
  5786. array_push ( $irDetail, $itDetail ['trainName'] );
  5787. }
  5788. array_push ( $irDetail, $value ['recipients'] . $value ['recipientsPhone'] );
  5789. array_push ( $irDetail, $value ['recipientsAddress'] );
  5790. array_push ( $irDetail, $value ['mailItems'] );
  5791. array_push ( $irDetail, $value ['userName'] . '&nbsp;' . $value ['date'] );
  5792. $fchtml = $value ['OL'] ['operation'];
  5793. if (count ( $list ) == $page_size)
  5794. $fchtml = $value ['OL'] ['operation'] . $html;
  5795. // 最后的审批意见
  5796. array_push ( $irDetail, $fchtml );
  5797. if ($value ['status'] == 2)
  5798. array_push ( $irDetail, '<span class="colGreen">同意</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5799. elseif ($value ['status'] == 3)
  5800. array_push ( $irDetail, '<span class="colOrange">退回</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5801. elseif ($value ['status'] == 4)
  5802. array_push ( $irDetail, '<span class="colRed">终止</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5803. else
  5804. array_push ( $irDetail, '' );
  5805. array_push ( $approvalList, $irDetail );
  5806. }
  5807. // $approvalListJson = json_encode ( $approvalList );
  5808. $recordsFiltered = $pageinfo ['total_data'];
  5809. echo json_encode ( array (
  5810. "draw" => intval ( $draw ),
  5811. "recordsTotal" => intval ( $pageinfo ['total_data'] ),
  5812. "recordsFiltered" => intval ( $recordsFiltered ),
  5813. "data" => $approvalList
  5814. ), JSON_UNESCAPED_UNICODE );
  5815. }
  5816. /**
  5817. * 审批发票查看更多--重构
  5818. */
  5819. function invoiceApprovalAchieve() {
  5820. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'ALL';
  5821. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5822. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5823. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5824. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5825. Doo::loadModel ( 'invoiceTraining' );
  5826. $invoiceTraining = new invoiceTraining ();
  5827. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  5828. $this->data ['trainList'] = $trainList;
  5829. $this->data ['dateString'] = $date;
  5830. $this->data ['status'] = $status;
  5831. $this->data ['invoiceType'] = $invoiceType;
  5832. $this->data ['invoiceTrain'] = $invoiceTrain;
  5833. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  5834. $this->data ['memu'] = "invoice";
  5835. $this->data ['staff'] = $this->staff;
  5836. $this->data ['receiptMemu'] = 'invoiceApproval';
  5837. $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  5838. }
  5839. function invoiceTAchieve() {
  5840. Doo::loadModel ( 'invoice' );
  5841. $invoice = new invoice ();
  5842. Doo::loadClass ( 'XDeode' );
  5843. $XDeode = new XDeode ( 5 );
  5844. Doo::loadModel ( 'staff' );
  5845. $staff = new staff ();
  5846. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  5847. $page_size = 12;
  5848. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5849. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  5850. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5851. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5852. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5853. Doo::loadModel ( 'invoiceTraining' );
  5854. $invoiceTraining = new invoiceTraining ();
  5855. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  5856. $get = "/" . $date;
  5857. $con = '';
  5858. if ($date == 'MONTHO')
  5859. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  5860. elseif ($date == 'MONTHT')
  5861. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  5862. elseif ($date == 'MONTHY')
  5863. $con = ' and YEAR(updateTime) = YEAR(NOW())'; // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  5864. if ($invoiceType == 'ORDINARY')
  5865. $con .= ' and invoiceType=0 ';
  5866. elseif ($invoiceType == 'SPECIAL')
  5867. $con .= ' and invoiceType=1 ';
  5868. if ($invoiceTrain == 'ORDINARY')
  5869. $con .= ' and trainId=0 ';
  5870. elseif ($invoiceTrain == 'TRAIN')
  5871. $con .= ' and trainId!=0 ';
  5872. if ($invoiceTrainName != 'ALL') {
  5873. $trainId = $XDeode->decode ( $invoiceTrainName );
  5874. if (is_numeric ( $trainId ))
  5875. $con .= ' and trainId =' . $trainId;
  5876. }
  5877. if (! empty ( $MebSea )) {
  5878. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  5879. $get .= "/" . $MebSea;
  5880. }
  5881. $pageinfo ['page'] = array (
  5882. 'previous' => ''
  5883. );
  5884. $sql = "";
  5885. $action = "";
  5886. if ($this->ACTION == 'invoicePrintAchieve') {
  5887. $sql = "status=2 and printStatus=1 and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  5888. $action = "invoicePrintAchieve";
  5889. } elseif ($this->ACTION == 'invoicePostAchieve') {
  5890. // and untreadStatus=0
  5891. $sql = "postStatus=1 and doPost=1 and status=2 and isDelete=0" . $con;
  5892. $action = "invoicePostAchieve";
  5893. } elseif ($this->ACTION == 'invoiceUntreadAchieve') { // printStatus=1 and
  5894. $sql = " untreadStatus=2 and status=2 " . $con;
  5895. $action = "invoiceUntreadAchieve";
  5896. }
  5897. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  5898. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5899. $this->data ['MebSeaEn'] = $MebSea;
  5900. $this->data ['MebSea'] = urlencode ( $MebSea );
  5901. $this->data ['get'] = $get;
  5902. $this->data ['page'] = $pageinfo;
  5903. $this->data ['trainList'] = $trainList;
  5904. $this->data ['invoiceType'] = $invoiceType;
  5905. $this->data ['invoiceTrain'] = $invoiceTrain;
  5906. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  5907. $this->data ['date'] = $date;
  5908. $this->data ['memu'] = "invoice";
  5909. $this->data ['staff'] = $this->staff;
  5910. if ($this->ACTION == 'invoicePrintAchieve') {
  5911. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  5912. $this->data ['receiptMemu'] = 'invoicePrint';
  5913. $this->data ['list'] = $list;
  5914. $this->render ( "/admin/invoicePrintAchieve", $this->data );
  5915. } elseif ($this->ACTION == 'invoicePostAchieve') {
  5916. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  5917. Doo::loadModel ( 'express' );
  5918. $express = new express ();
  5919. $expressList = $express->getExpressByAll ();
  5920. $this->data ['expressList'] = $expressList;
  5921. $this->data ['receiptMemu'] = 'invoicePost';
  5922. $this->data ['list'] = $list;
  5923. $this->render ( "/admin/invoicePostAchieve", $this->data );
  5924. } elseif ($this->ACTION == 'invoiceUntreadAchieve') {
  5925. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql,'desc','desc','untreadTime' );
  5926. $this->data ['receiptMemu'] = 'invoiceUntread';
  5927. $this->data ['list'] = $list;
  5928. $this->render ( "/admin/invoiceUntreadAchieve", $this->data );
  5929. }
  5930. }
  5931. /**
  5932. * 公司应收款
  5933. */
  5934. function invoiceAggregateCompanyDetail() {
  5935. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  5936. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  5937. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : 'ALL';
  5938. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  5939. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  5940. $titleORno = $this->get_args ( 'titleORno' ) ? $this->get_args ( 'titleORno' ) : "";
  5941. Doo::loadClass ( 'XDeode' );
  5942. $XDeode = new XDeode ( 5 );
  5943. Doo::loadModel ( 'invoice' );
  5944. $invoice = new invoice ();
  5945. Doo::loadModel ( 'staff' );
  5946. $staff = new staff ();
  5947. Doo::loadModel ( "invoiceCompanyManage" );
  5948. $invoiceCompanyManage = new invoiceCompanyManage ();
  5949. Doo::loadModel ( 'L_category' );
  5950. $category = new L_category ();
  5951. $sid = '';
  5952. if (! empty ( $sidKey )) {
  5953. $sid = $XDeode->decode ( $sidKey );
  5954. }
  5955. $staffDetail = $staff->getStaffBySid ( $sid );
  5956. $cid = '';
  5957. if (! empty ( $cidKey )) {
  5958. $cid = $XDeode->decode ( $cidKey );
  5959. }
  5960. $imcStaff = $invoiceCompanyManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  5961. $cidList = array ();
  5962. foreach ( $imcStaff as $key => $value ) {
  5963. array_push ( $cidList, $value ['cid'] );
  5964. }
  5965. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  5966. $cidString = implode ( ',', $cidList );
  5967. if (empty ( $cid ))
  5968. $staffList = $staff->getStaffInCid ( $cidString );
  5969. else
  5970. $staffList = $staff->getStaffByCidAll ( $cid ); //
  5971. //$MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  5972. $page_size = 25;
  5973. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5974. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  5975. $con = ' status=2 and untreadStatus!=2 and invalid=0 and isDelete=0 and badDebt=0 ';
  5976. $statisticsCon = '';
  5977. if (! empty ( $year ) && is_numeric ( $year ))
  5978. $con .= ' and Year(printTime)=' . $year . '';
  5979. if (! empty ( $month ) && is_numeric ( $month ))
  5980. $con .= ' and Month(printTime)="' . $month . '" ';
  5981. if ($status == 'UNRECORD')
  5982. $con .= ' and printStatus=1 and untreadStatus=0';
  5983. elseif ($status == 'RECORD')
  5984. $con .= ' and printStatus=1 and untreadStatus=3';
  5985. elseif ($status == 'BOUNCED')
  5986. $con .= ' and untreadStatus=2';
  5987. elseif ($status == 'PARTRECORD')
  5988. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  5989. elseif ($status == 'All') {
  5990. $con .= ' and printStatus=1 and ( untreadStatus=0 or untreadStatus=3 )';
  5991. }
  5992. if (! empty ( $sid ) && is_numeric ( $sid ))
  5993. $con .= ' and sid=' . $sid;
  5994. if (! empty ( $cid ) && is_numeric ( $cid ))
  5995. $con .= ' and cid=' . $cid;
  5996. else
  5997. $con .= ' and cid in (' . $cidString . ')';
  5998. // 开票内容筛选
  5999. if (! empty ( $invoiceElement ) && $invoiceElement != 'ALL') {
  6000. $con .= ' and invoiceElement="' . $invoiceElement . '"';
  6001. }
  6002. $get = "/" . $status . "?cidKey=" . $cidKey . "&sidKey=" . $sidKey . "&year=" . $year . "&month=" . $month
  6003. . "&invoiceElement=" . $invoiceElement."&titleORno=".urlencode ( $titleORno );
  6004. if (! empty ( $titleORno )) {
  6005. $con .= ' and ( invoiceTitle like "%' . $titleORno . '%" or invoiceCompany like "%' . $titleORno . '%" or invoiceNo like "%'.$titleORno.'%" )';
  6006. }
  6007. $pageinfo ['page'] = array (
  6008. 'previous' => ''
  6009. );
  6010. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateCompanyDetail", $get, "" );
  6011. $limit = $pageinfo ['lower'] . ',' . $page_size;
  6012. // 应收款合计
  6013. $ics = $invoice->getInvoiceCompanyStatistics ( $con );
  6014. //,'desc','desc','printTime'
  6015. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  6016. $monthHtml = "";
  6017. if ($year != "ALL") {
  6018. for($i = 1; $i <= 12; $i ++) {
  6019. if ($i == $month)
  6020. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  6021. else
  6022. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  6023. }
  6024. }
  6025. $this->data ['monthHtml'] = $monthHtml;
  6026. $this->data ['year'] = $year;
  6027. $this->data ['month'] = $month;
  6028. $this->data ['ics'] = $ics;
  6029. $this->data ['cidKey'] = $cidKey;
  6030. $this->data ['sid'] = $sid;
  6031. $this->data ['staffDetail'] = $staffDetail;
  6032. $this->data ['staffList'] = $staffList;
  6033. $this->data ['titleORnoEn'] = $titleORno;
  6034. $this->data ['titleORno'] = urlencode ( $titleORno );
  6035. $this->data ['invoiceDetail'] = array (
  6036. 'invoiceElement' => $invoiceElement
  6037. );
  6038. $this->data ['page'] = $pageinfo;
  6039. $this->data ['get'] = $get;
  6040. $this->data ['list'] = $list;
  6041. $this->data ['status'] = $status;
  6042. $this->data ['categoryList'] = $categoryList;
  6043. $this->data ['memu'] = "invoice";
  6044. $this->data ['staff'] = $this->staff;
  6045. $this->data ['receiptMemu'] = 'invoiceAggregateCompanyDetail';
  6046. $this->render ( "/admin/invoiceAggregateCompanyDetail", $this->data );
  6047. }
  6048. /**
  6049. * 获取一条收款信息
  6050. */
  6051. function ajaxGetInvoiceReceivables() {
  6052. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  6053. Doo::loadModel ( 'invoiceReceivables' );
  6054. $invoiceReceivables = new invoiceReceivables ();
  6055. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  6056. echo json_encode ( array (
  6057. 'status' => 1,
  6058. 'detail' => $detail
  6059. ) );
  6060. }
  6061. /**
  6062. * 异步获取办事处用户
  6063. */
  6064. function ajaxGetStaffByCategory() {
  6065. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "";
  6066. Doo::loadModel ( 'staff' );
  6067. $staff = new staff ();
  6068. if ($cid == "PUBLIC") {
  6069. echo json_encode ( array (
  6070. 'status' => 1,
  6071. 'html' => '<option value="PUBLIC">办事处待认领款项</option>'
  6072. ) );
  6073. die ();
  6074. }
  6075. if (! is_numeric ( $cid )) {
  6076. echo json_encode ( array (
  6077. 'status' => 0,
  6078. 'msg' => 'illegal request'
  6079. ) );
  6080. die ();
  6081. }
  6082. $staffList = $staff->getStaffByCid ( $cid );
  6083. $html = '<option value="PUBLIC">办事处待认领款项</option>';
  6084. foreach ( $staffList as $key => $value ) {
  6085. $html .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  6086. }
  6087. echo json_encode ( array (
  6088. 'status' => 1,
  6089. 'html' => $html
  6090. ) );
  6091. }
  6092. /**
  6093. * 异步获取一条发票的邮寄信息
  6094. */
  6095. function ajaxGetInvoicePostDetail() {
  6096. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  6097. Doo::loadModel ( 'invoice' );
  6098. $invoice = new invoice ();
  6099. $iid = $invoice->authcode ( $iid );
  6100. Doo::loadModel ( 'express' );
  6101. $express = new express ();
  6102. $expressList = $express->getExpressByAll ();
  6103. if (! is_numeric ( $iid )) {
  6104. echo json_encode ( array (
  6105. 'status' => 0,
  6106. 'msg' => 'illegal request'
  6107. ) );
  6108. die ();
  6109. }
  6110. $select = "iid,recipients,recipientsPhone,recipientsAddress,mailItems,expressCompany,expressNumber,actualItems";
  6111. $invoiceDetail = $invoice->getInvoiceByIid ( $iid, $select );
  6112. $html = "";
  6113. foreach ( $expressList as $key => $value ) {
  6114. if ($value ['company'] == $invoiceDetail ['expressCompany'])
  6115. $html .= '<option selected value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  6116. else
  6117. $html .= '<option value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  6118. }
  6119. $invoiceDetail ['eaHtml'] = $html;
  6120. echo json_encode ( array (
  6121. 'status' => 1,
  6122. 'invoiceDetail' => $invoiceDetail
  6123. ) );
  6124. }
  6125. /**
  6126. *
  6127. * @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 ) ); }
  6128. */
  6129. /**
  6130. *
  6131. * @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 ) ); }
  6132. */
  6133. /**
  6134. * 我的收款中 选择哪个发票入账,进行金额判断
  6135. */
  6136. function ajaxCompareInvoicePrice() {
  6137. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  6138. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  6139. Doo::loadModel ( 'invoice' );
  6140. $invoice = new invoice ();
  6141. Doo::loadModel ( 'invoiceReceivables' );
  6142. $invoiceReceivables = new invoiceReceivables ();
  6143. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  6144. $keyList = explode ( ';', $claimKey );
  6145. $receivablesPrice = 0;
  6146. foreach ( $keyList as $key => $value ) {
  6147. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $value );
  6148. $receivablesPrice += $detailM ['receivablesPrice'];
  6149. }
  6150. if ($receivablesPrice > $detail ['invoicePrice']) {
  6151. $price = $receivablesPrice - $detail ['invoicePrice'];
  6152. echo json_encode ( array (
  6153. 'status' => 1,
  6154. 'price' => $price
  6155. ) );
  6156. } else
  6157. echo json_encode ( array (
  6158. 'status' => 2
  6159. ) );
  6160. }
  6161. /**
  6162. * 获得打印发票
  6163. */
  6164. function ajaxGetInvoiceInfoByPrint() {
  6165. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  6166. if (empty ( $serial )) {
  6167. echo json_encode ( array (
  6168. 'status' => 2,
  6169. 'msg' => 'illegal request'
  6170. ) );
  6171. die ();
  6172. }
  6173. Doo::loadModel ( 'invoice' );
  6174. $invoice = new invoice ();
  6175. Doo::loadModel ( 'invoiceOperationLog' );
  6176. $invoiceOperationLog = new invoiceOperationLog ();
  6177. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  6178. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  6179. Doo::loadModel ( 'invoicePaper' );
  6180. $invoicePaper = new invoicePaper ();
  6181. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $detail ['invoiceType'] );
  6182. if (empty ( $detail ))
  6183. $html = '';
  6184. else {
  6185. $html = '
  6186. <form action="/invoicePrintDo" method="post" name="invoicePrint" class="nice-validator n-yellow" onSubmit="return checkPrintForm()" novalidate="novalidate">
  6187. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  6188. <input type="hidden" name="invoicePrintType" value="invoicePrintType">
  6189. <div class="modal-dialog modal-lg">
  6190. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  6191. <div class="modal-body saeaList">
  6192. <table class="table table-bordered table-condensed"><tbody>
  6193. <tr>
  6194. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  6195. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  6196. </tr>
  6197. <tr>
  6198. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  6199. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  6200. </tr>
  6201. <tr>
  6202. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  6203. </td>
  6204. </tr>
  6205. <tr>
  6206. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  6207. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  6208. </tr>
  6209. <tr>
  6210. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  6211. </tr></tbody></table>';
  6212. if ($detail ['invoiceType'] == 0)
  6213. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6214. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  6215. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  6216. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  6217. </tr>';
  6218. else
  6219. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6220. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  6221. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  6222. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  6223. ';
  6224. $html .= '<tr>
  6225. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  6226. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  6227. </tr>
  6228. <tr>
  6229. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  6230. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  6231. </tr></tbody></table>';
  6232. if ($detail ['doPost'] == 1)
  6233. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  6234. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  6235. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  6236. </tr><tr>
  6237. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  6238. </tr><tr>
  6239. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  6240. </tr></tbody></table>';
  6241. if (! empty ( $invoiceOperationLogList )) {
  6242. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th><th class="taC">发票打印</th></tr><tr><td>';
  6243. foreach ( $invoiceOperationLogList as $key => $value ) {
  6244. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  6245. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  6246. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  6247. if ($value ['status'] == 2) {
  6248. $html .= '<span class="colGreen">同意</span>';
  6249. } elseif ($value ['status'] == 3) {
  6250. $html .= '<span class="colOrange">退回</span>';
  6251. } elseif ($value ['status'] == 5) {
  6252. $html .= '<span class="colGreen">打印</span>';
  6253. } elseif ($value ['status'] == 4) {
  6254. $html .= '<span class="colRed">终止</span>';
  6255. }
  6256. $html .= $value ['operation'] . '</p></blockquote>';
  6257. }
  6258. }
  6259. $html .= '</td>
  6260. <td><span class="colRed">*</span>
  6261. <select name="invoiceNo" id="invoiceNo" style="width:97%">';
  6262. foreach ( $invoicePaperList as $key => $value ) {
  6263. $html .= '<option value="' . $value ['ipidKey'] . '">No.' . $value ['invoiceNo'] . '</option>';
  6264. }
  6265. $html .= '</select>
  6266. <span class="red" id="p-msg"></span>
  6267. </td>
  6268. </tr></tbody></table>';
  6269. }
  6270. $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>
  6271. </div></div></form>
  6272. <link rel=stylesheet href="' . WEB_SITE_GLOBAL . 'css/jquery.validator.css">
  6273. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/jquery.validator.min.js"></script>
  6274. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/zh-CN.js"></script>
  6275. <script src="' . WEB_SITE_GLOBAL . 'js/invoice.validator.js"></script>
  6276. ';
  6277. }
  6278. echo json_encode ( array (
  6279. 'status' => 1,
  6280. 'html' => $html
  6281. ) );
  6282. die ();
  6283. }
  6284. /**
  6285. * @ 获得与我有关收款数据 --需求变更 废弃 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 ) ); }
  6286. */
  6287. function ajaxGetInvoiceInfoByType() {
  6288. $type = $this->get_args ( 'type' ) ? $this->get_args ( 'type' ) : "";
  6289. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  6290. $loss = $this->get_args ( 'loss' ) ? $this->get_args ( 'loss' ) : false;
  6291. include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  6292. if (empty ( $serial )) {
  6293. echo json_encode ( array (
  6294. 'status' => 2,
  6295. 'msg' => 'illegal request'
  6296. ) );
  6297. die ();
  6298. }
  6299. if ($type == 'INVOICE') {
  6300. Doo::loadModel ( 'invoice' );
  6301. $invoice = new invoice ();
  6302. Doo::loadModel ( 'invoiceOperationLog' );
  6303. $invoiceOperationLog = new invoiceOperationLog ();
  6304. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  6305. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  6306. if (empty ( $detail ))
  6307. $html = '';
  6308. else {
  6309. $html = '
  6310. <div class="modal-dialog modal-lg">
  6311. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  6312. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  6313. <tr>
  6314. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  6315. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  6316. </tr>
  6317. <tr>
  6318. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  6319. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  6320. </tr>
  6321. <tr>
  6322. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  6323. </td>
  6324. </tr>
  6325. <tr>
  6326. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  6327. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  6328. </tr>
  6329. <tr>
  6330. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  6331. </tr>';
  6332. if ($detail ['settlementType'] == 1)
  6333. $html .= '<tr>
  6334. <th class="taC" width="150">结算方式</th><td colspan="3">培训班(<a href="/invoiceTrainingDetail/' . $detail ['invoiceTraining'] ['trainingKey'] . '.html" target="_blank">' . $detail ['invoiceTraining'] ['trainName'] . '</a>)</td>
  6335. </tr>';
  6336. else
  6337. $html .= '<tr>
  6338. <th class="taC" width="150">结算方式</th><td colspan="3">软件销售</td>
  6339. </tr>';
  6340. $html .= ' </tbody></table>';
  6341. if ($detail ['invoiceType'] == 0){
  6342. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6343. <tr><th colspan="4" class="taC">增值税普通发票';
  6344. if($detail ['invoiceForm']==1){
  6345. $html .= '( <span class="colRed">电子发票</span> )';
  6346. }
  6347. $html .= '</th></tr><tr>
  6348. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  6349. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  6350. </tr>';
  6351. }else{
  6352. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6353. <tr><th colspan="4" class="taC">增值税专用发票';
  6354. if($detail ['invoiceForm']==1){
  6355. $html .= '( <span class="colRed">电子发票</span> )';
  6356. }
  6357. $html .= '</th></tr><tr>
  6358. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  6359. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  6360. ';
  6361. }
  6362. $html .= '<tr>
  6363. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  6364. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  6365. </tr>
  6366. <tr>
  6367. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  6368. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  6369. </tr>
  6370. <tr>
  6371. <th class="taC">发票号</th><td>' . $detail ['invoiceNo'] . '</td>
  6372. <th class="taC"></th><td></td>
  6373. </tr>
  6374. </tbody></table>';
  6375. if ($detail ['doPost'] == 1) {
  6376. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  6377. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  6378. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  6379. </tr><tr>
  6380. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  6381. </tr><tr>
  6382. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  6383. </tr>
  6384. ';
  6385. if ($detail ['expressCom'] == 'SF')
  6386. $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>';
  6387. else
  6388. $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>';
  6389. $html .= '</tbody></table>';
  6390. }
  6391. if ($detail ['invoiceForm'] == 1) {
  6392. $html .= '<table class="table table-bordered table-condensed">
  6393. <tbody><tr><th colspan="4" class="taC">电子发票发送方式</th></tr>
  6394. <tr>
  6395. <th class="taC" width="150">收件人手机</th><td>'.$detail ['electronicPhone'].'</td>
  6396. <th class="taC" width="150">收件人邮箱</th><td>'.$detail ['electronicEmail'].'</td>
  6397. </tr></tbody></table>';
  6398. }
  6399. if (! empty ( $invoiceOperationLogList )) {
  6400. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  6401. foreach ( $invoiceOperationLogList as $key => $value ) {
  6402. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  6403. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  6404. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  6405. if ($value ['status'] == 2) {
  6406. $html .= '<span class="colGreen">同意</span>';
  6407. } elseif ($value ['status'] == 3) {
  6408. $html .= '<span class="colOrange">退回</span>';
  6409. } elseif ($value ['status'] == 5) {
  6410. $html .= '<span class="colGreen">打印</span>';
  6411. } elseif ($value ['status'] == 4) {
  6412. $html .= '<span class="colRed">终止</span>';
  6413. }
  6414. $html .= $value ['operation'] . '</p></blockquote>';
  6415. }
  6416. }
  6417. $html .= '</td></tr></tbody></table>';
  6418. }
  6419. $html .= '</div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  6420. }
  6421. echo json_encode ( array (
  6422. 'status' => 1,
  6423. 'html' => $html
  6424. ) );
  6425. die ();
  6426. } elseif ($type == 'RECEIVABLES') {
  6427. Doo::loadModel ( 'invoiceReceivables' );
  6428. $invoiceReceivables = new invoiceReceivables ();
  6429. Doo::loadModel ( 'invoiceRefund' );
  6430. $invoiceRefund = new invoiceRefund ();
  6431. $detail = $invoiceReceivables->getInvoiceReceivablesByIrsid ( $serial );
  6432. $ireList = $invoiceRefund->getInvoiceRefundIrid ( $detail ['irid'] );
  6433. if (empty ( $detail ))
  6434. $html = '';
  6435. else {
  6436. $html = '<div class="modal-dialog modal-lg"><div class="modal-content"><div class="modal-header"><h3>收款单详情</h3></div><div class="modal-body saeaList">
  6437. <table class="table table-bordered table-condensed">
  6438. <tbody><tr>
  6439. <th class="taC">收款流水号</th><td>' . $detail ['receivablesSerial'] . '</td>
  6440. <th class="taC">录入收款</th><td>' . $detail ['inputStaff'] . ' ' . $detail ['date'] . '</td>
  6441. </tr><tr>
  6442. <th class="taC">收款金额</th><td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  6443. <th class="taC">收款信息</th><td>' . $detail ['receivablesMessage'] . '</td>
  6444. </tr>
  6445. <tr>
  6446. <th class="taC">收款银行</th><td>' . $detail ['receivablesBank'] . '</td>
  6447. <th class="taC">银行到账</th><td>' . $detail ['receivablesDate'] . '</td>
  6448. </tr>
  6449. <tr>
  6450. <th class="taC">认领收款</th><td colspan="3">' . $detail ['inputStaff'] . ' 转入 ' . $detail ['username'] . ' ' . $detail ['confirmTime'] . '</td>
  6451. </tr>
  6452. </tbody></table>';
  6453. if (! empty ( $ireList )) {
  6454. $html .= '
  6455. <table class="table table-bordered table-condensed"><tbody><tr><th class="taC" colspan="5">退款记录</th></tr>
  6456. <tr>
  6457. <th class="taC">退款单位名称</th>
  6458. <th class="taC">退款的账号</th>
  6459. <th class="taC">退款金额</th>
  6460. <th class="taC">退款</th>
  6461. <th class="taC">备注</th>
  6462. </tr>
  6463. ';
  6464. foreach ( $ireList as $key => $value ) {
  6465. $refundLogList = explode ( "<br/>", $value ['refundLog'] );
  6466. $html .= '<tr>
  6467. <td>' . $value ['refundCompany'] . '</td>
  6468. <td>' . $value ['refundNumber'] . '</td>
  6469. <td><b class="colRed">¥' . $value ['refundPrice'] . '</b></td>
  6470. <td>' . $refundLogList [0] . $refundLogList [2] . '</td>
  6471. <td>' . $value ['refundRemarks'] . '</td>
  6472. </tr>
  6473. ';
  6474. }
  6475. }
  6476. $html .= '</tbody></table></div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  6477. }
  6478. echo json_encode ( array (
  6479. 'status' => 1,
  6480. 'html' => $html
  6481. ) );
  6482. die ();
  6483. } elseif ($type == 'IRTC') {
  6484. Doo::loadModel ( 'invoice' );
  6485. $invoice = new invoice ();
  6486. Doo::loadModel ( 'invoiceOperationLog' );
  6487. $invoiceOperationLog = new invoiceOperationLog ();
  6488. // Doo::loadModel ( 'invoiceReceivables' );
  6489. // $invoiceReceivables = new invoiceReceivables ();
  6490. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  6491. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  6492. if (empty ( $detail ))
  6493. $html = '';
  6494. else {
  6495. $receivablesPriceedHtml = '';
  6496. $receivablesPrice = $detail ['invoicePrice'];
  6497. if (! empty ( $detail ['irid'] )) {
  6498. // $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $detail ['irid'] );
  6499. // if (empty ( $irList ))
  6500. // $irList [0] ['sumPrice'] = 0;
  6501. // $balance = $detail ['invoicePrice'] - $irList [0] ['sumPrice'];
  6502. $enteredPrice=$detail ['invoicePrice']-$detail ['invoiceBalance'];
  6503. $receivablesPriceedHtml = '<table class="table table-bordered table-condensed"><tbody><tr>
  6504. <th class="taC">已入账金额</th><td><b class="colGreen" style="font-size:18px">¥' . $enteredPrice . '</b></td>
  6505. <th class="taC">剩余入账金额</th><td><b class="colRed" style="font-size:18px">¥' . $detail ['invoiceBalance'] . '</b></td>
  6506. </tr></tbody></table>';
  6507. $receivablesPrice = $detail ['invoiceBalance'];
  6508. }
  6509. if ($loss)
  6510. $detail ['invoicePrice'] = - $detail ['invoicePrice'];
  6511. $html = $receivablesPriceedHtml . '
  6512. <table class="table table-bordered table-condensed"><tbody>
  6513. <tr>
  6514. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  6515. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  6516. </tr>
  6517. <tr>
  6518. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  6519. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  6520. </tr>
  6521. <tr>
  6522. <th class="taC" width="150">发票备注</th><td colspan="3">' . $detail ['remark'] . '</td>
  6523. </tr>
  6524. <tr>
  6525. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  6526. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  6527. </tr>
  6528. <tr>
  6529. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  6530. </tr></tbody></table>';
  6531. if ($detail ['invoiceType'] == 0) {
  6532. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6533. <tr><th colspan="4" class="taC">增值税普通发票';
  6534. if($detail ['invoiceForm']==1){
  6535. $html .= '( <span class="colRed">电子发票</span> )';
  6536. }
  6537. $html.='</th></tr><tr>
  6538. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  6539. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  6540. </tr>';
  6541. $receivablesMessage = $detail ['invoiceTitle'];
  6542. } else {
  6543. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6544. <tr><th colspan="4" class="taC">增值税专用发票';
  6545. if($detail ['invoiceForm']==1){
  6546. $html .= '( <span class="colRed">电子发票</span> )';
  6547. }
  6548. $html .= '</th></tr><tr>
  6549. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  6550. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  6551. ';
  6552. $receivablesMessage = $detail ['invoiceCompany'];
  6553. }
  6554. $html .= '<tr>
  6555. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  6556. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  6557. </tr>
  6558. <tr>
  6559. <th class="taC">开户银行</th><td>' . $detail ['bankAccount'] . '</td>
  6560. <th class="taC">银行账号</th><td>' . $detail ['bank'] . '</td>
  6561. </tr></tbody></table>';
  6562. if ($detail ['doPost'] == 1)
  6563. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  6564. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  6565. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  6566. </tr><tr>
  6567. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  6568. </tr><tr>
  6569. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  6570. </tr></tbody></table>';
  6571. if (! empty ( $invoiceOperationLogList )) {
  6572. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  6573. foreach ( $invoiceOperationLogList as $key => $value ) {
  6574. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  6575. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  6576. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  6577. if ($value ['status'] == 2) {
  6578. $html .= '<span class="colGreen">同意</span>';
  6579. } elseif ($value ['status'] == 3) {
  6580. $html .= '<span class="colOrange">退回</span>';
  6581. } elseif ($value ['status'] == 5) {
  6582. $html .= '<span class="colGreen">打印</span>';
  6583. }
  6584. $html .= $value ['operation'] . '</p></blockquote>';
  6585. }
  6586. }
  6587. $html .= '</td></tr></tbody></table>';
  6588. }
  6589. }
  6590. echo json_encode ( array (
  6591. 'status' => 1,
  6592. 'html' => $html,
  6593. 'receivablesPrice' => $receivablesPrice,
  6594. 'receivablesMessage' => $receivablesMessage,
  6595. 'receivablesDate' => date ( "Y-m-d" ),
  6596. 'iidKey' => $serial
  6597. ) );
  6598. die ();
  6599. }
  6600. }
  6601. function ajaxGetInvoiceReceivablesByStaff() {
  6602. $postData = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : "";
  6603. if (empty ( $postData )) {
  6604. echo json_encode ( array (
  6605. 'status' => 2,
  6606. 'msg' => 'illegal request'
  6607. ) );
  6608. die ();
  6609. }
  6610. Doo::loadModel ( 'invoiceReceivables' );
  6611. $invoiceReceivables = new invoiceReceivables ();
  6612. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $postData );
  6613. if (empty ( $detail )) {
  6614. echo json_encode ( array (
  6615. 'status' => 2,
  6616. 'msg' => 'illegal request'
  6617. ) );
  6618. die ();
  6619. }
  6620. Doo::loadModel ( 'L_category' );
  6621. $lCategory = new L_category ();
  6622. Doo::loadModel ( 'staff' );
  6623. $staff = new staff ();
  6624. $staffList = $staff->getStaffByCid ( $detail ['cid'] );
  6625. $category = $lCategory->getCategory ();
  6626. $categoryHtml = '<option post-data="PUBLIC" value="PUBLIC" >公共待认领款项</option>';
  6627. $staffHtml = '<option value="PUBLIC">办事处待认领款项</option>';
  6628. foreach ( $category as $key => $value ) {
  6629. $categoryHtml .= '<option post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  6630. if ($value ['cid'] == $detail ['cid'])
  6631. $categoryHtml .= '<option selected post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  6632. }
  6633. foreach ( $staffList as $key => $value ) {
  6634. $staffHtml .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  6635. if ($value ['sid'] == $detail ['sid'])
  6636. $staffHtml .= '<option selected value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  6637. }
  6638. $rbankHtml = '<option value="广发银行珠海分行柠溪支行">广发银行珠海分行柠溪支行</option>';
  6639. echo json_encode ( array (
  6640. 'status' => 1,
  6641. 'categoryHtml' => $categoryHtml,
  6642. 'staffHtml' => $staffHtml,
  6643. 'rbankHtml' => $rbankHtml,
  6644. 'detail' => $detail
  6645. ) );
  6646. }
  6647. function ajaxGetInvoiceReceivablesByIrid() {
  6648. $irid = $this->get_args ( 'irid' ) ? $this->get_args ( 'irid' ) : "";
  6649. if (empty ( $irid )) {
  6650. echo json_encode ( array (
  6651. 'status' => 2,
  6652. 'msg' => 'illegal request'
  6653. ) );
  6654. die ();
  6655. }
  6656. Doo::loadModel ( 'invoiceReceivables' );
  6657. $invoiceReceivables = new invoiceReceivables ();
  6658. Doo::loadModel ( 'invoice' );
  6659. $invoice = new invoice ();
  6660. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid ); // 入账完成 待定 and postStatus=1
  6661. $flag = true;
  6662. $invoiceDetail = $invoice->getInvoiceByTitle ( $detail ['recepitTitleMark'], 'EXACTLY', " and status=2 and printStatus=1 and untreadStatus=0 ", $flag ); //
  6663. $bakDetail = array ();
  6664. if ($flag === false) {
  6665. array_push ( $bakDetail, $invoiceDetail );
  6666. $invoiceDetail = $bakDetail;
  6667. }
  6668. $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>
  6669. <tr>
  6670. <td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  6671. <td>' . $detail ['receivablesMessage'] . '</td>
  6672. <td>' . $detail ['receivablesBank'] . '<br>' . $detail ['receivablesDate'] . '</td>
  6673. <td>' . $detail ['title'] . '-' . $detail ['username'] . '<br>' . $detail ['confirmTime'] . '</td>
  6674. <td>' . $detail ['recepitTitleMark'] . '</td>
  6675. </tr></tbody></table>';
  6676. $isInvoice = false;
  6677. $invoiceHtml = '';
  6678. if (empty ( $invoiceDetail )) {
  6679. $isInvoice = true;
  6680. } else {
  6681. $invoiceHtml = '<table class="table table-bordered table-condensed">
  6682. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody>';
  6683. foreach ( $invoiceDetail as $key => $value ) {
  6684. $invoiceHtml .= '<tr>';
  6685. if (! empty ( $value ['invoiceType'] )) {
  6686. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  6687. } else {
  6688. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  6689. }
  6690. if (! empty ( $value ['invoiceType'] )) {
  6691. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  6692. } else {
  6693. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  6694. }
  6695. $invoiceHtml .= '
  6696. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  6697. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  6698. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir" data-ikey="' . $value ['iidKey'] . '" href="javascript:void(0)">入账</a></td>
  6699. </tr>
  6700. ';
  6701. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  6702. if (empty ( $irList ))
  6703. $irList [0] ['sumPrice'] = 0;
  6704. $balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  6705. $priceString = '';
  6706. if ($balance < $detail ['receivablesPrice']) {
  6707. $priceString = '收款金额超过开票金额,';
  6708. }
  6709. if ($balance > $detail ['receivablesPrice']) {
  6710. $priceString = '收款金额低于开票金额,';
  6711. }
  6712. }
  6713. $invoiceHtml .= '
  6714. <script>
  6715. $(\'a[bind-receivables^="ir"]\').click(function() {
  6716. var data = $(this).attr("data-ikey");
  6717. $("input[name=\'invoiceKey\']").val(data);
  6718. var invoiceKey=data;
  6719. if(invoiceKey==""){
  6720. alert("入账错误,请重新刷新页面");
  6721. return false;
  6722. }
  6723. if(window.confirm("' . $priceString . '确定入账吗?")){
  6724. $("#IBR").submit();
  6725. }else{
  6726. return false;
  6727. }
  6728. });
  6729. </script>
  6730. ';
  6731. $invoiceHtml .= '</tbody></table>';
  6732. }
  6733. echo json_encode ( array (
  6734. 'status' => 1,
  6735. 'irkey' => $detail ['iridEn'],
  6736. 'receivablesHtml' => $receivablesHtml,
  6737. 'isInvoice' => $isInvoice,
  6738. 'invoiceHtml' => $invoiceHtml
  6739. ) );
  6740. }
  6741. function ajaxGetInvoiceReceivablesByTitle() {
  6742. $title = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  6743. if (empty ( $title )) {
  6744. echo json_encode ( array (
  6745. 'status' => 2,
  6746. 'msg' => 'illegal request'
  6747. ) );
  6748. die ();
  6749. }
  6750. Doo::loadModel ( 'invoice' );
  6751. $invoice = new invoice ();
  6752. $invoiceDetail = $invoice->getInvoiceByTitle ( $title, 'FUZZY', " and status=2 and printStatus=1 and untreadStatus=0 and (irid='' or irid is null) ", true );
  6753. $invoiceHtml = '';
  6754. if (! empty ( $invoiceDetail )) {
  6755. $invoiceHtml = '<table class="table table-bordered table-condensed">
  6756. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody><tr>';
  6757. foreach ( $invoiceDetail as $key => $value ) {
  6758. if (! empty ( $value ['invoiceType'] )) {
  6759. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  6760. } else {
  6761. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  6762. }
  6763. if (! empty ( $value ['invoiceType'] )) {
  6764. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  6765. } else {
  6766. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  6767. }
  6768. $invoiceHtml .= '
  6769. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  6770. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  6771. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir' . $value ['iidKeyXD'] . '" data-ikey="' . $value ['iidKey'] . '" href="#">入账</a></td>
  6772. </tr>
  6773. ';
  6774. }
  6775. $invoiceHtml .= '</tbody></table>
  6776. <script>
  6777. $(\'a[bind-receivables^="ir"]\').click(function() {
  6778. var data = $(this).attr("data-ikey");
  6779. $("input[name=\'invoiceKey\']").val(data);
  6780. var invoiceKey=$("input[name=\'invoiceKey\']").val();
  6781. if(invoiceKey==""){
  6782. alert("入账错误,请重新刷新页面");
  6783. return false;
  6784. }
  6785. if(window.confirm("确定入账吗?")){
  6786. $("#IBR").submit();
  6787. }else{
  6788. return false;
  6789. }
  6790. });
  6791. </script>
  6792. ';
  6793. }
  6794. echo json_encode ( array (
  6795. 'status' => 1,
  6796. 'invoiceHtml' => $invoiceHtml
  6797. ) );
  6798. }
  6799. function ajaxInvoicePushNotice() {
  6800. Doo::loadModel ( 'invoice' );
  6801. $invoice = new invoice ();
  6802. $approval = $invoice->getOne ( array (
  6803. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  6804. 'desc' => 'iid',
  6805. 'asArray' => true
  6806. ) );
  6807. $isNotice = false;
  6808. if (! empty ( $approval ))
  6809. $isNotice = true;
  6810. $response = array (
  6811. 'error' => 0,
  6812. 'isNotice' => $isNotice
  6813. );
  6814. echo json_encode ( $response );
  6815. exit ();
  6816. }
  6817. public function ajaxCheckInvoiceNoUniqueness() {
  6818. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  6819. Doo::loadModel ( 'invoice' );
  6820. $invoice = new invoice ();
  6821. if (! empty ( $invoiceNo )) {
  6822. Doo::loadModel ( 'invoicePaper' );
  6823. $invoicePaper = new invoicePaper ();
  6824. Doo::loadClass ( 'XDeode' );
  6825. $XDeode = new XDeode ( 5 );
  6826. $ipid = $XDeode->decode ( $invoiceNo );
  6827. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  6828. $info = $invoice->getOne ( array (
  6829. 'where' => "invoiceNo = '" . $paperDetail ['invoiceNo'] . "'",
  6830. 'asArray' => TRUE
  6831. ) );
  6832. if (! empty ( $info )) {
  6833. echo json_encode ( array (
  6834. 'error' => '发票号已存在'
  6835. ) );
  6836. die ();
  6837. } else
  6838. echo json_encode ( array (
  6839. 'ok' => '可以使用!'
  6840. ) );
  6841. die ();
  6842. }
  6843. }
  6844. function ajaxCheckInvoicePrice() {
  6845. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) && is_numeric ( $this->get_args ( 'receivablesPrice' ) ) ? $this->get_args ( 'receivablesPrice' ) : "";
  6846. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  6847. Doo::loadModel ( 'invoice' );
  6848. $invoice = new invoice ();
  6849. Doo::loadModel ( 'invoiceReceivables' );
  6850. $invoiceReceivables = new invoiceReceivables ();
  6851. Doo::loadClass ( 'XDeode' );
  6852. $XDeode = new XDeode ( 5 );
  6853. if (! empty ( $receivablesPrice ) && ! empty ( $iidKey )) {
  6854. $iidKey = $XDeode->decode ( $iidKey );
  6855. $info = $invoice->getInvoiceByIid ( $iidKey );
  6856. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $info ['irid'] );
  6857. if (empty ( $irList ))
  6858. $irList [0] ['sumPrice'] = 0;
  6859. $balance = $info ['invoicePrice'] - $irList [0] ['sumPrice'];
  6860. if ($balance < $receivablesPrice) {
  6861. echo json_encode ( array (
  6862. 'error' => '收款金额超过开票金额。'
  6863. ) );
  6864. die ();
  6865. }
  6866. if ($balance > $receivablesPrice) {
  6867. echo json_encode ( array (
  6868. 'error' => '收款金额低于开票金额。'
  6869. ) );
  6870. die ();
  6871. }
  6872. }
  6873. }
  6874. function ajaxGetInvoiceByNew() {
  6875. Doo::loadModel ( 'invoice' );
  6876. $invoice = new invoice ();
  6877. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );
  6878. echo json_encode ( array (
  6879. 'status' => 1,
  6880. 'detail' => $detail
  6881. ) );
  6882. }
  6883. /**
  6884. * 旧输入导入
  6885. */
  6886. function importInvoice() {
  6887. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  6888. $data ['emsg'] = "";
  6889. if ($emsg != "")
  6890. $data ['emsg'] = "请填写完整的数据";
  6891. $data ['time'] = time ();
  6892. $this->render ( "/admin/invoiceImport", $data );
  6893. }
  6894. function uploadInvoice() {
  6895. // move_uploaded_file($_FILES['Filedata']['tmp_name'], "/upload/".$_FILES['Filedata']['name']);
  6896. if (isset ( $_FILES ['Filedata'] ['name'] )) {
  6897. $file = $_FILES ['Filedata'] ['tmp_name'];
  6898. $error = false;
  6899. if (! is_uploaded_file ( $file )) {
  6900. $error = '400 Bad Request';
  6901. }
  6902. if ($error) {
  6903. header ( 'HTTP/1.0 ' . $error );
  6904. die ( 'Error ' . $error );
  6905. } else {
  6906. include (DOO::conf ()->SITE_PATH . 'protected/plugin/io.han.php');
  6907. $this->IoHandler = new IoHandler ();
  6908. $pics = explode ( '.', $_FILES ['Filedata'] ['name'] );
  6909. // $filedir=$_POST['time'];
  6910. // 调用定义物理路径
  6911. $t = DOO::conf ()->SITE_PATH . "upload/invoice/";
  6912. $this->IoHandler->MakeDir ( $t );
  6913. $filename = $this->_GetFileEXT ( $_FILES ['Filedata'] ['name'] );
  6914. if ($filename != 'xlsx')
  6915. return "";
  6916. // $upload_dir = $t."/".time().rand(10,100).".".$filename;
  6917. $upload_file = iconv ( "UTF-8", "GB2312", $_FILES ["Filedata"] ["name"] );
  6918. $upload_dir = $t . "/" . $upload_file;
  6919. $k = move_uploaded_file ( $file, $upload_dir );
  6920. if ($k) {
  6921. $m = round ( $_FILES ['Filedata'] ['size'] / 1024 / 1024, 2 );
  6922. echo $pics [0] . "." . $filename . "#" . $m . "#" . $_FILES ['Filedata'] ['size'];
  6923. }
  6924. }
  6925. }
  6926. }
  6927. function importInvoiceDo() {
  6928. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  6929. if ($path != "") {
  6930. Doo::loadModel ( 'invoice' );
  6931. Doo::loadModel ( 'staff' );
  6932. $staff = new staff ();
  6933. Doo::loadModel ( 'invoiceStatistics' );
  6934. Doo::loadModel ( 'invoiceOperationLog' );
  6935. echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  6936. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . $path );
  6937. // print_r ( $exlArray );
  6938. // die ();
  6939. // echo json_encode($exlArray);die;
  6940. foreach ( $exlArray as $key => $value ) {
  6941. // 开票
  6942. $invoice = new invoice ();
  6943. $invoice->invoiceNo = $value ['invoiceNo'];
  6944. $invoice->invoiceType = 0;
  6945. if ($value ['invoiceType'] == '专')
  6946. $invoice->invoiceType = 1;
  6947. $invoice->invoicePrice = $value ['invoicePrice'];
  6948. $invoice->invoiceQuantity = 1;
  6949. $invoice->invoiceUnitPrice = $value ['invoicePrice'];
  6950. $invoice->invoiceTitle = $value ['invoiceTitle'];
  6951. if ($value ['invoiceType'] == '专')
  6952. $invoice->invoiceCompany = $value ['invoiceTitle'];
  6953. $invoice->userName = $value ['userName'];
  6954. $sDetail = $staff->getStaffByName ( $value ['userName'] );
  6955. $invoice->sid = $sDetail ['sid'];
  6956. $invoice->cid = $sDetail ['cid'];
  6957. $invoice->categoryName = $sDetail ['category'];
  6958. $invoice->invoiceElement = $value ['invoiceElement'];
  6959. $invoice->remark = $value ['remark'];
  6960. $invoice->date = $value ['date'];
  6961. $invoice->printTime = $value ['date'];
  6962. $invoice->ipSource = 1;
  6963. $invoice->printStatus = 1;
  6964. $invoice->status = 2;
  6965. $invoice->postStatus = 1;
  6966. $invoice->untreadStatus = 0;
  6967. $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  6968. $iid = $invoice->insert ();
  6969. // 汇总
  6970. $invoiceStatistics = new invoiceStatistics ();
  6971. //
  6972. $item = array (
  6973. 'date' => $value ['date'],
  6974. 'priceClass' => 1,
  6975. 'cid' => $sDetail ['cid'],
  6976. 'staff' => $sDetail ['sid'],
  6977. 'invoicePrice' => $value ['invoicePrice']
  6978. );
  6979. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  6980. $invoiceOperationLog = new invoiceOperationLog ();
  6981. $item = array (
  6982. 'date' => date ( "Y-m-d H:i:s" ),
  6983. 'operation' => date ( "Y-m-d" ) . " 导入",
  6984. 'status' => 1,
  6985. 'img' => $sDetail ['avatar'],
  6986. 'username' => $sDetail ['username'],
  6987. 'uid' => $sDetail ['sid'],
  6988. 'category' => $sDetail ['category'],
  6989. 'iid' => $iid
  6990. );
  6991. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  6992. }
  6993. return '/importInvoice?count=' . count ( $exlArray );
  6994. // return "/keyonline";
  6995. }
  6996. echo 'no file';
  6997. }
  6998. function importInvoiceReceivables() {
  6999. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  7000. $data ['emsg'] = "";
  7001. if ($emsg != "")
  7002. $data ['emsg'] = "请填写完整的数据";
  7003. $data ['time'] = time ();
  7004. $this->render ( "/admin/invoiceReceivablesImport", $data );
  7005. }
  7006. // 导入入账数据
  7007. function importInvoiceReceivablesDo() {
  7008. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  7009. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  7010. if ($path != "") {
  7011. Doo::loadModel ( 'invoiceReceivables' );
  7012. Doo::loadModel ( 'invoice' );
  7013. Doo::loadModel ( 'staff' );
  7014. $staff = new staff ();
  7015. Doo::loadModel ( 'invoiceStatistics' );
  7016. // echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  7017. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path ), 'invoiceReceivables' );
  7018. // print_r ( $exlArray );
  7019. // die ();
  7020. // echo json_encode($exlArray);die;
  7021. foreach ( $exlArray as $key => $value ) {
  7022. // 收款
  7023. $invoiceReceivables = new invoiceReceivables ();
  7024. $invoice = new invoice ();
  7025. $invoiceReceivables->bindStatus = 1;
  7026. $invoiceReceivables->receivablesPrice = $value ['receivablesPrice'];
  7027. $invoiceReceivables->receivablesMessage = $value ['receivablesMessage'];
  7028. $invoiceReceivables->receivablesBank = $value ['receivablesBank'];
  7029. $invoiceReceivables->receivablesDate = $value ['receivablesDate'];
  7030. $sDetail = $staff->getStaffByName ( $value ['receivablesStaff'] );
  7031. $invoiceReceivables->receivablesCategory = $sDetail ['cid'] . ':' . $sDetail ['category'];
  7032. $invoiceReceivables->receivablesStaff = $sDetail ['sid'] . '-' . $sDetail ['username'];
  7033. $invoiceReceivables->receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  7034. $invoiceReceivables->sourcePrice = $value ['sourcePrice'];
  7035. $iDetail = $invoice->getInvoiceByInvoiceNo ( $value ['invoiceNo'] );
  7036. $invoiceReceivables->iid = $iDetail ['iid'];
  7037. $irid = $invoiceReceivables->insert ();
  7038. // 发票绑定收款
  7039. $detail = $iDetail;
  7040. $iridString = "";
  7041. if (empty ( $detail ['irid'] ))
  7042. $iridString = $irid;
  7043. else
  7044. $iridString = $detail ['irid'] . ',' . $irid;
  7045. $item = array (
  7046. 'irid' => $iridString,
  7047. 'iid' => $detail ['iid']
  7048. );
  7049. $invoice->setInvoiceByCondition ( $item );
  7050. // 汇总
  7051. $invoiceStatistics = new invoiceStatistics ();
  7052. // 扣除入账统计金额
  7053. $item = array (
  7054. 'date' => $value ['receivablesDate'],
  7055. 'priceClass' => 3,
  7056. 'cid' => $sDetail ['cid'],
  7057. 'staff' => $sDetail ['sid'],
  7058. // 'irid' => $irid,
  7059. 'accountPrice' => $value ['receivablesPrice']
  7060. );
  7061. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  7062. }
  7063. return '/importInvoiceReceivables?count=' . count ( $exlArray );
  7064. echo 'data count ' . count ( $exlArray );
  7065. die ();
  7066. // return "/keyonline";
  7067. }
  7068. echo 'no file';
  7069. }
  7070. function formatExcelToArrayTrain($file_url = "") {
  7071. if (! file_exists ( $file_url )) {
  7072. return array ();
  7073. }
  7074. // Doo::loadClass ( 'PHPExcel' );
  7075. Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  7076. $PHPExcel = new PHPExcel ();
  7077. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  7078. if (! $PHPReader->canRead ( $file_url )) {
  7079. $PHPReader = new PHPExcel_Reader_Excel5 ();
  7080. if (! $PHPReader->canRead ( $file_url )) {
  7081. echo 'no Excel';
  7082. return;
  7083. }
  7084. }
  7085. $PHPExcel = $PHPReader->load ( $file_url );
  7086. /* * 读取excel文件中的第一个工作表 */
  7087. $currentSheet = $PHPExcel->getSheet ( 0 );
  7088. /* * 取得最大的列号 */
  7089. $allColumn = $currentSheet->getHighestColumn ();
  7090. /* * 取得一共有多少行 */
  7091. $allRow = $currentSheet->getHighestRow ();
  7092. $excel_array = array ();
  7093. // die($file_url);
  7094. $conk = 2;
  7095. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  7096. $excel_column = array ();
  7097. // 后期改进
  7098. if ($allColumn == 'AM')
  7099. $allColumn = 'Z';
  7100. /* * 从第A列开始输出 */
  7101. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  7102. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  7103. if ($val instanceof PHPExcel_RichText)
  7104. $val = $val->__toString ();
  7105. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  7106. // $val = "'" . addslashes ( $val ) . "'";
  7107. if ($currentColumn == 'A') {
  7108. $excel_column ['invoiceTitle'] = $val;
  7109. } elseif ($currentColumn == 'B')
  7110. $excel_column ['invoiceType'] = $val;
  7111. elseif ($currentColumn == 'C') {
  7112. $excel_column ['TIN'] = $val;
  7113. } elseif ($currentColumn == 'D') {
  7114. $excel_column ['address'] = $val;
  7115. } elseif ($currentColumn == 'E') {
  7116. $excel_column ['phone'] = $val;
  7117. } elseif ($currentColumn == 'F') {
  7118. $excel_column ['bank'] = $val;
  7119. } elseif ($currentColumn == 'G') {
  7120. $excel_column ['bankAccount'] = $val;
  7121. } elseif ($currentColumn == 'H') {
  7122. $excel_column ['invoiceElement'] = $val;
  7123. } elseif ($currentColumn == 'I') {
  7124. $excel_column ['invoiceQuantity'] = $val;
  7125. } elseif ($currentColumn == 'J') {
  7126. $excel_column ['invoiceUnitPrice'] = $val;
  7127. } elseif ($currentColumn == 'K') {
  7128. $excel_column ['remark'] = $val;
  7129. } elseif ($currentColumn == 'L') {
  7130. $excel_column ['recipientsAddress'] = $val;
  7131. } elseif ($currentColumn == 'M') {
  7132. $excel_column ['recipients'] = $val;
  7133. } elseif ($currentColumn == 'N') {
  7134. $excel_column ['recipientsPhone'] = $val;
  7135. }elseif ($currentColumn == 'O') {
  7136. $excel_column ['electronicPhone'] = $val;
  7137. } elseif ($currentColumn == 'P') {
  7138. $excel_column ['electronicEmail'] = $val;
  7139. }
  7140. }
  7141. if (! empty ( $excel_column ['invoiceTitle'] ) && ! empty ( $excel_column ['invoiceQuantity'] ) && ! empty ( $excel_column ['invoiceUnitPrice'] ))
  7142. array_push ( $excel_array, $excel_column );
  7143. }
  7144. return $excel_array;
  7145. }
  7146. /**
  7147. * 格式化excel文件为数组
  7148. * @param unknown_type $file_url
  7149. * @param unknown_type $mcid
  7150. */
  7151. function _format_excel_to_array($file_url = "", $sType = "") {
  7152. if (! file_exists ( $file_url )) {
  7153. return array ();
  7154. }
  7155. Doo::loadClass ( 'PHPExcel' );
  7156. // Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  7157. $PHPExcel = new PHPExcel ();
  7158. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  7159. if (! $PHPReader->canRead ( $file_url )) {
  7160. $PHPReader = new PHPExcel_Reader_Excel5 ();
  7161. if (! $PHPReader->canRead ( $file_url )) {
  7162. echo 'no Excel';
  7163. return;
  7164. }
  7165. }
  7166. $PHPExcel = $PHPReader->load ( $file_url );
  7167. /* * 读取excel文件中的第一个工作表 */
  7168. $currentSheet = $PHPExcel->getSheet ( 0 );
  7169. /* * 取得最大的列号 */
  7170. $allColumn = $currentSheet->getHighestColumn ();
  7171. /* * 取得一共有多少行 */
  7172. $allRow = $currentSheet->getHighestRow ();
  7173. $excel_array = array ();
  7174. // die($file_url);
  7175. $conk = 2;
  7176. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  7177. $excel_column = array ();
  7178. // 后期改进
  7179. if ($allColumn == 'AM')
  7180. $allColumn = 'Z';
  7181. /* * 从第A列开始输出 */
  7182. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  7183. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  7184. if ($val instanceof PHPExcel_RichText)
  7185. $val = $val->__toString ();
  7186. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  7187. // $val = "'" . addslashes ( $val ) . "'";
  7188. if ($sType == 'invoiceReceivables') {
  7189. if ($currentColumn == 'A')
  7190. $excel_column ['invoiceNo'] = $val;
  7191. elseif ($currentColumn == 'B')
  7192. $excel_column ['receivablesPrice'] = $val;
  7193. elseif ($currentColumn == 'C') {
  7194. $excel_column ['receivablesMessage'] = $val;
  7195. } elseif ($currentColumn == 'D') {
  7196. $excel_column ['receivablesBank'] = $val;
  7197. } elseif ($currentColumn == 'E') {
  7198. $excel_column ['receivablesDate'] = $this->excelTime ( $val );
  7199. } elseif ($currentColumn == 'F') {
  7200. $excel_column ['receivablesStaff'] = $val;
  7201. } elseif ($currentColumn == 'G') {
  7202. $excel_column ['sourcePrice'] = $val;
  7203. }
  7204. } elseif ($sType == "invoiceTrain") {
  7205. if ($currentColumn == 'A') {
  7206. $excel_column ['invoiceTitle'] = $val;
  7207. } elseif ($currentColumn == 'B')
  7208. $excel_column ['invoiceType'] = $val;
  7209. elseif ($currentColumn == 'C') {
  7210. $excel_column ['TIN'] = $val;
  7211. } elseif ($currentColumn == 'D') {
  7212. $excel_column ['address'] = $val;
  7213. } elseif ($currentColumn == 'E') {
  7214. $excel_column ['phone'] = $val;
  7215. } elseif ($currentColumn == 'F') {
  7216. $excel_column ['bank'] = $val;
  7217. } elseif ($currentColumn == 'G') {
  7218. $excel_column ['bankAccount'] = $val;
  7219. } elseif ($currentColumn == 'H') {
  7220. $excel_column ['invoiceElement'] = $val;
  7221. } elseif ($currentColumn == 'I') {
  7222. $excel_column ['invoiceQuantity'] = $val;
  7223. } elseif ($currentColumn == 'J') {
  7224. $excel_column ['invoiceUnitPrice'] = $val;
  7225. } elseif ($currentColumn == 'K') {
  7226. $excel_column ['remark'] = $val;
  7227. } elseif ($currentColumn == 'L') {
  7228. $excel_column ['recipientsAddress'] = $val;
  7229. } elseif ($currentColumn == 'M') {
  7230. $excel_column ['recipients'] = $val;
  7231. } elseif ($currentColumn == 'N') {
  7232. $excel_column ['recipientsPhone'] = $val;
  7233. }
  7234. } else {
  7235. if ($currentColumn == 'A')
  7236. $excel_column ['invoiceNo'] = $val;
  7237. elseif ($currentColumn == 'B')
  7238. $excel_column ['invoiceType'] = $val;
  7239. elseif ($currentColumn == 'C') {
  7240. $excel_column ['invoicePrice'] = $val;
  7241. } elseif ($currentColumn == 'D') {
  7242. $excel_column ['invoiceTitle'] = $val;
  7243. } elseif ($currentColumn == 'E') {
  7244. $excel_column ['userName'] = $val;
  7245. } elseif ($currentColumn == 'F') {
  7246. $excel_column ['categoryName'] = $val;
  7247. } elseif ($currentColumn == 'G') {
  7248. $excel_column ['invoiceElement'] = $val;
  7249. } elseif ($currentColumn == 'H') {
  7250. $excel_column ['remark'] = $val;
  7251. } elseif ($currentColumn == 'I') {
  7252. $excel_column ['date'] = $this->excelTime ( $val );
  7253. }
  7254. }
  7255. }
  7256. array_push ( $excel_array, $excel_column );
  7257. }
  7258. return $excel_array;
  7259. }
  7260. function excelTime($date, $time = false) {
  7261. if (function_exists ( 'GregorianToJD' )) {
  7262. if (is_numeric ( $date )) {
  7263. $jd = GregorianToJD ( 1, 1, 1970 );
  7264. $gregorian = JDToGregorian ( $jd + intval ( $date ) - 25569 );
  7265. $date = explode ( '/', $gregorian );
  7266. $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" : '');
  7267. return $date_str;
  7268. }
  7269. } else {
  7270. $date = $date > 25568 ? $date + 1 : 25569;
  7271. /* There was a bug if Converting date before 1-1-1970 (tstamp 0) */
  7272. $ofs = (70 * 365 + 17 + 2) * 86400;
  7273. $date = date ( "Y-m-d", ($date * 86400) - $ofs ) . ($time ? " 00:00:00" : '');
  7274. }
  7275. return $date;
  7276. }
  7277. /**
  7278. * 旧输入导入
  7279. */
  7280. function _GetFileEXT($filename) {
  7281. $pics = explode ( '.', $filename );
  7282. $num = count ( $pics );
  7283. return $pics [$num - 1];
  7284. }
  7285. function showCache($path = "", $sid = 0) {
  7286. // if (file_exists ( $path )) {
  7287. // $htm = file_get_contents ( $path );
  7288. // } else {
  7289. Doo::loadModel ( 'invoiceStatistics' );
  7290. $invoiceStatistics = new invoiceStatistics ();
  7291. $isBriefly = $invoiceStatistics->getBrieflyStatistics ( $sid );
  7292. $htm = '<tr><th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计开票</th>
  7293. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['invoicePrice'] . '</td>
  7294. <th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计入账</th>
  7295. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['accountPrice'] . '</td></tr>';
  7296. /*
  7297. * '<tr><th class="taC">今年累计开票</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['invoicePrice'] . '</td> <th class="taC">今年累计入账</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['accountPrice'] . '</td></tr>';
  7298. */
  7299. file_put_contents ( $path, $htm );
  7300. // }
  7301. return $htm;
  7302. }
  7303. /**
  7304. * 生成token
  7305. * @return string
  7306. */
  7307. function set_token() {
  7308. $str = md5 ( uniqid ( md5 ( microtime ( true ) ), true ) ); // 生成一个不会重复的字符串
  7309. $str = sha1 ( $str ); // 加密
  7310. return $str;
  7311. }
  7312. /**
  7313. * 获取get或者POST值
  7314. *
  7315. * @param string $name 属性名称
  7316. * @return fixed 值
  7317. */
  7318. function get_args($name) {
  7319. if (isset ( $_GET [$name] )) {
  7320. if (is_array ( $_GET [$name] ))
  7321. return $_GET [$name];
  7322. else
  7323. return addslashes ( $_GET [$name] );
  7324. } elseif (isset ( $_POST [$name] )) {
  7325. if (is_array ( $_POST [$name] ))
  7326. return $_POST [$name];
  7327. else
  7328. return addslashes ( $_POST [$name] );
  7329. } else
  7330. return false;
  7331. }
  7332. function SafeFilter(&$arr) {
  7333. $ra = Array (
  7334. '/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/',
  7335. '/script/',
  7336. '/javascript/',
  7337. '/vbscript/',
  7338. '/expression/',
  7339. '/applet/',
  7340. '/meta/',
  7341. '/xml/',
  7342. '/blink/',
  7343. '/link/',
  7344. '/style/',
  7345. '/embed/',
  7346. '/object/',
  7347. '/frame/',
  7348. '/layer/',
  7349. '/title/',
  7350. '/bgsound/',
  7351. '/base/',
  7352. '/onload/',
  7353. '/onunload/',
  7354. '/onchange/',
  7355. '/onsubmit/',
  7356. '/onreset/',
  7357. '/onselect/',
  7358. '/onblur/',
  7359. '/onfocus/',
  7360. '/onabort/',
  7361. '/onkeydown/',
  7362. '/onkeypress/',
  7363. '/onkeyup/',
  7364. '/onclick/',
  7365. '/ondblclick/',
  7366. '/onmousedown/',
  7367. '/onmousemove/',
  7368. '/onmouseout/',
  7369. '/onmouseover/',
  7370. '/onmouseup/',
  7371. '/onunload/'
  7372. );
  7373. if (is_array ( $arr )) {
  7374. foreach ( $arr as $key => $value ) {
  7375. if (! is_array ( $value )) {
  7376. if (! get_magic_quotes_gpc ()) // 不对magic_quotes_gpc转义过的字符使用addslashes(),避免双重转义。
  7377. {
  7378. $value = addslashes ( $value ); // 给单引号(')、双引号(")、反斜线(\)与 NUL(NULL 字符)加上反斜线转义
  7379. }
  7380. $value = preg_replace ( $ra, '', $value ); // 删除非打印字符,粗暴式过滤xss可疑字符串
  7381. $arr [$key] = htmlentities ( strip_tags ( $value ) ); // 去除 HTML 和 PHP 标记并转换为 HTML 实体
  7382. } else {
  7383. SafeFilter ( $arr [$key] );
  7384. }
  7385. }
  7386. }
  7387. }
  7388. /**
  7389. * Escape String
  7390. *
  7391. * @access public
  7392. * @param string
  7393. * @param bool whether or not the string will be used in a LIKE condition
  7394. * @return string
  7395. */
  7396. function escape_str($str, $like = FALSE) {
  7397. if (is_array ( $str )) {
  7398. foreach ( $str as $key => $val ) {
  7399. $str [$key] = $this->escape_str ( $val, $like );
  7400. }
  7401. return $str;
  7402. }
  7403. var_dump ( Doo::db ()->getDbObject () );
  7404. die ();
  7405. if (function_exists ( 'mysql_real_escape_string' ) and is_resource ( Doo::db ()->getDbObject () )) { // Doo::db ()->getDbObject()
  7406. $str = mysql_real_escape_string ( $str, Doo::db ()->getDbObject () );
  7407. } elseif (function_exists ( 'mysql_escape_string' )) {
  7408. $str = mysql_escape_string ( $str );
  7409. } else {
  7410. $str = addslashes ( $str );
  7411. }
  7412. // escape LIKE condition wildcards
  7413. if ($like === TRUE) {
  7414. $str = str_replace ( array (
  7415. '%',
  7416. '_'
  7417. ), array (
  7418. '\\%',
  7419. '\\_'
  7420. ), $str );
  7421. }
  7422. return $str;
  7423. }
  7424. /**
  7425. * 获得分页数据
  7426. * @param unknown_type $table
  7427. * @param unknown_type $condition
  7428. * @param unknown_type $on_page
  7429. * @param unknown_type $page_size
  7430. */
  7431. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  7432. $page_c = "";
  7433. $page ['previous'] = $this->get_previous ( $on_page );
  7434. $page ['on_page'] = $on_page;
  7435. $total_count = $this->get_table_count ( $table, $condition );
  7436. $total = intval ( $total_count / $page_size );
  7437. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  7438. $page ['total_data'] = $total_count;
  7439. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  7440. $i = 1;
  7441. $page_max = 1;
  7442. $page_width = 3;
  7443. if ($on_page >= $page_width) {
  7444. $page_max = intval ( $on_page / $page_width ) + 1;
  7445. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  7446. }
  7447. for(; $i <= $page ['total_page']; $i ++) {
  7448. if ($i == $on_page)
  7449. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  7450. else
  7451. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  7452. if ($i == ($page_width * $page_max))
  7453. break;
  7454. }
  7455. $page ['page'] = $page_c;
  7456. $page ['lower'] = (-- $on_page) * $page_size;
  7457. return $page;
  7458. }
  7459. /**
  7460. * 获取上一页
  7461. * @param unknown_type $on_page
  7462. */
  7463. function get_previous($on_page = 1) {
  7464. return $on_page != 0 ? $on_page - 1 : $on_page;
  7465. }
  7466. /**
  7467. * 获取总页数
  7468. * @param unknown_type $table
  7469. * @param unknown_type $condition
  7470. */
  7471. public function get_table_count($table = "", $condition = "") {
  7472. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  7473. $sql = "select count(*) as count from " . $table . " where " . $condition;
  7474. // echo $sql;die;
  7475. $query = Doo::db ()->query ( $sql );
  7476. $result = $query->fetch ();
  7477. return $result ['count'];
  7478. }
  7479. function isInvoiceNew($type = "GLOBAL") {
  7480. Doo::loadModel ( 'invoice' );
  7481. $invoice = new invoice ();
  7482. Doo::loadModel ( 'invoiceReceivables' );
  7483. $invoiceReceivables = new invoiceReceivables ();
  7484. Doo::loadModel ( 'staff' );
  7485. $staff = new staff ();
  7486. $st = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  7487. // 我的发票待处理
  7488. $pendingInvoice = $invoice->getOne ( array ( // or (status=2 and printStatus=1 and untreadStatus=0 ) or (status=2 and printStatus=1 and untreadStatus=2 )
  7489. 'where' => "(status=3 or status=4) and isDelete=0 and sid=" . $st [0] ['sid'],
  7490. 'desc' => 'iid',
  7491. 'asArray' => TRUE
  7492. ) );
  7493. // 我的收款待入账
  7494. /*
  7495. * $myClaim = $invoiceReceivables->getOne ( array ( 'where' => " receivablesStaff like '" . $st [0] ['sid'] . "-%' and receivablesCategory like '" . $st [0] ['cid'] . ":%' and bindStatus=0", 'desc' => 'irid', 'asArray' => TRUE ) );
  7496. */
  7497. // 发票审批
  7498. $approval = $invoice->getOne ( array (
  7499. 'where' => 'status=1 and pendingApprovals=' . $st [0] ['sid'],
  7500. 'desc' => 'iid',
  7501. 'asArray' => true
  7502. ) );
  7503. // 发票邮寄
  7504. $post = $invoice->getOne ( array (
  7505. 'where' => "postStatus=0 and printStatus=1 and isDelete=0 and doPost=1 and status=2",
  7506. 'asArray' => TRUE
  7507. ) );
  7508. // 发票打印
  7509. $print = $invoice->getOne ( array (
  7510. 'where' => "status=2 and printStatus=0 and untreadStatus=0 and moldManage like '%[\"" . $st [0] ['sid'] . "\",%'",
  7511. 'desc' => 'iid',
  7512. 'asArray' => TRUE
  7513. ) );
  7514. // 发票退票 printStatus=1 and
  7515. $untread = $invoice->getOne ( array (
  7516. 'where' => " untreadStatus=1 and status=2 ",
  7517. 'asArray' => TRUE
  7518. ) );
  7519. $new = array (
  7520. 'GLOBAL' => FALSE,
  7521. 'pendingInvoice' => FALSE,
  7522. // 'myClaim' => FALSE,
  7523. 'approval' => FALSE,
  7524. 'post' => FALSE,
  7525. 'print' => FALSE,
  7526. 'untread' => FALSE
  7527. );
  7528. // || ! empty ( $myClaim )
  7529. if (! empty ( $pendingInvoice ) || ! empty ( $approval ) || ! empty ( $post ) || ! empty ( $print ) || ! empty ( $untread ))
  7530. $new ['GLOBAL'] = TRUE;
  7531. if (! empty ( $pendingInvoice ))
  7532. $new ['pendingInvoice'] = TRUE;
  7533. // if (! empty ( $myClaim ))
  7534. // $new ['myClaim'] = TRUE;
  7535. if (! empty ( $approval ))
  7536. $new ['approval'] = TRUE;
  7537. if (! empty ( $post ))
  7538. $new ['post'] = TRUE;
  7539. if (! empty ( $print ))
  7540. $new ['print'] = TRUE;
  7541. if (! empty ( $untread ))
  7542. $new ['untread'] = TRUE;
  7543. return $new;
  7544. }
  7545. function setWXMsg($rid, $typeMsg = '') {
  7546. Doo::loadModel ( 'invoice' );
  7547. $invoice = new invoice ();
  7548. $invoiceDetail = $invoice->getOne ( array (
  7549. 'where' => 'iid=' . $rid,
  7550. 'asArray' => true
  7551. ) );
  7552. if (! empty ( $invoiceDetail )) {
  7553. Doo::loadModel ( 'staff' );
  7554. $staff = new staff ();
  7555. $staffmsg = $staff->getOne ( array (
  7556. 'where' => "sid='" . $invoiceDetail ['sid'] . "'",
  7557. 'asArray' => TRUE
  7558. ) );
  7559. if (! empty ( $staffmsg ['wxid'] )) {
  7560. require_once (SITE_PATH . '/protected/class/client.php');
  7561. $client = new client ( 'http://m.cld.smartcost.com.cn/' );
  7562. $user = $staffmsg ['wxid'];
  7563. $expCom = explode ( ":", $invoiceDetail ['expressCompany'] );
  7564. if (empty ( $expCom ))
  7565. $expCom [0] = '';
  7566. $msg = "";
  7567. if (empty ( $typeMsg ))
  7568. $msg = '太好了,您的发票' . $invoiceDetail ['invoiceSerial'] . ' 已邮寄 ' . $expCom [0] . ' ,快递号: <a href="https://m.kuaidi100.com/result.jsp?nu=' . $invoiceDetail ['expressNumber'] . '" >' . $invoiceDetail ['expressNumber'] . '</a>';
  7569. elseif ($typeMsg == "PRINT")
  7570. $msg = '太好了,您的发票已打印完成。';
  7571. $result = $client->SendMsg ( $user, $msg, 'text' );
  7572. }
  7573. }
  7574. }
  7575. /**
  7576. * 获取微信部门
  7577. * @param string $category
  7578. * @return number|mixed
  7579. */
  7580. function getToparty($category = '') {
  7581. $token = $this->getAccessToken (); //
  7582. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token={$token}&id=5" ), true );
  7583. $toparty = 0;
  7584. foreach ( $result ['department'] as $key => $value ) {
  7585. if ($value ['name'] == $category)
  7586. $toparty = $value ['id'];
  7587. }
  7588. return $toparty;
  7589. }
  7590. /**
  7591. * 获得某部门下的用户
  7592. * @param string $toparty
  7593. */
  7594. function getUserByToparty($toparty = '') {
  7595. $token = $this->getAccessToken (); //
  7596. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token={$token}&department_id={$toparty}" ), true );
  7597. $userList = array ();
  7598. foreach ( $result ['userlist'] as $key => $value ) {
  7599. array_push ( $userList, "'" . $value ['userid'] . "'" );
  7600. }
  7601. return $userList;
  7602. }
  7603. function msgSendToparty($msg, $title, $url, $toparty, $text = '') {
  7604. $token = $this->getAccessToken ();
  7605. if ($text == 'text') {
  7606. $data = '{
  7607. "touser": "' . $toparty . '",
  7608. "toparty": "",
  7609. "totag": "",
  7610. "msgtype": "text",
  7611. "agentid": 1000002,
  7612. "text": {
  7613. "content": "' . $msg . '"
  7614. },
  7615. "safe":0
  7616. }';
  7617. }
  7618. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  7619. if ($result->errmsg != 'ok') {
  7620. return 0;
  7621. } else {
  7622. return 1;
  7623. }
  7624. }
  7625. /**
  7626. * 获得可以发送微信用户列表
  7627. * @param string $category
  7628. * @return string
  7629. */
  7630. function getWxidByCategory($category = "") {
  7631. if (empty ( $category ))
  7632. return "";
  7633. Doo::loadModel ( 'staff' );
  7634. $staff = new staff ();
  7635. $toparty = $this->getToparty ( $category );
  7636. $wxList = array ();
  7637. $wxString = "";
  7638. if (! empty ( $toparty )) {
  7639. $userList = $this->getUserByToparty ( $toparty );
  7640. $userCon = implode ( ',', $userList );
  7641. // echo $userCon;
  7642. $sidList = $staff->getStaffByWxid ( $userCon );
  7643. foreach ( $sidList as $key => $value ) {
  7644. $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  7645. if ($falg) {
  7646. array_push ( $wxList, $value ['wxid'] );
  7647. }
  7648. }
  7649. $wxString = implode ( '|', $wxList );
  7650. }
  7651. return $wxString;
  7652. }
  7653. /**
  7654. * 读取发送信息规则判断是否需要发送
  7655. * @param number $sid
  7656. * @param string $sendType
  7657. * @return boolean
  7658. */
  7659. function isSendNotification($sid = 0, $sendType = '') {
  7660. Doo::loadModel ( "notificationConf" );
  7661. $notificationConf = new notificationConf ();
  7662. $detail = $notificationConf->getNotificationConfBySid ( $sid );
  7663. $conf = array ();
  7664. $sendFlag = true;
  7665. if (! empty ( $detail )) {
  7666. $conf = json_decode ( $detail ['conf'], true );
  7667. if (! empty ( $sendType )) {
  7668. if (isset ( $conf [$sendType] )) {
  7669. if ($conf [$sendType] == "CLOSE")
  7670. $sendFlag = false;
  7671. elseif ($conf [$sendType] == "Weekend") {
  7672. $day = date ( "w" );
  7673. if (1 <= $day && 5 >= $day)
  7674. $sendFlag = false;
  7675. } elseif ($conf [$sendType] == "OneToFriday") {
  7676. $day = date ( "w" );
  7677. if (0 == $day || 6 == $day)
  7678. $sendFlag = false;
  7679. }
  7680. }
  7681. } else
  7682. $sendFlag = false;
  7683. }
  7684. return $sendFlag;
  7685. }
  7686. /**
  7687. * 根据规则发送信息
  7688. * @param unknown $msg
  7689. * @param unknown $title
  7690. * @param unknown $url
  7691. * @param unknown $user
  7692. * @param string $text
  7693. * @return number
  7694. */
  7695. private function msgSend($msg, $title, $url, $user, $sid = 0, $sendType = '') {
  7696. $token = $this->getAccessToken ();
  7697. $falg = $this->isSendNotification ( $sid, $sendType );
  7698. // if ($text == 'text') {
  7699. // $data = '{
  7700. // "touser": "' . $user . '",
  7701. // "toparty": "",
  7702. // "totag": "",
  7703. // "msgtype": "text",
  7704. // "agentid": 1000002,
  7705. // "text": {
  7706. // "content": "' . $msg . '"
  7707. // },
  7708. // "safe":0
  7709. // }';
  7710. // } else {
  7711. $data = '{
  7712. "touser": "' . $user . '",
  7713. "toparty": "",
  7714. "totag": "",
  7715. "msgtype": "news",
  7716. "agentid": 1000002,
  7717. "news": {
  7718. "articles":[
  7719. {
  7720. "title": "' . $title . '",
  7721. "description": "' . $msg . '",
  7722. "url": "' . $url . '",
  7723. "picurl": ""
  7724. }
  7725. ]
  7726. }
  7727. }';
  7728. // }
  7729. if ($falg) {
  7730. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  7731. if ($result->errmsg != 'ok') {
  7732. return 0;
  7733. } else {
  7734. return 1;
  7735. }
  7736. } else
  7737. return 0;
  7738. }
  7739. private function getAccessToken() {
  7740. // access_token 应该全局存储与更新,以下代码以写入到文件中做示例
  7741. // $file = './access_token.txt';
  7742. // $data = json_decode ( file_get_contents ( $file ) );
  7743. // if ($data->expire_time < time () or ! $data->expire_time) {
  7744. // 如果是企业号用以下URL获取access_token
  7745. $url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$this->appId&corpsecret=$this->appSecret";
  7746. // $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$this->appId&secret=$this->appSecret";
  7747. $res = json_decode ( $this->httpGet ( $url ) );
  7748. $access_token = $res->access_token;
  7749. // echo $access_token;
  7750. // if ($access_token) {
  7751. // $data->expire_time = time () + 7000;
  7752. // $data->access_token = $access_token;
  7753. // $fp = fopen ( $file, "w" );
  7754. // fwrite ( $fp, json_encode ( $data ) );
  7755. // fclose ( $fp );
  7756. // }
  7757. // } else {
  7758. // $access_token = $data->access_token;
  7759. // }
  7760. return $access_token;
  7761. }
  7762. private function httpGet($url) {
  7763. $curl = curl_init ();
  7764. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  7765. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  7766. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  7767. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  7768. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  7769. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  7770. curl_setopt ( $curl, CURLOPT_URL, $url );
  7771. $res = curl_exec ( $curl );
  7772. curl_close ( $curl );
  7773. return $res;
  7774. }
  7775. private function httpPost($url, $data) {
  7776. $curl = curl_init ();
  7777. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  7778. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  7779. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  7780. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  7781. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  7782. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  7783. curl_setopt ( $curl, CURLOPT_URL, $url );
  7784. curl_setopt ( $curl, CURLOPT_POST, 1 );
  7785. curl_setopt ( $curl, CURLOPT_POSTFIELDS, $data );
  7786. $res = curl_exec ( $curl );
  7787. curl_close ( $curl );
  7788. return $res;
  7789. }
  7790. }
  7791. ?>