InvoiceController.php 290 KB

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