InvoiceController.php 302 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243
  1. <?php
  2. /**
  3. * 开票功能控制器
  4. * @author CP
  5. * @version 1.0
  6. * @namespace invoice
  7. * @package invoiceController
  8. */
  9. class InvoiceController extends DooController {
  10. public $staff;
  11. public $NEW;
  12. public $data;
  13. private $INVOICEKEY = "APPROVAL";
  14. private $INVOICECOLLECTPATH = "protected/cache/invoiceCollect/";
  15. private $ACTION = '';
  16. private $appId = 'wx3ee46531947a1384';
  17. private $appSecret = 'awGWzy3J5q_96VXKBLA2BQ9RpiT0LiPXnkMF-xV6h5o'; // awGWzy3J5q_96VXKBLA2BXU6mVCGynPGD-sxUCsdNDE //'PeiQVH8tbQE7pM9pVO4AIPlX9FFNpwu7O6Iy6VFcAVtpjTA3Qn42dbNmktBFkUHo';
  18. public function beforeRun($resource, $action) {
  19. Doo::loadModel ( "invoiceManage" );
  20. $invoiceManage = new invoiceManage ();
  21. Doo::loadClass ( 'XDeode' );
  22. $XDeode = new XDeode ( 5 );
  23. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  24. header ( 'Content-Type:text/html;charset=utf-8' );
  25. $moldList = $invoiceManage->getInvoiceByStaff ( $sid );
  26. if (empty ( $moldList )) {
  27. $flag = false;
  28. $uGroups = 'ordinary';
  29. if (Doo::acl ()->isAllowed ( $uGroups, $resource, $action )) {
  30. $flag = true;
  31. }
  32. } else {
  33. $flag = false;
  34. array_push ( $moldList, array (
  35. 'mold' => 'ordinary'
  36. ) );
  37. // 删除审批人后-加入权限问题-暂时关闭
  38. $fileInvoice = file_get_contents ( "protected/config/invoice/invoice.ini" );
  39. $fiML = json_decode ( $fileInvoice, true );
  40. if (empty ( $fiML ))
  41. $fiML = array ();
  42. foreach ( $fiML as $key => $value ) {
  43. $sidList = explode ( ',', $value );
  44. foreach ( $sidList as $k => $v ) {
  45. if ($v == $sid) {
  46. array_push ( $moldList, array (
  47. 'mold' => $key
  48. ) );
  49. break;
  50. }
  51. }
  52. }
  53. foreach ( $moldList as $value ) {
  54. if (Doo::acl ()->isAllowed ( $value ['mold'], $resource, $action )) {
  55. $flag = true;
  56. break;
  57. }
  58. }
  59. }
  60. /*
  61. * Doo::acl()->isAllowed($uGroups['groups'], $resource, $action);
  62. */
  63. // 单独判断办事处汇总的访问权限 invoiceAggregateCategoryDetail,invoiceAggregateStaffDetail
  64. if ($action == 'invoiceAggregateCategoryDetail' || $action == 'invoiceAggregateStaffDetail') {
  65. Doo::loadModel ( "invoiceCategoryManage" );
  66. $invoiceCategoryManage = new invoiceCategoryManage ();
  67. $icm = $invoiceCategoryManage->getInvoiceCMByStaff ( $sid );
  68. if (empty ( $icm ))
  69. die ( 'illegal request' );
  70. }
  71. // 单独判断应收款访问权限
  72. if ($action == 'invoiceAggregateCompanyDetail') {
  73. Doo::loadModel ( "invoiceCompanyManage" );
  74. $invoiceCompanyManage = new invoiceCompanyManage ();
  75. $icm = $invoiceCompanyManage->getInvoiceCMByStaff ( $sid );
  76. if (empty ( $icm ))
  77. die ( 'illegal request' );
  78. }
  79. // 主权限获得与判断
  80. Doo::loadModel ( 'staff' );
  81. $staff = new staff ();
  82. $detail = $staff->getStaffBySid ( $_COOKIE ["staff"] );
  83. $accessModular = 'INVOICE';
  84. if (empty ( $detail ['cldAccessArray'] ))
  85. die ( 'illegal request' );
  86. else {
  87. if (in_array ( $accessModular, $detail ['cldAccessArray'] )) {
  88. if (Doo::acl ()->isAllowed ( $accessModular, $resource, $action )) {
  89. $flag = true;
  90. } else {
  91. $flag = false;
  92. }
  93. } else {
  94. die ( 'illegal request' );
  95. }
  96. }
  97. if (! $flag)
  98. die ( 'illegal request' );
  99. }
  100. function __construct() {
  101. if (isset ( $_COOKIE ["staff"] )) {
  102. if (! empty ( $_COOKIE ["staff"] )) {
  103. Doo::loadModel ( 'staff' );
  104. $staff = new staff ();
  105. $uriPartsOrig = explode ( '/', $_SERVER ['REQUEST_URI'] );
  106. $this->ACTION = $uriPartsOrig [1];
  107. $this->data ['new'] = $this->isInvoiceNew ();
  108. $this->staff = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  109. $this->data ['isStaffCompleteMsg'] = false;
  110. $detail = $staff->checkStaffInfoIsComplete ( $_COOKIE ["staff"] );
  111. if (! empty ( $detail ))
  112. $this->data ['isStaffCompleteMsg'] = true;
  113. return "/";
  114. }
  115. }
  116. Doo::loadCore ( 'uri/DooUriRouter' );
  117. $router = new DooUriRouter ();
  118. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  119. if ($routeRs ['1'] != "login") {
  120. header ( 'Content-Type:text/html;charset=utf-8' );
  121. @header ( "Location: /login" );
  122. }
  123. }
  124. function testSend() {
  125. // 测试根据规则发送信息 普通发送
  126. // $pendingApprovalsSid = 41;
  127. // Doo::loadModel ( 'staff' );
  128. // $staff = new staff ();
  129. // $username2 = $staff->getOne ( array ( 'select' => 'wxid', 'where' => 'sid=' . $pendingApprovalsSid, 'asArray' => TRUE ) );
  130. // // 发送微信审批通知
  131. // $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  132. // $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  133. // Doo::loadModel ( 'staff' );
  134. // $staff = new staff ();
  135. // $toparty = $this->getToparty ( '广东办' );
  136. // $wxList = array ();
  137. // if (! empty ( $toparty )) {
  138. // $userList = $this->getUserByToparty ( $toparty );
  139. // $userCon = implode ( ',', $userList );
  140. // // echo $userCon;
  141. // $sidList = $staff->getStaffByWxid ( $userCon );
  142. // foreach ( $sidList as $key => $value ) {
  143. // $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  144. // if ($falg) {
  145. // array_push ( $wxList, $value ['wxid'] );
  146. // }
  147. // }
  148. // $wxString = implode ( '|', $wxList );
  149. // print_r ( $wxList );
  150. // echo $wxString;
  151. // }
  152. // 测试发送
  153. /*
  154. * //$toparty = $this->getWxidByCategory( $receivablesCategory [1] ); $toparty = $this->getToparty ( $receivablesCategory [1] ); $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。'; if ($toparty != 0) $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  155. */
  156. // print_r ( $userList );
  157. // $msTouser='caipin|outaozhen';
  158. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  159. // $title2 = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  160. // $hfreult = $this->msgSend ( '', $title2, '', 'outaozhen' );
  161. // $toparty= $this->getToparty('广东办');
  162. // $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  163. // $toparty = 26;
  164. // $msg = '';
  165. // $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/1.html';
  166. // $hfreult = $this->msgSendToparty ( $msg, '', '', $toparty,'text' );
  167. }
  168. function invoice() {
  169. Doo::loadModel ( 'invoice' );
  170. $invoice = new invoice ();
  171. Doo::loadModel ( 'express' );
  172. $express = new express ();
  173. $expressList = $express->getExpressByAll ();
  174. $this->data ['expressList'] = $expressList;
  175. // Doo::loadModel ( 'invoiceReceivables' );
  176. // $invoiceReceivables = new invoiceReceivables ();
  177. // $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  178. Doo::loadClass ( 'XDeode' );
  179. $XDeode = new XDeode ( 5 );
  180. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  181. Doo::loadModel ( 'invoiceStatistics' );
  182. $invoiceStatistics = new invoiceStatistics ();
  183. $isMonth = $invoiceStatistics->getStatisticsByMonth ( $sid );
  184. // 缓存统计结果
  185. $year = date ( "Y" );
  186. $tmp_date = date ( "Ym" );
  187. $tmp_year = substr ( $tmp_date, 0, 4 );
  188. $tmp_mon = substr ( $tmp_date, 4, 2 );
  189. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  190. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  191. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . "_" . $sid . ".htm";
  192. if (is_file ( $path ))
  193. $htm = file_get_contents ( $path );
  194. else
  195. $htm = $this->showCache ( $path, $sid );
  196. $invoiceList = $invoice->getMyInvoice ( $sid );
  197. $sql = 'status=2 and printStatus=1 and irid!="" and sid=' . $sid;
  198. $list = $invoice->getInvoiceByUntreadStatusPage ( 4, $sql );
  199. // 我的待入账发票 and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  200. $sql = "status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid=" . $sid;
  201. $myInvoiceUnAccount = $invoice->getInvoiceByUntreadStatusPage ( 4, $sql );
  202. // print_r($myInvoiceUnAccount);
  203. $this->data ['isMonth'] = $isMonth;
  204. $this->data ['htm'] = $htm;
  205. $this->data ['invoiceList'] = $invoiceList;
  206. $this->data ['receivablesList'] = $list;
  207. $this->data ['myInvoiceUnAccount'] = $myInvoiceUnAccount;
  208. $this->data ['memu'] = "invoice";
  209. $this->data ['staff'] = $this->staff;
  210. $this->data ['receiptMemu'] = 'invoice';
  211. $this->render ( "/admin/invoice", $this->data );
  212. }
  213. function invoiceExpress() {
  214. $expressCom = isset ( $this->params ['expressCom'] ) ? $this->params ['expressCom'] : "";
  215. $expressNumber = isset ( $this->params ['expressNumber'] ) ? $this->params ['expressNumber'] : "";
  216. $this->data ['expressCom'] = $expressCom;
  217. $this->data ['expressNumber'] = $expressNumber;
  218. $this->render ( "/admin/invoiceExpress", $this->data );
  219. }
  220. function invoiceAdd() {
  221. Doo::loadModel ( 'invoice' );
  222. $invoice = new invoice ();
  223. $detail=$invoice->getInvoiceByNew($this->staff [0] ['sid']);
  224. Doo::loadModel ( 'L_category' );
  225. $lCategory = new L_category ();
  226. $category = $lCategory->find ( array (
  227. 'asArray' => true
  228. ) );
  229. $this->data ['category'] = $category;
  230. Doo::loadModel ( 'invoiceTraining' );
  231. $invoiceTraining = new invoiceTraining ();
  232. $itList = $invoiceTraining->getInvoiceTrainingByUnfinished ($this->staff [0] ['cid']);
  233. $this->data ['itList'] = $itList;
  234. $this->data ['memu'] = "invoice";
  235. $this->data ['staff'] = $this->staff;
  236. $this->data ['receiptMemu'] = 'invoice';
  237. $this->render ( "/admin/invoiceAdd", $this->data );
  238. }
  239. function invoiceAddFill() {
  240. Doo::loadModel ( 'invoice' );
  241. $invoice = new invoice ();
  242. $detail=$invoice->getInvoiceByNew($this->staff [0] ['sid']);
  243. Doo::loadModel ( 'L_category' );
  244. $lCategory = new L_category ();
  245. $category = $lCategory->find ( array (
  246. 'asArray' => true
  247. ) );
  248. $this->data ['category'] = $category;
  249. Doo::loadModel ( 'invoiceTraining' );
  250. $invoiceTraining = new invoiceTraining ();
  251. $itList = $invoiceTraining->getInvoiceTrainingByUnfinished ($this->staff [0] ['cid']);
  252. $this->data ['itList'] = $itList;
  253. Doo::loadModel ( 'invoice' );
  254. $invoice = new invoice ();
  255. $detail=$invoice->getInvoiceByNew($this->staff [0] ['sid']);
  256. $detail['mailItemsArray']=json_decode($detail['mailItemsJson'],true);
  257. $this->data ['invoiceDetail'] = $detail;
  258. $this->data ['memu'] = "invoice";
  259. $this->data ['staff'] = $this->staff;
  260. $this->data ['receiptMemu'] = 'invoice';
  261. $this->render ( "/admin/invoiceAddFill", $this->data );
  262. }
  263. /**
  264. * 提交一份开票申请,并记录下操作日志
  265. *
  266. * @since 1.0.0
  267. * @var integer cid 办事处ID
  268. * @var integer invoiceType 发票类型
  269. * @var integer doPost 是否邮寄
  270. * @var integer invoicePrice 开票金额
  271. * @var string invoiceElement 开票内容
  272. * @var string invoiceTitle 发票抬头
  273. * @var string invoiceCompany 单位名称
  274. * @var string TIN 纳税人识别码
  275. * @var string address 注册地址
  276. * @var string phone 注册电话
  277. * @var string bank 开户银行
  278. * @var string bankAccount 银行账户
  279. * @var string recipients 收件人
  280. * @var string recipientsPhone 收件人手机/电话
  281. * @var string recipientsAddress 收件地址
  282. * @var string mailItems 邮寄物品
  283. * @var string remark 备注
  284. * @return string 返回跳转开票主页路径
  285. */
  286. function invoiceAddDo() {
  287. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  288. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  289. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  290. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  291. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  292. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  293. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  294. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  295. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  296. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  297. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  298. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  299. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  300. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  301. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  302. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  303. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  304. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  305. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  306. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  307. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  308. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  309. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  310. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  311. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  312. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  313. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  314. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  315. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  316. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  317. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  318. $trainId = $this->get_args ( 'trainId' ) ? $this->get_args ( 'trainId' ) : 0;
  319. $settlementType = $this->get_args ( 'settlementType' ) ? $this->get_args ( 'settlementType' ) : "";
  320. /*
  321. * $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;
  322. */
  323. if (empty ( $this->staff [0] ))
  324. die ( 'illegal request-Please login' );
  325. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $settlementType )) {
  326. Doo::loadModel ( 'invoice' );
  327. $invoice = new invoice ();
  328. Doo::loadModel ( 'L_category' );
  329. $lCategory = new L_category ();
  330. Doo::loadModel ( 'invoiceManage' );
  331. $invoiceManage = new invoiceManage ();
  332. Doo::loadModel ( 'invoiceOperationLog' );
  333. $invoiceOperationLog = new invoiceOperationLog ();
  334. Doo::loadClass ( 'XDeode' );
  335. $XDeode = new XDeode ( 5 );
  336. $trainId = $XDeode->decode ( $trainId );
  337. $categoryDetil = $lCategory->getOne ( array (
  338. 'SELECT' => 'title',
  339. 'where' => 'cid=' . $cid,
  340. 'asArray' => true
  341. ) );
  342. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  343. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  344. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  345. // print_r(current($invoiceManageDetail ['staffList']));
  346. // die;
  347. $moldManage = array ();
  348. foreach ( $invoiceManageList as $key => $value ) {
  349. if ($value ['mold'] == '发票打印')
  350. $moldManage [$value ['mold']] = $value ['staffList'];
  351. elseif ($value ['mold'] == '发票邮寄')
  352. $moldManage [$value ['mold']] = $value ['staffList'];
  353. elseif ($value ['mold'] == '发票退票')
  354. $moldManage [$value ['mold']] = $value ['staffList'];
  355. }
  356. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  357. $st = '';
  358. if ($settlementType == 'SOFTWARE') {
  359. $st = 0;
  360. $trainId=0;
  361. } elseif ($settlementType == 'TRAINING') {
  362. $st = 1;
  363. if (empty ( $trainId )&&!is_numeric($trainId)) {
  364. die ( 'illegal request-trainingIdError' );
  365. }
  366. } else {
  367. die ( 'illegal request-settlementError' );
  368. }
  369. $item = array (
  370. 'cid' => $cid,
  371. 'categoryName' => $categoryDetil ['title'],
  372. 'invoiceElement' => $invoiceElement,
  373. 'invoiceQuantity' => $invoiceQuantity,
  374. 'invoiceUnitPrice' => $invoiceUnitPrice,
  375. 'invoicePrice' => $invoicePrice,
  376. 'invoiceType' => $invoiceType,
  377. 'settlementType' => $st,
  378. 'doPost' => $doPost,
  379. 'status' => 1,
  380. 'invoiceSerial' => "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  381. 'date' => date ( "Y-m-d H:i:s" ),
  382. 'updateTime' => date ( "Y-m-d H:i:s" ),
  383. 'sid' => $this->staff [0] ['sid'],
  384. 'userName' => $this->staff [0] ['username'],
  385. 'invoiceManage' => $invoiceManageDetail ['staff'],
  386. 'pendingApprovals' => $pendingApprovalsSid,
  387. 'moldManage' => json_encode ( $moldManage ),
  388. 'remark' => $remark,
  389. 'trainId' => $trainId
  390. );
  391. if ($invoiceType == 0)
  392. $item += array (
  393. 'invoiceTitle' => $invoiceTitle,
  394. 'TIN' => $TINT,
  395. 'address' => $addressT,
  396. 'phone' => $phoneT,
  397. 'bank' => $bankT,
  398. 'bankAccount' => $bankAccountT
  399. );
  400. else {
  401. $item += array (
  402. 'invoiceCompany' => $invoiceCompany,
  403. 'TIN' => $TIN,
  404. 'address' => $address,
  405. 'phone' => $phone,
  406. 'bank' => $bank,
  407. 'bankAccount' => $bankAccount
  408. );
  409. }
  410. if ($doPost == 1) {
  411. $mailList = array (
  412. 'invoice' => 1,
  413. 'mailItems' => $mailItems
  414. );
  415. if (! empty ( $softLock ))
  416. $mailList += array (
  417. 'softLock' => $softLockNum
  418. );
  419. else
  420. $mailList += array (
  421. 'softLock' => 0
  422. );
  423. if (! empty ( $contract ))
  424. $mailList += array (
  425. 'contract' => $contractNum
  426. );
  427. else
  428. $mailList += array (
  429. 'contract' => 0
  430. );
  431. if (! empty ( $instructions ))
  432. $mailList += array (
  433. 'instructions' => $instructionsNum
  434. );
  435. else
  436. $mailList += array (
  437. 'instructions' => 0
  438. );
  439. if (! empty ( $remittance ))
  440. $mailList += array (
  441. 'remittance' => $remittance
  442. );
  443. else
  444. $mailList += array (
  445. 'remittance' => ''
  446. );
  447. $mailString = '发票x1张,备注:' . $mailItems;
  448. if (! empty ( $softLock ))
  449. $mailString .= ',软件锁x' . $softLockNum.'个';
  450. if (! empty ( $contract ))
  451. $mailString .= ',合同x' . $contractNum.'份';
  452. if (! empty ( $instructions ))
  453. $mailString .= ',说明书x' . $instructionsNum.'本';
  454. if (! empty ( $remittance ))
  455. $mailString .= ',汇款账号单(张)';
  456. $item += array (
  457. 'recipients' => $recipients,
  458. 'recipientsPhone' => $recipientsPhone,
  459. 'recipientsAddress' => $recipientsAddress,
  460. 'mailItems' => $mailString,
  461. 'mailItemsJson' => json_encode ( $mailList )
  462. );
  463. }
  464. $iid = $invoice->addInvoice ( $item );
  465. // 如果是培训班结算 创建培训班发票到培训班备份中
  466. if (! empty ( $st )&&$st==1) {
  467. Doo::loadModel ( 'invoiceStore' );
  468. $invoiceStore = new invoiceStore ();
  469. Doo::loadModel ( 'invoiceTraining' );
  470. $invoiceTraining = new invoiceTraining ();
  471. $isid = $invoiceStore->setInvoiceToInvoiceStore ( $iid );
  472. $itemIS = array (
  473. 'isid' => $isid,
  474. 'ipSource' => 1,
  475. 'apStatus'=>1,
  476. 'iid' => $iid
  477. );
  478. $invoiceStore->setInvoiceStoreByCondition ( $itemIS );
  479. // 更新培训班总数量
  480. $detailIT = $invoiceTraining->getInvoiceTrainingByItid ( $trainId );
  481. $item = array (
  482. 'itid' => $trainId,
  483. 'invoiceTotal' => $detailIT ['invoiceTotal'] + 1,
  484. 'submitStatus' => 1
  485. );
  486. $itid = $invoiceTraining->setInvoiceTrainByCondition ( $item );
  487. }
  488. // 操作日志
  489. $item = array (
  490. 'date' => date ( "Y-m-d H:i:s" ),
  491. 'operation' => "创建",
  492. 'status' => 1,
  493. 'img' => $this->staff [0] ['avatar'],
  494. 'username' => $this->staff [0] ['username'],
  495. 'uid' => $this->staff [0] ['sid'],
  496. 'category' => $this->staff [0] ['category'],
  497. 'iid' => $iid
  498. );
  499. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  500. $item = array (
  501. 'date' => date ( "Y-m-d H:i:s" ),
  502. 'operation' => "提交审批",
  503. 'status' => 1,
  504. 'img' => $this->staff [0] ['avatar'],
  505. 'username' => $this->staff [0] ['username'],
  506. 'uid' => $this->staff [0] ['sid'],
  507. 'category' => $this->staff [0] ['category'],
  508. 'iid' => $iid
  509. );
  510. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  511. Doo::loadModel ( 'staff' );
  512. $staff = new staff ();
  513. $username2 = $staff->getOne ( array (
  514. 'select' => 'wxid',
  515. 'where' => 'sid=' . $pendingApprovalsSid,
  516. 'asArray' => TRUE
  517. ) );
  518. // 发送微信审批通知
  519. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  520. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  521. }
  522. return "/invoice";
  523. }
  524. function invoiceEdit() {
  525. Doo::loadClass ( 'XDeode' );
  526. $XDeode = new XDeode ( 5 );
  527. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  528. $iid = $XDeode->decode ( $iid );
  529. if (! is_numeric ( $iid ))
  530. die ( 'illegal request' );
  531. Doo::loadModel ( 'invoice' );
  532. $invoice = new invoice ();
  533. Doo::loadModel ( 'invoiceOperationLog' );
  534. $invoiceOperationLog = new invoiceOperationLog ();
  535. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  536. $operation = $invoiceOperationLog->getInvoiceOperationByDropped ( $iid );
  537. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  538. $this->data ['operation'] = $operation;
  539. $this->data ['invoiceDetail'] = $invoiceDetail;
  540. $this->data ['memu'] = "invoice";
  541. $this->data ['staff'] = $this->staff;
  542. $this->data ['receiptMemu'] = 'invoice';
  543. $this->render ( "/admin/invoiceEdit", $this->data );
  544. }
  545. /**
  546. * 重新编辑退回的发票
  547. * @return string
  548. */
  549. function invoiceEditDo() {
  550. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  551. Doo::loadModel ( 'invoice' );
  552. $invoice = new invoice ();
  553. $iid = $invoice->authcode ( $iidKey );
  554. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  555. die ( 'illegal request' );
  556. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  557. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  558. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  559. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  560. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  561. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  562. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  563. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  564. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  565. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  566. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  567. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  568. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  569. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  570. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  571. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  572. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  573. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  574. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  575. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  576. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  577. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  578. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  579. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  580. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  581. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  582. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  583. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  584. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  585. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  586. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  587. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  588. Doo::loadModel ( 'invoiceManage' );
  589. $invoiceManage = new invoiceManage ();
  590. Doo::loadModel ( 'invoiceOperationLog' );
  591. $invoiceOperationLog = new invoiceOperationLog ();
  592. $cid = explode ( ':', $cid );
  593. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  594. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  595. $moldManage = array ();
  596. foreach ( $invoiceManageList as $key => $value ) {
  597. if ($value ['mold'] == '发票打印')
  598. $moldManage [$value ['mold']] = $value ['staffList'];
  599. elseif ($value ['mold'] == '发票邮寄')
  600. $moldManage [$value ['mold']] = $value ['staffList'];
  601. elseif ($value ['mold'] == '发票打印')
  602. $moldManage [$value ['mold']] = $value ['staffList'];
  603. }
  604. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  605. $item = array (
  606. 'iid' => $iid,
  607. 'cid' => $cid [0],
  608. 'categoryName' => $cid [1],
  609. 'invoiceElement' => $invoiceElement,
  610. 'invoiceQuantity' => $invoiceQuantity,
  611. 'invoiceUnitPrice' => $invoiceUnitPrice,
  612. 'invoicePrice' => $invoicePrice,
  613. 'invoiceType' => $invoiceType,
  614. 'doPost' => $doPost,
  615. 'status' => 1,
  616. 'updateTime' => date ( "Y-m-d H:i:s" ),
  617. 'remark' => $remark
  618. );
  619. if ($invoiceType == 0)
  620. $item += array (
  621. 'invoiceTitle' => $invoiceTitle,
  622. 'TIN' => $TINT,
  623. 'address' => $addressT,
  624. 'phone' => $phoneT,
  625. 'bank' => $bankT,
  626. 'bankAccount' => $bankAccountT
  627. );
  628. else {
  629. $item += array (
  630. 'invoiceCompany' => $invoiceCompany,
  631. 'TIN' => $TIN,
  632. 'address' => $address,
  633. 'phone' => $phone,
  634. 'bank' => $bank,
  635. 'bankAccount' => $bankAccount
  636. );
  637. }
  638. if ($doPost == 1) {
  639. $mailList = array (
  640. 'invoice' => 1,
  641. 'mailItems' => $mailItems
  642. );
  643. if (! empty ( $softLock ))
  644. $mailList += array (
  645. 'softLock' => $softLockNum
  646. );
  647. else
  648. $mailList += array (
  649. 'softLock' => '0'
  650. );
  651. if (! empty ( $contract ))
  652. $mailList += array (
  653. 'contract' => $contractNum
  654. );
  655. else
  656. $mailList += array (
  657. 'contract' => '0'
  658. );
  659. if (! empty ( $instructions ))
  660. $mailList += array (
  661. 'instructions' => $instructionsNum
  662. );
  663. else
  664. $mailList += array (
  665. 'instructions' => '0'
  666. );
  667. if (! empty ( $remittance ))
  668. $mailList += array (
  669. 'remittance' => $remittance
  670. );
  671. else
  672. $mailList += array (
  673. 'remittance' => ''
  674. );
  675. $mailString = '发票x1,备注:' . $mailItems;
  676. if (! empty ( $softLock ))
  677. $mailString .= ',软件锁x' . $softLockNum;
  678. if (! empty ( $contract ))
  679. $mailString .= ',合同x' . $contractNum;
  680. if (! empty ( $instructions ))
  681. $mailString .= ',说明书x' . $instructionsNum;
  682. if (! empty ( $remittance ))
  683. $mailString .= ',汇款账号单';
  684. $item += array (
  685. 'recipients' => $recipients,
  686. 'recipientsPhone' => $recipientsPhone,
  687. 'recipientsAddress' => $recipientsAddress,
  688. 'mailItems' => $mailString,
  689. 'mailItemsJson' => json_encode ( $mailList )
  690. );
  691. }
  692. $invoice->setInvoiceByCondition ( $item );
  693. $item = array (
  694. 'date' => date ( "Y-m-d H:i:s" ),
  695. 'operation' => "重新提交审批",
  696. 'status' => 1,
  697. 'img' => $this->staff [0] ['avatar'],
  698. 'username' => $this->staff [0] ['username'],
  699. 'uid' => $this->staff [0] ['sid'],
  700. 'category' => $this->staff [0] ['category'],
  701. 'iid' => $iid
  702. );
  703. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  704. }
  705. return "/invoice";
  706. }
  707. /**
  708. * 培训班
  709. */
  710. function invoiceTraining() {
  711. Doo::loadModel ( 'L_category' );
  712. $lCategory = new L_category ();
  713. Doo::loadModel ( 'invoiceTraining' );
  714. $invoiceTraining = new invoiceTraining ();
  715. $itTodoList = $invoiceTraining->getInvoiceTrainingByTodo ( '', $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  716. $itedList = $invoiceTraining->getInvoiceTrainingByStatus ( 2, '', $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  717. $category = $lCategory->getCategory ();
  718. $itid = array ();
  719. foreach ( $itTodoList as $key=>$value ) {
  720. array_push ( $itid, $value ['itid'] );
  721. //如果入账100%更新为已完成
  722. if ($itTodoList [$key] ['arriveSchedule']>=100){
  723. $invoiceTraining = new invoiceTraining ();
  724. $invoiceTraining->itid = $value ['itid'];
  725. $invoiceTraining->status = 2;
  726. $invoiceTraining->update ();
  727. }
  728. }
  729. foreach ( $itedList as $value ) {
  730. array_push ( $itid, $value ['itid'] );
  731. }
  732. $itid = implode ( ',', $itid );
  733. $this->data ['itStatist'] = $invoiceTraining->getInvoiceTrainStatistics ( $itid );
  734. // print_r($itTodoList);
  735. $this->data ['trainCount'] = count ( $itTodoList ) + count ( $itedList );
  736. $this->data ['itTodoList'] = $itTodoList;
  737. $this->data ['itedList'] = $itedList;
  738. $this->data ['category'] = $category;
  739. $this->data ['memu'] = "invoice";
  740. $this->data ['staff'] = $this->staff;
  741. $this->data ['receiptMemu'] = 'invoiceTraining';
  742. $this->render ( "/admin/invoiceTraining", $this->data );
  743. }
  744. /**
  745. * 创建培训班
  746. */
  747. function invoiceTrainingAdd() {
  748. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  749. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  750. $trainDate = $this->get_args ( 'trainDate' ) ? $this->get_args ( 'trainDate' ) : "";
  751. if (empty ( $this->staff [0] ))
  752. die ( 'illegal request' );
  753. if (! empty ( $cid ) && ! empty ( $trainName ) && ! empty ( $trainDate )) {
  754. Doo::loadModel ( 'invoiceTraining' );
  755. $invoiceTraining = new invoiceTraining ();
  756. Doo::loadModel ( 'invoice' );
  757. $invoice = new invoice ();
  758. Doo::loadModel ( 'L_category' );
  759. $lCategory = new L_category ();
  760. Doo::loadModel ( 'invoiceManage' );
  761. $invoiceManage = new invoiceManage ();
  762. Doo::loadModel ( 'invoiceOperationLog' );
  763. $invoiceOperationLog = new invoiceOperationLog ();
  764. $item = array (
  765. 'cid' => $cid,
  766. 'trainName' => $trainName,
  767. 'trainDate' => $trainDate,
  768. 'creator' => $this->staff [0] ['sid'],
  769. 'creatorDate' => date ( "Y-m-d H:i:s" )
  770. );
  771. $itid = $invoiceTraining->addInvoiceTraining ( $item );
  772. }
  773. return "/invoiceTraining";
  774. }
  775. /**
  776. * 删除培训班
  777. */
  778. function invoiceTrainingDelDo() {
  779. $itid = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  780. if (! empty ( $itid )) {
  781. Doo::loadModel ( 'invoiceTraining' );
  782. $invoiceTraining = new invoiceTraining ();
  783. $invoiceTraining->delInvoiceTrainingByItid ( $itid );
  784. }
  785. return "/invoiceTraining";
  786. }
  787. /**
  788. * 培训班详情
  789. */
  790. function invoiceTrainingDetail() {
  791. $trainStatus = $this->get_args ( 'trainStatus' ) ? $this->get_args ( 'trainStatus' ) : "ALL";
  792. $itid = isset ( $this->params ['trainingKey'] ) ? $this->params ['trainingKey'] : "";
  793. Doo::loadModel ( 'invoiceTraining' );
  794. $invoiceTraining = new invoiceTraining ();
  795. Doo::loadModel ( 'invoiceStore' );
  796. $invoiceStore = new invoiceStore ();
  797. if (empty ( $itid ))
  798. die ( 'illegal request' );
  799. $con = ' (b.untreadStatus is null or b.untreadStatus!=2) and ';
  800. if ($trainStatus == "SUBED")
  801. $con = ' (b.untreadStatus is null ) and ';
  802. elseif ($trainStatus == "APPROVAL")
  803. $con = ' ( b.status=1 and b.untreadStatus!=2 ) and ';
  804. elseif ($trainStatus == "TICKET")
  805. $con = ' (b.printStatus=1 and b.status=2 and b.untreadStatus!=2) and ';
  806. $detail = $invoiceTraining->getInvoiceTrainingByItid ( $itid );
  807. $isList = $invoiceStore->getinvoiceStoreByItid ( $itid, $con );
  808. // print_r($isList);
  809. $trainlist = array ();
  810. foreach ( $isList as $key => $value ) {
  811. $irDetail = array ();
  812. if ($value ['apStatus'] == 1) {
  813. // array_push ( $irDetail, '' );
  814. array_push ( $irDetail, '<input disabled type="checkbox" style="display:none" >' );
  815. } else {
  816. array_push ( $irDetail, '<input type="checkbox" class="hide" id="' . $value ['storeKey'] . '" name="isBox" value="' . $value ['storeKey'] . '" > <a href="/invoiceStoreEdit/' . $value ['storeKey'] . '.html">编辑</a>
  817. <a href="#confirm" onclick="invoiceStoreApproval(\'' . $value ['storeKey'] . '\')" data-toggle="modal">提交审批</a>
  818. <a href="#del" node-iStore="del" data-key="' . $value ['storeKey'] . '" onclick="invoiceStoreDel(\'' . $value ['storeKey'] . '\')" data-toggle="modal" class="colRed">移除</a>' );
  819. }
  820. array_push ( $irDetail, $value ['invoiceSerial'] );
  821. if ($value ['invoiceType'] == 1)
  822. array_push ( $irDetail, $value ['invoiceCompany'] );
  823. else
  824. array_push ( $irDetail, $value ['invoiceTitle'] );
  825. array_push ( $irDetail, $value ['TIN'] );
  826. array_push ( $irDetail, $value ['userName'] );
  827. if (empty ( $value ['mailItems'] ) && $value ['apStatus'] != 1) {
  828. array_push ( $irDetail, '<a href="#confirm-erro" onclick="invoiceStoreMail(\'' . $value ['storeKey'] . '\')" data-toggle="modal">设置邮寄物品</a>' );
  829. } else
  830. array_push ( $irDetail, $value ['mailItems'] );
  831. array_push ( $irDetail, $value ['recipientsAddress'] . $value ['recipients'] . $value ['recipientsPhone'] );
  832. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  833. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  834. array_push ( $irDetail, $value ['invoiceElement'] );
  835. array_push ( $irDetail, $value ['invoiceQuantity'] );
  836. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  837. if ($value ['invoiceType'] == 1)
  838. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  839. else
  840. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  841. array_push ( $irDetail, $value ['remark'] );
  842. if ($value ['status'] == 1)
  843. array_push ( $irDetail, '审批中' );
  844. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1)
  845. array_push ( $irDetail, '已出票' );
  846. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1 && $value ['printStatus'] != 'irid' && ($value ['untreadStatus'] == 3 || $value ['untreadStatus'] == 0))
  847. array_push ( $irDetail, '已入账' );
  848. else
  849. array_push ( $irDetail, '' );
  850. array_push ( $irDetail, $value ['invoiceNo'] );
  851. array_push ( $irDetail, $value ['printTime'] );
  852. $html = '';
  853. foreach ( $value ['invoiceReceivables'] as $value ) {
  854. $html .= '&nbsp;<a href="#billing" node-invoice="INFO" data-type="receivables" data-iskey="' . $value [2] . '" data-toggle="modal">' . $value [1] . '</a>';
  855. }
  856. array_push ( $irDetail, $html );
  857. array_push ( $trainlist, $irDetail );
  858. }
  859. $trainlistJson = json_encode ( $trainlist );
  860. if (empty ( $detail ))
  861. die ( 'illegal request' );
  862. $this->data ['trainStatus'] = $trainStatus;
  863. $this->data ['itid'] = $itid;
  864. $this->data ['trainlistJson'] = $trainlistJson;
  865. $this->data ['iTrainDetail'] = $detail;
  866. $this->data ['memu'] = "invoice";
  867. $this->data ['staff'] = $this->staff;
  868. $this->data ['receiptMemu'] = 'invoiceTraining';
  869. $this->render ( "/admin/invoiceTrainingDetail", $this->data );
  870. }
  871. /**
  872. * 上传培训班发票
  873. * @return string
  874. */
  875. function invoiceTrainingUpload() {
  876. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  877. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  878. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  879. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  880. header ( "HTTP/1.1 500 Internal Server Error" );
  881. echo "POST exceeded maximum allowed size.";
  882. exit ( 0 );
  883. }
  884. // Settings
  885. $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)
  886. $upload_name = "Filedata";
  887. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  888. $extension_whitelist = array (
  889. "doc",
  890. "txt",
  891. "jpg",
  892. "gif",
  893. "png"
  894. ); // Allowed file extensions
  895. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  896. // Other variables
  897. $MAX_FILENAME_LENGTH = 260;
  898. $file_name = "";
  899. $file_extension = "";
  900. $uploadErrors = array (
  901. 0 => "文件上传成功",
  902. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  903. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  904. 3 => "上传的文件仅为部分文件",
  905. 4 => "没有文件上传",
  906. 6 => "缺少临时文件夹"
  907. );
  908. $nk = time ();
  909. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  910. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  911. echo "文件无法保存.";
  912. exit ( 0 );
  913. }
  914. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  915. echo json_encode ( array (
  916. 'filename' => $file_name,
  917. 'id' => $nk
  918. ) );
  919. exit ( 0 );
  920. }
  921. /**
  922. * 导入发票临时仓库
  923. */
  924. function invoiceStoreImport() {
  925. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  926. $trainingKey = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  927. $path = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  928. if ($path != "" && ! empty ( $trainingKey )) {
  929. Doo::loadModel ( 'invoiceStore' );
  930. Doo::loadModel ( 'staff' );
  931. $staff = new staff ();
  932. Doo::loadModel ( 'invoiceTraining' );
  933. $invoiceTraining = new invoiceTraining ();
  934. Doo::loadClass ( 'XDeode' );
  935. $XDeode = new XDeode ( 5 );
  936. $itid = $XDeode->decode ( $trainingKey );
  937. $exlArray = $this->formatExcelToArrayTrain ( DOO::conf ()->SITE_PATH . "upload/invoiceTraining/" . $path );
  938. $userName = $this->staff [0] ['username'];
  939. $sDetail = $staff->getStaffByName ( $userName );
  940. // die('sdd');
  941. // 可以优化
  942. foreach ( $exlArray as $key => $value ) {
  943. // 开票
  944. $invoice = new invoiceStore ();
  945. $invoice->trainId = $itid;
  946. $invoice->invoiceType = 0;
  947. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  948. $invoice->invoiceType = 1;
  949. $invoice->invoiceQuantity = $value ['invoiceQuantity'];
  950. $invoice->invoiceUnitPrice = $value ['invoiceUnitPrice'];
  951. $invoice->invoicePrice = $value ['invoiceQuantity'] * $value ['invoiceUnitPrice'];
  952. $invoice->invoiceTitle = $value ['invoiceTitle'];
  953. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  954. $invoice->invoiceCompany = $value ['invoiceTitle'];
  955. $invoice->userName = $userName;
  956. $invoice->sid = $sDetail ['sid'];
  957. $invoice->cid = $sDetail ['cid'];
  958. $invoice->categoryName = $sDetail ['category'];
  959. $invoice->invoiceElement = $value ['invoiceElement'];
  960. $invoice->remark = $value ['remark'];
  961. // $invoice->date = $value ['date'];
  962. // $invoice->printTime = $value ['date'];
  963. $invoice->ipSource = 1;
  964. $invoice->printStatus = 1;
  965. $invoice->status = 2;
  966. $invoice->postStatus = 1;
  967. $invoice->untreadStatus = 0;
  968. // $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  969. $invoice->TIN = $value ['TIN'];
  970. $invoice->address = $value ['address'];
  971. $invoice->phone = $value ['phone'];
  972. $invoice->bank = $value ['bank'];
  973. $invoice->bankAccount = $value ['bankAccount'];
  974. $invoice->recipientsAddress = $value ['recipientsAddress'];
  975. $invoice->recipients = $value ['recipients'];
  976. $invoice->recipientsPhone = $value ['recipientsPhone'];
  977. $iid = $invoice->insert ();
  978. }
  979. // 加入发票总数量
  980. $item = array (
  981. 'itid' => $itid,
  982. 'invoiceTotal' => count ( $exlArray )
  983. );
  984. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  985. return '/invoiceTrainingDetail/' . $trainingKey . ".html";
  986. }
  987. echo 'no file';
  988. }
  989. /**
  990. * 编辑仓库里的发票
  991. */
  992. function invoiceStoreEdit() {
  993. Doo::loadClass ( 'XDeode' );
  994. $XDeode = new XDeode ( 5 );
  995. $iid = isset ( $this->params ['storeKey'] ) ? $this->params ['storeKey'] : "";
  996. $iid = $XDeode->decode ( $iid );
  997. if (! is_numeric ( $iid ))
  998. die ( 'illegal request' );
  999. Doo::loadModel ( 'invoiceStore' );
  1000. $invoiceStore = new invoiceStore ();
  1001. $invoiceDetail = $invoiceStore->getInvoiceStoreByIsid ( $iid );
  1002. // print_r($invoiceDetail);
  1003. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  1004. $this->data ['invoiceDetail'] = $invoiceDetail;
  1005. $this->data ['memu'] = "invoice";
  1006. $this->data ['staff'] = $this->staff;
  1007. $this->data ['receiptMemu'] = 'invoiceTraining';
  1008. $this->render ( "/admin/invoiceStoreEdit", $this->data );
  1009. }
  1010. function invoiceStoreEditDo() {
  1011. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1012. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1013. Doo::loadModel ( 'invoiceStore' );
  1014. $invoice = new invoiceStore ();
  1015. Doo::loadClass ( 'XDeode' );
  1016. $XDeode = new XDeode ( 5 );
  1017. $iid = $XDeode->decode ( $storeKey );
  1018. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1019. die ( 'illegal request' );
  1020. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  1021. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  1022. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  1023. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  1024. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  1025. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  1026. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  1027. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  1028. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  1029. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  1030. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  1031. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  1032. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  1033. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  1034. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1035. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1036. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1037. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1038. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  1039. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  1040. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  1041. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  1042. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  1043. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  1044. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1045. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1046. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1047. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1048. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1049. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1050. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1051. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  1052. $cid = explode ( ':', $cid );
  1053. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  1054. $item = array (
  1055. 'isid' => $iid,
  1056. 'cid' => $cid [0],
  1057. 'categoryName' => $cid [1],
  1058. 'invoiceElement' => $invoiceElement,
  1059. 'invoiceQuantity' => $invoiceQuantity,
  1060. 'invoiceUnitPrice' => $invoiceUnitPrice,
  1061. 'invoicePrice' => $invoicePrice,
  1062. 'invoiceType' => $invoiceType,
  1063. 'doPost' => $doPost,
  1064. 'status' => 1,
  1065. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1066. 'remark' => $remark
  1067. );
  1068. if ($invoiceType == 0)
  1069. $item += array (
  1070. 'invoiceTitle' => $invoiceTitle,
  1071. 'TIN' => $TINT,
  1072. 'address' => $addressT,
  1073. 'phone' => $phoneT,
  1074. 'bank' => $bankT,
  1075. 'bankAccount' => $bankAccountT
  1076. );
  1077. else {
  1078. $item += array (
  1079. 'invoiceCompany' => $invoiceCompany,
  1080. 'TIN' => $TIN,
  1081. 'address' => $address,
  1082. 'phone' => $phone,
  1083. 'bank' => $bank,
  1084. 'bankAccount' => $bankAccount
  1085. );
  1086. }
  1087. if ($doPost == 1) {
  1088. $mailList = array (
  1089. 'invoice' => 1,
  1090. 'mailItems' => $mailItems
  1091. );
  1092. if (! empty ( $softLock ))
  1093. $mailList += array (
  1094. 'softLock' => $softLockNum
  1095. );
  1096. else
  1097. $mailList += array (
  1098. 'softLock' => '0'
  1099. );
  1100. if (! empty ( $contract ))
  1101. $mailList += array (
  1102. 'contract' => $contractNum
  1103. );
  1104. else
  1105. $mailList += array (
  1106. 'contract' => '0'
  1107. );
  1108. if (! empty ( $instructions ))
  1109. $mailList += array (
  1110. 'instructions' => $instructionsNum
  1111. );
  1112. else
  1113. $mailList += array (
  1114. 'instructions' => '0'
  1115. );
  1116. if (! empty ( $remittance ))
  1117. $mailList += array (
  1118. 'remittance' => $remittance
  1119. );
  1120. else
  1121. $mailList += array (
  1122. 'remittance' => ''
  1123. );
  1124. $mailString = '发票x1,备注:' . $mailItems;
  1125. if (! empty ( $softLock ))
  1126. $mailString .= ',软件锁x' . $softLockNum;
  1127. if (! empty ( $contract ))
  1128. $mailString .= ',合同x' . $contractNum;
  1129. if (! empty ( $instructions ))
  1130. $mailString .= ',说明书x' . $instructionsNum;
  1131. if (! empty ( $remittance ))
  1132. $mailString .= ',汇款账号单';
  1133. $item += array (
  1134. 'recipients' => $recipients,
  1135. 'recipientsPhone' => $recipientsPhone,
  1136. 'recipientsAddress' => $recipientsAddress,
  1137. 'mailItems' => $mailString,
  1138. 'mailItemsJson' => json_encode ( $mailList )
  1139. );
  1140. }
  1141. $invoice->setInvoiceStoreByCondition ( $item );
  1142. }
  1143. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1144. }
  1145. /**
  1146. *
  1147. * @return string
  1148. */
  1149. function invoiceStoreDelete() {
  1150. Doo::loadClass ( 'XDeode' );
  1151. $XDeode = new XDeode ( 5 );
  1152. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1153. $iStoreKey = $this->get_args ( 'iStoreKey' ) ? $this->get_args ( 'iStoreKey' ) : 0;
  1154. $isid = $XDeode->decode ( $iStoreKey );
  1155. $itid = $XDeode->decode ( $trainKey );
  1156. if (! is_numeric ( $isid ))
  1157. die ( 'illegal request' );
  1158. Doo::loadModel ( 'invoiceStore' );
  1159. $invoiceStore = new invoiceStore ();
  1160. $invoiceStore->delete ( array (
  1161. 'where' => 'isid=' . $isid,
  1162. 'limit' => 1
  1163. ) );
  1164. Doo::loadModel ( 'invoiceTraining' );
  1165. $invoiceTraining = new invoiceTraining ();
  1166. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1167. $item = array (
  1168. 'itid' => $itid,
  1169. 'invoiceTotal' => $itDetail ['invoiceTotal'] - 1
  1170. );
  1171. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1172. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1173. }
  1174. /**
  1175. * 批量删除库里发票
  1176. */
  1177. function invoiceStoreBatchDelete() {
  1178. Doo::loadClass ( 'XDeode' );
  1179. $XDeode = new XDeode ( 5 );
  1180. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1181. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1182. if (empty($trainKey)||empty($storeKey))
  1183. die ( 'illegal request-IdKey' );
  1184. $tid = $XDeode->decode ( $trainKey );
  1185. if (! is_numeric ( $tid ) && ! empty ( $storeKey ))
  1186. die ( 'illegal request' );
  1187. Doo::loadModel ( 'invoiceStore' );
  1188. $isidKeyList = explode ( ',', $storeKey );
  1189. $isidList = array ();
  1190. foreach ( $isidKeyList as $value ) {
  1191. $isid = $XDeode->decode ( $value );
  1192. if (! empty ( $isid ) && is_numeric ( $isid ))
  1193. array_push ( $isidList, $isid );
  1194. }
  1195. $isidString = implode ( ',', $isidList );
  1196. $invoiceStore = new invoiceStore ();
  1197. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,apStatus' );
  1198. $isidList = array ();
  1199. foreach ( $isList as $key => $value ) {
  1200. if ($value ['apStatus'] == 0)
  1201. array_push ( $isidList, $value ['isid'] );
  1202. }
  1203. $isidString = implode ( ',', $isidList );
  1204. // print_r($isList);
  1205. // echo $isidString;
  1206. $invoiceStore = new invoiceStore ();
  1207. $invoiceStore->delete ( array (
  1208. 'where' => "isid in ( " . $isidString . ")",
  1209. 'asArray' => TRUE
  1210. ) );
  1211. Doo::loadModel ( 'invoiceTraining' );
  1212. $invoiceTraining = new invoiceTraining ();
  1213. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1214. $item = array (
  1215. 'itid' => $tid,
  1216. 'invoiceTotal' => $itDetail ['invoiceTotal'] - count ( $isidList )
  1217. );
  1218. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1219. // echo $tid;
  1220. // echo $storeKey;
  1221. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1222. }
  1223. /**
  1224. * 仓库发票提交审批
  1225. * @return string
  1226. */
  1227. function invoiceStoreApproval() {
  1228. Doo::loadClass ( 'XDeode' );
  1229. $XDeode = new XDeode ( 5 );
  1230. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1231. $iStoreKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1232. $isid = $XDeode->decode ( $iStoreKey );
  1233. $trainId = $XDeode->decode ( $trainKey );
  1234. if (! is_numeric ( $isid ))
  1235. die ( 'illegal request' );
  1236. Doo::loadModel ( 'invoiceStore' );
  1237. Doo::loadModel ( 'invoice' );
  1238. $invoice = new invoice ();
  1239. // 加入限制必须填写入开票内容和邮寄物品
  1240. $invoiceStore = new invoiceStore ();
  1241. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid, 'isid,trainId ,invoiceElement,mailItemsJson' );
  1242. if (empty ( $isDetail ['invoiceElement'] ) || empty ( $isDetail ['mailItemsJson'] )) {
  1243. header ( 'Content-Type:text/html;charset=utf-8' );
  1244. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1245. }
  1246. // 拷贝插入一条发票数据
  1247. $invoiceStore = new invoiceStore ();
  1248. $iid = $invoiceStore->setInvoiceStoreToApproval ( $isid );
  1249. $invoiceStore = new invoiceStore ();
  1250. $item = array (
  1251. 'isid' => $isid,
  1252. 'iid' => $iid,
  1253. 'apStatus' => 1
  1254. );
  1255. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1256. Doo::loadModel ( 'invoiceManage' );
  1257. $invoiceManage = new invoiceManage ();
  1258. Doo::loadModel ( 'invoiceOperationLog' );
  1259. $invoiceOperationLog = new invoiceOperationLog ();
  1260. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1261. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1262. $moldManage = array ();
  1263. foreach ( $invoiceManageList as $key => $value ) {
  1264. if ($value ['mold'] == '发票打印')
  1265. $moldManage [$value ['mold']] = $value ['staffList'];
  1266. elseif ($value ['mold'] == '发票邮寄')
  1267. $moldManage [$value ['mold']] = $value ['staffList'];
  1268. elseif ($value ['mold'] == '发票退票')
  1269. $moldManage [$value ['mold']] = $value ['staffList'];
  1270. }
  1271. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1272. $item = array (
  1273. 'iid' => $iid,
  1274. 'invoiceSerial' => "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  1275. 'date' => date ( "Y-m-d H:i:s" ),
  1276. 'status' => 1,
  1277. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1278. 'trainId' => $trainId,
  1279. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1280. 'moldManage' => json_encode ( $moldManage ),
  1281. 'settlementType'=>1,
  1282. 'pendingApprovals' => $pendingApprovalsSid
  1283. );
  1284. $invoice->setInvoiceByCondition ( $item );
  1285. Doo::loadModel ( 'invoiceTraining' );
  1286. $invoiceTraining = new invoiceTraining ();
  1287. $item = array (
  1288. 'itid' => $trainId,
  1289. 'submitStatus' => 1
  1290. );
  1291. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1292. $item = array (
  1293. 'date' => date ( "Y-m-d H:i:s" ),
  1294. 'operation' => "创建",
  1295. 'status' => 1,
  1296. 'img' => $this->staff [0] ['avatar'],
  1297. 'username' => $this->staff [0] ['username'],
  1298. 'uid' => $this->staff [0] ['sid'],
  1299. 'category' => $this->staff [0] ['category'],
  1300. 'iid' => $iid
  1301. );
  1302. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1303. $item = array (
  1304. 'date' => date ( "Y-m-d H:i:s" ),
  1305. 'operation' => "提交审批",
  1306. 'status' => 1,
  1307. 'img' => $this->staff [0] ['avatar'],
  1308. 'username' => $this->staff [0] ['username'],
  1309. 'uid' => $this->staff [0] ['sid'],
  1310. 'category' => $this->staff [0] ['category'],
  1311. 'iid' => $iid
  1312. );
  1313. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1314. Doo::loadModel ( 'staff' );
  1315. $staff = new staff ();
  1316. $username2 = $staff->getOne ( array (
  1317. 'select' => 'wxid',
  1318. 'where' => 'sid=' . $pendingApprovalsSid,
  1319. 'asArray' => TRUE
  1320. ) );
  1321. // 发送微信审批通知
  1322. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1323. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1324. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1325. }
  1326. /**
  1327. * 批量提交发票
  1328. * @return string
  1329. */
  1330. function invoiceStoreBatchApproval() {
  1331. Doo::loadClass ( 'XDeode' );
  1332. $XDeode = new XDeode ( 5 );
  1333. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1334. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1335. if (empty($trainKey)||empty($storeKey))
  1336. die ( 'illegal request-IdKey' );
  1337. $trainId = $XDeode->decode ( $trainKey );
  1338. $isidKeyList = explode ( ',', $storeKey );
  1339. $isidList = array ();
  1340. foreach ( $isidKeyList as $value ) {
  1341. $isid = $XDeode->decode ( $value );
  1342. if (! empty ( $isid ) && is_numeric ( $isid ))
  1343. array_push ( $isidList, $isid );
  1344. }
  1345. $isidString = implode ( ',', $isidList );
  1346. if (! is_numeric ( $trainId ))
  1347. die ( 'illegal request' );
  1348. Doo::loadModel ( 'invoiceStore' );
  1349. Doo::loadModel ( 'invoice' );
  1350. // 判断哪些已经加入审批过
  1351. // 加入限制必须填写入开票内容和邮寄物品
  1352. $invoiceStore = new invoiceStore ();
  1353. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,trainId ,invoiceElement,mailItemsJson' );
  1354. foreach ( $isList as $key => $value ) {
  1355. if (empty ( $value ['invoiceElement'] ) || empty ( $value ['mailItemsJson'] )) {
  1356. header ( 'Content-Type:text/html;charset=utf-8' );
  1357. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1358. }
  1359. }
  1360. // 拷贝插入一条发票数据
  1361. $invoiceStore = new invoiceStore ();
  1362. $invoiceStore->setInvoiceStoreBatchToApproval ( $isidString );
  1363. $invoiceStore = new invoiceStore ();
  1364. $item = array (
  1365. 'apStatus' => 1
  1366. );
  1367. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1368. // 获得正式发票ID
  1369. $invoice = new invoice ();
  1370. $iidList = $invoice->getInvoiceByIstoreid ( $isidString, 'iid,isid' );
  1371. $sqlList = array ();
  1372. $iidString = '';
  1373. $iida = array ();
  1374. foreach ( $iidList as $key => $value ) {
  1375. $sqlList [$value ['isid']] = $value ['iid'];
  1376. array_push ( $iida, $value ['iid'] );
  1377. }
  1378. $iidString = implode ( ',', $iida );
  1379. $ids = implode ( ',', array_keys ( $sqlList ) );
  1380. $sql = "UPDATE CLD_invoiceStore SET iid = CASE isid ";
  1381. foreach ( $sqlList as $id => $ordinal ) {
  1382. $sql .= sprintf ( "WHEN %d THEN %d ", $id, $ordinal );
  1383. }
  1384. $sql .= "END WHERE isid IN ($ids)";
  1385. $invoiceStore = new invoiceStore ();
  1386. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1387. Doo::loadModel ( 'invoiceManage' );
  1388. $invoiceManage = new invoiceManage ();
  1389. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1390. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1391. $moldManage = array ();
  1392. foreach ( $invoiceManageList as $key => $value ) {
  1393. if ($value ['mold'] == '发票打印')
  1394. $moldManage [$value ['mold']] = $value ['staffList'];
  1395. elseif ($value ['mold'] == '发票邮寄')
  1396. $moldManage [$value ['mold']] = $value ['staffList'];
  1397. elseif ($value ['mold'] == '发票退票')
  1398. $moldManage [$value ['mold']] = $value ['staffList'];
  1399. }
  1400. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1401. // 批量更新发票信息
  1402. $item = array (
  1403. 'date' => date ( "Y-m-d H:i:s" ),
  1404. 'status' => 1,
  1405. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1406. 'trainId' => $trainId,
  1407. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1408. 'moldManage' => json_encode ( $moldManage ),
  1409. 'settlementType'=>1,
  1410. 'pendingApprovals' => $pendingApprovalsSid
  1411. );
  1412. $invoice = new invoice ();
  1413. $invoice->BatchInvoiceByCondition ( $item, $iidString );
  1414. // 批量更新发票序列号
  1415. $sqlList = array ();
  1416. foreach ( $iida as $value ) {
  1417. $sqlList [$value] = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1418. }
  1419. $ids = implode ( ',', array_keys ( $sqlList ) );
  1420. $sql = "UPDATE CLD_invoice SET invoiceSerial = CASE iid ";
  1421. foreach ( $sqlList as $id => $ordinal ) {
  1422. $sql .= sprintf ( "WHEN %d THEN '%s' ", $id, $ordinal );
  1423. }
  1424. $sql .= "END WHERE iid IN ($ids)";
  1425. $invoiceStore = new invoiceStore ();
  1426. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1427. // 批量生产操作日志
  1428. Doo::loadModel ( 'invoiceOperationLog' );
  1429. $sqlList = array ();
  1430. foreach ( $iida as $key => $value ) {
  1431. $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 . '"),
  1432. ("' . 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 . '") ';
  1433. array_push ( $sqlList, $sql );
  1434. }
  1435. $iolSql = implode ( ',', $sqlList );
  1436. $sql = "INSERT INTO `CLD_invoiceOperationLog` (`date`, `operation`, `status`, `img`, `username`, `uid`, `category`, `iid`) VALUES " . $iolSql;
  1437. $invoiceOperationLog = new invoiceOperationLog ();
  1438. $invoiceOperationLog->setInvoiceOperationLogBySql ( $sql );
  1439. Doo::loadModel ( 'invoiceTraining' );
  1440. $invoiceTraining = new invoiceTraining ();
  1441. $item = array (
  1442. 'itid' => $trainId,
  1443. 'submitStatus' => 1
  1444. );
  1445. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1446. Doo::loadModel ( 'staff' );
  1447. $staff = new staff ();
  1448. $username2 = $staff->getOne ( array (
  1449. 'select' => 'wxid',
  1450. 'where' => 'sid=' . $pendingApprovalsSid,
  1451. 'asArray' => TRUE
  1452. ) );
  1453. // 发送微信审批通知
  1454. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1455. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1456. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1457. }
  1458. /**
  1459. */
  1460. function invoiceStoreMailItemSet() {
  1461. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1462. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1463. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1464. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1465. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1466. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1467. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1468. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1469. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1470. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1471. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1472. Doo::loadClass ( 'XDeode' );
  1473. $XDeode = new XDeode ( 5 );
  1474. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1475. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1476. $isid = $XDeode->decode ( $storeKey );
  1477. $trainId = $XDeode->decode ( $trainKey );
  1478. if (! is_numeric ( $isid ))
  1479. die ( 'illegal request' );
  1480. Doo::loadModel ( 'invoiceStore' );
  1481. $invoiceStore = new invoiceStore ();
  1482. $mailList = array (
  1483. 'invoice' => 1,
  1484. 'mailItems' => $mailItems
  1485. );
  1486. if (! empty ( $softLock ))
  1487. $mailList += array (
  1488. 'softLock' => $softLockNum
  1489. );
  1490. else
  1491. $mailList += array (
  1492. 'softLock' => 0
  1493. );
  1494. if (! empty ( $contract ))
  1495. $mailList += array (
  1496. 'contract' => $contractNum
  1497. );
  1498. else
  1499. $mailList += array (
  1500. 'contract' => 0
  1501. );
  1502. if (! empty ( $instructions ))
  1503. $mailList += array (
  1504. 'instructions' => $instructionsNum
  1505. );
  1506. else
  1507. $mailList += array (
  1508. 'instructions' => 0
  1509. );
  1510. if (! empty ( $remittance ))
  1511. $mailList += array (
  1512. 'remittance' => $remittance
  1513. );
  1514. else
  1515. $mailList += array (
  1516. 'remittance' => ''
  1517. );
  1518. $mailString = '发票x1,备注:' . $mailItems;
  1519. if (! empty ( $softLock ))
  1520. $mailString .= ',软件锁x' . $softLockNum;
  1521. if (! empty ( $contract ))
  1522. $mailString .= ',合同x' . $contractNum;
  1523. if (! empty ( $instructions ))
  1524. $mailString .= ',说明书x' . $instructionsNum;
  1525. if (! empty ( $remittance ))
  1526. $mailString .= ',汇款账号单';
  1527. $item = array (
  1528. 'isid' => $isid,
  1529. 'doPost' => 1,
  1530. 'mailItems' => $mailString,
  1531. 'mailItemsJson' => json_encode ( $mailList )
  1532. );
  1533. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1534. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1535. }
  1536. /**
  1537. * 批量设置邮寄物品
  1538. */
  1539. function invoiceStoreBatchMailItemSet() {
  1540. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1541. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1542. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1543. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1544. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1545. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1546. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1547. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1548. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1549. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1550. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1551. Doo::loadClass ( 'XDeode' );
  1552. $XDeode = new XDeode ( 5 );
  1553. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1554. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1555. if (empty($trainKey)||empty($storeKey))
  1556. die ( 'illegal request-IdKey' );
  1557. $isidKeyList = explode ( ',', $storeKey );
  1558. $isidList = array ();
  1559. foreach ( $isidKeyList as $value ) {
  1560. $isid = $XDeode->decode ( $value );
  1561. if (! empty ( $isid ) && is_numeric ( $isid ))
  1562. array_push ( $isidList, $isid );
  1563. }
  1564. $isidString = implode ( ',', $isidList );
  1565. $trainId = $XDeode->decode ( $trainKey );
  1566. if (! is_numeric ( $isid ))
  1567. die ( 'illegal request' );
  1568. Doo::loadModel ( 'invoiceStore' );
  1569. $invoiceStore = new invoiceStore ();
  1570. $mailList = array (
  1571. 'invoice' => 1,
  1572. 'mailItems' => $mailItems
  1573. );
  1574. if (! empty ( $softLock ))
  1575. $mailList += array (
  1576. 'softLock' => $softLockNum
  1577. );
  1578. else
  1579. $mailList += array (
  1580. 'softLock' => 0
  1581. );
  1582. if (! empty ( $contract ))
  1583. $mailList += array (
  1584. 'contract' => $contractNum
  1585. );
  1586. else
  1587. $mailList += array (
  1588. 'contract' => 0
  1589. );
  1590. if (! empty ( $instructions ))
  1591. $mailList += array (
  1592. 'instructions' => $instructionsNum
  1593. );
  1594. else
  1595. $mailList += array (
  1596. 'instructions' => 0
  1597. );
  1598. if (! empty ( $remittance ))
  1599. $mailList += array (
  1600. 'remittance' => $remittance
  1601. );
  1602. else
  1603. $mailList += array (
  1604. 'remittance' => ''
  1605. );
  1606. $mailString = '发票x1,备注:' . $mailItems;
  1607. if (! empty ( $softLock ))
  1608. $mailString .= ',软件锁x' . $softLockNum;
  1609. if (! empty ( $contract ))
  1610. $mailString .= ',合同x' . $contractNum;
  1611. if (! empty ( $instructions ))
  1612. $mailString .= ',说明书x' . $instructionsNum;
  1613. if (! empty ( $remittance ))
  1614. $mailString .= ',汇款账号单';
  1615. $item = array (
  1616. 'doPost' => 1,
  1617. 'mailItems' => $mailString,
  1618. 'mailItemsJson' => json_encode ( $mailList )
  1619. );
  1620. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1621. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1622. }
  1623. /**
  1624. * 废弃
  1625. */
  1626. function ajaxGetMailItemByIstore() {
  1627. Doo::loadClass ( 'XDeode' );
  1628. $XDeode = new XDeode ( 5 );
  1629. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1630. $isid = $XDeode->decode ( $storeKey );
  1631. if (! is_numeric ( $isid ))
  1632. die ( 'illegal request' );
  1633. Doo::loadModel ( 'invoiceStore' );
  1634. $invoiceStore = new invoiceStore ();
  1635. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid );
  1636. $isDetail ['mailItemsJson'] = json_decode ( $isDetail ['mailItemsJson'], true );
  1637. echo json_encode ( $isDetail ['mailItemsJson'] );
  1638. exit ();
  1639. }
  1640. /**
  1641. * 终止开票
  1642. */
  1643. function invoiceDroppedDo() {
  1644. $droppedIidKey = $this->get_args ( 'droppedIidKey' ) ? $this->get_args ( 'droppedIidKey' ) : '';
  1645. Doo::loadModel ( 'invoice' );
  1646. $invoice = new invoice ();
  1647. Doo::loadModel ( 'invoiceOperationLog' );
  1648. $invoiceOperationLog = new invoiceOperationLog ();
  1649. $iid = $invoice->authcode ( $droppedIidKey );
  1650. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1651. die ( 'illegal request' );
  1652. $item = array (
  1653. 'iid' => $iid,
  1654. 'status' => 4,
  1655. 'updateTime' => date ( "Y-m-d H:i:s" )
  1656. );
  1657. $invoice->setInvoiceByCondition ( $item );
  1658. $item = array (
  1659. 'date' => date ( "Y-m-d H:i:s" ),
  1660. 'operation' => '终止了开票',
  1661. 'status' => 4,
  1662. 'img' => $this->staff [0] ['avatar'],
  1663. 'username' => $this->staff [0] ['username'],
  1664. 'uid' => $this->staff [0] ['sid'],
  1665. 'category' => $this->staff [0] ['category'],
  1666. 'iid' => $iid
  1667. );
  1668. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1669. return "/invoice";
  1670. }
  1671. /**
  1672. * 更新退票的邮寄信息
  1673. */
  1674. function invoiceUntreadMailDo() {
  1675. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  1676. $untreadCompany = $this->get_args ( 'untreadCompany' ) ? $this->get_args ( 'untreadCompany' ) : "";
  1677. $untreadNumber = $this->get_args ( 'untreadNumber' ) ? $this->get_args ( 'untreadNumber' ) : "";
  1678. $untreadItems = $this->get_args ( 'untreadItems' ) ? $this->get_args ( 'untreadItems' ) : "";
  1679. Doo::loadModel ( 'invoice' );
  1680. $invoice = new invoice ();
  1681. $iid = $invoice->authcode ( $untreadIidKey );
  1682. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1683. die ( 'illegal request' );
  1684. $item = array (
  1685. 'iid' => $iid,
  1686. 'untreadCompany' => $untreadCompany,
  1687. 'untreadNumber' => $untreadNumber,
  1688. 'untreadItems' => $untreadItems
  1689. );
  1690. $invoice->setInvoiceByCondition ( $item );
  1691. return "/invoice";
  1692. }
  1693. /**
  1694. * 申请退票 --
  1695. */
  1696. function invoiceUntreadDo() {
  1697. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  1698. $untreadReason = $this->get_args ( 'untreadReason' ) ? $this->get_args ( 'untreadReason' ) : "";
  1699. $untreadPost = $this->get_args ( 'untreadPost' ) ? $this->get_args ( 'untreadPost' ) : "";
  1700. Doo::loadModel ( 'invoice' );
  1701. $invoice = new invoice ();
  1702. Doo::loadModel ( 'invoiceOperationLog' );
  1703. $invoiceOperationLog = new invoiceOperationLog ();
  1704. Doo::loadModel ( 'invoiceReceivables' );
  1705. $invoiceReceivables = new invoiceReceivables ();
  1706. $iid = $invoice->authcode ( $untreadIidKey );
  1707. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1708. die ( 'illegal request' );
  1709. /*
  1710. * 需求变革 有绑定收款也可以退票 $lt = $invoiceReceivables->getInvoiceReceivablesByIid ( $untreadIidKey ); if (! empty ( $lt )) { header ( 'Content-Type:text/html;charset=utf-8' ); die ( '该发票有收款绑定,请先移除!' ); }
  1711. */
  1712. $item = array (
  1713. 'iid' => $iid,
  1714. 'untreadStatus' => 1,
  1715. 'untreadReason' => $untreadReason,
  1716. 'untreadPost' => $untreadPost,
  1717. 'updateTime' => date ( "Y-m-d H:i:s" )
  1718. );
  1719. $invoice->setInvoiceByCondition ( $item );
  1720. $item = array (
  1721. 'date' => date ( "Y-m-d H:i:s" ),
  1722. 'operation' => '申请退票',
  1723. 'status' => 7,
  1724. 'img' => $this->staff [0] ['avatar'],
  1725. 'username' => $this->staff [0] ['username'],
  1726. 'uid' => $this->staff [0] ['sid'],
  1727. 'category' => $this->staff [0] ['category'],
  1728. 'iid' => $iid
  1729. );
  1730. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1731. return "/invoice";
  1732. }
  1733. /**
  1734. * 删除已终止的开票
  1735. */
  1736. function invoiceDelDo() {
  1737. Doo::loadModel ( 'invoice' );
  1738. $invoice = new invoice ();
  1739. Doo::loadModel ( 'invoiceOperationLog' );
  1740. $invoiceOperationLog = new invoiceOperationLog ();
  1741. Doo::loadClass ( 'XDeode' );
  1742. $XDeode = new XDeode ( 5 );
  1743. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  1744. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  1745. $iid = $XDeode->decode ( $iid );
  1746. Doo::loadModel ( 'invoiceStore' );
  1747. $invoiceStore = new invoiceStore ();
  1748. if (! is_numeric ( $iid ))
  1749. die ( 'illegal request' );
  1750. $invoiceDetail = $invoice->getMyInvoice ( $sid, $iid );
  1751. if (empty ( $invoiceDetail ))
  1752. die ( 'illegal request' );
  1753. $item = array (
  1754. 'iid' => $iid,
  1755. 'isDelete' => 1,
  1756. 'updateTime' => date ( "Y-m-d H:i:s" )
  1757. );
  1758. $invoice->setInvoiceByCondition ( $item );
  1759. $item = array (
  1760. 'date' => date ( "Y-m-d H:i:s" ),
  1761. 'operation' => '删除了已终止的发票',
  1762. 'status' => 4,
  1763. 'img' => $this->staff [0] ['avatar'],
  1764. 'username' => $this->staff [0] ['username'],
  1765. 'uid' => $this->staff [0] ['sid'],
  1766. 'category' => $this->staff [0] ['category'],
  1767. 'iid' => $iid
  1768. );
  1769. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1770. // 删除培训班发票仓库里的发票
  1771. $invoiceStore->delInvoiceStoreByIsid ( $invoiceDetail ['isid'] );
  1772. return "/invoice";
  1773. }
  1774. /**
  1775. */
  1776. function invoiceApproval() {
  1777. Doo::loadModel ( 'invoice' );
  1778. $invoice = new invoice ();
  1779. Doo::loadClass ( 'XDeode' );
  1780. $XDeode = new XDeode ( 5 );
  1781. Doo::loadModel ( 'staff' );
  1782. $staff = new staff ();
  1783. $invoiceList = $invoice->find ( array (
  1784. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  1785. 'desc' => 'iid',
  1786. 'limit' => 10,
  1787. 'asArray' => true
  1788. ) );
  1789. foreach ( $invoiceList as $key => $value ) {
  1790. $invoiceList [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1791. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1792. if (! empty ( $lastApprover )) {
  1793. $lastApproverKey = array_keys ( $lastApprover );
  1794. $lastApprover = end ( $lastApprover );
  1795. $staffDetail = $staff->getOne ( array (
  1796. 'where' => 'sid=' . end ( $lastApproverKey ),
  1797. 'asArray' => true
  1798. ) );
  1799. $lastApprover ['username'] = $staffDetail ['username'];
  1800. }
  1801. $invoiceList [$key] ['lastApprover'] = $lastApprover;
  1802. }
  1803. $ilist = $invoice->getInvoiceByProcessStatus ();
  1804. foreach ( $ilist as $key => $value ) {
  1805. $ilist [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1806. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1807. if (! empty ( $lastApprover )) {
  1808. $lastApproverKey = array_keys ( $lastApprover );
  1809. $lastApprover = end ( $lastApprover );
  1810. $staffDetail = $staff->getOne ( array (
  1811. 'where' => 'sid=' . end ( $lastApproverKey ),
  1812. 'asArray' => true
  1813. ) );
  1814. $lastApprover ['username'] = $staffDetail ['username'];
  1815. }
  1816. $ilist [$key] ['lastApprover'] = $lastApprover;
  1817. }
  1818. // print_r($ilist);
  1819. $this->data ['invoiceList'] = $invoiceList;
  1820. $this->data ['ilist'] = $ilist;
  1821. $this->data ['memu'] = "invoice";
  1822. $this->data ['staff'] = $this->staff;
  1823. $this->data ['receiptMemu'] = 'invoiceApproval';
  1824. $this->render ( "/admin/invoiceApproval", $this->data );
  1825. }
  1826. function invoiceDetail() {
  1827. Doo::loadClass ( 'XDeode' );
  1828. $XDeode = new XDeode ( 5 );
  1829. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  1830. $iid = $XDeode->decode ( $iid );
  1831. if (! is_numeric ( $iid ))
  1832. die ( 'illegal request' );
  1833. Doo::loadModel ( 'invoice' );
  1834. $invoice = new invoice ();
  1835. Doo::loadModel ( 'invoiceOperationLog' );
  1836. $invoiceOperationLog = new invoiceOperationLog ();
  1837. $invoiceDetail = $invoice->getOne ( array (
  1838. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'] . ' and iid=' . $iid,
  1839. 'asArray' => true
  1840. ) );
  1841. if (empty ( $invoiceDetail ))
  1842. die ( 'illegal request' );
  1843. if ($invoiceDetail ['settlementType'] == 1) {
  1844. Doo::loadModel ( 'invoiceTraining' );
  1845. $invoiceTraining = new invoiceTraining ();
  1846. $invoiceDetail ['invoiceTraining'] = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceDetail ['trainId'] );
  1847. }
  1848. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  1849. $this->data ['invoiceDetail'] = $invoiceDetail;
  1850. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  1851. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  1852. $this->data ['memu'] = "invoice";
  1853. $this->data ['staff'] = $this->staff;
  1854. $this->data ['receiptMemu'] = 'invoiceApproval';
  1855. $this->render ( "/admin/invoiceApprovalDetail", $this->data );
  1856. }
  1857. /**
  1858. * 对发票进行审批,其中操作有终止,退回,同意动作。操作成功并记录下操作日志
  1859. *
  1860. * @since 1.0.0
  1861. * @var integer iid 开票ID 已加密
  1862. * @var integer status 发票审批状态
  1863. * @var integer opintion 审批发票的意见
  1864. * @return string 如操作成功返回审批首页
  1865. */
  1866. function invoiceApprovalDo() {
  1867. Doo::loadModel ( 'invoice' );
  1868. $invoice = new invoice ();
  1869. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  1870. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  1871. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  1872. $divApproval = $this->get_args ( 'divApproval' ) ? $this->get_args ( 'divApproval' ) : "";
  1873. $iid = $invoice->authcode ( $iid );
  1874. if (! is_numeric ( $iid ))
  1875. die ( 'illegal request' );
  1876. // && ! empty ( $opinion )
  1877. if (! empty ( $iid ) && ! empty ( $status )) {
  1878. if (! ($status == 2 || $status == 3 || $status == 4))
  1879. die ( 'illegal request' );
  1880. Doo::loadModel ( 'invoiceOperationLog' );
  1881. $invoiceOperationLog = new invoiceOperationLog ();
  1882. $invoiceDetail = $invoice->getOne ( array (
  1883. 'where' => 'status=1 and iid=' . $iid . ' and pendingApprovals=' . $this->staff [0] ['sid'],
  1884. 'asArray' => true
  1885. ) );
  1886. if (empty ( $invoiceDetail ))
  1887. die ( 'illegal request' );
  1888. $processApprovals = json_decode ( $invoiceDetail ['processApprovals'], true );
  1889. $invoiceManage = json_decode ( $invoiceDetail ['invoiceManage'], true );
  1890. if ($status == 3) {
  1891. $invoice->status = $status;
  1892. $item = array (
  1893. 'operation' => $opinion
  1894. );
  1895. } else {
  1896. if (empty ( $processApprovals )) {
  1897. $processApprovals = array (
  1898. $this->staff [0] ['sid'] => array (
  1899. 'date' => date ( "Y-m-d H:i:s" ),
  1900. 'opinion' => $opinion,
  1901. 'status' => $status
  1902. )
  1903. );
  1904. // var_dump(next($invoiceManage));
  1905. $nextInvoiceManage = next ( $invoiceManage );
  1906. // print_r($nextInvoiceManage);
  1907. if ($status != 4 && $nextInvoiceManage !== false)
  1908. $invoice->pendingApprovals = $nextInvoiceManage [0];
  1909. $invoice->processApprovals = json_encode ( $processApprovals );
  1910. // var_dump($invoice);
  1911. // print_r($invoiceManage);
  1912. } else {
  1913. $processApprovals [$this->staff [0] ['sid']] = array (
  1914. 'date' => date ( "Y-m-d H:i:s" ),
  1915. 'opinion' => $opinion,
  1916. 'status' => $status
  1917. );
  1918. $pendingApprovals = 0;
  1919. foreach ( $invoiceManage as $key => $value ) {
  1920. if ($value [0] == $this->staff [0] ['sid']) {
  1921. if (isset ( $invoiceManage [$key + 1] ))
  1922. $pendingApprovals = $invoiceManage [$key + 1] [0];
  1923. break;
  1924. }
  1925. }
  1926. if ($status != 4 && ! empty ( $pendingApprovals ))
  1927. $invoice->pendingApprovals = $pendingApprovals;
  1928. $invoice->processApprovals = json_encode ( $processApprovals );
  1929. }
  1930. $item = array (
  1931. 'operation' => $opinion
  1932. );
  1933. if (count ( $processApprovals ) == count ( $invoiceManage ) && $status != 4) {
  1934. $invoice->status = $status;
  1935. $invoice->pendingApprovals = 0;
  1936. $invoice->approvalTime = date ( "Y-m-d H:i:s" );
  1937. } elseif ($status == 4) {
  1938. $invoice->status = $status;
  1939. $item = array (
  1940. 'operation' => $opinion
  1941. );
  1942. }
  1943. }
  1944. $invoice->updateTime = date ( "Y-m-d H:i:s" );
  1945. $invoice->update ( array (
  1946. 'where' => 'iid=' . $iid
  1947. ) );
  1948. $item += array (
  1949. 'date' => date ( "Y-m-d H:i:s" ),
  1950. 'img' => $this->staff [0] ['avatar'],
  1951. 'username' => $this->staff [0] ['username'],
  1952. 'uid' => $this->staff [0] ['sid'],
  1953. 'category' => $this->staff [0] ['category'],
  1954. 'status' => $status,
  1955. 'iid' => $iid
  1956. );
  1957. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1958. if (empty ( $divApproval ))
  1959. return '/invoiceApproval';
  1960. else
  1961. return '/invoiceApprovalAchieve/PEND';
  1962. }
  1963. die ( 'illegal request' );
  1964. }
  1965. /**
  1966. * 展示需要打印的发票数据
  1967. *
  1968. * @since 1.0.0
  1969. */
  1970. function invoicePrint() {
  1971. Doo::loadModel ( 'invoice' );
  1972. $invoice = new invoice ();
  1973. Doo::loadClass ( 'XDeode' );
  1974. $XDeode = new XDeode ( 5 );
  1975. Doo::loadModel ( 'staff' );
  1976. $staff = new staff ();
  1977. $toPrint = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0 );
  1978. $printed = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 1 );
  1979. foreach ( $toPrint as $key => $value ) {
  1980. $toPrint [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1981. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1982. if (! empty ( $lastApprover )) {
  1983. $lastApproverKey = array_keys ( $lastApprover );
  1984. $lastApprover = end ( $lastApprover );
  1985. $staffDetail = $staff->getOne ( array (
  1986. 'where' => 'sid=' . end ( $lastApproverKey ),
  1987. 'asArray' => true
  1988. ) );
  1989. $lastApprover ['username'] = $staffDetail ['username'];
  1990. }
  1991. $toPrint [$key] ['lastApprover'] = $lastApprover;
  1992. }
  1993. foreach ( $printed as $key => $value ) {
  1994. $printed [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1995. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1996. if (! empty ( $lastApprover )) {
  1997. $lastApproverKey = array_keys ( $lastApprover );
  1998. $lastApprover = end ( $lastApprover );
  1999. $staffDetail = $staff->getOne ( array (
  2000. 'where' => 'sid=' . end ( $lastApproverKey ),
  2001. 'asArray' => true
  2002. ) );
  2003. $lastApprover ['username'] = $staffDetail ['username'];
  2004. }
  2005. $printed [$key] ['lastApprover'] = $lastApprover;
  2006. }
  2007. $this->data ['printed'] = $printed;
  2008. $this->data ['toPrint'] = $toPrint;
  2009. $this->data ['memu'] = "invoice";
  2010. $this->data ['staff'] = $this->staff;
  2011. $this->data ['receiptMemu'] = 'invoicePrint';
  2012. $this->render ( "/admin/invoicePrint", $this->data );
  2013. }
  2014. /**
  2015. * 展示发票打印的详情页面
  2016. *
  2017. * @since 1.0.0
  2018. */
  2019. function invoicePrintDetail() {
  2020. Doo::loadClass ( 'XDeode' );
  2021. $XDeode = new XDeode ( 5 );
  2022. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  2023. $iid = $XDeode->decode ( $iid );
  2024. if (! is_numeric ( $iid ))
  2025. die ( 'illegal request' );
  2026. Doo::loadModel ( 'invoice' );
  2027. $invoice = new invoice ();
  2028. Doo::loadModel ( 'invoiceOperationLog' );
  2029. $invoiceOperationLog = new invoiceOperationLog ();
  2030. Doo::loadModel ( 'invoicePaper' );
  2031. $invoicePaper = new invoicePaper ();
  2032. $invoiceDetail = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0, $iid );
  2033. if (empty ( $invoiceDetail ))
  2034. die ( 'illegal request' );
  2035. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $invoiceDetail ['invoiceType'] );
  2036. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  2037. if ($invoiceDetail ['settlementType'] == 1) {
  2038. Doo::loadModel ( 'invoiceTraining' );
  2039. $invoiceTraining = new invoiceTraining ();
  2040. $invoiceDetail ['invoiceTraining'] = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceDetail ['trainId'] );
  2041. }
  2042. $this->data ['invoicePaperList'] = $invoicePaperList;
  2043. $this->data ['invoiceDetail'] = $invoiceDetail;
  2044. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  2045. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  2046. $this->data ['memu'] = "invoice";
  2047. $this->data ['staff'] = $this->staff;
  2048. $this->data ['receiptMemu'] = 'invoicePrint';
  2049. $this->render ( "/admin/invoicePrintDetail", $this->data );
  2050. }
  2051. /**
  2052. * 所有待打印 发票
  2053. */
  2054. function invoicePrintStayAchieve() {
  2055. Doo::loadModel ( 'invoice' );
  2056. $invoice = new invoice ();
  2057. Doo::loadClass ( 'XDeode' );
  2058. $XDeode = new XDeode ( 5 );
  2059. Doo::loadModel ( 'staff' );
  2060. $staff = new staff ();
  2061. $MebSea = $this->get_args ( 'MebSea' ) ? urldecode ( $this->get_args ( 'MebSea' ) ) : "";
  2062. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  2063. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  2064. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  2065. Doo::loadModel ( 'invoiceTraining' );
  2066. $invoiceTraining = new invoiceTraining ();
  2067. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  2068. $page_size = 12;
  2069. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2070. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : "ALL";
  2071. // $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : "ALL";
  2072. $get = "/" . $status;
  2073. $con = ' and status=2 ';
  2074. if ($status == 'TOPRINT')
  2075. $con = ' and status=2 and printStatus=0 ';
  2076. elseif ($status == 'PRINTED')
  2077. $con = ' and status=2 and printStatus=1';
  2078. if ($invoiceType == 'ORDINARY')
  2079. $con .= ' and invoiceType=0 ';
  2080. elseif ($invoiceType == 'SPECIAL')
  2081. $con .= ' and invoiceType=1 ';
  2082. if ($invoiceTrain == 'ORDINARY')
  2083. $con .= ' and trainId=0 ';
  2084. elseif ($invoiceTrain == 'TRAIN')
  2085. $con .= ' and trainId!=0 ';
  2086. if ($invoiceTrainName != 'ALL') {
  2087. $trainId = $XDeode->decode ( $invoiceTrainName );
  2088. if (is_numeric ( $trainId ))
  2089. $con .= ' and trainId =' . $trainId;
  2090. }
  2091. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2092. $dateArr = explode ( ':', $date );
  2093. $D1 = '';
  2094. $D2 = '';
  2095. if (! empty ( $date )) {
  2096. $D1 = $dateArr [0];
  2097. $D2 = $dateArr [1];
  2098. }
  2099. if (! empty ( $D1 ) && ! empty ( $D2 ) && ! empty ( $date ))
  2100. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2101. if (! empty ( $MebSea )) {
  2102. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  2103. }
  2104. $pageinfo ['page'] = array (
  2105. 'previous' => ''
  2106. );
  2107. $get .= "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea )."&invoiceType=".urlencode ( $invoiceType )."&invoiceTrain=".urlencode ( $invoiceTrain )."";
  2108. $sql = " (untreadStatus=0 or untreadStatus=3) and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  2109. $action = "invoicePrintStayAchieve";
  2110. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2111. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2112. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  2113. $this->data ['trainList'] = $trainList;
  2114. $this->data ['invoiceType'] = $invoiceType;
  2115. $this->data ['invoiceTrain'] = $invoiceTrain;
  2116. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  2117. $this->data ['MebSeaEn'] = $MebSea;
  2118. $this->data ['MebSea'] = urlencode ( $MebSea );
  2119. $this->data ['get'] = $get;
  2120. $this->data ['page'] = $pageinfo;
  2121. $this->data ['date'] = $date;
  2122. $this->data ['status'] = $status;
  2123. $this->data ['invoiceType'] = $invoiceType;
  2124. $this->data ['memu'] = "invoice";
  2125. $this->data ['staff'] = $this->staff;
  2126. foreach ( $list as $key => $value ) {
  2127. $list [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2128. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2129. if (! empty ( $lastApprover )) {
  2130. $lastApproverKey = array_keys ( $lastApprover );
  2131. $lastApprover = end ( $lastApprover );
  2132. $staffDetail = $staff->getOne ( array (
  2133. 'where' => 'sid=' . end ( $lastApproverKey ),
  2134. 'asArray' => true
  2135. ) );
  2136. $lastApprover ['username'] = $staffDetail ['username'];
  2137. }
  2138. $list [$key] ['lastApprover'] = $lastApprover;
  2139. }
  2140. $this->data ['receiptMemu'] = 'invoicePrint';
  2141. $this->data ['list'] = $list;
  2142. $this->render ( "/admin/invoicePrintStayAchieve", $this->data );
  2143. }
  2144. /**
  2145. * 填写票号并完成打印
  2146. * @since 1.0.0
  2147. */
  2148. function invoicePrintDo() {
  2149. Doo::loadModel ( 'invoice' );
  2150. $invoice = new invoice ();
  2151. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2152. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  2153. $invoicePrintType = $this->get_args ( 'invoicePrintType' ) ? $this->get_args ( 'invoicePrintType' ) : "";
  2154. $iid = $invoice->authcode ( $iid );
  2155. if (! is_numeric ( $iid ))
  2156. die ( 'illegal request' );
  2157. if (! empty ( $iid ) && ! empty ( $invoiceNo )) {
  2158. Doo::loadModel ( 'invoiceOperationLog' );
  2159. $invoiceOperationLog = new invoiceOperationLog ();
  2160. Doo::loadModel ( 'invoiceStatistics' );
  2161. $invoiceStatistics = new invoiceStatistics ();
  2162. $XDeode = new XDeode ( 5 );
  2163. Doo::loadModel ( 'invoicePaper' );
  2164. $invoicePaper = new invoicePaper ();
  2165. $invoicePrintDetail = $invoice->getInvoiceByPrint ( $iid );
  2166. if (empty ( $invoicePrintDetail ))
  2167. die ( 'illegal request' );
  2168. //
  2169. $ipid = $XDeode->decode ( $invoiceNo );
  2170. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  2171. if (empty ( $paperDetail ))
  2172. die ( 'illegal request' );
  2173. $invoicePaper = new invoicePaper ();
  2174. $item = array (
  2175. 'iid' => $iid,
  2176. 'ipid' => $ipid
  2177. );
  2178. $invoicePaper->setInvoicePaperByCondition ( $item );
  2179. $item = array (
  2180. 'iid' => $iid,
  2181. 'printStatus' => 1,
  2182. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2183. 'printer' => $this->staff [0] ['username'],
  2184. 'printTime' => date ( "Y-m-d H:i:s" ),
  2185. 'invoiceNo' => $paperDetail ['invoiceNo']
  2186. );
  2187. $invoice->setInvoiceByCondition ( $item );
  2188. $item = array (
  2189. 'date' => date ( "Y-m-d H:i:s" ),
  2190. 'operation' => '打印发票号:' . $paperDetail ['invoiceNo'],
  2191. 'status' => 5,
  2192. 'img' => $this->staff [0] ['avatar'],
  2193. 'username' => $this->staff [0] ['username'],
  2194. 'uid' => $this->staff [0] ['sid'],
  2195. 'category' => $this->staff [0] ['category'],
  2196. 'iid' => $iid
  2197. );
  2198. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2199. // 去统计--负票不汇总
  2200. if ($invoicePrintDetail ['untreadStatus'] != 4) {
  2201. $item = array (
  2202. 'date' => date ( "Y-m-d H:i:s" ),
  2203. 'priceClass' => 1,
  2204. 'cid' => $invoicePrintDetail ['cid'],
  2205. 'staff' => $invoicePrintDetail ['sid'],
  2206. 'invoicePrice' => $invoicePrintDetail ['invoicePrice']
  2207. );
  2208. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2209. }
  2210. // 发送通知信息到微信-去除
  2211. // $this->setWXMsg($iid,'PRINT');
  2212. // 申请人获取微信通知
  2213. Doo::loadModel ( 'staff' );
  2214. $staff = new staff ();
  2215. Doo::loadClass ( 'XDeode' );
  2216. $XDeode = new XDeode ( 5 );
  2217. $username2 = $staff->getOne ( array (
  2218. 'select' => 'wxid',
  2219. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2220. 'asArray' => TRUE
  2221. ) );
  2222. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '完成打印';
  2223. $msg = '';
  2224. $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/' . $XDeode->encode ( $invoicePrintDetail ['iid'] ) . '.html';
  2225. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2226. if (empty ( $invoicePrintType ))
  2227. return "/invoicePrint";
  2228. else
  2229. return "/invoicePrintStayAchieve";
  2230. }
  2231. }
  2232. /**
  2233. * 需要邮寄的发票
  2234. * @since 1.0.0
  2235. */
  2236. function invoicePost() {
  2237. Doo::loadModel ( 'invoice' );
  2238. $invoice = new invoice ();
  2239. Doo::loadModel ( 'express' );
  2240. $express = new express ();
  2241. $invoicePost = $invoice->getPostByInvoice ();
  2242. $invoicePosted = $invoice->getPostByInvoice ( 1 );
  2243. $expressList = $express->getExpressByAll ();
  2244. $invoicePostExpress = "";
  2245. if (isset ( $_COOKIE ["invoicePostExpress"] ))
  2246. $invoicePostExpress = $_COOKIE ["invoicePostExpress"];
  2247. $this->data ['invoicePostExpress'] = $invoicePostExpress;
  2248. $this->data ['expressList'] = $expressList;
  2249. $this->data ['invoicePost'] = $invoicePost;
  2250. $this->data ['invoicePosted'] = $invoicePosted;
  2251. $this->data ['memu'] = "invoice";
  2252. $this->data ['staff'] = $this->staff;
  2253. $this->data ['receiptMemu'] = 'invoicePost';
  2254. $this->render ( "/admin/invoicePost", $this->data );
  2255. }
  2256. /**
  2257. * 添加发票邮寄信息
  2258. */
  2259. function invoiceExpressAddDo() {
  2260. Doo::loadModel ( 'invoice' );
  2261. $invoice = new invoice ();
  2262. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2263. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2264. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2265. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2266. $iid = $iid = $invoice->authcode ( $iid );
  2267. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2268. die ( 'illegal request' );
  2269. $invoicePrintDetail = $invoice->getInvoiceByIid ( $iid );
  2270. setcookie ( 'invoicePostExpress', $expressNumber );
  2271. $item = array (
  2272. 'iid' => $iid,
  2273. 'postStatus' => 1,
  2274. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2275. 'postTime' => date ( "Y-m-d H:i:s" ),
  2276. 'expressCompany' => $expressCompany,
  2277. 'expressNumber' => $expressNumber,
  2278. 'actualItems' => $actualItems,
  2279. 'poster' => $this->staff [0] ['username']
  2280. );
  2281. $invoice->setInvoiceByCondition ( $item );
  2282. // 微信通知-去掉
  2283. // $this->setWXMsg ( $iid );
  2284. Doo::loadModel ( 'staff' );
  2285. $staff = new staff ();
  2286. Doo::loadClass ( 'XDeode' );
  2287. $XDeode = new XDeode ( 5 );
  2288. $username2 = $staff->getOne ( array (
  2289. 'select' => 'wxid',
  2290. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2291. 'asArray' => TRUE
  2292. ) );
  2293. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '已邮寄';
  2294. $expCom = explode ( ":", $invoicePrintDetail ['expressCompany'] );
  2295. if (empty ( $expCom ))
  2296. $expCom [0] = '';
  2297. $msg = $expCom [0] . ':' . $invoicePrintDetail ['expressNumber'] . '';
  2298. $url = 'https://m.kuaidi100.com/result.jsp?nu=' . $invoicePrintDetail ['expressNumber'];
  2299. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2300. return '/invoicePost';
  2301. }
  2302. function invoiceExpressUpdateDo() {
  2303. Doo::loadModel ( 'invoice' );
  2304. $invoice = new invoice ();
  2305. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  2306. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2307. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2308. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2309. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2310. $iid = $invoice->authcode ( $iid );
  2311. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2312. die ( 'illegal request' );
  2313. $item = array (
  2314. 'iid' => $iid,
  2315. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2316. 'expressCompany' => $expressCompany,
  2317. 'expressNumber' => $expressNumber,
  2318. 'actualItems' => $actualItems,
  2319. 'poster' => $this->staff [0] ['username']
  2320. );
  2321. $invoice->setInvoiceByCondition ( $item );
  2322. return $action;
  2323. }
  2324. /**
  2325. * 可退票管理
  2326. */
  2327. function invoiceUntreadIsAchieve() {
  2328. Doo::loadModel ( 'invoice' );
  2329. $invoice = new invoice ();
  2330. Doo::loadClass ( 'XDeode' );
  2331. $XDeode = new XDeode ( 5 );
  2332. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2333. $page_size = 18;
  2334. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2335. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2336. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  2337. $dateArr = explode ( ':', $date );
  2338. $D1 = '';
  2339. $D2 = '';
  2340. if (! empty ( $date )) {
  2341. $D1 = $dateArr [0];
  2342. $D2 = $dateArr [1];
  2343. }
  2344. $con = '';
  2345. if (! empty ( $D1 ) && ! empty ( $D2 ))
  2346. $con = ' and bindTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2347. // if ($date == 'MONTHO')
  2348. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  2349. // elseif ($date == 'MONTHT')
  2350. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  2351. // elseif ($date == 'MONTHY')
  2352. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  2353. if (! empty ( $MebSea )) {
  2354. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  2355. }
  2356. $pageinfo ['page'] = array (
  2357. 'previous' => ''
  2358. );
  2359. // printStatus=1 and
  2360. $sql = " (untreadStatus=0 or untreadStatus=3) and status=2 and sid=" . $this->staff [0] ['sid'] . $con;
  2361. $action = "invoiceUntreadIsAchieve";
  2362. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2363. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2364. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2365. // print_r($list);
  2366. $this->data ['MebSeaEn'] = $MebSea;
  2367. // $this->data ['MebSea'] = urlencode ( $MebSea );
  2368. $this->data ['get'] = $get;
  2369. $this->data ['page'] = $pageinfo;
  2370. $this->data ['date'] = $date;
  2371. $this->data ['list'] = $list;
  2372. $this->data ['memu'] = "invoice";
  2373. $this->data ['staff'] = $this->staff;
  2374. $this->data ['receiptMemu'] = 'invoice';
  2375. $this->render ( "/admin/invoiceUntreadIsAchieve", $this->data );
  2376. }
  2377. /**
  2378. * 退票处理页面
  2379. */
  2380. function invoiceUntread() {
  2381. Doo::loadModel ( 'invoice' );
  2382. $invoice = new invoice ();
  2383. $untreadInvoice = $invoice->getInvoiceByUntreadStatus ( 1 );
  2384. $establishedInvoice = $invoice->getInvoiceByUntreadStatus ( 2 );
  2385. foreach ( $establishedInvoice as $key => $value ) {
  2386. // months
  2387. $lossDate = strtotime ( "+1 month", strtotime ( $value ['OperationLog'] ['date'] ) );
  2388. $nowDate = strtotime ( 'now' );
  2389. $establishedInvoice [$key] ['lossShow'] = false;
  2390. if ($lossDate < $nowDate)
  2391. $establishedInvoice [$key] ['lossShow'] = true;
  2392. }
  2393. $this->data ['untreadInvoice'] = $untreadInvoice;
  2394. $this->data ['establishedInvoice'] = $establishedInvoice;
  2395. $this->data ['memu'] = "invoice";
  2396. $this->data ['staff'] = $this->staff;
  2397. $this->data ['receiptMemu'] = 'invoiceUntread';
  2398. $this->render ( "/admin/invoiceUntread", $this->data );
  2399. }
  2400. /**
  2401. * 确认收到退回的发票,开票状态为退回 //收款状态解绑,公司统计扣除入账额度
  2402. */
  2403. function invoiceUntreadEstablishedDo() {
  2404. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  2405. Doo::loadModel ( 'invoice' );
  2406. $invoice = new invoice ();
  2407. Doo::loadModel ( 'invoiceOperationLog' );
  2408. $invoiceOperationLog = new invoiceOperationLog ();
  2409. Doo::loadModel ( 'invoiceReceivables' );
  2410. Doo::loadModel ( 'invoiceStatistics' );
  2411. $iid = $invoice->authcode ( $untreadIidKey );
  2412. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2413. die ( 'illegal request' );
  2414. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  2415. if ($invoiceDetails ['untreadStatus'] != 1)
  2416. die ( 'illegal request' );
  2417. $item = array (
  2418. 'iid' => $iid,
  2419. // 'irid'=>'',
  2420. 'untreadStatus' => 2,
  2421. 'updateTime' => date ( "Y-m-d H:i:s" )
  2422. );
  2423. $invoice->setInvoiceByCondition ( $item );
  2424. $item = array (
  2425. 'date' => date ( "Y-m-d H:i:s" ),
  2426. 'operation' => '已确认退票',
  2427. 'status' => 6,
  2428. 'img' => $this->staff [0] ['avatar'],
  2429. 'username' => $this->staff [0] ['username'],
  2430. 'uid' => $this->staff [0] ['sid'],
  2431. 'category' => $this->staff [0] ['category'],
  2432. 'iid' => $iid
  2433. );
  2434. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2435. // 收款解绑以及入账扣除 收款扣除
  2436. if (! empty ( $invoiceDetails ['irid'] )) {
  2437. $iridList = explode ( ',', $invoiceDetails ['irid'] );
  2438. foreach ( $iridList as $value ) {
  2439. $invoiceReceivables = new invoiceReceivables ();
  2440. $irDetails = $invoiceReceivables->getOne ( array (
  2441. 'where' => " irid=" . $value . ' and bindStatus=1',
  2442. 'asArray' => TRUE
  2443. ) );
  2444. $item = array (
  2445. 'irid' => $value,
  2446. 'bindStatus' => 0,
  2447. 'untreadStatus' => 1,
  2448. 'untreadStaff' => $invoiceDetails ['userName'],
  2449. 'unbundlingTime' => date ( "Y-m-d H:i:s" ),
  2450. 'iid' => 0
  2451. );
  2452. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2453. if (! empty ( $irDetails )) {
  2454. // 扣除入账
  2455. $invoiceStatistics = new invoiceStatistics ();
  2456. $item = array (
  2457. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2458. 'priceClass' => 3,
  2459. 'cid' => $invoiceDetails ['cid'],
  2460. 'staff' => $invoiceDetails ['sid'],
  2461. 'accountPrice' => - $irDetails ['receivablesPrice']
  2462. );
  2463. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2464. // 扣除收款
  2465. $invoiceStatistics = new invoiceStatistics ();
  2466. $item = array (
  2467. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2468. 'priceClass' => 2,
  2469. 'cid' => $invoiceDetails ['cid'],
  2470. 'staff' => $invoiceDetails ['sid'],
  2471. 'irid' => $irDetails ['irid'],
  2472. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  2473. );
  2474. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2475. }
  2476. // 解绑时删除收入流水
  2477. Doo::loadModel ( 'wasteBook' );
  2478. $wasteBook = new wasteBook ();
  2479. $wasteBook->delete ( array (
  2480. 'where' => 'dataID=' . $value . ' and accountType=7',
  2481. 'limit' => 1
  2482. ) );
  2483. }
  2484. }
  2485. return "/invoiceUntread";
  2486. }
  2487. /**
  2488. * 建立负票,关联原来发票
  2489. */
  2490. function invoiceLossDo() {
  2491. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2492. if (! empty ( $iidKey )) {
  2493. Doo::loadClass ( 'XDeode' );
  2494. $XDeode = new XDeode ( 5 );
  2495. Doo::loadModel ( 'invoice' );
  2496. $invoice = new invoice ();
  2497. Doo::loadModel ( 'invoiceOperationLog' );
  2498. $invoiceOperationLog = new invoiceOperationLog ();
  2499. $iidKey = $XDeode->decode ( $iidKey );
  2500. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  2501. // 拷贝插入一条发票数据
  2502. $iid = $invoice->setInvoiceLoss ( $iidKey );
  2503. // 更新负票
  2504. $invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  2505. $invoice = new invoice ();
  2506. $item = array (
  2507. 'iid' => $iid,
  2508. 'sid' => $this->staff [0] ['sid'],
  2509. 'userName' => $this->staff [0] ['username'],
  2510. 'cid' => $this->staff [0] ['cid'],
  2511. 'categoryName' => $this->staff [0] ['category'],
  2512. 'invoiceQuantity' => - $invoiceDetail ['invoiceQuantity'],
  2513. 'invoicePrice' => - $invoiceDetail ['invoicePrice'],
  2514. 'invoiceSerial' => $invoiceSerial,
  2515. 'invoiceNo' => '',
  2516. 'printStatus' => 0,
  2517. 'untreadStatus' => 4,
  2518. // 关联发票号
  2519. 'lossIid' => $invoiceDetail ['iid']
  2520. );
  2521. $invoice->setInvoiceByCondition ( $item );
  2522. // 更新原发票
  2523. $invoice = new invoice ();
  2524. $item = array (
  2525. 'iid' => $invoiceDetail ['iid'],
  2526. 'lossIid' => $iid
  2527. );
  2528. $invoice->setInvoiceByCondition ( $item );
  2529. // 操作日志
  2530. $item = array (
  2531. 'date' => date ( "Y-m-d H:i:s" ),
  2532. 'operation' => "创建负票" . $invoiceSerial,
  2533. 'status' => 12,
  2534. 'img' => $this->staff [0] ['avatar'],
  2535. 'username' => $this->staff [0] ['username'],
  2536. 'uid' => $this->staff [0] ['sid'],
  2537. 'category' => $this->staff [0] ['category'],
  2538. 'iid' => $iid
  2539. );
  2540. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2541. // print_r($invoiceDetail);
  2542. // echo $iid;die;
  2543. }
  2544. return '/invoiceUntread';
  2545. }
  2546. /**
  2547. * 上传银行到账 收款文件
  2548. */
  2549. function invoiceReceivablesBankUpload() {
  2550. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  2551. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  2552. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  2553. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  2554. header ( "HTTP/1.1 500 Internal Server Error" );
  2555. echo "POST exceeded maximum allowed size.";
  2556. exit ( 0 );
  2557. }
  2558. // Settings
  2559. $save_path = DOO::conf ()->SITE_PATH . "upload/invoiceReceivablesBank/"; // The path were we will save the file (getcwd() may not be reliable and should be tested in your environment)
  2560. $upload_name = "Filedata";
  2561. $file_name = "";
  2562. $nk = time ();
  2563. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  2564. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  2565. echo "文件无法保存.";
  2566. exit ( 0 );
  2567. }
  2568. echo json_encode ( array (
  2569. 'filename' => $file_name,
  2570. 'id' => $nk
  2571. ) );
  2572. exit ( 0 );
  2573. }
  2574. /**
  2575. * 解析银行到账收款execl并导入库中
  2576. */
  2577. function invoiceReceivablesImport() {
  2578. $path = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  2579. if ($path != "") {
  2580. Doo::loadModel ( 'invoiceReceivables' );
  2581. $invoiceReceivables = new invoiceReceivables ();
  2582. Doo::loadClass ( 'invoice.func' );
  2583. Doo::loadModel ( 'invoiceROLog' );
  2584. $invoiceROLog = new invoiceROLog ();
  2585. Doo::loadModel ( 'invoiceStatistics' );
  2586. $invoiceStatistics = new invoiceStatistics ();
  2587. $exlArray = formatExcelToArrayBank ( DOO::conf ()->SITE_PATH . "upload/invoiceReceivablesBank/" . $path );
  2588. $bankBatchNumber = 'BBN_' . time ();
  2589. Doo::db ()->beginTransaction ();
  2590. // 批量存储收款--由于必须获得收款ID,
  2591. $sql = 'INSERT INTO CLD_invoiceReceivables (OriginalPrice,receivablesPrice, receivablesMessage,receivablesSerial,receivablesBank,receivablesDate,inputStaff,date,receivablesCategory,receivablesStaff,bankBatchNumber,recepitTitleMark)
  2592. VALUES ';
  2593. $date = date ( "Y-m-d" );
  2594. $receivablesList = array ();
  2595. foreach ( $exlArray as $key => $value ) {
  2596. $receivablesSql = '(' . $value ["receivablesPrice"] . ',' . $value ["receivablesPrice"] . ',"' . $value ["receivablesMessage"] . '",' . '"#SK' . date ( "Ymd" ) . mt_rand ( 1000, 9999 ) . '","' . $value ["receivablesBank"] . '","' . $value ["receivablesDate"] . '","' . $this->staff [0] ['username'] . '","' . $date . '","PUBLIC","PUBLIC","' . $bankBatchNumber . '","' . $value ["receivablesMessage"] . '")';
  2597. array_push ( $receivablesList, $receivablesSql );
  2598. }
  2599. $sql = $sql . implode ( ',', $receivablesList );
  2600. // echo $sql;
  2601. Doo::db ()->query ( $sql );
  2602. // 批量存储收款统计
  2603. // 获得刚刚导入数据的irid组-缺少办事处和人员
  2604. $iridList = $invoiceReceivables->getInvoiceReceivablesByBBN ( $bankBatchNumber );
  2605. // 没有irid 回滚所有操作
  2606. if (empty ( $iridList )) {
  2607. Doo::db ()->rollBack ();
  2608. header ( 'Content-Type:text/html;charset=utf-8' );
  2609. die ( '文档或数据不正确,请重新<a href="/invoiceReceivables">上传</a>.' );
  2610. }
  2611. $sql = 'INSERT INTO CLD_invoiceStatistics (date, priceClass,irid,receivablesPrice)
  2612. VALUES ';
  2613. $statisticsList = array ();
  2614. foreach ( $iridList as $value ) {
  2615. $statisticsSql = '("' . $date . '",2,' . $value ['irid'] . ',' . $value ["receivablesPrice"] . ')';
  2616. array_push ( $statisticsList, $statisticsSql );
  2617. }
  2618. $sql = $sql . implode ( ',', $statisticsList );
  2619. Doo::db ()->query ( $sql );
  2620. // 批量存储操作日志
  2621. $sql = 'INSERT INTO CLD_invoiceROLog (operation, date,status,img, username,uid,category,irid)
  2622. VALUES ';
  2623. $ROLogList = array ();
  2624. foreach ( $iridList as $value ) {
  2625. $ROLogSql = '("' . $this->staff [0] ['username'] . ' 转入 公共待认领款项","' . $date . '",1,"' . $this->staff [0] ['avatar'] . '","' . $this->staff [0] ['username'] . '","' . $this->staff [0] ['sid'] . '","' . $this->staff [0] ['category'] . '","' . $value ['irid'] . '")';
  2626. array_push ( $ROLogList, $ROLogSql );
  2627. }
  2628. $sql = $sql . implode ( ',', $ROLogList );
  2629. Doo::db ()->query ( $sql );
  2630. // 批量写入流水
  2631. $sql = 'INSERT INTO CLD_wasteBook (dataID, expensesType,accountType,accountPriceShow, accountPrice,accountBank,category,cid,name,sid,inputDate)
  2632. VALUES ';
  2633. $wasteBookList = array ();
  2634. foreach ( $iridList as $value ) {
  2635. $accountBank = '';
  2636. if ($value ['receivablesBank'] == '纵横广发') {
  2637. $accountBank = 'CGBDeposit';
  2638. } elseif ($value ['receivablesBank'] == '纵横工行') {
  2639. $accountBank = 'ICBCDeposit';
  2640. } elseif ($value ['receivablesBank'] == '华润银行') {
  2641. $accountBank = 'HUADeposit';
  2642. } elseif ($value ['receivablesBank'] == '个人广发') {
  2643. $accountBank = 'PersonalDeposit';
  2644. }
  2645. $wasteBookSql = '("' . $value ['irid'] . ' ",1,7,"' . $value ['receivablesPrice'] . '","' . $value ['receivablesPrice'] . '","' . $accountBank . '",
  2646. "' . $this->staff [0] ['category'] . '","' . $this->staff [0] ['cid'] . '","' . $this->staff [0] ['username'] . '","' . $this->staff [0] ['sid'] . '","' . date ( "Y-m-d H:i:s" ) . '")';
  2647. array_push ( $wasteBookList, $wasteBookSql );
  2648. }
  2649. $sql = $sql . implode ( ',', $wasteBookList );
  2650. Doo::db ()->query ( $sql );
  2651. Doo::db ()->commit ();
  2652. return "/invoiceReceivables";
  2653. }
  2654. echo 'no file';
  2655. }
  2656. function invoiceReceivables() {
  2657. $invoiceTC = $this->get_args ( 'invoiceTC' ) ? $this->get_args ( 'invoiceTC' ) : '';
  2658. Doo::loadModel ( 'L_category' );
  2659. $lCategory = new L_category ();
  2660. Doo::loadModel ( 'staff' );
  2661. $staff = new staff ();
  2662. Doo::loadModel ( 'invoiceReceivables' );
  2663. $invoiceReceivables = new invoiceReceivables ();
  2664. Doo::loadModel ( 'invoice' );
  2665. $invoice = new invoice ();
  2666. Doo::loadClass ( 'XDeode' );
  2667. $XDeode = new XDeode ( 5 );
  2668. $category = $lCategory->getCategory ();
  2669. $staffList = $staff->getStaffByCid ( $this->staff [0] ['cid'] );
  2670. $sql = 'bindStatus=1 and iid!=0';
  2671. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByNew ( 4, $sql );
  2672. // 获取未入账发票
  2673. $invoiceUnAccount = $invoice->getInvoiceByUnAccount ( $invoiceTC );
  2674. $invoiceExistAccount = $invoice->getInvoiceByUnAccount ( '', true );
  2675. foreach ( $invoiceUnAccount as $key => $value ) {
  2676. $invoiceUnAccount [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2677. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2678. if (! empty ( $lastApprover )) {
  2679. $lastApproverKey = array_keys ( $lastApprover );
  2680. $lastApprover = end ( $lastApprover );
  2681. $staffDetail = $staff->getOne ( array (
  2682. 'where' => 'sid=' . end ( $lastApproverKey ),
  2683. 'asArray' => true
  2684. ) );
  2685. $lastApprover ['username'] = $staffDetail ['username'];
  2686. }
  2687. $invoiceUnAccount [$key] ['lastApprover'] = $lastApprover;
  2688. }
  2689. foreach ( $invoiceExistAccount as $key => $value ) {
  2690. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  2691. if (empty ( $irList ))
  2692. $irList [0] ['sumPrice'] = 0;
  2693. $balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  2694. $invoiceExistAccount [$key] ['existAccount'] = $irList [0] ['sumPrice'];
  2695. $invoiceExistAccount [$key] ['balance'] = $balance;
  2696. }
  2697. $receivablesInput = $invoiceReceivables->getInvoiceReceivablesByInput ();
  2698. $halfList = $invoiceReceivables->getInvoiceReceivablesByHalf ();
  2699. $this->data ['halfList'] = $halfList;
  2700. $this->data ['halfCount'] = count ( $halfList );
  2701. // print_r($receivablesList);
  2702. $this->data ['receivablesDate'] = date ( "Y-m-d" );
  2703. $this->data ['ieaCount'] = count ( $invoiceExistAccount );
  2704. $this->data ['invoiceExistAccount'] = $invoiceExistAccount;
  2705. $this->data ['receivablesInput'] = $receivablesInput;
  2706. $this->data ['year'] = date ( 'Y' );
  2707. $this->data ['invoiceUnAccount'] = $invoiceUnAccount;
  2708. $this->data ['receivablesList'] = $receivablesList;
  2709. $this->data ['staffList'] = $staffList;
  2710. $this->data ['category'] = $category;
  2711. $this->data ['memu'] = "invoice";
  2712. $this->data ['staff'] = $this->staff;
  2713. $this->data ['receiptMemu'] = 'invoiceReceivables';
  2714. $this->render ( "/admin/invoiceReceivables", $this->data );
  2715. }
  2716. /**
  2717. * 设置收款认领地区
  2718. */
  2719. function setInvoiceReceivablesClaim() {
  2720. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  2721. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  2722. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  2723. if (! empty ( $iridKey ) && ! empty ( $receivablesCategory )) {
  2724. Doo::loadModel ( 'invoiceReceivables' );
  2725. $invoiceReceivables = new invoiceReceivables ();
  2726. Doo::loadClass ( 'XDeode' );
  2727. $XDeode = new XDeode ( 5 );
  2728. Doo::loadModel ( 'invoiceROLog' );
  2729. $invoiceROLog = new invoiceROLog ();
  2730. $irid = $XDeode->decode ( $iridKey );
  2731. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  2732. if (empty ( $irDetail ))
  2733. die ( 'illegal request' );
  2734. $item = array (
  2735. 'irid' => $irid,
  2736. 'receivablesCategory' => $receivablesCategory
  2737. );
  2738. if ($receivablesCategory != 'PUBLIC') {
  2739. $item += array (
  2740. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  2741. 'inputType' => 1
  2742. );
  2743. }
  2744. $invoiceReceivables = new invoiceReceivables ();
  2745. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2746. // 收款操作日志
  2747. $item = array (
  2748. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 ",
  2749. 'date' => date ( "Y-m-d" ),
  2750. 'status' => 1,
  2751. 'img' => $this->staff [0] ['avatar'],
  2752. 'username' => $this->staff [0] ['username'],
  2753. 'uid' => $this->staff [0] ['sid'],
  2754. 'category' => $this->staff [0] ['category'],
  2755. 'irid' => $irid
  2756. );
  2757. $invoiceROLog->setInvoiceROLog ( $item );
  2758. if (empty ( $action ))
  2759. return '/invoiceReceivables';
  2760. else
  2761. return "/invoiceReceivablesAS";
  2762. }
  2763. die ( 'illegal request' );
  2764. }
  2765. /**
  2766. * 新添加收款直接入账发票
  2767. */
  2768. function invoiceCompareClaimPrice() {
  2769. // 收款录入
  2770. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2771. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  2772. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  2773. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  2774. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  2775. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $iidKey )) {
  2776. Doo::loadModel ( 'invoiceReceivables' );
  2777. $invoiceReceivables = new invoiceReceivables ();
  2778. Doo::loadModel ( 'invoiceROLog' );
  2779. $invoiceROLog = new invoiceROLog ();
  2780. Doo::loadModel ( 'invoiceStatistics' );
  2781. Doo::loadModel ( 'invoice' );
  2782. $invoice = new invoice ();
  2783. Doo::loadClass ( 'XDeode' );
  2784. $XDeode = new XDeode ( 5 );
  2785. Doo::loadModel ( 'invoiceOperationLog' );
  2786. $invoiceOperationLog = new invoiceOperationLog ();
  2787. $iidKey = $XDeode->decode ( $iidKey );
  2788. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  2789. if (! ($invoiceDetail ['status'] == 2 && $invoiceDetail ['printStatus'] == 1 && $invoiceDetail ['untreadStatus'] == 0))
  2790. die ( 'illegal request' );
  2791. $receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  2792. // 收款录入 并绑定发票
  2793. Doo::db ()->beginTransaction ();
  2794. $bindStatus = 0;
  2795. if ($receivablesPrice <= $invoiceDetail ['invoicePrice'])
  2796. $bindStatus = 1;
  2797. $titleMark = $invoiceDetail ['invoiceTitle'];
  2798. if (! empty ( $invoiceDetail ['invoiceCompany'] ))
  2799. $titleMark = $invoiceDetail ['invoiceCompany'];
  2800. $item = array (
  2801. 'recepitTitleMark' => $titleMark,
  2802. 'bindStatus' => $bindStatus,
  2803. 'iid' => $invoiceDetail ['iid'],
  2804. 'bindPrice' => $invoiceDetail ['invoicePrice'],
  2805. 'bindDate' => date ( "Y-m-d H:i:s" ),
  2806. 'receivablesPrice' => $receivablesPrice,
  2807. 'OriginalPrice' => $receivablesPrice,
  2808. 'receivablesMessage' => $receivablesMessage,
  2809. 'receivablesSerial' => $receivablesSerial,
  2810. 'receivablesBank' => $receivablesBank,
  2811. 'receivablesDate' => $receivablesDate,
  2812. 'inputStaff' => $this->staff [0] ['username'],
  2813. 'accountClerk' => $this->staff [0] ['username'],
  2814. 'date' => date ( "Y-m-d" ),
  2815. 'receivablesCategory' => $invoiceDetail ['cid'] . ':' . $invoiceDetail ['categoryName'],
  2816. 'receivablesStaff' => $invoiceDetail ['sid'] . '-' . $invoiceDetail ['userName'],
  2817. 'confirmTime' => date ( "Y-m-d H:i:s" )
  2818. );
  2819. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  2820. $item = array ();
  2821. // 收款操作日志
  2822. $item = array (
  2823. 'operation' => $this->staff [0] ['username'] . " 转入 " . $invoiceDetail ['userName']
  2824. );
  2825. $item += array (
  2826. 'date' => date ( "Y-m-d" ),
  2827. 'status' => 1,
  2828. 'img' => $this->staff [0] ['avatar'],
  2829. 'username' => $this->staff [0] ['username'],
  2830. 'uid' => $this->staff [0] ['sid'],
  2831. 'category' => $this->staff [0] ['category'],
  2832. 'irid' => $irid
  2833. );
  2834. $invoiceROLog->setInvoiceROLog ( $item );
  2835. // 收款统计
  2836. $invoiceStatistics = new invoiceStatistics ();
  2837. $item = array (
  2838. 'date' => $receivablesDate,
  2839. 'priceClass' => 2,
  2840. 'irid' => $irid,
  2841. 'cid' => $invoiceDetail ['cid'],
  2842. 'staff' => $invoiceDetail ['sid'],
  2843. 'receivablesPrice' => $receivablesPrice
  2844. );
  2845. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2846. // 收款 入 发票
  2847. $detail = $invoiceDetail;
  2848. $iridString = "";
  2849. if (empty ( $detail ['irid'] ))
  2850. $iridString = $irid;
  2851. else
  2852. $iridString = $detail ['irid'] . ',' . $irid;
  2853. $item = array (
  2854. 'irid' => $iridString,
  2855. 'bindTime' => date ( "Y-m-d H:i:s" ),
  2856. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2857. 'iid' => $detail ['iid']
  2858. );
  2859. $invoiceReceivables = new invoiceReceivables ();
  2860. $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  2861. if ($detail ['invoicePrice'] <= $sum)
  2862. $item += array (
  2863. 'untreadStatus' => 3
  2864. );
  2865. $invoice->setInvoiceByCondition ( $item );
  2866. // 操作日志
  2867. $item = array (
  2868. 'date' => date ( "Y-m-d H:i:s" ),
  2869. 'operation' => "收款入账" . $receivablesSerial . "到发票" . $detail ['invoiceSerial'],
  2870. 'status' => 8,
  2871. 'img' => $this->staff [0] ['avatar'],
  2872. 'username' => $this->staff [0] ['username'],
  2873. 'uid' => $this->staff [0] ['sid'],
  2874. 'category' => $this->staff [0] ['category'],
  2875. 'iid' => $detail ['iid']
  2876. );
  2877. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2878. // 入账汇总
  2879. $invoiceStatistics = new invoiceStatistics ();
  2880. // $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $iridString );
  2881. // $accountPrice = 0;
  2882. // foreach ( $list as $key => $value ) {
  2883. // $accountPrice += $value ['receivablesPrice'];
  2884. // }
  2885. $item = array (
  2886. 'date' => $receivablesDate,
  2887. 'priceClass' => 3,
  2888. 'cid' => $invoiceDetail ['cid'],
  2889. 'staff' => $invoiceDetail ['sid'],
  2890. 'accountPrice' => $receivablesPrice
  2891. );
  2892. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2893. // 公司流水记录
  2894. Doo::loadModel ( 'wasteBook' );
  2895. $wasteBook = new wasteBook ();
  2896. $abDetail = $wasteBook->getAccountBookByAid ( 2, 7, $irid );
  2897. $accountBank = '';
  2898. if ($receivablesBank == '纵横广发') {
  2899. $accountBank = 'CGBDeposit';
  2900. } elseif ($receivablesBank == '纵横工行') {
  2901. $accountBank = 'ICBCDeposit';
  2902. } elseif ($receivablesBank == '华润银行') {
  2903. $accountBank = 'HUADeposit';
  2904. } elseif ($receivablesBank == '个人广发') {
  2905. $accountBank = 'PersonalDeposit';
  2906. }
  2907. if (empty ( $abDetail )) {
  2908. $item = array (
  2909. 'dataID' => $irid,
  2910. 'expensesType' => 1,
  2911. 'accountType' => 7,
  2912. 'accountPrice' => $receivablesPrice,
  2913. 'accountPriceShow' => $receivablesPrice,
  2914. 'accountBank' => $accountBank,
  2915. 'category' => $this->staff [0] ['category'],
  2916. 'cid' => $this->staff [0] ['cid'],
  2917. 'name' => $this->staff [0] ['username'],
  2918. 'sid' => $this->staff [0] ['sid'],
  2919. 'inputDate' => date ( "Y-m-d H:i:s" )
  2920. );
  2921. $wasteBook->setAccountBookStatistics ( $item );
  2922. }
  2923. Doo::db ()->commit ();
  2924. }
  2925. return '/invoiceReceivables';
  2926. }
  2927. /**
  2928. * 录入收款数据
  2929. * @return string
  2930. */
  2931. function invoiceReceivablesDo() {
  2932. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  2933. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  2934. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  2935. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  2936. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  2937. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  2938. Doo::loadModel ( 'invoiceReceivables' );
  2939. $invoiceReceivables = new invoiceReceivables ();
  2940. Doo::loadModel ( 'invoiceROLog' );
  2941. $invoiceROLog = new invoiceROLog ();
  2942. Doo::loadModel ( 'invoiceStatistics' );
  2943. $invoiceStatistics = new invoiceStatistics ();
  2944. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $receivablesCategory ) && ! empty ( $receivablesStaff )) {
  2945. $item = array (
  2946. 'receivablesPrice' => $receivablesPrice,
  2947. 'OriginalPrice' => $receivablesPrice,
  2948. 'receivablesMessage' => $receivablesMessage,
  2949. 'receivablesSerial' => "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  2950. 'receivablesBank' => $receivablesBank,
  2951. 'receivablesDate' => $receivablesDate,
  2952. 'inputStaff' => $this->staff [0] ['username'],
  2953. 'date' => date ( "Y-m-d" ),
  2954. 'receivablesCategory' => $receivablesCategory,
  2955. 'receivablesStaff' => $receivablesStaff
  2956. );
  2957. if ($receivablesCategory != 'PUBLIC') {
  2958. $item += array (
  2959. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  2960. 'inputType' => 1
  2961. );
  2962. }
  2963. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  2964. $item = array ();
  2965. // 收款操作日志
  2966. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  2967. $item = array (
  2968. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  2969. );
  2970. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  2971. $item = array (
  2972. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  2973. );
  2974. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  2975. $receivablesStaff = explode ( '-', $receivablesStaff );
  2976. $item = array (
  2977. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  2978. );
  2979. }
  2980. $item += array (
  2981. 'date' => date ( "Y-m-d" ),
  2982. 'status' => 1,
  2983. 'img' => $this->staff [0] ['avatar'],
  2984. 'username' => $this->staff [0] ['username'],
  2985. 'uid' => $this->staff [0] ['sid'],
  2986. 'category' => $this->staff [0] ['category'],
  2987. 'irid' => $irid
  2988. );
  2989. $invoiceROLog->setInvoiceROLog ( $item );
  2990. $item = array (
  2991. 'date' => $receivablesDate,
  2992. 'priceClass' => 2,
  2993. 'irid' => $irid,
  2994. 'receivablesPrice' => $receivablesPrice
  2995. );
  2996. if ($receivablesCategory != 'PUBLIC') {
  2997. $receivablesCategory = explode ( ":", $receivablesCategory );
  2998. $item += array (
  2999. 'cid' => $receivablesCategory [0]
  3000. );
  3001. }
  3002. if ($receivablesStaff2 != 'PUBLIC') {
  3003. $receivablesStaff = explode ( "-", $receivablesStaff2 );
  3004. $item += array (
  3005. 'staff' => $receivablesStaff [0]
  3006. );
  3007. }
  3008. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3009. $toparty = $this->getWxidByCategory ( $receivablesCategory [1] );
  3010. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  3011. $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  3012. if ($toparty != 0)
  3013. $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  3014. // 公司流水记录
  3015. Doo::loadModel ( 'wasteBook' );
  3016. $wasteBook = new wasteBook ();
  3017. $abDetail = $wasteBook->getAccountBookByAid ( 1, 7, $irid );
  3018. $accountBank = '';
  3019. if ($receivablesBank == '纵横广发') {
  3020. $accountBank = 'CGBDeposit';
  3021. } elseif ($receivablesBank == '纵横工行') {
  3022. $accountBank = 'ICBCDeposit';
  3023. } elseif ($receivablesBank == '华润银行') {
  3024. $accountBank = 'HUADeposit';
  3025. } elseif ($receivablesBank == '个人广发') {
  3026. $accountBank = 'PersonalDeposit';
  3027. }
  3028. $item = array (
  3029. 'dataID' => $irid,
  3030. 'expensesType' => 1,
  3031. 'accountType' => 7,
  3032. 'accountPriceShow' => $receivablesPrice,
  3033. 'accountPrice' => $receivablesPrice,
  3034. 'accountBank' => $accountBank,
  3035. 'category' => $this->staff [0] ['category'],
  3036. 'cid' => $this->staff [0] ['cid'],
  3037. 'name' => $this->staff [0] ['username'],
  3038. 'sid' => $this->staff [0] ['sid'],
  3039. 'inputDate' => date ( "Y-m-d H:i:s" )
  3040. );
  3041. $wasteBook->setAccountBookStatistics ( $item );
  3042. }
  3043. return "/invoiceReceivables";
  3044. }
  3045. /**
  3046. * 收款认领页面-包括公共认领 办事处认领 最近已认领数据
  3047. */
  3048. function invoiceReceivablesClaim() {
  3049. Doo::loadModel ( 'invoiceReceivables' );
  3050. $invoiceReceivables = new invoiceReceivables ();
  3051. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  3052. $this->data ['receivablesList'] = $receivablesList;
  3053. $this->data ['memu'] = "invoice";
  3054. $this->data ['staff'] = $this->staff;
  3055. $this->data ['receiptMemu'] = 'invoiceReceivablesClaim';
  3056. $this->render ( "/admin/invoiceReceivablesClaim", $this->data );
  3057. }
  3058. function invoiceReceivablesTitleMarkSet() {
  3059. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  3060. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  3061. if (empty ( $iridKey ) || empty ( $recepitTitleMark ))
  3062. die ( 'illegal request' );
  3063. Doo::loadModel ( 'invoiceReceivables' );
  3064. $invoiceReceivables = new invoiceReceivables ();
  3065. Doo::loadClass ( 'XDeode' );
  3066. $XDeode = new XDeode ( 5 );
  3067. $irid = $XDeode->decode ( $iridKey );
  3068. if (! is_numeric ( $irid ))
  3069. die ( 'illegal request' );
  3070. $invoiceReceivables->recepitTitleMark = $recepitTitleMark;
  3071. $invoiceReceivables->update ( array (
  3072. 'where' => 'irid = ' . $irid
  3073. ) );
  3074. return '/invoiceReceivablesClaim';
  3075. }
  3076. /**
  3077. * 更新收款相关数据
  3078. */
  3079. function invoiceReceivablesUpdateClaim() {
  3080. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3081. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3082. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3083. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3084. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3085. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  3086. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  3087. if (empty ( $claimKey ))
  3088. die ( 'illegal request' );
  3089. Doo::loadModel ( 'invoiceReceivables' );
  3090. $invoiceReceivables = new invoiceReceivables ();
  3091. Doo::loadModel ( 'invoiceROLog' );
  3092. $invoiceROLog = new invoiceROLog ();
  3093. $con = ' and iid=0 and bindStatus=0'; // and receivablesCategory!="PUBLIC" and receivablesStaff!="PUBLIC"
  3094. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  3095. if (empty ( $detail ))
  3096. die ( 'illegal request' );
  3097. $invoiceReceivables = new invoiceReceivables ();
  3098. $item = array (
  3099. 'irid' => $detail ['irid']
  3100. );
  3101. if ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3102. $item += array (
  3103. 'confirmTime' => date ( "Y-m-d H:i:s" )
  3104. );
  3105. }
  3106. if (! empty ( $receivablesCategory ))
  3107. $item += array (
  3108. 'receivablesCategory' => $receivablesCategory
  3109. );
  3110. if (! empty ( $receivablesStaff ))
  3111. $item += array (
  3112. 'receivablesStaff' => $receivablesStaff
  3113. );
  3114. if (! empty ( $receivablesPrice ))
  3115. $item += array (
  3116. 'receivablesPrice' => $receivablesPrice
  3117. );
  3118. if (! empty ( $receivablesMessage ))
  3119. $item += array (
  3120. 'receivablesMessage' => $receivablesMessage
  3121. );
  3122. if (! empty ( $receivablesBank ))
  3123. $item += array (
  3124. 'receivablesBank' => $receivablesBank
  3125. );
  3126. if (! empty ( $receivablesDate ))
  3127. $item += array (
  3128. 'receivablesDate' => $receivablesDate
  3129. );
  3130. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3131. // 收款操作日志
  3132. $item = array ();
  3133. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3134. $item = array (
  3135. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  3136. );
  3137. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3138. $item = array (
  3139. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  3140. );
  3141. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3142. $receivablesStaff = explode ( '-', $receivablesStaff );
  3143. $item = array (
  3144. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  3145. );
  3146. }
  3147. $item += array (
  3148. 'date' => date ( "Y-m-d" ),
  3149. 'status' => 1,
  3150. 'img' => $this->staff [0] ['avatar'],
  3151. 'username' => $this->staff [0] ['username'],
  3152. 'uid' => $this->staff [0] ['sid'],
  3153. 'category' => $this->staff [0] ['category'],
  3154. 'irid' => $detail ['irid']
  3155. );
  3156. $invoiceROLog->setInvoiceROLog ( $item );
  3157. return '/invoiceReceivablesAS';
  3158. }
  3159. function invoiceReceivablesDelete() {
  3160. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  3161. $skll = $this->get_args ( 'skll' ) ? $this->get_args ( 'skll' ) : "";
  3162. if ($skll != '删除到款')
  3163. die ( 'illegal request' );
  3164. if (empty ( $claimKey ))
  3165. die ( 'illegal request' );
  3166. Doo::loadModel ( 'invoiceReceivables' );
  3167. $invoiceReceivables = new invoiceReceivables ();
  3168. $con = ' and bindStatus=0 ';
  3169. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  3170. if (empty ( $detail ))
  3171. die ( 'illegal request' );
  3172. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  3173. // 扣除收款汇总信息 汇总
  3174. Doo::loadModel ( 'invoiceStatistics' );
  3175. $invoiceStatistics = new invoiceStatistics ();
  3176. $item = array (
  3177. 'date' => $detail ['receivablesDate'],
  3178. 'priceClass' => 2,
  3179. 'irid' => $detail ['irid'],
  3180. 'receivablesPrice' => - $detail ['receivablesPrice']
  3181. );
  3182. if ($detail ['receivablesCategory'] != 'PUBLIC') {
  3183. $receivablesCategory = explode ( ":", $detail ['receivablesCategory'] );
  3184. $item += array (
  3185. 'cid' => $receivablesCategory [0]
  3186. );
  3187. }
  3188. if ($detail ['receivablesStaff'] != 'PUBLIC') {
  3189. $receivablesStaff = explode ( "-", $detail ['receivablesStaff'] );
  3190. $item += array (
  3191. 'staff' => $receivablesStaff [0]
  3192. );
  3193. }
  3194. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3195. // 公司流水-删除时删除流水
  3196. Doo::loadModel ( 'wasteBook' );
  3197. $wasteBook = new wasteBook ();
  3198. $wasteBook->delete ( array (
  3199. 'where' => 'dataID=' . $detail ['irid'] . ' and accountType=7',
  3200. 'limit' => 1
  3201. ) );
  3202. return '/invoiceReceivablesAS';
  3203. }
  3204. /**
  3205. * 管理员录入的收款 ,确认认领到谁的名下.统计收款金额
  3206. */
  3207. function invoiceReceivablesAscription() {
  3208. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  3209. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  3210. Doo::loadModel ( 'invoiceReceivables' );
  3211. $invoiceReceivables = new invoiceReceivables ();
  3212. Doo::loadModel ( 'invoiceROLog' );
  3213. $invoiceROLog = new invoiceROLog ();
  3214. Doo::loadModel ( 'invoiceStatistics' );
  3215. $invoiceStatistics = new invoiceStatistics ();
  3216. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  3217. if (! empty ( $detail ) && $detail ['receivablesStaff'] == 'PUBLIC' && ! empty ( $recepitTitleMark )) {
  3218. $item = array (
  3219. 'irid' => $detail ['irid'],
  3220. 'receivablesCategory' => $this->staff [0] ['cid'] . ":" . $this->staff [0] ['category'],
  3221. 'receivablesStaff' => $this->staff [0] ['sid'] . "-" . $this->staff [0] ['username'],
  3222. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3223. 'recepitTitleMark' => $recepitTitleMark,
  3224. 'source' => 1
  3225. );
  3226. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3227. $item = array (
  3228. 'date' => date ( "Y-m-d" ),
  3229. 'operation' => $this->staff [0] ['username'] . " 认领 ",
  3230. 'status' => 2,
  3231. 'img' => $this->staff [0] ['avatar'],
  3232. 'username' => $this->staff [0] ['username'],
  3233. 'uid' => $this->staff [0] ['sid'],
  3234. 'category' => $this->staff [0] ['category'],
  3235. 'irid' => $irid
  3236. );
  3237. $invoiceROLog->setInvoiceROLog ( $item );
  3238. $item = array (
  3239. 'cid' => $this->staff [0] ['cid'],
  3240. 'staff' => $this->staff [0] ['sid']
  3241. );
  3242. $invoiceStatistics->updateInvoiceStatisticsByIrid ( $item, $detail ['irid'], 2 );
  3243. }
  3244. return "/invoiceReceivablesClaim";
  3245. }
  3246. /**
  3247. */
  3248. function invoiceMyReceivables() {
  3249. Doo::loadModel ( 'invoiceReceivables' );
  3250. $invoiceReceivables = new invoiceReceivables ();
  3251. Doo::loadModel ( 'invoiceStatistics' );
  3252. $invoiceStatistics = new invoiceStatistics ();
  3253. $isMonth = $invoiceStatistics->getStatisticsByMonth ( $this->staff [0] ['sid'] );
  3254. $year = date ( "Y" );
  3255. $tmp_date = date ( "Ym" );
  3256. $tmp_year = substr ( $tmp_date, 0, 4 );
  3257. $tmp_mon = substr ( $tmp_date, 4, 2 );
  3258. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  3259. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  3260. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . ".htm";
  3261. $htm = $this->showCache ( $path );
  3262. $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  3263. $this->data ['isMonth'] = $isMonth;
  3264. $this->data ['htm'] = $htm;
  3265. $this->data ['list'] = $list;
  3266. $this->data ['memu'] = "invoice";
  3267. $this->data ['staff'] = $this->staff;
  3268. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  3269. $this->render ( "/admin/invoiceMyReceivables", $this->data );
  3270. }
  3271. /**
  3272. * 纸票管理
  3273. */
  3274. function invoicePaper() {
  3275. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3276. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3277. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3278. $this->data ['dateString'] = $date;
  3279. $this->data ['status'] = $status;
  3280. $this->data ['invoiceType'] = $invoiceType;
  3281. $this->data ['memu'] = "invoice";
  3282. $this->data ['staff'] = $this->staff;
  3283. $this->data ['receiptMemu'] = 'invoicePaper';
  3284. $this->render ( "/admin/invoicePaper", $this->data );
  3285. }
  3286. /**
  3287. * 获得纸票分页数据
  3288. */
  3289. function ajaxGetinvoicePaperAchieve() {
  3290. Doo::loadModel ( 'invoicePaper' );
  3291. $invoicePaper = new invoicePaper ();
  3292. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3293. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3294. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ORDINARY";
  3295. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3296. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  3297. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  3298. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  3299. $MebSea = $this->get_args ( 'search' );
  3300. $MebSea = $MebSea ['value'];
  3301. $page_size = $length;
  3302. $con = '';
  3303. if ($status == 'ALL')
  3304. $con = ' where 1 ';
  3305. elseif ($status == 'PRINTED')
  3306. $con = ' where a.iid!=0 '; // $con = ' where b.isDelete=0 and a.iid!=0 and b.status=2 and b.untreadStatus=0 ';
  3307. elseif ($status == 'UNPRINT')
  3308. $con = ' where a.iid=0 '; // $con = ' where b.isDelete=0 and a.iid=0 and b.status=2 and b.untreadStatus=0 ';
  3309. elseif ($status == 'TICKET')
  3310. $con = ' where b.isDelete=0 and b.untreadStatus=2';
  3311. if ($invoiceType == 'ORDINARY')
  3312. $con .= ' and a.invoiceType=0 ';
  3313. elseif ($invoiceType == 'SPECIAL')
  3314. $con .= ' and a.invoiceType=1 ';
  3315. $dateArr = explode ( ':', $date );
  3316. $D1 = $dateString = '';
  3317. $D2 = '';
  3318. if (! empty ( $date )) {
  3319. $D1 = $dateArr [0];
  3320. if (isset ( $dateArr [1] ))
  3321. $D2 = $dateArr [1];
  3322. else
  3323. $D2 = '';
  3324. $dateString = $D1 . " : " . $D2;
  3325. }
  3326. if (! empty ( $D1 ) && ! empty ( $D2 ))
  3327. $con .= ' and b.printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  3328. elseif (! empty ( $D1 ) && empty ( $D2 ))
  3329. $con .= ' and b.printTime like "%' . $D1 . '%" ';
  3330. if (! empty ( $MebSea ))
  3331. $con .= ' and ( b.invoiceTitle like "%' . $MebSea . '%" or b.invoiceCompany like "%' . $MebSea . '%" or a.invoiceNo like "%' . $MebSea . '%" )';
  3332. $invoiceTotal = $invoicePaper->getInvoicePaperCount ();
  3333. $sql = ' ' . $con;
  3334. $limit = $page . ',' . $page_size;
  3335. $list = $invoicePaper->getInvoicePaper ( $limit, $sql, 'desc' );
  3336. $paperList = array ();
  3337. foreach ( $list as $key => $value ) {
  3338. $irDetail = array ();
  3339. if ($value ['iid'] == 0)
  3340. array_push ( $irDetail, '<a href="javascript:if(window.confirm(\'确认删除?\'))window.location=\'/invoicePaperDel/' . $value ['ipidKey'] . '\'" >删除</a>' );
  3341. else
  3342. array_push ( $irDetail, '' );
  3343. array_push ( $irDetail, $value ['invoiceCode'] );
  3344. array_push ( $irDetail, $value ['invoiceNo'] );
  3345. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKey'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  3346. if ($value ['invoiceType'] == 1)
  3347. array_push ( $irDetail, $value ['invoiceCompany'] );
  3348. else
  3349. array_push ( $irDetail, $value ['invoiceTitle'] );
  3350. if ($value ['invoiceType'] == 1)
  3351. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  3352. else
  3353. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  3354. array_push ( $irDetail, $value ['invoiceElement'] );
  3355. array_push ( $irDetail, $value ['categoryName'] . '-' . $value ['userName'] );
  3356. array_push ( $irDetail, $value ['printTime'] );
  3357. array_push ( $paperList, $irDetail );
  3358. }
  3359. // $approvalListJson = json_encode ( $approvalList );
  3360. $recordsFiltered = $invoiceTotal;
  3361. echo json_encode ( array (
  3362. "draw" => intval ( $draw ),
  3363. "recordsTotal" => intval ( $invoiceTotal ),
  3364. "recordsFiltered" => intval ( $recordsFiltered ),
  3365. "data" => $paperList
  3366. ), JSON_UNESCAPED_UNICODE );
  3367. }
  3368. function invoicePaperDel() {
  3369. $ipidKey = isset ( $this->params ['ipidKey'] ) ? $this->params ['ipidKey'] : "";
  3370. $XDeode = new XDeode ( 5 );
  3371. $ipid = $XDeode->decode ( $ipidKey );
  3372. if (empty ( $ipid ))
  3373. die ( 'illegal request' );
  3374. Doo::loadModel ( 'invoicePaper' );
  3375. $invoicePaper = new invoicePaper ();
  3376. $invoicePaper->delete ( array (
  3377. 'where' => 'ipid=' . $ipid . ' and iid=0',
  3378. 'limit' => 1
  3379. ) );
  3380. return '/invoicePaper';
  3381. }
  3382. /**
  3383. * 添加纸质发票号
  3384. */
  3385. function invoicePaperAdd() {
  3386. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : '0';
  3387. $invoiceCode = $this->get_args ( 'invoiceCode' ) ? $this->get_args ( 'invoiceCode' ) : "";
  3388. $invoiceNoStart = $this->get_args ( 'invoiceNoStart' ) && is_numeric ( $this->get_args ( 'invoiceNoStart' ) ) ? $this->get_args ( 'invoiceNoStart' ) : 0;
  3389. $invoiceNoTotal = $this->get_args ( 'invoiceNoTotal' ) && is_numeric ( $this->get_args ( 'invoiceNoTotal' ) ) ? $this->get_args ( 'invoiceNoTotal' ) : 0;
  3390. if ($invoiceType != '' && ! empty ( $invoiceCode ) && ! empty ( $invoiceNoStart ) && ! empty ( $invoiceNoTotal )) {
  3391. $sum = $invoiceNoStart + $invoiceNoTotal;
  3392. if (empty ( $sum ))
  3393. die ( 'illegal request' );
  3394. // echo $invoiceNoStart;
  3395. // echo $sum;
  3396. // echo strlen((int)$invoiceNoStart);
  3397. $sumLenght = strlen ( $invoiceNoStart ) - strlen ( ( int ) $invoiceNoStart );
  3398. Doo::db ()->beginTransaction ();
  3399. // 批量存储纸质发票
  3400. $date = date ( "Y-m-d H:i:s" );
  3401. $sql = 'INSERT INTO CLD_invoicePaper (invoiceType, invoiceCode,invoiceNo,date)
  3402. VALUES ';
  3403. $paperList = array ();
  3404. for($invoiceNoStart; $invoiceNoStart <= $sum - 1; $invoiceNoStart ++) {
  3405. // 数字前面自加0
  3406. $INLENGHT = strlen ( ( int ) $invoiceNoStart ) + $sumLenght;
  3407. $var = sprintf ( "%0" . $INLENGHT . "d", $invoiceNoStart );
  3408. $paperSql = '(' . $invoiceType . ',"' . $invoiceCode . '","' . $var . '","' . $date . '")';
  3409. array_push ( $paperList, $paperSql );
  3410. }
  3411. if (empty ( $paperList ))
  3412. die ( 'illegal request' );
  3413. $sql = $sql . implode ( ',', $paperList );
  3414. Doo::db ()->query ( $sql );
  3415. Doo::db ()->commit ();
  3416. return 'invoicePaper';
  3417. }
  3418. die ( 'illegal request' );
  3419. }
  3420. /**
  3421. * 收款绑定发票 ,//一个收款只能绑定一个发票
  3422. */
  3423. function invoiceBindReceivables() {
  3424. $claimKey = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  3425. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  3426. Doo::loadModel ( 'invoice' );
  3427. $invoice = new invoice ();
  3428. Doo::loadModel ( 'invoiceReceivables' );
  3429. $invoiceReceivables = new invoiceReceivables ();
  3430. Doo::loadModel ( 'invoiceOperationLog' );
  3431. $invoiceOperationLog = new invoiceOperationLog ();
  3432. if (empty ( $invoiceKey ) || empty ( $claimKey ))
  3433. die ( 'illegal request' );
  3434. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  3435. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey );
  3436. if (empty ( $detail ) && empty ( $detailM ))
  3437. die ( 'illegal request' );
  3438. if ($detail ['untreadStatus'] == 3)
  3439. die ( 'illegal request' );
  3440. // 修改 绑定状态改为 金额
  3441. $invoiceReceivables = new invoiceReceivables ();
  3442. $invoicePrice = $detail ['invoicePrice'] + $detailM ['bindPrice'];
  3443. if ($detailM ['receivablesPrice'] > $invoicePrice) {
  3444. $item = array (
  3445. 'bindPrice' => $invoicePrice
  3446. );
  3447. } elseif ($detailM ['receivablesPrice'] <= $invoicePrice) {
  3448. $item = array (
  3449. 'bindPrice' => $invoicePrice,
  3450. 'bindStatus' => 1,
  3451. 'bindDate' => date ( "Y-m-d H:i:s" )
  3452. );
  3453. } else {
  3454. die ( 'illegal request' );
  3455. }
  3456. if ($detailM ['iid'] == 0) {
  3457. $item += array (
  3458. 'iid' => $detail ['iid']
  3459. );
  3460. } else {
  3461. $iidExtend = explode ( ',', $detailM ['iidExtend'] );
  3462. array_push ( $iidExtend, $detail ['iid'] );
  3463. $item += array (
  3464. 'iidExtend' => implode ( ',', $iidExtend )
  3465. );
  3466. }
  3467. $titleMark = $detail ['invoiceTitle'];
  3468. if (! empty ( $detail ['invoiceCompany'] ))
  3469. $titleMark = $detail ['invoiceCompany'];
  3470. $item += array (
  3471. 'irid' => $detailM ['irid'],
  3472. 'recepitTitleMark' => $titleMark,
  3473. 'accountClerk' => $this->staff [0] ['username']
  3474. );
  3475. // 如何没有人收款 则自动绑定收款
  3476. if ($detailM ['receivablesCategory'] == 'PUBLIC' || $detailM ['receivablesStaff'] == 'PUBLIC') {
  3477. $item += array (
  3478. 'receivablesCategory' => $detail ['cid'] . ':' . $detail ['categoryName'],
  3479. 'receivablesStaff' => $detail ['sid'] . '-' . $detail ['userName']
  3480. );
  3481. }
  3482. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3483. $iridString = "";
  3484. if (empty ( $detail ['irid'] ))
  3485. $iridString = $detailM ['irid'];
  3486. else
  3487. $iridString = $detail ['irid'] . ',' . $detailM ['irid'];
  3488. $item = array (
  3489. 'iid' => $detail ['iid'],
  3490. 'irid' => $iridString
  3491. );
  3492. $invoiceReceivables = new invoiceReceivables ();
  3493. $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  3494. if ($detail ['invoicePrice'] <= $sum)
  3495. $item += array (
  3496. 'untreadStatus' => 3,
  3497. 'bindTime' => date ( "Y-m-d H:i:s" )
  3498. );
  3499. // print_r($item);
  3500. // echo $sum;die;
  3501. $invoice->setInvoiceByCondition ( $item );
  3502. // 操作日志
  3503. $item = array (
  3504. 'date' => date ( "Y-m-d H:i:s" ),
  3505. 'operation' => "收款" . $detailM ['receivablesSerial'] . "入账到发票" . $detail ['invoiceSerial'],
  3506. 'status' => 8,
  3507. 'img' => $this->staff [0] ['avatar'],
  3508. 'username' => $this->staff [0] ['username'],
  3509. 'uid' => $this->staff [0] ['sid'],
  3510. 'category' => $this->staff [0] ['category'],
  3511. 'iid' => $detail ['iid']
  3512. );
  3513. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3514. Doo::loadModel ( 'invoiceStatistics' );
  3515. $invoiceStatistics = new invoiceStatistics ();
  3516. $item = array (
  3517. 'date' => $detailM ['receivablesDate'],
  3518. 'priceClass' => 3,
  3519. 'cid' => $detail ['cid'],
  3520. 'staff' => $detail ['sid'],
  3521. 'accountPrice' => $detailM ['receivablesPrice']
  3522. );
  3523. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3524. // 公司流水记录
  3525. // Doo::loadModel ( 'wasteBook' );
  3526. // $wasteBook = new wasteBook ();
  3527. // $abDetail = $wasteBook->getAccountBookByAid (1,8,$detail ['iid'] );
  3528. // $accountBank='';
  3529. // if ($detailM ['receivablesBank']=='纵横广发'){
  3530. // $accountBank='CGBDeposit';
  3531. // }elseif($detailM ['receivablesBank']=='纵横工行'){
  3532. // $accountBank='ICBCDeposit';
  3533. // }elseif($detailM ['receivablesBank']=='华润银行'){
  3534. // $accountBank='HUADeposit';
  3535. // }elseif($detailM ['receivablesBank']=='个人广发'){
  3536. // $accountBank='PersonalDeposit';
  3537. // }
  3538. // if (empty($abDetail)){
  3539. // $item = array (
  3540. // 'dataID' => $detail ['iid'],
  3541. // 'expensesType' => 1,
  3542. // 'accountType' => 8,
  3543. // 'accountPriceShow'=>$detail ['invoicePrice'],
  3544. // 'accountPrice'=>$detail ['invoicePrice'],
  3545. // 'accountBank'=>$accountBank,
  3546. // 'category'=>$this->staff[0]['category'],
  3547. // 'cid'=>$this->staff[0]['cid'],
  3548. // 'name'=>$this->staff[0]['username'],
  3549. // 'sid'=>$this->staff[0]['sid'],
  3550. // 'inputDate'=>date ( "Y-m-d H:i:s" )
  3551. // );
  3552. // $wasteBook->setAccountBookStatistics($item);
  3553. // }
  3554. return "/invoiceReceivables";
  3555. }
  3556. /**
  3557. * 核销 动作,确认入账统计 发票收款完成--需求更变 废弃 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"; }
  3558. */
  3559. function invoiceAggregate() {
  3560. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3561. Doo::loadModel ( 'invoiceStatistics' );
  3562. $invoiceStatistics = new invoiceStatistics ();
  3563. Doo::loadModel ( 'L_category' );
  3564. $Lcategory = new L_category ();
  3565. $isList = $invoiceStatistics->getInvoiceStatisticsByYear ( $year );
  3566. $LcategoryList = $Lcategory->getCategory ();
  3567. // print_r($isList);
  3568. $html = ""; // $invoicePriceCategory=0;$receivablesPriceCategory=0;$accountPriceCategory=0;
  3569. foreach ( $LcategoryList as $key => $value ) {
  3570. $html .= '<tr><th><a href="/invoiceAggregateCategory/' . $value ['cidKey'] . '">' . $value ['title'] . '</a></th>';
  3571. $month = 1;
  3572. $invoicePriceYear = 0;
  3573. $receivablesPriceYear = 0;
  3574. $accountPriceYear = 0;
  3575. for(; $month <= 12; $month ++) {
  3576. $flag = true;
  3577. foreach ( $isList ['statisticsMonthCid'] as $k => $v ) {
  3578. if ($value ['cid'] == $v ['cid'] && $month == $v ['month']) {
  3579. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  3580. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  3581. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  3582. ';
  3583. $invoicePriceYear += $v ['invoicePrice'];
  3584. $receivablesPriceYear += $v ['receivablesPrice'];
  3585. $accountPriceYear += $v ['accountPrice'];
  3586. $flag = false;
  3587. break;
  3588. }
  3589. }
  3590. if ($flag)
  3591. $html .= '<td class="taR"></td>
  3592. <td class="taR"></td>
  3593. <td class="taR"><b></b></td>
  3594. ';
  3595. }
  3596. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  3597. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  3598. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  3599. ';
  3600. $html .= '</tr>';
  3601. }
  3602. $html .= '<tr><th><b class="colGreen">月合计</b></th>';
  3603. $invoicePriceYear = 0;
  3604. $receivablesPriceYear = 0;
  3605. $accountPriceYear = 0;
  3606. for($month = 1; $month <= 12; $month ++) {
  3607. $flag = true;
  3608. foreach ( $isList ['statisticsMonth'] as $k => $v ) {
  3609. if ($month == $v ['month']) {
  3610. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  3611. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  3612. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  3613. ';
  3614. $invoicePriceYear += $v ['invoicePrice'];
  3615. $receivablesPriceYear += $v ['receivablesPrice'];
  3616. $accountPriceYear += $v ['accountPrice'];
  3617. $flag = false;
  3618. break;
  3619. }
  3620. }
  3621. if ($flag) {
  3622. $html .= '<td class="taR"></td>
  3623. <td class="taR"></td>
  3624. <td class="taR"><b></b></td>
  3625. ';
  3626. }
  3627. }
  3628. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  3629. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  3630. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  3631. ';
  3632. $html .= '</tr>';
  3633. // print_r($isList);
  3634. $this->data ['html'] = $html;
  3635. $this->data ['LcategoryList'] = $LcategoryList;
  3636. $this->data ['isList'] = $isList;
  3637. $this->data ['year'] = $year;
  3638. $this->data ['memu'] = "invoice";
  3639. $this->data ['staff'] = $this->staff;
  3640. $this->data ['receiptMemu'] = 'invoiceAggregate';
  3641. $this->render ( "/admin/invoiceAggregate", $this->data );
  3642. }
  3643. function invoiceAggregateStaff() {
  3644. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3645. Doo::loadModel ( 'invoiceStatistics' );
  3646. $invoiceStatistics = new invoiceStatistics ();
  3647. Doo::loadModel ( 'L_category' );
  3648. $Lcategory = new L_category ();
  3649. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year );
  3650. $staffList = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year );
  3651. $cStaff = $Lcategory->getCategoryStaff ();
  3652. $html = '';
  3653. foreach ( $cStaff as $key => $value ) {
  3654. $categoryFir = true;
  3655. foreach ( $value ['staff'] as $k => $v ) {
  3656. if ($categoryFir) {
  3657. $width = count ( $value ['staff'] ) + 1;
  3658. $html .= '<tr><th rowspan="' . $width . '">' . $value ['title'] . ' </th>';
  3659. $categoryFir = false;
  3660. } else
  3661. $html .= '<tr>';
  3662. $html .= '<th>' . $v ['username'] . '</th>';
  3663. $invoicePriceStaffYear = 0;
  3664. $receivablesPriceStaffYear = 0;
  3665. $accountPriceStaffYear = 0;
  3666. for($month = 1; $month <= 12; $month ++) {
  3667. $flag = true;
  3668. foreach ( $staffList ['statisticsMonthStaff'] as $sl => $slv ) {
  3669. if ($v ['sid'] == $slv ['staff'] && $month == $slv ['month']) {
  3670. $html .= '<td class="taR">¥' . $slv ['invoicePrice'] . '</td>
  3671. <td class="taR">¥' . $slv ['receivablesPrice'] . '</td>
  3672. <td class="taR"><b>¥' . $slv ['accountPrice'] . '</b></td>
  3673. ';
  3674. $invoicePriceStaffYear += $slv ['invoicePrice'];
  3675. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  3676. $accountPriceStaffYear += $slv ['accountPrice'];
  3677. $flag = false;
  3678. break;
  3679. }
  3680. }
  3681. if ($flag)
  3682. $html .= '<td class="taR"></td>
  3683. <td class="taR"></td>
  3684. <td class="taR"><b></b></td>
  3685. ';
  3686. }
  3687. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  3688. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  3689. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  3690. ';
  3691. }
  3692. $html .= '</tr>';
  3693. // 小计
  3694. if (! empty ( $value ['staff'] )) {
  3695. $html .= '<tr><th class="taR">小计</th>';
  3696. $invoicePriceStaffYear = 0;
  3697. $receivablesPriceStaffYear = 0;
  3698. $accountPriceStaffYear = 0;
  3699. for($month = 1; $month <= 12; $month ++) {
  3700. $flag = true;
  3701. foreach ( $staffList ['statisticsMonthCid'] as $smc => $smcv ) {
  3702. if ($value ['cid'] == $smcv ['cid'] && $month == $slv ['month']) {
  3703. $html .= '<td class="taR">¥' . $smcv ['invoicePrice'] . '</td>
  3704. <td class="taR">¥' . $smcv ['receivablesPrice'] . '</td>
  3705. <td class="taR"><b>¥' . $smcv ['accountPrice'] . '</b></td>
  3706. ';
  3707. $invoicePriceStaffYear += $slv ['invoicePrice'];
  3708. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  3709. $accountPriceStaffYear += $slv ['accountPrice'];
  3710. $flag = false;
  3711. break;
  3712. }
  3713. }
  3714. if ($flag)
  3715. $html .= '<td class="taR"></td>
  3716. <td class="taR"></td>
  3717. <td class="taR"><b></b></td>
  3718. ';
  3719. }
  3720. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  3721. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  3722. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  3723. ';
  3724. $html .= '</tr>';
  3725. }
  3726. }
  3727. $html .= '<tr class="warning"><th colspan="2"><b class="colGreen" >月合计</b></th>';
  3728. $invoicePriceYear = 0;
  3729. $receivablesPriceYear = 0;
  3730. $accountPriceYear = 0;
  3731. for($month = 1; $month <= 12; $month ++) {
  3732. $flag = true;
  3733. foreach ( $staffList ['statisticsMonth'] as $k => $v ) {
  3734. if ($month == $v ['month']) {
  3735. $html .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>
  3736. <td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>
  3737. <td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>
  3738. ';
  3739. $invoicePriceYear += $v ['invoicePrice'];
  3740. $receivablesPriceYear += $v ['receivablesPrice'];
  3741. $accountPriceYear += $v ['accountPrice'];
  3742. $flag = false;
  3743. break;
  3744. }
  3745. }
  3746. if ($flag)
  3747. $html .= '<td class="taR"></td>
  3748. <td class="taR"></td>
  3749. <td class="taR"><b></b></td>
  3750. ';
  3751. }
  3752. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  3753. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  3754. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  3755. ';
  3756. $html .= '</tr>';
  3757. $this->data ['html'] = $html;
  3758. $this->data ['isList'] = $toteList;
  3759. $this->data ['year'] = $year;
  3760. $this->data ['memu'] = "invoice";
  3761. $this->data ['staff'] = $this->staff;
  3762. $this->data ['receiptMemu'] = 'invoiceAggregate';
  3763. $this->render ( "/admin/invoiceAggregateStaff", $this->data );
  3764. }
  3765. function invoiceAggregateCategory() {
  3766. Doo::loadClass ( 'XDeode' );
  3767. $XDeode = new XDeode ( 5 );
  3768. $cid = $cidKey = isset ( $this->params ['cid'] ) ? $this->params ['cid'] : "";
  3769. $cid = $XDeode->decode ( $cid );
  3770. if (! is_numeric ( $cid ))
  3771. die ( 'illegal request' );
  3772. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3773. Doo::loadModel ( 'invoiceStatistics' );
  3774. $invoiceStatistics = new invoiceStatistics ();
  3775. Doo::loadModel ( 'staff' );
  3776. $staff = new staff ();
  3777. $list = $staff->getStaffByCid ( $cid );
  3778. $isCategory = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year, $cid );
  3779. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year, $cid );
  3780. if (empty ( $list ))
  3781. die ( '该办事处没有成员' );
  3782. $htmlA = $htmlB = $htmlC = $html = '';
  3783. foreach ( $list as $key => $value ) {
  3784. $htmlA = '<tr><th rowspan="3">' . $value ['username'] . '</th><th class="taC">开票</th>';
  3785. $htmlB = '<tr><th class="taC">收款</th>';
  3786. $htmlC = '<tr><th class="taC">入账</th>';
  3787. $invoicePriceStaffYear = 0;
  3788. $receivablesPriceStaffYear = 0;
  3789. $accountPriceStaffYear = 0;
  3790. for($month = 1; $month <= 12; $month ++) {
  3791. $flag = true;
  3792. foreach ( $isCategory ['statisticsMonthStaff'] as $k => $v ) {
  3793. if ($value ['sid'] == $v ['staff'] && $month == $v ['month']) {
  3794. $htmlA .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>';
  3795. $htmlB .= '<td class="taR">¥' . $v ['receivablesPrice'] . '</td>';
  3796. $htmlC .= '<td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>';
  3797. $invoicePriceStaffYear += $v ['invoicePrice'];
  3798. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  3799. $accountPriceStaffYear += $v ['accountPrice'];
  3800. $flag = false;
  3801. break;
  3802. }
  3803. }
  3804. if ($flag) {
  3805. $htmlA .= '<td class="taR">-</td>';
  3806. $htmlB .= '<td class="taR">-</td>';
  3807. $htmlC .= '<td class="taR"><b>-</b></td>';
  3808. }
  3809. }
  3810. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  3811. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  3812. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  3813. $htmlA .= '</tr>';
  3814. $htmlB .= '</tr>';
  3815. $htmlC .= '</tr>';
  3816. $html .= $htmlA . $htmlB . $htmlC;
  3817. }
  3818. $htmlA = $htmlB = $htmlC = "";
  3819. $htmlA = '<tr><th rowspan="3">月合计</th><th class="taC">开票</th>';
  3820. $htmlB = '<tr><th class="taC">收款</th>';
  3821. $htmlC = '<tr><th class="taC">入账</th>';
  3822. $invoicePriceStaffYear = 0;
  3823. $receivablesPriceStaffYear = 0;
  3824. $accountPriceStaffYear = 0;
  3825. for($month = 1; $month <= 12; $month ++) {
  3826. $flag = true;
  3827. foreach ( $isCategory ['statisticsMonth'] as $k => $v ) {
  3828. if ($month == $v ['month']) {
  3829. $htmlA .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>';
  3830. $htmlB .= '<td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>';
  3831. $htmlC .= '<td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>';
  3832. $invoicePriceStaffYear += $v ['invoicePrice'];
  3833. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  3834. $accountPriceStaffYear += $v ['accountPrice'];
  3835. $flag = false;
  3836. break;
  3837. }
  3838. }
  3839. if ($flag) {
  3840. $htmlA .= '<td class="taR">-</td>';
  3841. $htmlB .= '<td class="taR">-</td>';
  3842. $htmlC .= '<td class="taR"><b>-</b></td>';
  3843. }
  3844. }
  3845. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  3846. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  3847. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  3848. $htmlA .= '</tr>';
  3849. $htmlB .= '</tr>';
  3850. $htmlC .= '</tr>';
  3851. $html .= $htmlA . $htmlB . $htmlC;
  3852. $this->data ['html'] = $html;
  3853. $this->data ['cidKey'] = $cidKey;
  3854. $this->data ['slist'] = $list;
  3855. $this->data ['isList'] = $toteList;
  3856. $this->data ['year'] = $year;
  3857. $this->data ['memu'] = "invoice";
  3858. $this->data ['staff'] = $this->staff;
  3859. $this->data ['receiptMemu'] = 'invoiceAggregate';
  3860. $this->render ( "/admin/invoiceAggregateCategory", $this->data );
  3861. }
  3862. /**
  3863. * 办事处汇总信息
  3864. */
  3865. function invoiceAggregateCategoryDetail() {
  3866. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  3867. Doo::loadClass ( 'XDeode' );
  3868. $XDeode = new XDeode ( 5 );
  3869. Doo::loadModel ( 'invoiceStatistics' );
  3870. $invoiceStatistics = new invoiceStatistics ();
  3871. Doo::loadModel ( 'L_category' );
  3872. $category = new L_category ();
  3873. Doo::loadModel ( 'invoice' );
  3874. $invoice = new invoice ();
  3875. Doo::loadModel ( 'staff' );
  3876. $staff = new staff ();
  3877. Doo::loadModel ( "invoiceCategoryManage" );
  3878. $invoiceCategoryManage = new invoiceCategoryManage ();
  3879. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  3880. $cidList = array ();
  3881. foreach ( $imcStaff as $key => $value ) {
  3882. array_push ( $cidList, $value ['cid'] );
  3883. if (empty ( $cidKey ))
  3884. $cidKey = $XDeode->encode ( $value ['cid'] );
  3885. }
  3886. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  3887. $cid = $XDeode->decode ( $cidKey );
  3888. $month = date ( "m", strtotime ( "-1 month" ) );
  3889. $redis = new Redis ();
  3890. $redis->connect ( '127.0.0.1', '6379' );
  3891. $redisKey = ''; // date('Y-m-d').'_iacd_'.$cid;
  3892. $redisValue = ''; // $redis->lrange($redisKey, 0, -1);
  3893. if (empty ( $redisValue )) {
  3894. $isMC = $invoiceStatistics->getInvoiceStatistiscsMothByCategory ( $cid );
  3895. $schedule = $invoice->getInvoiceScheduleByCid ( $cid );
  3896. // 获得办事处人员下的汇总
  3897. $slist = $staff->getStaffByCid ( $cid );
  3898. $ismsbMonth = $invoiceStatistics->getISMSByCategoryByMonth ( $cid, $month ); // 上一个月的汇总
  3899. $ismsb = $invoiceStatistics->getISMSByCategory ( $cid ); // 当月汇总
  3900. $ISAS = $invoiceStatistics->getISASByCategory ( $cid ); // 全部汇总
  3901. $scheduleStaff = $invoice->getInvoiceScheduleByCidGroupSid ( $cid ); // 完成度
  3902. foreach ( $slist as $key => $value ) {
  3903. $slist [$key] ['invoicePrice'] = 0;
  3904. $slist [$key] ['receivablesPrice'] = 0;
  3905. $slist [$key] ['accountPrice'] = 0;
  3906. $slist [$key] ['invoiceAllPrice'] = 0;
  3907. $slist [$key] ['receivablesAllPrice'] = 0;
  3908. $slist [$key] ['accountAllPrice'] = 0;
  3909. $slist [$key] ['schedule'] = 0;
  3910. $slist [$key] ['invoiceMonthPrice'] = 0;
  3911. $slist [$key] ['receivablesMonthPrice'] = 0;
  3912. $slist [$key] ['accountMonthPrice'] = 0;
  3913. foreach ( $ismsbMonth as $y => $l ) {
  3914. if ($value ['sid'] == $l ['staff']) {
  3915. $slist [$key] ['invoiceMonthPrice'] = $l ['invoicePrice'];
  3916. $slist [$key] ['receivablesMonthPrice'] = $l ['receivablesPrice'];
  3917. $slist [$key] ['accountMonthPrice'] = $l ['accountPrice'];
  3918. }
  3919. }
  3920. foreach ( $ismsb as $k => $v ) {
  3921. if ($value ['sid'] == $v ['staff']) {
  3922. $slist [$key] ['invoicePrice'] = $v ['invoicePrice'];
  3923. $slist [$key] ['receivablesPrice'] = $v ['receivablesPrice'];
  3924. $slist [$key] ['accountPrice'] = $v ['accountPrice'];
  3925. }
  3926. }
  3927. foreach ( $ISAS as $e => $a ) {
  3928. if ($value ['sid'] == $a ['staff']) {
  3929. $slist [$key] ['invoiceAllPrice'] = $a ['invoicePrice'];
  3930. $slist [$key] ['receivablesAllPrice'] = $a ['receivablesPrice'];
  3931. $slist [$key] ['accountAllPrice'] = $a ['accountPrice'];
  3932. }
  3933. }
  3934. if (isset ( $scheduleStaff [$value ['sid']] ))
  3935. $slist [$key] ['schedule'] = $scheduleStaff [$value ['sid']];
  3936. }
  3937. $this->data ['cidKey'] = $cidKey;
  3938. $schedule = ( int ) ($schedule * 100);
  3939. $this->data ['slist'] = $slist;
  3940. $this->data ['isMC'] = $isMC;
  3941. $this->data ['schedule'] = $schedule;
  3942. $slist = json_encode ( $slist );
  3943. $isMC = json_encode ( $isMC );
  3944. $schedule = json_encode ( $schedule );
  3945. $redis->lpush ( $redisKey, $slist );
  3946. $redis->lpush ( $redisKey, $isMC );
  3947. $redis->lpush ( $redisKey, $schedule );
  3948. } else {
  3949. $this->data ['cidKey'] = $cidKey;
  3950. $this->data ['slist'] = json_decode ( $redisValue [2], true );
  3951. $this->data ['isMC'] = json_decode ( $redisValue [1], true );
  3952. $this->data ['schedule'] = json_decode ( $redisValue [0], true );
  3953. }
  3954. $this->data ['month'] = $month;
  3955. $this->data ['categoryList'] = $categoryList;
  3956. $this->data ['memu'] = "invoice";
  3957. $this->data ['staff'] = $this->staff;
  3958. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  3959. $this->render ( "/admin/invoiceAggregateCategoryDetail", $this->data );
  3960. }
  3961. /**
  3962. * 办事处人员汇总详情
  3963. */
  3964. function invoiceAggregateStaffDetail() {
  3965. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  3966. // $sidKey = isset ( $this->params ['sidKey'] ) ? $this->params ['sidKey'] : '';
  3967. Doo::loadClass ( 'XDeode' );
  3968. $XDeode = new XDeode ( 5 );
  3969. Doo::loadModel ( 'invoice' );
  3970. $invoice = new invoice ();
  3971. Doo::loadModel ( 'staff' );
  3972. $staff = new staff ();
  3973. Doo::loadModel ( "invoiceCategoryManage" );
  3974. $invoiceCategoryManage = new invoiceCategoryManage ();
  3975. $sid = $XDeode->decode ( $sidKey );
  3976. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  3977. $cidList = array ();
  3978. foreach ( $imcStaff as $key => $value ) {
  3979. array_push ( $cidList, $value ['cid'] );
  3980. if (empty ( $cidKey ))
  3981. $cidKey = $XDeode->encode ( $value ['cid'] );
  3982. }
  3983. $cidString = implode ( ',', $cidList );
  3984. $staffList = $staff->getStaffInCid ( $cidString );
  3985. $staffDetail = $staff->getStaffBySid ( $sid );
  3986. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  3987. $page_size = 18;
  3988. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  3989. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  3990. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  3991. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  3992. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  3993. $dateArr = explode ( ':', $date );
  3994. $D1 = '';
  3995. $D2 = '';
  3996. if (! empty ( $date )) {
  3997. $D1 = $dateArr [0] . " 00:00:00 ";
  3998. if (isset ( $dateArr [1] ))
  3999. $D2 = $dateArr [1] . " 23:59:59 ";
  4000. else
  4001. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4002. // $D2 = $dateArr [1];
  4003. }
  4004. $con = ' status=2 ';
  4005. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4006. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4007. if ($status == 'UNRECORD')
  4008. $con .= ' and printStatus=1 and untreadStatus=0';
  4009. elseif ($status == 'RECORD')
  4010. $con .= ' and printStatus=1 and untreadStatus=3';
  4011. elseif ($status == 'BOUNCED')
  4012. $con .= ' and untreadStatus=2';
  4013. elseif ($status == 'PARTRECORD')
  4014. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  4015. elseif ($status == 'All') {
  4016. $con .= ' and ( untreadStatus=2 or untreadStatus=0 or untreadStatus=3 )';
  4017. }
  4018. $con .= ' and sid=' . $sid;
  4019. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  4020. if (! empty ( $MebSea )) {
  4021. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  4022. }
  4023. $pageinfo ['page'] = array (
  4024. 'previous' => ''
  4025. );
  4026. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateStaffDetail", $get, "" );
  4027. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4028. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  4029. $this->data ['staffDetail'] = $staffDetail;
  4030. $this->data ['staffList'] = $staffList;
  4031. $this->data ['MebSeaEn'] = $MebSea;
  4032. $this->data ['MebSea'] = urlencode ( $MebSea );
  4033. $this->data ['date'] = $date;
  4034. $this->data ['page'] = $pageinfo;
  4035. $this->data ['get'] = $get;
  4036. $this->data ['list'] = $list;
  4037. $this->data ['status'] = $status;
  4038. $this->data ['sidKey'] = $sidKey;
  4039. $this->data ['memu'] = "invoice";
  4040. $this->data ['staff'] = $this->staff;
  4041. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4042. $this->render ( "/admin/invoiceAggregateStaffDetail", $this->data );
  4043. }
  4044. /**
  4045. * 办事处人员汇总收款情
  4046. */
  4047. function invoiceAggregateStaffReceivablesDetail() {
  4048. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  4049. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  4050. Doo::loadModel ( 'invoiceReceivables' );
  4051. $invoiceReceivables = new invoiceReceivables ();
  4052. Doo::loadModel ( 'staff' );
  4053. $staff = new staff ();
  4054. Doo::loadModel ( "invoiceCategoryManage" );
  4055. $invoiceCategoryManage = new invoiceCategoryManage ();
  4056. Doo::loadClass ( 'XDeode' );
  4057. $XDeode = new XDeode ( 5 );
  4058. $sid = $XDeode->decode ( $sidKey );
  4059. $staffDetail = $staff->getStaffBySid ( $sid );
  4060. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4061. $cidList = array ();
  4062. foreach ( $imcStaff as $key => $value ) {
  4063. array_push ( $cidList, $value ['cid'] );
  4064. if (empty ( $cidKey ))
  4065. $cidKey = $XDeode->encode ( $value ['cid'] );
  4066. }
  4067. $cidString = implode ( ',', $cidList );
  4068. $staffList = $staff->getStaffInCid ( $cidString );
  4069. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4070. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  4071. $page_size = 10;
  4072. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4073. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4074. if ($timeType == "BINDOTP") {
  4075. $status = 'Credited';
  4076. }
  4077. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  4078. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  4079. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  4080. $dateArr = explode ( ':', $date );
  4081. $D1 = '';
  4082. $D2 = '';
  4083. if (! empty ( $date )) {
  4084. $D1 = $dateArr [0] . " 00:00:00 ";
  4085. if (isset ( $dateArr [1] ))
  4086. $D2 = $dateArr [1] . " 23:59:59 ";
  4087. else
  4088. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4089. }
  4090. $con = ' a.receivablesStaff like "%' . $staffDetail ['username'] . '%" ';
  4091. $descField = 'a.bindDate';
  4092. if ($timeType == 'CREATE')
  4093. $descField = 'a.date';
  4094. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4095. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4096. elseif (! empty ( $D1 ) && empty ( $D2 ))
  4097. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  4098. if ($status == 'Unclaimed')
  4099. $con .= ' and a.bindStatus=0';
  4100. elseif ($status == 'Credited')
  4101. $con .= ' and a.bindStatus=1';
  4102. elseif ($status == 'Claim')
  4103. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  4104. elseif ($status == 'BBN')
  4105. $con .= ' and a.bindPrice>a.receivablesPrice';
  4106. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  4107. if (! empty ( $MebSea )) {
  4108. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" )';
  4109. }
  4110. $pageinfo ['page'] = array (
  4111. 'previous' => ''
  4112. );
  4113. $sql = 'select group_concat(b.invoiceSerial) as invoiceSerial ,group_concat(b.iid) as invoiceId
  4114. from CLD_invoiceReceivables as a left join CLD_invoice as b on
  4115. find_in_set(b.iid,a.iidExtend) or a.iid=b.iid
  4116. where ' . $con . ' group by a.irid ';
  4117. $pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceAggregateStaffReceivablesDetail", $get, "" );
  4118. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4119. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', 'printTime' );
  4120. foreach ( $list as $key => $value ) {
  4121. $list [$key] ['category'] = '';
  4122. if ($value ['receivablesCategory'] != 'PUBLIC') {
  4123. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  4124. $list [$key] ['category'] = $receivablesCategory [1];
  4125. }
  4126. }
  4127. // print_r($list);
  4128. $this->data ['staffDetail'] = $staffDetail;
  4129. $this->data ['sidKey'] = $sidKey;
  4130. $this->data ['staffList'] = $staffList;
  4131. $this->data ['timeType'] = $timeType;
  4132. $this->data ['MebSeaEn'] = $MebSea;
  4133. $this->data ['MebSea'] = urlencode ( $MebSea );
  4134. $this->data ['date'] = $date;
  4135. $this->data ['page'] = $pageinfo;
  4136. $this->data ['get'] = $get;
  4137. $this->data ['list'] = $list;
  4138. $this->data ['status'] = $status;
  4139. $this->data ['memu'] = "invoice";
  4140. $this->data ['staff'] = $this->staff;
  4141. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4142. $this->render ( "/admin/invoiceAggregateStaffReceivablesDetail", $this->data );
  4143. }
  4144. function invoiceAchieve() {
  4145. Doo::loadModel ( 'invoice' );
  4146. $invoice = new invoice ();
  4147. Doo::loadClass ( 'XDeode' );
  4148. $XDeode = new XDeode ( 5 );
  4149. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4150. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4151. $page_size = 18;
  4152. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4153. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4154. $get = "/" . $date;
  4155. $con = '';
  4156. if ($date == 'MONTHO')
  4157. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4158. elseif ($date == 'MONTHT')
  4159. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4160. elseif ($date == 'MONTHY')
  4161. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4162. if (! empty ( $MebSea )) {
  4163. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4164. $get .= "/" . $MebSea;
  4165. }
  4166. $pageinfo ['page'] = array (
  4167. 'previous' => ''
  4168. );
  4169. $sql = 'status=2 and printStatus=1 and irid!="" and ( untreadStatus=3 or untreadStatus=0 ) and sid=' . $sid . $con;
  4170. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceAchieve", $get, "" );
  4171. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4172. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  4173. // print_r($pageinfo);
  4174. $this->data ['MebSeaEn'] = $MebSea;
  4175. $this->data ['MebSea'] = urlencode ( $MebSea );
  4176. $this->data ['get'] = $get;
  4177. $this->data ['page'] = $pageinfo;
  4178. $this->data ['list'] = $list;
  4179. $this->data ['date'] = $date;
  4180. $this->data ['memu'] = "invoice";
  4181. $this->data ['staff'] = $this->staff;
  4182. $this->data ['receiptMemu'] = 'invoice';
  4183. $this->render ( "/admin/invoiceAchieve", $this->data );
  4184. }
  4185. /**
  4186. */
  4187. function invoiceMyUnAccountAchieve() {
  4188. Doo::loadModel ( 'invoice' );
  4189. $invoice = new invoice ();
  4190. Doo::loadClass ( 'XDeode' );
  4191. $XDeode = new XDeode ( 5 );
  4192. Doo::loadModel ( 'staff' );
  4193. $staff = new staff ();
  4194. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4195. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4196. $page_size = 18;
  4197. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4198. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4199. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4200. $dateArr = explode ( ':', $date );
  4201. $D1 = '';
  4202. $D2 = '';
  4203. if (! empty ( $date )) {
  4204. $D1 = $dateArr [0];
  4205. $D2 = $dateArr [1];
  4206. }
  4207. $con = '';
  4208. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4209. $con = ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4210. if (! empty ( $MebSea )) {
  4211. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4212. }
  4213. $pageinfo ['page'] = array (
  4214. 'previous' => ''
  4215. );
  4216. // and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  4217. $sql = " status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid= " . $sid . $con;
  4218. $action = "invoiceMyUnAccountAchieve";
  4219. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  4220. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4221. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  4222. Doo::loadModel ( 'express' );
  4223. $express = new express ();
  4224. $expressList = $express->getExpressByAll ();
  4225. $this->data ['expressList'] = $expressList;
  4226. // print_r($list);
  4227. $this->data ['MebSeaEn'] = $MebSea;
  4228. $this->data ['get'] = $get;
  4229. $this->data ['page'] = $pageinfo;
  4230. $this->data ['date'] = $date;
  4231. $this->data ['list'] = $list;
  4232. $this->data ['memu'] = "invoice";
  4233. $this->data ['staff'] = $this->staff;
  4234. $this->data ['receiptMemu'] = 'invoice';
  4235. $this->render ( "/admin/invoiceMyUnAccountAchieve", $this->data );
  4236. }
  4237. function invoiceReceivablesAchieve() {
  4238. Doo::loadModel ( 'invoiceReceivables' );
  4239. $invoiceReceivables = new invoiceReceivables ();
  4240. Doo::loadClass ( 'XDeode' );
  4241. $XDeode = new XDeode ( 5 );
  4242. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4243. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  4244. $page_size = 12;
  4245. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4246. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4247. $get = "/" . $date;
  4248. $con = '';
  4249. if ($date == 'MONTHO')
  4250. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4251. elseif ($date == 'MONTHT')
  4252. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4253. elseif ($date == 'MONTHY')
  4254. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4255. if (! empty ( $MebSea )) {
  4256. $con .= ' and ( receivablesMessage like "%' . $MebSea . '%" or receivablesPrice like "%' . $MebSea . '%" )';
  4257. $get .= "/" . $MebSea;
  4258. }
  4259. $pageinfo ['page'] = array (
  4260. 'previous' => ''
  4261. );
  4262. $sql = " bindStatus=1 and receivablesStaff like '" . $sid . "_%' " . $con;
  4263. $pageinfo = $this->get_page ( "CLD_invoiceReceivables", $sql, $page, $page_size, "invoiceReceivablesAchieve", $get, "" );
  4264. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4265. $list = $invoiceReceivables->getReceivablesByUntreadStatusPage ( $limit, $sql );
  4266. // print_r($pageinfo);
  4267. $this->data ['MebSeaEn'] = $MebSea;
  4268. $this->data ['MebSea'] = urlencode ( $MebSea );
  4269. $this->data ['get'] = $get;
  4270. $this->data ['page'] = $pageinfo;
  4271. $this->data ['list'] = $list;
  4272. $this->data ['date'] = $date;
  4273. $this->data ['memu'] = "invoice";
  4274. $this->data ['staff'] = $this->staff;
  4275. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  4276. $this->render ( "/admin/invoiceReceivablesAchieve", $this->data );
  4277. }
  4278. /**
  4279. * 收款解绑
  4280. */
  4281. function invoiceUnBundLing() {
  4282. $unBundKey = $this->get_args ( 'unBundKey' ) ? $this->get_args ( 'unBundKey' ) : '';
  4283. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  4284. Doo::loadModel ( 'invoice' );
  4285. $invoice = new invoice ();
  4286. Doo::loadModel ( 'invoiceReceivables' );
  4287. $invoiceReceivables = new invoiceReceivables ();
  4288. Doo::loadModel ( 'invoiceOperationLog' );
  4289. $invoiceOperationLog = new invoiceOperationLog ();
  4290. Doo::loadModel ( 'invoiceROLog' );
  4291. $invoiceROLog = new invoiceROLog ();
  4292. Doo::loadModel ( 'invoiceStatistics' );
  4293. Doo::loadClass ( 'XDeode' );
  4294. $XDeode = new XDeode ( 5 );
  4295. if (empty ( $iidKey ) || empty ( $unBundKey ))
  4296. die ( 'illegal request' );
  4297. $iid = $XDeode->decode ( $iidKey );
  4298. $irid = $invoice->authcode ( $unBundKey );
  4299. if ((! empty ( $irid ) && ! is_numeric ( $irid )) || (! empty ( $iid ) && ! is_numeric ( $iid )))
  4300. die ( 'illegal request' );
  4301. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4302. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  4303. if (empty ( $irDetails ) || empty ( $invoiceDetails ) || (empty ( $irDetails ['iid'] ) && empty ( $irDetails ['iidExtend'] )) || $invoiceDetails ['untreadStatus'] == 2)
  4304. die ( 'illegal request' );
  4305. // 收款
  4306. $item = array (
  4307. 'irid' => $irDetails ['irid'],
  4308. 'bindPrice' => $irDetails ['bindPrice'] - $invoiceDetails ['invoicePrice'],
  4309. 'bindStatus' => 0
  4310. );
  4311. if ($irDetails ['iid'] == $iid)
  4312. $item += array (
  4313. 'iid' => 0
  4314. );
  4315. else {
  4316. $iidExtend = explode ( ',', $irDetails ['iidExtend'] );
  4317. foreach ( $iidExtend as $key => $value ) {
  4318. if ($value == $iid)
  4319. unset ( $iidExtend [$key] );
  4320. }
  4321. $iidExtend = implode ( ',', $iidExtend );
  4322. $item += array (
  4323. 'iidExtend' => $iidExtend
  4324. );
  4325. }
  4326. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4327. // 收款操作日志
  4328. $item = array (
  4329. 'operation' => $this->staff [0] ['username'] . " 解绑 " . $irDetails ['receivablesSerial'],
  4330. 'date' => date ( "Y-m-d" ),
  4331. 'status' => 3,
  4332. 'img' => $this->staff [0] ['avatar'],
  4333. 'username' => $this->staff [0] ['username'],
  4334. 'uid' => $this->staff [0] ['sid'],
  4335. 'category' => $this->staff [0] ['category'],
  4336. 'irid' => $irid
  4337. );
  4338. $invoiceROLog->setInvoiceROLog ( $item );
  4339. // 扣除入账统计金额
  4340. $invoiceStatistics = new invoiceStatistics ();
  4341. $item = array (
  4342. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  4343. 'priceClass' => 3,
  4344. 'cid' => $invoiceDetails ['cid'],
  4345. 'staff' => $invoiceDetails ['sid'],
  4346. 'accountPrice' => - $irDetails ['receivablesPrice']
  4347. );
  4348. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4349. // 扣除收款统计金额
  4350. $invoiceStatistics = new invoiceStatistics ();
  4351. $item = array (
  4352. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  4353. 'priceClass' => 2,
  4354. 'cid' => $invoiceDetails ['cid'],
  4355. 'staff' => $invoiceDetails ['sid'],
  4356. 'irid' => $irDetails ['irid'],
  4357. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  4358. );
  4359. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4360. // 发票解绑去收款ID
  4361. $iridString = $invoiceDetails ['irid'];
  4362. if (! empty ( $invoiceDetails ['irid'] )) {
  4363. $list = explode ( ',', $invoiceDetails ['irid'] );
  4364. foreach ( $list as $key => $value ) {
  4365. if ($value == $irDetails ['irid']) {
  4366. unset ( $list [$key] );
  4367. break;
  4368. }
  4369. }
  4370. $iridString = implode ( ",", $list );
  4371. }
  4372. $item = array (
  4373. 'iid' => $invoiceDetails ['iid'],
  4374. 'irid' => $iridString,
  4375. 'updateTime' => date ( "Y-m-d H:i:s" )
  4376. );
  4377. if ($invoiceDetails ['untreadStatus'] == 3)
  4378. $item += array (
  4379. 'untreadStatus' => 0
  4380. );
  4381. $invoice->setInvoiceByCondition ( $item );
  4382. $item = array (
  4383. 'date' => date ( "Y-m-d H:i:s" ),
  4384. 'operation' => '解绑 收款 ' . $irDetails ['receivablesSerial'],
  4385. 'status' => 11,
  4386. 'img' => $this->staff [0] ['avatar'],
  4387. 'username' => $this->staff [0] ['username'],
  4388. 'uid' => $this->staff [0] ['sid'],
  4389. 'category' => $this->staff [0] ['category'],
  4390. 'iid' => $invoiceDetails ['iid']
  4391. );
  4392. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  4393. // 公司流水-解绑时删除流水
  4394. Doo::loadModel ( 'wasteBook' );
  4395. $wasteBook = new wasteBook ();
  4396. // $wasteBook->delete ( array (
  4397. // 'where' => 'dataID=' . $irDetails ['irid'] . ' and accountType=7',
  4398. // 'limit' => 1
  4399. // ) );
  4400. // 银行
  4401. /*
  4402. * $abDetail = $wasteBook->getAccountBookByAid (2,7,$irDetails ['irid'] ); $accountBank=''; if ($irDetails ['receivablesBank']=='纵横广发'){ $accountBank='CGBDeposit'; }elseif($irDetails ['receivablesBank']=='纵横工行'){ $accountBank='ICBCDeposit'; }elseif($irDetails ['receivablesBank']=='华润银行'){ $accountBank='HUADeposit'; }elseif($irDetails ['receivablesBank']=='个人广发'){ $accountBank='PersonalDeposit'; } if (empty($abDetail)){ $item = array ( 'dataID' => $irDetails ['irid'], 'expensesType' => 2, 'accountType' => 7, 'accountPriceShow'=>$irDetails ['receivablesPrice'], 'accountPrice' => -$irDetails ['receivablesPrice'], 'accountBank'=>$accountBank, 'cid'=>$this->staff[0]['cid'], 'name'=>$this->staff[0]['username'], 'sid'=>$this->staff[0]['sid'], 'inputDate'=>date ( "Y-m-d H:i:s" ) ); $wasteBook->setAccountBookStatistics($item); }
  4403. */
  4404. return "/invoiceReceivablesAS";
  4405. }
  4406. /**
  4407. * 或者该收款下的所以发票
  4408. */
  4409. function ajaxGetInvoiceReceivablesByInvoice() {
  4410. $irid = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : '';
  4411. Doo::loadModel ( 'invoice' );
  4412. $invoice = new invoice ();
  4413. Doo::loadModel ( 'invoiceReceivables' );
  4414. $invoiceReceivables = new invoiceReceivables ();
  4415. $irid = $invoice->authcode ( $irid );
  4416. if (! empty ( $irid ) && ! is_numeric ( $irid ))
  4417. die ( 'illegal request' );
  4418. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4419. $iidString = $irDetails ['iid'];
  4420. $iidExtend = array_filter ( explode ( ',', $irDetails ['iidExtend'] ) );
  4421. if (! empty ( $irDetails ['iidExtend'] ))
  4422. $iidString .= ',' . implode ( ',', $iidExtend );
  4423. $invoiceList = $invoice->getInvoiceInIid ( $iidString, 'iid,invoiceSerial,invoicePrice,invoiceTitle,invoiceCompany,invoiceElement' );
  4424. $html = "";
  4425. foreach ( $invoiceList as $key => $value ) {
  4426. $title = $value ['invoiceTitle'];
  4427. if (! empty ( $value ['invoiceCompany'] ))
  4428. $title = $value ['invoiceCompany'];
  4429. $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>';
  4430. }
  4431. echo json_encode ( array (
  4432. 'status' => 1,
  4433. 'html' => $html
  4434. ) );
  4435. }
  4436. /**
  4437. * 发票管理
  4438. */
  4439. function invoiceAS() {
  4440. Doo::loadModel ( 'invoice' );
  4441. $invoice = new invoice ();
  4442. Doo::loadModel ( 'invoiceReceivables' );
  4443. $invoiceReceivables = new invoiceReceivables ();
  4444. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4445. $page_size = 18;
  4446. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4447. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4448. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4449. $dateArr = explode ( ':', $date );
  4450. $D1 = '';
  4451. $D2 = '';
  4452. if (! empty ( $date )) {
  4453. $D1 = $dateArr [0] . " 00:00:00 ";
  4454. if (isset ( $dateArr [1] ))
  4455. $D2 = $dateArr [1] . " 23:59:59 ";
  4456. else
  4457. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4458. // $D2 = $dateArr [1];
  4459. }
  4460. $con = ' status=2 ';
  4461. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4462. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4463. if ($status == 'UNRECORD')
  4464. $con .= ' and printStatus=1 and untreadStatus=0';
  4465. elseif ($status == 'RECORD')
  4466. $con .= ' and printStatus=1 and untreadStatus=3';
  4467. elseif ($status == 'BOUNCED')
  4468. $con .= ' and untreadStatus=2';
  4469. elseif ($status == 'PARTRECORD')
  4470. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  4471. elseif ($status == 'All') {
  4472. $con .= ' and ( untreadStatus=2 or untreadStatus=1 or untreadStatus=0 or untreadStatus=3 )';
  4473. }
  4474. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4475. if (! empty ( $MebSea )) {
  4476. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  4477. }
  4478. $pageinfo ['page'] = array (
  4479. 'previous' => ''
  4480. );
  4481. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAS", $get, "" );
  4482. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4483. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  4484. $this->data ['MebSeaEn'] = $MebSea;
  4485. $this->data ['MebSea'] = urlencode ( $MebSea );
  4486. $this->data ['date'] = $date;
  4487. $this->data ['page'] = $pageinfo;
  4488. $this->data ['get'] = $get;
  4489. $this->data ['list'] = $list;
  4490. $this->data ['status'] = $status;
  4491. $this->data ['memu'] = "invoice";
  4492. $this->data ['staff'] = $this->staff;
  4493. $this->data ['receiptMemu'] = 'invoiceReceivables';
  4494. $this->render ( "/admin/invoiceAS", $this->data );
  4495. }
  4496. /**
  4497. * 收款管理
  4498. */
  4499. function invoiceReceivablesAS() {
  4500. Doo::loadModel ( 'invoiceReceivables' );
  4501. $invoiceReceivables = new invoiceReceivables ();
  4502. Doo::loadModel ( 'L_category' );
  4503. $lCategory = new L_category ();
  4504. $category = $lCategory->getCategory ();
  4505. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4506. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  4507. $page_size = 10;
  4508. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4509. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4510. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4511. $dateArr = explode ( ':', $date );
  4512. $D1 = '';
  4513. $D2 = '';
  4514. if (! empty ( $date )) {
  4515. $D1 = $dateArr [0]; // ." 00:00:00 ";
  4516. if (isset ( $dateArr [1] ))
  4517. $D2 = $dateArr [1]; // ." 23:59:59 ";
  4518. else
  4519. $D2 = $dateArr [0]; // ." 23:59:59 ";//date ( "Y-m-d" );
  4520. }
  4521. $descField = 'a.receivablesDate';
  4522. if ($timeType == 'CREATE')
  4523. $descField = 'a.date';
  4524. $con = '1';
  4525. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4526. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4527. elseif (! empty ( $D1 ) && empty ( $D2 ))
  4528. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  4529. if ($status == 'Unclaimed')
  4530. $con .= ' and a.bindStatus=0';
  4531. elseif ($status == 'Credited')
  4532. $con .= ' and a.bindStatus=1';
  4533. elseif ($status == 'Claim')
  4534. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  4535. elseif ($status == 'BBN')
  4536. $con .= ' and a.bankBatchNumber!=""';
  4537. elseif ($status == 'REFUND')
  4538. $con .= ' and ( (a.bindStatus=0 and a.refundLog!="" ) or a.bindStatus=2)';
  4539. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4540. if (! empty ( $MebSea )) {
  4541. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" or a.receivablesSerial like "%' . $MebSea . '%" )';
  4542. }
  4543. $pageinfo ['page'] = array (
  4544. 'previous' => ''
  4545. );
  4546. $sql = 'select group_concat(b.invoiceSerial) as invoiceSerial ,group_concat(b.iid) as invoiceId
  4547. from CLD_invoiceReceivables as a left join CLD_invoice as b on
  4548. find_in_set(b.iid,a.iidExtend) or a.iid=b.iid
  4549. where ' . $con . ' group by a.irid ';
  4550. $pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceReceivablesAS", $get, "" );
  4551. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4552. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', $descField );
  4553. foreach ( $list as $key => $value ) {
  4554. $list [$key] ['category'] = '';
  4555. if ($value ['receivablesCategory'] != 'PUBLIC') {
  4556. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  4557. $list [$key] ['category'] = $receivablesCategory [1];
  4558. }
  4559. }
  4560. // print_r($list);
  4561. $this->data ['category'] = $category;
  4562. $this->data ['timeType'] = $timeType;
  4563. $this->data ['MebSeaEn'] = $MebSea;
  4564. $this->data ['MebSea'] = urlencode ( $MebSea );
  4565. $this->data ['date'] = $date;
  4566. $this->data ['page'] = $pageinfo;
  4567. $this->data ['get'] = $get;
  4568. $this->data ['list'] = $list;
  4569. $this->data ['status'] = $status;
  4570. $this->data ['memu'] = "invoice";
  4571. $this->data ['staff'] = $this->staff;
  4572. $this->data ['receiptMemu'] = 'invoiceReceivables';
  4573. $this->render ( "/admin/invoiceReceivablesAS", $this->data );
  4574. }
  4575. /**
  4576. * 删除一条收款
  4577. */
  4578. function delInvoiceReceivables() {
  4579. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  4580. if (empty ( $iridKey ))
  4581. die ( 'illegal request' );
  4582. Doo::loadClass ( 'XDeode' );
  4583. $XDeode = new XDeode ( 5 );
  4584. $irid = $XDeode->decode ( $iridKey );
  4585. Doo::loadModel ( 'invoiceReceivables' );
  4586. $invoiceReceivables = new invoiceReceivables ();
  4587. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4588. if (empty ( $detail ))
  4589. die ( 'illegal request' );
  4590. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  4591. // 扣除收款汇总信息 汇总
  4592. Doo::loadModel ( 'invoiceStatistics' );
  4593. $invoiceStatistics = new invoiceStatistics ();
  4594. $item = array (
  4595. 'date' => $detail ['receivablesDate'],
  4596. 'priceClass' => 2,
  4597. 'irid' => $detail ['irid'],
  4598. 'receivablesPrice' => - $detail ['receivablesPrice']
  4599. );
  4600. if ($detail ['receivablesCategory'] != 'PUBLIC') {
  4601. $receivablesCategory = explode ( ":", $detail ['receivablesCategory'] );
  4602. $item += array (
  4603. 'cid' => $receivablesCategory [0]
  4604. );
  4605. }
  4606. if ($detail ['receivablesStaff'] != 'PUBLIC') {
  4607. $receivablesStaff = explode ( "-", $detail ['receivablesStaff'] );
  4608. $item += array (
  4609. 'staff' => $receivablesStaff [0]
  4610. );
  4611. }
  4612. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4613. return '/invoiceReceivablesAS';
  4614. }
  4615. /**
  4616. * 添加退款信息
  4617. */
  4618. function setInvoiceReceivablesRefund() {
  4619. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  4620. $refundType = $this->get_args ( 'refundType' ) && is_numeric ( $this->get_args ( 'refundType' ) ) ? $this->get_args ( 'refundType' ) : '0';
  4621. $refundCompany = $this->get_args ( 'refundCompany' ) ? $this->get_args ( 'refundCompany' ) : "";
  4622. $refundNumber = $this->get_args ( 'refundNumber' ) ? $this->get_args ( 'refundNumber' ) : "";
  4623. $refundPrice = $this->get_args ( 'refundPrice' ) ? $this->get_args ( 'refundPrice' ) : "";
  4624. $refundRemarks = $this->get_args ( 'refundRemarks' ) ? $this->get_args ( 'refundRemarks' ) : "";
  4625. if ($refundPrice < 0)
  4626. die ( 'illegal request' );
  4627. if (! empty ( $iridKey ) && ! empty ( $refundCompany ) && ! empty ( $refundNumber ) && ! empty ( $refundPrice )) {
  4628. Doo::loadModel ( 'invoiceReceivables' );
  4629. $invoiceReceivables = new invoiceReceivables ();
  4630. Doo::loadModel ( 'invoiceRefund' );
  4631. $invoiceRefund = new invoiceRefund ();
  4632. $irid = $invoiceReceivables->authcode ( $iridKey );
  4633. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4634. if ($irDetail ['receivablesPrice'] < $refundPrice)
  4635. die ( 'illegal request' );
  4636. $invoiceReceivables = new invoiceReceivables ();
  4637. $refundLog = $this->staff [0] ['username'] . ' 退款 <b class="colRed">¥' . $refundPrice . '</b>
  4638. <br/><a href="#refunded" onclick="getRefundByDetail(\'' . $iridKey . '\')" data-toggle="modal">退款信息</a> <br/>' . date ( "Y-m-d H:i:s" ) . '
  4639. ';
  4640. $item = array (
  4641. 'irid' => $irid,
  4642. 'refundCompany' => $refundCompany,
  4643. 'refundNumber' => $refundNumber,
  4644. 'refundPrice' => $refundPrice,
  4645. 'refundRemarks' => $refundRemarks,
  4646. 'refundLog' => $refundLog
  4647. );
  4648. if ($refundType == 1) {
  4649. $item += array (
  4650. 'refundType' => $refundType,
  4651. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice,
  4652. 'bindStatus' => 2
  4653. );
  4654. } elseif ($refundType == 0 && $irDetail ['receivablesPrice'] <= $refundPrice) {
  4655. $item += array (
  4656. 'refundType' => 1,
  4657. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice,
  4658. 'bindStatus' => 2
  4659. );
  4660. } else {
  4661. $item += array (
  4662. 'refundType' => $refundType,
  4663. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice
  4664. );
  4665. }
  4666. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4667. // 添加退款记录
  4668. $item = array (
  4669. 'irid' => $irid,
  4670. 'refundType' => $refundType,
  4671. 'refundCompany' => $refundCompany,
  4672. 'refundNumber' => $refundNumber,
  4673. 'refundPrice' => $refundPrice,
  4674. 'refundLog' => $refundLog,
  4675. 'refundRemarks' => $refundRemarks,
  4676. 'date' => date ( "Y-m-d H:i:s" )
  4677. );
  4678. $invoiceRefund->addInvoiceRefund ( $item );
  4679. // 扣除收款汇总信息 汇总
  4680. Doo::loadModel ( 'invoiceStatistics' );
  4681. $invoiceStatistics = new invoiceStatistics ();
  4682. $item = array (
  4683. 'date' => $irDetail ['receivablesDate'],
  4684. 'priceClass' => 2,
  4685. 'irid' => $irDetail ['irid'],
  4686. 'receivablesPrice' => - $refundPrice
  4687. );
  4688. if ($irDetail ['receivablesCategory'] != 'PUBLIC') {
  4689. $receivablesCategory = explode ( ":", $irDetail ['receivablesCategory'] );
  4690. $item += array (
  4691. 'cid' => $receivablesCategory [0]
  4692. );
  4693. }
  4694. if ($irDetail ['receivablesStaff'] != 'PUBLIC') {
  4695. $receivablesStaff = explode ( "-", $irDetail ['receivablesStaff'] );
  4696. $item += array (
  4697. 'staff' => $receivablesStaff [0]
  4698. );
  4699. }
  4700. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4701. // 公司日常支出流水
  4702. Doo::loadModel ( 'wasteBook' );
  4703. $wasteBook = new wasteBook ();
  4704. $accountBank = '';
  4705. if ($irDetail ['receivablesBank'] == '纵横广发') {
  4706. $accountBank = 'CGBDeposit';
  4707. } elseif ($irDetail ['receivablesBank'] == '纵横工行') {
  4708. $accountBank = 'ICBCDeposit';
  4709. } elseif ($irDetail ['receivablesBank'] == '华润银行') {
  4710. $accountBank = 'HUADeposit';
  4711. } elseif ($irDetail ['receivablesBank'] == '个人广发') {
  4712. $accountBank = 'PersonalDeposit';
  4713. }
  4714. $itemWaste = array (
  4715. 'accountPrice' => - $refundPrice,
  4716. 'expensesType' => 2,
  4717. 'accountType' => 11,
  4718. 'accountPriceShow' => $refundPrice,
  4719. 'dataID' => $irid,
  4720. 'accountBank' => $accountBank,
  4721. 'category' => $this->staff [0] ['category'],
  4722. 'cid' => $this->staff [0] ['cid'],
  4723. 'name' => $this->staff [0] ['username'],
  4724. 'sid' => $this->staff [0] ['sid'],
  4725. 'inputDate' => date ( "Y-m-d H:i:s" )
  4726. );
  4727. $wasteBook->setAccountBookStatistics ( $itemWaste );
  4728. return '/invoiceReceivablesAS';
  4729. }
  4730. die ( 'illegal request' );
  4731. }
  4732. function ajaxCheckInvoiceReceivablesRefund() {
  4733. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  4734. $refundPrice = $this->get_args ( 'refundPrice' ) ? $this->get_args ( 'refundPrice' ) : "";
  4735. if ($refundPrice < 0) {
  4736. echo json_encode ( array (
  4737. 'error' => '金额不能为负'
  4738. ) );
  4739. die ();
  4740. }
  4741. if (! empty ( $refundPrice ) && ! empty ( $iridKey )) {
  4742. Doo::loadModel ( 'invoiceReceivables' );
  4743. $invoiceReceivables = new invoiceReceivables ();
  4744. $irid = $invoiceReceivables->authcode ( $iridKey );
  4745. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4746. if ($irDetail ['receivablesPrice'] < $refundPrice) {
  4747. echo json_encode ( array (
  4748. 'error' => '退款金额不能超过收款金额'
  4749. ) );
  4750. die ();
  4751. }
  4752. echo json_encode ( array (
  4753. 'ok' => '可以使用!'
  4754. ) );
  4755. die ();
  4756. }
  4757. }
  4758. /**
  4759. * 获得收款退款信息
  4760. */
  4761. function getRefundByDetail() {
  4762. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  4763. Doo::loadModel ( 'invoiceReceivables' );
  4764. $invoiceReceivables = new invoiceReceivables ();
  4765. if (! empty ( $iridKey )) {
  4766. $irid = $invoiceReceivables->authcode ( $iridKey );
  4767. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4768. echo json_encode ( array (
  4769. 'status' => 1,
  4770. 'irDetail' => $irDetail
  4771. ) );
  4772. die ();
  4773. }
  4774. echo json_encode ( array (
  4775. 'status' => 2
  4776. ) );
  4777. }
  4778. /**
  4779. * 根据收款序列号获得收款退款信息
  4780. */
  4781. function ajaxGetInvoiceReceivablesBySerial() {
  4782. $receivablesSerial = $this->get_args ( 'receivablesSerial' ) ? $this->get_args ( 'receivablesSerial' ) : '';
  4783. if (! empty ( $receivablesSerial )) {
  4784. Doo::loadModel ( 'invoiceReceivables' );
  4785. $invoiceReceivables = new invoiceReceivables ();
  4786. // , ' and refundLog=""'
  4787. $irDetail = $invoiceReceivables->getInvoiceReceivablesBySerial ( $receivablesSerial );
  4788. $html = '';
  4789. if (! empty ( $irDetail ))
  4790. $html = '<td><b>¥' . $irDetail ['receivablesPrice'] . '</b></td>
  4791. <td>' . $irDetail ['receivablesMessage'] . '</td>
  4792. <td>' . $irDetail ['receivablesBank'] . '<br>' . $irDetail ['receivablesDate'] . '</td>
  4793. <td>' . $irDetail ['title'] . '-' . $irDetail ['username'] . '<br>' . $irDetail ['confirmTime'] . '</td>
  4794. <td>' . $irDetail ['recepitTitleMark'] . '
  4795. <input type="hidden" name="iridKey" id="iridKey" value="' . $irDetail ['iridKey'] . '">
  4796. </td>';
  4797. echo json_encode ( array (
  4798. 'status' => 1,
  4799. 'html' => $html,
  4800. 'irDetail' => $irDetail
  4801. ) );
  4802. die ();
  4803. }
  4804. echo json_encode ( array (
  4805. 'status' => 2
  4806. ) );
  4807. }
  4808. /**
  4809. * 绑定新收款
  4810. */
  4811. function relationNewInvoiceReceivables() {
  4812. $iridKeyOld = $this->get_args ( 'iridKeyOld' ) ? $this->get_args ( 'iridKeyOld' ) : '';
  4813. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  4814. if (! empty ( $iridKeyOld ) && ! empty ( $iridKey )) {
  4815. Doo::loadModel ( 'invoiceReceivables' );
  4816. $invoiceReceivables = new invoiceReceivables ();
  4817. Doo::loadClass ( 'XDeode' );
  4818. $XDeode = new XDeode ( 5 );
  4819. $irid = $XDeode->decode ( $iridKey );
  4820. $iridOld = $invoiceReceivables->authcode ( $iridKeyOld );
  4821. echo $irid . 'bbb' . $iridOld;
  4822. $oldIrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $iridOld );
  4823. $IrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4824. if (empty ( $oldIrDetail ) || empty ( $IrDetail ))
  4825. die ( 'illegal request' );
  4826. $relationLog = $this->staff [0] ['username'] . ' 关联新款 <a href="#billing" onclick="invoiceReceivblesDivShow(\'' . $iridKey . '\',\'receivables\')" data-toggle="modal">' . $IrDetail ['receivablesSerial'] . '</a>
  4827. <br/>' . date ( "Y-m-d H:i:s" ) . '
  4828. ';
  4829. $invoiceReceivables = new invoiceReceivables ();
  4830. $item = array (
  4831. 'irid' => $iridOld,
  4832. 'relationIrid' => $irid,
  4833. 'relationLog' => $relationLog
  4834. );
  4835. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4836. return '/invoiceReceivablesAS';
  4837. }
  4838. die ( 'illegal request' );
  4839. }
  4840. // function invoiceApprovalAchieve() {
  4841. // Doo::loadModel ( 'invoice' );
  4842. // $invoice = new invoice ();
  4843. // $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  4844. // $page_size = 12;
  4845. // $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4846. // $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4847. // $get = "/" . $date;
  4848. // $con = '';
  4849. // if ($date == 'MONTHO')
  4850. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4851. // elseif ($date == 'MONTHT')
  4852. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4853. // elseif ($date == 'MONTHY')
  4854. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4855. // if (! empty ( $MebSea )) {
  4856. // $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4857. // $get .= "/" . $MebSea;
  4858. // }
  4859. // $pageinfo ['page'] = array (
  4860. // 'previous' => ''
  4861. // );
  4862. // $sql = '(status=1 or status=2 or status=3 or status=4) and processApprovals!=""' . $con; // echo $sql;
  4863. // $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", $get, "" );
  4864. // $limit = $pageinfo ['lower'] . ',' . $page_size;
  4865. // $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  4866. // // print_r($list);
  4867. // $this->data ['MebSeaEn'] = $MebSea;
  4868. // $this->data ['MebSea'] = urlencode ( $MebSea );
  4869. // $this->data ['get'] = $get;
  4870. // $this->data ['page'] = $pageinfo;
  4871. // $this->data ['list'] = $list;
  4872. // $this->data ['date'] = $date;
  4873. // $this->data ['memu'] = "invoice";
  4874. // $this->data ['staff'] = $this->staff;
  4875. // $this->data ['receiptMemu'] = 'invoiceApproval';
  4876. // $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  4877. // }
  4878. /**
  4879. * 获得审批发票的信息以及审批页面
  4880. */
  4881. function ajaxGetInvoiceApprovalDetail() {
  4882. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  4883. if (empty ( $serial )) {
  4884. echo json_encode ( array (
  4885. 'status' => 2,
  4886. 'msg' => 'illegal request'
  4887. ) );
  4888. die ();
  4889. }
  4890. Doo::loadModel ( 'invoice' );
  4891. $invoice = new invoice ();
  4892. Doo::loadModel ( 'invoiceOperationLog' );
  4893. $invoiceOperationLog = new invoiceOperationLog ();
  4894. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  4895. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  4896. if (empty ( $detail ))
  4897. $html = '';
  4898. else {
  4899. $html = '
  4900. <form action="/invoiceApprovalDo" method="post" name="invoiceApproval" class="nice-validator n-yellow" novalidate="novalidate">
  4901. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  4902. <input type="hidden" name="status" value="">
  4903. <input type="hidden" name="divApproval" value="divApproval">
  4904. <div class="modal-dialog modal-lg">
  4905. <div class="modal-content"><div class="modal-header"><h3>发票审批详情</h3></div>
  4906. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  4907. <tr>
  4908. <th class="taC" width="150">发票审批</th><td><textarea name="opinion" style="width:98%" placeholder="在这写下您的审批意见,选填。"></textarea></td>
  4909. </tr>
  4910. <tr>
  4911. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  4912. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  4913. </tr>
  4914. <tr>
  4915. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  4916. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  4917. </tr>
  4918. <tr>
  4919. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  4920. </td>
  4921. </tr>
  4922. <tr>
  4923. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  4924. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  4925. </tr>
  4926. <tr>
  4927. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  4928. </tr></tbody></table>';
  4929. if ($detail ['invoiceType'] == 0)
  4930. $html .= '<table class="table table-bordered table-condensed"><tbody>
  4931. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  4932. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  4933. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  4934. </tr>';
  4935. else
  4936. $html .= '<table class="table table-bordered table-condensed"><tbody>
  4937. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  4938. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  4939. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  4940. ';
  4941. $html .= '<tr>
  4942. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  4943. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  4944. </tr>
  4945. <tr>
  4946. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  4947. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  4948. </tr></tbody></table>';
  4949. if ($detail ['doPost'] == 1) {
  4950. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  4951. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  4952. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  4953. </tr><tr>
  4954. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  4955. </tr><tr>
  4956. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  4957. </tr>
  4958. ';
  4959. if ($detail ['expressCom'] == 'SF')
  4960. $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>';
  4961. else
  4962. $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>';
  4963. $html .= '</tbody></table>';
  4964. }
  4965. if (! empty ( $invoiceOperationLogList )) {
  4966. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  4967. foreach ( $invoiceOperationLogList as $key => $value ) {
  4968. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  4969. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  4970. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  4971. if ($value ['status'] == 2) {
  4972. $html .= '<span class="colGreen">同意</span>';
  4973. } elseif ($value ['status'] == 3) {
  4974. $html .= '<span class="colOrange">退回</span>';
  4975. } elseif ($value ['status'] == 5) {
  4976. $html .= '<span class="colGreen">打印</span>';
  4977. } elseif ($value ['status'] == 4) {
  4978. $html .= '<span class="colRed">终止</span>';
  4979. }
  4980. $html .= $value ['operation'] . '</p></blockquote>';
  4981. }
  4982. }
  4983. $html .= '</td></tr></tbody></table>';
  4984. }
  4985. $html .= '</div><div class="modal-footer">
  4986. <a href="javascript:void(0)" node-approval="approval" diss-data="2" class="button btn-done" data-placement="top" data-toggle="ctooltip" >同意</a>
  4987. <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>
  4988. <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>
  4989. <a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>
  4990. </form>
  4991. <script type="text/javascript">
  4992. $("a[node-approval^=\'approval\']").click(function() {
  4993. $("input[name=\'status\']").val($(this).attr("diss-data"));
  4994. $("form[name=\'invoiceApproval\']").submit();
  4995. });
  4996. </script>
  4997. ';
  4998. }
  4999. echo json_encode ( array (
  5000. 'status' => 1,
  5001. 'html' => $html
  5002. ) );
  5003. die ();
  5004. }
  5005. /**
  5006. * 获得审批发票分页数据
  5007. */
  5008. function ajaxGetinvoiceApprovalAchieve() {
  5009. Doo::loadModel ( 'invoice' );
  5010. $invoice = new invoice ();
  5011. Doo::loadModel ( 'staff' );
  5012. $staff = new staff ();
  5013. Doo::loadClass ( 'XDeode' );
  5014. $XDeode = new XDeode ( 5 );
  5015. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  5016. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5017. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5018. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5019. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5020. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  5021. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  5022. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  5023. $MebSea = $this->get_args ( 'search' );
  5024. $MebSea = $MebSea ['value'];
  5025. $page_size = $length;
  5026. $con = '';
  5027. if ($status == 'ALL')
  5028. $con = ' (status=1 or status=2 or status=3 or status=4) and isDelete=0 ';
  5029. elseif ($status == 'PEND')
  5030. $con = ' isDelete=0 and status=1';
  5031. elseif ($status == 'APPROVED')
  5032. $con = ' isDelete=0 and status=2';
  5033. if ($invoiceType == 'ORDINARY')
  5034. $con .= ' and invoiceType=0 ';
  5035. elseif ($invoiceType == 'SPECIAL')
  5036. $con .= ' and invoiceType=1 ';
  5037. if ($invoiceTrain == 'ORDINARY')
  5038. $con .= ' and trainId=0 ';
  5039. elseif ($invoiceTrain == 'TRAIN')
  5040. $con .= ' and trainId!=0 ';
  5041. if ($invoiceTrainName != 'ALL') {
  5042. $trainId = $XDeode->decode ( $invoiceTrainName );
  5043. if (is_numeric ( $trainId ))
  5044. $con .= ' and trainId =' . $trainId;
  5045. }
  5046. $dateArr = explode ( ':', $date );
  5047. $D1 = $dateString = '';
  5048. $D2 = '';
  5049. if (! empty ( $date )) {
  5050. $D1 = $dateArr [0];
  5051. if (isset ( $dateArr [1] ))
  5052. $D2 = $dateArr [1];
  5053. else
  5054. $D2 = '';
  5055. $dateString = $D1 . " : " . $D2;
  5056. }
  5057. if (! empty ( $D1 ) && ! empty ( $D2 ))
  5058. $con .= ' and approvalTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  5059. elseif (! empty ( $D1 ) && empty ( $D2 ))
  5060. $con .= ' and approvalTime like "%' . $D1 . '%" ';
  5061. if (! empty ( $MebSea ))
  5062. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceSerial like "%' . $MebSea . '%" )';
  5063. // /
  5064. $pageinfo ['page'] = array (
  5065. 'previous' => ''
  5066. );
  5067. $sql = ' ' . $con;
  5068. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", '', "" );
  5069. $limit = $page . ',' . $page_size;
  5070. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  5071. $approvalList = array ();
  5072. $html = '
  5073. <script type="text/javascript">
  5074. </script>
  5075. ';
  5076. foreach ( $list as $key => $value ) {
  5077. $irDetail = array ();
  5078. if ($value ['status'] == 1 && $value ['pendingApprovals'] == $this->staff [0] ['sid']) {
  5079. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoiceApproval(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">审批发票</a>' );
  5080. } else
  5081. array_push ( $irDetail, '' );
  5082. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  5083. if ($value ['invoiceType'] == 1)
  5084. array_push ( $irDetail, $value ['invoiceCompany'] );
  5085. else
  5086. array_push ( $irDetail, $value ['invoiceTitle'] );
  5087. array_push ( $irDetail, $value ['TIN'] );
  5088. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  5089. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  5090. array_push ( $irDetail, $value ['remark'] );
  5091. array_push ( $irDetail, $value ['invoiceElement'] );
  5092. array_push ( $irDetail, $value ['invoiceQuantity'] );
  5093. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  5094. if ($value ['invoiceType'] == 1)
  5095. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  5096. else
  5097. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  5098. array_push ( $irDetail, $value ['recipients'] . $value ['recipientsPhone'] );
  5099. array_push ( $irDetail, $value ['recipientsAddress'] );
  5100. array_push ( $irDetail, $value ['mailItems'] );
  5101. array_push ( $irDetail, $value ['userName'] . '&nbsp;' . $value ['date'] );
  5102. $fchtml = $value ['OL'] ['operation'];
  5103. if (count ( $list ) == $page_size)
  5104. $fchtml = $value ['OL'] ['operation'] . $html;
  5105. // 最后的审批意见
  5106. array_push ( $irDetail, $fchtml );
  5107. if ($value ['status'] == 2)
  5108. array_push ( $irDetail, '<span class="colGreen">同意</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5109. elseif ($value ['status'] == 3)
  5110. array_push ( $irDetail, '<span class="colOrange">退回</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5111. elseif ($value ['status'] == 4)
  5112. array_push ( $irDetail, '<span class="colRed">终止</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5113. else
  5114. array_push ( $irDetail, '' );
  5115. array_push ( $approvalList, $irDetail );
  5116. }
  5117. // $approvalListJson = json_encode ( $approvalList );
  5118. $recordsFiltered = $pageinfo ['total_data'];
  5119. echo json_encode ( array (
  5120. "draw" => intval ( $draw ),
  5121. "recordsTotal" => intval ( $pageinfo ['total_data'] ),
  5122. "recordsFiltered" => intval ( $recordsFiltered ),
  5123. "data" => $approvalList
  5124. ), JSON_UNESCAPED_UNICODE );
  5125. }
  5126. /**
  5127. * 审批发票查看更多--重构
  5128. */
  5129. function invoiceApprovalAchieve() {
  5130. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'ALL';
  5131. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5132. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5133. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5134. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5135. Doo::loadModel ( 'invoiceTraining' );
  5136. $invoiceTraining = new invoiceTraining ();
  5137. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  5138. $this->data ['trainList'] = $trainList;
  5139. $this->data ['dateString'] = $date;
  5140. $this->data ['status'] = $status;
  5141. $this->data ['invoiceType'] = $invoiceType;
  5142. $this->data ['invoiceTrain'] = $invoiceTrain;
  5143. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  5144. $this->data ['memu'] = "invoice";
  5145. $this->data ['staff'] = $this->staff;
  5146. $this->data ['receiptMemu'] = 'invoiceApproval';
  5147. $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  5148. }
  5149. function invoiceTAchieve() {
  5150. Doo::loadModel ( 'invoice' );
  5151. $invoice = new invoice ();
  5152. Doo::loadClass ( 'XDeode' );
  5153. $XDeode = new XDeode ( 5 );
  5154. Doo::loadModel ( 'staff' );
  5155. $staff = new staff ();
  5156. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  5157. $page_size = 12;
  5158. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5159. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  5160. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5161. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5162. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5163. Doo::loadModel ( 'invoiceTraining' );
  5164. $invoiceTraining = new invoiceTraining ();
  5165. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  5166. $get = "/" . $date;
  5167. $con = '';
  5168. if ($date == 'MONTHO')
  5169. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  5170. elseif ($date == 'MONTHT')
  5171. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  5172. elseif ($date == 'MONTHY')
  5173. $con = ' and YEAR(updateTime) = YEAR(NOW())'; // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  5174. if ($invoiceType == 'ORDINARY')
  5175. $con .= ' and invoiceType=0 ';
  5176. elseif ($invoiceType == 'SPECIAL')
  5177. $con .= ' and invoiceType=1 ';
  5178. if ($invoiceTrain == 'ORDINARY')
  5179. $con .= ' and trainId=0 ';
  5180. elseif ($invoiceTrain == 'TRAIN')
  5181. $con .= ' and trainId!=0 ';
  5182. if ($invoiceTrainName != 'ALL') {
  5183. $trainId = $XDeode->decode ( $invoiceTrainName );
  5184. if (is_numeric ( $trainId ))
  5185. $con .= ' and trainId =' . $trainId;
  5186. }
  5187. if (! empty ( $MebSea )) {
  5188. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  5189. $get .= "/" . $MebSea;
  5190. }
  5191. $pageinfo ['page'] = array (
  5192. 'previous' => ''
  5193. );
  5194. $sql = "";
  5195. $action = "";
  5196. if ($this->ACTION == 'invoicePrintAchieve') {
  5197. $sql = "status=2 and printStatus=1 and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  5198. $action = "invoicePrintAchieve";
  5199. } elseif ($this->ACTION == 'invoicePostAchieve') {
  5200. // and untreadStatus=0
  5201. $sql = "postStatus=1 and doPost=1 and status=2 and isDelete=0" . $con;
  5202. $action = "invoicePostAchieve";
  5203. } elseif ($this->ACTION == 'invoiceUntreadAchieve') { // printStatus=1 and
  5204. $sql = " untreadStatus=2 and status=2 " . $con;
  5205. $action = "invoiceUntreadAchieve";
  5206. }
  5207. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  5208. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5209. $this->data ['MebSeaEn'] = $MebSea;
  5210. $this->data ['MebSea'] = urlencode ( $MebSea );
  5211. $this->data ['get'] = $get;
  5212. $this->data ['page'] = $pageinfo;
  5213. $this->data ['trainList'] = $trainList;
  5214. $this->data ['invoiceType'] = $invoiceType;
  5215. $this->data ['invoiceTrain'] = $invoiceTrain;
  5216. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  5217. $this->data ['date'] = $date;
  5218. $this->data ['memu'] = "invoice";
  5219. $this->data ['staff'] = $this->staff;
  5220. if ($this->ACTION == 'invoicePrintAchieve') {
  5221. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  5222. $this->data ['receiptMemu'] = 'invoicePrint';
  5223. $this->data ['list'] = $list;
  5224. $this->render ( "/admin/invoicePrintAchieve", $this->data );
  5225. } elseif ($this->ACTION == 'invoicePostAchieve') {
  5226. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  5227. Doo::loadModel ( 'express' );
  5228. $express = new express ();
  5229. $expressList = $express->getExpressByAll ();
  5230. $this->data ['expressList'] = $expressList;
  5231. $this->data ['receiptMemu'] = 'invoicePost';
  5232. $this->data ['list'] = $list;
  5233. $this->render ( "/admin/invoicePostAchieve", $this->data );
  5234. } elseif ($this->ACTION == 'invoiceUntreadAchieve') {
  5235. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  5236. $this->data ['receiptMemu'] = 'invoiceUntread';
  5237. $this->data ['list'] = $list;
  5238. $this->render ( "/admin/invoiceUntreadAchieve", $this->data );
  5239. }
  5240. }
  5241. /**
  5242. * 公司应收款
  5243. */
  5244. function invoiceAggregateCompanyDetail() {
  5245. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  5246. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  5247. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : 'ALL';
  5248. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  5249. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  5250. Doo::loadClass ( 'XDeode' );
  5251. $XDeode = new XDeode ( 5 );
  5252. Doo::loadModel ( 'invoice' );
  5253. $invoice = new invoice ();
  5254. Doo::loadModel ( 'staff' );
  5255. $staff = new staff ();
  5256. Doo::loadModel ( "invoiceCompanyManage" );
  5257. $invoiceCompanyManage = new invoiceCompanyManage ();
  5258. Doo::loadModel ( 'L_category' );
  5259. $category = new L_category ();
  5260. $sid = '';
  5261. if (! empty ( $sidKey )) {
  5262. $sid = $XDeode->decode ( $sidKey );
  5263. }
  5264. $staffDetail = $staff->getStaffBySid ( $sid );
  5265. $cid = '';
  5266. if (! empty ( $cidKey )) {
  5267. $cid = $XDeode->decode ( $cidKey );
  5268. }
  5269. $imcStaff = $invoiceCompanyManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  5270. $cidList = array ();
  5271. foreach ( $imcStaff as $key => $value ) {
  5272. array_push ( $cidList, $value ['cid'] );
  5273. }
  5274. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  5275. $cidString = implode ( ',', $cidList );
  5276. if (empty ( $cid ))
  5277. $staffList = $staff->getStaffInCid ( $cidString );
  5278. else
  5279. $staffList = $staff->getStaffByCidAll ( $cid ); //
  5280. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  5281. $page_size = 25;
  5282. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5283. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  5284. $con = ' status=2 and untreadStatus!=2 ';
  5285. $statisticsCon = '';
  5286. if (! empty ( $year ) && is_numeric ( $year ))
  5287. $con .= ' and Year(printTime)=' . $year . '';
  5288. if (! empty ( $month ) && is_numeric ( $month ))
  5289. $con .= ' and Month(printTime)="' . $month . '" ';
  5290. if ($status == 'UNRECORD')
  5291. $con .= ' and printStatus=1 and untreadStatus=0';
  5292. elseif ($status == 'RECORD')
  5293. $con .= ' and printStatus=1 and untreadStatus=3';
  5294. elseif ($status == 'BOUNCED')
  5295. $con .= ' and untreadStatus=2';
  5296. elseif ($status == 'PARTRECORD')
  5297. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  5298. elseif ($status == 'All') {
  5299. $con .= ' and printStatus=1 and ( untreadStatus=0 or untreadStatus=3 )';
  5300. }
  5301. if (! empty ( $sid ) && is_numeric ( $sid ))
  5302. $con .= ' and sid=' . $sid;
  5303. if (! empty ( $cid ) && is_numeric ( $cid ))
  5304. $con .= ' and cid=' . $cid;
  5305. else
  5306. $con .= ' and cid in (' . $cidString . ')';
  5307. // 开票内容筛选
  5308. if (! empty ( $invoiceElement ) && $invoiceElement != 'ALL') {
  5309. $con .= ' and invoiceElement="' . $invoiceElement . '"';
  5310. }
  5311. $get = "/" . $status . "?cidKey=" . $cidKey . "&sidKey=" . $sidKey . "&year=" . $year . "&month=" . $month . "&invoiceElement=" . $invoiceElement;
  5312. if (! empty ( $MebSea )) {
  5313. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  5314. }
  5315. $pageinfo ['page'] = array (
  5316. 'previous' => ''
  5317. );
  5318. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateCompanyDetail", $get, "" );
  5319. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5320. // 应收款合计
  5321. $ics = $invoice->getInvoiceCompanyStatistics ( $con );
  5322. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  5323. $monthHtml = "";
  5324. if ($year != "ALL") {
  5325. for($i = 1; $i <= 12; $i ++) {
  5326. if ($i == $month)
  5327. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  5328. else
  5329. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  5330. }
  5331. }
  5332. $this->data ['monthHtml'] = $monthHtml;
  5333. $this->data ['year'] = $year;
  5334. $this->data ['month'] = $month;
  5335. $this->data ['ics'] = $ics;
  5336. $this->data ['cidKey'] = $cidKey;
  5337. $this->data ['sid'] = $sid;
  5338. $this->data ['staffDetail'] = $staffDetail;
  5339. $this->data ['staffList'] = $staffList;
  5340. $this->data ['MebSeaEn'] = $MebSea;
  5341. $this->data ['MebSea'] = urlencode ( $MebSea );
  5342. $this->data ['invoiceDetail'] = array (
  5343. 'invoiceElement' => $invoiceElement
  5344. );
  5345. $this->data ['page'] = $pageinfo;
  5346. $this->data ['get'] = $get;
  5347. $this->data ['list'] = $list;
  5348. $this->data ['status'] = $status;
  5349. $this->data ['categoryList'] = $categoryList;
  5350. $this->data ['memu'] = "invoice";
  5351. $this->data ['staff'] = $this->staff;
  5352. $this->data ['receiptMemu'] = 'invoiceAggregateCompanyDetail';
  5353. $this->render ( "/admin/invoiceAggregateCompanyDetail", $this->data );
  5354. }
  5355. /**
  5356. * 获取一条收款信息
  5357. */
  5358. function ajaxGetInvoiceReceivables() {
  5359. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  5360. Doo::loadModel ( 'invoiceReceivables' );
  5361. $invoiceReceivables = new invoiceReceivables ();
  5362. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5363. echo json_encode ( array (
  5364. 'status' => 1,
  5365. 'detail' => $detail
  5366. ) );
  5367. }
  5368. /**
  5369. * 异步获取办事处用户
  5370. */
  5371. function ajaxGetStaffByCategory() {
  5372. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "";
  5373. Doo::loadModel ( 'staff' );
  5374. $staff = new staff ();
  5375. if ($cid == "PUBLIC") {
  5376. echo json_encode ( array (
  5377. 'status' => 1,
  5378. 'html' => '<option value="PUBLIC">办事处待认领款项</option>'
  5379. ) );
  5380. die ();
  5381. }
  5382. if (! is_numeric ( $cid )) {
  5383. echo json_encode ( array (
  5384. 'status' => 0,
  5385. 'msg' => 'illegal request'
  5386. ) );
  5387. die ();
  5388. }
  5389. $staffList = $staff->getStaffByCid ( $cid );
  5390. $html = '<option value="PUBLIC">办事处待认领款项</option>';
  5391. foreach ( $staffList as $key => $value ) {
  5392. $html .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  5393. }
  5394. echo json_encode ( array (
  5395. 'status' => 1,
  5396. 'html' => $html
  5397. ) );
  5398. }
  5399. /**
  5400. * 异步获取一条发票的邮寄信息
  5401. */
  5402. function ajaxGetInvoicePostDetail() {
  5403. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  5404. Doo::loadModel ( 'invoice' );
  5405. $invoice = new invoice ();
  5406. $iid = $invoice->authcode ( $iid );
  5407. Doo::loadModel ( 'express' );
  5408. $express = new express ();
  5409. $expressList = $express->getExpressByAll ();
  5410. if (! is_numeric ( $iid )) {
  5411. echo json_encode ( array (
  5412. 'status' => 0,
  5413. 'msg' => 'illegal request'
  5414. ) );
  5415. die ();
  5416. }
  5417. $select = "iid,recipients,recipientsPhone,recipientsAddress,mailItems,expressCompany,expressNumber,actualItems";
  5418. $invoiceDetail = $invoice->getInvoiceByIid ( $iid, $select );
  5419. $html = "";
  5420. foreach ( $expressList as $key => $value ) {
  5421. if ($value ['company'] == $invoiceDetail ['expressCompany'])
  5422. $html .= '<option selected value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  5423. else
  5424. $html .= '<option value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  5425. }
  5426. $invoiceDetail ['eaHtml'] = $html;
  5427. echo json_encode ( array (
  5428. 'status' => 1,
  5429. 'invoiceDetail' => $invoiceDetail
  5430. ) );
  5431. }
  5432. /**
  5433. *
  5434. * @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 ) ); }
  5435. */
  5436. /**
  5437. *
  5438. * @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 ) ); }
  5439. */
  5440. /**
  5441. * 我的收款中 选择哪个发票入账,进行金额判断
  5442. */
  5443. function ajaxCompareInvoicePrice() {
  5444. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  5445. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  5446. Doo::loadModel ( 'invoice' );
  5447. $invoice = new invoice ();
  5448. Doo::loadModel ( 'invoiceReceivables' );
  5449. $invoiceReceivables = new invoiceReceivables ();
  5450. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  5451. $keyList = explode ( ';', $claimKey );
  5452. $receivablesPrice = 0;
  5453. foreach ( $keyList as $key => $value ) {
  5454. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $value );
  5455. $receivablesPrice += $detailM ['receivablesPrice'];
  5456. }
  5457. if ($receivablesPrice > $detail ['invoicePrice']) {
  5458. $price = $receivablesPrice - $detail ['invoicePrice'];
  5459. echo json_encode ( array (
  5460. 'status' => 1,
  5461. 'price' => $price
  5462. ) );
  5463. } else
  5464. echo json_encode ( array (
  5465. 'status' => 2
  5466. ) );
  5467. }
  5468. /**
  5469. * 获得打印发票
  5470. */
  5471. function ajaxGetInvoiceInfoByPrint() {
  5472. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5473. if (empty ( $serial )) {
  5474. echo json_encode ( array (
  5475. 'status' => 2,
  5476. 'msg' => 'illegal request'
  5477. ) );
  5478. die ();
  5479. }
  5480. Doo::loadModel ( 'invoice' );
  5481. $invoice = new invoice ();
  5482. Doo::loadModel ( 'invoiceOperationLog' );
  5483. $invoiceOperationLog = new invoiceOperationLog ();
  5484. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5485. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5486. Doo::loadModel ( 'invoicePaper' );
  5487. $invoicePaper = new invoicePaper ();
  5488. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $detail ['invoiceType'] );
  5489. if (empty ( $detail ))
  5490. $html = '';
  5491. else {
  5492. $html = '
  5493. <form action="/invoicePrintDo" method="post" name="invoicePrint" class="nice-validator n-yellow" onSubmit="return checkPrintForm()" novalidate="novalidate">
  5494. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  5495. <input type="hidden" name="invoicePrintType" value="invoicePrintType">
  5496. <div class="modal-dialog modal-lg">
  5497. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  5498. <div class="modal-body saeaList">
  5499. <table class="table table-bordered table-condensed"><tbody>
  5500. <tr>
  5501. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5502. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5503. </tr>
  5504. <tr>
  5505. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5506. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5507. </tr>
  5508. <tr>
  5509. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5510. </td>
  5511. </tr>
  5512. <tr>
  5513. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5514. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5515. </tr>
  5516. <tr>
  5517. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5518. </tr></tbody></table>';
  5519. if ($detail ['invoiceType'] == 0)
  5520. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5521. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5522. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5523. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5524. </tr>';
  5525. else
  5526. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5527. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5528. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5529. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5530. ';
  5531. $html .= '<tr>
  5532. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5533. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5534. </tr>
  5535. <tr>
  5536. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5537. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5538. </tr></tbody></table>';
  5539. if ($detail ['doPost'] == 1)
  5540. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5541. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5542. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5543. </tr><tr>
  5544. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5545. </tr><tr>
  5546. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5547. </tr></tbody></table>';
  5548. if (! empty ( $invoiceOperationLogList )) {
  5549. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th><th class="taC">发票打印</th></tr><tr><td>';
  5550. foreach ( $invoiceOperationLogList as $key => $value ) {
  5551. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5552. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5553. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5554. if ($value ['status'] == 2) {
  5555. $html .= '<span class="colGreen">同意</span>';
  5556. } elseif ($value ['status'] == 3) {
  5557. $html .= '<span class="colOrange">退回</span>';
  5558. } elseif ($value ['status'] == 5) {
  5559. $html .= '<span class="colGreen">打印</span>';
  5560. } elseif ($value ['status'] == 4) {
  5561. $html .= '<span class="colRed">终止</span>';
  5562. }
  5563. $html .= $value ['operation'] . '</p></blockquote>';
  5564. }
  5565. }
  5566. $html .= '</td>
  5567. <td><span class="colRed">*</span>
  5568. <select name="invoiceNo" id="invoiceNo" style="width:97%">';
  5569. foreach ( $invoicePaperList as $key => $value ) {
  5570. $html .= '<option value="' . $value ['ipidKey'] . '">No.' . $value ['invoiceNo'] . '</option>';
  5571. }
  5572. $html .= '</select>
  5573. <span class="red" id="p-msg"></span>
  5574. </td>
  5575. </tr></tbody></table>';
  5576. }
  5577. $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>
  5578. </div></div></form>
  5579. <link rel=stylesheet href="' . WEB_SITE_GLOBAL . 'css/jquery.validator.css">
  5580. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/jquery.validator.min.js"></script>
  5581. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/zh-CN.js"></script>
  5582. <script src="' . WEB_SITE_GLOBAL . 'js/invoice.validator.js"></script>
  5583. ';
  5584. }
  5585. echo json_encode ( array (
  5586. 'status' => 1,
  5587. 'html' => $html
  5588. ) );
  5589. die ();
  5590. }
  5591. /**
  5592. * @ 获得与我有关收款数据 --需求变更 废弃 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 ) ); }
  5593. */
  5594. function ajaxGetInvoiceInfoByType() {
  5595. $type = $this->get_args ( 'type' ) ? $this->get_args ( 'type' ) : "";
  5596. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5597. $loss = $this->get_args ( 'loss' ) ? $this->get_args ( 'loss' ) : false;
  5598. if (empty ( $serial )) {
  5599. echo json_encode ( array (
  5600. 'status' => 2,
  5601. 'msg' => 'illegal request'
  5602. ) );
  5603. die ();
  5604. }
  5605. if ($type == 'INVOICE') {
  5606. Doo::loadModel ( 'invoice' );
  5607. $invoice = new invoice ();
  5608. Doo::loadModel ( 'invoiceOperationLog' );
  5609. $invoiceOperationLog = new invoiceOperationLog ();
  5610. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5611. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5612. if (empty ( $detail ))
  5613. $html = '';
  5614. else {
  5615. $html = '
  5616. <div class="modal-dialog modal-lg">
  5617. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  5618. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  5619. <tr>
  5620. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5621. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5622. </tr>
  5623. <tr>
  5624. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5625. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5626. </tr>
  5627. <tr>
  5628. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5629. </td>
  5630. </tr>
  5631. <tr>
  5632. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5633. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5634. </tr>
  5635. <tr>
  5636. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5637. </tr>';
  5638. if ($detail ['settlementType'] == 1)
  5639. $html .= '<tr>
  5640. <th class="taC" width="150">结算方式</th><td colspan="3">培训班(<a href="/invoiceTrainingDetail/' . $detail ['invoiceTraining'] ['trainingKey'] . '.html" target="_blank">' . $detail ['invoiceTraining'] ['trainName'] . '</a>)</td>
  5641. </tr>';
  5642. else
  5643. $html .= '<tr>
  5644. <th class="taC" width="150">结算方式</th><td colspan="3">软件销售</td>
  5645. </tr>';
  5646. $html .= ' </tbody></table>';
  5647. if ($detail ['invoiceType'] == 0)
  5648. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5649. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5650. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5651. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5652. </tr>';
  5653. else
  5654. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5655. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5656. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5657. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5658. ';
  5659. $html .= '<tr>
  5660. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5661. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5662. </tr>
  5663. <tr>
  5664. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5665. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5666. </tr></tbody></table>';
  5667. if ($detail ['doPost'] == 1) {
  5668. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5669. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5670. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5671. </tr><tr>
  5672. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5673. </tr><tr>
  5674. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5675. </tr>
  5676. ';
  5677. if ($detail ['expressCom'] == 'SF')
  5678. $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>';
  5679. else
  5680. $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>';
  5681. $html .= '</tbody></table>';
  5682. }
  5683. if (! empty ( $invoiceOperationLogList )) {
  5684. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  5685. foreach ( $invoiceOperationLogList as $key => $value ) {
  5686. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5687. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5688. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5689. if ($value ['status'] == 2) {
  5690. $html .= '<span class="colGreen">同意</span>';
  5691. } elseif ($value ['status'] == 3) {
  5692. $html .= '<span class="colOrange">退回</span>';
  5693. } elseif ($value ['status'] == 5) {
  5694. $html .= '<span class="colGreen">打印</span>';
  5695. } elseif ($value ['status'] == 4) {
  5696. $html .= '<span class="colRed">终止</span>';
  5697. }
  5698. $html .= $value ['operation'] . '</p></blockquote>';
  5699. }
  5700. }
  5701. $html .= '</td></tr></tbody></table>';
  5702. }
  5703. $html .= '</div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  5704. }
  5705. echo json_encode ( array (
  5706. 'status' => 1,
  5707. 'html' => $html
  5708. ) );
  5709. die ();
  5710. } elseif ($type == 'RECEIVABLES') {
  5711. Doo::loadModel ( 'invoiceReceivables' );
  5712. $invoiceReceivables = new invoiceReceivables ();
  5713. Doo::loadModel ( 'invoiceRefund' );
  5714. $invoiceRefund = new invoiceRefund ();
  5715. $detail = $invoiceReceivables->getInvoiceReceivablesByIrsid ( $serial );
  5716. $ireList = $invoiceRefund->getInvoiceRefundIrid ( $detail ['irid'] );
  5717. if (empty ( $detail ))
  5718. $html = '';
  5719. else {
  5720. $html = '<div class="modal-dialog modal-lg"><div class="modal-content"><div class="modal-header"><h3>收款单详情</h3></div><div class="modal-body saeaList">
  5721. <table class="table table-bordered table-condensed">
  5722. <tbody><tr>
  5723. <th class="taC">收款流水号</th><td>' . $detail ['receivablesSerial'] . '</td>
  5724. <th class="taC">录入收款</th><td>' . $detail ['inputStaff'] . ' ' . $detail ['date'] . '</td>
  5725. </tr><tr>
  5726. <th class="taC">收款金额</th><td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  5727. <th class="taC">收款信息</th><td>' . $detail ['receivablesMessage'] . '</td>
  5728. </tr>
  5729. <tr>
  5730. <th class="taC">收款银行</th><td>' . $detail ['receivablesBank'] . '</td>
  5731. <th class="taC">银行到账</th><td>' . $detail ['receivablesDate'] . '</td>
  5732. </tr>
  5733. <tr>
  5734. <th class="taC">认领收款</th><td colspan="3">' . $detail ['inputStaff'] . ' 转入 ' . $detail ['username'] . ' ' . $detail ['confirmTime'] . '</td>
  5735. </tr>
  5736. </tbody></table>';
  5737. if (! empty ( $ireList )) {
  5738. $html .= '
  5739. <table class="table table-bordered table-condensed"><tbody><tr><th class="taC" colspan="5">退款记录</th></tr>
  5740. <tr>
  5741. <th class="taC">退款单位名称</th>
  5742. <th class="taC">退款的账号</th>
  5743. <th class="taC">退款金额</th>
  5744. <th class="taC">退款</th>
  5745. <th class="taC">备注</th>
  5746. </tr>
  5747. ';
  5748. foreach ( $ireList as $key => $value ) {
  5749. $refundLogList = explode ( "<br/>", $value ['refundLog'] );
  5750. $html .= '<tr>
  5751. <td>' . $value ['refundCompany'] . '</td>
  5752. <td>' . $value ['refundNumber'] . '</td>
  5753. <td><b class="colRed">¥' . $value ['refundPrice'] . '</b></td>
  5754. <td>' . $refundLogList [0] . $refundLogList [2] . '</td>
  5755. <td>' . $value ['refundRemarks'] . '</td>
  5756. </tr>
  5757. ';
  5758. }
  5759. }
  5760. $html .= '</tbody></table></div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  5761. }
  5762. echo json_encode ( array (
  5763. 'status' => 1,
  5764. 'html' => $html
  5765. ) );
  5766. die ();
  5767. } elseif ($type == 'IRTC') {
  5768. Doo::loadModel ( 'invoice' );
  5769. $invoice = new invoice ();
  5770. Doo::loadModel ( 'invoiceOperationLog' );
  5771. $invoiceOperationLog = new invoiceOperationLog ();
  5772. Doo::loadModel ( 'invoiceReceivables' );
  5773. $invoiceReceivables = new invoiceReceivables ();
  5774. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5775. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5776. if (empty ( $detail ))
  5777. $html = '';
  5778. else {
  5779. $receivablesPriceedHtml = '';
  5780. $receivablesPrice = $detail ['invoicePrice'];
  5781. if (! empty ( $detail ['irid'] )) {
  5782. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $detail ['irid'] );
  5783. if (empty ( $irList ))
  5784. $irList [0] ['sumPrice'] = 0;
  5785. $balance = $detail ['invoicePrice'] - $irList [0] ['sumPrice'];
  5786. $receivablesPriceedHtml = '<table class="table table-bordered table-condensed"><tbody><tr>
  5787. <th class="taC">已入账金额</th><td><b class="colGreen" style="font-size:18px">¥' . $irList [0] ['sumPrice'] . '</b></td>
  5788. <th class="taC">剩余入账金额</th><td><b class="colRed" style="font-size:18px">¥' . $balance . '</b></td>
  5789. </tr></tbody></table>';
  5790. $receivablesPrice = $balance;
  5791. }
  5792. if ($loss)
  5793. $detail ['invoicePrice'] = - $detail ['invoicePrice'];
  5794. $html = $receivablesPriceedHtml . '
  5795. <table class="table table-bordered table-condensed"><tbody>
  5796. <tr>
  5797. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5798. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5799. </tr>
  5800. <tr>
  5801. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5802. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5803. </tr>
  5804. <tr>
  5805. <th class="taC" width="150">发票备注</th><td colspan="3">' . $detail ['remark'] . '</td>
  5806. </tr>
  5807. <tr>
  5808. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5809. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5810. </tr>
  5811. <tr>
  5812. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5813. </tr></tbody></table>';
  5814. if ($detail ['invoiceType'] == 0) {
  5815. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5816. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5817. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5818. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5819. </tr>';
  5820. $receivablesMessage = $detail ['invoiceTitle'];
  5821. } else {
  5822. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5823. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5824. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5825. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5826. ';
  5827. $receivablesMessage = $detail ['invoiceCompany'];
  5828. }
  5829. $html .= '<tr>
  5830. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5831. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5832. </tr>
  5833. <tr>
  5834. <th class="taC">开户银行</th><td>' . $detail ['bankAccount'] . '</td>
  5835. <th class="taC">银行账号</th><td>' . $detail ['bank'] . '</td>
  5836. </tr></tbody></table>';
  5837. if ($detail ['doPost'] == 1)
  5838. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5839. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5840. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5841. </tr><tr>
  5842. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5843. </tr><tr>
  5844. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5845. </tr></tbody></table>';
  5846. if (! empty ( $invoiceOperationLogList )) {
  5847. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  5848. foreach ( $invoiceOperationLogList as $key => $value ) {
  5849. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5850. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5851. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5852. if ($value ['status'] == 2) {
  5853. $html .= '<span class="colGreen">同意</span>';
  5854. } elseif ($value ['status'] == 3) {
  5855. $html .= '<span class="colOrange">退回</span>';
  5856. } elseif ($value ['status'] == 5) {
  5857. $html .= '<span class="colGreen">打印</span>';
  5858. }
  5859. $html .= $value ['operation'] . '</p></blockquote>';
  5860. }
  5861. }
  5862. $html .= '</td></tr></tbody></table>';
  5863. }
  5864. }
  5865. echo json_encode ( array (
  5866. 'status' => 1,
  5867. 'html' => $html,
  5868. 'receivablesPrice' => $receivablesPrice,
  5869. 'receivablesMessage' => $receivablesMessage,
  5870. 'receivablesDate' => date ( "Y-m-d" ),
  5871. 'iidKey' => $serial
  5872. ) );
  5873. die ();
  5874. }
  5875. }
  5876. function ajaxGetInvoiceReceivablesByStaff() {
  5877. $postData = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : "";
  5878. if (empty ( $postData )) {
  5879. echo json_encode ( array (
  5880. 'status' => 2,
  5881. 'msg' => 'illegal request'
  5882. ) );
  5883. die ();
  5884. }
  5885. Doo::loadModel ( 'invoiceReceivables' );
  5886. $invoiceReceivables = new invoiceReceivables ();
  5887. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $postData );
  5888. if (empty ( $detail )) {
  5889. echo json_encode ( array (
  5890. 'status' => 2,
  5891. 'msg' => 'illegal request'
  5892. ) );
  5893. die ();
  5894. }
  5895. Doo::loadModel ( 'L_category' );
  5896. $lCategory = new L_category ();
  5897. Doo::loadModel ( 'staff' );
  5898. $staff = new staff ();
  5899. $staffList = $staff->getStaffByCid ( $detail ['cid'] );
  5900. $category = $lCategory->getCategory ();
  5901. $categoryHtml = '<option post-data="PUBLIC" value="PUBLIC" >公共待认领款项</option>';
  5902. $staffHtml = '<option value="PUBLIC">办事处待认领款项</option>';
  5903. foreach ( $category as $key => $value ) {
  5904. $categoryHtml .= '<option post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  5905. if ($value ['cid'] == $detail ['cid'])
  5906. $categoryHtml .= '<option selected post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  5907. }
  5908. foreach ( $staffList as $key => $value ) {
  5909. $staffHtml .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  5910. if ($value ['sid'] == $detail ['sid'])
  5911. $staffHtml .= '<option selected value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  5912. }
  5913. $rbankHtml = '<option value="广发银行珠海分行柠溪支行">广发银行珠海分行柠溪支行</option>';
  5914. echo json_encode ( array (
  5915. 'status' => 1,
  5916. 'categoryHtml' => $categoryHtml,
  5917. 'staffHtml' => $staffHtml,
  5918. 'rbankHtml' => $rbankHtml,
  5919. 'detail' => $detail
  5920. ) );
  5921. }
  5922. function ajaxGetInvoiceReceivablesByIrid() {
  5923. $irid = $this->get_args ( 'irid' ) ? $this->get_args ( 'irid' ) : "";
  5924. if (empty ( $irid )) {
  5925. echo json_encode ( array (
  5926. 'status' => 2,
  5927. 'msg' => 'illegal request'
  5928. ) );
  5929. die ();
  5930. }
  5931. Doo::loadModel ( 'invoiceReceivables' );
  5932. $invoiceReceivables = new invoiceReceivables ();
  5933. Doo::loadModel ( 'invoice' );
  5934. $invoice = new invoice ();
  5935. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid ); // 入账完成 待定 and postStatus=1
  5936. $flag = true;
  5937. $invoiceDetail = $invoice->getInvoiceByTitle ( $detail ['recepitTitleMark'], 'EXACTLY', " and status=2 and printStatus=1 and untreadStatus=0 ", $flag ); //
  5938. $bakDetail = array ();
  5939. if ($flag === false) {
  5940. array_push ( $bakDetail, $invoiceDetail );
  5941. $invoiceDetail = $bakDetail;
  5942. }
  5943. $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>
  5944. <tr>
  5945. <td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  5946. <td>' . $detail ['receivablesMessage'] . '</td>
  5947. <td>' . $detail ['receivablesBank'] . '<br>' . $detail ['receivablesDate'] . '</td>
  5948. <td>' . $detail ['title'] . '-' . $detail ['username'] . '<br>' . $detail ['confirmTime'] . '</td>
  5949. <td>' . $detail ['recepitTitleMark'] . '</td>
  5950. </tr></tbody></table>';
  5951. $isInvoice = false;
  5952. $invoiceHtml = '';
  5953. if (empty ( $invoiceDetail )) {
  5954. $isInvoice = true;
  5955. } else {
  5956. $invoiceHtml = '<table class="table table-bordered table-condensed">
  5957. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody>';
  5958. foreach ( $invoiceDetail as $key => $value ) {
  5959. $invoiceHtml .= '<tr>';
  5960. if (! empty ( $value ['invoiceType'] )) {
  5961. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  5962. } else {
  5963. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  5964. }
  5965. if (! empty ( $value ['invoiceType'] )) {
  5966. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  5967. } else {
  5968. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  5969. }
  5970. $invoiceHtml .= '
  5971. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  5972. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  5973. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir" data-ikey="' . $value ['iidKey'] . '" href="javascript:void(0)">入账</a></td>
  5974. </tr>
  5975. ';
  5976. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  5977. if (empty ( $irList ))
  5978. $irList [0] ['sumPrice'] = 0;
  5979. $balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  5980. $priceString = '';
  5981. if ($balance < $detail ['receivablesPrice']) {
  5982. $priceString = '收款金额超过开票金额,';
  5983. }
  5984. if ($balance > $detail ['receivablesPrice']) {
  5985. $priceString = '收款金额低于开票金额,';
  5986. }
  5987. }
  5988. $invoiceHtml .= '
  5989. <script>
  5990. $(\'a[bind-receivables^="ir"]\').click(function() {
  5991. var data = $(this).attr("data-ikey");
  5992. $("input[name=\'invoiceKey\']").val(data);
  5993. var invoiceKey=data;
  5994. if(invoiceKey==""){
  5995. alert("入账错误,请重新刷新页面");
  5996. return false;
  5997. }
  5998. if(window.confirm("' . $priceString . '确定入账吗?")){
  5999. $("#IBR").submit();
  6000. }else{
  6001. return false;
  6002. }
  6003. });
  6004. </script>
  6005. ';
  6006. $invoiceHtml .= '</tbody></table>';
  6007. }
  6008. echo json_encode ( array (
  6009. 'status' => 1,
  6010. 'irkey' => $detail ['iridEn'],
  6011. 'receivablesHtml' => $receivablesHtml,
  6012. 'isInvoice' => $isInvoice,
  6013. 'invoiceHtml' => $invoiceHtml
  6014. ) );
  6015. }
  6016. function ajaxGetInvoiceReceivablesByTitle() {
  6017. $title = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  6018. if (empty ( $title )) {
  6019. echo json_encode ( array (
  6020. 'status' => 2,
  6021. 'msg' => 'illegal request'
  6022. ) );
  6023. die ();
  6024. }
  6025. Doo::loadModel ( 'invoice' );
  6026. $invoice = new invoice ();
  6027. $invoiceDetail = $invoice->getInvoiceByTitle ( $title, 'FUZZY', " and status=2 and printStatus=1 and untreadStatus=0 and irid='' ", true );
  6028. $invoiceHtml = '';
  6029. if (! empty ( $invoiceDetail )) {
  6030. $invoiceHtml = '<table class="table table-bordered table-condensed">
  6031. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody><tr>';
  6032. foreach ( $invoiceDetail as $key => $value ) {
  6033. if (! empty ( $value ['invoiceType'] )) {
  6034. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  6035. } else {
  6036. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  6037. }
  6038. if (! empty ( $value ['invoiceType'] )) {
  6039. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  6040. } else {
  6041. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  6042. }
  6043. $invoiceHtml .= '
  6044. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  6045. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  6046. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir' . $value ['iidKeyXD'] . '" data-ikey="' . $value ['iidKey'] . '" href="#">入账</a></td>
  6047. </tr>
  6048. ';
  6049. }
  6050. $invoiceHtml .= '</tbody></table>
  6051. <script>
  6052. $(\'a[bind-receivables^="ir"]\').click(function() {
  6053. var data = $(this).attr("data-ikey");
  6054. $("input[name=\'invoiceKey\']").val(data);
  6055. var invoiceKey=$("input[name=\'invoiceKey\']").val();
  6056. if(invoiceKey==""){
  6057. alert("入账错误,请重新刷新页面");
  6058. return false;
  6059. }
  6060. if(window.confirm("确定入账吗?")){
  6061. $("#IBR").submit();
  6062. }else{
  6063. return false;
  6064. }
  6065. });
  6066. </script>
  6067. ';
  6068. }
  6069. echo json_encode ( array (
  6070. 'status' => 1,
  6071. 'invoiceHtml' => $invoiceHtml
  6072. ) );
  6073. }
  6074. function ajaxInvoicePushNotice() {
  6075. Doo::loadModel ( 'invoice' );
  6076. $invoice = new invoice ();
  6077. $approval = $invoice->getOne ( array (
  6078. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  6079. 'desc' => 'iid',
  6080. 'asArray' => true
  6081. ) );
  6082. $isNotice = false;
  6083. if (! empty ( $approval ))
  6084. $isNotice = true;
  6085. $response = array (
  6086. 'error' => 0,
  6087. 'isNotice' => $isNotice
  6088. );
  6089. echo json_encode ( $response );
  6090. exit ();
  6091. }
  6092. public function ajaxCheckInvoiceNoUniqueness() {
  6093. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  6094. Doo::loadModel ( 'invoice' );
  6095. $invoice = new invoice ();
  6096. if (! empty ( $invoiceNo )) {
  6097. Doo::loadModel ( 'invoicePaper' );
  6098. $invoicePaper = new invoicePaper ();
  6099. Doo::loadClass ( 'XDeode' );
  6100. $XDeode = new XDeode ( 5 );
  6101. $ipid = $XDeode->decode ( $invoiceNo );
  6102. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  6103. $info = $invoice->getOne ( array (
  6104. 'where' => "invoiceNo = '" . $paperDetail ['invoiceNo'] . "'",
  6105. 'asArray' => TRUE
  6106. ) );
  6107. if (! empty ( $info )) {
  6108. echo json_encode ( array (
  6109. 'error' => '发票号已存在'
  6110. ) );
  6111. die ();
  6112. } else
  6113. echo json_encode ( array (
  6114. 'ok' => '可以使用!'
  6115. ) );
  6116. die ();
  6117. }
  6118. }
  6119. function ajaxCheckInvoicePrice() {
  6120. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) && is_numeric ( $this->get_args ( 'receivablesPrice' ) ) ? $this->get_args ( 'receivablesPrice' ) : "";
  6121. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  6122. Doo::loadModel ( 'invoice' );
  6123. $invoice = new invoice ();
  6124. Doo::loadModel ( 'invoiceReceivables' );
  6125. $invoiceReceivables = new invoiceReceivables ();
  6126. Doo::loadClass ( 'XDeode' );
  6127. $XDeode = new XDeode ( 5 );
  6128. if (! empty ( $receivablesPrice ) && ! empty ( $iidKey )) {
  6129. $iidKey = $XDeode->decode ( $iidKey );
  6130. $info = $invoice->getInvoiceByIid ( $iidKey );
  6131. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $info ['irid'] );
  6132. if (empty ( $irList ))
  6133. $irList [0] ['sumPrice'] = 0;
  6134. $balance = $info ['invoicePrice'] - $irList [0] ['sumPrice'];
  6135. if ($balance < $receivablesPrice) {
  6136. echo json_encode ( array (
  6137. 'error' => '收款金额超过开票金额。'
  6138. ) );
  6139. die ();
  6140. }
  6141. if ($balance > $receivablesPrice) {
  6142. echo json_encode ( array (
  6143. 'error' => '收款金额低于开票金额。'
  6144. ) );
  6145. die ();
  6146. }
  6147. }
  6148. }
  6149. function ajaxGetInvoiceByNew(){
  6150. Doo::loadModel ( 'invoice' );
  6151. $invoice = new invoice ();
  6152. $detail=$invoice->getInvoiceByNew($this->staff [0] ['sid']);
  6153. echo json_encode ( array (
  6154. 'status' => 1,
  6155. 'detail' => $detail
  6156. ) );
  6157. }
  6158. /**
  6159. * 旧输入导入
  6160. */
  6161. function importInvoice() {
  6162. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  6163. $data ['emsg'] = "";
  6164. if ($emsg != "")
  6165. $data ['emsg'] = "请填写完整的数据";
  6166. $data ['time'] = time ();
  6167. $this->render ( "/admin/invoiceImport", $data );
  6168. }
  6169. function uploadInvoice() {
  6170. // move_uploaded_file($_FILES['Filedata']['tmp_name'], "/upload/".$_FILES['Filedata']['name']);
  6171. if (isset ( $_FILES ['Filedata'] ['name'] )) {
  6172. $file = $_FILES ['Filedata'] ['tmp_name'];
  6173. $error = false;
  6174. if (! is_uploaded_file ( $file )) {
  6175. $error = '400 Bad Request';
  6176. }
  6177. if ($error) {
  6178. header ( 'HTTP/1.0 ' . $error );
  6179. die ( 'Error ' . $error );
  6180. } else {
  6181. include (DOO::conf ()->SITE_PATH . 'protected/plugin/io.han.php');
  6182. $this->IoHandler = new IoHandler ();
  6183. $pics = explode ( '.', $_FILES ['Filedata'] ['name'] );
  6184. // $filedir=$_POST['time'];
  6185. // 调用定义物理路径
  6186. $t = DOO::conf ()->SITE_PATH . "upload/invoice/";
  6187. $this->IoHandler->MakeDir ( $t );
  6188. $filename = $this->_GetFileEXT ( $_FILES ['Filedata'] ['name'] );
  6189. if ($filename != 'xlsx')
  6190. return "";
  6191. // $upload_dir = $t."/".time().rand(10,100).".".$filename;
  6192. $upload_file = iconv ( "UTF-8", "GB2312", $_FILES ["Filedata"] ["name"] );
  6193. $upload_dir = $t . "/" . $upload_file;
  6194. $k = move_uploaded_file ( $file, $upload_dir );
  6195. if ($k) {
  6196. $m = round ( $_FILES ['Filedata'] ['size'] / 1024 / 1024, 2 );
  6197. echo $pics [0] . "." . $filename . "#" . $m . "#" . $_FILES ['Filedata'] ['size'];
  6198. }
  6199. }
  6200. }
  6201. }
  6202. function importInvoiceDo() {
  6203. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  6204. if ($path != "") {
  6205. Doo::loadModel ( 'invoice' );
  6206. Doo::loadModel ( 'staff' );
  6207. $staff = new staff ();
  6208. Doo::loadModel ( 'invoiceStatistics' );
  6209. Doo::loadModel ( 'invoiceOperationLog' );
  6210. echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  6211. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . $path );
  6212. // print_r ( $exlArray );
  6213. // die ();
  6214. // echo json_encode($exlArray);die;
  6215. foreach ( $exlArray as $key => $value ) {
  6216. // 开票
  6217. $invoice = new invoice ();
  6218. $invoice->invoiceNo = $value ['invoiceNo'];
  6219. $invoice->invoiceType = 0;
  6220. if ($value ['invoiceType'] == '专')
  6221. $invoice->invoiceType = 1;
  6222. $invoice->invoicePrice = $value ['invoicePrice'];
  6223. $invoice->invoiceQuantity = 1;
  6224. $invoice->invoiceUnitPrice = $value ['invoicePrice'];
  6225. $invoice->invoiceTitle = $value ['invoiceTitle'];
  6226. if ($value ['invoiceType'] == '专')
  6227. $invoice->invoiceCompany = $value ['invoiceTitle'];
  6228. $invoice->userName = $value ['userName'];
  6229. $sDetail = $staff->getStaffByName ( $value ['userName'] );
  6230. $invoice->sid = $sDetail ['sid'];
  6231. $invoice->cid = $sDetail ['cid'];
  6232. $invoice->categoryName = $sDetail ['category'];
  6233. $invoice->invoiceElement = $value ['invoiceElement'];
  6234. $invoice->remark = $value ['remark'];
  6235. $invoice->date = $value ['date'];
  6236. $invoice->printTime = $value ['date'];
  6237. $invoice->ipSource = 1;
  6238. $invoice->printStatus = 1;
  6239. $invoice->status = 2;
  6240. $invoice->postStatus = 1;
  6241. $invoice->untreadStatus = 0;
  6242. $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  6243. $iid = $invoice->insert ();
  6244. // 汇总
  6245. $invoiceStatistics = new invoiceStatistics ();
  6246. //
  6247. $item = array (
  6248. 'date' => $value ['date'],
  6249. 'priceClass' => 1,
  6250. 'cid' => $sDetail ['cid'],
  6251. 'staff' => $sDetail ['sid'],
  6252. 'invoicePrice' => $value ['invoicePrice']
  6253. );
  6254. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  6255. $invoiceOperationLog = new invoiceOperationLog ();
  6256. $item = array (
  6257. 'date' => date ( "Y-m-d H:i:s" ),
  6258. 'operation' => date ( "Y-m-d" ) . " 导入",
  6259. 'status' => 1,
  6260. 'img' => $sDetail ['avatar'],
  6261. 'username' => $sDetail ['username'],
  6262. 'uid' => $sDetail ['sid'],
  6263. 'category' => $sDetail ['category'],
  6264. 'iid' => $iid
  6265. );
  6266. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  6267. }
  6268. return '/importInvoice?count=' . count ( $exlArray );
  6269. // return "/keyonline";
  6270. }
  6271. echo 'no file';
  6272. }
  6273. function importInvoiceReceivables() {
  6274. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  6275. $data ['emsg'] = "";
  6276. if ($emsg != "")
  6277. $data ['emsg'] = "请填写完整的数据";
  6278. $data ['time'] = time ();
  6279. $this->render ( "/admin/invoiceReceivablesImport", $data );
  6280. }
  6281. // 导入入账数据
  6282. function importInvoiceReceivablesDo() {
  6283. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  6284. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  6285. if ($path != "") {
  6286. Doo::loadModel ( 'invoiceReceivables' );
  6287. Doo::loadModel ( 'invoice' );
  6288. Doo::loadModel ( 'staff' );
  6289. $staff = new staff ();
  6290. Doo::loadModel ( 'invoiceStatistics' );
  6291. // echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  6292. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path ), 'invoiceReceivables' );
  6293. // print_r ( $exlArray );
  6294. // die ();
  6295. // echo json_encode($exlArray);die;
  6296. foreach ( $exlArray as $key => $value ) {
  6297. // 收款
  6298. $invoiceReceivables = new invoiceReceivables ();
  6299. $invoice = new invoice ();
  6300. $invoiceReceivables->bindStatus = 1;
  6301. $invoiceReceivables->receivablesPrice = $value ['receivablesPrice'];
  6302. $invoiceReceivables->receivablesMessage = $value ['receivablesMessage'];
  6303. $invoiceReceivables->receivablesBank = $value ['receivablesBank'];
  6304. $invoiceReceivables->receivablesDate = $value ['receivablesDate'];
  6305. $sDetail = $staff->getStaffByName ( $value ['receivablesStaff'] );
  6306. $invoiceReceivables->receivablesCategory = $sDetail ['cid'] . ':' . $sDetail ['category'];
  6307. $invoiceReceivables->receivablesStaff = $sDetail ['sid'] . '-' . $sDetail ['username'];
  6308. $invoiceReceivables->receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  6309. $invoiceReceivables->sourcePrice = $value ['sourcePrice'];
  6310. $iDetail = $invoice->getInvoiceByInvoiceNo ( $value ['invoiceNo'] );
  6311. $invoiceReceivables->iid = $iDetail ['iid'];
  6312. $irid = $invoiceReceivables->insert ();
  6313. // 发票绑定收款
  6314. $detail = $iDetail;
  6315. $iridString = "";
  6316. if (empty ( $detail ['irid'] ))
  6317. $iridString = $irid;
  6318. else
  6319. $iridString = $detail ['irid'] . ',' . $irid;
  6320. $item = array (
  6321. 'irid' => $iridString,
  6322. 'iid' => $detail ['iid']
  6323. );
  6324. $invoice->setInvoiceByCondition ( $item );
  6325. // 汇总
  6326. $invoiceStatistics = new invoiceStatistics ();
  6327. // 扣除入账统计金额
  6328. $item = array (
  6329. 'date' => $value ['receivablesDate'],
  6330. 'priceClass' => 3,
  6331. 'cid' => $sDetail ['cid'],
  6332. 'staff' => $sDetail ['sid'],
  6333. // 'irid' => $irid,
  6334. 'accountPrice' => $value ['receivablesPrice']
  6335. );
  6336. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  6337. }
  6338. return '/importInvoiceReceivables?count=' . count ( $exlArray );
  6339. echo 'data count ' . count ( $exlArray );
  6340. die ();
  6341. // return "/keyonline";
  6342. }
  6343. echo 'no file';
  6344. }
  6345. function formatExcelToArrayTrain($file_url = "") {
  6346. if (! file_exists ( $file_url )) {
  6347. return array ();
  6348. }
  6349. // Doo::loadClass ( 'PHPExcel' );
  6350. Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  6351. $PHPExcel = new PHPExcel ();
  6352. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  6353. if (! $PHPReader->canRead ( $file_url )) {
  6354. $PHPReader = new PHPExcel_Reader_Excel5 ();
  6355. if (! $PHPReader->canRead ( $file_url )) {
  6356. echo 'no Excel';
  6357. return;
  6358. }
  6359. }
  6360. $PHPExcel = $PHPReader->load ( $file_url );
  6361. /* * 读取excel文件中的第一个工作表 */
  6362. $currentSheet = $PHPExcel->getSheet ( 0 );
  6363. /* * 取得最大的列号 */
  6364. $allColumn = $currentSheet->getHighestColumn ();
  6365. /* * 取得一共有多少行 */
  6366. $allRow = $currentSheet->getHighestRow ();
  6367. $excel_array = array ();
  6368. // die($file_url);
  6369. $conk = 2;
  6370. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  6371. $excel_column = array ();
  6372. // 后期改进
  6373. if ($allColumn == 'AM')
  6374. $allColumn = 'Z';
  6375. /* * 从第A列开始输出 */
  6376. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  6377. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  6378. if ($val instanceof PHPExcel_RichText)
  6379. $val = $val->__toString ();
  6380. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  6381. // $val = "'" . addslashes ( $val ) . "'";
  6382. if ($currentColumn == 'A') {
  6383. $excel_column ['invoiceTitle'] = $val;
  6384. } elseif ($currentColumn == 'B')
  6385. $excel_column ['invoiceType'] = $val;
  6386. elseif ($currentColumn == 'C') {
  6387. $excel_column ['TIN'] = $val;
  6388. } elseif ($currentColumn == 'D') {
  6389. $excel_column ['address'] = $val;
  6390. } elseif ($currentColumn == 'E') {
  6391. $excel_column ['phone'] = $val;
  6392. } elseif ($currentColumn == 'F') {
  6393. $excel_column ['bank'] = $val;
  6394. } elseif ($currentColumn == 'G') {
  6395. $excel_column ['bankAccount'] = $val;
  6396. } elseif ($currentColumn == 'H') {
  6397. $excel_column ['invoiceElement'] = $val;
  6398. } elseif ($currentColumn == 'I') {
  6399. $excel_column ['invoiceQuantity'] = $val;
  6400. } elseif ($currentColumn == 'J') {
  6401. $excel_column ['invoiceUnitPrice'] = $val;
  6402. } elseif ($currentColumn == 'K') {
  6403. $excel_column ['remark'] = $val;
  6404. } elseif ($currentColumn == 'L') {
  6405. $excel_column ['recipientsAddress'] = $val;
  6406. } elseif ($currentColumn == 'M') {
  6407. $excel_column ['recipients'] = $val;
  6408. } elseif ($currentColumn == 'N') {
  6409. $excel_column ['recipientsPhone'] = $val;
  6410. }
  6411. }
  6412. if (! empty ( $excel_column ['invoiceTitle'] ) && ! empty ( $excel_column ['invoiceQuantity'] ) && ! empty ( $excel_column ['invoiceUnitPrice'] ))
  6413. array_push ( $excel_array, $excel_column );
  6414. }
  6415. return $excel_array;
  6416. }
  6417. /**
  6418. * 格式化excel文件为数组
  6419. * @param unknown_type $file_url
  6420. * @param unknown_type $mcid
  6421. */
  6422. function _format_excel_to_array($file_url = "", $sType = "") {
  6423. if (! file_exists ( $file_url )) {
  6424. return array ();
  6425. }
  6426. Doo::loadClass ( 'PHPExcel' );
  6427. // Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  6428. $PHPExcel = new PHPExcel ();
  6429. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  6430. if (! $PHPReader->canRead ( $file_url )) {
  6431. $PHPReader = new PHPExcel_Reader_Excel5 ();
  6432. if (! $PHPReader->canRead ( $file_url )) {
  6433. echo 'no Excel';
  6434. return;
  6435. }
  6436. }
  6437. $PHPExcel = $PHPReader->load ( $file_url );
  6438. /* * 读取excel文件中的第一个工作表 */
  6439. $currentSheet = $PHPExcel->getSheet ( 0 );
  6440. /* * 取得最大的列号 */
  6441. $allColumn = $currentSheet->getHighestColumn ();
  6442. /* * 取得一共有多少行 */
  6443. $allRow = $currentSheet->getHighestRow ();
  6444. $excel_array = array ();
  6445. // die($file_url);
  6446. $conk = 2;
  6447. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  6448. $excel_column = array ();
  6449. // 后期改进
  6450. if ($allColumn == 'AM')
  6451. $allColumn = 'Z';
  6452. /* * 从第A列开始输出 */
  6453. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  6454. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  6455. if ($val instanceof PHPExcel_RichText)
  6456. $val = $val->__toString ();
  6457. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  6458. // $val = "'" . addslashes ( $val ) . "'";
  6459. if ($sType == 'invoiceReceivables') {
  6460. if ($currentColumn == 'A')
  6461. $excel_column ['invoiceNo'] = $val;
  6462. elseif ($currentColumn == 'B')
  6463. $excel_column ['receivablesPrice'] = $val;
  6464. elseif ($currentColumn == 'C') {
  6465. $excel_column ['receivablesMessage'] = $val;
  6466. } elseif ($currentColumn == 'D') {
  6467. $excel_column ['receivablesBank'] = $val;
  6468. } elseif ($currentColumn == 'E') {
  6469. $excel_column ['receivablesDate'] = $this->excelTime ( $val );
  6470. } elseif ($currentColumn == 'F') {
  6471. $excel_column ['receivablesStaff'] = $val;
  6472. } elseif ($currentColumn == 'G') {
  6473. $excel_column ['sourcePrice'] = $val;
  6474. }
  6475. } elseif ($sType == "invoiceTrain") {
  6476. if ($currentColumn == 'A') {
  6477. $excel_column ['invoiceTitle'] = $val;
  6478. } elseif ($currentColumn == 'B')
  6479. $excel_column ['invoiceType'] = $val;
  6480. elseif ($currentColumn == 'C') {
  6481. $excel_column ['TIN'] = $val;
  6482. } elseif ($currentColumn == 'D') {
  6483. $excel_column ['address'] = $val;
  6484. } elseif ($currentColumn == 'E') {
  6485. $excel_column ['phone'] = $val;
  6486. } elseif ($currentColumn == 'F') {
  6487. $excel_column ['bank'] = $val;
  6488. } elseif ($currentColumn == 'G') {
  6489. $excel_column ['bankAccount'] = $val;
  6490. } elseif ($currentColumn == 'H') {
  6491. $excel_column ['invoiceElement'] = $val;
  6492. } elseif ($currentColumn == 'I') {
  6493. $excel_column ['invoiceQuantity'] = $val;
  6494. } elseif ($currentColumn == 'J') {
  6495. $excel_column ['invoiceUnitPrice'] = $val;
  6496. } elseif ($currentColumn == 'K') {
  6497. $excel_column ['remark'] = $val;
  6498. } elseif ($currentColumn == 'L') {
  6499. $excel_column ['recipientsAddress'] = $val;
  6500. } elseif ($currentColumn == 'M') {
  6501. $excel_column ['recipients'] = $val;
  6502. } elseif ($currentColumn == 'N') {
  6503. $excel_column ['recipientsPhone'] = $val;
  6504. }
  6505. } else {
  6506. if ($currentColumn == 'A')
  6507. $excel_column ['invoiceNo'] = $val;
  6508. elseif ($currentColumn == 'B')
  6509. $excel_column ['invoiceType'] = $val;
  6510. elseif ($currentColumn == 'C') {
  6511. $excel_column ['invoicePrice'] = $val;
  6512. } elseif ($currentColumn == 'D') {
  6513. $excel_column ['invoiceTitle'] = $val;
  6514. } elseif ($currentColumn == 'E') {
  6515. $excel_column ['userName'] = $val;
  6516. } elseif ($currentColumn == 'F') {
  6517. $excel_column ['categoryName'] = $val;
  6518. } elseif ($currentColumn == 'G') {
  6519. $excel_column ['invoiceElement'] = $val;
  6520. } elseif ($currentColumn == 'H') {
  6521. $excel_column ['remark'] = $val;
  6522. } elseif ($currentColumn == 'I') {
  6523. $excel_column ['date'] = $this->excelTime ( $val );
  6524. }
  6525. }
  6526. }
  6527. array_push ( $excel_array, $excel_column );
  6528. }
  6529. return $excel_array;
  6530. }
  6531. function excelTime($date, $time = false) {
  6532. if (function_exists ( 'GregorianToJD' )) {
  6533. if (is_numeric ( $date )) {
  6534. $jd = GregorianToJD ( 1, 1, 1970 );
  6535. $gregorian = JDToGregorian ( $jd + intval ( $date ) - 25569 );
  6536. $date = explode ( '/', $gregorian );
  6537. $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" : '');
  6538. return $date_str;
  6539. }
  6540. } else {
  6541. $date = $date > 25568 ? $date + 1 : 25569;
  6542. /* There was a bug if Converting date before 1-1-1970 (tstamp 0) */
  6543. $ofs = (70 * 365 + 17 + 2) * 86400;
  6544. $date = date ( "Y-m-d", ($date * 86400) - $ofs ) . ($time ? " 00:00:00" : '');
  6545. }
  6546. return $date;
  6547. }
  6548. /**
  6549. * 旧输入导入
  6550. */
  6551. function _GetFileEXT($filename) {
  6552. $pics = explode ( '.', $filename );
  6553. $num = count ( $pics );
  6554. return $pics [$num - 1];
  6555. }
  6556. function showCache($path = "", $sid = 0) {
  6557. // if (file_exists ( $path )) {
  6558. // $htm = file_get_contents ( $path );
  6559. // } else {
  6560. Doo::loadModel ( 'invoiceStatistics' );
  6561. $invoiceStatistics = new invoiceStatistics ();
  6562. $isBriefly = $invoiceStatistics->getBrieflyStatistics ( $sid );
  6563. $htm = '<tr><th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计开票</th>
  6564. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['invoicePrice'] . '</td>
  6565. <th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计入账</th>
  6566. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['accountPrice'] . '</td></tr>';
  6567. /*
  6568. * '<tr><th class="taC">今年累计开票</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['invoicePrice'] . '</td> <th class="taC">今年累计入账</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['accountPrice'] . '</td></tr>';
  6569. */
  6570. file_put_contents ( $path, $htm );
  6571. // }
  6572. return $htm;
  6573. }
  6574. /**
  6575. * 获取get或者POST值
  6576. *
  6577. * @param string $name 属性名称
  6578. * @return fixed 值
  6579. */
  6580. function get_args($name) {
  6581. if (isset ( $_GET [$name] )) {
  6582. if (is_array ( $_GET [$name] ))
  6583. return $_GET [$name];
  6584. else
  6585. return addslashes ( $_GET [$name] );
  6586. } elseif (isset ( $_POST [$name] )) {
  6587. if (is_array ( $_POST [$name] ))
  6588. return $_POST [$name];
  6589. else
  6590. return addslashes ( $_POST [$name] );
  6591. } else
  6592. return false;
  6593. }
  6594. function SafeFilter(&$arr) {
  6595. $ra = Array (
  6596. '/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/',
  6597. '/script/',
  6598. '/javascript/',
  6599. '/vbscript/',
  6600. '/expression/',
  6601. '/applet/',
  6602. '/meta/',
  6603. '/xml/',
  6604. '/blink/',
  6605. '/link/',
  6606. '/style/',
  6607. '/embed/',
  6608. '/object/',
  6609. '/frame/',
  6610. '/layer/',
  6611. '/title/',
  6612. '/bgsound/',
  6613. '/base/',
  6614. '/onload/',
  6615. '/onunload/',
  6616. '/onchange/',
  6617. '/onsubmit/',
  6618. '/onreset/',
  6619. '/onselect/',
  6620. '/onblur/',
  6621. '/onfocus/',
  6622. '/onabort/',
  6623. '/onkeydown/',
  6624. '/onkeypress/',
  6625. '/onkeyup/',
  6626. '/onclick/',
  6627. '/ondblclick/',
  6628. '/onmousedown/',
  6629. '/onmousemove/',
  6630. '/onmouseout/',
  6631. '/onmouseover/',
  6632. '/onmouseup/',
  6633. '/onunload/'
  6634. );
  6635. if (is_array ( $arr )) {
  6636. foreach ( $arr as $key => $value ) {
  6637. if (! is_array ( $value )) {
  6638. if (! get_magic_quotes_gpc ()) // 不对magic_quotes_gpc转义过的字符使用addslashes(),避免双重转义。
  6639. {
  6640. $value = addslashes ( $value ); // 给单引号(')、双引号(")、反斜线(\)与 NUL(NULL 字符)加上反斜线转义
  6641. }
  6642. $value = preg_replace ( $ra, '', $value ); // 删除非打印字符,粗暴式过滤xss可疑字符串
  6643. $arr [$key] = htmlentities ( strip_tags ( $value ) ); // 去除 HTML 和 PHP 标记并转换为 HTML 实体
  6644. } else {
  6645. SafeFilter ( $arr [$key] );
  6646. }
  6647. }
  6648. }
  6649. }
  6650. /**
  6651. * Escape String
  6652. *
  6653. * @access public
  6654. * @param string
  6655. * @param bool whether or not the string will be used in a LIKE condition
  6656. * @return string
  6657. */
  6658. function escape_str($str, $like = FALSE) {
  6659. if (is_array ( $str )) {
  6660. foreach ( $str as $key => $val ) {
  6661. $str [$key] = $this->escape_str ( $val, $like );
  6662. }
  6663. return $str;
  6664. }
  6665. var_dump ( Doo::db ()->getDbObject () );
  6666. die ();
  6667. if (function_exists ( 'mysql_real_escape_string' ) and is_resource ( Doo::db ()->getDbObject () )) { // Doo::db ()->getDbObject()
  6668. $str = mysql_real_escape_string ( $str, Doo::db ()->getDbObject () );
  6669. } elseif (function_exists ( 'mysql_escape_string' )) {
  6670. $str = mysql_escape_string ( $str );
  6671. } else {
  6672. $str = addslashes ( $str );
  6673. }
  6674. // escape LIKE condition wildcards
  6675. if ($like === TRUE) {
  6676. $str = str_replace ( array (
  6677. '%',
  6678. '_'
  6679. ), array (
  6680. '\\%',
  6681. '\\_'
  6682. ), $str );
  6683. }
  6684. return $str;
  6685. }
  6686. /**
  6687. * 获得分页数据
  6688. * @param unknown_type $table
  6689. * @param unknown_type $condition
  6690. * @param unknown_type $on_page
  6691. * @param unknown_type $page_size
  6692. */
  6693. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  6694. $page_c = "";
  6695. $page ['previous'] = $this->get_previous ( $on_page );
  6696. $page ['on_page'] = $on_page;
  6697. $total_count = $this->get_table_count ( $table, $condition );
  6698. $total = intval ( $total_count / $page_size );
  6699. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  6700. $page ['total_data'] = $total_count;
  6701. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  6702. $i = 1;
  6703. $page_max = 1;
  6704. $page_width = 3;
  6705. if ($on_page >= $page_width) {
  6706. $page_max = intval ( $on_page / $page_width ) + 1;
  6707. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  6708. }
  6709. for(; $i <= $page ['total_page']; $i ++) {
  6710. if ($i == $on_page)
  6711. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  6712. else
  6713. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  6714. if ($i == ($page_width * $page_max))
  6715. break;
  6716. }
  6717. $page ['page'] = $page_c;
  6718. $page ['lower'] = (-- $on_page) * $page_size;
  6719. return $page;
  6720. }
  6721. /**
  6722. * 获取上一页
  6723. * @param unknown_type $on_page
  6724. */
  6725. function get_previous($on_page = 1) {
  6726. return $on_page != 0 ? $on_page - 1 : $on_page;
  6727. }
  6728. /**
  6729. * 获取总页数
  6730. * @param unknown_type $table
  6731. * @param unknown_type $condition
  6732. */
  6733. public function get_table_count($table = "", $condition = "") {
  6734. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  6735. $sql = "select count(*) as count from " . $table . " where " . $condition;
  6736. // echo $sql;die;
  6737. $query = Doo::db ()->query ( $sql );
  6738. $result = $query->fetch ();
  6739. return $result ['count'];
  6740. }
  6741. /**
  6742. * 获得分页数据
  6743. * @param unknown_type $table
  6744. * @param unknown_type $condition
  6745. * @param unknown_type $on_page
  6746. * @param unknown_type $page_size
  6747. */
  6748. function getPageBySql($sql = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  6749. $page_c = "";
  6750. $page ['previous'] = $this->get_previous ( $on_page );
  6751. $page ['on_page'] = $on_page;
  6752. $total_count = $this->getTableCountBySql ( $sql );
  6753. $total = intval ( $total_count / $page_size );
  6754. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  6755. $page ['total_data'] = $total_count;
  6756. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  6757. $i = 1;
  6758. $page_max = 1;
  6759. $page_width = 3;
  6760. if ($on_page >= $page_width) {
  6761. $page_max = intval ( $on_page / $page_width ) + 1;
  6762. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  6763. }
  6764. for(; $i <= $page ['total_page']; $i ++) {
  6765. if ($i == $on_page)
  6766. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  6767. else
  6768. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  6769. if ($i == ($page_width * $page_max))
  6770. break;
  6771. }
  6772. $page ['page'] = $page_c;
  6773. $page ['lower'] = (-- $on_page) * $page_size;
  6774. return $page;
  6775. }
  6776. /**
  6777. * 获得总页数 sql
  6778. * @param string $type
  6779. * @return boolean[]
  6780. */
  6781. public function getTableCountBySql($sql = "") {
  6782. $query = Doo::db ()->query ( $sql );
  6783. $result = $query->fetchAll ();
  6784. return count ( $result );
  6785. }
  6786. function isInvoiceNew($type = "GLOBAL") {
  6787. Doo::loadModel ( 'invoice' );
  6788. $invoice = new invoice ();
  6789. Doo::loadModel ( 'invoiceReceivables' );
  6790. $invoiceReceivables = new invoiceReceivables ();
  6791. Doo::loadModel ( 'staff' );
  6792. $staff = new staff ();
  6793. $st = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  6794. // 我的发票待处理
  6795. $pendingInvoice = $invoice->getOne ( array ( // or (status=2 and printStatus=1 and untreadStatus=0 ) or (status=2 and printStatus=1 and untreadStatus=2 )
  6796. 'where' => "(status=3 or status=4) and isDelete=0 and sid=" . $st [0] ['sid'],
  6797. 'desc' => 'iid',
  6798. 'asArray' => TRUE
  6799. ) );
  6800. // 我的收款待入账
  6801. /*
  6802. * $myClaim = $invoiceReceivables->getOne ( array ( 'where' => " receivablesStaff like '" . $st [0] ['sid'] . "-%' and receivablesCategory like '" . $st [0] ['cid'] . ":%' and bindStatus=0", 'desc' => 'irid', 'asArray' => TRUE ) );
  6803. */
  6804. // 发票审批
  6805. $approval = $invoice->getOne ( array (
  6806. 'where' => 'status=1 and pendingApprovals=' . $st [0] ['sid'],
  6807. 'desc' => 'iid',
  6808. 'asArray' => true
  6809. ) );
  6810. // 发票邮寄
  6811. $post = $invoice->getOne ( array (
  6812. 'where' => "postStatus=0 and printStatus=1 and isDelete=0 and doPost=1 and status=2",
  6813. 'asArray' => TRUE
  6814. ) );
  6815. // 发票打印
  6816. $print = $invoice->getOne ( array (
  6817. 'where' => "status=2 and printStatus=0 and untreadStatus=0 and moldManage like '%[\"" . $st [0] ['sid'] . "\",%'",
  6818. 'desc' => 'iid',
  6819. 'asArray' => TRUE
  6820. ) );
  6821. // 发票退票 printStatus=1 and
  6822. $untread = $invoice->getOne ( array (
  6823. 'where' => " untreadStatus=1 and status=2 ",
  6824. 'asArray' => TRUE
  6825. ) );
  6826. $new = array (
  6827. 'GLOBAL' => FALSE,
  6828. 'pendingInvoice' => FALSE,
  6829. // 'myClaim' => FALSE,
  6830. 'approval' => FALSE,
  6831. 'post' => FALSE,
  6832. 'print' => FALSE,
  6833. 'untread' => FALSE
  6834. );
  6835. // || ! empty ( $myClaim )
  6836. if (! empty ( $pendingInvoice ) || ! empty ( $approval ) || ! empty ( $post ) || ! empty ( $print ) || ! empty ( $untread ))
  6837. $new ['GLOBAL'] = TRUE;
  6838. if (! empty ( $pendingInvoice ))
  6839. $new ['pendingInvoice'] = TRUE;
  6840. // if (! empty ( $myClaim ))
  6841. // $new ['myClaim'] = TRUE;
  6842. if (! empty ( $approval ))
  6843. $new ['approval'] = TRUE;
  6844. if (! empty ( $post ))
  6845. $new ['post'] = TRUE;
  6846. if (! empty ( $print ))
  6847. $new ['print'] = TRUE;
  6848. if (! empty ( $untread ))
  6849. $new ['untread'] = TRUE;
  6850. return $new;
  6851. }
  6852. function setWXMsg($rid, $typeMsg = '') {
  6853. Doo::loadModel ( 'invoice' );
  6854. $invoice = new invoice ();
  6855. $invoiceDetail = $invoice->getOne ( array (
  6856. 'where' => 'iid=' . $rid,
  6857. 'asArray' => true
  6858. ) );
  6859. if (! empty ( $invoiceDetail )) {
  6860. Doo::loadModel ( 'staff' );
  6861. $staff = new staff ();
  6862. $staffmsg = $staff->getOne ( array (
  6863. 'where' => "sid='" . $invoiceDetail ['sid'] . "'",
  6864. 'asArray' => TRUE
  6865. ) );
  6866. if (! empty ( $staffmsg ['wxid'] )) {
  6867. require_once (SITE_PATH . '/protected/class/client.php');
  6868. $client = new client ( 'http://m.cld.smartcost.com.cn/' );
  6869. $user = $staffmsg ['wxid'];
  6870. $expCom = explode ( ":", $invoiceDetail ['expressCompany'] );
  6871. if (empty ( $expCom ))
  6872. $expCom [0] = '';
  6873. $msg = "";
  6874. if (empty ( $typeMsg ))
  6875. $msg = '太好了,您的发票' . $invoiceDetail ['invoiceSerial'] . ' 已邮寄 ' . $expCom [0] . ' ,快递号: <a href="https://m.kuaidi100.com/result.jsp?nu=' . $invoiceDetail ['expressNumber'] . '" >' . $invoiceDetail ['expressNumber'] . '</a>';
  6876. elseif ($typeMsg == "PRINT")
  6877. $msg = '太好了,您的发票已打印完成。';
  6878. $result = $client->SendMsg ( $user, $msg, 'text' );
  6879. }
  6880. }
  6881. }
  6882. /**
  6883. * 获取微信部门
  6884. * @param string $category
  6885. * @return number|mixed
  6886. */
  6887. function getToparty($category = '') {
  6888. $token = $this->getAccessToken (); //
  6889. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token={$token}&id=5" ), true );
  6890. $toparty = 0;
  6891. foreach ( $result ['department'] as $key => $value ) {
  6892. if ($value ['name'] == $category)
  6893. $toparty = $value ['id'];
  6894. }
  6895. return $toparty;
  6896. }
  6897. /**
  6898. * 获得某部门下的用户
  6899. * @param string $toparty
  6900. */
  6901. function getUserByToparty($toparty = '') {
  6902. $token = $this->getAccessToken (); //
  6903. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token={$token}&department_id={$toparty}" ), true );
  6904. $userList = array ();
  6905. foreach ( $result ['userlist'] as $key => $value ) {
  6906. array_push ( $userList, "'" . $value ['userid'] . "'" );
  6907. }
  6908. return $userList;
  6909. }
  6910. function msgSendToparty($msg, $title, $url, $toparty, $text = '') {
  6911. $token = $this->getAccessToken ();
  6912. if ($text == 'text') {
  6913. $data = '{
  6914. "touser": "' . $toparty . '",
  6915. "toparty": "",
  6916. "totag": "",
  6917. "msgtype": "text",
  6918. "agentid": 1000002,
  6919. "text": {
  6920. "content": "' . $msg . '"
  6921. },
  6922. "safe":0
  6923. }';
  6924. }
  6925. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  6926. if ($result->errmsg != 'ok') {
  6927. return 0;
  6928. } else {
  6929. return 1;
  6930. }
  6931. }
  6932. /**
  6933. * 获得可以发送微信用户列表
  6934. * @param string $category
  6935. * @return string
  6936. */
  6937. function getWxidByCategory($category = "") {
  6938. if (empty ( $category ))
  6939. return "";
  6940. Doo::loadModel ( 'staff' );
  6941. $staff = new staff ();
  6942. $toparty = $this->getToparty ( $category );
  6943. $wxList = array ();
  6944. $wxString = "";
  6945. if (! empty ( $toparty )) {
  6946. $userList = $this->getUserByToparty ( $toparty );
  6947. $userCon = implode ( ',', $userList );
  6948. // echo $userCon;
  6949. $sidList = $staff->getStaffByWxid ( $userCon );
  6950. foreach ( $sidList as $key => $value ) {
  6951. $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  6952. if ($falg) {
  6953. array_push ( $wxList, $value ['wxid'] );
  6954. }
  6955. }
  6956. $wxString = implode ( '|', $wxList );
  6957. }
  6958. return $wxString;
  6959. }
  6960. /**
  6961. * 读取发送信息规则判断是否需要发送
  6962. * @param number $sid
  6963. * @param string $sendType
  6964. * @return boolean
  6965. */
  6966. function isSendNotification($sid = 0, $sendType = '') {
  6967. Doo::loadModel ( "notificationConf" );
  6968. $notificationConf = new notificationConf ();
  6969. $detail = $notificationConf->getNotificationConfBySid ( $sid );
  6970. $conf = array ();
  6971. $sendFlag = true;
  6972. if (! empty ( $detail )) {
  6973. $conf = json_decode ( $detail ['conf'], true );
  6974. if (! empty ( $sendType )) {
  6975. if (isset ( $conf [$sendType] )) {
  6976. if ($conf [$sendType] == "CLOSE")
  6977. $sendFlag = false;
  6978. elseif ($conf [$sendType] == "Weekend") {
  6979. $day = date ( "w" );
  6980. if (1 <= $day && 5 >= $day)
  6981. $sendFlag = false;
  6982. } elseif ($conf [$sendType] == "OneToFriday") {
  6983. $day = date ( "w" );
  6984. if (0 == $day || 6 == $day)
  6985. $sendFlag = false;
  6986. }
  6987. }
  6988. } else
  6989. $sendFlag = false;
  6990. }
  6991. return $sendFlag;
  6992. }
  6993. /**
  6994. * 根据规则发送信息
  6995. * @param unknown $msg
  6996. * @param unknown $title
  6997. * @param unknown $url
  6998. * @param unknown $user
  6999. * @param string $text
  7000. * @return number
  7001. */
  7002. private function msgSend($msg, $title, $url, $user, $sid = 0, $sendType = '') {
  7003. $token = $this->getAccessToken ();
  7004. $falg = $this->isSendNotification ( $sid, $sendType );
  7005. // if ($text == 'text') {
  7006. // $data = '{
  7007. // "touser": "' . $user . '",
  7008. // "toparty": "",
  7009. // "totag": "",
  7010. // "msgtype": "text",
  7011. // "agentid": 1000002,
  7012. // "text": {
  7013. // "content": "' . $msg . '"
  7014. // },
  7015. // "safe":0
  7016. // }';
  7017. // } else {
  7018. $data = '{
  7019. "touser": "' . $user . '",
  7020. "toparty": "",
  7021. "totag": "",
  7022. "msgtype": "news",
  7023. "agentid": 1000002,
  7024. "news": {
  7025. "articles":[
  7026. {
  7027. "title": "' . $title . '",
  7028. "description": "' . $msg . '",
  7029. "url": "' . $url . '",
  7030. "picurl": ""
  7031. }
  7032. ]
  7033. }
  7034. }';
  7035. // }
  7036. if ($falg) {
  7037. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  7038. if ($result->errmsg != 'ok') {
  7039. return 0;
  7040. } else {
  7041. return 1;
  7042. }
  7043. } else
  7044. return 0;
  7045. }
  7046. private function getAccessToken() {
  7047. // access_token 应该全局存储与更新,以下代码以写入到文件中做示例
  7048. // $file = './access_token.txt';
  7049. // $data = json_decode ( file_get_contents ( $file ) );
  7050. // if ($data->expire_time < time () or ! $data->expire_time) {
  7051. // 如果是企业号用以下URL获取access_token
  7052. $url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$this->appId&corpsecret=$this->appSecret";
  7053. // $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$this->appId&secret=$this->appSecret";
  7054. $res = json_decode ( $this->httpGet ( $url ) );
  7055. $access_token = $res->access_token;
  7056. // echo $access_token;
  7057. // if ($access_token) {
  7058. // $data->expire_time = time () + 7000;
  7059. // $data->access_token = $access_token;
  7060. // $fp = fopen ( $file, "w" );
  7061. // fwrite ( $fp, json_encode ( $data ) );
  7062. // fclose ( $fp );
  7063. // }
  7064. // } else {
  7065. // $access_token = $data->access_token;
  7066. // }
  7067. return $access_token;
  7068. }
  7069. private function httpGet($url) {
  7070. $curl = curl_init ();
  7071. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  7072. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  7073. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  7074. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  7075. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  7076. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  7077. curl_setopt ( $curl, CURLOPT_URL, $url );
  7078. $res = curl_exec ( $curl );
  7079. curl_close ( $curl );
  7080. return $res;
  7081. }
  7082. private function httpPost($url, $data) {
  7083. $curl = curl_init ();
  7084. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  7085. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  7086. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  7087. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  7088. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  7089. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  7090. curl_setopt ( $curl, CURLOPT_URL, $url );
  7091. curl_setopt ( $curl, CURLOPT_POST, 1 );
  7092. curl_setopt ( $curl, CURLOPT_POSTFIELDS, $data );
  7093. $res = curl_exec ( $curl );
  7094. curl_close ( $curl );
  7095. return $res;
  7096. }
  7097. }
  7098. ?>