InvoiceController.php 250 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690
  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. // var_dump($flag) ;
  64. // 单独判断办事处汇总的访问权限 invoiceAggregateCategoryDetail
  65. if ($action == 'invoiceAggregateCategoryDetail') {
  66. Doo::loadModel ( "invoiceCategoryManage" );
  67. $invoiceCategoryManage = new invoiceCategoryManage ();
  68. $icm = $invoiceCategoryManage->getInvoiceCMByStaff ( $sid );
  69. if (empty ( $icm ))
  70. die ( 'illegal request' );
  71. }
  72. if (! $flag)
  73. die ( 'illegal request' );
  74. }
  75. function __construct() {
  76. if (isset ( $_COOKIE ["staff"] )) {
  77. if (! empty ( $_COOKIE ["staff"] )) {
  78. Doo::loadModel ( 'staff' );
  79. $staff = new staff ();
  80. $uriPartsOrig = explode ( '/', $_SERVER ['REQUEST_URI'] );
  81. $this->ACTION = $uriPartsOrig [1];
  82. $this->data ['new'] = $this->isInvoiceNew ();
  83. $this->staff = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  84. return "/";
  85. }
  86. }
  87. Doo::loadCore ( 'uri/DooUriRouter' );
  88. $router = new DooUriRouter ();
  89. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  90. if ($routeRs ['1'] != "login") {
  91. header ( 'Content-Type:text/html;charset=utf-8' );
  92. @header ( "Location: /login" );
  93. }
  94. }
  95. function testSend() {
  96. // 测试根据规则发送信息 普通发送
  97. // $pendingApprovalsSid = 41;
  98. // Doo::loadModel ( 'staff' );
  99. // $staff = new staff ();
  100. // $username2 = $staff->getOne ( array ( 'select' => 'wxid', 'where' => 'sid=' . $pendingApprovalsSid, 'asArray' => TRUE ) );
  101. // // 发送微信审批通知
  102. // $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  103. // $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  104. // Doo::loadModel ( 'staff' );
  105. // $staff = new staff ();
  106. // $toparty = $this->getToparty ( '广东办' );
  107. // $wxList = array ();
  108. // if (! empty ( $toparty )) {
  109. // $userList = $this->getUserByToparty ( $toparty );
  110. // $userCon = implode ( ',', $userList );
  111. // // echo $userCon;
  112. // $sidList = $staff->getStaffByWxid ( $userCon );
  113. // foreach ( $sidList as $key => $value ) {
  114. // $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  115. // if ($falg) {
  116. // array_push ( $wxList, $value ['wxid'] );
  117. // }
  118. // }
  119. // $wxString = implode ( '|', $wxList );
  120. // print_r ( $wxList );
  121. // echo $wxString;
  122. // }
  123. // 测试发送
  124. /*
  125. * //$toparty = $this->getWxidByCategory( $receivablesCategory [1] ); $toparty = $this->getToparty ( $receivablesCategory [1] ); $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。'; if ($toparty != 0) $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  126. */
  127. // print_r ( $userList );
  128. // $msTouser='caipin|outaozhen';
  129. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  130. // $title2 = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  131. // $hfreult = $this->msgSend ( '', $title2, '', 'outaozhen' );
  132. // $toparty= $this->getToparty('广东办');
  133. // $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  134. // $toparty = 26;
  135. // $msg = '';
  136. // $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/1.html';
  137. // $hfreult = $this->msgSendToparty ( $msg, '', '', $toparty,'text' );
  138. }
  139. function invoice() {
  140. Doo::loadModel ( 'invoice' );
  141. $invoice = new invoice ();
  142. Doo::loadModel ( 'express' );
  143. $express = new express ();
  144. $expressList = $express->getExpressByAll ();
  145. $this->data ['expressList'] = $expressList;
  146. // Doo::loadModel ( 'invoiceReceivables' );
  147. // $invoiceReceivables = new invoiceReceivables ();
  148. // $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  149. Doo::loadModel ( 'invoiceStatistics' );
  150. $invoiceStatistics = new invoiceStatistics ();
  151. $isMonth = $invoiceStatistics->getStatisticsByMonth ();
  152. $year = date ( "Y" );
  153. $tmp_date = date ( "Ym" );
  154. $tmp_year = substr ( $tmp_date, 0, 4 );
  155. $tmp_mon = substr ( $tmp_date, 4, 2 );
  156. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  157. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  158. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . ".htm";
  159. $htm = $this->showCache ( $path );
  160. Doo::loadClass ( 'XDeode' );
  161. $XDeode = new XDeode ( 5 );
  162. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  163. $invoiceList = $invoice->getMyInvoice ( $sid );
  164. $sql = 'status=2 and printStatus=1 and irid!="" and sid=' . $sid;
  165. $list = $invoice->getInvoiceByUntreadStatusPage ( 4, $sql );
  166. // 我的待入账发票 and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  167. $sql = "status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid=" . $sid;
  168. $myInvoiceUnAccount = $invoice->getInvoiceByUntreadStatusPage ( 4, $sql );
  169. // print_r($myInvoiceUnAccount);
  170. $this->data ['isMonth'] = $isMonth;
  171. $this->data ['htm'] = $htm;
  172. $this->data ['invoiceList'] = $invoiceList;
  173. $this->data ['receivablesList'] = $list;
  174. $this->data ['myInvoiceUnAccount'] = $myInvoiceUnAccount;
  175. $this->data ['memu'] = "invoice";
  176. $this->data ['staff'] = $this->staff;
  177. $this->data ['receiptMemu'] = 'invoice';
  178. $this->render ( "/admin/invoice", $this->data );
  179. }
  180. function invoiceExpress() {
  181. $expressCom = isset ( $this->params ['expressCom'] ) ? $this->params ['expressCom'] : "";
  182. $expressNumber = isset ( $this->params ['expressNumber'] ) ? $this->params ['expressNumber'] : "";
  183. $this->data ['expressCom'] = $expressCom;
  184. $this->data ['expressNumber'] = $expressNumber;
  185. $this->render ( "/admin/invoiceExpress", $this->data );
  186. }
  187. function invoiceAdd() {
  188. Doo::loadModel ( 'L_category' );
  189. $lCategory = new L_category ();
  190. $category = $lCategory->find ( array (
  191. 'asArray' => true
  192. ) );
  193. $this->data ['category'] = $category;
  194. $this->data ['memu'] = "invoice";
  195. $this->data ['staff'] = $this->staff;
  196. $this->data ['receiptMemu'] = 'invoice';
  197. $this->render ( "/admin/invoiceAdd", $this->data );
  198. }
  199. /**
  200. * 提交一份开票申请,并记录下操作日志
  201. *
  202. * @since 1.0.0
  203. * @var integer cid 办事处ID
  204. * @var integer invoiceType 发票类型
  205. * @var integer doPost 是否邮寄
  206. * @var integer invoicePrice 开票金额
  207. * @var string invoiceElement 开票内容
  208. * @var string invoiceTitle 发票抬头
  209. * @var string invoiceCompany 单位名称
  210. * @var string TIN 纳税人识别码
  211. * @var string address 注册地址
  212. * @var string phone 注册电话
  213. * @var string bank 开户银行
  214. * @var string bankAccount 银行账户
  215. * @var string recipients 收件人
  216. * @var string recipientsPhone 收件人手机/电话
  217. * @var string recipientsAddress 收件地址
  218. * @var string mailItems 邮寄物品
  219. * @var string remark 备注
  220. * @return string 返回跳转开票主页路径
  221. */
  222. function invoiceAddDo() {
  223. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  224. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  225. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  226. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  227. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  228. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  229. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  230. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  231. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  232. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  233. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  234. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  235. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  236. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  237. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  238. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  239. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  240. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  241. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  242. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  243. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  244. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  245. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  246. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  247. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  248. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  249. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  250. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  251. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  252. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  253. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  254. /*
  255. * $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;
  256. */
  257. if (empty ( $this->staff [0] ))
  258. die ( 'illegal request' );
  259. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement )) {
  260. Doo::loadModel ( 'invoice' );
  261. $invoice = new invoice ();
  262. Doo::loadModel ( 'L_category' );
  263. $lCategory = new L_category ();
  264. Doo::loadModel ( 'invoiceManage' );
  265. $invoiceManage = new invoiceManage ();
  266. Doo::loadModel ( 'invoiceOperationLog' );
  267. $invoiceOperationLog = new invoiceOperationLog ();
  268. $categoryDetil = $lCategory->getOne ( array (
  269. 'SELECT' => 'title',
  270. 'where' => 'cid=' . $cid,
  271. 'asArray' => true
  272. ) );
  273. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  274. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  275. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  276. // print_r(current($invoiceManageDetail ['staffList']));
  277. // die;
  278. $moldManage = array ();
  279. foreach ( $invoiceManageList as $key => $value ) {
  280. if ($value ['mold'] == '发票打印')
  281. $moldManage [$value ['mold']] = $value ['staffList'];
  282. elseif ($value ['mold'] == '发票邮寄')
  283. $moldManage [$value ['mold']] = $value ['staffList'];
  284. elseif ($value ['mold'] == '发票退票')
  285. $moldManage [$value ['mold']] = $value ['staffList'];
  286. }
  287. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  288. $item = array (
  289. 'cid' => $cid,
  290. 'categoryName' => $categoryDetil ['title'],
  291. 'invoiceElement' => $invoiceElement,
  292. 'invoiceQuantity' => $invoiceQuantity,
  293. 'invoiceUnitPrice' => $invoiceUnitPrice,
  294. 'invoicePrice' => $invoicePrice,
  295. 'invoiceType' => $invoiceType,
  296. 'doPost' => $doPost,
  297. 'status' => 1,
  298. 'invoiceSerial' => "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  299. 'date' => date ( "Y-m-d H:i:s" ),
  300. 'updateTime' => date ( "Y-m-d H:i:s" ),
  301. 'sid' => $this->staff [0] ['sid'],
  302. 'userName' => $this->staff [0] ['username'],
  303. 'invoiceManage' => $invoiceManageDetail ['staff'],
  304. 'pendingApprovals' => $pendingApprovalsSid,
  305. 'moldManage' => json_encode ( $moldManage ),
  306. 'remark' => $remark
  307. );
  308. if ($invoiceType == 0)
  309. $item += array (
  310. 'invoiceTitle' => $invoiceTitle,
  311. 'TIN' => $TINT,
  312. 'address' => $addressT,
  313. 'phone' => $phoneT,
  314. 'bank' => $bankT,
  315. 'bankAccount' => $bankAccountT
  316. );
  317. else {
  318. $item += array (
  319. 'invoiceCompany' => $invoiceCompany,
  320. 'TIN' => $TIN,
  321. 'address' => $address,
  322. 'phone' => $phone,
  323. 'bank' => $bank,
  324. 'bankAccount' => $bankAccount
  325. );
  326. }
  327. if ($doPost == 1) {
  328. $mailList = array (
  329. 'invoice' => 1,
  330. 'mailItems' => $mailItems
  331. );
  332. if (! empty ( $softLock ))
  333. $mailList += array (
  334. 'softLock' => $softLockNum
  335. );
  336. else
  337. $mailList += array (
  338. 'softLock' => 0
  339. );
  340. if (! empty ( $contract ))
  341. $mailList += array (
  342. 'contract' => $contractNum
  343. );
  344. else
  345. $mailList += array (
  346. 'contract' => 0
  347. );
  348. if (! empty ( $instructions ))
  349. $mailList += array (
  350. 'instructions' => $instructionsNum
  351. );
  352. else
  353. $mailList += array (
  354. 'instructions' => 0
  355. );
  356. if (! empty ( $remittance ))
  357. $mailList += array (
  358. 'remittance' => $remittance
  359. );
  360. else
  361. $mailList += array (
  362. 'remittance' => ''
  363. );
  364. $mailString = '发票x1,备注:' . $mailItems;
  365. if (! empty ( $softLock ))
  366. $mailString .= ',软件锁x' . $softLockNum;
  367. if (! empty ( $contract ))
  368. $mailString .= ',合同x' . $contractNum;
  369. if (! empty ( $instructions ))
  370. $mailString .= ',说明书x' . $instructionsNum;
  371. if (! empty ( $remittance ))
  372. $mailString .= ',汇款账号单';
  373. $item += array (
  374. 'recipients' => $recipients,
  375. 'recipientsPhone' => $recipientsPhone,
  376. 'recipientsAddress' => $recipientsAddress,
  377. 'mailItems' => $mailString,
  378. 'mailItemsJson' => json_encode ( $mailList )
  379. );
  380. }
  381. $iid = $invoice->addInvoice ( $item );
  382. $item = array (
  383. 'date' => date ( "Y-m-d H:i:s" ),
  384. 'operation' => "创建",
  385. 'status' => 1,
  386. 'img' => $this->staff [0] ['avatar'],
  387. 'username' => $this->staff [0] ['username'],
  388. 'uid' => $this->staff [0] ['sid'],
  389. 'category' => $this->staff [0] ['category'],
  390. 'iid' => $iid
  391. );
  392. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  393. $item = array (
  394. 'date' => date ( "Y-m-d H:i:s" ),
  395. 'operation' => "提交审批",
  396. 'status' => 1,
  397. 'img' => $this->staff [0] ['avatar'],
  398. 'username' => $this->staff [0] ['username'],
  399. 'uid' => $this->staff [0] ['sid'],
  400. 'category' => $this->staff [0] ['category'],
  401. 'iid' => $iid
  402. );
  403. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  404. Doo::loadModel ( 'staff' );
  405. $staff = new staff ();
  406. $username2 = $staff->getOne ( array (
  407. 'select' => 'wxid',
  408. 'where' => 'sid=' . $pendingApprovalsSid,
  409. 'asArray' => TRUE
  410. ) );
  411. // 发送微信审批通知
  412. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  413. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  414. }
  415. return "/invoice";
  416. }
  417. function invoiceEdit() {
  418. Doo::loadClass ( 'XDeode' );
  419. $XDeode = new XDeode ( 5 );
  420. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  421. $iid = $XDeode->decode ( $iid );
  422. if (! is_numeric ( $iid ))
  423. die ( 'illegal request' );
  424. Doo::loadModel ( 'invoice' );
  425. $invoice = new invoice ();
  426. Doo::loadModel ( 'invoiceOperationLog' );
  427. $invoiceOperationLog = new invoiceOperationLog ();
  428. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  429. $operation = $invoiceOperationLog->getInvoiceOperationByDropped ( $iid );
  430. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  431. $this->data ['operation'] = $operation;
  432. $this->data ['invoiceDetail'] = $invoiceDetail;
  433. $this->data ['memu'] = "invoice";
  434. $this->data ['staff'] = $this->staff;
  435. $this->data ['receiptMemu'] = 'invoice';
  436. $this->render ( "/admin/invoiceEdit", $this->data );
  437. }
  438. /**
  439. * 重新编辑退回的发票
  440. * @return string
  441. */
  442. function invoiceEditDo() {
  443. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  444. Doo::loadModel ( 'invoice' );
  445. $invoice = new invoice ();
  446. $iid = $invoice->authcode ( $iidKey );
  447. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  448. die ( 'illegal request' );
  449. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  450. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  451. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  452. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  453. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  454. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  455. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  456. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  457. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  458. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  459. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  460. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  461. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  462. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  463. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  464. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  465. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  466. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  467. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  468. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  469. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  470. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  471. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  472. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  473. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  474. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  475. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  476. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  477. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  478. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  479. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  480. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  481. Doo::loadModel ( 'invoiceManage' );
  482. $invoiceManage = new invoiceManage ();
  483. Doo::loadModel ( 'invoiceOperationLog' );
  484. $invoiceOperationLog = new invoiceOperationLog ();
  485. $cid = explode ( ':', $cid );
  486. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  487. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  488. $moldManage = array ();
  489. foreach ( $invoiceManageList as $key => $value ) {
  490. if ($value ['mold'] == '发票打印')
  491. $moldManage [$value ['mold']] = $value ['staffList'];
  492. elseif ($value ['mold'] == '发票邮寄')
  493. $moldManage [$value ['mold']] = $value ['staffList'];
  494. elseif ($value ['mold'] == '发票打印')
  495. $moldManage [$value ['mold']] = $value ['staffList'];
  496. }
  497. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  498. $item = array (
  499. 'iid' => $iid,
  500. 'cid' => $cid [0],
  501. 'categoryName' => $cid [1],
  502. 'invoiceElement' => $invoiceElement,
  503. 'invoiceQuantity' => $invoiceQuantity,
  504. 'invoiceUnitPrice' => $invoiceUnitPrice,
  505. 'invoicePrice' => $invoicePrice,
  506. 'invoiceType' => $invoiceType,
  507. 'doPost' => $doPost,
  508. 'status' => 1,
  509. 'updateTime' => date ( "Y-m-d H:i:s" ),
  510. 'remark' => $remark
  511. );
  512. if ($invoiceType == 0)
  513. $item += array (
  514. 'invoiceTitle' => $invoiceTitle,
  515. 'TIN' => $TINT,
  516. 'address' => $addressT,
  517. 'phone' => $phoneT,
  518. 'bank' => $bankT,
  519. 'bankAccount' => $bankAccountT
  520. );
  521. else {
  522. $item += array (
  523. 'invoiceCompany' => $invoiceCompany,
  524. 'TIN' => $TIN,
  525. 'address' => $address,
  526. 'phone' => $phone,
  527. 'bank' => $bank,
  528. 'bankAccount' => $bankAccount
  529. );
  530. }
  531. if ($doPost == 1) {
  532. $mailList = array (
  533. 'invoice' => 1,
  534. 'mailItems' => $mailItems
  535. );
  536. if (! empty ( $softLock ))
  537. $mailList += array (
  538. 'softLock' => $softLockNum
  539. );
  540. else
  541. $mailList += array (
  542. 'softLock' => '0'
  543. );
  544. if (! empty ( $contract ))
  545. $mailList += array (
  546. 'contract' => $contractNum
  547. );
  548. else
  549. $mailList += array (
  550. 'contract' => '0'
  551. );
  552. if (! empty ( $instructions ))
  553. $mailList += array (
  554. 'instructions' => $instructionsNum
  555. );
  556. else
  557. $mailList += array (
  558. 'instructions' => '0'
  559. );
  560. if (! empty ( $remittance ))
  561. $mailList += array (
  562. 'remittance' => $remittance
  563. );
  564. else
  565. $mailList += array (
  566. 'remittance' => ''
  567. );
  568. $mailString = '发票x1,备注:' . $mailItems;
  569. if (! empty ( $softLock ))
  570. $mailString .= ',软件锁x' . $softLockNum;
  571. if (! empty ( $contract ))
  572. $mailString .= ',合同x' . $contractNum;
  573. if (! empty ( $instructions ))
  574. $mailString .= ',说明书x' . $instructionsNum;
  575. if (! empty ( $remittance ))
  576. $mailString .= ',汇款账号单';
  577. $item += array (
  578. 'recipients' => $recipients,
  579. 'recipientsPhone' => $recipientsPhone,
  580. 'recipientsAddress' => $recipientsAddress,
  581. 'mailItems' => $mailString,
  582. 'mailItemsJson' => json_encode ( $mailList )
  583. );
  584. }
  585. $invoice->setInvoiceByCondition ( $item );
  586. $item = array (
  587. 'date' => date ( "Y-m-d H:i:s" ),
  588. 'operation' => "重新提交审批",
  589. 'status' => 1,
  590. 'img' => $this->staff [0] ['avatar'],
  591. 'username' => $this->staff [0] ['username'],
  592. 'uid' => $this->staff [0] ['sid'],
  593. 'category' => $this->staff [0] ['category'],
  594. 'iid' => $iid
  595. );
  596. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  597. }
  598. return "/invoice";
  599. }
  600. /**
  601. * 培训班
  602. */
  603. function invoiceTraining() {
  604. Doo::loadModel ( 'L_category' );
  605. $lCategory = new L_category ();
  606. Doo::loadModel ( 'invoiceTraining' );
  607. $invoiceTraining = new invoiceTraining ();
  608. $itTodoList = $invoiceTraining->getInvoiceTrainingByTodo ( '', $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  609. $itedList = $invoiceTraining->getInvoiceTrainingByStatus ( 2, '', $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  610. $category = $lCategory->getCategory ();
  611. $itid = array ();
  612. foreach ( $itTodoList as $value ) {
  613. array_push ( $itid, $value ['itid'] );
  614. }
  615. foreach ( $itedList as $value ) {
  616. array_push ( $itid, $value ['itid'] );
  617. }
  618. $itid = implode ( ',', $itid );
  619. $this->data ['itStatist'] = $invoiceTraining->getInvoiceTrainStatistics ( $itid );
  620. // print_r($itTodoList);
  621. $this->data ['trainCount'] = count ( $itTodoList ) + count ( $itedList );
  622. $this->data ['itTodoList'] = $itTodoList;
  623. $this->data ['itedList'] = $itedList;
  624. $this->data ['category'] = $category;
  625. $this->data ['memu'] = "invoice";
  626. $this->data ['staff'] = $this->staff;
  627. $this->data ['receiptMemu'] = 'invoiceTraining';
  628. $this->render ( "/admin/invoiceTraining", $this->data );
  629. }
  630. /**
  631. * 创建培训班
  632. */
  633. function invoiceTrainingAdd() {
  634. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  635. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  636. $trainDate = $this->get_args ( 'trainDate' ) ? $this->get_args ( 'trainDate' ) : "";
  637. if (empty ( $this->staff [0] ))
  638. die ( 'illegal request' );
  639. if (! empty ( $cid ) && ! empty ( $trainName ) && ! empty ( $trainDate )) {
  640. Doo::loadModel ( 'invoiceTraining' );
  641. $invoiceTraining = new invoiceTraining ();
  642. Doo::loadModel ( 'invoice' );
  643. $invoice = new invoice ();
  644. Doo::loadModel ( 'L_category' );
  645. $lCategory = new L_category ();
  646. Doo::loadModel ( 'invoiceManage' );
  647. $invoiceManage = new invoiceManage ();
  648. Doo::loadModel ( 'invoiceOperationLog' );
  649. $invoiceOperationLog = new invoiceOperationLog ();
  650. $item = array (
  651. 'cid' => $cid,
  652. 'trainName' => $trainName,
  653. 'trainDate' => $trainDate,
  654. 'creator' => $this->staff [0] ['sid'],
  655. 'creatorDate' => date ( "Y-m-d H:i:s" )
  656. );
  657. $itid = $invoiceTraining->addInvoiceTraining ( $item );
  658. }
  659. return "/invoiceTraining";
  660. }
  661. /**
  662. * 删除培训班
  663. */
  664. function invoiceTrainingDelDo() {
  665. $itid = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  666. if (! empty ( $itid )) {
  667. Doo::loadModel ( 'invoiceTraining' );
  668. $invoiceTraining = new invoiceTraining ();
  669. $invoiceTraining->delInvoiceTrainingByItid ( $itid );
  670. }
  671. return "/invoiceTraining";
  672. }
  673. /**
  674. * 培训班详情
  675. */
  676. function invoiceTrainingDetail() {
  677. $trainStatus = $this->get_args ( 'trainStatus' ) ? $this->get_args ( 'trainStatus' ) : "ALL";
  678. $itid = isset ( $this->params ['trainingKey'] ) ? $this->params ['trainingKey'] : "";
  679. Doo::loadModel ( 'invoiceTraining' );
  680. $invoiceTraining = new invoiceTraining ();
  681. Doo::loadModel ( 'invoiceStore' );
  682. $invoiceStore = new invoiceStore ();
  683. if (empty ( $itid ))
  684. die ( 'illegal request' );
  685. $detail = $invoiceTraining->getInvoiceTrainingByItid ( $itid );
  686. $isList = $invoiceStore->getinvoiceStoreByItid ( $itid );
  687. // print_r($isList);
  688. $trainlist = array ();
  689. foreach ( $isList as $key => $value ) {
  690. $irDetail = array ();
  691. if ($value ['apStatus'] == 1) {
  692. // array_push ( $irDetail, '' );
  693. array_push ( $irDetail, '<input class="hide" disabled type="checkbox" >' );
  694. } else {
  695. array_push ( $irDetail, '<input type="checkbox" class="hide" id="' . $value ['storeKey'] . '" name="isBox" value="' . $value ['storeKey'] . '" > <a href="/invoiceStoreEdit/' . $value ['storeKey'] . '.html">编辑</a>
  696. <a href="#confirm" onclick="invoiceStoreApproval(\'' . $value ['storeKey'] . '\')" data-toggle="modal">提交审批</a>
  697. <a href="#del" node-iStore="del" data-key="' . $value ['storeKey'] . '" onclick="invoiceStoreDel(\'' . $value ['storeKey'] . '\')" data-toggle="modal" class="colRed">移除</a>' );
  698. }
  699. array_push ( $irDetail, $value ['invoiceSerial'] );
  700. if ($value ['invoiceType'] == 1)
  701. array_push ( $irDetail, $value ['invoiceCompany'] );
  702. else
  703. array_push ( $irDetail, $value ['invoiceTitle'] );
  704. array_push ( $irDetail, $value ['TIN'] );
  705. array_push ( $irDetail, $value ['userName'] );
  706. if (empty ( $value ['mailItems'] ) && $value ['apStatus'] != 1) {
  707. array_push ( $irDetail, '<a href="#confirm-erro" onclick="invoiceStoreMail(\'' . $value ['storeKey'] . '\')" data-toggle="modal">设置邮寄物品</a>' );
  708. } else
  709. array_push ( $irDetail, $value ['mailItems'] );
  710. array_push ( $irDetail, $value ['recipientsAddress'] . $value ['recipients'] . $value ['recipientsPhone'] );
  711. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  712. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  713. array_push ( $irDetail, $value ['invoiceElement'] );
  714. array_push ( $irDetail, $value ['invoiceQuantity'] );
  715. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  716. if ($value ['invoiceType'] == 1)
  717. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  718. else
  719. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  720. array_push ( $irDetail, $value ['remark'] );
  721. if ($value ['status'] == 1)
  722. array_push ( $irDetail, '审批中' );
  723. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1)
  724. array_push ( $irDetail, '已出票' );
  725. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1 && $value ['printStatus'] != 'irid' && ($value ['untreadStatus'] == 3 || $value ['untreadStatus'] == 0))
  726. array_push ( $irDetail, '已入账' );
  727. else
  728. array_push ( $irDetail, '' );
  729. array_push ( $irDetail, $value ['invoiceNo'] );
  730. array_push ( $irDetail, $value ['printTime'] );
  731. $html = '';
  732. foreach ( $value ['invoiceReceivables'] as $value ) {
  733. $html .= '&nbsp;<a href="#billing" node-invoice="INFO" data-type="receivables" data-iskey="' . $value [2] . '" data-toggle="modal">' . $value [1] . '</a>';
  734. }
  735. array_push ( $irDetail, $html );
  736. array_push ( $trainlist, $irDetail );
  737. }
  738. $trainlistJson = json_encode ( $trainlist );
  739. if (empty ( $detail ))
  740. die ( 'illegal request' );
  741. $this->data ['trainStatus'] = $trainStatus;
  742. $this->data ['itid'] = $itid;
  743. $this->data ['trainlistJson'] = $trainlistJson;
  744. $this->data ['iTrainDetail'] = $detail;
  745. $this->data ['memu'] = "invoice";
  746. $this->data ['staff'] = $this->staff;
  747. $this->data ['receiptMemu'] = 'invoiceTraining';
  748. $this->render ( "/admin/invoiceTrainingDetail", $this->data );
  749. }
  750. /**
  751. * 上传培训班发票
  752. * @return string
  753. */
  754. function invoiceTrainingUpload() {
  755. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  756. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  757. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  758. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  759. header ( "HTTP/1.1 500 Internal Server Error" );
  760. echo "POST exceeded maximum allowed size.";
  761. exit ( 0 );
  762. }
  763. // Settings
  764. $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)
  765. $upload_name = "Filedata";
  766. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  767. $extension_whitelist = array (
  768. "doc",
  769. "txt",
  770. "jpg",
  771. "gif",
  772. "png"
  773. ); // Allowed file extensions
  774. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  775. // Other variables
  776. $MAX_FILENAME_LENGTH = 260;
  777. $file_name = "";
  778. $file_extension = "";
  779. $uploadErrors = array (
  780. 0 => "文件上传成功",
  781. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  782. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  783. 3 => "上传的文件仅为部分文件",
  784. 4 => "没有文件上传",
  785. 6 => "缺少临时文件夹"
  786. );
  787. $nk = time ();
  788. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  789. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  790. echo "文件无法保存.";
  791. exit ( 0 );
  792. }
  793. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  794. echo json_encode ( array (
  795. 'filename' => $file_name,
  796. 'id' => $nk
  797. ) );
  798. exit ( 0 );
  799. }
  800. /**
  801. * 导入发票临时仓库
  802. */
  803. function invoiceStoreImport() {
  804. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  805. $trainingKey = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  806. $path = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  807. if ($path != "" && ! empty ( $trainingKey )) {
  808. Doo::loadModel ( 'invoiceStore' );
  809. Doo::loadModel ( 'staff' );
  810. $staff = new staff ();
  811. Doo::loadModel ( 'invoiceTraining' );
  812. $invoiceTraining = new invoiceTraining ();
  813. Doo::loadClass ( 'XDeode' );
  814. $XDeode = new XDeode ( 5 );
  815. $itid = $XDeode->decode ( $trainingKey );
  816. $exlArray = $this->formatExcelToArrayTrain ( DOO::conf ()->SITE_PATH . "upload/invoiceTraining/" . $path );
  817. $userName = $this->staff [0] ['username'];
  818. $sDetail = $staff->getStaffByName ( $userName );
  819. // die('sdd');
  820. // 可以优化
  821. foreach ( $exlArray as $key => $value ) {
  822. // 开票
  823. $invoice = new invoiceStore ();
  824. $invoice->trainId = $itid;
  825. $invoice->invoiceType = 0;
  826. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  827. $invoice->invoiceType = 1;
  828. $invoice->invoiceQuantity = $value ['invoiceQuantity'];
  829. $invoice->invoiceUnitPrice = $value ['invoiceUnitPrice'];
  830. $invoice->invoicePrice = $value ['invoiceQuantity'] * $value ['invoiceUnitPrice'];
  831. $invoice->invoiceTitle = $value ['invoiceTitle'];
  832. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  833. $invoice->invoiceCompany = $value ['invoiceTitle'];
  834. $invoice->userName = $userName;
  835. $invoice->sid = $sDetail ['sid'];
  836. $invoice->cid = $sDetail ['cid'];
  837. $invoice->categoryName = $sDetail ['category'];
  838. $invoice->invoiceElement = $value ['invoiceElement'];
  839. $invoice->remark = $value ['remark'];
  840. // $invoice->date = $value ['date'];
  841. // $invoice->printTime = $value ['date'];
  842. $invoice->ipSource = 1;
  843. $invoice->printStatus = 1;
  844. $invoice->status = 2;
  845. $invoice->postStatus = 1;
  846. $invoice->untreadStatus = 0;
  847. // $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  848. $invoice->TIN = $value ['TIN'];
  849. $invoice->address = $value ['address'];
  850. $invoice->phone = $value ['phone'];
  851. $invoice->bank = $value ['bank'];
  852. $invoice->bankAccount = $value ['bankAccount'];
  853. $invoice->recipientsAddress = $value ['recipientsAddress'];
  854. $invoice->recipients = $value ['recipients'];
  855. $invoice->recipientsPhone = $value ['recipientsPhone'];
  856. $iid = $invoice->insert ();
  857. }
  858. // 加入发票总数量
  859. $item = array (
  860. 'itid' => $itid,
  861. 'invoiceTotal' => count ( $exlArray )
  862. );
  863. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  864. return '/invoiceTrainingDetail/' . $trainingKey . ".html";
  865. }
  866. echo 'no file';
  867. }
  868. /**
  869. * 编辑仓库里的发票
  870. */
  871. function invoiceStoreEdit() {
  872. Doo::loadClass ( 'XDeode' );
  873. $XDeode = new XDeode ( 5 );
  874. $iid = isset ( $this->params ['storeKey'] ) ? $this->params ['storeKey'] : "";
  875. $iid = $XDeode->decode ( $iid );
  876. if (! is_numeric ( $iid ))
  877. die ( 'illegal request' );
  878. Doo::loadModel ( 'invoiceStore' );
  879. $invoiceStore = new invoiceStore ();
  880. $invoiceDetail = $invoiceStore->getInvoiceStoreByIsid ( $iid );
  881. // print_r($invoiceDetail);
  882. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  883. $this->data ['invoiceDetail'] = $invoiceDetail;
  884. $this->data ['memu'] = "invoice";
  885. $this->data ['staff'] = $this->staff;
  886. $this->data ['receiptMemu'] = 'invoiceTraining';
  887. $this->render ( "/admin/invoiceStoreEdit", $this->data );
  888. }
  889. function invoiceStoreEditDo() {
  890. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  891. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  892. Doo::loadModel ( 'invoiceStore' );
  893. $invoice = new invoiceStore ();
  894. Doo::loadClass ( 'XDeode' );
  895. $XDeode = new XDeode ( 5 );
  896. $iid = $XDeode->decode ( $storeKey );
  897. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  898. die ( 'illegal request' );
  899. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  900. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  901. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  902. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  903. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  904. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  905. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  906. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  907. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  908. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  909. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  910. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  911. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  912. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  913. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  914. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  915. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  916. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  917. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  918. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  919. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  920. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  921. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  922. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  923. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  924. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  925. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  926. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  927. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  928. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  929. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  930. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  931. $cid = explode ( ':', $cid );
  932. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  933. $item = array (
  934. 'isid' => $iid,
  935. 'cid' => $cid [0],
  936. 'categoryName' => $cid [1],
  937. 'invoiceElement' => $invoiceElement,
  938. 'invoiceQuantity' => $invoiceQuantity,
  939. 'invoiceUnitPrice' => $invoiceUnitPrice,
  940. 'invoicePrice' => $invoicePrice,
  941. 'invoiceType' => $invoiceType,
  942. 'doPost' => $doPost,
  943. 'status' => 1,
  944. 'updateTime' => date ( "Y-m-d H:i:s" ),
  945. 'remark' => $remark
  946. );
  947. if ($invoiceType == 0)
  948. $item += array (
  949. 'invoiceTitle' => $invoiceTitle,
  950. 'TIN' => $TINT,
  951. 'address' => $addressT,
  952. 'phone' => $phoneT,
  953. 'bank' => $bankT,
  954. 'bankAccount' => $bankAccountT
  955. );
  956. else {
  957. $item += array (
  958. 'invoiceCompany' => $invoiceCompany,
  959. 'TIN' => $TIN,
  960. 'address' => $address,
  961. 'phone' => $phone,
  962. 'bank' => $bank,
  963. 'bankAccount' => $bankAccount
  964. );
  965. }
  966. if ($doPost == 1) {
  967. $mailList = array (
  968. 'invoice' => 1,
  969. 'mailItems' => $mailItems
  970. );
  971. if (! empty ( $softLock ))
  972. $mailList += array (
  973. 'softLock' => $softLockNum
  974. );
  975. else
  976. $mailList += array (
  977. 'softLock' => '0'
  978. );
  979. if (! empty ( $contract ))
  980. $mailList += array (
  981. 'contract' => $contractNum
  982. );
  983. else
  984. $mailList += array (
  985. 'contract' => '0'
  986. );
  987. if (! empty ( $instructions ))
  988. $mailList += array (
  989. 'instructions' => $instructionsNum
  990. );
  991. else
  992. $mailList += array (
  993. 'instructions' => '0'
  994. );
  995. if (! empty ( $remittance ))
  996. $mailList += array (
  997. 'remittance' => $remittance
  998. );
  999. else
  1000. $mailList += array (
  1001. 'remittance' => ''
  1002. );
  1003. $mailString = '发票x1,备注:' . $mailItems;
  1004. if (! empty ( $softLock ))
  1005. $mailString .= ',软件锁x' . $softLockNum;
  1006. if (! empty ( $contract ))
  1007. $mailString .= ',合同x' . $contractNum;
  1008. if (! empty ( $instructions ))
  1009. $mailString .= ',说明书x' . $instructionsNum;
  1010. if (! empty ( $remittance ))
  1011. $mailString .= ',汇款账号单';
  1012. $item += array (
  1013. 'recipients' => $recipients,
  1014. 'recipientsPhone' => $recipientsPhone,
  1015. 'recipientsAddress' => $recipientsAddress,
  1016. 'mailItems' => $mailString,
  1017. 'mailItemsJson' => json_encode ( $mailList )
  1018. );
  1019. }
  1020. $invoice->setInvoiceStoreByCondition ( $item );
  1021. }
  1022. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1023. }
  1024. /**
  1025. *
  1026. * @return string
  1027. */
  1028. function invoiceStoreDelete() {
  1029. Doo::loadClass ( 'XDeode' );
  1030. $XDeode = new XDeode ( 5 );
  1031. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1032. $iStoreKey = $this->get_args ( 'iStoreKey' ) ? $this->get_args ( 'iStoreKey' ) : 0;
  1033. $isid = $XDeode->decode ( $iStoreKey );
  1034. $itid = $XDeode->decode ( $trainKey );
  1035. if (! is_numeric ( $isid ))
  1036. die ( 'illegal request' );
  1037. Doo::loadModel ( 'invoiceStore' );
  1038. $invoiceStore = new invoiceStore ();
  1039. $invoiceStore->delete ( array (
  1040. 'where' => 'isid=' . $isid,
  1041. 'limit' => 1
  1042. ) );
  1043. Doo::loadModel ( 'invoiceTraining' );
  1044. $invoiceTraining = new invoiceTraining ();
  1045. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1046. $item = array (
  1047. 'itid' => $itid,
  1048. 'invoiceTotal' => $itDetail ['invoiceTotal'] - 1
  1049. );
  1050. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1051. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1052. }
  1053. /**
  1054. * 批量删除库里发票
  1055. */
  1056. function invoiceStoreBatchDelete() {
  1057. Doo::loadClass ( 'XDeode' );
  1058. $XDeode = new XDeode ( 5 );
  1059. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1060. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1061. $tid = $XDeode->decode ( $trainKey );
  1062. if (! is_numeric ( $tid ) && ! empty ( $storeKey ))
  1063. die ( 'illegal request' );
  1064. Doo::loadModel ( 'invoiceStore' );
  1065. $isidKeyList = explode ( ',', $storeKey );
  1066. $isidList = array ();
  1067. foreach ( $isidKeyList as $value ) {
  1068. $isid = $XDeode->decode ( $value );
  1069. if (! empty ( $isid ) && is_numeric ( $isid ))
  1070. array_push ( $isidList, $isid );
  1071. }
  1072. $isidString = implode ( ',', $isidList );
  1073. $invoiceStore = new invoiceStore ();
  1074. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,apStatus' );
  1075. $isidList = array ();
  1076. foreach ( $isList as $key => $value ) {
  1077. if ($value ['apStatus'] == 0)
  1078. array_push ( $isidList, $value ['isid'] );
  1079. }
  1080. $isidString = implode ( ',', $isidList );
  1081. // print_r($isList);
  1082. // echo $isidString;
  1083. $invoiceStore = new invoiceStore ();
  1084. $invoiceStore->delete ( array (
  1085. 'where' => "isid in ( " . $isidString . ")",
  1086. 'asArray' => TRUE
  1087. ) );
  1088. Doo::loadModel ( 'invoiceTraining' );
  1089. $invoiceTraining = new invoiceTraining ();
  1090. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1091. $item = array (
  1092. 'itid' => $tid,
  1093. 'invoiceTotal' => $itDetail ['invoiceTotal'] - count ( $isidList )
  1094. );
  1095. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1096. // echo $tid;
  1097. // echo $storeKey;
  1098. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1099. }
  1100. /**
  1101. * 仓库发票提交审批
  1102. * @return string
  1103. */
  1104. function invoiceStoreApproval() {
  1105. Doo::loadClass ( 'XDeode' );
  1106. $XDeode = new XDeode ( 5 );
  1107. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1108. $iStoreKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1109. $isid = $XDeode->decode ( $iStoreKey );
  1110. $trainId = $XDeode->decode ( $trainKey );
  1111. if (! is_numeric ( $isid ))
  1112. die ( 'illegal request' );
  1113. Doo::loadModel ( 'invoiceStore' );
  1114. Doo::loadModel ( 'invoice' );
  1115. $invoice = new invoice ();
  1116. // 拷贝插入一条发票数据
  1117. $invoiceStore = new invoiceStore ();
  1118. $iid = $invoiceStore->setInvoiceStoreToApproval ( $isid );
  1119. $invoiceStore = new invoiceStore ();
  1120. $item = array (
  1121. 'isid' => $isid,
  1122. 'iid' => $iid,
  1123. 'apStatus' => 1
  1124. );
  1125. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1126. Doo::loadModel ( 'invoiceManage' );
  1127. $invoiceManage = new invoiceManage ();
  1128. Doo::loadModel ( 'invoiceOperationLog' );
  1129. $invoiceOperationLog = new invoiceOperationLog ();
  1130. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1131. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1132. $moldManage = array ();
  1133. foreach ( $invoiceManageList as $key => $value ) {
  1134. if ($value ['mold'] == '发票打印')
  1135. $moldManage [$value ['mold']] = $value ['staffList'];
  1136. elseif ($value ['mold'] == '发票邮寄')
  1137. $moldManage [$value ['mold']] = $value ['staffList'];
  1138. elseif ($value ['mold'] == '发票退票')
  1139. $moldManage [$value ['mold']] = $value ['staffList'];
  1140. }
  1141. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1142. $item = array (
  1143. 'iid' => $iid,
  1144. 'invoiceSerial' => "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  1145. 'date' => date ( "Y-m-d H:i:s" ),
  1146. 'status' => 1,
  1147. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1148. 'trainId' => $trainId,
  1149. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1150. 'moldManage' => json_encode ( $moldManage ),
  1151. 'pendingApprovals' => $pendingApprovalsSid
  1152. );
  1153. $invoice->setInvoiceByCondition ( $item );
  1154. Doo::loadModel ( 'invoiceTraining' );
  1155. $invoiceTraining = new invoiceTraining ();
  1156. $item = array (
  1157. 'itid' => $trainId,
  1158. 'submitStatus' => 1
  1159. );
  1160. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1161. $item = array (
  1162. 'date' => date ( "Y-m-d H:i:s" ),
  1163. 'operation' => "创建",
  1164. 'status' => 1,
  1165. 'img' => $this->staff [0] ['avatar'],
  1166. 'username' => $this->staff [0] ['username'],
  1167. 'uid' => $this->staff [0] ['sid'],
  1168. 'category' => $this->staff [0] ['category'],
  1169. 'iid' => $iid
  1170. );
  1171. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1172. $item = array (
  1173. 'date' => date ( "Y-m-d H:i:s" ),
  1174. 'operation' => "提交审批",
  1175. 'status' => 1,
  1176. 'img' => $this->staff [0] ['avatar'],
  1177. 'username' => $this->staff [0] ['username'],
  1178. 'uid' => $this->staff [0] ['sid'],
  1179. 'category' => $this->staff [0] ['category'],
  1180. 'iid' => $iid
  1181. );
  1182. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1183. Doo::loadModel ( 'staff' );
  1184. $staff = new staff ();
  1185. $username2 = $staff->getOne ( array (
  1186. 'select' => 'wxid',
  1187. 'where' => 'sid=' . $pendingApprovalsSid,
  1188. 'asArray' => TRUE
  1189. ) );
  1190. // 发送微信审批通知
  1191. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1192. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1193. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1194. }
  1195. /**
  1196. * 批量提交发票
  1197. * @return string
  1198. */
  1199. function invoiceStoreBatchApproval() {
  1200. Doo::loadClass ( 'XDeode' );
  1201. $XDeode = new XDeode ( 5 );
  1202. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1203. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1204. $trainId = $XDeode->decode ( $trainKey );
  1205. $isidKeyList = explode ( ',', $storeKey );
  1206. $isidList = array ();
  1207. foreach ( $isidKeyList as $value ) {
  1208. $isid = $XDeode->decode ( $value );
  1209. if (! empty ( $isid ) && is_numeric ( $isid ))
  1210. array_push ( $isidList, $isid );
  1211. }
  1212. $isidString = implode ( ',', $isidList );
  1213. if (! is_numeric ( $trainId ))
  1214. die ( 'illegal request' );
  1215. Doo::loadModel ( 'invoiceStore' );
  1216. Doo::loadModel ( 'invoice' );
  1217. // 判断哪些已经加入审批过
  1218. // 拷贝插入一条发票数据
  1219. $invoiceStore = new invoiceStore ();
  1220. $invoiceStore->setInvoiceStoreBatchToApproval ( $isidString );
  1221. $invoiceStore = new invoiceStore ();
  1222. $item = array (
  1223. 'apStatus' => 1
  1224. );
  1225. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1226. // 获得正式发票ID
  1227. $invoice = new invoice ();
  1228. $iidList = $invoice->getInvoiceByIstoreid ( $isidString, 'iid,isid' );
  1229. $sqlList = array ();
  1230. $iidString = '';
  1231. $iida = array ();
  1232. foreach ( $iidList as $key => $value ) {
  1233. $sqlList [$value ['isid']] = $value ['iid'];
  1234. array_push ( $iida, $value ['iid'] );
  1235. }
  1236. $iidString = implode ( ',', $iida );
  1237. $ids = implode ( ',', array_keys ( $sqlList ) );
  1238. $sql = "UPDATE CLD_invoiceStore SET iid = CASE isid ";
  1239. foreach ( $sqlList as $id => $ordinal ) {
  1240. $sql .= sprintf ( "WHEN %d THEN %d ", $id, $ordinal );
  1241. }
  1242. $sql .= "END WHERE isid IN ($ids)";
  1243. $invoiceStore = new invoiceStore ();
  1244. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1245. Doo::loadModel ( 'invoiceManage' );
  1246. $invoiceManage = new invoiceManage ();
  1247. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1248. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1249. $moldManage = array ();
  1250. foreach ( $invoiceManageList as $key => $value ) {
  1251. if ($value ['mold'] == '发票打印')
  1252. $moldManage [$value ['mold']] = $value ['staffList'];
  1253. elseif ($value ['mold'] == '发票邮寄')
  1254. $moldManage [$value ['mold']] = $value ['staffList'];
  1255. elseif ($value ['mold'] == '发票退票')
  1256. $moldManage [$value ['mold']] = $value ['staffList'];
  1257. }
  1258. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1259. // 批量更新发票信息
  1260. $item = array (
  1261. 'date' => date ( "Y-m-d H:i:s" ),
  1262. 'status' => 1,
  1263. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1264. 'trainId' => $trainId,
  1265. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1266. 'moldManage' => json_encode ( $moldManage ),
  1267. 'pendingApprovals' => $pendingApprovalsSid
  1268. );
  1269. $invoice = new invoice ();
  1270. $invoice->BatchInvoiceByCondition ( $item, $iidString );
  1271. // 批量更新发票序列号
  1272. $sqlList = array ();
  1273. foreach ( $iida as $value ) {
  1274. $sqlList [$value] = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1275. }
  1276. $ids = implode ( ',', array_keys ( $sqlList ) );
  1277. $sql = "UPDATE CLD_invoice SET invoiceSerial = CASE iid ";
  1278. foreach ( $sqlList as $id => $ordinal ) {
  1279. $sql .= sprintf ( "WHEN %d THEN '%s' ", $id, $ordinal );
  1280. }
  1281. $sql .= "END WHERE iid IN ($ids)";
  1282. $invoiceStore = new invoiceStore ();
  1283. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1284. // 批量生产操作日志
  1285. Doo::loadModel ( 'invoiceOperationLog' );
  1286. $sqlList = array ();
  1287. foreach ( $iida as $key => $value ) {
  1288. $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 . '"),
  1289. ("' . 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 . '") ';
  1290. array_push ( $sqlList, $sql );
  1291. }
  1292. $iolSql = implode ( ',', $sqlList );
  1293. $sql = "INSERT INTO `CLD_invoiceOperationLog` (`date`, `operation`, `status`, `img`, `username`, `uid`, `category`, `iid`) VALUES " . $iolSql;
  1294. $invoiceOperationLog = new invoiceOperationLog ();
  1295. $invoiceOperationLog->setInvoiceOperationLogBySql ( $sql );
  1296. Doo::loadModel ( 'invoiceTraining' );
  1297. $invoiceTraining = new invoiceTraining ();
  1298. $item = array (
  1299. 'itid' => $trainId,
  1300. 'submitStatus' => 1
  1301. );
  1302. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1303. // Doo::loadModel ( 'invoiceOperationLog' );
  1304. // $item = array (
  1305. // 'date' => date ( "Y-m-d H:i:s" ),
  1306. // 'operation' => "创建",
  1307. // 'status' => 1,
  1308. // 'img' => $this->staff [0] ['avatar'],
  1309. // 'username' => $this->staff [0] ['username'],
  1310. // 'uid' => $this->staff [0] ['sid'],
  1311. // 'category' => $this->staff [0] ['category'],
  1312. // 'iid' => $iid
  1313. // );
  1314. // $invoiceOperationLog = new invoiceOperationLog ();
  1315. // $invoiceOperationLog->setInvoiceOperationLog ( $item ,$iidString);
  1316. // $item = array (
  1317. // 'date' => date ( "Y-m-d H:i:s" ),
  1318. // 'operation' => "提交审批",
  1319. // 'status' => 1,
  1320. // 'img' => $this->staff [0] ['avatar'],
  1321. // 'username' => $this->staff [0] ['username'],
  1322. // 'uid' => $this->staff [0] ['sid'],
  1323. // 'category' => $this->staff [0] ['category'],
  1324. // 'iid' => $iid
  1325. // );
  1326. // $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1327. Doo::loadModel ( 'staff' );
  1328. $staff = new staff ();
  1329. $username2 = $staff->getOne ( array (
  1330. 'select' => 'wxid',
  1331. 'where' => 'sid=' . $pendingApprovalsSid,
  1332. 'asArray' => TRUE
  1333. ) );
  1334. // 发送微信审批通知
  1335. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1336. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1337. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1338. }
  1339. /**
  1340. */
  1341. function invoiceStoreMailItemSet() {
  1342. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1343. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1344. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1345. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1346. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1347. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1348. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1349. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1350. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1351. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1352. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1353. Doo::loadClass ( 'XDeode' );
  1354. $XDeode = new XDeode ( 5 );
  1355. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1356. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1357. $isid = $XDeode->decode ( $storeKey );
  1358. $trainId = $XDeode->decode ( $trainKey );
  1359. if (! is_numeric ( $isid ))
  1360. die ( 'illegal request' );
  1361. Doo::loadModel ( 'invoiceStore' );
  1362. $invoiceStore = new invoiceStore ();
  1363. $mailList = array (
  1364. 'invoice' => 1,
  1365. 'mailItems' => $mailItems
  1366. );
  1367. if (! empty ( $softLock ))
  1368. $mailList += array (
  1369. 'softLock' => $softLockNum
  1370. );
  1371. else
  1372. $mailList += array (
  1373. 'softLock' => 0
  1374. );
  1375. if (! empty ( $contract ))
  1376. $mailList += array (
  1377. 'contract' => $contractNum
  1378. );
  1379. else
  1380. $mailList += array (
  1381. 'contract' => 0
  1382. );
  1383. if (! empty ( $instructions ))
  1384. $mailList += array (
  1385. 'instructions' => $instructionsNum
  1386. );
  1387. else
  1388. $mailList += array (
  1389. 'instructions' => 0
  1390. );
  1391. if (! empty ( $remittance ))
  1392. $mailList += array (
  1393. 'remittance' => $remittance
  1394. );
  1395. else
  1396. $mailList += array (
  1397. 'remittance' => ''
  1398. );
  1399. $mailString = '发票x1,备注:' . $mailItems;
  1400. if (! empty ( $softLock ))
  1401. $mailString .= ',软件锁x' . $softLockNum;
  1402. if (! empty ( $contract ))
  1403. $mailString .= ',合同x' . $contractNum;
  1404. if (! empty ( $instructions ))
  1405. $mailString .= ',说明书x' . $instructionsNum;
  1406. if (! empty ( $remittance ))
  1407. $mailString .= ',汇款账号单';
  1408. $item = array (
  1409. 'isid' => $isid,
  1410. 'doPost' => 1,
  1411. 'mailItems' => $mailString,
  1412. 'mailItemsJson' => json_encode ( $mailList )
  1413. );
  1414. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1415. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1416. }
  1417. /**
  1418. * 批量设置邮寄物品
  1419. */
  1420. function invoiceStoreBatchMailItemSet() {
  1421. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1422. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1423. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1424. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1425. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1426. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1427. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1428. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1429. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1430. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1431. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1432. Doo::loadClass ( 'XDeode' );
  1433. $XDeode = new XDeode ( 5 );
  1434. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1435. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1436. $isidKeyList = explode ( ',', $storeKey );
  1437. $isidList = array ();
  1438. foreach ( $isidKeyList as $value ) {
  1439. $isid = $XDeode->decode ( $value );
  1440. if (! empty ( $isid ) && is_numeric ( $isid ))
  1441. array_push ( $isidList, $isid );
  1442. }
  1443. $isidString = implode ( ',', $isidList );
  1444. $trainId = $XDeode->decode ( $trainKey );
  1445. if (! is_numeric ( $isid ))
  1446. die ( 'illegal request' );
  1447. Doo::loadModel ( 'invoiceStore' );
  1448. $invoiceStore = new invoiceStore ();
  1449. $mailList = array (
  1450. 'invoice' => 1,
  1451. 'mailItems' => $mailItems
  1452. );
  1453. if (! empty ( $softLock ))
  1454. $mailList += array (
  1455. 'softLock' => $softLockNum
  1456. );
  1457. else
  1458. $mailList += array (
  1459. 'softLock' => 0
  1460. );
  1461. if (! empty ( $contract ))
  1462. $mailList += array (
  1463. 'contract' => $contractNum
  1464. );
  1465. else
  1466. $mailList += array (
  1467. 'contract' => 0
  1468. );
  1469. if (! empty ( $instructions ))
  1470. $mailList += array (
  1471. 'instructions' => $instructionsNum
  1472. );
  1473. else
  1474. $mailList += array (
  1475. 'instructions' => 0
  1476. );
  1477. if (! empty ( $remittance ))
  1478. $mailList += array (
  1479. 'remittance' => $remittance
  1480. );
  1481. else
  1482. $mailList += array (
  1483. 'remittance' => ''
  1484. );
  1485. $mailString = '发票x1,备注:' . $mailItems;
  1486. if (! empty ( $softLock ))
  1487. $mailString .= ',软件锁x' . $softLockNum;
  1488. if (! empty ( $contract ))
  1489. $mailString .= ',合同x' . $contractNum;
  1490. if (! empty ( $instructions ))
  1491. $mailString .= ',说明书x' . $instructionsNum;
  1492. if (! empty ( $remittance ))
  1493. $mailString .= ',汇款账号单';
  1494. $item = array (
  1495. 'doPost' => 1,
  1496. 'mailItems' => $mailString,
  1497. 'mailItemsJson' => json_encode ( $mailList )
  1498. );
  1499. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1500. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1501. }
  1502. /**
  1503. * 废弃
  1504. */
  1505. function ajaxGetMailItemByIstore() {
  1506. Doo::loadClass ( 'XDeode' );
  1507. $XDeode = new XDeode ( 5 );
  1508. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1509. $isid = $XDeode->decode ( $storeKey );
  1510. if (! is_numeric ( $isid ))
  1511. die ( 'illegal request' );
  1512. Doo::loadModel ( 'invoiceStore' );
  1513. $invoiceStore = new invoiceStore ();
  1514. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid );
  1515. $isDetail ['mailItemsJson'] = json_decode ( $isDetail ['mailItemsJson'], true );
  1516. echo json_encode ( $isDetail ['mailItemsJson'] );
  1517. exit ();
  1518. }
  1519. /**
  1520. * 终止开票
  1521. */
  1522. function invoiceDroppedDo() {
  1523. $droppedIidKey = $this->get_args ( 'droppedIidKey' ) ? $this->get_args ( 'droppedIidKey' ) : '';
  1524. Doo::loadModel ( 'invoice' );
  1525. $invoice = new invoice ();
  1526. Doo::loadModel ( 'invoiceOperationLog' );
  1527. $invoiceOperationLog = new invoiceOperationLog ();
  1528. $iid = $invoice->authcode ( $droppedIidKey );
  1529. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1530. die ( 'illegal request' );
  1531. $item = array (
  1532. 'iid' => $iid,
  1533. 'status' => 4,
  1534. 'updateTime' => date ( "Y-m-d H:i:s" )
  1535. );
  1536. $invoice->setInvoiceByCondition ( $item );
  1537. $item = array (
  1538. 'date' => date ( "Y-m-d H:i:s" ),
  1539. 'operation' => '终止了开票',
  1540. 'status' => 4,
  1541. 'img' => $this->staff [0] ['avatar'],
  1542. 'username' => $this->staff [0] ['username'],
  1543. 'uid' => $this->staff [0] ['sid'],
  1544. 'category' => $this->staff [0] ['category'],
  1545. 'iid' => $iid
  1546. );
  1547. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1548. return "/invoice";
  1549. }
  1550. /**
  1551. * 更新退票的邮寄信息
  1552. */
  1553. function invoiceUntreadMailDo() {
  1554. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  1555. $untreadCompany = $this->get_args ( 'untreadCompany' ) ? $this->get_args ( 'untreadCompany' ) : "";
  1556. $untreadNumber = $this->get_args ( 'untreadNumber' ) ? $this->get_args ( 'untreadNumber' ) : "";
  1557. $untreadItems = $this->get_args ( 'untreadItems' ) ? $this->get_args ( 'untreadItems' ) : "";
  1558. Doo::loadModel ( 'invoice' );
  1559. $invoice = new invoice ();
  1560. $iid = $invoice->authcode ( $untreadIidKey );
  1561. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1562. die ( 'illegal request' );
  1563. $item = array (
  1564. 'iid' => $iid,
  1565. 'untreadCompany' => $untreadCompany,
  1566. 'untreadNumber' => $untreadNumber,
  1567. 'untreadItems' => $untreadItems
  1568. );
  1569. $invoice->setInvoiceByCondition ( $item );
  1570. return "/invoice";
  1571. }
  1572. /**
  1573. * 申请退票 --
  1574. */
  1575. function invoiceUntreadDo() {
  1576. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  1577. $untreadReason = $this->get_args ( 'untreadReason' ) ? $this->get_args ( 'untreadReason' ) : "";
  1578. $untreadPost = $this->get_args ( 'untreadPost' ) ? $this->get_args ( 'untreadPost' ) : "";
  1579. Doo::loadModel ( 'invoice' );
  1580. $invoice = new invoice ();
  1581. Doo::loadModel ( 'invoiceOperationLog' );
  1582. $invoiceOperationLog = new invoiceOperationLog ();
  1583. Doo::loadModel ( 'invoiceReceivables' );
  1584. $invoiceReceivables = new invoiceReceivables ();
  1585. $iid = $invoice->authcode ( $untreadIidKey );
  1586. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1587. die ( 'illegal request' );
  1588. /*
  1589. * 需求变革 有绑定收款也可以退票 $lt = $invoiceReceivables->getInvoiceReceivablesByIid ( $untreadIidKey ); if (! empty ( $lt )) { header ( 'Content-Type:text/html;charset=utf-8' ); die ( '该发票有收款绑定,请先移除!' ); }
  1590. */
  1591. $item = array (
  1592. 'iid' => $iid,
  1593. 'untreadStatus' => 1,
  1594. 'untreadReason' => $untreadReason,
  1595. 'untreadPost' => $untreadPost,
  1596. 'updateTime' => date ( "Y-m-d H:i:s" )
  1597. );
  1598. $invoice->setInvoiceByCondition ( $item );
  1599. $item = array (
  1600. 'date' => date ( "Y-m-d H:i:s" ),
  1601. 'operation' => '申请退票',
  1602. 'status' => 7,
  1603. 'img' => $this->staff [0] ['avatar'],
  1604. 'username' => $this->staff [0] ['username'],
  1605. 'uid' => $this->staff [0] ['sid'],
  1606. 'category' => $this->staff [0] ['category'],
  1607. 'iid' => $iid
  1608. );
  1609. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1610. return "/invoice";
  1611. }
  1612. /**
  1613. * 删除已终止的开票
  1614. */
  1615. function invoiceDelDo() {
  1616. Doo::loadModel ( 'invoice' );
  1617. $invoice = new invoice ();
  1618. Doo::loadModel ( 'invoiceOperationLog' );
  1619. $invoiceOperationLog = new invoiceOperationLog ();
  1620. Doo::loadClass ( 'XDeode' );
  1621. $XDeode = new XDeode ( 5 );
  1622. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  1623. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  1624. $iid = $XDeode->decode ( $iid );
  1625. Doo::loadModel ( 'invoiceStore' );
  1626. $invoiceStore = new invoiceStore ();
  1627. if (! is_numeric ( $iid ))
  1628. die ( 'illegal request' );
  1629. $invoiceDetail = $invoice->getMyInvoice ( $sid, $iid );
  1630. if (empty ( $invoiceDetail ))
  1631. die ( 'illegal request' );
  1632. $item = array (
  1633. 'iid' => $iid,
  1634. 'isDelete' => 1,
  1635. 'updateTime' => date ( "Y-m-d H:i:s" )
  1636. );
  1637. $invoice->setInvoiceByCondition ( $item );
  1638. $item = array (
  1639. 'date' => date ( "Y-m-d H:i:s" ),
  1640. 'operation' => '删除了已终止的发票',
  1641. 'status' => 4,
  1642. 'img' => $this->staff [0] ['avatar'],
  1643. 'username' => $this->staff [0] ['username'],
  1644. 'uid' => $this->staff [0] ['sid'],
  1645. 'category' => $this->staff [0] ['category'],
  1646. 'iid' => $iid
  1647. );
  1648. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1649. // 删除培训班发票仓库里的发票
  1650. $invoiceStore->delInvoiceStoreByIsid ( $invoiceDetail ['isid'] );
  1651. return "/invoice";
  1652. }
  1653. function invoiceApproval() {
  1654. Doo::loadModel ( 'invoice' );
  1655. $invoice = new invoice ();
  1656. Doo::loadClass ( 'XDeode' );
  1657. $XDeode = new XDeode ( 5 );
  1658. Doo::loadModel ( 'staff' );
  1659. $staff = new staff ();
  1660. $invoiceList = $invoice->find ( array (
  1661. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  1662. 'desc' => 'iid',
  1663. 'asArray' => true
  1664. ) );
  1665. foreach ( $invoiceList as $key => $value ) {
  1666. $invoiceList [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1667. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1668. if (! empty ( $lastApprover )) {
  1669. $lastApproverKey = array_keys ( $lastApprover );
  1670. $lastApprover = end ( $lastApprover );
  1671. $staffDetail = $staff->getOne ( array (
  1672. 'where' => 'sid=' . end ( $lastApproverKey ),
  1673. 'asArray' => true
  1674. ) );
  1675. $lastApprover ['username'] = $staffDetail ['username'];
  1676. }
  1677. $invoiceList [$key] ['lastApprover'] = $lastApprover;
  1678. }
  1679. $ilist = $invoice->getInvoiceByProcessStatus ();
  1680. foreach ( $ilist as $key => $value ) {
  1681. $ilist [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1682. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1683. if (! empty ( $lastApprover )) {
  1684. $lastApproverKey = array_keys ( $lastApprover );
  1685. $lastApprover = end ( $lastApprover );
  1686. $staffDetail = $staff->getOne ( array (
  1687. 'where' => 'sid=' . end ( $lastApproverKey ),
  1688. 'asArray' => true
  1689. ) );
  1690. $lastApprover ['username'] = $staffDetail ['username'];
  1691. }
  1692. $ilist [$key] ['lastApprover'] = $lastApprover;
  1693. }
  1694. // print_r($ilist);
  1695. $this->data ['invoiceList'] = $invoiceList;
  1696. $this->data ['ilist'] = $ilist;
  1697. $this->data ['memu'] = "invoice";
  1698. $this->data ['staff'] = $this->staff;
  1699. $this->data ['receiptMemu'] = 'invoiceApproval';
  1700. $this->render ( "/admin/invoiceApproval", $this->data );
  1701. }
  1702. function invoiceDetail() {
  1703. Doo::loadClass ( 'XDeode' );
  1704. $XDeode = new XDeode ( 5 );
  1705. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  1706. $iid = $XDeode->decode ( $iid );
  1707. if (! is_numeric ( $iid ))
  1708. die ( 'illegal request' );
  1709. Doo::loadModel ( 'invoice' );
  1710. $invoice = new invoice ();
  1711. Doo::loadModel ( 'invoiceOperationLog' );
  1712. $invoiceOperationLog = new invoiceOperationLog ();
  1713. $invoiceDetail = $invoice->getOne ( array (
  1714. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'] . ' and iid=' . $iid,
  1715. 'asArray' => true
  1716. ) );
  1717. if (empty ( $invoiceDetail ))
  1718. die ( 'illegal request' );
  1719. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  1720. $this->data ['invoiceDetail'] = $invoiceDetail;
  1721. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  1722. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  1723. $this->data ['memu'] = "invoice";
  1724. $this->data ['staff'] = $this->staff;
  1725. $this->data ['receiptMemu'] = 'invoiceApproval';
  1726. $this->render ( "/admin/invoiceApprovalDetail", $this->data );
  1727. }
  1728. /**
  1729. * 对发票进行审批,其中操作有终止,退回,同意动作。操作成功并记录下操作日志
  1730. *
  1731. * @since 1.0.0
  1732. * @var integer iid 开票ID 已加密
  1733. * @var integer status 发票审批状态
  1734. * @var integer opintion 审批发票的意见
  1735. * @return string 如操作成功返回审批首页
  1736. */
  1737. function invoiceApprovalDo() {
  1738. Doo::loadModel ( 'invoice' );
  1739. $invoice = new invoice ();
  1740. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  1741. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  1742. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  1743. $iid = $invoice->authcode ( $iid );
  1744. if (! is_numeric ( $iid ))
  1745. die ( 'illegal request' );
  1746. // && ! empty ( $opinion )
  1747. if (! empty ( $iid ) && ! empty ( $status )) {
  1748. if (! ($status == 2 || $status == 3 || $status == 4))
  1749. die ( 'illegal request' );
  1750. Doo::loadModel ( 'invoiceOperationLog' );
  1751. $invoiceOperationLog = new invoiceOperationLog ();
  1752. $invoiceDetail = $invoice->getOne ( array (
  1753. 'where' => 'status=1 and iid=' . $iid . ' and pendingApprovals=' . $this->staff [0] ['sid'],
  1754. 'asArray' => true
  1755. ) );
  1756. if (empty ( $invoiceDetail ))
  1757. die ( 'illegal request' );
  1758. $processApprovals = json_decode ( $invoiceDetail ['processApprovals'], true );
  1759. $invoiceManage = json_decode ( $invoiceDetail ['invoiceManage'], true );
  1760. if ($status == 3) {
  1761. $invoice->status = $status;
  1762. $item = array (
  1763. 'operation' => $opinion
  1764. );
  1765. } else {
  1766. if (empty ( $processApprovals )) {
  1767. $processApprovals = array (
  1768. $this->staff [0] ['sid'] => array (
  1769. 'date' => date ( "Y-m-d H:i:s" ),
  1770. 'opinion' => $opinion,
  1771. 'status' => $status
  1772. )
  1773. );
  1774. // var_dump(next($invoiceManage));
  1775. $nextInvoiceManage = next ( $invoiceManage );
  1776. // print_r($nextInvoiceManage);
  1777. if ($status != 4 && $nextInvoiceManage !== false)
  1778. $invoice->pendingApprovals = $nextInvoiceManage [0];
  1779. $invoice->processApprovals = json_encode ( $processApprovals );
  1780. // var_dump($invoice);
  1781. // print_r($invoiceManage);
  1782. } else {
  1783. $processApprovals [$this->staff [0] ['sid']] = array (
  1784. 'date' => date ( "Y-m-d H:i:s" ),
  1785. 'opinion' => $opinion,
  1786. 'status' => $status
  1787. );
  1788. $pendingApprovals = 0;
  1789. foreach ( $invoiceManage as $key => $value ) {
  1790. if ($value [0] == $this->staff [0] ['sid']) {
  1791. if (isset ( $invoiceManage [$key + 1] ))
  1792. $pendingApprovals = $invoiceManage [$key + 1] [0];
  1793. break;
  1794. }
  1795. }
  1796. if ($status != 4 && ! empty ( $pendingApprovals ))
  1797. $invoice->pendingApprovals = $pendingApprovals;
  1798. $invoice->processApprovals = json_encode ( $processApprovals );
  1799. }
  1800. $item = array (
  1801. 'operation' => $opinion
  1802. );
  1803. if (count ( $processApprovals ) == count ( $invoiceManage ) && $status != 4) {
  1804. $invoice->status = $status;
  1805. $invoice->pendingApprovals = 0;
  1806. $invoice->approvalTime = date ( "Y-m-d H:i:s" );
  1807. } elseif ($status == 4) {
  1808. $invoice->status = $status;
  1809. $item = array (
  1810. 'operation' => $opinion
  1811. );
  1812. }
  1813. }
  1814. $invoice->updateTime = date ( "Y-m-d H:i:s" );
  1815. $invoice->update ( array (
  1816. 'where' => 'iid=' . $iid
  1817. ) );
  1818. $item += array (
  1819. 'date' => date ( "Y-m-d H:i:s" ),
  1820. 'img' => $this->staff [0] ['avatar'],
  1821. 'username' => $this->staff [0] ['username'],
  1822. 'uid' => $this->staff [0] ['sid'],
  1823. 'category' => $this->staff [0] ['category'],
  1824. 'status' => $status,
  1825. 'iid' => $iid
  1826. );
  1827. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1828. return '/invoiceApproval';
  1829. }
  1830. die ( 'illegal request' );
  1831. }
  1832. /**
  1833. * 展示需要打印的发票数据
  1834. *
  1835. * @since 1.0.0
  1836. */
  1837. function invoicePrint() {
  1838. Doo::loadModel ( 'invoice' );
  1839. $invoice = new invoice ();
  1840. Doo::loadClass ( 'XDeode' );
  1841. $XDeode = new XDeode ( 5 );
  1842. Doo::loadModel ( 'staff' );
  1843. $staff = new staff ();
  1844. $toPrint = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0 );
  1845. $printed = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 1 );
  1846. foreach ( $toPrint as $key => $value ) {
  1847. $toPrint [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1848. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1849. if (! empty ( $lastApprover )) {
  1850. $lastApproverKey = array_keys ( $lastApprover );
  1851. $lastApprover = end ( $lastApprover );
  1852. $staffDetail = $staff->getOne ( array (
  1853. 'where' => 'sid=' . end ( $lastApproverKey ),
  1854. 'asArray' => true
  1855. ) );
  1856. $lastApprover ['username'] = $staffDetail ['username'];
  1857. }
  1858. $toPrint [$key] ['lastApprover'] = $lastApprover;
  1859. }
  1860. foreach ( $printed as $key => $value ) {
  1861. $printed [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1862. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1863. if (! empty ( $lastApprover )) {
  1864. $lastApproverKey = array_keys ( $lastApprover );
  1865. $lastApprover = end ( $lastApprover );
  1866. $staffDetail = $staff->getOne ( array (
  1867. 'where' => 'sid=' . end ( $lastApproverKey ),
  1868. 'asArray' => true
  1869. ) );
  1870. $lastApprover ['username'] = $staffDetail ['username'];
  1871. }
  1872. $printed [$key] ['lastApprover'] = $lastApprover;
  1873. }
  1874. $this->data ['printed'] = $printed;
  1875. $this->data ['toPrint'] = $toPrint;
  1876. $this->data ['memu'] = "invoice";
  1877. $this->data ['staff'] = $this->staff;
  1878. $this->data ['receiptMemu'] = 'invoicePrint';
  1879. $this->render ( "/admin/invoicePrint", $this->data );
  1880. }
  1881. /**
  1882. * 展示发票打印的详情页面
  1883. *
  1884. * @since 1.0.0
  1885. */
  1886. function invoicePrintDetail() {
  1887. Doo::loadClass ( 'XDeode' );
  1888. $XDeode = new XDeode ( 5 );
  1889. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  1890. $iid = $XDeode->decode ( $iid );
  1891. if (! is_numeric ( $iid ))
  1892. die ( 'illegal request' );
  1893. Doo::loadModel ( 'invoice' );
  1894. $invoice = new invoice ();
  1895. Doo::loadModel ( 'invoiceOperationLog' );
  1896. $invoiceOperationLog = new invoiceOperationLog ();
  1897. $invoiceDetail = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0, $iid );
  1898. if (empty ( $invoiceDetail ))
  1899. die ( 'illegal request' );
  1900. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  1901. $this->data ['invoiceDetail'] = $invoiceDetail;
  1902. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  1903. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  1904. $this->data ['memu'] = "invoice";
  1905. $this->data ['staff'] = $this->staff;
  1906. $this->data ['receiptMemu'] = 'invoicePrint';
  1907. $this->render ( "/admin/invoicePrintDetail", $this->data );
  1908. }
  1909. /**
  1910. * 所有待打印 发票
  1911. */
  1912. function invoicePrintStayAchieve() {
  1913. Doo::loadModel ( 'invoice' );
  1914. $invoice = new invoice ();
  1915. Doo::loadClass ( 'XDeode' );
  1916. $XDeode = new XDeode ( 5 );
  1917. Doo::loadModel ( 'staff' );
  1918. $staff = new staff ();
  1919. $MebSea = $this->get_args ( 'MebSea' ) ? urldecode ( $this->get_args ( 'MebSea' ) ) : "";
  1920. $page_size = 12;
  1921. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  1922. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : "ALL";
  1923. // $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : "ALL";
  1924. $get = "/" . $status;
  1925. $con = ' and status=2 ';
  1926. if ($status == 'TOPRINT')
  1927. $con = ' and status=2 and printStatus=0 ';
  1928. elseif ($status == 'PRINTED')
  1929. $con = ' and status=2 and printStatus=1';
  1930. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  1931. $dateArr = explode ( ':', $date );
  1932. $D1 = '';
  1933. $D2 = '';
  1934. if (! empty ( $date )) {
  1935. $D1 = $dateArr [0];
  1936. $D2 = $dateArr [1];
  1937. }
  1938. if (! empty ( $D1 ) && ! empty ( $D2 ) && ! empty ( $date ))
  1939. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  1940. if (! empty ( $MebSea )) {
  1941. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  1942. }
  1943. $pageinfo ['page'] = array (
  1944. 'previous' => ''
  1945. );
  1946. $get .= "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  1947. $sql = " (untreadStatus=0 or untreadStatus=3) and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  1948. $action = "invoicePrintStayAchieve";
  1949. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  1950. $limit = $pageinfo ['lower'] . ',' . $page_size;
  1951. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  1952. $this->data ['MebSeaEn'] = $MebSea;
  1953. $this->data ['MebSea'] = urlencode ( $MebSea );
  1954. $this->data ['get'] = $get;
  1955. $this->data ['page'] = $pageinfo;
  1956. $this->data ['date'] = $date;
  1957. $this->data ['status'] = $status;
  1958. $this->data ['memu'] = "invoice";
  1959. $this->data ['staff'] = $this->staff;
  1960. foreach ( $list as $key => $value ) {
  1961. $list [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1962. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1963. if (! empty ( $lastApprover )) {
  1964. $lastApproverKey = array_keys ( $lastApprover );
  1965. $lastApprover = end ( $lastApprover );
  1966. $staffDetail = $staff->getOne ( array (
  1967. 'where' => 'sid=' . end ( $lastApproverKey ),
  1968. 'asArray' => true
  1969. ) );
  1970. $lastApprover ['username'] = $staffDetail ['username'];
  1971. }
  1972. $list [$key] ['lastApprover'] = $lastApprover;
  1973. }
  1974. $this->data ['receiptMemu'] = 'invoicePrint';
  1975. $this->data ['list'] = $list;
  1976. $this->render ( "/admin/invoicePrintStayAchieve", $this->data );
  1977. }
  1978. /**
  1979. * 填写票号并完成打印
  1980. * @since 1.0.0
  1981. */
  1982. function invoicePrintDo() {
  1983. Doo::loadModel ( 'invoice' );
  1984. $invoice = new invoice ();
  1985. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  1986. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  1987. $iid = $invoice->authcode ( $iid );
  1988. if (! is_numeric ( $iid ))
  1989. die ( 'illegal request' );
  1990. if (! empty ( $iid ) && ! empty ( $invoiceNo )) {
  1991. Doo::loadModel ( 'invoiceOperationLog' );
  1992. $invoiceOperationLog = new invoiceOperationLog ();
  1993. Doo::loadModel ( 'invoiceStatistics' );
  1994. $invoiceStatistics = new invoiceStatistics ();
  1995. // $info=$invoice->getOne(array('where'=>"invoiceNo = '".$invoiceNo."'",'asArray' => TRUE));
  1996. $invoicePrintDetail = $invoice->getInvoiceByPrint ( $iid );
  1997. if (empty ( $invoicePrintDetail ))
  1998. die ( 'illegal request' );
  1999. $item = array (
  2000. 'iid' => $iid,
  2001. 'printStatus' => 1,
  2002. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2003. 'printer' => $this->staff [0] ['username'],
  2004. 'printTime' => date ( "Y-m-d H:i:s" ),
  2005. 'invoiceNo' => $invoiceNo
  2006. );
  2007. $invoice->setInvoiceByCondition ( $item );
  2008. $item = array (
  2009. 'date' => date ( "Y-m-d H:i:s" ),
  2010. 'operation' => '打印发票号:' . $invoiceNo,
  2011. 'status' => 5,
  2012. 'img' => $this->staff [0] ['avatar'],
  2013. 'username' => $this->staff [0] ['username'],
  2014. 'uid' => $this->staff [0] ['sid'],
  2015. 'category' => $this->staff [0] ['category'],
  2016. 'iid' => $iid
  2017. );
  2018. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2019. // 去统计--负票不汇总
  2020. if ($invoicePrintDetail ['untreadStatus'] != 4) {
  2021. $item = array (
  2022. 'date' => date ( "Y-m-d H:i:s" ),
  2023. 'priceClass' => 1,
  2024. 'cid' => $invoicePrintDetail ['cid'],
  2025. 'staff' => $invoicePrintDetail ['sid'],
  2026. 'invoicePrice' => $invoicePrintDetail ['invoicePrice']
  2027. );
  2028. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2029. }
  2030. // 发送通知信息到微信-去除
  2031. // $this->setWXMsg($iid,'PRINT');
  2032. // 申请人获取微信通知
  2033. Doo::loadModel ( 'staff' );
  2034. $staff = new staff ();
  2035. Doo::loadClass ( 'XDeode' );
  2036. $XDeode = new XDeode ( 5 );
  2037. $username2 = $staff->getOne ( array (
  2038. 'select' => 'wxid',
  2039. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2040. 'asArray' => TRUE
  2041. ) );
  2042. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '完成打印';
  2043. $msg = '';
  2044. $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/' . $XDeode->encode ( $invoicePrintDetail ['iid'] ) . '.html';
  2045. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2046. return "/invoicePrint";
  2047. }
  2048. }
  2049. /**
  2050. * 需要邮寄的发票
  2051. * @since 1.0.0
  2052. */
  2053. function invoicePost() {
  2054. Doo::loadModel ( 'invoice' );
  2055. $invoice = new invoice ();
  2056. Doo::loadModel ( 'express' );
  2057. $express = new express ();
  2058. $invoicePost = $invoice->getPostByInvoice ();
  2059. $invoicePosted = $invoice->getPostByInvoice ( 1 );
  2060. $expressList = $express->getExpressByAll ();
  2061. $this->data ['expressList'] = $expressList;
  2062. $this->data ['invoicePost'] = $invoicePost;
  2063. $this->data ['invoicePosted'] = $invoicePosted;
  2064. $this->data ['memu'] = "invoice";
  2065. $this->data ['staff'] = $this->staff;
  2066. $this->data ['receiptMemu'] = 'invoicePost';
  2067. $this->render ( "/admin/invoicePost", $this->data );
  2068. }
  2069. /**
  2070. * 添加发票邮寄信息
  2071. */
  2072. function invoiceExpressAddDo() {
  2073. Doo::loadModel ( 'invoice' );
  2074. $invoice = new invoice ();
  2075. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2076. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2077. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2078. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2079. $iid = $iid = $invoice->authcode ( $iid );
  2080. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2081. die ( 'illegal request' );
  2082. $invoicePrintDetail = $invoice->getInvoiceByIid ( $iid );
  2083. $item = array (
  2084. 'iid' => $iid,
  2085. 'postStatus' => 1,
  2086. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2087. 'postTime' => date ( "Y-m-d H:i:s" ),
  2088. 'expressCompany' => $expressCompany,
  2089. 'expressNumber' => $expressNumber,
  2090. 'actualItems' => $actualItems,
  2091. 'poster' => $this->staff [0] ['username']
  2092. );
  2093. $invoice->setInvoiceByCondition ( $item );
  2094. // 微信通知-去掉
  2095. // $this->setWXMsg ( $iid );
  2096. Doo::loadModel ( 'staff' );
  2097. $staff = new staff ();
  2098. Doo::loadClass ( 'XDeode' );
  2099. $XDeode = new XDeode ( 5 );
  2100. $username2 = $staff->getOne ( array (
  2101. 'select' => 'wxid',
  2102. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2103. 'asArray' => TRUE
  2104. ) );
  2105. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '已邮寄';
  2106. $expCom = explode ( ":", $invoicePrintDetail ['expressCompany'] );
  2107. if (empty ( $expCom ))
  2108. $expCom [0] = '';
  2109. $msg = $expCom [0] . ':' . $invoicePrintDetail ['expressNumber'] . '';
  2110. $url = 'https://m.kuaidi100.com/result.jsp?nu=' . $invoicePrintDetail ['expressNumber'];
  2111. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2112. return '/invoicePost';
  2113. }
  2114. function invoiceExpressUpdateDo() {
  2115. Doo::loadModel ( 'invoice' );
  2116. $invoice = new invoice ();
  2117. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  2118. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2119. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2120. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2121. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2122. $iid = $invoice->authcode ( $iid );
  2123. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2124. die ( 'illegal request' );
  2125. $item = array (
  2126. 'iid' => $iid,
  2127. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2128. 'expressCompany' => $expressCompany,
  2129. 'expressNumber' => $expressNumber,
  2130. 'actualItems' => $actualItems,
  2131. 'poster' => $this->staff [0] ['username']
  2132. );
  2133. $invoice->setInvoiceByCondition ( $item );
  2134. return $action;
  2135. }
  2136. /**
  2137. * 可退票管理
  2138. */
  2139. function invoiceUntreadIsAchieve() {
  2140. Doo::loadModel ( 'invoice' );
  2141. $invoice = new invoice ();
  2142. Doo::loadClass ( 'XDeode' );
  2143. $XDeode = new XDeode ( 5 );
  2144. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2145. $page_size = 18;
  2146. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2147. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2148. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  2149. $dateArr = explode ( ':', $date );
  2150. $D1 = '';
  2151. $D2 = '';
  2152. if (! empty ( $date )) {
  2153. $D1 = $dateArr [0];
  2154. $D2 = $dateArr [1];
  2155. }
  2156. $con = '';
  2157. if (! empty ( $D1 ) && ! empty ( $D2 ))
  2158. $con = ' and bindTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2159. // if ($date == 'MONTHO')
  2160. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  2161. // elseif ($date == 'MONTHT')
  2162. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  2163. // elseif ($date == 'MONTHY')
  2164. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  2165. if (! empty ( $MebSea )) {
  2166. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  2167. }
  2168. $pageinfo ['page'] = array (
  2169. 'previous' => ''
  2170. );
  2171. // printStatus=1 and
  2172. $sql = " (untreadStatus=0 or untreadStatus=3) and status=2 and sid=" . $this->staff [0] ['sid'] . $con;
  2173. $action = "invoiceUntreadIsAchieve";
  2174. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2175. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2176. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2177. // print_r($list);
  2178. $this->data ['MebSeaEn'] = $MebSea;
  2179. // $this->data ['MebSea'] = urlencode ( $MebSea );
  2180. $this->data ['get'] = $get;
  2181. $this->data ['page'] = $pageinfo;
  2182. $this->data ['date'] = $date;
  2183. $this->data ['list'] = $list;
  2184. $this->data ['memu'] = "invoice";
  2185. $this->data ['staff'] = $this->staff;
  2186. $this->data ['receiptMemu'] = 'invoice';
  2187. $this->render ( "/admin/invoiceUntreadIsAchieve", $this->data );
  2188. }
  2189. /**
  2190. * 退票处理页面
  2191. */
  2192. function invoiceUntread() {
  2193. Doo::loadModel ( 'invoice' );
  2194. $invoice = new invoice ();
  2195. $untreadInvoice = $invoice->getInvoiceByUntreadStatus ( 1 );
  2196. $establishedInvoice = $invoice->getInvoiceByUntreadStatus ( 2 );
  2197. foreach ( $establishedInvoice as $key => $value ) {
  2198. // months
  2199. $lossDate = strtotime ( "+1 month", strtotime ( $value ['OperationLog'] ['date'] ) );
  2200. $nowDate = strtotime ( 'now' );
  2201. $establishedInvoice [$key] ['lossShow'] = false;
  2202. if ($lossDate < $nowDate)
  2203. $establishedInvoice [$key] ['lossShow'] = true;
  2204. }
  2205. $this->data ['untreadInvoice'] = $untreadInvoice;
  2206. $this->data ['establishedInvoice'] = $establishedInvoice;
  2207. $this->data ['memu'] = "invoice";
  2208. $this->data ['staff'] = $this->staff;
  2209. $this->data ['receiptMemu'] = 'invoiceUntread';
  2210. $this->render ( "/admin/invoiceUntread", $this->data );
  2211. }
  2212. /**
  2213. * 确认收到退回的发票,开票状态为退回 //收款状态解绑,公司统计扣除入账额度
  2214. */
  2215. function invoiceUntreadEstablishedDo() {
  2216. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  2217. Doo::loadModel ( 'invoice' );
  2218. $invoice = new invoice ();
  2219. Doo::loadModel ( 'invoiceOperationLog' );
  2220. $invoiceOperationLog = new invoiceOperationLog ();
  2221. Doo::loadModel ( 'invoiceReceivables' );
  2222. Doo::loadModel ( 'invoiceStatistics' );
  2223. $iid = $invoice->authcode ( $untreadIidKey );
  2224. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2225. die ( 'illegal request' );
  2226. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  2227. if ($invoiceDetails ['untreadStatus'] != 1)
  2228. die ( 'illegal request' );
  2229. $item = array (
  2230. 'iid' => $iid,
  2231. // 'irid'=>'',
  2232. 'untreadStatus' => 2,
  2233. 'updateTime' => date ( "Y-m-d H:i:s" )
  2234. );
  2235. $invoice->setInvoiceByCondition ( $item );
  2236. $item = array (
  2237. 'date' => date ( "Y-m-d H:i:s" ),
  2238. 'operation' => '已确认退票',
  2239. 'status' => 6,
  2240. 'img' => $this->staff [0] ['avatar'],
  2241. 'username' => $this->staff [0] ['username'],
  2242. 'uid' => $this->staff [0] ['sid'],
  2243. 'category' => $this->staff [0] ['category'],
  2244. 'iid' => $iid
  2245. );
  2246. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2247. // 收款解绑以及入账扣除 收款扣除
  2248. if (! empty ( $invoiceDetails ['irid'] )) {
  2249. $iridList = explode ( ',', $invoiceDetails ['irid'] );
  2250. foreach ( $iridList as $value ) {
  2251. $invoiceReceivables = new invoiceReceivables ();
  2252. $irDetails = $invoiceReceivables->getOne ( array (
  2253. 'where' => " irid=" . $value . ' and bindStatus=1',
  2254. 'asArray' => TRUE
  2255. ) );
  2256. $item = array (
  2257. 'irid' => $value,
  2258. 'bindStatus' => 0,
  2259. 'untreadStatus' => 1,
  2260. 'untreadStaff' => $invoiceDetails ['userName'],
  2261. 'unbundlingTime' => date ( "Y-m-d H:i:s" ),
  2262. 'iid' => 0
  2263. );
  2264. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2265. if (! empty ( $irDetails )) {
  2266. // 扣除入账
  2267. $invoiceStatistics = new invoiceStatistics ();
  2268. $item = array (
  2269. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2270. 'priceClass' => 3,
  2271. 'cid' => $invoiceDetails ['cid'],
  2272. 'staff' => $invoiceDetails ['sid'],
  2273. 'accountPrice' => - $irDetails ['receivablesPrice']
  2274. );
  2275. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2276. // 扣除收款
  2277. $invoiceStatistics = new invoiceStatistics ();
  2278. $item = array (
  2279. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2280. 'priceClass' => 2,
  2281. 'cid' => $invoiceDetails ['cid'],
  2282. 'staff' => $invoiceDetails ['sid'],
  2283. 'irid' => $irDetails ['irid'],
  2284. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  2285. );
  2286. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2287. }
  2288. }
  2289. }
  2290. return "/invoiceUntread";
  2291. }
  2292. /**
  2293. * 建立负票,关联原来发票
  2294. */
  2295. function invoiceLossDo() {
  2296. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2297. if (! empty ( $iidKey )) {
  2298. Doo::loadClass ( 'XDeode' );
  2299. $XDeode = new XDeode ( 5 );
  2300. Doo::loadModel ( 'invoice' );
  2301. $invoice = new invoice ();
  2302. Doo::loadModel ( 'invoiceOperationLog' );
  2303. $invoiceOperationLog = new invoiceOperationLog ();
  2304. $iidKey = $XDeode->decode ( $iidKey );
  2305. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  2306. // 拷贝插入一条发票数据
  2307. $iid = $invoice->setInvoiceLoss ( $iidKey );
  2308. // 更新负票
  2309. $invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  2310. $invoice = new invoice ();
  2311. $item = array (
  2312. 'iid' => $iid,
  2313. 'sid' => $this->staff [0] ['sid'],
  2314. 'userName' => $this->staff [0] ['username'],
  2315. 'cid' => $this->staff [0] ['cid'],
  2316. 'categoryName' => $this->staff [0] ['category'],
  2317. 'invoiceQuantity' => - $invoiceDetail ['invoiceQuantity'],
  2318. 'invoicePrice' => - $invoiceDetail ['invoicePrice'],
  2319. 'invoiceSerial' => $invoiceSerial,
  2320. 'invoiceNo' => '',
  2321. 'printStatus' => 0,
  2322. 'untreadStatus' => 4,
  2323. // 关联发票号
  2324. 'lossIid' => $invoiceDetail ['iid']
  2325. );
  2326. $invoice->setInvoiceByCondition ( $item );
  2327. // 更新原发票
  2328. $invoice = new invoice ();
  2329. $item = array (
  2330. 'iid' => $invoiceDetail ['iid'],
  2331. 'lossIid' => $iid
  2332. );
  2333. $invoice->setInvoiceByCondition ( $item );
  2334. // 操作日志
  2335. $item = array (
  2336. 'date' => date ( "Y-m-d H:i:s" ),
  2337. 'operation' => "创建负票" . $invoiceSerial,
  2338. 'status' => 12,
  2339. 'img' => $this->staff [0] ['avatar'],
  2340. 'username' => $this->staff [0] ['username'],
  2341. 'uid' => $this->staff [0] ['sid'],
  2342. 'category' => $this->staff [0] ['category'],
  2343. 'iid' => $iid
  2344. );
  2345. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2346. // print_r($invoiceDetail);
  2347. // echo $iid;die;
  2348. }
  2349. return '/invoiceUntread';
  2350. }
  2351. function invoiceReceivables() {
  2352. $invoiceTC = $this->get_args ( 'invoiceTC' ) ? $this->get_args ( 'invoiceTC' ) : '';
  2353. Doo::loadModel ( 'L_category' );
  2354. $lCategory = new L_category ();
  2355. Doo::loadModel ( 'staff' );
  2356. $staff = new staff ();
  2357. Doo::loadModel ( 'invoiceReceivables' );
  2358. $invoiceReceivables = new invoiceReceivables ();
  2359. Doo::loadModel ( 'invoice' );
  2360. $invoice = new invoice ();
  2361. Doo::loadClass ( 'XDeode' );
  2362. $XDeode = new XDeode ( 5 );
  2363. $category = $lCategory->getCategory ();
  2364. $staffList = $staff->getStaffByCid ( $this->staff [0] ['cid'] );
  2365. $sql = 'bindStatus=1 and iid!=0';
  2366. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByNew ( 4, $sql );
  2367. // 获取未入账发票
  2368. $invoiceUnAccount = $invoice->getInvoiceByUnAccount ( $invoiceTC );
  2369. $invoiceExistAccount = $invoice->getInvoiceByUnAccount ( '', true );
  2370. foreach ( $invoiceUnAccount as $key => $value ) {
  2371. $invoiceUnAccount [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2372. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2373. if (! empty ( $lastApprover )) {
  2374. $lastApproverKey = array_keys ( $lastApprover );
  2375. $lastApprover = end ( $lastApprover );
  2376. $staffDetail = $staff->getOne ( array (
  2377. 'where' => 'sid=' . end ( $lastApproverKey ),
  2378. 'asArray' => true
  2379. ) );
  2380. $lastApprover ['username'] = $staffDetail ['username'];
  2381. }
  2382. $invoiceUnAccount [$key] ['lastApprover'] = $lastApprover;
  2383. }
  2384. foreach ( $invoiceExistAccount as $key => $value ) {
  2385. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  2386. if (empty ( $irList ))
  2387. $irList [0] ['sumPrice'] = 0;
  2388. $balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  2389. $invoiceExistAccount [$key] ['existAccount'] = $irList [0] ['sumPrice'];
  2390. $invoiceExistAccount [$key] ['balance'] = $balance;
  2391. }
  2392. $receivablesInput = $invoiceReceivables->getInvoiceReceivablesByInput ();
  2393. $halfList = $invoiceReceivables->getInvoiceReceivablesByHalf ();
  2394. $this->data ['halfList'] = $halfList;
  2395. $this->data ['halfCount'] = count ( $halfList );
  2396. // print_r($receivablesList);
  2397. $this->data ['receivablesDate'] = date ( "Y-m-d" );
  2398. $this->data ['ieaCount'] = count ( $invoiceExistAccount );
  2399. $this->data ['invoiceExistAccount'] = $invoiceExistAccount;
  2400. $this->data ['receivablesInput'] = $receivablesInput;
  2401. $this->data ['year'] = date ( 'Y' );
  2402. $this->data ['invoiceUnAccount'] = $invoiceUnAccount;
  2403. $this->data ['receivablesList'] = $receivablesList;
  2404. $this->data ['staffList'] = $staffList;
  2405. $this->data ['category'] = $category;
  2406. $this->data ['memu'] = "invoice";
  2407. $this->data ['staff'] = $this->staff;
  2408. $this->data ['receiptMemu'] = 'invoiceReceivables';
  2409. $this->render ( "/admin/invoiceReceivables", $this->data );
  2410. }
  2411. /**
  2412. * 新添加收款直接入账发票
  2413. */
  2414. function invoiceCompareClaimPrice() {
  2415. // 收款录入
  2416. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2417. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  2418. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  2419. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  2420. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  2421. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $iidKey )) {
  2422. Doo::loadModel ( 'invoiceReceivables' );
  2423. $invoiceReceivables = new invoiceReceivables ();
  2424. Doo::loadModel ( 'invoiceROLog' );
  2425. $invoiceROLog = new invoiceROLog ();
  2426. Doo::loadModel ( 'invoiceStatistics' );
  2427. Doo::loadModel ( 'invoice' );
  2428. $invoice = new invoice ();
  2429. Doo::loadClass ( 'XDeode' );
  2430. $XDeode = new XDeode ( 5 );
  2431. Doo::loadModel ( 'invoiceOperationLog' );
  2432. $invoiceOperationLog = new invoiceOperationLog ();
  2433. $iidKey = $XDeode->decode ( $iidKey );
  2434. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  2435. if (! ($invoiceDetail ['status'] == 2 && $invoiceDetail ['printStatus'] == 1 && $invoiceDetail ['untreadStatus'] == 0))
  2436. die ( 'illegal request' );
  2437. $receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  2438. // 收款录入 并绑定发票
  2439. Doo::db ()->beginTransaction ();
  2440. $bindStatus = 0;
  2441. if ($receivablesPrice <= $invoiceDetail ['invoicePrice'])
  2442. $bindStatus = 1;
  2443. $item = array (
  2444. 'bindStatus' => $bindStatus,
  2445. 'iid' => $invoiceDetail ['iid'],
  2446. 'bindPrice' => $invoiceDetail ['invoicePrice'],
  2447. 'bindDate' => date ( "Y-m-d H:i:s" ),
  2448. 'receivablesPrice' => $receivablesPrice,
  2449. 'receivablesMessage' => $receivablesMessage,
  2450. 'receivablesSerial' => $receivablesSerial,
  2451. 'receivablesBank' => $receivablesBank,
  2452. 'receivablesDate' => $receivablesDate,
  2453. 'inputStaff' => $this->staff [0] ['username'],
  2454. 'accountClerk' => $this->staff [0] ['username'],
  2455. 'date' => date ( "Y-m-d" ),
  2456. 'receivablesCategory' => $invoiceDetail ['cid'] . ':' . $invoiceDetail ['categoryName'],
  2457. 'receivablesStaff' => $invoiceDetail ['sid'] . '-' . $invoiceDetail ['userName'],
  2458. 'confirmTime' => date ( "Y-m-d H:i:s" )
  2459. );
  2460. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  2461. $item = array ();
  2462. // 收款操作日志
  2463. $item = array (
  2464. 'operation' => $this->staff [0] ['username'] . " 转入 " . $invoiceDetail ['userName']
  2465. );
  2466. $item += array (
  2467. 'date' => date ( "Y-m-d" ),
  2468. 'status' => 1,
  2469. 'img' => $this->staff [0] ['avatar'],
  2470. 'username' => $this->staff [0] ['username'],
  2471. 'uid' => $this->staff [0] ['sid'],
  2472. 'category' => $this->staff [0] ['category'],
  2473. 'irid' => $irid
  2474. );
  2475. $invoiceROLog->setInvoiceROLog ( $item );
  2476. // 收款统计
  2477. $invoiceStatistics = new invoiceStatistics ();
  2478. $item = array (
  2479. 'date' => $receivablesDate,
  2480. 'priceClass' => 2,
  2481. 'irid' => $irid,
  2482. 'cid' => $invoiceDetail ['cid'],
  2483. 'staff' => $invoiceDetail ['sid'],
  2484. 'receivablesPrice' => $receivablesPrice
  2485. );
  2486. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2487. // 收款 入 发票
  2488. $detail = $invoiceDetail;
  2489. $iridString = "";
  2490. if (empty ( $detail ['irid'] ))
  2491. $iridString = $irid;
  2492. else
  2493. $iridString = $detail ['irid'] . ',' . $irid;
  2494. $item = array (
  2495. 'irid' => $iridString,
  2496. 'bindTime' => date ( "Y-m-d H:i:s" ),
  2497. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2498. 'iid' => $detail ['iid']
  2499. );
  2500. $invoiceReceivables = new invoiceReceivables ();
  2501. $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  2502. if ($detail ['invoicePrice'] <= $sum)
  2503. $item += array (
  2504. 'untreadStatus' => 3
  2505. );
  2506. $invoice->setInvoiceByCondition ( $item );
  2507. // 操作日志
  2508. $item = array (
  2509. 'date' => date ( "Y-m-d H:i:s" ),
  2510. 'operation' => "收款入账" . $receivablesSerial . "到发票" . $detail ['invoiceSerial'],
  2511. 'status' => 8,
  2512. 'img' => $this->staff [0] ['avatar'],
  2513. 'username' => $this->staff [0] ['username'],
  2514. 'uid' => $this->staff [0] ['sid'],
  2515. 'category' => $this->staff [0] ['category'],
  2516. 'iid' => $detail ['iid']
  2517. );
  2518. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2519. // 入账汇总
  2520. $invoiceStatistics = new invoiceStatistics ();
  2521. // $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $iridString );
  2522. // $accountPrice = 0;
  2523. // foreach ( $list as $key => $value ) {
  2524. // $accountPrice += $value ['receivablesPrice'];
  2525. // }
  2526. $item = array (
  2527. 'date' => $receivablesDate,
  2528. 'priceClass' => 3,
  2529. 'cid' => $invoiceDetail ['cid'],
  2530. 'staff' => $invoiceDetail ['sid'],
  2531. 'accountPrice' => $receivablesPrice
  2532. );
  2533. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2534. Doo::db ()->commit ();
  2535. }
  2536. return '/invoiceReceivables';
  2537. }
  2538. /**
  2539. * 检索未入账发票数据 function sir() { }
  2540. */
  2541. /**
  2542. * 录入收款数据
  2543. * @return string
  2544. */
  2545. function invoiceReceivablesDo() {
  2546. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  2547. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  2548. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  2549. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  2550. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  2551. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  2552. Doo::loadModel ( 'invoiceReceivables' );
  2553. $invoiceReceivables = new invoiceReceivables ();
  2554. Doo::loadModel ( 'invoiceROLog' );
  2555. $invoiceROLog = new invoiceROLog ();
  2556. Doo::loadModel ( 'invoiceStatistics' );
  2557. $invoiceStatistics = new invoiceStatistics ();
  2558. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $receivablesCategory ) && ! empty ( $receivablesStaff )) {
  2559. $item = array (
  2560. 'receivablesPrice' => $receivablesPrice,
  2561. 'receivablesMessage' => $receivablesMessage,
  2562. 'receivablesSerial' => "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  2563. 'receivablesBank' => $receivablesBank,
  2564. 'receivablesDate' => $receivablesDate,
  2565. 'inputStaff' => $this->staff [0] ['username'],
  2566. 'date' => date ( "Y-m-d" ),
  2567. 'receivablesCategory' => $receivablesCategory,
  2568. 'receivablesStaff' => $receivablesStaff
  2569. );
  2570. if ($receivablesCategory != 'PUBLIC') {
  2571. $item += array (
  2572. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  2573. 'inputType' => 1
  2574. );
  2575. }
  2576. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  2577. $item = array ();
  2578. // 收款操作日志
  2579. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  2580. $item = array (
  2581. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  2582. );
  2583. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  2584. $item = array (
  2585. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  2586. );
  2587. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  2588. $receivablesStaff = explode ( '-', $receivablesStaff );
  2589. $item = array (
  2590. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  2591. );
  2592. }
  2593. $item += array (
  2594. 'date' => date ( "Y-m-d" ),
  2595. 'status' => 1,
  2596. 'img' => $this->staff [0] ['avatar'],
  2597. 'username' => $this->staff [0] ['username'],
  2598. 'uid' => $this->staff [0] ['sid'],
  2599. 'category' => $this->staff [0] ['category'],
  2600. 'irid' => $irid
  2601. );
  2602. $invoiceROLog->setInvoiceROLog ( $item );
  2603. $item = array (
  2604. 'date' => $receivablesDate,
  2605. 'priceClass' => 2,
  2606. 'irid' => $irid,
  2607. 'receivablesPrice' => $receivablesPrice
  2608. );
  2609. if ($receivablesCategory != 'PUBLIC') {
  2610. $receivablesCategory = explode ( ":", $receivablesCategory );
  2611. $item += array (
  2612. 'cid' => $receivablesCategory [0]
  2613. );
  2614. }
  2615. if ($receivablesStaff2 != 'PUBLIC') {
  2616. $receivablesStaff = explode ( "-", $receivablesStaff2 );
  2617. $item += array (
  2618. 'staff' => $receivablesStaff [0]
  2619. );
  2620. }
  2621. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2622. $toparty = $this->getWxidByCategory ( $receivablesCategory [1] );
  2623. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  2624. $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  2625. if ($toparty != 0)
  2626. $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  2627. }
  2628. return "/invoiceReceivables";
  2629. }
  2630. /**
  2631. * 收款认领页面-包括公共认领 办事处认领 最近已认领数据
  2632. */
  2633. function invoiceReceivablesClaim() {
  2634. Doo::loadModel ( 'invoiceReceivables' );
  2635. $invoiceReceivables = new invoiceReceivables ();
  2636. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  2637. $this->data ['receivablesList'] = $receivablesList;
  2638. $this->data ['memu'] = "invoice";
  2639. $this->data ['staff'] = $this->staff;
  2640. $this->data ['receiptMemu'] = 'invoiceReceivablesClaim';
  2641. $this->render ( "/admin/invoiceReceivablesClaim", $this->data );
  2642. }
  2643. function invoiceReceivablesTitleMarkSet() {
  2644. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  2645. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  2646. if (empty ( $iridKey ) || empty ( $recepitTitleMark ))
  2647. die ( 'illegal request' );
  2648. Doo::loadModel ( 'invoiceReceivables' );
  2649. $invoiceReceivables = new invoiceReceivables ();
  2650. Doo::loadClass ( 'XDeode' );
  2651. $XDeode = new XDeode ( 5 );
  2652. $irid = $XDeode->decode ( $iridKey );
  2653. if (! is_numeric ( $irid ))
  2654. die ( 'illegal request' );
  2655. $invoiceReceivables->recepitTitleMark = $recepitTitleMark;
  2656. $invoiceReceivables->update ( array (
  2657. 'where' => 'irid = ' . $irid
  2658. ) );
  2659. return '/invoiceReceivablesClaim';
  2660. }
  2661. /**
  2662. * 更新收款相关数据
  2663. */
  2664. function invoiceReceivablesUpdateClaim() {
  2665. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  2666. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  2667. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  2668. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  2669. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  2670. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  2671. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  2672. if (empty ( $claimKey ))
  2673. die ( 'illegal request' );
  2674. Doo::loadModel ( 'invoiceReceivables' );
  2675. $invoiceReceivables = new invoiceReceivables ();
  2676. Doo::loadModel ( 'invoiceROLog' );
  2677. $invoiceROLog = new invoiceROLog ();
  2678. $con = ' and iid=0 and bindStatus=0'; // and receivablesCategory!="PUBLIC" and receivablesStaff!="PUBLIC"
  2679. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  2680. if (empty ( $detail ))
  2681. die ( 'illegal request' );
  2682. $invoiceReceivables = new invoiceReceivables ();
  2683. $item = array (
  2684. 'irid' => $detail ['irid']
  2685. );
  2686. if ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  2687. $item += array (
  2688. 'confirmTime' => date ( "Y-m-d H:i:s" )
  2689. );
  2690. }
  2691. if (! empty ( $receivablesCategory ))
  2692. $item += array (
  2693. 'receivablesCategory' => $receivablesCategory
  2694. );
  2695. if (! empty ( $receivablesStaff ))
  2696. $item += array (
  2697. 'receivablesStaff' => $receivablesStaff
  2698. );
  2699. if (! empty ( $receivablesPrice ))
  2700. $item += array (
  2701. 'receivablesPrice' => $receivablesPrice
  2702. );
  2703. if (! empty ( $receivablesMessage ))
  2704. $item += array (
  2705. 'receivablesMessage' => $receivablesMessage
  2706. );
  2707. if (! empty ( $receivablesBank ))
  2708. $item += array (
  2709. 'receivablesBank' => $receivablesBank
  2710. );
  2711. if (! empty ( $receivablesDate ))
  2712. $item += array (
  2713. 'receivablesDate' => $receivablesDate
  2714. );
  2715. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2716. // 收款操作日志
  2717. $item = array ();
  2718. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  2719. $item = array (
  2720. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  2721. );
  2722. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  2723. $item = array (
  2724. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  2725. );
  2726. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  2727. $receivablesStaff = explode ( '-', $receivablesStaff );
  2728. $item = array (
  2729. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  2730. );
  2731. }
  2732. $item += array (
  2733. 'date' => date ( "Y-m-d" ),
  2734. 'status' => 1,
  2735. 'img' => $this->staff [0] ['avatar'],
  2736. 'username' => $this->staff [0] ['username'],
  2737. 'uid' => $this->staff [0] ['sid'],
  2738. 'category' => $this->staff [0] ['category'],
  2739. 'irid' => $detail ['irid']
  2740. );
  2741. $invoiceROLog->setInvoiceROLog ( $item );
  2742. return '/invoiceReceivablesAS';
  2743. }
  2744. function invoiceReceivablesDelete() {
  2745. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  2746. if (empty ( $claimKey ))
  2747. die ( 'illegal request' );
  2748. Doo::loadModel ( 'invoiceReceivables' );
  2749. $invoiceReceivables = new invoiceReceivables ();
  2750. $con = ' and iid=0 and bindStatus=0 and receivablesStaff="PUBLIC"';
  2751. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  2752. if (empty ( $detail ))
  2753. die ( 'illegal request' );
  2754. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  2755. return '/invoiceReceivablesAS';
  2756. }
  2757. /**
  2758. * 管理员录入的收款 ,确认认领到谁的名下.统计收款金额
  2759. */
  2760. function invoiceReceivablesAscription() {
  2761. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  2762. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  2763. Doo::loadModel ( 'invoiceReceivables' );
  2764. $invoiceReceivables = new invoiceReceivables ();
  2765. Doo::loadModel ( 'invoiceROLog' );
  2766. $invoiceROLog = new invoiceROLog ();
  2767. Doo::loadModel ( 'invoiceStatistics' );
  2768. $invoiceStatistics = new invoiceStatistics ();
  2769. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  2770. if (! empty ( $detail ) && $detail ['receivablesStaff'] == 'PUBLIC' && ! empty ( $recepitTitleMark )) {
  2771. $item = array (
  2772. 'irid' => $detail ['irid'],
  2773. 'receivablesCategory' => $this->staff [0] ['cid'] . ":" . $this->staff [0] ['category'],
  2774. 'receivablesStaff' => $this->staff [0] ['sid'] . "-" . $this->staff [0] ['username'],
  2775. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  2776. 'recepitTitleMark' => $recepitTitleMark,
  2777. 'source' => 1
  2778. );
  2779. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2780. $item = array (
  2781. 'date' => date ( "Y-m-d" ),
  2782. 'operation' => $this->staff [0] ['username'] . " 认领 ",
  2783. 'status' => 2,
  2784. 'img' => $this->staff [0] ['avatar'],
  2785. 'username' => $this->staff [0] ['username'],
  2786. 'uid' => $this->staff [0] ['sid'],
  2787. 'category' => $this->staff [0] ['category'],
  2788. 'irid' => $irid
  2789. );
  2790. $invoiceROLog->setInvoiceROLog ( $item );
  2791. $item = array (
  2792. 'cid' => $this->staff [0] ['cid'],
  2793. 'staff' => $this->staff [0] ['sid']
  2794. );
  2795. $invoiceStatistics->updateInvoiceStatisticsByIrid ( $item, $detail ['irid'], 2 );
  2796. }
  2797. return "/invoiceReceivablesClaim";
  2798. }
  2799. /**
  2800. */
  2801. function invoiceMyReceivables() {
  2802. Doo::loadModel ( 'invoiceReceivables' );
  2803. $invoiceReceivables = new invoiceReceivables ();
  2804. Doo::loadModel ( 'invoiceStatistics' );
  2805. $invoiceStatistics = new invoiceStatistics ();
  2806. $isMonth = $invoiceStatistics->getStatisticsByMonth ();
  2807. $year = date ( "Y" );
  2808. $tmp_date = date ( "Ym" );
  2809. $tmp_year = substr ( $tmp_date, 0, 4 );
  2810. $tmp_mon = substr ( $tmp_date, 4, 2 );
  2811. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  2812. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  2813. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . ".htm";
  2814. $htm = $this->showCache ( $path );
  2815. $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  2816. $this->data ['isMonth'] = $isMonth;
  2817. $this->data ['htm'] = $htm;
  2818. $this->data ['list'] = $list;
  2819. $this->data ['memu'] = "invoice";
  2820. $this->data ['staff'] = $this->staff;
  2821. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  2822. $this->render ( "/admin/invoiceMyReceivables", $this->data );
  2823. }
  2824. /**
  2825. * 收款绑定发票 ,一个收款只能绑定一个发票
  2826. */
  2827. function invoiceBindReceivables() {
  2828. $claimKey = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  2829. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2830. Doo::loadModel ( 'invoice' );
  2831. $invoice = new invoice ();
  2832. Doo::loadModel ( 'invoiceReceivables' );
  2833. $invoiceReceivables = new invoiceReceivables ();
  2834. Doo::loadModel ( 'invoiceOperationLog' );
  2835. $invoiceOperationLog = new invoiceOperationLog ();
  2836. if (empty ( $invoiceKey ) || empty ( $claimKey ))
  2837. die ( 'illegal request' );
  2838. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  2839. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey );
  2840. if (empty ( $detail ) && empty ( $detailM ))
  2841. die ( 'illegal request' );
  2842. if ($detail ['untreadStatus'] == 3)
  2843. die ( 'illegal request' );
  2844. // 修改 绑定状态改为 金额
  2845. $invoiceReceivables = new invoiceReceivables ();
  2846. $invoicePrice = $detail ['invoicePrice'] + $detailM ['bindPrice'];
  2847. if ($detailM ['receivablesPrice'] > $invoicePrice) {
  2848. $item = array (
  2849. 'bindPrice' => $invoicePrice
  2850. );
  2851. } elseif ($detailM ['receivablesPrice'] <= $invoicePrice) {
  2852. $item = array (
  2853. 'bindPrice' => $invoicePrice,
  2854. 'bindStatus' => 1,
  2855. 'bindDate' => date ( "Y-m-d H:i:s" )
  2856. );
  2857. } else {
  2858. die ( 'illegal request' );
  2859. }
  2860. if ($detailM ['iid'] == 0) {
  2861. $item += array (
  2862. 'iid' => $detail ['iid']
  2863. );
  2864. } else {
  2865. $iidExtend = explode ( ',', $detailM ['iidExtend'] );
  2866. array_push ( $iidExtend, $detail ['iid'] );
  2867. $item += array (
  2868. 'iidExtend' => implode ( ',', $iidExtend )
  2869. );
  2870. }
  2871. $item += array (
  2872. 'irid' => $detailM ['irid'],
  2873. 'accountClerk' => $this->staff [0] ['username']
  2874. );
  2875. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2876. $iridString = "";
  2877. if (empty ( $detail ['irid'] ))
  2878. $iridString = $detailM ['irid'];
  2879. else
  2880. $iridString = $detail ['irid'] . ',' . $detailM ['irid'];
  2881. $item = array (
  2882. 'iid' => $detail ['iid'],
  2883. 'irid' => $iridString
  2884. );
  2885. $invoiceReceivables = new invoiceReceivables ();
  2886. $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  2887. if ($detail ['invoicePrice'] <= $sum)
  2888. $item += array (
  2889. 'untreadStatus' => 3,
  2890. 'bindTime' => date ( "Y-m-d H:i:s" )
  2891. );
  2892. // print_r($item);
  2893. // echo $sum;die;
  2894. $invoice->setInvoiceByCondition ( $item );
  2895. // 操作日志
  2896. $item = array (
  2897. 'date' => date ( "Y-m-d H:i:s" ),
  2898. 'operation' => "收款" . $detailM ['receivablesSerial'] . "入账到发票" . $detail ['invoiceSerial'],
  2899. 'status' => 8,
  2900. 'img' => $this->staff [0] ['avatar'],
  2901. 'username' => $this->staff [0] ['username'],
  2902. 'uid' => $this->staff [0] ['sid'],
  2903. 'category' => $this->staff [0] ['category'],
  2904. 'iid' => $detail ['iid']
  2905. );
  2906. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2907. Doo::loadModel ( 'invoiceStatistics' );
  2908. $invoiceStatistics = new invoiceStatistics ();
  2909. $item = array (
  2910. 'date' => $detailM ['receivablesDate'],
  2911. 'priceClass' => 3,
  2912. 'cid' => $detail ['cid'],
  2913. 'staff' => $detail ['sid'],
  2914. 'accountPrice' => $detailM ['receivablesPrice']
  2915. );
  2916. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2917. return "/invoiceReceivables";
  2918. }
  2919. /**
  2920. * 核销 动作,确认入账统计 发票收款完成--需求更变 废弃 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"; }
  2921. */
  2922. function invoiceAggregate() {
  2923. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  2924. Doo::loadModel ( 'invoiceStatistics' );
  2925. $invoiceStatistics = new invoiceStatistics ();
  2926. Doo::loadModel ( 'L_category' );
  2927. $Lcategory = new L_category ();
  2928. $isList = $invoiceStatistics->getInvoiceStatisticsByYear ( $year );
  2929. $LcategoryList = $Lcategory->getCategory ();
  2930. // print_r($isList);
  2931. $html = ""; // $invoicePriceCategory=0;$receivablesPriceCategory=0;$accountPriceCategory=0;
  2932. foreach ( $LcategoryList as $key => $value ) {
  2933. $html .= '<tr><th><a href="/invoiceAggregateCategory/' . $value ['cidKey'] . '">' . $value ['title'] . '</a></th>';
  2934. $month = 1;
  2935. $invoicePriceYear = 0;
  2936. $receivablesPriceYear = 0;
  2937. $accountPriceYear = 0;
  2938. for(; $month <= 12; $month ++) {
  2939. $flag = true;
  2940. foreach ( $isList ['statisticsMonthCid'] as $k => $v ) {
  2941. if ($value ['cid'] == $v ['cid'] && $month == $v ['month']) {
  2942. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  2943. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  2944. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  2945. ';
  2946. $invoicePriceYear += $v ['invoicePrice'];
  2947. $receivablesPriceYear += $v ['receivablesPrice'];
  2948. $accountPriceYear += $v ['accountPrice'];
  2949. $flag = false;
  2950. break;
  2951. }
  2952. }
  2953. if ($flag)
  2954. $html .= '<td class="taR"></td>
  2955. <td class="taR"></td>
  2956. <td class="taR"><b></b></td>
  2957. ';
  2958. }
  2959. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  2960. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  2961. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  2962. ';
  2963. $html .= '</tr>';
  2964. }
  2965. $html .= '<tr><th><b class="colGreen">月合计</b></th>';
  2966. $invoicePriceYear = 0;
  2967. $receivablesPriceYear = 0;
  2968. $accountPriceYear = 0;
  2969. for($month = 1; $month <= 12; $month ++) {
  2970. $flag = true;
  2971. foreach ( $isList ['statisticsMonth'] as $k => $v ) {
  2972. if ($month == $v ['month']) {
  2973. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  2974. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  2975. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  2976. ';
  2977. $invoicePriceYear += $v ['invoicePrice'];
  2978. $receivablesPriceYear += $v ['receivablesPrice'];
  2979. $accountPriceYear += $v ['accountPrice'];
  2980. $flag = false;
  2981. break;
  2982. }
  2983. }
  2984. if ($flag) {
  2985. $html .= '<td class="taR"></td>
  2986. <td class="taR"></td>
  2987. <td class="taR"><b></b></td>
  2988. ';
  2989. }
  2990. }
  2991. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  2992. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  2993. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  2994. ';
  2995. $html .= '</tr>';
  2996. // print_r($isList);
  2997. $this->data ['html'] = $html;
  2998. $this->data ['LcategoryList'] = $LcategoryList;
  2999. $this->data ['isList'] = $isList;
  3000. $this->data ['year'] = $year;
  3001. $this->data ['memu'] = "invoice";
  3002. $this->data ['staff'] = $this->staff;
  3003. $this->data ['receiptMemu'] = 'invoiceAggregate';
  3004. $this->render ( "/admin/invoiceAggregate", $this->data );
  3005. }
  3006. function invoiceAggregateStaff() {
  3007. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3008. Doo::loadModel ( 'invoiceStatistics' );
  3009. $invoiceStatistics = new invoiceStatistics ();
  3010. Doo::loadModel ( 'L_category' );
  3011. $Lcategory = new L_category ();
  3012. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year );
  3013. $staffList = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year );
  3014. $cStaff = $Lcategory->getCategoryStaff ();
  3015. $html = '';
  3016. foreach ( $cStaff as $key => $value ) {
  3017. $categoryFir = true;
  3018. foreach ( $value ['staff'] as $k => $v ) {
  3019. if ($categoryFir) {
  3020. $width = count ( $value ['staff'] ) + 1;
  3021. $html .= '<tr><th rowspan="' . $width . '">' . $value ['title'] . ' </th>';
  3022. $categoryFir = false;
  3023. } else
  3024. $html .= '<tr>';
  3025. $html .= '<th>' . $v ['username'] . '</th>';
  3026. $invoicePriceStaffYear = 0;
  3027. $receivablesPriceStaffYear = 0;
  3028. $accountPriceStaffYear = 0;
  3029. for($month = 1; $month <= 12; $month ++) {
  3030. $flag = true;
  3031. foreach ( $staffList ['statisticsMonthStaff'] as $sl => $slv ) {
  3032. if ($v ['sid'] == $slv ['staff'] && $month == $slv ['month']) {
  3033. $html .= '<td class="taR">¥' . $slv ['invoicePrice'] . '</td>
  3034. <td class="taR">¥' . $slv ['receivablesPrice'] . '</td>
  3035. <td class="taR"><b>¥' . $slv ['accountPrice'] . '</b></td>
  3036. ';
  3037. $invoicePriceStaffYear += $slv ['invoicePrice'];
  3038. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  3039. $accountPriceStaffYear += $slv ['accountPrice'];
  3040. $flag = false;
  3041. break;
  3042. }
  3043. }
  3044. if ($flag)
  3045. $html .= '<td class="taR"></td>
  3046. <td class="taR"></td>
  3047. <td class="taR"><b></b></td>
  3048. ';
  3049. }
  3050. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  3051. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  3052. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  3053. ';
  3054. }
  3055. $html .= '</tr>';
  3056. // 小计
  3057. if (! empty ( $value ['staff'] )) {
  3058. $html .= '<tr><th class="taR">小计</th>';
  3059. $invoicePriceStaffYear = 0;
  3060. $receivablesPriceStaffYear = 0;
  3061. $accountPriceStaffYear = 0;
  3062. for($month = 1; $month <= 12; $month ++) {
  3063. $flag = true;
  3064. foreach ( $staffList ['statisticsMonthCid'] as $smc => $smcv ) {
  3065. if ($value ['cid'] == $smcv ['cid'] && $month == $slv ['month']) {
  3066. $html .= '<td class="taR">¥' . $smcv ['invoicePrice'] . '</td>
  3067. <td class="taR">¥' . $smcv ['receivablesPrice'] . '</td>
  3068. <td class="taR"><b>¥' . $smcv ['accountPrice'] . '</b></td>
  3069. ';
  3070. $invoicePriceStaffYear += $slv ['invoicePrice'];
  3071. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  3072. $accountPriceStaffYear += $slv ['accountPrice'];
  3073. $flag = false;
  3074. break;
  3075. }
  3076. }
  3077. if ($flag)
  3078. $html .= '<td class="taR"></td>
  3079. <td class="taR"></td>
  3080. <td class="taR"><b></b></td>
  3081. ';
  3082. }
  3083. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  3084. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  3085. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  3086. ';
  3087. $html .= '</tr>';
  3088. }
  3089. }
  3090. $html .= '<tr class="warning"><th colspan="2"><b class="colGreen" >月合计</b></th>';
  3091. $invoicePriceYear = 0;
  3092. $receivablesPriceYear = 0;
  3093. $accountPriceYear = 0;
  3094. for($month = 1; $month <= 12; $month ++) {
  3095. $flag = true;
  3096. foreach ( $staffList ['statisticsMonth'] as $k => $v ) {
  3097. if ($month == $v ['month']) {
  3098. $html .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>
  3099. <td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>
  3100. <td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>
  3101. ';
  3102. $invoicePriceYear += $v ['invoicePrice'];
  3103. $receivablesPriceYear += $v ['receivablesPrice'];
  3104. $accountPriceYear += $v ['accountPrice'];
  3105. $flag = false;
  3106. break;
  3107. }
  3108. }
  3109. if ($flag)
  3110. $html .= '<td class="taR"></td>
  3111. <td class="taR"></td>
  3112. <td class="taR"><b></b></td>
  3113. ';
  3114. }
  3115. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  3116. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  3117. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  3118. ';
  3119. $html .= '</tr>';
  3120. $this->data ['html'] = $html;
  3121. $this->data ['isList'] = $toteList;
  3122. $this->data ['year'] = $year;
  3123. $this->data ['memu'] = "invoice";
  3124. $this->data ['staff'] = $this->staff;
  3125. $this->data ['receiptMemu'] = 'invoiceAggregate';
  3126. $this->render ( "/admin/invoiceAggregateStaff", $this->data );
  3127. }
  3128. function invoiceAggregateCategory() {
  3129. Doo::loadClass ( 'XDeode' );
  3130. $XDeode = new XDeode ( 5 );
  3131. $cid = $cidKey = isset ( $this->params ['cid'] ) ? $this->params ['cid'] : "";
  3132. $cid = $XDeode->decode ( $cid );
  3133. if (! is_numeric ( $cid ))
  3134. die ( 'illegal request' );
  3135. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3136. Doo::loadModel ( 'invoiceStatistics' );
  3137. $invoiceStatistics = new invoiceStatistics ();
  3138. Doo::loadModel ( 'staff' );
  3139. $staff = new staff ();
  3140. $list = $staff->getStaffByCid ( $cid );
  3141. $isCategory = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year, $cid );
  3142. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year, $cid );
  3143. if (empty ( $list ))
  3144. die ( '该办事处没有成员' );
  3145. $htmlA = $htmlB = $htmlC = $html = '';
  3146. foreach ( $list as $key => $value ) {
  3147. $htmlA = '<tr><th rowspan="3">' . $value ['username'] . '</th><th class="taC">开票</th>';
  3148. $htmlB = '<tr><th class="taC">收款</th>';
  3149. $htmlC = '<tr><th class="taC">入账</th>';
  3150. $invoicePriceStaffYear = 0;
  3151. $receivablesPriceStaffYear = 0;
  3152. $accountPriceStaffYear = 0;
  3153. for($month = 1; $month <= 12; $month ++) {
  3154. $flag = true;
  3155. foreach ( $isCategory ['statisticsMonthStaff'] as $k => $v ) {
  3156. if ($value ['sid'] == $v ['staff'] && $month == $v ['month']) {
  3157. $htmlA .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>';
  3158. $htmlB .= '<td class="taR">¥' . $v ['receivablesPrice'] . '</td>';
  3159. $htmlC .= '<td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>';
  3160. $invoicePriceStaffYear += $v ['invoicePrice'];
  3161. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  3162. $accountPriceStaffYear += $v ['accountPrice'];
  3163. $flag = false;
  3164. break;
  3165. }
  3166. }
  3167. if ($flag) {
  3168. $htmlA .= '<td class="taR">-</td>';
  3169. $htmlB .= '<td class="taR">-</td>';
  3170. $htmlC .= '<td class="taR"><b>-</b></td>';
  3171. }
  3172. }
  3173. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  3174. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  3175. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  3176. $htmlA .= '</tr>';
  3177. $htmlB .= '</tr>';
  3178. $htmlC .= '</tr>';
  3179. $html .= $htmlA . $htmlB . $htmlC;
  3180. }
  3181. $htmlA = $htmlB = $htmlC = "";
  3182. $htmlA = '<tr><th rowspan="3">月合计</th><th class="taC">开票</th>';
  3183. $htmlB = '<tr><th class="taC">收款</th>';
  3184. $htmlC = '<tr><th class="taC">入账</th>';
  3185. $invoicePriceStaffYear = 0;
  3186. $receivablesPriceStaffYear = 0;
  3187. $accountPriceStaffYear = 0;
  3188. for($month = 1; $month <= 12; $month ++) {
  3189. $flag = true;
  3190. foreach ( $isCategory ['statisticsMonth'] as $k => $v ) {
  3191. if ($month == $v ['month']) {
  3192. $htmlA .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>';
  3193. $htmlB .= '<td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>';
  3194. $htmlC .= '<td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>';
  3195. $invoicePriceStaffYear += $v ['invoicePrice'];
  3196. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  3197. $accountPriceStaffYear += $v ['accountPrice'];
  3198. $flag = false;
  3199. break;
  3200. }
  3201. }
  3202. if ($flag) {
  3203. $htmlA .= '<td class="taR">-</td>';
  3204. $htmlB .= '<td class="taR">-</td>';
  3205. $htmlC .= '<td class="taR"><b>-</b></td>';
  3206. }
  3207. }
  3208. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  3209. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  3210. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  3211. $htmlA .= '</tr>';
  3212. $htmlB .= '</tr>';
  3213. $htmlC .= '</tr>';
  3214. $html .= $htmlA . $htmlB . $htmlC;
  3215. $this->data ['html'] = $html;
  3216. $this->data ['cidKey'] = $cidKey;
  3217. $this->data ['slist'] = $list;
  3218. $this->data ['isList'] = $toteList;
  3219. $this->data ['year'] = $year;
  3220. $this->data ['memu'] = "invoice";
  3221. $this->data ['staff'] = $this->staff;
  3222. $this->data ['receiptMemu'] = 'invoiceAggregate';
  3223. $this->render ( "/admin/invoiceAggregateCategory", $this->data );
  3224. }
  3225. function invoiceAggregateCategoryDetail() {
  3226. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  3227. Doo::loadClass ( 'XDeode' );
  3228. $XDeode = new XDeode ( 5 );
  3229. Doo::loadModel ( 'invoiceStatistics' );
  3230. $invoiceStatistics = new invoiceStatistics ();
  3231. Doo::loadModel ( 'L_category' );
  3232. $category = new L_category ();
  3233. Doo::loadModel ( 'invoice' );
  3234. $invoice = new invoice ();
  3235. Doo::loadModel ( 'staff' );
  3236. $staff = new staff ();
  3237. Doo::loadModel ( "invoiceCategoryManage" );
  3238. $invoiceCategoryManage = new invoiceCategoryManage ();
  3239. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  3240. $cidList = array ();
  3241. foreach ( $imcStaff as $key => $value ) {
  3242. array_push ( $cidList, $value ['cid'] );
  3243. if (empty ( $cidKey ))
  3244. $cidKey = $XDeode->encode ( $value ['cid'] );
  3245. }
  3246. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  3247. $cid = $XDeode->decode ( $cidKey );
  3248. $redis = new Redis ();
  3249. $redis->connect ( '127.0.0.1', '6379' );
  3250. $redisKey = ''; // date('Y-m-d').'_iacd_'.$cid;
  3251. $redisValue = ''; // $redis->lrange($redisKey, 0, -1);
  3252. if (empty ( $redisValue )) {
  3253. $isMC = $invoiceStatistics->getInvoiceStatistiscsMothByCategory ( $cid );
  3254. $schedule = $invoice->getInvoiceScheduleByCid ( $cid );
  3255. // 获得办事处人员下的汇总
  3256. $slist = $staff->getStaffByCid ( $cid );
  3257. $ismsb = $invoiceStatistics->getISMSByCategory ( $cid ); // 当月汇总
  3258. $ISAS = $invoiceStatistics->getISASByCategory ( $cid ); // 全部汇总
  3259. $scheduleStaff = $invoice->getInvoiceScheduleByCidGroupSid ( $cid ); // 完成度
  3260. foreach ( $slist as $key => $value ) {
  3261. $slist [$key] ['invoicePrice'] = 0;
  3262. $slist [$key] ['receivablesPrice'] = 0;
  3263. $slist [$key] ['accountPrice'] = 0;
  3264. $slist [$key] ['invoiceAllPrice'] = 0;
  3265. $slist [$key] ['receivablesAllPrice'] = 0;
  3266. $slist [$key] ['accountAllPrice'] = 0;
  3267. $slist [$key] ['schedule'] = 0;
  3268. foreach ( $ismsb as $k => $v ) {
  3269. if ($value ['sid'] == $v ['staff']) {
  3270. $slist [$key] ['invoicePrice'] = $v ['invoicePrice'];
  3271. $slist [$key] ['receivablesPrice'] = $v ['receivablesPrice'];
  3272. $slist [$key] ['accountPrice'] = $v ['accountPrice'];
  3273. }
  3274. }
  3275. foreach ( $ISAS as $e => $a ) {
  3276. if ($value ['sid'] == $a ['staff']) {
  3277. $slist [$key] ['invoiceAllPrice'] = $a ['invoicePrice'];
  3278. $slist [$key] ['receivablesAllPrice'] = $a ['receivablesPrice'];
  3279. $slist [$key] ['accountAllPrice'] = $a ['accountPrice'];
  3280. }
  3281. }
  3282. if (isset ( $scheduleStaff [$value ['sid']] ))
  3283. $slist [$key] ['schedule'] = $scheduleStaff [$value ['sid']];
  3284. }
  3285. $this->data ['cidKey'] = $cidKey;
  3286. $schedule = ( int ) ($schedule * 100);
  3287. $this->data ['slist'] = $slist;
  3288. $this->data ['isMC'] = $isMC;
  3289. $this->data ['schedule'] = $schedule;
  3290. $slist = json_encode ( $slist );
  3291. $isMC = json_encode ( $isMC );
  3292. $schedule = json_encode ( $schedule );
  3293. $redis->lpush ( $redisKey, $slist );
  3294. $redis->lpush ( $redisKey, $isMC );
  3295. $redis->lpush ( $redisKey, $schedule );
  3296. } else {
  3297. $this->data ['cidKey'] = $cidKey;
  3298. $this->data ['slist'] = json_decode ( $redisValue [2], true );
  3299. $this->data ['isMC'] = json_decode ( $redisValue [1], true );
  3300. $this->data ['schedule'] = json_decode ( $redisValue [0], true );
  3301. }
  3302. $this->data ['categoryList'] = $categoryList;
  3303. $this->data ['memu'] = "invoice";
  3304. $this->data ['staff'] = $this->staff;
  3305. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  3306. $this->render ( "/admin/invoiceAggregateCategoryDetail", $this->data );
  3307. }
  3308. function invoiceAchieve() {
  3309. Doo::loadModel ( 'invoice' );
  3310. $invoice = new invoice ();
  3311. Doo::loadClass ( 'XDeode' );
  3312. $XDeode = new XDeode ( 5 );
  3313. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  3314. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  3315. $page_size = 18;
  3316. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  3317. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  3318. $get = "/" . $date;
  3319. $con = '';
  3320. if ($date == 'MONTHO')
  3321. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  3322. elseif ($date == 'MONTHT')
  3323. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  3324. elseif ($date == 'MONTHY')
  3325. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  3326. if (! empty ( $MebSea )) {
  3327. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  3328. $get .= "/" . $MebSea;
  3329. }
  3330. $pageinfo ['page'] = array (
  3331. 'previous' => ''
  3332. );
  3333. $sql = 'status=2 and printStatus=1 and irid!="" and ( untreadStatus=3 or untreadStatus=0 ) and sid=' . $sid . $con;
  3334. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceAchieve", $get, "" );
  3335. $limit = $pageinfo ['lower'] . ',' . $page_size;
  3336. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  3337. // print_r($pageinfo);
  3338. $this->data ['MebSeaEn'] = $MebSea;
  3339. $this->data ['MebSea'] = urlencode ( $MebSea );
  3340. $this->data ['get'] = $get;
  3341. $this->data ['page'] = $pageinfo;
  3342. $this->data ['list'] = $list;
  3343. $this->data ['date'] = $date;
  3344. $this->data ['memu'] = "invoice";
  3345. $this->data ['staff'] = $this->staff;
  3346. $this->data ['receiptMemu'] = 'invoice';
  3347. $this->render ( "/admin/invoiceAchieve", $this->data );
  3348. }
  3349. function invoiceMyUnAccountAchieve() {
  3350. Doo::loadModel ( 'invoice' );
  3351. $invoice = new invoice ();
  3352. Doo::loadClass ( 'XDeode' );
  3353. $XDeode = new XDeode ( 5 );
  3354. Doo::loadModel ( 'staff' );
  3355. $staff = new staff ();
  3356. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  3357. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  3358. $page_size = 18;
  3359. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  3360. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3361. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  3362. $dateArr = explode ( ':', $date );
  3363. $D1 = '';
  3364. $D2 = '';
  3365. if (! empty ( $date )) {
  3366. $D1 = $dateArr [0];
  3367. $D2 = $dateArr [1];
  3368. }
  3369. $con = '';
  3370. if (! empty ( $D1 ) && ! empty ( $D2 ))
  3371. $con = ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  3372. if (! empty ( $MebSea )) {
  3373. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  3374. }
  3375. $pageinfo ['page'] = array (
  3376. 'previous' => ''
  3377. );
  3378. // and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  3379. $sql = " status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid= " . $sid . $con;
  3380. $action = "invoiceMyUnAccountAchieve";
  3381. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  3382. $limit = $pageinfo ['lower'] . ',' . $page_size;
  3383. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  3384. Doo::loadModel ( 'express' );
  3385. $express = new express ();
  3386. $expressList = $express->getExpressByAll ();
  3387. $this->data ['expressList'] = $expressList;
  3388. // print_r($list);
  3389. $this->data ['MebSeaEn'] = $MebSea;
  3390. $this->data ['get'] = $get;
  3391. $this->data ['page'] = $pageinfo;
  3392. $this->data ['date'] = $date;
  3393. $this->data ['list'] = $list;
  3394. $this->data ['memu'] = "invoice";
  3395. $this->data ['staff'] = $this->staff;
  3396. $this->data ['receiptMemu'] = 'invoice';
  3397. $this->render ( "/admin/invoiceMyUnAccountAchieve", $this->data );
  3398. }
  3399. function invoiceReceivablesAchieve() {
  3400. Doo::loadModel ( 'invoiceReceivables' );
  3401. $invoiceReceivables = new invoiceReceivables ();
  3402. Doo::loadClass ( 'XDeode' );
  3403. $XDeode = new XDeode ( 5 );
  3404. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  3405. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  3406. $page_size = 12;
  3407. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  3408. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  3409. $get = "/" . $date;
  3410. $con = '';
  3411. if ($date == 'MONTHO')
  3412. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  3413. elseif ($date == 'MONTHT')
  3414. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  3415. elseif ($date == 'MONTHY')
  3416. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  3417. if (! empty ( $MebSea )) {
  3418. $con .= ' and ( receivablesMessage like "%' . $MebSea . '%" or receivablesPrice like "%' . $MebSea . '%" )';
  3419. $get .= "/" . $MebSea;
  3420. }
  3421. $pageinfo ['page'] = array (
  3422. 'previous' => ''
  3423. );
  3424. $sql = " bindStatus=1 and receivablesStaff like '" . $sid . "_%' " . $con;
  3425. $pageinfo = $this->get_page ( "CLD_invoiceReceivables", $sql, $page, $page_size, "invoiceReceivablesAchieve", $get, "" );
  3426. $limit = $pageinfo ['lower'] . ',' . $page_size;
  3427. $list = $invoiceReceivables->getReceivablesByUntreadStatusPage ( $limit, $sql );
  3428. // print_r($pageinfo);
  3429. $this->data ['MebSeaEn'] = $MebSea;
  3430. $this->data ['MebSea'] = urlencode ( $MebSea );
  3431. $this->data ['get'] = $get;
  3432. $this->data ['page'] = $pageinfo;
  3433. $this->data ['list'] = $list;
  3434. $this->data ['date'] = $date;
  3435. $this->data ['memu'] = "invoice";
  3436. $this->data ['staff'] = $this->staff;
  3437. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  3438. $this->render ( "/admin/invoiceReceivablesAchieve", $this->data );
  3439. }
  3440. /**
  3441. * 收款解绑
  3442. */
  3443. function invoiceUnBundLing() {
  3444. $unBundKey = $this->get_args ( 'unBundKey' ) ? $this->get_args ( 'unBundKey' ) : '';
  3445. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  3446. Doo::loadModel ( 'invoice' );
  3447. $invoice = new invoice ();
  3448. Doo::loadModel ( 'invoiceReceivables' );
  3449. $invoiceReceivables = new invoiceReceivables ();
  3450. Doo::loadModel ( 'invoiceOperationLog' );
  3451. $invoiceOperationLog = new invoiceOperationLog ();
  3452. Doo::loadModel ( 'invoiceROLog' );
  3453. $invoiceROLog = new invoiceROLog ();
  3454. Doo::loadModel ( 'invoiceStatistics' );
  3455. Doo::loadClass ( 'XDeode' );
  3456. $XDeode = new XDeode ( 5 );
  3457. if (empty ( $iidKey ))
  3458. die ( 'illegal request' );
  3459. $iid = $XDeode->decode ( $iidKey );
  3460. $irid = $invoice->authcode ( $unBundKey );
  3461. if ((! empty ( $irid ) && ! is_numeric ( $irid )) || (! empty ( $iid ) && ! is_numeric ( $iid )))
  3462. die ( 'illegal request' );
  3463. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  3464. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  3465. if (empty ( $irDetails ) || empty ( $invoiceDetails ) || (empty ( $irDetails ['iid'] ) && empty ( $irDetails ['iidExtend'] )) || $invoiceDetails ['untreadStatus'] == 2)
  3466. die ( 'illegal request' );
  3467. // 收款
  3468. $item = array (
  3469. 'irid' => $irDetails ['irid'],
  3470. 'bindPrice' => $irDetails ['bindPrice'] - $invoiceDetails ['invoicePrice'],
  3471. 'bindStatus' => 0
  3472. );
  3473. if ($irDetails ['iid'] == $iid)
  3474. $item += array (
  3475. 'iid' => 0
  3476. );
  3477. else {
  3478. $iidExtend = explode ( ',', $irDetails ['iidExtend'] );
  3479. foreach ( $iidExtend as $key => $value ) {
  3480. if ($value == $iid)
  3481. unset ( $iidExtend [$key] );
  3482. }
  3483. $iidExtend = implode ( ',', $iidExtend );
  3484. $item += array (
  3485. 'iidExtend' => $iidExtend
  3486. );
  3487. }
  3488. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3489. // 收款操作日志
  3490. $item = array (
  3491. 'operation' => $this->staff [0] ['username'] . " 解绑 " . $irDetails ['receivablesSerial'],
  3492. 'date' => date ( "Y-m-d" ),
  3493. 'status' => 3,
  3494. 'img' => $this->staff [0] ['avatar'],
  3495. 'username' => $this->staff [0] ['username'],
  3496. 'uid' => $this->staff [0] ['sid'],
  3497. 'category' => $this->staff [0] ['category'],
  3498. 'irid' => $irid
  3499. );
  3500. $invoiceROLog->setInvoiceROLog ( $item );
  3501. // 扣除入账统计金额
  3502. $invoiceStatistics = new invoiceStatistics ();
  3503. $item = array (
  3504. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  3505. 'priceClass' => 3,
  3506. 'cid' => $invoiceDetails ['cid'],
  3507. 'staff' => $invoiceDetails ['sid'],
  3508. 'accountPrice' => - $irDetails ['receivablesPrice']
  3509. );
  3510. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3511. // 扣除收款统计金额
  3512. $invoiceStatistics = new invoiceStatistics ();
  3513. $item = array (
  3514. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  3515. 'priceClass' => 2,
  3516. 'cid' => $invoiceDetails ['cid'],
  3517. 'staff' => $invoiceDetails ['sid'],
  3518. 'irid' => $irDetails ['irid'],
  3519. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  3520. );
  3521. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3522. // 发票解绑去收款ID
  3523. $iridString = $invoiceDetails ['irid'];
  3524. if (! empty ( $invoiceDetails ['irid'] )) {
  3525. $list = explode ( ',', $invoiceDetails ['irid'] );
  3526. foreach ( $list as $key => $value ) {
  3527. if ($value == $irDetails ['irid']) {
  3528. unset ( $list [$key] );
  3529. break;
  3530. }
  3531. }
  3532. $iridString = implode ( ",", $list );
  3533. }
  3534. $item = array (
  3535. 'iid' => $invoiceDetails ['iid'],
  3536. 'irid' => $iridString,
  3537. 'updateTime' => date ( "Y-m-d H:i:s" )
  3538. );
  3539. if ($invoiceDetails ['untreadStatus'] == 3)
  3540. $item += array (
  3541. 'untreadStatus' => 0
  3542. );
  3543. $invoice->setInvoiceByCondition ( $item );
  3544. $item = array (
  3545. 'date' => date ( "Y-m-d H:i:s" ),
  3546. 'operation' => '解绑 收款 ' . $irDetails ['receivablesSerial'],
  3547. 'status' => 11,
  3548. 'img' => $this->staff [0] ['avatar'],
  3549. 'username' => $this->staff [0] ['username'],
  3550. 'uid' => $this->staff [0] ['sid'],
  3551. 'category' => $this->staff [0] ['category'],
  3552. 'iid' => $invoiceDetails ['iid']
  3553. );
  3554. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3555. return "/invoiceReceivablesAS";
  3556. }
  3557. /**
  3558. * 或者该收款下的所以发票
  3559. */
  3560. function ajaxGetInvoiceReceivablesByInvoice() {
  3561. $irid = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : '';
  3562. Doo::loadModel ( 'invoice' );
  3563. $invoice = new invoice ();
  3564. Doo::loadModel ( 'invoiceReceivables' );
  3565. $invoiceReceivables = new invoiceReceivables ();
  3566. $irid = $invoice->authcode ( $irid );
  3567. if (! empty ( $irid ) && ! is_numeric ( $irid ))
  3568. die ( 'illegal request' );
  3569. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  3570. $iidString = $irDetails ['iid'];
  3571. $iidExtend = array_filter ( explode ( ',', $irDetails ['iidExtend'] ) );
  3572. if (! empty ( $irDetails ['iidExtend'] ))
  3573. $iidString .= ',' . implode ( ',', $iidExtend );
  3574. $invoiceList = $invoice->getInvoiceInIid ( $iidString, 'iid,invoiceSerial,invoicePrice,invoiceTitle,invoiceCompany,invoiceElement' );
  3575. $html = "";
  3576. foreach ( $invoiceList as $key => $value ) {
  3577. $title = $value ['invoiceTitle'];
  3578. if (! empty ( $value ['invoiceCompany'] ))
  3579. $title = $value ['invoiceCompany'];
  3580. $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>';
  3581. }
  3582. echo json_encode ( array (
  3583. 'status' => 1,
  3584. 'html' => $html
  3585. ) );
  3586. }
  3587. /**
  3588. * 发票管理
  3589. */
  3590. function invoiceAS() {
  3591. Doo::loadModel ( 'invoice' );
  3592. $invoice = new invoice ();
  3593. Doo::loadModel ( 'invoiceReceivables' );
  3594. $invoiceReceivables = new invoiceReceivables ();
  3595. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  3596. $page_size = 18;
  3597. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  3598. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  3599. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3600. $dateArr = explode ( ':', $date );
  3601. $D1 = '';
  3602. $D2 = '';
  3603. if (! empty ( $date )) {
  3604. $D1 = $dateArr [0] . " 00:00:00 ";
  3605. if (isset ( $dateArr [1] ))
  3606. $D2 = $dateArr [1] . " 23:59:59 ";
  3607. else
  3608. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  3609. // $D2 = $dateArr [1];
  3610. }
  3611. $con = ' status=2 ';
  3612. if (! empty ( $D1 ) && ! empty ( $D2 ))
  3613. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  3614. if ($status == 'UNRECORD')
  3615. $con .= ' and printStatus=1 and untreadStatus=0';
  3616. elseif ($status == 'RECORD')
  3617. $con .= ' and printStatus=1 and untreadStatus=3';
  3618. elseif ($status == 'BOUNCED')
  3619. $con .= ' and untreadStatus=2';
  3620. elseif ($status == 'PARTRECORD')
  3621. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  3622. elseif ($status == 'All') {
  3623. $con .= ' and ( untreadStatus=2 or untreadStatus=0 or untreadStatus=3 )';
  3624. }
  3625. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  3626. if (! empty ( $MebSea )) {
  3627. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  3628. }
  3629. $pageinfo ['page'] = array (
  3630. 'previous' => ''
  3631. );
  3632. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAS", $get, "" );
  3633. $limit = $pageinfo ['lower'] . ',' . $page_size;
  3634. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  3635. // foreach ($list as $key=>$value){
  3636. // $list[$key]['rpSum']=0;
  3637. // if (!empty($value['irid']))
  3638. // $list[$key]['rpSum']=$invoiceReceivables->getSumOfReceivablesPrice($value['irid']);
  3639. // }
  3640. $this->data ['MebSeaEn'] = $MebSea;
  3641. $this->data ['MebSea'] = urlencode ( $MebSea );
  3642. $this->data ['date'] = $date;
  3643. $this->data ['page'] = $pageinfo;
  3644. $this->data ['get'] = $get;
  3645. $this->data ['list'] = $list;
  3646. $this->data ['status'] = $status;
  3647. $this->data ['memu'] = "invoice";
  3648. $this->data ['staff'] = $this->staff;
  3649. $this->data ['receiptMemu'] = 'invoiceReceivables';
  3650. $this->render ( "/admin/invoiceAS", $this->data );
  3651. }
  3652. /**
  3653. * 收款管理
  3654. */
  3655. function invoiceReceivablesAS() {
  3656. Doo::loadModel ( 'invoiceReceivables' );
  3657. $invoiceReceivables = new invoiceReceivables ();
  3658. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  3659. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  3660. $page_size = 10;
  3661. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  3662. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  3663. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3664. $dateArr = explode ( ':', $date );
  3665. $D1 = '';
  3666. $D2 = '';
  3667. if (! empty ( $date )) {
  3668. $D1 = $dateArr [0]; // ." 00:00:00 ";
  3669. if (isset ( $dateArr [1] ))
  3670. $D2 = $dateArr [1]; // ." 23:59:59 ";
  3671. else
  3672. $D2 = $dateArr [0]; // ." 23:59:59 ";//date ( "Y-m-d" );
  3673. }
  3674. $descField = 'a.receivablesDate';
  3675. if ($timeType == 'CREATE')
  3676. $descField = 'a.date';
  3677. $con = '1';
  3678. if (! empty ( $D1 ) && ! empty ( $D2 ))
  3679. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  3680. // echo $con;
  3681. if ($status == 'Unclaimed')
  3682. $con .= ' and a.bindStatus=0';
  3683. elseif ($status == 'Credited')
  3684. $con .= ' and a.bindStatus=1';
  3685. elseif ($status == 'Claim')
  3686. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  3687. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  3688. if (! empty ( $MebSea )) {
  3689. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" )';
  3690. }
  3691. $pageinfo ['page'] = array (
  3692. 'previous' => ''
  3693. );
  3694. $sql = 'select count(*) as count
  3695. from CLD_invoiceReceivables as a left join CLD_invoice as b on
  3696. find_in_set(b.iid,a.iidExtend) or a.iid=b.iid
  3697. where ' . $con . ' group by a.irid
  3698. ';
  3699. $pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceReceivablesAS", $get, "" );
  3700. // print_r($pageinfo);
  3701. // $pageinfo = $this->get_page ( "CLD_invoiceReceivables", $con, $page, $page_size, "invoiceReceivablesAS", $get, "" );
  3702. $limit = $pageinfo ['lower'] . ',' . $page_size;
  3703. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', $descField );
  3704. // print_r($list);
  3705. $this->data ['timeType'] = $timeType;
  3706. $this->data ['MebSeaEn'] = $MebSea;
  3707. $this->data ['MebSea'] = urlencode ( $MebSea );
  3708. $this->data ['date'] = $date;
  3709. $this->data ['page'] = $pageinfo;
  3710. $this->data ['get'] = $get;
  3711. $this->data ['list'] = $list;
  3712. $this->data ['status'] = $status;
  3713. $this->data ['memu'] = "invoice";
  3714. $this->data ['staff'] = $this->staff;
  3715. $this->data ['receiptMemu'] = 'invoiceReceivables';
  3716. $this->render ( "/admin/invoiceReceivablesAS", $this->data );
  3717. }
  3718. function invoiceApprovalAchieve() {
  3719. Doo::loadModel ( 'invoice' );
  3720. $invoice = new invoice ();
  3721. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  3722. $page_size = 12;
  3723. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  3724. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  3725. $get = "/" . $date;
  3726. $con = '';
  3727. if ($date == 'MONTHO')
  3728. $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  3729. elseif ($date == 'MONTHT')
  3730. $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  3731. elseif ($date == 'MONTHY')
  3732. $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  3733. if (! empty ( $MebSea )) {
  3734. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  3735. $get .= "/" . $MebSea;
  3736. }
  3737. $pageinfo ['page'] = array (
  3738. 'previous' => ''
  3739. );
  3740. $sql = '(status=1 or status=2 or status=3 or status=4) and processApprovals!=""' . $con; // echo $sql;
  3741. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", $get, "" );
  3742. $limit = $pageinfo ['lower'] . ',' . $page_size;
  3743. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  3744. // print_r($list);
  3745. $this->data ['MebSeaEn'] = $MebSea;
  3746. $this->data ['MebSea'] = urlencode ( $MebSea );
  3747. $this->data ['get'] = $get;
  3748. $this->data ['page'] = $pageinfo;
  3749. $this->data ['list'] = $list;
  3750. $this->data ['date'] = $date;
  3751. $this->data ['memu'] = "invoice";
  3752. $this->data ['staff'] = $this->staff;
  3753. $this->data ['receiptMemu'] = 'invoiceApproval';
  3754. $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  3755. }
  3756. /**
  3757. * 获得审批发票的信息以及审批页面
  3758. */
  3759. function ajaxGetInvoiceApprovalDetail() {
  3760. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  3761. if (empty ( $serial )) {
  3762. echo json_encode ( array (
  3763. 'status' => 2,
  3764. 'msg' => 'illegal request'
  3765. ) );
  3766. die ();
  3767. }
  3768. Doo::loadModel ( 'invoice' );
  3769. $invoice = new invoice ();
  3770. Doo::loadModel ( 'invoiceOperationLog' );
  3771. $invoiceOperationLog = new invoiceOperationLog ();
  3772. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  3773. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  3774. if (empty ( $detail ))
  3775. $html = '';
  3776. else {
  3777. $html = '
  3778. <form action="/invoiceApprovalDo" method="post" name="invoiceApproval" class="nice-validator n-yellow" novalidate="novalidate">
  3779. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  3780. <input type="hidden" name="status" value="">
  3781. <div class="modal-dialog modal-lg">
  3782. <div class="modal-content"><div class="modal-header"><h3>发票审批详情</h3></div>
  3783. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  3784. <tr>
  3785. <th class="taC" width="150">发票审批</th><td><textarea name="opinion" style="width:98%" placeholder="在这写下您的审批意见,选填。"></textarea></td>
  3786. </tr>
  3787. <tr>
  3788. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  3789. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  3790. </tr>
  3791. <tr>
  3792. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  3793. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  3794. </tr>
  3795. <tr>
  3796. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  3797. </td>
  3798. </tr>
  3799. <tr>
  3800. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  3801. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  3802. </tr>
  3803. <tr>
  3804. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  3805. </tr></tbody></table>';
  3806. if ($detail ['invoiceType'] == 0)
  3807. $html .= '<table class="table table-bordered table-condensed"><tbody>
  3808. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  3809. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  3810. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  3811. </tr>';
  3812. else
  3813. $html .= '<table class="table table-bordered table-condensed"><tbody>
  3814. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  3815. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  3816. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  3817. ';
  3818. $html .= '<tr>
  3819. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  3820. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  3821. </tr>
  3822. <tr>
  3823. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  3824. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  3825. </tr></tbody></table>';
  3826. if ($detail ['doPost'] == 1) {
  3827. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  3828. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  3829. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  3830. </tr><tr>
  3831. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  3832. </tr><tr>
  3833. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  3834. </tr>
  3835. ';
  3836. if ($detail ['expressCom'] == 'SF')
  3837. $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>';
  3838. else
  3839. $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>';
  3840. $html .= '</tbody></table>';
  3841. }
  3842. if (! empty ( $invoiceOperationLogList )) {
  3843. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  3844. foreach ( $invoiceOperationLogList as $key => $value ) {
  3845. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  3846. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  3847. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  3848. if ($value ['status'] == 2) {
  3849. $html .= '<span class="colGreen">同意</span>';
  3850. } elseif ($value ['status'] == 3) {
  3851. $html .= '<span class="colOrange">退回</span>';
  3852. } elseif ($value ['status'] == 5) {
  3853. $html .= '<span class="colGreen">打印</span>';
  3854. } elseif ($value ['status'] == 4) {
  3855. $html .= '<span class="colRed">终止</span>';
  3856. }
  3857. $html .= $value ['operation'] . '</p></blockquote>';
  3858. }
  3859. }
  3860. $html .= '</td></tr></tbody></table>';
  3861. }
  3862. $html .= '</div><div class="modal-footer">
  3863. <a href="javascript:void(0)" node-approval="approval" diss-data="2" class="button btn-done" data-placement="top" data-toggle="ctooltip" >同意</a>
  3864. <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>
  3865. <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>
  3866. <a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>
  3867. </form>
  3868. <script type="text/javascript">
  3869. $("a[node-approval^=\'approval\']").click(function() {
  3870. $("input[name=\'status\']").val($(this).attr("diss-data"));
  3871. $("form[name=\'invoiceApproval\']").submit();
  3872. });
  3873. </script>
  3874. ';
  3875. }
  3876. echo json_encode ( array (
  3877. 'status' => 1,
  3878. 'html' => $html
  3879. ) );
  3880. die ();
  3881. }
  3882. /**
  3883. * 获得审批发票分页数据
  3884. */
  3885. function ajaxGetinvoiceApprovalAchieveDevelopment() {
  3886. Doo::loadModel ( 'invoice' );
  3887. $invoice = new invoice ();
  3888. Doo::loadModel ( 'staff' );
  3889. $staff = new staff ();
  3890. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3891. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3892. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ORDINARY";
  3893. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3894. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  3895. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  3896. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  3897. $MebSea = $this->get_args ( 'search' );
  3898. $MebSea = $MebSea ['value'];
  3899. $page_size = $length;
  3900. $con = '';
  3901. if ($status == 'ALL')
  3902. $con = ' and isDelete=0 ';
  3903. elseif ($status == 'PEND')
  3904. $con = ' and isDelete=0 and status=1';
  3905. elseif ($status == 'APPROVED')
  3906. $con = ' and isDelete=0 and status=2';
  3907. if ($invoiceType == 'ORDINARY')
  3908. $con .= ' and invoiceType=0 ';
  3909. elseif ($invoiceType == 'SPECIAL')
  3910. $con .= ' and invoiceType=1 ';
  3911. if ($invoiceTrain == 'ORDINARY')
  3912. $con .= ' and trainId=0 ';
  3913. elseif ($invoiceTrain == 'TRAIN')
  3914. $con .= ' and trainId!=0 ';
  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 approvalTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  3928. elseif (! empty ( $D1 ) && empty ( $D2 ))
  3929. $con .= ' and approvalTime = "' . $D1 . '" ';
  3930. if (! empty ( $MebSea ))
  3931. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceSerial like "%' . $MebSea . '%" )';
  3932. // /
  3933. $pageinfo ['page'] = array (
  3934. 'previous' => ''
  3935. );
  3936. $sql = '(status=1 or status=2 or status=3 or status=4) ' . $con;
  3937. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", '', "" );
  3938. $limit = $page . ',' . $page_size;
  3939. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  3940. $approvalList = array ();
  3941. $html = '
  3942. <script type="text/javascript">
  3943. </script>
  3944. ';
  3945. foreach ( $list as $key => $value ) {
  3946. $irDetail = array ();
  3947. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  3948. if ($value ['invoiceType'] == 1)
  3949. array_push ( $irDetail, $value ['invoiceCompany'] );
  3950. else
  3951. array_push ( $irDetail, $value ['invoiceTitle'] );
  3952. array_push ( $irDetail, $value ['TIN'] );
  3953. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  3954. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  3955. array_push ( $irDetail, $value ['remark'] );
  3956. array_push ( $irDetail, $value ['recipients'] . $value ['recipientsPhone'] );
  3957. array_push ( $irDetail, $value ['recipientsAddress'] );
  3958. array_push ( $irDetail, $value ['mailItems'] );
  3959. array_push ( $irDetail, $value ['invoiceElement'] );
  3960. array_push ( $irDetail, $value ['invoiceQuantity'] );
  3961. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  3962. if ($value ['invoiceType'] == 1)
  3963. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  3964. else
  3965. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  3966. array_push ( $irDetail, $value ['userName'] . '&nbsp;' . $value ['date'] );
  3967. $fchtml = $value ['OL'] ['operation'];
  3968. if (count ( $list ) == $page_size)
  3969. $fchtml = $value ['OL'] ['operation'] . $html;
  3970. // 最后的审批意见
  3971. array_push ( $irDetail, $fchtml );
  3972. if ($value ['status'] == 2)
  3973. array_push ( $irDetail, '<span class="colGreen">同意</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  3974. elseif ($value ['status'] == 3)
  3975. array_push ( $irDetail, '<span class="colOrange">退回</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  3976. elseif ($value ['status'] == 4)
  3977. array_push ( $irDetail, '<span class="colRed">终止</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  3978. elseif ($value ['status'] == 1) {
  3979. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoiceApproval(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">审批发票</a>' );
  3980. } else
  3981. array_push ( $irDetail, '' );
  3982. array_push ( $approvalList, $irDetail );
  3983. }
  3984. // $approvalListJson = json_encode ( $approvalList );
  3985. $recordsFiltered = $pageinfo ['total_data'];
  3986. echo json_encode ( array (
  3987. "draw" => intval ( $draw ),
  3988. "recordsTotal" => intval ( $pageinfo ['total_data'] ),
  3989. "recordsFiltered" => intval ( $recordsFiltered ),
  3990. "data" => $approvalList
  3991. ), JSON_UNESCAPED_UNICODE );
  3992. }
  3993. /**
  3994. * 审批发票查看更多--重构
  3995. */
  3996. function invoiceApprovalAchieveDevelopment() {
  3997. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'ALL';
  3998. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3999. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ORDINARY";
  4000. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4001. /*
  4002. * Doo::loadModel ( 'invoice' ); $invoice = new invoice (); Doo::loadModel ( 'staff' ); $staff = new staff (); $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  4003. * $page_size = 12; $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4004. * $con = ''; if ($status == 'ALL') $con = ' and isDelete=0 '; elseif ($status == 'PEND') $con = ' and isDelete=0 and status=1'; elseif ($status == 'APPROVED') $con = ' and isDelete=0 and status=2';
  4005. * if ($invoiceType == 'ORDINARY') $con .= ' and invoiceType=0 '; elseif ($invoiceType == 'SPECIAL') $con .= ' and invoiceType=1 ';
  4006. * if ($invoiceTrain == 'ORDINARY') $con .= ' and trainId=0 '; elseif ($invoiceTrain == 'TRAIN') $con .= ' and trainId!=0 ';
  4007. * $dateArr = explode ( ':', $date ); $D1 = $dateString = ''; $D2 = ''; if (! empty ( $date )) { $D1 = $dateArr [0]; if (isset ( $dateArr [1] )) $D2 = $dateArr [1]; else $D2 = ''; $dateString = $D1 . " : " . $D2; } if (! empty ( $D1 ) && ! empty ( $D2 )) $con .= ' and approvalTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" '; elseif (! empty ( $D1 ) && empty ( $D2 )) $con .= ' and approvalTime = "' . $D1 . '" ';
  4008. * $get = '/' . $status . '?invoiceType=' . $invoiceType . '&invoiceTrain=' . $invoiceTrain . '&date=' . $date;
  4009. * $pageinfo ['page'] = array ( 'previous' => '' ); $sql = '(status=1 or status=2 or status=3 or status=4) ' . $con;
  4010. * $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", $get, "" );
  4011. * $limit = $pageinfo ['lower'] . ',' . $page_size;
  4012. * $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  4013. * $approvalList = array (); foreach ( $list as $key => $value ) { $irDetail = array ();
  4014. * array_push ( $irDetail, $value ['invoiceSerial'] );
  4015. * if ($value ['invoiceType'] == 1) array_push ( $irDetail, $value ['invoiceCompany'] ); else array_push ( $irDetail, $value ['invoiceTitle'] ); array_push ( $irDetail, $value ['TIN'] ); array_push ( $irDetail, $value ['address'] . $value ['phone'] ); array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] ); array_push ( $irDetail, $value ['remark'] ); array_push ( $irDetail, $value ['recipients'] . $value ['recipientsPhone'] ); array_push ( $irDetail, $value ['recipientsAddress'] ); array_push ( $irDetail, $value ['mailItems'] ); array_push ( $irDetail, $value ['invoiceElement'] ); array_push ( $irDetail, $value ['invoiceQuantity'] ); array_push ( $irDetail, $value ['invoiceUnitPrice'] ); if ($value ['invoiceType'] == 1) array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' ); else array_push ( $irDetail, '¥' . $value ['invoicePrice'] ); array_push ( $irDetail, $value ['userName'] . '&nbsp;' . $value ['date'] );
  4016. * // 最后的审批意见 array_push ( $irDetail, $value ['OL'] ['operation'] );
  4017. * if ($value ['status'] == 2) array_push ( $irDetail, '<span class="colGreen">同意</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] ); elseif ($value ['status'] == 3) array_push ( $irDetail, '<span class="colOrange">退回</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] ); elseif ($value ['status'] == 4) array_push ( $irDetail, '<span class="colRed">终止</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] ); elseif ($value ['status'] == 1) array_push ( $irDetail, '<a href="#approvalInvice" data-toggle="modal">审批发票</a>' ); else array_push ( $irDetail, '' ); array_push ( $approvalList, $irDetail ); } $approvalListJson = json_encode ( $approvalList ); //print_r($pageinfo); $this->data ['approvalListJson'] = $approvalListJson;
  4018. * // print_r($list);
  4019. * $this->data ['MebSeaEn'] = $MebSea; $this->data ['MebSea'] = urlencode ( $MebSea ); $this->data ['get'] = $get; $this->data ['page'] = $pageinfo; $this->data ['list'] = $list;
  4020. */
  4021. $this->data ['dateString'] = $date;
  4022. $this->data ['status'] = $status;
  4023. $this->data ['invoiceType'] = $invoiceType;
  4024. $this->data ['invoiceTrain'] = $invoiceTrain;
  4025. $this->data ['memu'] = "invoice";
  4026. $this->data ['staff'] = $this->staff;
  4027. $this->data ['receiptMemu'] = 'invoiceApproval';
  4028. $this->render ( "/admin/invoiceApprovalAchieveDevelopment", $this->data );
  4029. }
  4030. function invoiceTAchieve() {
  4031. Doo::loadModel ( 'invoice' );
  4032. $invoice = new invoice ();
  4033. Doo::loadClass ( 'XDeode' );
  4034. $XDeode = new XDeode ( 5 );
  4035. Doo::loadModel ( 'staff' );
  4036. $staff = new staff ();
  4037. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  4038. $page_size = 12;
  4039. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4040. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4041. $get = "/" . $date;
  4042. $con = '';
  4043. if ($date == 'MONTHO')
  4044. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4045. elseif ($date == 'MONTHT')
  4046. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4047. elseif ($date == 'MONTHY')
  4048. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4049. if (! empty ( $MebSea )) {
  4050. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4051. $get .= "/" . $MebSea;
  4052. }
  4053. $pageinfo ['page'] = array (
  4054. 'previous' => ''
  4055. );
  4056. $sql = "";
  4057. $action = "";
  4058. if ($this->ACTION == 'invoicePrintAchieve') {
  4059. $sql = "status=2 and printStatus=1 and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  4060. $action = "invoicePrintAchieve";
  4061. } elseif ($this->ACTION == 'invoicePostAchieve') {
  4062. // and untreadStatus=0
  4063. $sql = "postStatus=1 and doPost=1 and status=2 and isDelete=0" . $con;
  4064. $action = "invoicePostAchieve";
  4065. } elseif ($this->ACTION == 'invoiceUntreadAchieve') { // printStatus=1 and
  4066. $sql = " untreadStatus=2 and status=2 " . $con;
  4067. $action = "invoiceUntreadAchieve";
  4068. }
  4069. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  4070. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4071. $this->data ['MebSeaEn'] = $MebSea;
  4072. $this->data ['MebSea'] = urlencode ( $MebSea );
  4073. $this->data ['get'] = $get;
  4074. $this->data ['page'] = $pageinfo;
  4075. $this->data ['date'] = $date;
  4076. $this->data ['memu'] = "invoice";
  4077. $this->data ['staff'] = $this->staff;
  4078. if ($this->ACTION == 'invoicePrintAchieve') {
  4079. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  4080. $this->data ['receiptMemu'] = 'invoicePrint';
  4081. $this->data ['list'] = $list;
  4082. $this->render ( "/admin/invoicePrintAchieve", $this->data );
  4083. } elseif ($this->ACTION == 'invoicePostAchieve') {
  4084. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  4085. Doo::loadModel ( 'express' );
  4086. $express = new express ();
  4087. $expressList = $express->getExpressByAll ();
  4088. $this->data ['expressList'] = $expressList;
  4089. $this->data ['receiptMemu'] = 'invoicePost';
  4090. $this->data ['list'] = $list;
  4091. $this->render ( "/admin/invoicePostAchieve", $this->data );
  4092. } elseif ($this->ACTION == 'invoiceUntreadAchieve') {
  4093. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  4094. $this->data ['receiptMemu'] = 'invoiceUntread';
  4095. $this->data ['list'] = $list;
  4096. $this->render ( "/admin/invoiceUntreadAchieve", $this->data );
  4097. }
  4098. }
  4099. /**
  4100. *
  4101. * @deprecated 获得与我有关可收款的发票 废弃 function ajaxGetInvoiceByStaff() { $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : ""; Doo::loadModel ( 'invoice' ); $invoice = new invoice (); $list = $invoice->getInvoiceByReceivables ( $this->staff [0] ['sid'] ); $html = ""; $i = 1; foreach ( $list as $key => $value ) { $html .= '<tr> <td>' . $value ['invoiceElement'] . '</td> <td>¥' . $value ['invoicePrice'] . '</td>'; if (! empty ( $value ['invoiceType'] )) { $html .= '<td>增值税专用发票</td> <td>' . $value ['invoiceCompany'] . '</td>'; } else { $html .= '<td>增值税普通发票</td> <td>' . $value ['invoiceTitle'] . '</td>'; } $html .= '<td><label><input type="radio" node-Claim="true_' . $i . '" p-data="' . $value ['iidKey'] . '" name="invoiceClaim"> 使用Ta</label></td></tr> <script> $(\'input[node-Claim="true_' . $i . '"]\').click(function() { var invoiceKey= $(this).attr("p-data"); var claimKey=$("input[name=\'key\']").val(); $("p[node-msg=\"true\"]").hide(); var url = "/ajaxCompareInvoicePrice"; $.ajax({ url : url, type : "post", cache : false, dataType : "json", data : { claimKey : claimKey, invoiceKey:invoiceKey }, global : true, success : function(data) { $("input[name=\'invoiceKey\']").val("' . $value ['iidKey'] . '"); if (data.status == 1) { $("p[node-msg=\"true\"]").html("收款金额超出开票金额 ¥"+data.price+"元,请谨慎操作。"); $("p[node-msg=\"true\"]").show(); } }, error : function(err) { } }); }); </script> '; $i ++; } echo json_encode ( array ( 'status' => 1, 'html' => $html ) ); }
  4102. */
  4103. /**
  4104. * 获取一条收款信息
  4105. */
  4106. function ajaxGetInvoiceReceivables() {
  4107. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  4108. Doo::loadModel ( 'invoiceReceivables' );
  4109. $invoiceReceivables = new invoiceReceivables ();
  4110. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4111. echo json_encode ( array (
  4112. 'status' => 1,
  4113. 'detail' => $detail
  4114. ) );
  4115. }
  4116. /**
  4117. * 异步获取办事处用户
  4118. */
  4119. function ajaxGetStaffByCategory() {
  4120. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "";
  4121. Doo::loadModel ( 'staff' );
  4122. $staff = new staff ();
  4123. if ($cid == "PUBLIC") {
  4124. echo json_encode ( array (
  4125. 'status' => 1,
  4126. 'html' => '<option value="PUBLIC">办事处待认领款项</option>'
  4127. ) );
  4128. die ();
  4129. }
  4130. if (! is_numeric ( $cid )) {
  4131. echo json_encode ( array (
  4132. 'status' => 0,
  4133. 'msg' => 'illegal request'
  4134. ) );
  4135. die ();
  4136. }
  4137. $staffList = $staff->getStaffByCid ( $cid );
  4138. $html = '<option value="PUBLIC">办事处待认领款项</option>';
  4139. foreach ( $staffList as $key => $value ) {
  4140. $html .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  4141. }
  4142. echo json_encode ( array (
  4143. 'status' => 1,
  4144. 'html' => $html
  4145. ) );
  4146. }
  4147. /**
  4148. * 异步获取一条发票的邮寄信息
  4149. */
  4150. function ajaxGetInvoicePostDetail() {
  4151. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  4152. Doo::loadModel ( 'invoice' );
  4153. $invoice = new invoice ();
  4154. $iid = $invoice->authcode ( $iid );
  4155. Doo::loadModel ( 'express' );
  4156. $express = new express ();
  4157. $expressList = $express->getExpressByAll ();
  4158. if (! is_numeric ( $iid )) {
  4159. echo json_encode ( array (
  4160. 'status' => 0,
  4161. 'msg' => 'illegal request'
  4162. ) );
  4163. die ();
  4164. }
  4165. $select = "iid,recipients,recipientsPhone,recipientsAddress,mailItems,expressCompany,expressNumber,actualItems";
  4166. $invoiceDetail = $invoice->getInvoiceByIid ( $iid, $select );
  4167. $html = "";
  4168. foreach ( $expressList as $key => $value ) {
  4169. if ($value ['company'] == $invoiceDetail ['expressCompany'])
  4170. $html .= '<option selected value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  4171. else
  4172. $html .= '<option value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  4173. }
  4174. $invoiceDetail ['eaHtml'] = $html;
  4175. echo json_encode ( array (
  4176. 'status' => 1,
  4177. 'invoiceDetail' => $invoiceDetail
  4178. ) );
  4179. }
  4180. /**
  4181. *
  4182. * @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 ) ); }
  4183. */
  4184. /**
  4185. *
  4186. * @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 ) ); }
  4187. */
  4188. /**
  4189. * 我的收款中 选择哪个发票入账,进行金额判断
  4190. */
  4191. function ajaxCompareInvoicePrice() {
  4192. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  4193. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  4194. Doo::loadModel ( 'invoice' );
  4195. $invoice = new invoice ();
  4196. Doo::loadModel ( 'invoiceReceivables' );
  4197. $invoiceReceivables = new invoiceReceivables ();
  4198. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  4199. $keyList = explode ( ';', $claimKey );
  4200. $receivablesPrice = 0;
  4201. foreach ( $keyList as $key => $value ) {
  4202. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $value );
  4203. $receivablesPrice += $detailM ['receivablesPrice'];
  4204. }
  4205. if ($receivablesPrice > $detail ['invoicePrice']) {
  4206. $price = $receivablesPrice - $detail ['invoicePrice'];
  4207. echo json_encode ( array (
  4208. 'status' => 1,
  4209. 'price' => $price
  4210. ) );
  4211. } else
  4212. echo json_encode ( array (
  4213. 'status' => 2
  4214. ) );
  4215. }
  4216. /**
  4217. * 获得打印发票
  4218. */
  4219. function ajaxGetInvoiceInfoByPrint() {
  4220. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  4221. if (empty ( $serial )) {
  4222. echo json_encode ( array (
  4223. 'status' => 2,
  4224. 'msg' => 'illegal request'
  4225. ) );
  4226. die ();
  4227. }
  4228. Doo::loadModel ( 'invoice' );
  4229. $invoice = new invoice ();
  4230. Doo::loadModel ( 'invoiceOperationLog' );
  4231. $invoiceOperationLog = new invoiceOperationLog ();
  4232. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  4233. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  4234. if (empty ( $detail ))
  4235. $html = '';
  4236. else {
  4237. $html = '
  4238. <form action="/invoicePrintDo" method="post" name="invoicePrint" class="nice-validator n-yellow" onSubmit="return checkPrintForm()" novalidate="novalidate">
  4239. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  4240. <div class="modal-dialog modal-lg">
  4241. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  4242. <div class="modal-body saeaList">
  4243. <table class="table table-bordered table-condensed"><tbody>
  4244. <tr>
  4245. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  4246. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  4247. </tr>
  4248. <tr>
  4249. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  4250. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  4251. </tr>
  4252. <tr>
  4253. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  4254. </td>
  4255. </tr>
  4256. <tr>
  4257. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  4258. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  4259. </tr>
  4260. <tr>
  4261. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  4262. </tr></tbody></table>';
  4263. if ($detail ['invoiceType'] == 0)
  4264. $html .= '<table class="table table-bordered table-condensed"><tbody>
  4265. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  4266. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  4267. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  4268. </tr>';
  4269. else
  4270. $html .= '<table class="table table-bordered table-condensed"><tbody>
  4271. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  4272. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  4273. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  4274. ';
  4275. $html .= '<tr>
  4276. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  4277. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  4278. </tr>
  4279. <tr>
  4280. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  4281. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  4282. </tr></tbody></table>';
  4283. if ($detail ['doPost'] == 1)
  4284. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  4285. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  4286. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  4287. </tr><tr>
  4288. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  4289. </tr><tr>
  4290. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  4291. </tr></tbody></table>';
  4292. if (! empty ( $invoiceOperationLogList )) {
  4293. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th><th class="taC">发票打印</th></tr><tr><td>';
  4294. foreach ( $invoiceOperationLogList as $key => $value ) {
  4295. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  4296. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  4297. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  4298. if ($value ['status'] == 2) {
  4299. $html .= '<span class="colGreen">同意</span>';
  4300. } elseif ($value ['status'] == 3) {
  4301. $html .= '<span class="colOrange">退回</span>';
  4302. } elseif ($value ['status'] == 5) {
  4303. $html .= '<span class="colGreen">打印</span>';
  4304. } elseif ($value ['status'] == 4) {
  4305. $html .= '<span class="colRed">终止</span>';
  4306. }
  4307. $html .= $value ['operation'] . '</p></blockquote>';
  4308. }
  4309. }
  4310. $html .= '</td>
  4311. <td><span class="colRed">*</span>No.<input name="invoiceNo" id="invoiceNo" value="" type="text" placeholder="输入发票号" aria-required="true" aria-invalid="true" class="n-invalid">
  4312. <span class="red" id="p-msg"></span>
  4313. </td>
  4314. </tr></tbody></table>';
  4315. }
  4316. $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>
  4317. </div></div></form>
  4318. <link rel=stylesheet href="' . WEB_SITE_GLOBAL . 'css/jquery.validator.css">
  4319. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/jquery.validator.min.js"></script>
  4320. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/zh-CN.js"></script>
  4321. <script src="' . WEB_SITE_GLOBAL . 'js/invoice.validator.js"></script>
  4322. ';
  4323. }
  4324. echo json_encode ( array (
  4325. 'status' => 1,
  4326. 'html' => $html
  4327. ) );
  4328. die ();
  4329. }
  4330. /**
  4331. * @ 获得与我有关收款数据 --需求变更 废弃 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 ) ); }
  4332. */
  4333. function ajaxGetInvoiceInfoByType() {
  4334. $type = $this->get_args ( 'type' ) ? $this->get_args ( 'type' ) : "";
  4335. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  4336. $loss = $this->get_args ( 'loss' ) ? $this->get_args ( 'loss' ) : false;
  4337. if (empty ( $serial )) {
  4338. echo json_encode ( array (
  4339. 'status' => 2,
  4340. 'msg' => 'illegal request'
  4341. ) );
  4342. die ();
  4343. }
  4344. if ($type == 'INVOICE') {
  4345. Doo::loadModel ( 'invoice' );
  4346. $invoice = new invoice ();
  4347. Doo::loadModel ( 'invoiceOperationLog' );
  4348. $invoiceOperationLog = new invoiceOperationLog ();
  4349. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  4350. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  4351. if (empty ( $detail ))
  4352. $html = '';
  4353. else {
  4354. $html = '
  4355. <div class="modal-dialog modal-lg">
  4356. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  4357. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  4358. <tr>
  4359. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  4360. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  4361. </tr>
  4362. <tr>
  4363. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  4364. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  4365. </tr>
  4366. <tr>
  4367. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  4368. </td>
  4369. </tr>
  4370. <tr>
  4371. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  4372. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  4373. </tr>
  4374. <tr>
  4375. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  4376. </tr></tbody></table>';
  4377. if ($detail ['invoiceType'] == 0)
  4378. $html .= '<table class="table table-bordered table-condensed"><tbody>
  4379. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  4380. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  4381. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  4382. </tr>';
  4383. else
  4384. $html .= '<table class="table table-bordered table-condensed"><tbody>
  4385. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  4386. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  4387. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  4388. ';
  4389. $html .= '<tr>
  4390. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  4391. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  4392. </tr>
  4393. <tr>
  4394. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  4395. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  4396. </tr></tbody></table>';
  4397. if ($detail ['doPost'] == 1) {
  4398. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  4399. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  4400. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  4401. </tr><tr>
  4402. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  4403. </tr><tr>
  4404. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  4405. </tr>
  4406. ';
  4407. if ($detail ['expressCom'] == 'SF')
  4408. $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>';
  4409. else
  4410. $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>';
  4411. $html .= '</tbody></table>';
  4412. }
  4413. if (! empty ( $invoiceOperationLogList )) {
  4414. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  4415. foreach ( $invoiceOperationLogList as $key => $value ) {
  4416. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  4417. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  4418. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  4419. if ($value ['status'] == 2) {
  4420. $html .= '<span class="colGreen">同意</span>';
  4421. } elseif ($value ['status'] == 3) {
  4422. $html .= '<span class="colOrange">退回</span>';
  4423. } elseif ($value ['status'] == 5) {
  4424. $html .= '<span class="colGreen">打印</span>';
  4425. } elseif ($value ['status'] == 4) {
  4426. $html .= '<span class="colRed">终止</span>';
  4427. }
  4428. $html .= $value ['operation'] . '</p></blockquote>';
  4429. }
  4430. }
  4431. $html .= '</td></tr></tbody></table>';
  4432. }
  4433. $html .= '</div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  4434. }
  4435. echo json_encode ( array (
  4436. 'status' => 1,
  4437. 'html' => $html
  4438. ) );
  4439. die ();
  4440. } elseif ($type == 'RECEIVABLES') {
  4441. Doo::loadModel ( 'invoiceReceivables' );
  4442. $invoiceReceivables = new invoiceReceivables ();
  4443. //
  4444. $detail = $invoiceReceivables->getInvoiceReceivablesByIrsid ( $serial );
  4445. if (empty ( $detail ))
  4446. $html = '';
  4447. else {
  4448. $html = '<div class="modal-dialog modal-lg"><div class="modal-content"><div class="modal-header"><h3>收款单详情</h3></div><div class="modal-body saeaList"><table class="table table-bordered table-condensed">
  4449. <tbody><tr>
  4450. <th class="taC">收款流水号</th><td>' . $detail ['receivablesSerial'] . '</td>
  4451. <th class="taC">录入收款</th><td>' . $detail ['inputStaff'] . ' ' . $detail ['date'] . '</td>
  4452. </tr><tr>
  4453. <th class="taC">收款金额</th><td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  4454. <th class="taC">收款信息</th><td>' . $detail ['receivablesMessage'] . '</td>
  4455. </tr>
  4456. <tr>
  4457. <th class="taC">收款银行</th><td>' . $detail ['receivablesBank'] . '</td>
  4458. <th class="taC">银行到账</th><td>' . $detail ['receivablesDate'] . '</td>
  4459. </tr>
  4460. <tr>
  4461. <th class="taC">认领收款</th><td colspan="3">' . $detail ['inputStaff'] . ' 转入 ' . $detail ['username'] . ' ' . $detail ['confirmTime'] . '</td>
  4462. </tr>
  4463. </tbody></table></div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  4464. }
  4465. echo json_encode ( array (
  4466. 'status' => 1,
  4467. 'html' => $html
  4468. ) );
  4469. die ();
  4470. } elseif ($type == 'IRTC') {
  4471. Doo::loadModel ( 'invoice' );
  4472. $invoice = new invoice ();
  4473. Doo::loadModel ( 'invoiceOperationLog' );
  4474. $invoiceOperationLog = new invoiceOperationLog ();
  4475. Doo::loadModel ( 'invoiceReceivables' );
  4476. $invoiceReceivables = new invoiceReceivables ();
  4477. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  4478. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  4479. if (empty ( $detail ))
  4480. $html = '';
  4481. else {
  4482. $receivablesPriceedHtml = '';
  4483. $receivablesPrice = $detail ['invoicePrice'];
  4484. if (! empty ( $detail ['irid'] )) {
  4485. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $detail ['irid'] );
  4486. if (empty ( $irList ))
  4487. $irList [0] ['sumPrice'] = 0;
  4488. $balance = $detail ['invoicePrice'] - $irList [0] ['sumPrice'];
  4489. $receivablesPriceedHtml = '<table class="table table-bordered table-condensed"><tbody><tr>
  4490. <th class="taC">已入账金额</th><td><b class="colGreen" style="font-size:18px">¥' . $irList [0] ['sumPrice'] . '</b></td>
  4491. <th class="taC">剩余入账金额</th><td><b class="colRed" style="font-size:18px">¥' . $balance . '</b></td>
  4492. </tr></tbody></table>';
  4493. $receivablesPrice = $balance;
  4494. }
  4495. if ($loss)
  4496. $detail ['invoicePrice'] = - $detail ['invoicePrice'];
  4497. $html = $receivablesPriceedHtml . '
  4498. <table class="table table-bordered table-condensed"><tbody>
  4499. <tr>
  4500. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  4501. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  4502. </tr>
  4503. <tr>
  4504. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  4505. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  4506. </tr>
  4507. <tr>
  4508. <th class="taC" width="150">发票备注</th><td colspan="3">' . $detail ['remark'] . '</td>
  4509. </tr>
  4510. <tr>
  4511. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  4512. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  4513. </tr>
  4514. <tr>
  4515. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  4516. </tr></tbody></table>';
  4517. if ($detail ['invoiceType'] == 0) {
  4518. $html .= '<table class="table table-bordered table-condensed"><tbody>
  4519. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  4520. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  4521. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  4522. </tr>';
  4523. $receivablesMessage = $detail ['invoiceTitle'];
  4524. } else {
  4525. $html .= '<table class="table table-bordered table-condensed"><tbody>
  4526. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  4527. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  4528. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  4529. ';
  4530. $receivablesMessage = $detail ['invoiceCompany'];
  4531. }
  4532. $html .= '<tr>
  4533. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  4534. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  4535. </tr>
  4536. <tr>
  4537. <th class="taC">开户银行</th><td>' . $detail ['bankAccount'] . '</td>
  4538. <th class="taC">银行账号</th><td>' . $detail ['bank'] . '</td>
  4539. </tr></tbody></table>';
  4540. if ($detail ['doPost'] == 1)
  4541. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  4542. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  4543. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  4544. </tr><tr>
  4545. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  4546. </tr><tr>
  4547. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  4548. </tr></tbody></table>';
  4549. if (! empty ( $invoiceOperationLogList )) {
  4550. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  4551. foreach ( $invoiceOperationLogList as $key => $value ) {
  4552. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  4553. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  4554. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  4555. if ($value ['status'] == 2) {
  4556. $html .= '<span class="colGreen">同意</span>';
  4557. } elseif ($value ['status'] == 3) {
  4558. $html .= '<span class="colOrange">退回</span>';
  4559. } elseif ($value ['status'] == 5) {
  4560. $html .= '<span class="colGreen">打印</span>';
  4561. }
  4562. $html .= $value ['operation'] . '</p></blockquote>';
  4563. }
  4564. }
  4565. $html .= '</td></tr></tbody></table>';
  4566. }
  4567. }
  4568. echo json_encode ( array (
  4569. 'status' => 1,
  4570. 'html' => $html,
  4571. 'receivablesPrice' => $receivablesPrice,
  4572. 'receivablesMessage' => $receivablesMessage,
  4573. 'receivablesDate' => date ( "Y-m-d" ),
  4574. 'iidKey' => $serial
  4575. ) );
  4576. die ();
  4577. }
  4578. }
  4579. function ajaxGetInvoiceReceivablesByStaff() {
  4580. $postData = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : "";
  4581. if (empty ( $postData )) {
  4582. echo json_encode ( array (
  4583. 'status' => 2,
  4584. 'msg' => 'illegal request'
  4585. ) );
  4586. die ();
  4587. }
  4588. Doo::loadModel ( 'invoiceReceivables' );
  4589. $invoiceReceivables = new invoiceReceivables ();
  4590. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $postData );
  4591. if (empty ( $detail )) {
  4592. echo json_encode ( array (
  4593. 'status' => 2,
  4594. 'msg' => 'illegal request'
  4595. ) );
  4596. die ();
  4597. }
  4598. Doo::loadModel ( 'L_category' );
  4599. $lCategory = new L_category ();
  4600. Doo::loadModel ( 'staff' );
  4601. $staff = new staff ();
  4602. $staffList = $staff->getStaffByCid ( $detail ['cid'] );
  4603. $category = $lCategory->getCategory ();
  4604. $categoryHtml = '<option post-data="PUBLIC" value="PUBLIC" >公共待认领款项</option>';
  4605. $staffHtml = '<option value="PUBLIC">办事处待认领款项</option>';
  4606. foreach ( $category as $key => $value ) {
  4607. $categoryHtml .= '<option post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  4608. if ($value ['cid'] == $detail ['cid'])
  4609. $categoryHtml .= '<option selected post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  4610. }
  4611. foreach ( $staffList as $key => $value ) {
  4612. $staffHtml .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  4613. if ($value ['sid'] == $detail ['sid'])
  4614. $staffHtml .= '<option selected value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  4615. }
  4616. $rbankHtml = '<option value="广发银行珠海分行柠溪支行">广发银行珠海分行柠溪支行</option>';
  4617. echo json_encode ( array (
  4618. 'status' => 1,
  4619. 'categoryHtml' => $categoryHtml,
  4620. 'staffHtml' => $staffHtml,
  4621. 'rbankHtml' => $rbankHtml,
  4622. 'detail' => $detail
  4623. ) );
  4624. }
  4625. function ajaxGetInvoiceReceivablesByIrid() {
  4626. $irid = $this->get_args ( 'irid' ) ? $this->get_args ( 'irid' ) : "";
  4627. if (empty ( $irid )) {
  4628. echo json_encode ( array (
  4629. 'status' => 2,
  4630. 'msg' => 'illegal request'
  4631. ) );
  4632. die ();
  4633. }
  4634. Doo::loadModel ( 'invoiceReceivables' );
  4635. $invoiceReceivables = new invoiceReceivables ();
  4636. Doo::loadModel ( 'invoice' );
  4637. $invoice = new invoice ();
  4638. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid ); // 入账完成 待定 and postStatus=1
  4639. $flag = true;
  4640. $invoiceDetail = $invoice->getInvoiceByTitle ( $detail ['recepitTitleMark'], 'EXACTLY', " and status=2 and printStatus=1 and untreadStatus=0 ", $flag ); //
  4641. $bakDetail = array ();
  4642. if ($flag === false) {
  4643. array_push ( $bakDetail, $invoiceDetail );
  4644. $invoiceDetail = $bakDetail;
  4645. }
  4646. $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>
  4647. <tr>
  4648. <td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  4649. <td>' . $detail ['receivablesMessage'] . '</td>
  4650. <td>' . $detail ['receivablesBank'] . '<br>' . $detail ['receivablesDate'] . '</td>
  4651. <td>' . $detail ['title'] . '-' . $detail ['username'] . '<br>' . $detail ['confirmTime'] . '</td>
  4652. <td>' . $detail ['recepitTitleMark'] . '</td>
  4653. </tr></tbody></table>';
  4654. $isInvoice = false;
  4655. $invoiceHtml = '';
  4656. if (empty ( $invoiceDetail )) {
  4657. $isInvoice = true;
  4658. } else {
  4659. $invoiceHtml = '<table class="table table-bordered table-condensed">
  4660. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody>';
  4661. foreach ( $invoiceDetail as $key => $value ) {
  4662. $invoiceHtml .= '<tr>';
  4663. if (! empty ( $value ['invoiceType'] )) {
  4664. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  4665. } else {
  4666. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  4667. }
  4668. if (! empty ( $value ['invoiceType'] )) {
  4669. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  4670. } else {
  4671. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  4672. }
  4673. $invoiceHtml .= '
  4674. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  4675. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  4676. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir" data-ikey="' . $value ['iidKey'] . '" href="javascript:void(0)">入账</a></td>
  4677. </tr>
  4678. ';
  4679. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  4680. if (empty ( $irList ))
  4681. $irList [0] ['sumPrice'] = 0;
  4682. $balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  4683. $priceString = '';
  4684. if ($balance < $detail ['receivablesPrice']) {
  4685. $priceString = '收款金额超过开票金额,';
  4686. }
  4687. if ($balance > $detail ['receivablesPrice']) {
  4688. $priceString = '收款金额低于开票金额,';
  4689. }
  4690. }
  4691. $invoiceHtml .= '
  4692. <script>
  4693. $(\'a[bind-receivables^="ir"]\').click(function() {
  4694. var data = $(this).attr("data-ikey");
  4695. $("input[name=\'invoiceKey\']").val(data);
  4696. var invoiceKey=data;
  4697. if(invoiceKey==""){
  4698. alert("入账错误,请重新刷新页面");
  4699. return false;
  4700. }
  4701. if(window.confirm("' . $priceString . '确定入账吗?")){
  4702. $("#IBR").submit();
  4703. }else{
  4704. return false;
  4705. }
  4706. });
  4707. </script>
  4708. ';
  4709. $invoiceHtml .= '</tbody></table>';
  4710. }
  4711. echo json_encode ( array (
  4712. 'status' => 1,
  4713. 'irkey' => $detail ['iridEn'],
  4714. 'receivablesHtml' => $receivablesHtml,
  4715. 'isInvoice' => $isInvoice,
  4716. 'invoiceHtml' => $invoiceHtml
  4717. ) );
  4718. }
  4719. function ajaxGetInvoiceReceivablesByTitle() {
  4720. $title = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  4721. if (empty ( $title )) {
  4722. echo json_encode ( array (
  4723. 'status' => 2,
  4724. 'msg' => 'illegal request'
  4725. ) );
  4726. die ();
  4727. }
  4728. Doo::loadModel ( 'invoice' );
  4729. $invoice = new invoice ();
  4730. $invoiceDetail = $invoice->getInvoiceByTitle ( $title, 'FUZZY', " and status=2 and printStatus=1 and untreadStatus=0 and irid='' ", true );
  4731. $invoiceHtml = '';
  4732. if (! empty ( $invoiceDetail )) {
  4733. $invoiceHtml = '<table class="table table-bordered table-condensed">
  4734. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody><tr>';
  4735. foreach ( $invoiceDetail as $key => $value ) {
  4736. if (! empty ( $value ['invoiceType'] )) {
  4737. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  4738. } else {
  4739. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  4740. }
  4741. if (! empty ( $value ['invoiceType'] )) {
  4742. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  4743. } else {
  4744. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  4745. }
  4746. $invoiceHtml .= '
  4747. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  4748. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  4749. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir' . $value ['iidKeyXD'] . '" data-ikey="' . $value ['iidKey'] . '" href="#">入账</a></td>
  4750. </tr>
  4751. ';
  4752. }
  4753. $invoiceHtml .= '</tbody></table>
  4754. <script>
  4755. $(\'a[bind-receivables^="ir"]\').click(function() {
  4756. var data = $(this).attr("data-ikey");
  4757. $("input[name=\'invoiceKey\']").val(data);
  4758. var invoiceKey=$("input[name=\'invoiceKey\']").val();
  4759. if(invoiceKey==""){
  4760. alert("入账错误,请重新刷新页面");
  4761. return false;
  4762. }
  4763. if(window.confirm("确定入账吗?")){
  4764. $("#IBR").submit();
  4765. }else{
  4766. return false;
  4767. }
  4768. });
  4769. </script>
  4770. ';
  4771. }
  4772. echo json_encode ( array (
  4773. 'status' => 1,
  4774. 'invoiceHtml' => $invoiceHtml
  4775. ) );
  4776. }
  4777. function ajaxInvoicePushNotice() {
  4778. Doo::loadModel ( 'invoice' );
  4779. $invoice = new invoice ();
  4780. $approval = $invoice->getOne ( array (
  4781. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  4782. 'desc' => 'iid',
  4783. 'asArray' => true
  4784. ) );
  4785. $isNotice = false;
  4786. if (! empty ( $approval ))
  4787. $isNotice = true;
  4788. $response = array (
  4789. 'error' => 0,
  4790. 'isNotice' => $isNotice
  4791. );
  4792. echo json_encode ( $response );
  4793. exit ();
  4794. }
  4795. public function ajaxCheckInvoiceNoUniqueness() {
  4796. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  4797. Doo::loadModel ( 'invoice' );
  4798. $invoice = new invoice ();
  4799. if (! empty ( $invoiceNo )) {
  4800. $info = $invoice->getOne ( array (
  4801. 'where' => "invoiceNo = '" . $invoiceNo . "'",
  4802. 'asArray' => TRUE
  4803. ) );
  4804. if (! empty ( $info )) {
  4805. echo json_encode ( array (
  4806. 'error' => '发票号已存在'
  4807. ) );
  4808. die ();
  4809. } else
  4810. echo json_encode ( array (
  4811. 'ok' => '可以使用!'
  4812. ) );
  4813. die ();
  4814. }
  4815. }
  4816. function ajaxCheckInvoicePrice() {
  4817. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) && is_numeric ( $this->get_args ( 'receivablesPrice' ) ) ? $this->get_args ( 'receivablesPrice' ) : "";
  4818. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  4819. Doo::loadModel ( 'invoice' );
  4820. $invoice = new invoice ();
  4821. Doo::loadModel ( 'invoiceReceivables' );
  4822. $invoiceReceivables = new invoiceReceivables ();
  4823. Doo::loadClass ( 'XDeode' );
  4824. $XDeode = new XDeode ( 5 );
  4825. if (! empty ( $receivablesPrice ) && ! empty ( $iidKey )) {
  4826. $iidKey = $XDeode->decode ( $iidKey );
  4827. $info = $invoice->getInvoiceByIid ( $iidKey );
  4828. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $info ['irid'] );
  4829. if (empty ( $irList ))
  4830. $irList [0] ['sumPrice'] = 0;
  4831. $balance = $info ['invoicePrice'] - $irList [0] ['sumPrice'];
  4832. if ($balance < $receivablesPrice) {
  4833. echo json_encode ( array (
  4834. 'error' => '收款金额超过开票金额。'
  4835. ) );
  4836. die ();
  4837. }
  4838. if ($balance > $receivablesPrice) {
  4839. echo json_encode ( array (
  4840. 'error' => '收款金额低于开票金额。'
  4841. ) );
  4842. die ();
  4843. }
  4844. }
  4845. }
  4846. /**
  4847. * 旧输入导入
  4848. */
  4849. function importInvoice() {
  4850. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  4851. $data ['emsg'] = "";
  4852. if ($emsg != "")
  4853. $data ['emsg'] = "请填写完整的数据";
  4854. $data ['time'] = time ();
  4855. $this->render ( "/admin/invoiceImport", $data );
  4856. }
  4857. function uploadInvoice() {
  4858. // move_uploaded_file($_FILES['Filedata']['tmp_name'], "/upload/".$_FILES['Filedata']['name']);
  4859. if (isset ( $_FILES ['Filedata'] ['name'] )) {
  4860. $file = $_FILES ['Filedata'] ['tmp_name'];
  4861. $error = false;
  4862. if (! is_uploaded_file ( $file )) {
  4863. $error = '400 Bad Request';
  4864. }
  4865. if ($error) {
  4866. header ( 'HTTP/1.0 ' . $error );
  4867. die ( 'Error ' . $error );
  4868. } else {
  4869. include (DOO::conf ()->SITE_PATH . 'protected/plugin/io.han.php');
  4870. $this->IoHandler = new IoHandler ();
  4871. $pics = explode ( '.', $_FILES ['Filedata'] ['name'] );
  4872. // $filedir=$_POST['time'];
  4873. // 调用定义物理路径
  4874. $t = DOO::conf ()->SITE_PATH . "upload/invoice/";
  4875. $this->IoHandler->MakeDir ( $t );
  4876. $filename = $this->_GetFileEXT ( $_FILES ['Filedata'] ['name'] );
  4877. if ($filename != 'xlsx')
  4878. return "";
  4879. // $upload_dir = $t."/".time().rand(10,100).".".$filename;
  4880. $upload_file = iconv ( "UTF-8", "GB2312", $_FILES ["Filedata"] ["name"] );
  4881. $upload_dir = $t . "/" . $upload_file;
  4882. $k = move_uploaded_file ( $file, $upload_dir );
  4883. if ($k) {
  4884. $m = round ( $_FILES ['Filedata'] ['size'] / 1024 / 1024, 2 );
  4885. echo $pics [0] . "." . $filename . "#" . $m . "#" . $_FILES ['Filedata'] ['size'];
  4886. }
  4887. }
  4888. }
  4889. }
  4890. function importInvoiceDo() {
  4891. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  4892. if ($path != "") {
  4893. Doo::loadModel ( 'invoice' );
  4894. Doo::loadModel ( 'staff' );
  4895. $staff = new staff ();
  4896. Doo::loadModel ( 'invoiceStatistics' );
  4897. Doo::loadModel ( 'invoiceOperationLog' );
  4898. echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  4899. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . $path );
  4900. // print_r ( $exlArray );
  4901. // die ();
  4902. // echo json_encode($exlArray);die;
  4903. foreach ( $exlArray as $key => $value ) {
  4904. // 开票
  4905. $invoice = new invoice ();
  4906. $invoice->invoiceNo = $value ['invoiceNo'];
  4907. $invoice->invoiceType = 0;
  4908. if ($value ['invoiceType'] == '专')
  4909. $invoice->invoiceType = 1;
  4910. $invoice->invoicePrice = $value ['invoicePrice'];
  4911. $invoice->invoiceQuantity = 1;
  4912. $invoice->invoiceUnitPrice = $value ['invoicePrice'];
  4913. $invoice->invoiceTitle = $value ['invoiceTitle'];
  4914. if ($value ['invoiceType'] == '专')
  4915. $invoice->invoiceCompany = $value ['invoiceTitle'];
  4916. $invoice->userName = $value ['userName'];
  4917. $sDetail = $staff->getStaffByName ( $value ['userName'] );
  4918. $invoice->sid = $sDetail ['sid'];
  4919. $invoice->cid = $sDetail ['cid'];
  4920. $invoice->categoryName = $sDetail ['category'];
  4921. $invoice->invoiceElement = $value ['invoiceElement'];
  4922. $invoice->remark = $value ['remark'];
  4923. $invoice->date = $value ['date'];
  4924. $invoice->printTime = $value ['date'];
  4925. $invoice->ipSource = 1;
  4926. $invoice->printStatus = 1;
  4927. $invoice->status = 2;
  4928. $invoice->postStatus = 1;
  4929. $invoice->untreadStatus = 0;
  4930. $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  4931. $iid = $invoice->insert ();
  4932. // 汇总
  4933. $invoiceStatistics = new invoiceStatistics ();
  4934. //
  4935. $item = array (
  4936. 'date' => $value ['date'],
  4937. 'priceClass' => 1,
  4938. 'cid' => $sDetail ['cid'],
  4939. 'staff' => $sDetail ['sid'],
  4940. 'invoicePrice' => $value ['invoicePrice']
  4941. );
  4942. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4943. $invoiceOperationLog = new invoiceOperationLog ();
  4944. $item = array (
  4945. 'date' => date ( "Y-m-d H:i:s" ),
  4946. 'operation' => date ( "Y-m-d" ) . " 导入",
  4947. 'status' => 1,
  4948. 'img' => $sDetail ['avatar'],
  4949. 'username' => $sDetail ['username'],
  4950. 'uid' => $sDetail ['sid'],
  4951. 'category' => $sDetail ['category'],
  4952. 'iid' => $iid
  4953. );
  4954. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  4955. }
  4956. return '/importInvoice?count=' . count ( $exlArray );
  4957. // return "/keyonline";
  4958. }
  4959. echo 'no file';
  4960. }
  4961. function importInvoiceReceivables() {
  4962. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  4963. $data ['emsg'] = "";
  4964. if ($emsg != "")
  4965. $data ['emsg'] = "请填写完整的数据";
  4966. $data ['time'] = time ();
  4967. $this->render ( "/admin/invoiceReceivablesImport", $data );
  4968. }
  4969. // 导入入账数据
  4970. function importInvoiceReceivablesDo() {
  4971. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  4972. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  4973. if ($path != "") {
  4974. Doo::loadModel ( 'invoiceReceivables' );
  4975. Doo::loadModel ( 'invoice' );
  4976. Doo::loadModel ( 'staff' );
  4977. $staff = new staff ();
  4978. Doo::loadModel ( 'invoiceStatistics' );
  4979. // echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  4980. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path ), 'invoiceReceivables' );
  4981. // print_r ( $exlArray );
  4982. // die ();
  4983. // echo json_encode($exlArray);die;
  4984. foreach ( $exlArray as $key => $value ) {
  4985. // 收款
  4986. $invoiceReceivables = new invoiceReceivables ();
  4987. $invoice = new invoice ();
  4988. $invoiceReceivables->bindStatus = 1;
  4989. $invoiceReceivables->receivablesPrice = $value ['receivablesPrice'];
  4990. $invoiceReceivables->receivablesMessage = $value ['receivablesMessage'];
  4991. $invoiceReceivables->receivablesBank = $value ['receivablesBank'];
  4992. $invoiceReceivables->receivablesDate = $value ['receivablesDate'];
  4993. $sDetail = $staff->getStaffByName ( $value ['receivablesStaff'] );
  4994. $invoiceReceivables->receivablesCategory = $sDetail ['cid'] . ':' . $sDetail ['category'];
  4995. $invoiceReceivables->receivablesStaff = $sDetail ['sid'] . '-' . $sDetail ['username'];
  4996. $invoiceReceivables->receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  4997. $invoiceReceivables->sourcePrice = $value ['sourcePrice'];
  4998. $iDetail = $invoice->getInvoiceByInvoiceNo ( $value ['invoiceNo'] );
  4999. $invoiceReceivables->iid = $iDetail ['iid'];
  5000. $irid = $invoiceReceivables->insert ();
  5001. // 发票绑定收款
  5002. $detail = $iDetail;
  5003. $iridString = "";
  5004. if (empty ( $detail ['irid'] ))
  5005. $iridString = $irid;
  5006. else
  5007. $iridString = $detail ['irid'] . ',' . $irid;
  5008. $item = array (
  5009. 'irid' => $iridString,
  5010. 'iid' => $detail ['iid']
  5011. );
  5012. $invoice->setInvoiceByCondition ( $item );
  5013. // 汇总
  5014. $invoiceStatistics = new invoiceStatistics ();
  5015. // 扣除入账统计金额
  5016. $item = array (
  5017. 'date' => $value ['receivablesDate'],
  5018. 'priceClass' => 3,
  5019. 'cid' => $sDetail ['cid'],
  5020. 'staff' => $sDetail ['sid'],
  5021. // 'irid' => $irid,
  5022. 'accountPrice' => $value ['receivablesPrice']
  5023. );
  5024. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  5025. }
  5026. return '/importInvoiceReceivables?count=' . count ( $exlArray );
  5027. echo 'data count ' . count ( $exlArray );
  5028. die ();
  5029. // return "/keyonline";
  5030. }
  5031. echo 'no file';
  5032. }
  5033. function formatExcelToArrayTrain($file_url = "") {
  5034. if (! file_exists ( $file_url )) {
  5035. return array ();
  5036. }
  5037. // Doo::loadClass ( 'PHPExcel' );
  5038. Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  5039. $PHPExcel = new PHPExcel ();
  5040. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  5041. if (! $PHPReader->canRead ( $file_url )) {
  5042. $PHPReader = new PHPExcel_Reader_Excel5 ();
  5043. if (! $PHPReader->canRead ( $file_url )) {
  5044. echo 'no Excel';
  5045. return;
  5046. }
  5047. }
  5048. $PHPExcel = $PHPReader->load ( $file_url );
  5049. /* * 读取excel文件中的第一个工作表 */
  5050. $currentSheet = $PHPExcel->getSheet ( 0 );
  5051. /* * 取得最大的列号 */
  5052. $allColumn = $currentSheet->getHighestColumn ();
  5053. /* * 取得一共有多少行 */
  5054. $allRow = $currentSheet->getHighestRow ();
  5055. $excel_array = array ();
  5056. // die($file_url);
  5057. $conk = 2;
  5058. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  5059. $excel_column = array ();
  5060. // 后期改进
  5061. if ($allColumn == 'AM')
  5062. $allColumn = 'Z';
  5063. /* * 从第A列开始输出 */
  5064. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  5065. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  5066. if ($val instanceof PHPExcel_RichText)
  5067. $val = $val->__toString ();
  5068. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  5069. // $val = "'" . addslashes ( $val ) . "'";
  5070. if ($currentColumn == 'A') {
  5071. $excel_column ['invoiceTitle'] = $val;
  5072. } elseif ($currentColumn == 'B')
  5073. $excel_column ['invoiceType'] = $val;
  5074. elseif ($currentColumn == 'C') {
  5075. $excel_column ['TIN'] = $val;
  5076. } elseif ($currentColumn == 'D') {
  5077. $excel_column ['address'] = $val;
  5078. } elseif ($currentColumn == 'E') {
  5079. $excel_column ['phone'] = $val;
  5080. } elseif ($currentColumn == 'F') {
  5081. $excel_column ['bank'] = $val;
  5082. } elseif ($currentColumn == 'G') {
  5083. $excel_column ['bankAccount'] = $val;
  5084. } elseif ($currentColumn == 'H') {
  5085. $excel_column ['invoiceElement'] = $val;
  5086. } elseif ($currentColumn == 'I') {
  5087. $excel_column ['invoiceQuantity'] = $val;
  5088. } elseif ($currentColumn == 'J') {
  5089. $excel_column ['invoiceUnitPrice'] = $val;
  5090. } elseif ($currentColumn == 'K') {
  5091. $excel_column ['remark'] = $val;
  5092. } elseif ($currentColumn == 'L') {
  5093. $excel_column ['recipientsAddress'] = $val;
  5094. } elseif ($currentColumn == 'M') {
  5095. $excel_column ['recipients'] = $val;
  5096. } elseif ($currentColumn == 'N') {
  5097. $excel_column ['recipientsPhone'] = $val;
  5098. }
  5099. }
  5100. if (! empty ( $excel_column ['invoiceTitle'] ) && ! empty ( $excel_column ['invoiceQuantity'] ) && ! empty ( $excel_column ['invoiceUnitPrice'] ))
  5101. array_push ( $excel_array, $excel_column );
  5102. }
  5103. return $excel_array;
  5104. }
  5105. /**
  5106. * 格式化excel文件为数组
  5107. * @param unknown_type $file_url
  5108. * @param unknown_type $mcid
  5109. */
  5110. function _format_excel_to_array($file_url = "", $sType = "") {
  5111. if (! file_exists ( $file_url )) {
  5112. return array ();
  5113. }
  5114. Doo::loadClass ( 'PHPExcel' );
  5115. // Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  5116. $PHPExcel = new PHPExcel ();
  5117. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  5118. if (! $PHPReader->canRead ( $file_url )) {
  5119. $PHPReader = new PHPExcel_Reader_Excel5 ();
  5120. if (! $PHPReader->canRead ( $file_url )) {
  5121. echo 'no Excel';
  5122. return;
  5123. }
  5124. }
  5125. $PHPExcel = $PHPReader->load ( $file_url );
  5126. /* * 读取excel文件中的第一个工作表 */
  5127. $currentSheet = $PHPExcel->getSheet ( 0 );
  5128. /* * 取得最大的列号 */
  5129. $allColumn = $currentSheet->getHighestColumn ();
  5130. /* * 取得一共有多少行 */
  5131. $allRow = $currentSheet->getHighestRow ();
  5132. $excel_array = array ();
  5133. // die($file_url);
  5134. $conk = 2;
  5135. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  5136. $excel_column = array ();
  5137. // 后期改进
  5138. if ($allColumn == 'AM')
  5139. $allColumn = 'Z';
  5140. /* * 从第A列开始输出 */
  5141. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  5142. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  5143. if ($val instanceof PHPExcel_RichText)
  5144. $val = $val->__toString ();
  5145. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  5146. // $val = "'" . addslashes ( $val ) . "'";
  5147. if ($sType == 'invoiceReceivables') {
  5148. if ($currentColumn == 'A')
  5149. $excel_column ['invoiceNo'] = $val;
  5150. elseif ($currentColumn == 'B')
  5151. $excel_column ['receivablesPrice'] = $val;
  5152. elseif ($currentColumn == 'C') {
  5153. $excel_column ['receivablesMessage'] = $val;
  5154. } elseif ($currentColumn == 'D') {
  5155. $excel_column ['receivablesBank'] = $val;
  5156. } elseif ($currentColumn == 'E') {
  5157. $excel_column ['receivablesDate'] = $this->excelTime ( $val );
  5158. } elseif ($currentColumn == 'F') {
  5159. $excel_column ['receivablesStaff'] = $val;
  5160. } elseif ($currentColumn == 'G') {
  5161. $excel_column ['sourcePrice'] = $val;
  5162. }
  5163. } elseif ($sType == "invoiceTrain") {
  5164. if ($currentColumn == 'A') {
  5165. $excel_column ['invoiceTitle'] = $val;
  5166. } elseif ($currentColumn == 'B')
  5167. $excel_column ['invoiceType'] = $val;
  5168. elseif ($currentColumn == 'C') {
  5169. $excel_column ['TIN'] = $val;
  5170. } elseif ($currentColumn == 'D') {
  5171. $excel_column ['address'] = $val;
  5172. } elseif ($currentColumn == 'E') {
  5173. $excel_column ['phone'] = $val;
  5174. } elseif ($currentColumn == 'F') {
  5175. $excel_column ['bank'] = $val;
  5176. } elseif ($currentColumn == 'G') {
  5177. $excel_column ['bankAccount'] = $val;
  5178. } elseif ($currentColumn == 'H') {
  5179. $excel_column ['invoiceElement'] = $val;
  5180. } elseif ($currentColumn == 'I') {
  5181. $excel_column ['invoiceQuantity'] = $val;
  5182. } elseif ($currentColumn == 'J') {
  5183. $excel_column ['invoiceUnitPrice'] = $val;
  5184. } elseif ($currentColumn == 'K') {
  5185. $excel_column ['remark'] = $val;
  5186. } elseif ($currentColumn == 'L') {
  5187. $excel_column ['recipientsAddress'] = $val;
  5188. } elseif ($currentColumn == 'M') {
  5189. $excel_column ['recipients'] = $val;
  5190. } elseif ($currentColumn == 'N') {
  5191. $excel_column ['recipientsPhone'] = $val;
  5192. }
  5193. } else {
  5194. if ($currentColumn == 'A')
  5195. $excel_column ['invoiceNo'] = $val;
  5196. elseif ($currentColumn == 'B')
  5197. $excel_column ['invoiceType'] = $val;
  5198. elseif ($currentColumn == 'C') {
  5199. $excel_column ['invoicePrice'] = $val;
  5200. } elseif ($currentColumn == 'D') {
  5201. $excel_column ['invoiceTitle'] = $val;
  5202. } elseif ($currentColumn == 'E') {
  5203. $excel_column ['userName'] = $val;
  5204. } elseif ($currentColumn == 'F') {
  5205. $excel_column ['categoryName'] = $val;
  5206. } elseif ($currentColumn == 'G') {
  5207. $excel_column ['invoiceElement'] = $val;
  5208. } elseif ($currentColumn == 'H') {
  5209. $excel_column ['remark'] = $val;
  5210. } elseif ($currentColumn == 'I') {
  5211. $excel_column ['date'] = $this->excelTime ( $val );
  5212. }
  5213. }
  5214. }
  5215. array_push ( $excel_array, $excel_column );
  5216. }
  5217. return $excel_array;
  5218. }
  5219. function excelTime($date, $time = false) {
  5220. if (function_exists ( 'GregorianToJD' )) {
  5221. if (is_numeric ( $date )) {
  5222. $jd = GregorianToJD ( 1, 1, 1970 );
  5223. $gregorian = JDToGregorian ( $jd + intval ( $date ) - 25569 );
  5224. $date = explode ( '/', $gregorian );
  5225. $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" : '');
  5226. return $date_str;
  5227. }
  5228. } else {
  5229. $date = $date > 25568 ? $date + 1 : 25569;
  5230. /* There was a bug if Converting date before 1-1-1970 (tstamp 0) */
  5231. $ofs = (70 * 365 + 17 + 2) * 86400;
  5232. $date = date ( "Y-m-d", ($date * 86400) - $ofs ) . ($time ? " 00:00:00" : '');
  5233. }
  5234. return $date;
  5235. }
  5236. /**
  5237. * 旧输入导入
  5238. */
  5239. function _GetFileEXT($filename) {
  5240. $pics = explode ( '.', $filename );
  5241. $num = count ( $pics );
  5242. return $pics [$num - 1];
  5243. }
  5244. function showCache($path = "") {
  5245. // if (file_exists ( $path )) {
  5246. // $htm = file_get_contents ( $path );
  5247. // } else {
  5248. Doo::loadModel ( 'invoiceStatistics' );
  5249. $invoiceStatistics = new invoiceStatistics ();
  5250. $isBriefly = $invoiceStatistics->getBrieflyStatistics ();
  5251. $htm = '<tr><th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计开票</th>
  5252. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['invoicePrice'] . '</td>
  5253. <th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计入账</th>
  5254. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['accountPrice'] . '</td></tr>';
  5255. /*
  5256. * '<tr><th class="taC">今年累计开票</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['invoicePrice'] . '</td> <th class="taC">今年累计入账</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['accountPrice'] . '</td></tr>';
  5257. */
  5258. file_put_contents ( $path, $htm, FILE_APPEND );
  5259. // }
  5260. return $htm;
  5261. }
  5262. /**
  5263. * 获取get或者POST值
  5264. *
  5265. * @param string $name 属性名称
  5266. * @return fixed 值
  5267. */
  5268. function get_args($name) {
  5269. if (isset ( $_GET [$name] )) {
  5270. if (is_array ( $_GET [$name] ))
  5271. return $_GET [$name];
  5272. else
  5273. return addslashes ( $_GET [$name] );
  5274. } elseif (isset ( $_POST [$name] )) {
  5275. if (is_array ( $_POST [$name] ))
  5276. return $_POST [$name];
  5277. else
  5278. return addslashes ( $_POST [$name] );
  5279. } else
  5280. return false;
  5281. }
  5282. function SafeFilter(&$arr) {
  5283. $ra = Array (
  5284. '/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/',
  5285. '/script/',
  5286. '/javascript/',
  5287. '/vbscript/',
  5288. '/expression/',
  5289. '/applet/',
  5290. '/meta/',
  5291. '/xml/',
  5292. '/blink/',
  5293. '/link/',
  5294. '/style/',
  5295. '/embed/',
  5296. '/object/',
  5297. '/frame/',
  5298. '/layer/',
  5299. '/title/',
  5300. '/bgsound/',
  5301. '/base/',
  5302. '/onload/',
  5303. '/onunload/',
  5304. '/onchange/',
  5305. '/onsubmit/',
  5306. '/onreset/',
  5307. '/onselect/',
  5308. '/onblur/',
  5309. '/onfocus/',
  5310. '/onabort/',
  5311. '/onkeydown/',
  5312. '/onkeypress/',
  5313. '/onkeyup/',
  5314. '/onclick/',
  5315. '/ondblclick/',
  5316. '/onmousedown/',
  5317. '/onmousemove/',
  5318. '/onmouseout/',
  5319. '/onmouseover/',
  5320. '/onmouseup/',
  5321. '/onunload/'
  5322. );
  5323. if (is_array ( $arr )) {
  5324. foreach ( $arr as $key => $value ) {
  5325. if (! is_array ( $value )) {
  5326. if (! get_magic_quotes_gpc ()) // 不对magic_quotes_gpc转义过的字符使用addslashes(),避免双重转义。
  5327. {
  5328. $value = addslashes ( $value ); // 给单引号(')、双引号(")、反斜线(\)与 NUL(NULL 字符)加上反斜线转义
  5329. }
  5330. $value = preg_replace ( $ra, '', $value ); // 删除非打印字符,粗暴式过滤xss可疑字符串
  5331. $arr [$key] = htmlentities ( strip_tags ( $value ) ); // 去除 HTML 和 PHP 标记并转换为 HTML 实体
  5332. } else {
  5333. SafeFilter ( $arr [$key] );
  5334. }
  5335. }
  5336. }
  5337. }
  5338. /**
  5339. * Escape String
  5340. *
  5341. * @access public
  5342. * @param string
  5343. * @param bool whether or not the string will be used in a LIKE condition
  5344. * @return string
  5345. */
  5346. function escape_str($str, $like = FALSE) {
  5347. if (is_array ( $str )) {
  5348. foreach ( $str as $key => $val ) {
  5349. $str [$key] = $this->escape_str ( $val, $like );
  5350. }
  5351. return $str;
  5352. }
  5353. var_dump ( Doo::db ()->getDbObject () );
  5354. die ();
  5355. if (function_exists ( 'mysql_real_escape_string' ) and is_resource ( Doo::db ()->getDbObject () )) { // Doo::db ()->getDbObject()
  5356. $str = mysql_real_escape_string ( $str, Doo::db ()->getDbObject () );
  5357. } elseif (function_exists ( 'mysql_escape_string' )) {
  5358. $str = mysql_escape_string ( $str );
  5359. } else {
  5360. $str = addslashes ( $str );
  5361. }
  5362. // escape LIKE condition wildcards
  5363. if ($like === TRUE) {
  5364. $str = str_replace ( array (
  5365. '%',
  5366. '_'
  5367. ), array (
  5368. '\\%',
  5369. '\\_'
  5370. ), $str );
  5371. }
  5372. return $str;
  5373. }
  5374. /**
  5375. * 获得分页数据
  5376. * @param unknown_type $table
  5377. * @param unknown_type $condition
  5378. * @param unknown_type $on_page
  5379. * @param unknown_type $page_size
  5380. */
  5381. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  5382. $page_c = "";
  5383. $page ['previous'] = $this->get_previous ( $on_page );
  5384. $page ['on_page'] = $on_page;
  5385. $total_count = $this->get_table_count ( $table, $condition );
  5386. $total = intval ( $total_count / $page_size );
  5387. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  5388. $page ['total_data'] = $total_count;
  5389. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  5390. $i = 1;
  5391. $page_max = 1;
  5392. $page_width = 3;
  5393. if ($on_page >= $page_width) {
  5394. $page_max = intval ( $on_page / $page_width ) + 1;
  5395. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  5396. }
  5397. for(; $i <= $page ['total_page']; $i ++) {
  5398. if ($i == $on_page)
  5399. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  5400. else
  5401. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  5402. if ($i == ($page_width * $page_max))
  5403. break;
  5404. }
  5405. $page ['page'] = $page_c;
  5406. $page ['lower'] = (-- $on_page) * $page_size;
  5407. return $page;
  5408. }
  5409. /**
  5410. * 获取上一页
  5411. * @param unknown_type $on_page
  5412. */
  5413. function get_previous($on_page = 1) {
  5414. return $on_page != 0 ? $on_page - 1 : $on_page;
  5415. }
  5416. /**
  5417. * 获取总页数
  5418. * @param unknown_type $table
  5419. * @param unknown_type $condition
  5420. */
  5421. public function get_table_count($table = "", $condition = "") {
  5422. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  5423. $sql = "select count(*) as count from " . $table . " where " . $condition;
  5424. // echo $sql;die;
  5425. $query = Doo::db ()->query ( $sql );
  5426. $result = $query->fetch ();
  5427. return $result ['count'];
  5428. }
  5429. /**
  5430. * 获得分页数据
  5431. * @param unknown_type $table
  5432. * @param unknown_type $condition
  5433. * @param unknown_type $on_page
  5434. * @param unknown_type $page_size
  5435. */
  5436. function getPageBySql($sql = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  5437. $page_c = "";
  5438. $page ['previous'] = $this->get_previous ( $on_page );
  5439. $page ['on_page'] = $on_page;
  5440. $total_count = $this->getTableCountBySql ( $sql );
  5441. $total = intval ( $total_count / $page_size );
  5442. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  5443. $page ['total_data'] = $total_count;
  5444. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  5445. $i = 1;
  5446. $page_max = 1;
  5447. $page_width = 3;
  5448. if ($on_page >= $page_width) {
  5449. $page_max = intval ( $on_page / $page_width ) + 1;
  5450. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  5451. }
  5452. for(; $i <= $page ['total_page']; $i ++) {
  5453. if ($i == $on_page)
  5454. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  5455. else
  5456. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  5457. if ($i == ($page_width * $page_max))
  5458. break;
  5459. }
  5460. $page ['page'] = $page_c;
  5461. $page ['lower'] = (-- $on_page) * $page_size;
  5462. return $page;
  5463. }
  5464. /**
  5465. * 获得总页数 sql
  5466. * @param string $type
  5467. * @return boolean[]
  5468. */
  5469. public function getTableCountBySql($sql = "") {
  5470. $query = Doo::db ()->query ( $sql );
  5471. $result = $query->fetch ();
  5472. return $result ['count'];
  5473. }
  5474. function isInvoiceNew($type = "GLOBAL") {
  5475. Doo::loadModel ( 'invoice' );
  5476. $invoice = new invoice ();
  5477. Doo::loadModel ( 'invoiceReceivables' );
  5478. $invoiceReceivables = new invoiceReceivables ();
  5479. Doo::loadModel ( 'staff' );
  5480. $staff = new staff ();
  5481. $st = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  5482. // 我的发票待处理
  5483. $pendingInvoice = $invoice->getOne ( array ( // or (status=2 and printStatus=1 and untreadStatus=0 ) or (status=2 and printStatus=1 and untreadStatus=2 )
  5484. 'where' => "(status=3 or status=4) and isDelete=0 and sid=" . $st [0] ['sid'],
  5485. 'desc' => 'iid',
  5486. 'asArray' => TRUE
  5487. ) );
  5488. // 我的收款待入账
  5489. /*
  5490. * $myClaim = $invoiceReceivables->getOne ( array ( 'where' => " receivablesStaff like '" . $st [0] ['sid'] . "-%' and receivablesCategory like '" . $st [0] ['cid'] . ":%' and bindStatus=0", 'desc' => 'irid', 'asArray' => TRUE ) );
  5491. */
  5492. // 发票审批
  5493. $approval = $invoice->getOne ( array (
  5494. 'where' => 'status=1 and pendingApprovals=' . $st [0] ['sid'],
  5495. 'desc' => 'iid',
  5496. 'asArray' => true
  5497. ) );
  5498. // 发票邮寄
  5499. $post = $invoice->getOne ( array (
  5500. 'where' => "postStatus=0 and printStatus=1 and isDelete=0 and doPost=1 and status=2",
  5501. 'asArray' => TRUE
  5502. ) );
  5503. // 发票打印
  5504. $print = $invoice->getOne ( array (
  5505. 'where' => "status=2 and printStatus=0 and untreadStatus=0 and moldManage like '%[\"" . $st [0] ['sid'] . "\",%'",
  5506. 'desc' => 'iid',
  5507. 'asArray' => TRUE
  5508. ) );
  5509. // 发票退票 printStatus=1 and
  5510. $untread = $invoice->getOne ( array (
  5511. 'where' => " untreadStatus=1 and status=2 ",
  5512. 'asArray' => TRUE
  5513. ) );
  5514. $new = array (
  5515. 'GLOBAL' => FALSE,
  5516. 'pendingInvoice' => FALSE,
  5517. // 'myClaim' => FALSE,
  5518. 'approval' => FALSE,
  5519. 'post' => FALSE,
  5520. 'print' => FALSE,
  5521. 'untread' => FALSE
  5522. );
  5523. // || ! empty ( $myClaim )
  5524. if (! empty ( $pendingInvoice ) || ! empty ( $approval ) || ! empty ( $post ) || ! empty ( $print ) || ! empty ( $untread ))
  5525. $new ['GLOBAL'] = TRUE;
  5526. if (! empty ( $pendingInvoice ))
  5527. $new ['pendingInvoice'] = TRUE;
  5528. // if (! empty ( $myClaim ))
  5529. // $new ['myClaim'] = TRUE;
  5530. if (! empty ( $approval ))
  5531. $new ['approval'] = TRUE;
  5532. if (! empty ( $post ))
  5533. $new ['post'] = TRUE;
  5534. if (! empty ( $print ))
  5535. $new ['print'] = TRUE;
  5536. if (! empty ( $untread ))
  5537. $new ['untread'] = TRUE;
  5538. return $new;
  5539. }
  5540. function setWXMsg($rid, $typeMsg = '') {
  5541. Doo::loadModel ( 'invoice' );
  5542. $invoice = new invoice ();
  5543. $invoiceDetail = $invoice->getOne ( array (
  5544. 'where' => 'iid=' . $rid,
  5545. 'asArray' => true
  5546. ) );
  5547. if (! empty ( $invoiceDetail )) {
  5548. Doo::loadModel ( 'staff' );
  5549. $staff = new staff ();
  5550. $staffmsg = $staff->getOne ( array (
  5551. 'where' => "sid='" . $invoiceDetail ['sid'] . "'",
  5552. 'asArray' => TRUE
  5553. ) );
  5554. if (! empty ( $staffmsg ['wxid'] )) {
  5555. require_once (SITE_PATH . '/protected/class/client.php');
  5556. $client = new client ( 'http://m.cld.smartcost.com.cn/' );
  5557. $user = $staffmsg ['wxid'];
  5558. $expCom = explode ( ":", $invoiceDetail ['expressCompany'] );
  5559. if (empty ( $expCom ))
  5560. $expCom [0] = '';
  5561. $msg = "";
  5562. if (empty ( $typeMsg ))
  5563. $msg = '太好了,您的发票' . $invoiceDetail ['invoiceSerial'] . ' 已邮寄 ' . $expCom [0] . ' ,快递号: <a href="https://m.kuaidi100.com/result.jsp?nu=' . $invoiceDetail ['expressNumber'] . '" >' . $invoiceDetail ['expressNumber'] . '</a>';
  5564. elseif ($typeMsg == "PRINT")
  5565. $msg = '太好了,您的发票已打印完成。';
  5566. $result = $client->SendMsg ( $user, $msg, 'text' );
  5567. }
  5568. }
  5569. }
  5570. /**
  5571. * 获取微信部门
  5572. * @param string $category
  5573. * @return number|mixed
  5574. */
  5575. function getToparty($category = '') {
  5576. $token = $this->getAccessToken (); //
  5577. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token={$token}&id=5" ), true );
  5578. $toparty = 0;
  5579. foreach ( $result ['department'] as $key => $value ) {
  5580. if ($value ['name'] == $category)
  5581. $toparty = $value ['id'];
  5582. }
  5583. return $toparty;
  5584. }
  5585. /**
  5586. * 获得某部门下的用户
  5587. * @param string $toparty
  5588. */
  5589. function getUserByToparty($toparty = '') {
  5590. $token = $this->getAccessToken (); //
  5591. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token={$token}&department_id={$toparty}" ), true );
  5592. $userList = array ();
  5593. foreach ( $result ['userlist'] as $key => $value ) {
  5594. array_push ( $userList, "'" . $value ['userid'] . "'" );
  5595. }
  5596. return $userList;
  5597. }
  5598. function msgSendToparty($msg, $title, $url, $toparty, $text = '') {
  5599. $token = $this->getAccessToken ();
  5600. if ($text == 'text') {
  5601. $data = '{
  5602. "touser": "' . $toparty . '",
  5603. "toparty": "",
  5604. "totag": "",
  5605. "msgtype": "text",
  5606. "agentid": 1000002,
  5607. "text": {
  5608. "content": "' . $msg . '"
  5609. },
  5610. "safe":0
  5611. }';
  5612. }
  5613. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  5614. if ($result->errmsg != 'ok') {
  5615. return 0;
  5616. } else {
  5617. return 1;
  5618. }
  5619. }
  5620. /**
  5621. * 获得可以发送微信用户列表
  5622. * @param string $category
  5623. * @return string
  5624. */
  5625. function getWxidByCategory($category = "") {
  5626. if (empty ( $category ))
  5627. return "";
  5628. Doo::loadModel ( 'staff' );
  5629. $staff = new staff ();
  5630. $toparty = $this->getToparty ( $category );
  5631. $wxList = array ();
  5632. $wxString = "";
  5633. if (! empty ( $toparty )) {
  5634. $userList = $this->getUserByToparty ( $toparty );
  5635. $userCon = implode ( ',', $userList );
  5636. // echo $userCon;
  5637. $sidList = $staff->getStaffByWxid ( $userCon );
  5638. foreach ( $sidList as $key => $value ) {
  5639. $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  5640. if ($falg) {
  5641. array_push ( $wxList, $value ['wxid'] );
  5642. }
  5643. }
  5644. $wxString = implode ( '|', $wxList );
  5645. }
  5646. return $wxString;
  5647. }
  5648. /**
  5649. * 读取发送信息规则判断是否需要发送
  5650. * @param number $sid
  5651. * @param string $sendType
  5652. * @return boolean
  5653. */
  5654. function isSendNotification($sid = 0, $sendType = '') {
  5655. Doo::loadModel ( "notificationConf" );
  5656. $notificationConf = new notificationConf ();
  5657. $detail = $notificationConf->getNotificationConfBySid ( $sid );
  5658. $conf = array ();
  5659. $sendFlag = true;
  5660. if (! empty ( $detail )) {
  5661. $conf = json_decode ( $detail ['conf'], true );
  5662. if (! empty ( $sendType )) {
  5663. if (isset ( $conf [$sendType] )) {
  5664. if ($conf [$sendType] == "CLOSE")
  5665. $sendFlag = false;
  5666. elseif ($conf [$sendType] == "Weekend") {
  5667. $day = date ( "w" );
  5668. if (1 <= $day && 5 >= $day)
  5669. $sendFlag = false;
  5670. } elseif ($conf [$sendType] == "OneToFriday") {
  5671. $day = date ( "w" );
  5672. if (0 == $day || 6 == $day)
  5673. $sendFlag = false;
  5674. }
  5675. }
  5676. } else
  5677. $sendFlag = false;
  5678. }
  5679. return $sendFlag;
  5680. }
  5681. /**
  5682. * 根据规则发送信息
  5683. * @param unknown $msg
  5684. * @param unknown $title
  5685. * @param unknown $url
  5686. * @param unknown $user
  5687. * @param string $text
  5688. * @return number
  5689. */
  5690. private function msgSend($msg, $title, $url, $user, $sid = 0, $sendType = '') {
  5691. $token = $this->getAccessToken ();
  5692. $falg = $this->isSendNotification ( $sid, $sendType );
  5693. // if ($text == 'text') {
  5694. // $data = '{
  5695. // "touser": "' . $user . '",
  5696. // "toparty": "",
  5697. // "totag": "",
  5698. // "msgtype": "text",
  5699. // "agentid": 1000002,
  5700. // "text": {
  5701. // "content": "' . $msg . '"
  5702. // },
  5703. // "safe":0
  5704. // }';
  5705. // } else {
  5706. $data = '{
  5707. "touser": "' . $user . '",
  5708. "toparty": "",
  5709. "totag": "",
  5710. "msgtype": "news",
  5711. "agentid": 1000002,
  5712. "news": {
  5713. "articles":[
  5714. {
  5715. "title": "' . $title . '",
  5716. "description": "' . $msg . '",
  5717. "url": "' . $url . '",
  5718. "picurl": ""
  5719. }
  5720. ]
  5721. }
  5722. }';
  5723. // }
  5724. if ($falg) {
  5725. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  5726. if ($result->errmsg != 'ok') {
  5727. return 0;
  5728. } else {
  5729. return 1;
  5730. }
  5731. } else
  5732. return 0;
  5733. }
  5734. private function getAccessToken() {
  5735. // access_token 应该全局存储与更新,以下代码以写入到文件中做示例
  5736. // $file = './access_token.txt';
  5737. // $data = json_decode ( file_get_contents ( $file ) );
  5738. // if ($data->expire_time < time () or ! $data->expire_time) {
  5739. // 如果是企业号用以下URL获取access_token
  5740. $url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$this->appId&corpsecret=$this->appSecret";
  5741. // $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$this->appId&secret=$this->appSecret";
  5742. $res = json_decode ( $this->httpGet ( $url ) );
  5743. $access_token = $res->access_token;
  5744. // echo $access_token;
  5745. // if ($access_token) {
  5746. // $data->expire_time = time () + 7000;
  5747. // $data->access_token = $access_token;
  5748. // $fp = fopen ( $file, "w" );
  5749. // fwrite ( $fp, json_encode ( $data ) );
  5750. // fclose ( $fp );
  5751. // }
  5752. // } else {
  5753. // $access_token = $data->access_token;
  5754. // }
  5755. return $access_token;
  5756. }
  5757. private function httpGet($url) {
  5758. $curl = curl_init ();
  5759. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  5760. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  5761. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  5762. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  5763. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  5764. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  5765. curl_setopt ( $curl, CURLOPT_URL, $url );
  5766. $res = curl_exec ( $curl );
  5767. curl_close ( $curl );
  5768. return $res;
  5769. }
  5770. private function httpPost($url, $data) {
  5771. $curl = curl_init ();
  5772. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  5773. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  5774. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  5775. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  5776. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  5777. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  5778. curl_setopt ( $curl, CURLOPT_URL, $url );
  5779. curl_setopt ( $curl, CURLOPT_POST, 1 );
  5780. curl_setopt ( $curl, CURLOPT_POSTFIELDS, $data );
  5781. $res = curl_exec ( $curl );
  5782. curl_close ( $curl );
  5783. return $res;
  5784. }
  5785. }
  5786. ?>