InvoiceController.php 289 KB

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