InvoiceController.php 323 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437
  1. <?php
  2. /**
  3. * 开票功能控制器
  4. * @author CP
  5. * @version 1.0
  6. * @namespace invoice
  7. * @package invoiceController
  8. */
  9. require "protected/services/invoice_service.php";
  10. class InvoiceController extends DooController
  11. {
  12. public $staff;
  13. public $NEW;
  14. public $data;
  15. public $invoiceService;
  16. private $INVOICEKEY = "APPROVAL";
  17. private $INVOICECOLLECTPATH = "protected/cache/invoiceCollect/";
  18. private $ACTION = '';
  19. private $appId = 'wx3ee46531947a1384';
  20. private $appSecret = 'awGWzy3J5q_96VXKBLA2BQ9RpiT0LiPXnkMF-xV6h5o'; // awGWzy3J5q_96VXKBLA2BXU6mVCGynPGD-sxUCsdNDE //'PeiQVH8tbQE7pM9pVO4AIPlX9FFNpwu7O6Iy6VFcAVtpjTA3Qn42dbNmktBFkUHo';
  21. public function beforeRun($resource, $action)
  22. {
  23. Doo::loadModel("invoiceManage");
  24. $invoiceManage = new invoiceManage();
  25. Doo::loadClass('XDeode');
  26. $XDeode = new XDeode(5);
  27. $sid = $XDeode->decode($_COOKIE["staff"]);
  28. header('Content-Type:text/html;charset=utf-8');
  29. $moldList = $invoiceManage->getInvoiceByStaff($sid);
  30. if (empty($moldList)) {
  31. $flag = false;
  32. $uGroups = 'ordinary';
  33. if (Doo::acl()->isAllowed($uGroups, $resource, $action)) {
  34. $flag = true;
  35. }
  36. } else {
  37. $flag = false;
  38. array_push($moldList, array(
  39. 'mold' => 'ordinary'
  40. ));
  41. // 删除审批人后-加入权限问题-暂时关闭
  42. $fileInvoice = file_get_contents("protected/config/invoice/invoice.ini");
  43. $fiML = json_decode($fileInvoice, true);
  44. if (empty($fiML))
  45. $fiML = array();
  46. foreach ($fiML as $key => $value) {
  47. $sidList = explode(',', $value);
  48. foreach ($sidList as $k => $v) {
  49. if ($v == $sid) {
  50. array_push($moldList, array(
  51. 'mold' => $key
  52. ));
  53. break;
  54. }
  55. }
  56. }
  57. foreach ($moldList as $value) {
  58. if (Doo::acl()->isAllowed($value['mold'], $resource, $action)) {
  59. $flag = true;
  60. break;
  61. }
  62. }
  63. }
  64. /*
  65. * Doo::acl()->isAllowed($uGroups['groups'], $resource, $action);
  66. */
  67. // 单独判断办事处汇总的访问权限 invoiceAggregateCategoryDetail,invoiceAggregateStaffDetail
  68. if ($action == 'invoiceAggregateCategoryDetail' || $action == 'invoiceAggregateStaffDetail') {
  69. Doo::loadModel("invoiceCategoryManage");
  70. $invoiceCategoryManage = new invoiceCategoryManage();
  71. $icm = $invoiceCategoryManage->getInvoiceCMByStaff($sid);
  72. if (empty($icm))
  73. die('illegal request-iacd');
  74. }
  75. // 单独判断应收款访问权限
  76. if ($action == 'invoiceAggregateCompanyDetail') {
  77. Doo::loadModel("invoiceCompanyManage");
  78. $invoiceCompanyManage = new invoiceCompanyManage();
  79. $icm = $invoiceCompanyManage->getInvoiceCMByStaff($sid);
  80. if (empty($icm))
  81. die('illegal request');
  82. }
  83. // 主权限获得与判断
  84. Doo::loadModel('staff');
  85. $staff = new staff();
  86. $detail = $staff->getStaffBySid($_COOKIE["staff"]);
  87. $accessModular = 'INVOICE';
  88. if (empty($detail['cldAccessArray']))
  89. die('illegal request');
  90. else {
  91. if (in_array($accessModular, $detail['cldAccessArray'])) {
  92. if (Doo::acl()->isAllowed($accessModular, $resource, $action)) {
  93. $flag = true;
  94. } else {
  95. $flag = false;
  96. }
  97. } else {
  98. die('illegal request');
  99. }
  100. }
  101. if (!$flag)
  102. die('illegal request');
  103. }
  104. function __construct()
  105. {
  106. $this->invoiceService = new invoice_service();
  107. //echo $routeRs ['1'];
  108. //die('dd');
  109. if (isset($_COOKIE["staff"])) {
  110. if (!empty($_COOKIE["staff"])) {
  111. Doo::loadModel('staff');
  112. $staff = new staff();
  113. $uriPartsOrig = explode('/', $_SERVER['REQUEST_URI']);
  114. $this->ACTION = $uriPartsOrig[1];
  115. $this->data['new'] = $this->isInvoiceNew();
  116. $this->staff = $staff->getUserByIdList($_COOKIE["staff"]);
  117. $this->data['isStaffCompleteMsg'] = false;
  118. $detail = $staff->checkStaffInfoIsComplete($_COOKIE["staff"]);
  119. if (!empty($detail))
  120. $this->data['isStaffCompleteMsg'] = true;
  121. return "/";
  122. }
  123. }
  124. Doo::loadCore('uri/DooUriRouter');
  125. $router = new DooUriRouter();
  126. $routeRs = $router->execute(Doo::app()->route, Doo::conf()->SUBFOLDER);
  127. if ($routeRs['1'] != "login") {
  128. header('Content-Type:text/html;charset=utf-8');
  129. @header("Location: /login");
  130. }
  131. }
  132. function testSend()
  133. {
  134. // 测试根据规则发送信息 普通发送
  135. // $pendingApprovalsSid = 41;
  136. // Doo::loadModel ( 'staff' );
  137. // $staff = new staff ();
  138. // $username2 = $staff->getOne ( array ( 'select' => 'wxid', 'where' => 'sid=' . $pendingApprovalsSid, 'asArray' => TRUE ) );
  139. // // 发送微信审批通知
  140. // $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  141. // $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  142. // Doo::loadModel ( 'staff' );
  143. // $staff = new staff ();
  144. // $toparty = $this->getToparty ( '广东办' );
  145. // $wxList = array ();
  146. // if (! empty ( $toparty )) {
  147. // $userList = $this->getUserByToparty ( $toparty );
  148. // $userCon = implode ( ',', $userList );
  149. // // echo $userCon;
  150. // $sidList = $staff->getStaffByWxid ( $userCon );
  151. // foreach ( $sidList as $key => $value ) {
  152. // $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  153. // if ($falg) {
  154. // array_push ( $wxList, $value ['wxid'] );
  155. // }
  156. // }
  157. // $wxString = implode ( '|', $wxList );
  158. // print_r ( $wxList );
  159. // echo $wxString;
  160. // }
  161. // 测试发送
  162. /*
  163. * //$toparty = $this->getWxidByCategory( $receivablesCategory [1] ); $toparty = $this->getToparty ( $receivablesCategory [1] ); $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。'; if ($toparty != 0) $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  164. */
  165. // print_r ( $userList );
  166. // $msTouser='caipin|outaozhen';
  167. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  168. // $title2 = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  169. // $hfreult = $this->msgSend ( '', $title2, '', 'outaozhen' );
  170. // $toparty= $this->getToparty('广东办');
  171. // $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  172. // $toparty = 26;
  173. // $msg = '';
  174. // $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/1.html';
  175. // $hfreult = $this->msgSendToparty ( $msg, '', '', $toparty,'text' );
  176. }
  177. function cloudShow()
  178. {
  179. $data['memu'] = "buildActivation";
  180. $data['staff'] = $this->staff;
  181. $this->render("/cloudShow", $data);
  182. }
  183. function invoice()
  184. {
  185. Doo::loadModel('invoice');
  186. $invoice = new invoice();
  187. Doo::loadModel('express');
  188. $express = new express();
  189. $expressList = $express->getExpressByAll();
  190. $this->data['expressList'] = $expressList;
  191. // Doo::loadModel ( 'invoiceReceivables' );
  192. // $invoiceReceivables = new invoiceReceivables ();
  193. // $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  194. Doo::loadClass('XDeode');
  195. $XDeode = new XDeode(5);
  196. $sid = $XDeode->decode($_COOKIE["staff"]);
  197. Doo::loadModel('invoiceStatistics');
  198. $invoiceStatistics = new invoiceStatistics();
  199. $isMonth = $invoiceStatistics->getStatisticsByMonth($sid);
  200. // 缓存统计结果
  201. $year = date("Y");
  202. $tmp_date = date("Ym");
  203. $tmp_year = substr($tmp_date, 0, 4);
  204. $tmp_mon = substr($tmp_date, 4, 2);
  205. $tmp_forwardmonth = mktime(0, 0, 0, $tmp_mon - 1, 1, $tmp_year);
  206. $fm_forward_month = date("m", $tmp_forwardmonth);
  207. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . "_" . $sid . ".htm";
  208. if (is_file($path))
  209. $htm = file_get_contents($path);
  210. else
  211. $htm = $this->showCache($path, $sid);
  212. $invoiceList = $invoice->getMyInvoice($sid);
  213. $sql = 'status=2 and printStatus=1 and irid!="" and sid=' . $sid;
  214. $list = $invoice->getInvoiceByUntreadStatusPage(4, $sql);
  215. // 我的待入账发票 and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  216. $sql = "status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid=" . $sid;
  217. $myInvoiceUnAccount = $invoice->getInvoiceByUntreadStatusPage(4, $sql);
  218. // 获得已退票功能
  219. $untreadStatusList = $invoice->getMyInvoiceByUntreadStatus(2, 0, 5, $sid);
  220. $this->data['untreadStatusList'] = $untreadStatusList;
  221. // print_r($untreadStatusList);
  222. $this->data['isMonth'] = $isMonth;
  223. $this->data['htm'] = $htm;
  224. $this->data['invoiceList'] = $invoiceList;
  225. $this->data['receivablesList'] = $list;
  226. $this->data['myInvoiceUnAccount'] = $myInvoiceUnAccount;
  227. $this->data['memu'] = "invoice";
  228. $this->data['staff'] = $this->staff;
  229. $this->data['receiptMemu'] = 'invoice';
  230. $this->render("/admin/invoice", $this->data);
  231. }
  232. function invoiceExpress()
  233. {
  234. $expressCom = isset($this->params['expressCom']) ? $this->params['expressCom'] : "";
  235. $expressNumber = isset($this->params['expressNumber']) ? $this->params['expressNumber'] : "";
  236. $this->data['expressCom'] = $expressCom;
  237. $this->data['expressNumber'] = $expressNumber;
  238. $this->render("/admin/invoiceExpress", $this->data);
  239. }
  240. function invoiceAdd()
  241. {
  242. // include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  243. session_start();
  244. /*Doo::loadModel ( 'invoice' );
  245. $invoice = new invoice ();
  246. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );*/
  247. // 1.获得发票项
  248. $invoiceItemList = $this->invoiceService->getInvoiceItem();
  249. Doo::loadModel('L_category');
  250. $lCategory = new L_category();
  251. $category = $lCategory->find(array(
  252. 'asArray' => true
  253. ));
  254. $this->data['category'] = $category;
  255. Doo::loadModel('invoiceTraining');
  256. $invoiceTraining = new invoiceTraining();
  257. $itList = $invoiceTraining->findAll(array(
  258. 'where' => " cid=" . $this->staff[0]['cid'] . ' or creator =' . $this->staff[0]['sid'],
  259. 'desc' => 'itid',
  260. 'asArray' => TRUE
  261. ));
  262. //$itList = $invoiceTraining->getInvoiceTrainingByCid ( $this->staff [0] ['cid'] );
  263. Doo::loadModel('receipt');
  264. $receipt = new receipt();
  265. foreach ($itList as $key => $value) { // 不展示已结算完结的培训班
  266. $receiptDetail = $receipt->getReceiptByinvoiceTrainId($value['itid']);
  267. if (!empty($receiptDetail)) {
  268. if ($receiptDetail['status'] == 8 || $receiptDetail['status'] == 9) {
  269. unset($itList[$key]);
  270. }
  271. }
  272. }
  273. $this->data['itList'] = $itList;
  274. $token = $this->set_token();
  275. $tokenTime = time() . rand(5, 15);
  276. $_SESSION['token_' . $this->staff[0]['sidKey'] . '_' . $tokenTime] = $token;
  277. $this->data['invoiceItemList'] = $invoiceItemList;
  278. $this->data['token'] = $token;
  279. $this->data['tokenTime'] = $tokenTime;
  280. $this->data['memu'] = "invoice";
  281. $this->data['staff'] = $this->staff;
  282. $this->data['receiptMemu'] = 'invoice';
  283. $this->render("/admin/invoiceAdd", $this->data);
  284. }
  285. /**
  286. * 自更新发票信息库
  287. * @param unknown $invoicePrintDetail
  288. */
  289. function autoUpdateInvoiceInfoBase($invoicePrintDetail)
  290. {
  291. // 发票信息库
  292. Doo::loadModel('invoiceInfoBase');
  293. $invoiceInfoBase = new invoiceInfoBase();
  294. $updateDate = strtotime($invoicePrintDetail['date']);
  295. $TIN = $invoicePrintDetail['TIN'];
  296. $invoiceTitle = $invoicePrintDetail['invoiceTitle'];
  297. if (empty($invoiceTitle))
  298. $invoiceTitle = $invoicePrintDetail['invoiceCompany'];
  299. $IIBList = $invoiceInfoBase->getInvoiceInfoByTT($TIN, $invoiceTitle);
  300. // 确认有该条发票信息
  301. $invoiceInfoBase = new invoiceInfoBase();
  302. if (!empty($IIBList)) {
  303. // 发票库里的信息数量
  304. $IIBListCount = count($IIBList);
  305. if ($IIBListCount == 1) { // 更新发票--提交是最新的时间
  306. $item = array(
  307. 'iibID' => $IIBList[0]['iibID'],
  308. 'invoiceTitle' => $invoiceTitle,
  309. 'TIN' => $TIN
  310. );
  311. if (!empty($invoicePrintDetail['address'])) {
  312. $item += array(
  313. 'address' => $invoicePrintDetail['address']
  314. );
  315. }
  316. if (!empty($invoicePrintDetail['phone'])) {
  317. $item += array(
  318. 'phone' => $invoicePrintDetail['phone']
  319. );
  320. }
  321. if (!empty($invoicePrintDetail['bank'])) {
  322. $item += array(
  323. 'bank' => $invoicePrintDetail['bank']
  324. );
  325. }
  326. if (!empty($invoicePrintDetail['bankAccount'])) {
  327. $item += array(
  328. 'bankAccount' => $invoicePrintDetail['bankAccount']
  329. );
  330. }
  331. if ($updateDate >= strtotime($IIBList[0]['updateDate'])) {
  332. $item += array(
  333. 'updateDate' => $invoicePrintDetail['date']
  334. );
  335. $invoiceInfoBase->setInvoiceInfoBaseByCondition($item);
  336. }
  337. } else { // 删除多张发票,重新添加发票
  338. $iibIDStr = '';
  339. $iibID = array();
  340. foreach ($IIBList as $key => $value) {
  341. array_push($iibID, $value['iibID']);
  342. }
  343. $iibIDStr = implode(",", $iibID); // 删除
  344. $invoiceInfoBase->delInvoiceInfoBaseByIibStr($iibIDStr);
  345. $item = array(
  346. 'invoiceTitle' => $invoiceTitle,
  347. 'TIN' => $TIN,
  348. 'address' => $invoicePrintDetail['address'],
  349. 'phone' => $invoicePrintDetail['phone'],
  350. 'bank' => $invoicePrintDetail['bank'],
  351. 'bankAccount' => $invoicePrintDetail['bankAccount'],
  352. 'updateDate' => $invoicePrintDetail['date']
  353. );
  354. $invoiceInfoBase->addInvoiceInfoBase($item);
  355. }
  356. } else { // 没有新增发票信息
  357. $item = array(
  358. 'invoiceTitle' => $invoiceTitle,
  359. 'TIN' => $TIN,
  360. 'address' => $invoicePrintDetail['address'],
  361. 'phone' => $invoicePrintDetail['phone'],
  362. 'bank' => $invoicePrintDetail['bank'],
  363. 'bankAccount' => $invoicePrintDetail['bankAccount'],
  364. 'updateDate' => $invoicePrintDetail['date']
  365. );
  366. $invoiceInfoBase->addInvoiceInfoBase($item);
  367. }
  368. }
  369. function invoiceAddFill()
  370. {
  371. session_start();
  372. Doo::loadModel('L_category');
  373. $lCategory = new L_category();
  374. $category = $lCategory->find(array(
  375. 'asArray' => true
  376. ));
  377. $this->data['category'] = $category;
  378. Doo::loadModel('invoiceTraining');
  379. $invoiceTraining = new invoiceTraining();
  380. $itList = $invoiceTraining->getInvoiceTrainingByCid($this->staff[0]['cid']);
  381. $this->data['itList'] = $itList;
  382. Doo::loadModel('invoice');
  383. $invoice = new invoice();
  384. $detail = $invoice->getInvoiceByNew($this->staff[0]['sid']);
  385. $detail['mailItemsArray'] = json_decode($detail['mailItemsJson'], true);
  386. $token = $this->set_token();
  387. $tokenTime = time() . rand(5, 15);
  388. $_SESSION['token_' . $this->staff[0]['sidKey'] . '_' . $tokenTime] = $token;
  389. $this->data['token'] = $token;
  390. $this->data['tokenTime'] = $tokenTime;
  391. $this->data['invoiceDetail'] = $detail;
  392. $this->data['memu'] = "invoice";
  393. $this->data['staff'] = $this->staff;
  394. $this->data['receiptMemu'] = 'invoice';
  395. $this->render("/admin/invoiceAddFill", $this->data);
  396. }
  397. /**
  398. * 提交一份开票申请,并记录下操作日志
  399. *
  400. * @since 1.0.0
  401. * @var integer cid 办事处ID
  402. * @var integer invoiceType 发票类型
  403. * @var integer doPost 是否邮寄
  404. * @var integer invoicePrice 开票金额
  405. * @var string invoiceElement 开票内容
  406. * @var string invoiceTitle 发票抬头
  407. * @var string invoiceCompany 单位名称
  408. * @var string TIN 纳税人识别码
  409. * @var string address 注册地址
  410. * @var string phone 注册电话
  411. * @var string bank 开户银行
  412. * @var string bankAccount 银行账户
  413. * @var string recipients 收件人
  414. * @var string recipientsPhone 收件人手机/电话
  415. * @var string recipientsAddress 收件地址
  416. * @var string mailItems 邮寄物品
  417. * @var string remark 备注
  418. * @return string 返回跳转开票主页路径
  419. */
  420. function invoiceAddDo()
  421. {
  422. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  423. $cid = $this->get_args('cid') && is_numeric($this->get_args('cid')) ? $this->get_args('cid') : 0;
  424. $invoiceType = $this->get_args('invoiceType') && is_numeric($this->get_args('invoiceType')) ? $this->get_args('invoiceType') : 0;
  425. $doPost = $this->get_args('doPost') && is_numeric($this->get_args('doPost')) ? $this->get_args('doPost') : 0;
  426. // $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  427. $invoiceQuantity = $this->get_args('invoiceQuantity') && is_numeric($this->get_args('invoiceQuantity')) ? $this->get_args('invoiceQuantity') : 0;
  428. $invoiceUnitPrice = $this->get_args('invoiceUnitPrice') && is_numeric($this->get_args('invoiceUnitPrice')) ? $this->get_args('invoiceUnitPrice') : 0;
  429. $invoiceForm = $this->get_args('invoiceForm') ? $this->get_args('invoiceForm') : "";
  430. $invoiceElement = $this->get_args('invoiceElement') ? $this->get_args('invoiceElement') : "";
  431. $invoiceTitle = $this->get_args('invoiceTitle') ? $this->get_args('invoiceTitle') : "";
  432. $invoiceCompany = $this->get_args('invoiceCompany') ? $this->get_args('invoiceCompany') : "";
  433. $TIN = $this->get_args('TIN') ? $this->get_args('TIN') : "";
  434. $address = $this->get_args('address') ? $this->get_args('address') : "";
  435. $phone = $this->get_args('phone') ? $this->get_args('phone') : "";
  436. $bank = $this->get_args('bank') ? $this->get_args('bank') : "";
  437. $bankAccount = $this->get_args('bankAccount') ? $this->get_args('bankAccount') : "";
  438. $recipients = $this->get_args('recipients') ? $this->get_args('recipients') : "";
  439. $recipientsPhone = $this->get_args('recipientsPhone') ? $this->get_args('recipientsPhone') : "";
  440. $recipientsAddress = $this->get_args('recipientsAddress') ? $this->get_args('recipientsAddress') : "";
  441. $remark = $this->get_args('remark') ? $this->get_args('remark') : "";
  442. $TINT = $this->get_args('TINT') ? $this->get_args('TINT') : "";
  443. $addressT = $this->get_args('addressT') ? $this->get_args('addressT') : "";
  444. $phoneT = $this->get_args('phoneT') ? $this->get_args('phoneT') : "";
  445. $bankT = $this->get_args('bankT') ? $this->get_args('bankT') : "";
  446. $bankAccountT = $this->get_args('bankAccountT') ? $this->get_args('bankAccountT') : "";
  447. $softLock = $this->get_args('softLock') ? $this->get_args('softLock') : 0;
  448. $softLockNum = $this->get_args('softLockNum') ? $this->get_args('softLockNum') : 0;
  449. $contract = $this->get_args('contract') ? $this->get_args('contract') : 0;
  450. $contractNum = $this->get_args('contractNum') ? $this->get_args('contractNum') : 0;
  451. $instructions = $this->get_args('instructions') ? $this->get_args('instructions') : 0;
  452. $instructionsNum = $this->get_args('instructionsNum') ? $this->get_args('instructionsNum') : 0;
  453. $remittance = $this->get_args('remittance') ? $this->get_args('remittance') : 0;
  454. $mailItems = $this->get_args('mailItems') ? $this->get_args('mailItems') : "";
  455. $trainId = $this->get_args('trainId') ? $this->get_args('trainId') : 0;
  456. $settlementType = $this->get_args('settlementType') ? $this->get_args('settlementType') : "";
  457. $electronicPhone = $this->get_args('electronicPhone') ? $this->get_args('electronicPhone') : "";
  458. $electronicEmail = $this->get_args('electronicEmail') ? $this->get_args('electronicEmail') : "";
  459. /*
  460. * $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;
  461. */
  462. $token = $this->get_args('token') ? $this->get_args('token') : "";
  463. $tokenTime = $this->get_args('tokenTime') ? $this->get_args('tokenTime') : "";
  464. if (empty($token)) {
  465. die('illegal request-token');
  466. } else {
  467. session_start();
  468. $sessionKey = 'token_' . $this->staff[0]['sidKey'] . '_' . $tokenTime;
  469. header('Content-Type:text/html;charset=utf-8');
  470. if (!isset($_SESSION[$sessionKey]) || empty($_SESSION[$sessionKey])) {
  471. die('请重新刷新发票申请页面');
  472. } elseif ($_SESSION[$sessionKey] == 'repeat') {
  473. die('请勿重复申请发票');
  474. } else {
  475. if ($_SESSION[$sessionKey] != $token) {
  476. die('请勿重复申请发票');
  477. } else {
  478. $_SESSION[$sessionKey] = 'repeat';
  479. }
  480. }
  481. }
  482. if ($invoiceForm == 'electronic') {
  483. if (empty(trim($electronicPhone)) && empty(trim($electronicEmail))) {
  484. die('请至少填写一种联系方式--电子发票');
  485. }
  486. }
  487. if ($invoiceType == 1) {
  488. $temporary = $invoiceQuantity * $invoiceUnitPrice;
  489. if ($temporary > 100001) {
  490. header('Content-Type:text/html;charset=utf-8');
  491. die('专用发票总金额暂时不能超过100000.00(十万)元。');
  492. }
  493. } elseif ($invoiceType == 0) {
  494. $temporary = $invoiceQuantity * $invoiceUnitPrice;
  495. if ($temporary > 100001) {
  496. header('Content-Type:text/html;charset=utf-8');
  497. die('专用发票总金额暂时不能超过100000.00(十万)元。');
  498. }
  499. } else {
  500. die('illegal request-invoiceType');
  501. }
  502. if (empty($this->staff[0]))
  503. die('illegal request-Please login');
  504. if (!empty($cid) && !empty($invoiceQuantity) && !empty($invoiceUnitPrice) && !empty($invoiceElement) && !empty($settlementType) && !empty($invoiceForm)) {
  505. Doo::loadModel('invoice');
  506. $invoice = new invoice();
  507. Doo::loadModel('L_category');
  508. $lCategory = new L_category();
  509. Doo::loadModel('invoiceManage');
  510. $invoiceManage = new invoiceManage();
  511. Doo::loadModel('invoiceOperationLog');
  512. $invoiceOperationLog = new invoiceOperationLog();
  513. Doo::loadClass('XDeode');
  514. $XDeode = new XDeode(5);
  515. $trainId = $XDeode->decode($trainId);
  516. $categoryDetil = $lCategory->getOne(array(
  517. 'SELECT' => 'title',
  518. 'where' => 'cid=' . $cid,
  519. 'asArray' => true
  520. ));
  521. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  522. $invoiceManageList = $invoiceManage->getInvoiceByAll();
  523. $invoiceManageDetail = $invoiceManage->getInvoiceByMold("发票审批");
  524. // print_r(current($invoiceManageDetail ['staffList']));
  525. // die;
  526. $moldManage = array();
  527. foreach ($invoiceManageList as $key => $value) {
  528. if ($value['mold'] == '发票打印')
  529. $moldManage[$value['mold']] = $value['staffList'];
  530. elseif ($value['mold'] == '发票邮寄')
  531. $moldManage[$value['mold']] = $value['staffList'];
  532. elseif ($value['mold'] == '发票退票')
  533. $moldManage[$value['mold']] = $value['staffList'];
  534. }
  535. $pendingApprovalsSid = current($invoiceManageDetail['staffList'])[0];
  536. $st = '';
  537. if ($settlementType == 'SOFTWARE') {
  538. $st = 0;
  539. $trainId = 0;
  540. } elseif ($settlementType == 'TRAINING') {
  541. $st = 1;
  542. if (empty($trainId) && !is_numeric($trainId)) {
  543. die('illegal request-trainingIdError');
  544. }
  545. } else {
  546. die('illegal request-settlementError');
  547. }
  548. if ($invoiceForm == 'electronic') {
  549. $invoiceSerial = "#FE" . date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
  550. $invoiceForm = 1;
  551. $invoiceType = 0;
  552. if (!empty($electronicPhone) || !empty($electronicEmail)) {
  553. } else {
  554. die('illegal request-electronicContact');
  555. }
  556. $mailList = array();
  557. $mailString = '备注:' . $mailItems;
  558. } elseif ($invoiceForm == 'paper') {
  559. $invoiceSerial = "#F" . date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
  560. $invoiceForm = 0;
  561. $mailList = array(
  562. 'invoice' => 1,
  563. 'mailItems' => $mailItems
  564. );
  565. $mailString = '发票x1张,备注:' . $mailItems;
  566. } else {
  567. die('illegal request-invoiceForm');
  568. }
  569. $item = array(
  570. 'cid' => $cid,
  571. 'categoryName' => $categoryDetil['title'],
  572. 'invoiceElement' => $invoiceElement,
  573. 'invoiceForm' => $invoiceForm,
  574. 'electronicPhone' => $electronicPhone,
  575. 'electronicEmail' => $electronicEmail,
  576. 'invoiceQuantity' => $invoiceQuantity,
  577. 'invoiceUnitPrice' => $invoiceUnitPrice,
  578. 'invoicePrice' => $invoicePrice,
  579. 'invoiceType' => $invoiceType,
  580. 'settlementType' => $st,
  581. 'doPost' => $doPost,
  582. 'status' => 1,
  583. 'invoiceSerial' => $invoiceSerial,
  584. 'date' => date("Y-m-d H:i:s"),
  585. 'updateTime' => date("Y-m-d H:i:s"),
  586. 'sid' => $this->staff[0]['sid'],
  587. 'userName' => $this->staff[0]['username'],
  588. 'invoiceManage' => $invoiceManageDetail['staff'],
  589. 'pendingApprovals' => $pendingApprovalsSid,
  590. 'moldManage' => json_encode($moldManage),
  591. 'remark' => $remark,
  592. 'trainId' => $trainId
  593. );
  594. if ($invoiceType == 0)
  595. $item += array(
  596. 'invoiceTitle' => $invoiceTitle,
  597. 'TIN' => $TINT,
  598. 'address' => $addressT,
  599. 'phone' => $phoneT,
  600. 'bank' => $bankT,
  601. 'bankAccount' => $bankAccountT
  602. );
  603. else {
  604. $item += array(
  605. 'invoiceCompany' => $invoiceCompany,
  606. 'TIN' => $TIN,
  607. 'address' => $address,
  608. 'phone' => $phone,
  609. 'bank' => $bank,
  610. 'bankAccount' => $bankAccount
  611. );
  612. }
  613. if ($doPost == 1) {
  614. if (!empty($softLock))
  615. $mailList += array(
  616. 'softLock' => $softLockNum
  617. );
  618. else
  619. $mailList += array(
  620. 'softLock' => 0
  621. );
  622. if (!empty($contract))
  623. $mailList += array(
  624. 'contract' => $contractNum
  625. );
  626. else
  627. $mailList += array(
  628. 'contract' => 0
  629. );
  630. if (!empty($instructions))
  631. $mailList += array(
  632. 'instructions' => $instructionsNum
  633. );
  634. else
  635. $mailList += array(
  636. 'instructions' => 0
  637. );
  638. if (!empty($remittance))
  639. $mailList += array(
  640. 'remittance' => $remittance
  641. );
  642. else
  643. $mailList += array(
  644. 'remittance' => ''
  645. );
  646. if (!empty($softLock))
  647. $mailString .= ',软件锁x' . $softLockNum . '个';
  648. if (!empty($contract))
  649. $mailString .= ',合同x' . $contractNum . '份';
  650. if (!empty($instructions))
  651. $mailString .= ',说明书x' . $instructionsNum . '本';
  652. if (!empty($remittance))
  653. $mailString .= ',汇款账号单(张)';
  654. $item += array(
  655. 'recipients' => $recipients,
  656. 'recipientsPhone' => $recipientsPhone,
  657. 'recipientsAddress' => $recipientsAddress,
  658. 'mailItems' => $mailString,
  659. 'mailItemsJson' => json_encode($mailList)
  660. );
  661. }
  662. $iid = $invoice->addInvoice($item);
  663. // 如果是培训班结算 创建培训班发票到培训班备份中
  664. if (!empty($st) && $st == 1) {
  665. Doo::loadModel('invoiceStore');
  666. $invoiceStore = new invoiceStore();
  667. Doo::loadModel('invoiceTraining');
  668. $invoiceTraining = new invoiceTraining();
  669. $isid = $invoiceStore->setInvoiceToInvoiceStore($iid);
  670. $itemIS = array(
  671. 'isid' => $isid,
  672. 'ipSource' => 1,
  673. 'apStatus' => 1,
  674. 'iid' => $iid
  675. );
  676. $invoiceStore->setInvoiceStoreByCondition($itemIS);
  677. // 更新培训班总数量
  678. $detailIT = $invoiceTraining->getInvoiceTrainingByItid($trainId);
  679. $item = array(
  680. 'itid' => $trainId,
  681. 'invoiceTotal' => $detailIT['invoiceTotal'] + 1,
  682. 'submitStatus' => 1
  683. );
  684. $itid = $invoiceTraining->setInvoiceTrainByCondition($item);
  685. }
  686. // 操作日志
  687. $item = array(
  688. 'date' => date("Y-m-d H:i:s"),
  689. 'operation' => "创建",
  690. 'status' => 1,
  691. 'img' => $this->staff[0]['avatar'],
  692. 'username' => $this->staff[0]['username'],
  693. 'uid' => $this->staff[0]['sid'],
  694. 'category' => $this->staff[0]['category'],
  695. 'iid' => $iid
  696. );
  697. $invoiceOperationLog->setInvoiceOperationLog($item);
  698. $item = array(
  699. 'date' => date("Y-m-d H:i:s"),
  700. 'operation' => "提交审批",
  701. 'status' => 1,
  702. 'img' => $this->staff[0]['avatar'],
  703. 'username' => $this->staff[0]['username'],
  704. 'uid' => $this->staff[0]['sid'],
  705. 'category' => $this->staff[0]['category'],
  706. 'iid' => $iid
  707. );
  708. $invoiceOperationLog->setInvoiceOperationLog($item);
  709. Doo::loadModel('staff');
  710. $staff = new staff();
  711. $username2 = $staff->getOne(array(
  712. 'select' => 'wxid',
  713. 'where' => 'sid=' . $pendingApprovalsSid,
  714. 'asArray' => TRUE
  715. ));
  716. // 发送微信审批通知
  717. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  718. $this->msgSend('', $title2, '', $username2['wxid'], $pendingApprovalsSid, 'approval');
  719. }
  720. return "/invoice";
  721. }
  722. function invoiceEdit()
  723. {
  724. Doo::loadClass('XDeode');
  725. $XDeode = new XDeode(5);
  726. $iid = isset($this->params['iid']) ? $this->params['iid'] : "";
  727. $iid = $XDeode->decode($iid);
  728. if (!is_numeric($iid))
  729. die('illegal request');
  730. Doo::loadModel('invoice');
  731. $invoice = new invoice();
  732. Doo::loadModel('invoiceOperationLog');
  733. $invoiceOperationLog = new invoiceOperationLog();
  734. $invoiceDetail = $invoice->getInvoiceByIid($iid);
  735. $operation = $invoiceOperationLog->getInvoiceOperationByDropped($iid);
  736. $invoiceDetail['mailItemsJson'] = '';
  737. if (isset($invoiceDetail['mailItemsJson'])) {
  738. $invoiceDetail['mailItemsJson'] = json_decode($invoiceDetail['mailItemsJson'], true);
  739. }
  740. $this->data['operation'] = $operation;
  741. $this->data['invoiceDetail'] = $invoiceDetail;
  742. $this->data['memu'] = "invoice";
  743. $this->data['staff'] = $this->staff;
  744. $this->data['receiptMemu'] = 'invoice';
  745. $this->render("/admin/invoiceEdit", $this->data);
  746. }
  747. /**
  748. * 重新编辑退回的发票
  749. * @return string
  750. */
  751. function invoiceEditDo()
  752. {
  753. $iidKey = $this->get_args('iidKey') ? $this->get_args('iidKey') : '';
  754. Doo::loadModel('invoice');
  755. $invoice = new invoice();
  756. $iid = $invoice->authcode($iidKey);
  757. if (!empty($iid) && !is_numeric($iid))
  758. die('illegal request');
  759. $cid = $this->get_args('cid') ? $this->get_args('cid') : 0;
  760. $invoiceType = $this->get_args('invoiceType') && is_numeric($this->get_args('invoiceType')) ? $this->get_args('invoiceType') : 0;
  761. $doPost = $this->get_args('doPost') && is_numeric($this->get_args('doPost')) ? $this->get_args('doPost') : 0;
  762. $invoicePrice = $this->get_args('invoicePrice') ? $this->get_args('invoicePrice') : "";
  763. $invoiceQuantity = $this->get_args('invoiceQuantity') && is_numeric($this->get_args('invoiceQuantity')) ? $this->get_args('invoiceQuantity') : 0;
  764. $invoiceUnitPrice = $this->get_args('invoiceUnitPrice') && is_numeric($this->get_args('invoiceUnitPrice')) ? $this->get_args('invoiceUnitPrice') : 0;
  765. $invoiceElement = $this->get_args('invoiceElement') ? $this->get_args('invoiceElement') : "";
  766. $invoiceTitle = $this->get_args('invoiceTitle') ? $this->get_args('invoiceTitle') : "";
  767. $invoiceCompany = $this->get_args('invoiceCompany') ? $this->get_args('invoiceCompany') : "";
  768. $TIN = $this->get_args('TIN') ? $this->get_args('TIN') : "";
  769. $address = $this->get_args('address') ? $this->get_args('address') : "";
  770. $phone = $this->get_args('phone') ? $this->get_args('phone') : "";
  771. $bank = $this->get_args('bank') ? $this->get_args('bank') : "";
  772. $bankAccount = $this->get_args('bankAccount') ? $this->get_args('bankAccount') : "";
  773. $recipients = $this->get_args('recipients') ? $this->get_args('recipients') : "";
  774. $recipientsPhone = $this->get_args('recipientsPhone') ? $this->get_args('recipientsPhone') : "";
  775. $recipientsAddress = $this->get_args('recipientsAddress') ? $this->get_args('recipientsAddress') : "";
  776. $mailItems = $this->get_args('mailItems') ? $this->get_args('mailItems') : "";
  777. $remark = $this->get_args('remark') ? $this->get_args('remark') : "";
  778. $TINT = $this->get_args('TINT') ? $this->get_args('TINT') : "";
  779. $addressT = $this->get_args('addressT') ? $this->get_args('addressT') : "";
  780. $phoneT = $this->get_args('phoneT') ? $this->get_args('phoneT') : "";
  781. $bankT = $this->get_args('bankT') ? $this->get_args('bankT') : "";
  782. $bankAccountT = $this->get_args('bankAccountT') ? $this->get_args('bankAccountT') : "";
  783. $softLock = $this->get_args('softLock') ? $this->get_args('softLock') : 0;
  784. $softLockNum = $this->get_args('softLockNum') ? $this->get_args('softLockNum') : 0;
  785. $contract = $this->get_args('contract') ? $this->get_args('contract') : 0;
  786. $contractNum = $this->get_args('contractNum') ? $this->get_args('contractNum') : 0;
  787. $instructions = $this->get_args('instructions') ? $this->get_args('instructions') : 0;
  788. $instructionsNum = $this->get_args('instructionsNum') ? $this->get_args('instructionsNum') : 0;
  789. $remittance = $this->get_args('remittance') ? $this->get_args('remittance') : 0;
  790. $electronicPhone = $this->get_args('electronicPhone') ? $this->get_args('electronicPhone') : "";
  791. $electronicEmail = $this->get_args('electronicEmail') ? $this->get_args('electronicEmail') : "";
  792. $invoiceForm = $this->get_args('invoiceForm') ? $this->get_args('invoiceForm') : "";
  793. if ($invoiceType == 1) {
  794. $temporary = $invoiceQuantity * $invoiceUnitPrice;
  795. if ($temporary > 100001)
  796. die('illegal request-Please priceError');
  797. }
  798. if ($invoiceForm == 'electronic') {
  799. if (empty(trim($electronicPhone)) && empty(trim($electronicEmail))) {
  800. die('请至少填写一种联系方式--电子发票');
  801. }
  802. }
  803. if (!empty($cid) && !empty($invoiceQuantity) && !empty($invoiceUnitPrice) && !empty($invoiceElement) && !empty($iid)) {
  804. Doo::loadModel('invoiceManage');
  805. $invoiceManage = new invoiceManage();
  806. Doo::loadModel('invoiceOperationLog');
  807. $invoiceOperationLog = new invoiceOperationLog();
  808. Doo::loadModel('invoiceStore');
  809. $invoiceStore = new invoiceStore();
  810. $cid = explode(':', $cid);
  811. $invoiceManageList = $invoiceManage->getInvoiceByAll();
  812. $invoiceManageDetail = $invoiceManage->getInvoiceByMold("发票审批");
  813. $moldManage = array();
  814. foreach ($invoiceManageList as $key => $value) {
  815. if ($value['mold'] == '发票打印')
  816. $moldManage[$value['mold']] = $value['staffList'];
  817. elseif ($value['mold'] == '发票邮寄')
  818. $moldManage[$value['mold']] = $value['staffList'];
  819. elseif ($value['mold'] == '发票打印')
  820. $moldManage[$value['mold']] = $value['staffList'];
  821. }
  822. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  823. if ($invoiceForm == 'electronic') {
  824. $invoiceForm = 1;
  825. $invoiceType = 0;
  826. if (!empty($electronicPhone) || !empty($electronicEmail)) {
  827. } else {
  828. die('illegal request-electronicContact');
  829. }
  830. $mailList = array();
  831. $mailString = '备注:' . $mailItems;
  832. } elseif ($invoiceForm == 'paper') {
  833. $invoiceForm = 0;
  834. $mailList = array(
  835. 'invoice' => 1,
  836. 'mailItems' => $mailItems
  837. );
  838. $mailString = '发票x1张,备注:' . $mailItems;
  839. } else {
  840. die('illegal request-invoiceForm');
  841. }
  842. $item = array(
  843. 'iid' => $iid,
  844. 'cid' => $cid[0],
  845. 'categoryName' => $cid[1],
  846. 'invoiceElement' => $invoiceElement,
  847. 'invoiceForm' => $invoiceForm,
  848. 'electronicPhone' => $electronicPhone,
  849. 'electronicEmail' => $electronicEmail,
  850. 'invoiceQuantity' => $invoiceQuantity,
  851. 'invoiceUnitPrice' => $invoiceUnitPrice,
  852. 'invoicePrice' => $invoicePrice,
  853. 'invoiceType' => $invoiceType,
  854. 'doPost' => $doPost,
  855. 'status' => 1,
  856. 'updateTime' => date("Y-m-d H:i:s"),
  857. 'remark' => $remark
  858. );
  859. if ($invoiceType == 0)
  860. $item += array(
  861. 'invoiceTitle' => $invoiceTitle,
  862. 'TIN' => $TINT,
  863. 'address' => $addressT,
  864. 'phone' => $phoneT,
  865. 'bank' => $bankT,
  866. 'bankAccount' => $bankAccountT
  867. );
  868. else {
  869. $item += array(
  870. 'invoiceCompany' => $invoiceCompany,
  871. 'TIN' => $TIN,
  872. 'address' => $address,
  873. 'phone' => $phone,
  874. 'bank' => $bank,
  875. 'bankAccount' => $bankAccount
  876. );
  877. }
  878. if ($doPost == 1) {
  879. if (!empty($softLock))
  880. $mailList += array(
  881. 'softLock' => $softLockNum
  882. );
  883. else
  884. $mailList += array(
  885. 'softLock' => '0'
  886. );
  887. if (!empty($contract))
  888. $mailList += array(
  889. 'contract' => $contractNum
  890. );
  891. else
  892. $mailList += array(
  893. 'contract' => '0'
  894. );
  895. if (!empty($instructions))
  896. $mailList += array(
  897. 'instructions' => $instructionsNum
  898. );
  899. else
  900. $mailList += array(
  901. 'instructions' => '0'
  902. );
  903. if (!empty($remittance))
  904. $mailList += array(
  905. 'remittance' => $remittance
  906. );
  907. else
  908. $mailList += array(
  909. 'remittance' => ''
  910. );
  911. if (!empty($softLock))
  912. $mailString .= ',软件锁x' . $softLockNum;
  913. if (!empty($contract))
  914. $mailString .= ',合同x' . $contractNum;
  915. if (!empty($instructions))
  916. $mailString .= ',说明书x' . $instructionsNum;
  917. if (!empty($remittance))
  918. $mailString .= ',汇款账号单';
  919. $item += array(
  920. 'recipients' => $recipients,
  921. 'recipientsPhone' => $recipientsPhone,
  922. 'recipientsAddress' => $recipientsAddress,
  923. 'mailItems' => $mailString,
  924. 'mailItemsJson' => json_encode($mailList)
  925. );
  926. }
  927. $invoice->setInvoiceByCondition($item);
  928. // 更新培训班仓库里的发票
  929. $detail = $invoice->getInvoiceByIid($iid);
  930. if (!empty($detail['isid'])) {
  931. $invoiceStore->isid = $detail['isid'];
  932. $invoiceStore->invoiceQuantity = $invoiceQuantity;
  933. $invoiceStore->invoiceUnitPrice = $invoiceUnitPrice;
  934. $invoiceStore->invoicePrice = $invoicePrice;
  935. $invoiceStore->update();
  936. }
  937. $item = array(
  938. 'date' => date("Y-m-d H:i:s"),
  939. 'operation' => "重新提交审批",
  940. 'status' => 1,
  941. 'img' => $this->staff[0]['avatar'],
  942. 'username' => $this->staff[0]['username'],
  943. 'uid' => $this->staff[0]['sid'],
  944. 'category' => $this->staff[0]['category'],
  945. 'iid' => $iid
  946. );
  947. $invoiceOperationLog->setInvoiceOperationLog($item);
  948. }
  949. return "/invoice";
  950. }
  951. /**
  952. * 培训班
  953. */
  954. function invoiceTraining()
  955. {
  956. Doo::loadModel('L_category');
  957. $lCategory = new L_category();
  958. Doo::loadModel('invoiceTraining');
  959. $invoiceTraining = new invoiceTraining();
  960. Doo::loadModel('invoiceTrainManage');
  961. $invoiceTrainManage = new invoiceTrainManage();
  962. $imcStaff = $invoiceTrainManage->getInvoiceCMByStaff($this->staff[0]['sid']);
  963. $cidList = array();
  964. foreach ($imcStaff as $key => $value) {
  965. array_push($cidList, $value['cid']);
  966. }
  967. if (empty($cidList)) {
  968. $cidString = $this->staff[0]['cid'];
  969. } else {
  970. $cidString = implode(',', $cidList);
  971. $cidString .= $cidString . ',' . $this->staff[0]['cid'];
  972. }
  973. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  974. // $itTodoList = $invoiceTraining->getInvoiceTrainingByTodo ( '', $cidString, $this->staff [0] ['sid'] );
  975. //TODO 待完成入账培训班
  976. $itTodoList = $this->invoiceService->getTrainByCategoryStaff(0, $cidString, $this->staff[0]['sid']);
  977. // if($this->staff [0] ['sid']==94){
  978. // $itTodoList=$this->invoiceService->getTrainByCategoryStaff(0,$cidString,$this->staff [0] ['sid']);
  979. // }else{
  980. // $itTodoList = $invoiceTraining->getInvoiceTrainingByTodo ( '', $cidString, $this->staff [0] ['sid'] );
  981. // }
  982. // $itTodoList=$this->invoiceService->getTrainByCategoryStaff(0,$cidString,$this->staff [0] ['sid']);
  983. $itedList = $invoiceTraining->getInvoiceTrainingByStatus(2, '', $cidString, $this->staff[0]['sid']);
  984. $category = $lCategory->getCategory();
  985. $itid = array();
  986. foreach ($itTodoList as $key => $value) {
  987. array_push($itid, $value['itid']);
  988. // 如果入账100%更新为已完成
  989. if ($itTodoList[$key]['arriveSchedule'] >= 100) {
  990. $invoiceTraining = new invoiceTraining();
  991. $invoiceTraining->itid = $value['itid'];
  992. $invoiceTraining->status = 2;
  993. $invoiceTraining->update();
  994. }
  995. }
  996. foreach ($itedList as $value) {
  997. array_push($itid, $value['itid']);
  998. }
  999. $itid = implode(',', $itid);
  1000. $this->data['itStatist'] = $invoiceTraining->getInvoiceTrainStatistics($itid);
  1001. // print_r($itTodoList);
  1002. $this->data['trainCount'] = count($itTodoList) + count($itedList);
  1003. $this->data['itTodoList'] = $itTodoList;
  1004. $this->data['itedList'] = $itedList;
  1005. $this->data['category'] = $category;
  1006. $this->data['memu'] = "invoice";
  1007. $this->data['staff'] = $this->staff;
  1008. $this->data['receiptMemu'] = 'invoiceTraining';
  1009. $this->render("/admin/invoiceTraining", $this->data);
  1010. }
  1011. /**
  1012. * 创建培训班
  1013. */
  1014. function invoiceTrainingAdd()
  1015. {
  1016. $cid = $this->get_args('cid') && is_numeric($this->get_args('cid')) ? $this->get_args('cid') : 0;
  1017. $trainName = $this->get_args('trainName') ? $this->get_args('trainName') : "";
  1018. $trainDate = $this->get_args('trainDate') ? $this->get_args('trainDate') : "";
  1019. if (empty($this->staff[0]))
  1020. die('illegal request');
  1021. if (!empty($cid) && !empty($trainName) && !empty($trainDate)) {
  1022. Doo::loadModel('invoiceTraining');
  1023. $invoiceTraining = new invoiceTraining();
  1024. Doo::loadModel('invoice');
  1025. $invoice = new invoice();
  1026. Doo::loadModel('L_category');
  1027. $lCategory = new L_category();
  1028. Doo::loadModel('invoiceManage');
  1029. $invoiceManage = new invoiceManage();
  1030. Doo::loadModel('invoiceOperationLog');
  1031. $invoiceOperationLog = new invoiceOperationLog();
  1032. $item = array(
  1033. 'cid' => $cid,
  1034. 'trainName' => $trainName,
  1035. 'trainDate' => $trainDate,
  1036. 'creator' => $this->staff[0]['sid'],
  1037. 'creatorDate' => date("Y-m-d H:i:s")
  1038. );
  1039. $itid = $invoiceTraining->addInvoiceTraining($item);
  1040. }
  1041. return "/invoiceTraining";
  1042. }
  1043. /**
  1044. * 删除培训班
  1045. */
  1046. function invoiceTrainingDelDo()
  1047. {
  1048. $itid = $this->get_args('trainingKey') ? $this->get_args('trainingKey') : "";
  1049. if (!empty($itid)) {
  1050. Doo::loadModel('invoiceTraining');
  1051. $invoiceTraining = new invoiceTraining();
  1052. $invoiceTraining->delInvoiceTrainingByItid($itid);
  1053. }
  1054. return "/invoiceTraining";
  1055. }
  1056. /**
  1057. * 培训班详情
  1058. */
  1059. function invoiceTrainingDetail()
  1060. {
  1061. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  1062. $trainStatus = $this->get_args('trainStatus') ? $this->get_args('trainStatus') : "ALL";
  1063. $itid = isset($this->params['trainingKey']) ? $this->params['trainingKey'] : "";
  1064. Doo::loadModel('invoiceTraining');
  1065. $invoiceTraining = new invoiceTraining();
  1066. Doo::loadModel('invoiceStore');
  1067. $invoiceStore = new invoiceStore();
  1068. if (empty($itid))
  1069. die('illegal request');
  1070. $con = '(b.untreadStatus is null or b.untreadStatus!=2) and ';
  1071. if ($trainStatus == "SUBED")
  1072. $con = ' (b.untreadStatus is null ) and ';
  1073. elseif ($trainStatus == "APPROVAL")
  1074. $con = ' ( b.status=1 and b.untreadStatus!=2 ) and ';
  1075. elseif ($trainStatus == "TICKET")
  1076. $con = ' (b.printStatus=1 and b.status=2 and b.untreadStatus!=2) and ';
  1077. elseif ($trainStatus == "TICKETING") {
  1078. $con = ' (b.status=2 and b.untreadStatus=1) and ';
  1079. }
  1080. $con .= ' a.invoiceForm=0 and ';
  1081. $detail = $invoiceTraining->getInvoiceTrainingByItid($itid);
  1082. $isList = $invoiceStore->getinvoiceStoreByItid($itid, $con, 0);
  1083. //print_r($isList);
  1084. $trainlistJson = $this->_trainList($isList);
  1085. if (empty($detail))
  1086. die('illegal request');
  1087. // 培训班结算是否有和是否已经结算完成
  1088. Doo::loadModel('receipt');
  1089. $receipt = new receipt();
  1090. $receiptDetail = $receipt->getReceiptByinvoiceTrainId($itid);
  1091. $this->data['receiptDetail'] = $receiptDetail;
  1092. $this->data['trainStatus'] = $trainStatus;
  1093. $this->data['itid'] = $itid;
  1094. $this->data['trainlistJson'] = $trainlistJson;
  1095. $this->data['iTrainDetail'] = $detail;
  1096. $this->data['memu'] = "invoice";
  1097. $this->data['staff'] = $this->staff;
  1098. $this->data['receiptMemu'] = 'invoiceTraining';
  1099. $this->render("/admin/invoiceTrainingDetail", $this->data);
  1100. }
  1101. function invoiceTrainingElectronicDetail()
  1102. {
  1103. $trainStatus = $this->get_args('trainStatus') ? $this->get_args('trainStatus') : "ALL";
  1104. $itid = isset($this->params['trainingKey']) ? $this->params['trainingKey'] : "";
  1105. Doo::loadModel('invoiceTraining');
  1106. $invoiceTraining = new invoiceTraining();
  1107. Doo::loadModel('invoiceStore');
  1108. $invoiceStore = new invoiceStore();
  1109. if (empty($itid))
  1110. die('illegal request');
  1111. $con = ' (b.untreadStatus is null or b.untreadStatus!=2) and ';
  1112. if ($trainStatus == "SUBED")
  1113. $con = ' (b.untreadStatus is null ) and ';
  1114. elseif ($trainStatus == "APPROVAL")
  1115. $con = ' ( b.status=1 and b.untreadStatus!=2 ) and ';
  1116. elseif ($trainStatus == "TICKET")
  1117. $con = ' (b.printStatus=1 and b.status=2 and b.untreadStatus!=2) and ';
  1118. elseif ($trainStatus == "TICKETING") {
  1119. $con = ' (b.status=2 and b.untreadStatus=1) and ';
  1120. }
  1121. $con .= ' a.invoiceForm=1 and ';
  1122. $detail = $invoiceTraining->getInvoiceTrainingByItid($itid);
  1123. // TODO 获得电子票
  1124. $isList = $invoiceStore->getinvoiceStoreByItid($itid, $con, 1);
  1125. //print_r($isList);
  1126. if (empty($detail)) {
  1127. die('illegal request');
  1128. }
  1129. $trainlistJson = $this->_trainList($isList, 1);
  1130. // 培训班结算是否有和是否已经结算完成
  1131. Doo::loadModel('receipt');
  1132. $receipt = new receipt();
  1133. $receiptDetail = $receipt->getReceiptByinvoiceTrainId($itid);
  1134. $this->data['receiptDetail'] = $receiptDetail;
  1135. $this->data['trainStatus'] = $trainStatus;
  1136. $this->data['itid'] = $itid;
  1137. $this->data['trainlistJson'] = $trainlistJson;
  1138. $this->data['iTrainDetail'] = $detail;
  1139. $this->data['memu'] = "invoice";
  1140. $this->data['staff'] = $this->staff;
  1141. $this->data['receiptMemu'] = 'invoiceTraining';
  1142. $this->render("/invoice/invoiceTrainingElectronicDetail", $this->data);
  1143. }
  1144. function _trainList($isList, $type = 0)
  1145. {
  1146. $trainlist = array();
  1147. foreach ($isList as $key => $value) {
  1148. $irDetail = array();
  1149. if ($value['apStatus'] == 1) {
  1150. // array_push ( $irDetail, '' );
  1151. array_push($irDetail, '<input disabled type="checkbox" style="display:none" >');
  1152. } else {
  1153. array_push($irDetail, '<input type="checkbox" class="hide" id="' . $value['storeKey'] . '" name="isBox" value="' . $value['storeKey'] . '" > <a href="/invoiceStoreEdit/' . $value['storeKey'] . '.html">编辑</a>
  1154. <a href="#confirm" onclick="invoiceStoreApproval(\'' . $value['storeKey'] . '\')" data-toggle="modal">提交审批</a>
  1155. <a href="#del" node-iStore="del" data-key="' . $value['storeKey'] . '" onclick="invoiceStoreDel(\'' . $value['storeKey'] . '\')" data-toggle="modal" class="colRed">移除</a>');
  1156. }
  1157. array_push($irDetail, $value['invoiceSerial']);
  1158. if ($value['invoiceType'] == 1)
  1159. array_push($irDetail, $value['invoiceCompany']);
  1160. else
  1161. array_push($irDetail, $value['invoiceTitle']);
  1162. array_push($irDetail, $value['TIN']);
  1163. array_push($irDetail, $value['userName']);
  1164. if (empty($value['mailItems']) && $value['apStatus'] != 1) {
  1165. array_push($irDetail, '<a href="#confirm-erro" onclick="invoiceStoreMail(\'' . $value['storeKey'] . '\')" data-toggle="modal">设置邮寄物品</a>');
  1166. } else
  1167. array_push($irDetail, $value['mailItems']);
  1168. array_push($irDetail, $value['recipientsAddress'] . $value['recipients'] . $value['recipientsPhone']);
  1169. if ($type == 1) {
  1170. array_push($irDetail, $value['electronicPhone']);
  1171. array_push($irDetail, $value['electronicEmail']);
  1172. }
  1173. array_push($irDetail, $value['address'] . $value['phone']);
  1174. array_push($irDetail, $value['bank'] . $value['bankAccount']);
  1175. array_push($irDetail, $value['invoiceElement']);
  1176. array_push($irDetail, $value['invoiceQuantity']);
  1177. array_push($irDetail, $value['invoiceUnitPrice']);
  1178. if ($value['invoiceType'] == 1)
  1179. array_push($irDetail, '¥' . $value['invoicePrice'] . '<sup>专</sup>');
  1180. else
  1181. array_push($irDetail, '¥' . $value['invoicePrice']);
  1182. array_push($irDetail, $value['remark']);
  1183. if ($value['status'] == 1)
  1184. array_push($irDetail, '审批中');
  1185. elseif ($value['status'] == 2 && $value['printStatus'] == 1)
  1186. array_push($irDetail, '已出票');
  1187. elseif ($value['status'] == 2 && $value['printStatus'] == 1 && $value['printStatus'] != 'irid' && ($value['untreadStatus'] == 3 || $value['untreadStatus'] == 0))
  1188. array_push($irDetail, '已入账');
  1189. else
  1190. array_push($irDetail, '');
  1191. array_push($irDetail, $value['invoiceNo']);
  1192. array_push($irDetail, $value['printTime']);
  1193. $html = '';
  1194. foreach ($value['invoiceReceivables'] as $v) {
  1195. $html .= '&nbsp;<a href="#billing" node-invoice="INFO" data-type="receivables" data-iskey="' . $v[2] . '" data-toggle="modal">' . $v[1] . '</a>';
  1196. }
  1197. array_push($irDetail, $html);
  1198. array_push($trainlist, $irDetail);
  1199. }
  1200. $trainlistJson = json_encode($trainlist);
  1201. return $trainlistJson;
  1202. }
  1203. /**
  1204. * 上传培训班发票
  1205. * @return string
  1206. */
  1207. function invoiceTrainingUpload()
  1208. {
  1209. $POST_MAX_SIZE = ini_get('post_max_size');
  1210. $unit = strtoupper(substr($POST_MAX_SIZE, -1));
  1211. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  1212. if ((int) $_SERVER['CONTENT_LENGTH'] > $multiplier * (int) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  1213. header("HTTP/1.1 500 Internal Server Error");
  1214. echo "POST exceeded maximum allowed size.";
  1215. exit(0);
  1216. }
  1217. // Settings
  1218. $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)
  1219. $upload_name = "Filedata";
  1220. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  1221. $extension_whitelist = array(
  1222. "doc",
  1223. "txt",
  1224. "jpg",
  1225. "gif",
  1226. "png"
  1227. ); // Allowed file extensions
  1228. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  1229. // Other variables
  1230. $MAX_FILENAME_LENGTH = 260;
  1231. $file_name = "";
  1232. $file_extension = "";
  1233. $uploadErrors = array(
  1234. 0 => "文件上传成功",
  1235. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  1236. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  1237. 3 => "上传的文件仅为部分文件",
  1238. 4 => "没有文件上传",
  1239. 6 => "缺少临时文件夹"
  1240. );
  1241. $nk = time();
  1242. $file_name = $nk . '.' . $this->_GetFileEXT($_FILES[$upload_name]['name']); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  1243. if (!@move_uploaded_file($_FILES[$upload_name]["tmp_name"], $save_path . $file_name)) {
  1244. echo "文件无法保存.";
  1245. exit(0);
  1246. }
  1247. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  1248. echo json_encode(array(
  1249. 'filename' => $file_name,
  1250. 'id' => $nk
  1251. ));
  1252. exit(0);
  1253. }
  1254. /**
  1255. * 导入发票临时仓库
  1256. */
  1257. function invoiceStoreImport()
  1258. {
  1259. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  1260. $trainingKey = $this->get_args('trainingKey') ? $this->get_args('trainingKey') : "";
  1261. $path = $this->get_args('trainName') ? $this->get_args('trainName') : "";
  1262. if ($path != "" && !empty($trainingKey)) {
  1263. Doo::loadModel('invoiceStore');
  1264. Doo::loadModel('staff');
  1265. $staff = new staff();
  1266. Doo::loadModel('invoiceTraining');
  1267. $invoiceTraining = new invoiceTraining();
  1268. Doo::loadClass('XDeode');
  1269. $XDeode = new XDeode(5);
  1270. $itid = $XDeode->decode($trainingKey);
  1271. // 培训班结算是否有和是否已经结算完成
  1272. Doo::loadModel('receipt');
  1273. $receipt = new receipt();
  1274. $receiptDetail = $receipt->getReceiptByinvoiceTrainId($itid);
  1275. if (!empty($receiptDetail)) {
  1276. if ($receiptDetail['status'] == 8 || $receiptDetail['status'] == 9)
  1277. die('illegal request--status');
  1278. }
  1279. $exlArray = $this->formatExcelToArrayTrain(DOO::conf()->SITE_PATH . "upload/invoiceTraining/" . $path);
  1280. $userName = $this->staff[0]['username'];
  1281. $sDetail = $staff->getStaffByName($userName);
  1282. //print_r($exlArray);die;
  1283. // die('sdd');
  1284. // 可以优化
  1285. foreach ($exlArray as $key => $value) {
  1286. // 开票
  1287. $invoice = new invoiceStore();
  1288. $invoice->trainId = $itid;
  1289. $invoice->invoiceType = 0;
  1290. if ($value['invoiceType'] == '专' || $value['invoiceType'] == '专票')
  1291. $invoice->invoiceType = 1;
  1292. elseif ($value['invoiceType'] == '电子') {
  1293. $invoice->invoiceType = 0;
  1294. $invoice->invoiceForm = 1;
  1295. }
  1296. $invoice->invoiceQuantity = $value['invoiceQuantity'];
  1297. $invoice->invoiceUnitPrice = $value['invoiceUnitPrice'];
  1298. $invoice->invoicePrice = $value['invoiceQuantity'] * $value['invoiceUnitPrice'];
  1299. $invoice->invoiceTitle = $value['invoiceTitle'];
  1300. if ($value['invoiceType'] == '专' || $value['invoiceType'] == '专票')
  1301. $invoice->invoiceCompany = $value['invoiceTitle'];
  1302. $invoice->userName = $userName;
  1303. $invoice->sid = $sDetail['sid'];
  1304. $invoice->cid = $sDetail['cid'];
  1305. $invoice->categoryName = $sDetail['category'];
  1306. $invoice->invoiceElement = $value['invoiceElement'];
  1307. $invoice->remark = $value['remark'];
  1308. // $invoice->date = $value ['date'];
  1309. // $invoice->printTime = $value ['date'];
  1310. $invoice->ipSource = 1;
  1311. $invoice->printStatus = 0;
  1312. $invoice->status = 0;
  1313. $invoice->postStatus = 1;
  1314. $invoice->untreadStatus = 0;
  1315. // $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1316. $invoice->TIN = $value['TIN'];
  1317. $invoice->address = $value['address'];
  1318. $invoice->phone = $value['phone'];
  1319. $invoice->bank = $value['bank'];
  1320. $invoice->bankAccount = $value['bankAccount'];
  1321. $invoice->recipientsAddress = $value['recipientsAddress'];
  1322. $invoice->recipients = $value['recipients'];
  1323. $invoice->recipientsPhone = $value['recipientsPhone'];
  1324. $invoice->electronicPhone = $value['electronicPhone'];
  1325. $invoice->electronicEmail = $value['electronicEmail'];
  1326. $iid = $invoice->insert();
  1327. }
  1328. // 加入发票总数量
  1329. $item = array(
  1330. 'itid' => $itid,
  1331. 'invoiceTotal' => count($exlArray)
  1332. );
  1333. $invoiceTraining->setInvoiceTrainByCondition($item);
  1334. return '/invoiceTrainingDetail/' . $trainingKey . ".html";
  1335. }
  1336. echo 'no file';
  1337. }
  1338. /**
  1339. * 编辑仓库里的发票
  1340. */
  1341. function invoiceStoreEdit()
  1342. {
  1343. Doo::loadClass('XDeode');
  1344. $XDeode = new XDeode(5);
  1345. $iid = isset($this->params['storeKey']) ? $this->params['storeKey'] : "";
  1346. $iid = $XDeode->decode($iid);
  1347. if (!is_numeric($iid))
  1348. die('illegal request');
  1349. Doo::loadModel('invoiceStore');
  1350. $invoiceStore = new invoiceStore();
  1351. $invoiceDetail = $invoiceStore->getInvoiceStoreByIsid($iid);
  1352. // print_r($invoiceDetail);
  1353. $invoiceDetail['mailItemsJson'] = json_decode($invoiceDetail['mailItemsJson'], true);
  1354. $this->data['invoiceDetail'] = $invoiceDetail;
  1355. $this->data['memu'] = "invoice";
  1356. $this->data['staff'] = $this->staff;
  1357. $this->data['receiptMemu'] = 'invoiceTraining';
  1358. $this->render("/admin/invoiceStoreEdit", $this->data);
  1359. }
  1360. function invoiceStoreEditDo()
  1361. {
  1362. $storeKey = $this->get_args('storeKey') ? $this->get_args('storeKey') : '';
  1363. $trainKey = $this->get_args('trainKey') ? $this->get_args('trainKey') : '';
  1364. Doo::loadModel('invoiceStore');
  1365. $invoice = new invoiceStore();
  1366. Doo::loadClass('XDeode');
  1367. $XDeode = new XDeode(5);
  1368. $iid = $XDeode->decode($storeKey);
  1369. if (!empty($iid) && !is_numeric($iid))
  1370. die('illegal request');
  1371. $cid = $this->get_args('cid') ? $this->get_args('cid') : 0;
  1372. $invoiceType = $this->get_args('invoiceType') && is_numeric($this->get_args('invoiceType')) ? $this->get_args('invoiceType') : 0;
  1373. $doPost = $this->get_args('doPost') && is_numeric($this->get_args('doPost')) ? $this->get_args('doPost') : 0;
  1374. $invoicePrice = $this->get_args('invoicePrice') ? $this->get_args('invoicePrice') : "";
  1375. $invoiceQuantity = $this->get_args('invoiceQuantity') && is_numeric($this->get_args('invoiceQuantity')) ? $this->get_args('invoiceQuantity') : 0;
  1376. $invoiceUnitPrice = $this->get_args('invoiceUnitPrice') && is_numeric($this->get_args('invoiceUnitPrice')) ? $this->get_args('invoiceUnitPrice') : 0;
  1377. $invoiceElement = $this->get_args('invoiceElement') ? $this->get_args('invoiceElement') : "";
  1378. $invoiceTitle = $this->get_args('invoiceTitle') ? $this->get_args('invoiceTitle') : "";
  1379. $invoiceCompany = $this->get_args('invoiceCompany') ? $this->get_args('invoiceCompany') : "";
  1380. $TIN = $this->get_args('TIN') ? $this->get_args('TIN') : "";
  1381. $address = $this->get_args('address') ? $this->get_args('address') : "";
  1382. $phone = $this->get_args('phone') ? $this->get_args('phone') : "";
  1383. $bank = $this->get_args('bank') ? $this->get_args('bank') : "";
  1384. $bankAccount = $this->get_args('bankAccount') ? $this->get_args('bankAccount') : "";
  1385. $recipients = $this->get_args('recipients') ? $this->get_args('recipients') : "";
  1386. $recipientsPhone = $this->get_args('recipientsPhone') ? $this->get_args('recipientsPhone') : "";
  1387. $recipientsAddress = $this->get_args('recipientsAddress') ? $this->get_args('recipientsAddress') : "";
  1388. $mailItems = $this->get_args('mailItems') ? $this->get_args('mailItems') : "";
  1389. $remark = $this->get_args('remark') ? $this->get_args('remark') : "";
  1390. $TINT = $this->get_args('TINT') ? $this->get_args('TINT') : "";
  1391. $addressT = $this->get_args('addressT') ? $this->get_args('addressT') : "";
  1392. $phoneT = $this->get_args('phoneT') ? $this->get_args('phoneT') : "";
  1393. $bankT = $this->get_args('bankT') ? $this->get_args('bankT') : "";
  1394. $bankAccountT = $this->get_args('bankAccountT') ? $this->get_args('bankAccountT') : "";
  1395. $softLock = $this->get_args('softLock') ? $this->get_args('softLock') : 0;
  1396. $softLockNum = $this->get_args('softLockNum') ? $this->get_args('softLockNum') : 0;
  1397. $contract = $this->get_args('contract') ? $this->get_args('contract') : 0;
  1398. $contractNum = $this->get_args('contractNum') ? $this->get_args('contractNum') : 0;
  1399. $instructions = $this->get_args('instructions') ? $this->get_args('instructions') : 0;
  1400. $instructionsNum = $this->get_args('instructionsNum') ? $this->get_args('instructionsNum') : 0;
  1401. $remittance = $this->get_args('remittance') ? $this->get_args('remittance') : 0;
  1402. $electronicPhone = $this->get_args('electronicPhone') ? $this->get_args('electronicPhone') : "";
  1403. $electronicEmail = $this->get_args('electronicEmail') ? $this->get_args('electronicEmail') : "";
  1404. $invoiceForm = $this->get_args('invoiceForm') ? $this->get_args('invoiceForm') : "";
  1405. if (!empty($cid) && !empty($invoiceQuantity) && !empty($invoiceUnitPrice) && !empty($invoiceElement) && !empty($iid)) {
  1406. $cid = explode(':', $cid);
  1407. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  1408. $item = array(
  1409. 'isid' => $iid,
  1410. 'cid' => $cid[0],
  1411. 'categoryName' => $cid[1],
  1412. 'invoiceElement' => $invoiceElement,
  1413. 'invoiceQuantity' => $invoiceQuantity,
  1414. 'invoiceUnitPrice' => $invoiceUnitPrice,
  1415. 'invoicePrice' => $invoicePrice,
  1416. 'invoiceType' => $invoiceType,
  1417. 'doPost' => $doPost,
  1418. 'status' => 1,
  1419. 'updateTime' => date("Y-m-d H:i:s"),
  1420. 'remark' => $remark
  1421. );
  1422. if ($invoiceType == 0)
  1423. $item += array(
  1424. 'invoiceTitle' => $invoiceTitle,
  1425. 'TIN' => $TINT,
  1426. 'address' => $addressT,
  1427. 'phone' => $phoneT,
  1428. 'bank' => $bankT,
  1429. 'bankAccount' => $bankAccountT
  1430. );
  1431. else {
  1432. $item += array(
  1433. 'invoiceCompany' => $invoiceCompany,
  1434. 'TIN' => $TIN,
  1435. 'address' => $address,
  1436. 'phone' => $phone,
  1437. 'bank' => $bank,
  1438. 'bankAccount' => $bankAccount
  1439. );
  1440. }
  1441. if ($invoiceForm == 'paper') {
  1442. $item += array(
  1443. 'invoiceForm' => 0
  1444. );
  1445. } elseif ($invoiceForm == 'electronic') {
  1446. $item += array(
  1447. 'invoiceForm' => 1,
  1448. 'electronicPhone' => $electronicPhone,
  1449. 'electronicEmail' => $electronicEmail,
  1450. );
  1451. }
  1452. if ($doPost == 1) {
  1453. $mailList = array(
  1454. 'invoice' => 1,
  1455. 'mailItems' => $mailItems
  1456. );
  1457. if (!empty($softLock))
  1458. $mailList += array(
  1459. 'softLock' => $softLockNum
  1460. );
  1461. else
  1462. $mailList += array(
  1463. 'softLock' => '0'
  1464. );
  1465. if (!empty($contract))
  1466. $mailList += array(
  1467. 'contract' => $contractNum
  1468. );
  1469. else
  1470. $mailList += array(
  1471. 'contract' => '0'
  1472. );
  1473. if (!empty($instructions))
  1474. $mailList += array(
  1475. 'instructions' => $instructionsNum
  1476. );
  1477. else
  1478. $mailList += array(
  1479. 'instructions' => '0'
  1480. );
  1481. if (!empty($remittance))
  1482. $mailList += array(
  1483. 'remittance' => $remittance
  1484. );
  1485. else
  1486. $mailList += array(
  1487. 'remittance' => ''
  1488. );
  1489. $mailString = '发票x1,备注:' . $mailItems;
  1490. if (!empty($softLock))
  1491. $mailString .= ',软件锁x' . $softLockNum;
  1492. if (!empty($contract))
  1493. $mailString .= ',合同x' . $contractNum;
  1494. if (!empty($instructions))
  1495. $mailString .= ',说明书x' . $instructionsNum;
  1496. if (!empty($remittance))
  1497. $mailString .= ',汇款账号单';
  1498. $item += array(
  1499. 'recipients' => $recipients,
  1500. 'recipientsPhone' => $recipientsPhone,
  1501. 'recipientsAddress' => $recipientsAddress,
  1502. 'mailItems' => $mailString,
  1503. 'mailItemsJson' => json_encode($mailList)
  1504. );
  1505. }
  1506. $invoice->setInvoiceStoreByCondition($item);
  1507. }
  1508. if (!empty($invoiceForm) && $invoiceForm == 'electronic') {
  1509. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1510. } else {
  1511. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1512. }
  1513. }
  1514. /**
  1515. *
  1516. * @return string
  1517. */
  1518. function invoiceStoreDelete()
  1519. {
  1520. Doo::loadClass('XDeode');
  1521. $XDeode = new XDeode(5);
  1522. $trainKey = $this->get_args('trainKey') ? $this->get_args('trainKey') : '';
  1523. $iStoreKey = $this->get_args('iStoreKey') ? $this->get_args('iStoreKey') : 0;
  1524. $invoiceFrom = $this->get_args('invoiceFrom') ? $this->get_args('invoiceFrom') : "";
  1525. $isid = $XDeode->decode($iStoreKey);
  1526. $itid = $XDeode->decode($trainKey);
  1527. if (!is_numeric($isid))
  1528. die('illegal request');
  1529. Doo::loadModel('invoiceStore');
  1530. $invoiceStore = new invoiceStore();
  1531. $invoiceStore->delete(array(
  1532. 'where' => 'isid=' . $isid,
  1533. 'limit' => 1
  1534. ));
  1535. Doo::loadModel('invoiceTraining');
  1536. $invoiceTraining = new invoiceTraining();
  1537. $itDetail = $invoiceTraining->getInvoiceTrainingByItid($trainKey);
  1538. $item = array(
  1539. 'itid' => $itid,
  1540. 'invoiceTotal' => $itDetail['invoiceTotal'] - 1
  1541. );
  1542. $invoiceTraining->setInvoiceTrainByCondition($item);
  1543. if (!empty($invoiceFrom) && $invoiceFrom == 'electronic') {
  1544. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1545. } else {
  1546. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1547. }
  1548. }
  1549. /**
  1550. * 批量删除库里发票
  1551. */
  1552. function invoiceStoreBatchDelete()
  1553. {
  1554. Doo::loadClass('XDeode');
  1555. $XDeode = new XDeode(5);
  1556. $trainKey = $this->get_args('trainKey') ? $this->get_args('trainKey') : '';
  1557. $storeKey = $this->get_args('storeKey') ? $this->get_args('storeKey') : '';
  1558. $invoiceFrom = $this->get_args('invoiceFrom') ? $this->get_args('invoiceFrom') : "";
  1559. if (empty($trainKey) || empty($storeKey))
  1560. die('illegal request-IdKey');
  1561. $tid = $XDeode->decode($trainKey);
  1562. if (!is_numeric($tid) && !empty($storeKey))
  1563. die('illegal request');
  1564. Doo::loadModel('invoiceStore');
  1565. $isidKeyList = explode(',', $storeKey);
  1566. $isidList = array();
  1567. foreach ($isidKeyList as $value) {
  1568. $isid = $XDeode->decode($value);
  1569. if (!empty($isid) && is_numeric($isid))
  1570. array_push($isidList, $isid);
  1571. }
  1572. $isidString = implode(',', $isidList);
  1573. $invoiceStore = new invoiceStore();
  1574. $isList = $invoiceStore->getInvoiceStoreInIsid($isidString, 'isid,apStatus');
  1575. $isidList = array();
  1576. foreach ($isList as $key => $value) {
  1577. if ($value['apStatus'] == 0)
  1578. array_push($isidList, $value['isid']);
  1579. }
  1580. $isidString = implode(',', $isidList);
  1581. // print_r($isList);
  1582. // echo $isidString;
  1583. $invoiceStore = new invoiceStore();
  1584. $invoiceStore->delete(array(
  1585. 'where' => "isid in ( " . $isidString . ")",
  1586. 'asArray' => TRUE
  1587. ));
  1588. Doo::loadModel('invoiceTraining');
  1589. $invoiceTraining = new invoiceTraining();
  1590. $itDetail = $invoiceTraining->getInvoiceTrainingByItid($trainKey);
  1591. $item = array(
  1592. 'itid' => $tid,
  1593. 'invoiceTotal' => $itDetail['invoiceTotal'] - count($isidList)
  1594. );
  1595. $invoiceTraining->setInvoiceTrainByCondition($item);
  1596. // echo $tid;
  1597. // echo $storeKey;
  1598. if (!empty($invoiceFrom) && $invoiceFrom == 'electronic') {
  1599. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1600. } else {
  1601. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1602. }
  1603. }
  1604. function invoiceStoreBatchElectronicPhone()
  1605. {
  1606. $electronicPhone = $this->get_args('electronicPhone') ? $this->get_args('electronicPhone') : '';
  1607. $invoiceFrom = $this->get_args('invoiceFrom') ? $this->get_args('invoiceFrom') : "";
  1608. Doo::loadClass('XDeode');
  1609. $XDeode = new XDeode(5);
  1610. $trainKey = $this->get_args('trainKey') ? $this->get_args('trainKey') : '';
  1611. $storeKey = $this->get_args('storeKey') ? $this->get_args('storeKey') : '';
  1612. if (empty($trainKey) || empty($storeKey))
  1613. die('illegal request-IdKey');
  1614. $isidKeyList = explode(',', $storeKey);
  1615. $isidList = array();
  1616. foreach ($isidKeyList as $value) {
  1617. $isid = $XDeode->decode($value);
  1618. if (!empty($isid) && is_numeric($isid))
  1619. array_push($isidList, $isid);
  1620. }
  1621. $isidString = implode(',', $isidList);
  1622. $trainId = $XDeode->decode($trainKey);
  1623. if (!is_numeric($isid))
  1624. die('illegal request--isid');
  1625. Doo::loadModel('invoiceStore');
  1626. $invoiceStore = new invoiceStore();
  1627. $item = array(
  1628. 'electronicPhone' => $electronicPhone
  1629. );
  1630. $invoiceStore->setInvoiceStoreByCondition($item, $isidString);
  1631. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1632. }
  1633. function invoiceStoreBatchElectronicEmail()
  1634. {
  1635. $electronicEmail = $this->get_args('electronicEmail') ? $this->get_args('electronicEmail') : '';
  1636. $invoiceFrom = $this->get_args('invoiceFrom') ? $this->get_args('invoiceFrom') : "";
  1637. Doo::loadClass('XDeode');
  1638. $XDeode = new XDeode(5);
  1639. $trainKey = $this->get_args('trainKey') ? $this->get_args('trainKey') : '';
  1640. $storeKey = $this->get_args('storeKey') ? $this->get_args('storeKey') : '';
  1641. if (empty($trainKey) || empty($storeKey))
  1642. die('illegal request-IdKey');
  1643. $isidKeyList = explode(',', $storeKey);
  1644. $isidList = array();
  1645. foreach ($isidKeyList as $value) {
  1646. $isid = $XDeode->decode($value);
  1647. if (!empty($isid) && is_numeric($isid))
  1648. array_push($isidList, $isid);
  1649. }
  1650. $isidString = implode(',', $isidList);
  1651. $trainId = $XDeode->decode($trainKey);
  1652. if (!is_numeric($isid))
  1653. die('illegal request');
  1654. Doo::loadModel('invoiceStore');
  1655. $invoiceStore = new invoiceStore();
  1656. $item = array(
  1657. 'electronicEmail' => $electronicEmail
  1658. );
  1659. $invoiceStore->setInvoiceStoreByCondition($item, $isidString);
  1660. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1661. }
  1662. /**
  1663. * 仓库发票提交审批
  1664. * @return string
  1665. */
  1666. function invoiceStoreApproval()
  1667. {
  1668. Doo::loadClass('XDeode');
  1669. $XDeode = new XDeode(5);
  1670. $trainKey = $this->get_args('trainKey') ? $this->get_args('trainKey') : '';
  1671. $iStoreKey = $this->get_args('storeKey') ? $this->get_args('storeKey') : 0;
  1672. $invoiceFrom = $this->get_args('invoiceFrom') ? $this->get_args('invoiceFrom') : "";
  1673. $isid = $XDeode->decode($iStoreKey);
  1674. $trainId = $XDeode->decode($trainKey);
  1675. if (!is_numeric($isid))
  1676. die('illegal request');
  1677. Doo::loadModel('invoiceStore');
  1678. Doo::loadModel('invoice');
  1679. $invoice = new invoice();
  1680. // 加入限制必须填写入开票内容和邮寄物品
  1681. $invoiceStore = new invoiceStore();
  1682. $isDetail = $invoiceStore->getInvoiceStoreByIsid($isid, 'isid,trainId ,invoiceElement,mailItemsJson,electronicPhone,electronicEmail');
  1683. if (empty($isDetail['invoiceElement']) || empty($isDetail['mailItemsJson'])) {
  1684. header('Content-Type:text/html;charset=utf-8');
  1685. die('illegal request! 请设置开票内容或邮寄物品');
  1686. }
  1687. if (!empty($invoiceFrom) && $invoiceFrom == 'electronic') {
  1688. if (empty($isDetail['electronicPhone']) && empty($isDetail['electronicEmail'])) {
  1689. header('Content-Type:text/html;charset=utf-8');
  1690. die('illegal request! 请设置电子开票的收件人手机或者邮箱');
  1691. }
  1692. }
  1693. // 拷贝插入一条发票数据
  1694. $invoiceStore = new invoiceStore();
  1695. $iid = $invoiceStore->setInvoiceStoreToApproval($isid);
  1696. $invoiceStore = new invoiceStore();
  1697. $item = array(
  1698. 'isid' => $isid,
  1699. 'iid' => $iid,
  1700. 'apStatus' => 1
  1701. );
  1702. $invoiceStore->setInvoiceStoreByCondition($item);
  1703. Doo::loadModel('invoiceManage');
  1704. $invoiceManage = new invoiceManage();
  1705. Doo::loadModel('invoiceOperationLog');
  1706. $invoiceOperationLog = new invoiceOperationLog();
  1707. $invoiceManageList = $invoiceManage->getInvoiceByAll();
  1708. $invoiceManageDetail = $invoiceManage->getInvoiceByMold("发票审批");
  1709. $moldManage = array();
  1710. foreach ($invoiceManageList as $key => $value) {
  1711. if ($value['mold'] == '发票打印')
  1712. $moldManage[$value['mold']] = $value['staffList'];
  1713. elseif ($value['mold'] == '发票邮寄')
  1714. $moldManage[$value['mold']] = $value['staffList'];
  1715. elseif ($value['mold'] == '发票退票')
  1716. $moldManage[$value['mold']] = $value['staffList'];
  1717. }
  1718. $pendingApprovalsSid = current($invoiceManageDetail['staffList'])[0];
  1719. if (!empty($invoiceFrom) && $invoiceFrom == 'electronic') {
  1720. $invoiceSerial = "#FE" . date("Ymd") . mt_rand(1000, 9999);
  1721. } else {
  1722. $invoiceSerial = "#F" . date("Ymd") . mt_rand(1000, 9999);
  1723. }
  1724. $item = array(
  1725. 'iid' => $iid,
  1726. 'isid' => $isid,
  1727. 'invoiceSerial' => $invoiceSerial,
  1728. 'date' => date("Y-m-d H:i:s"),
  1729. 'status' => 1,
  1730. 'updateTime' => date("Y-m-d H:i:s"),
  1731. 'trainId' => $trainId,
  1732. 'invoiceManage' => $invoiceManageDetail['staff'],
  1733. 'moldManage' => json_encode($moldManage),
  1734. 'settlementType' => 1,
  1735. 'pendingApprovals' => $pendingApprovalsSid
  1736. );
  1737. $invoice->setInvoiceByCondition($item);
  1738. Doo::loadModel('invoiceTraining');
  1739. $invoiceTraining = new invoiceTraining();
  1740. $item = array(
  1741. 'itid' => $trainId,
  1742. 'submitStatus' => 1
  1743. );
  1744. $invoiceTraining->setInvoiceTrainByCondition($item);
  1745. $item = array(
  1746. 'date' => date("Y-m-d H:i:s"),
  1747. 'operation' => "创建",
  1748. 'status' => 1,
  1749. 'img' => $this->staff[0]['avatar'],
  1750. 'username' => $this->staff[0]['username'],
  1751. 'uid' => $this->staff[0]['sid'],
  1752. 'category' => $this->staff[0]['category'],
  1753. 'iid' => $iid
  1754. );
  1755. $invoiceOperationLog->setInvoiceOperationLog($item);
  1756. $item = array(
  1757. 'date' => date("Y-m-d H:i:s"),
  1758. 'operation' => "提交审批",
  1759. 'status' => 1,
  1760. 'img' => $this->staff[0]['avatar'],
  1761. 'username' => $this->staff[0]['username'],
  1762. 'uid' => $this->staff[0]['sid'],
  1763. 'category' => $this->staff[0]['category'],
  1764. 'iid' => $iid
  1765. );
  1766. $invoiceOperationLog->setInvoiceOperationLog($item);
  1767. Doo::loadModel('staff');
  1768. $staff = new staff();
  1769. $username2 = $staff->getOne(array(
  1770. 'select' => 'wxid',
  1771. 'where' => 'sid=' . $pendingApprovalsSid,
  1772. 'asArray' => TRUE
  1773. ));
  1774. // 发送微信审批通知
  1775. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1776. $this->msgSend('', $title2, '', $username2['wxid'], $pendingApprovalsSid, 'approval');
  1777. if (!empty($invoiceFrom) && $invoiceFrom == 'electronic') {
  1778. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1779. } else {
  1780. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1781. }
  1782. }
  1783. /**
  1784. * 批量提交发票
  1785. * @return string
  1786. */
  1787. function invoiceStoreBatchApproval()
  1788. {
  1789. Doo::loadClass('XDeode');
  1790. $XDeode = new XDeode(5);
  1791. $trainKey = $this->get_args('trainKey') ? $this->get_args('trainKey') : '';
  1792. $storeKey = $this->get_args('storeKey') ? $this->get_args('storeKey') : 0;
  1793. $invoiceFrom = $this->get_args('invoiceFrom') ? $this->get_args('invoiceFrom') : '';
  1794. if (empty($trainKey) || empty($storeKey))
  1795. die('illegal request-IdKey');
  1796. $trainId = $XDeode->decode($trainKey);
  1797. $isidKeyList = explode(',', $storeKey);
  1798. $isidList = array();
  1799. foreach ($isidKeyList as $value) {
  1800. $isid = $XDeode->decode($value);
  1801. if (!empty($isid) && is_numeric($isid))
  1802. array_push($isidList, $isid);
  1803. }
  1804. $isidString = implode(',', $isidList);
  1805. if (!is_numeric($trainId))
  1806. die('illegal request');
  1807. Doo::loadModel('invoiceStore');
  1808. Doo::loadModel('invoice');
  1809. // 判断哪些已经加入审批过
  1810. // 加入限制必须填写入开票内容和邮寄物品
  1811. $invoiceStore = new invoiceStore();
  1812. $isList = $invoiceStore->getInvoiceStoreInIsid($isidString, 'isid,trainId ,invoiceElement,mailItemsJson,electronicPhone,electronicEmail,invoiceForm');
  1813. foreach ($isList as $key => $value) {
  1814. if (empty($value['invoiceElement']) || empty($value['mailItemsJson'])) {
  1815. header('Content-Type:text/html;charset=utf-8');
  1816. die('illegal request! 请设置开票内容或邮寄物品');
  1817. }
  1818. if (!empty($invoiceFrom) && $invoiceFrom == 'electronic') {
  1819. $value['electronicPhone'] = trim($value['electronicPhone']);
  1820. $value['electronicEmail'] = trim($value['electronicEmail']);
  1821. if (empty($value['electronicPhone']) && empty($value['electronicEmail'])) {
  1822. header('Content-Type:text/html;charset=utf-8');
  1823. die('illegal request! 请设置电子开票的收件人手机或者邮箱');
  1824. }
  1825. }
  1826. }
  1827. // 拷贝插入一条发票数据
  1828. $invoiceStore = new invoiceStore();
  1829. $invoiceStore->setInvoiceStoreBatchToApproval($isidString);
  1830. $invoiceStore = new invoiceStore();
  1831. $item = array(
  1832. 'apStatus' => 1
  1833. );
  1834. $invoiceStore->setInvoiceStoreByCondition($item, $isidString);
  1835. // 获得正式发票ID
  1836. $invoice = new invoice();
  1837. $iidList = $invoice->getInvoiceByIstoreid($isidString, 'iid,isid');
  1838. $sqlList = array();
  1839. $iidString = '';
  1840. $iida = array();
  1841. foreach ($iidList as $key => $value) {
  1842. $sqlList[$value['isid']] = $value['iid'];
  1843. array_push($iida, $value['iid']);
  1844. }
  1845. $iidString = implode(',', $iida);
  1846. $ids = implode(',', array_keys($sqlList));
  1847. $sql = "UPDATE CLD_invoiceStore SET iid = CASE isid ";
  1848. foreach ($sqlList as $id => $ordinal) {
  1849. $sql .= sprintf("WHEN %d THEN %d ", $id, $ordinal);
  1850. }
  1851. $sql .= "END WHERE isid IN ($ids)";
  1852. $invoiceStore = new invoiceStore();
  1853. $invoiceStore->UpdateBatchInvoiceStore($sql);
  1854. Doo::loadModel('invoiceManage');
  1855. $invoiceManage = new invoiceManage();
  1856. $invoiceManageList = $invoiceManage->getInvoiceByAll();
  1857. $invoiceManageDetail = $invoiceManage->getInvoiceByMold("发票审批");
  1858. $moldManage = array();
  1859. foreach ($invoiceManageList as $key => $value) {
  1860. if ($value['mold'] == '发票打印')
  1861. $moldManage[$value['mold']] = $value['staffList'];
  1862. elseif ($value['mold'] == '发票邮寄')
  1863. $moldManage[$value['mold']] = $value['staffList'];
  1864. elseif ($value['mold'] == '发票退票')
  1865. $moldManage[$value['mold']] = $value['staffList'];
  1866. }
  1867. $pendingApprovalsSid = current($invoiceManageDetail['staffList'])[0];
  1868. // 批量更新发票信息
  1869. $item = array(
  1870. 'date' => date("Y-m-d H:i:s"),
  1871. 'status' => 1,
  1872. 'updateTime' => date("Y-m-d H:i:s"),
  1873. 'trainId' => $trainId,
  1874. 'invoiceManage' => $invoiceManageDetail['staff'],
  1875. 'moldManage' => json_encode($moldManage),
  1876. 'settlementType' => 1,
  1877. 'pendingApprovals' => $pendingApprovalsSid
  1878. );
  1879. $invoice = new invoice();
  1880. $invoice->BatchInvoiceByCondition($item, $iidString);
  1881. // 批量更新发票中仓库isid
  1882. $sql = "UPDATE CLD_invoiceStore SET isid = CASE iid ";
  1883. foreach ($sqlList as $isid => $iid) {
  1884. $sql .= sprintf("WHEN %d THEN %d ", $iid, $isid);
  1885. }
  1886. $sql .= "END WHERE iid IN ($iidString)";
  1887. $invoice = new invoice();
  1888. $invoice->UpdateBatchInvoice($sql);
  1889. // 批量更新发票序列号
  1890. $sqlList = array();
  1891. foreach ($iida as $value) {
  1892. if (!empty($invoiceFrom) && $invoiceFrom == 'electronic') {
  1893. $sqlList[$value] = "#FE" . date("Ymd") . mt_rand(1000, 9999);
  1894. } else {
  1895. $sqlList[$value] = "#F" . date("Ymd") . mt_rand(1000, 9999);
  1896. }
  1897. }
  1898. $ids = implode(',', array_keys($sqlList));
  1899. $sql = "UPDATE CLD_invoice SET invoiceSerial = CASE iid ";
  1900. foreach ($sqlList as $id => $ordinal) {
  1901. $sql .= sprintf("WHEN %d THEN '%s' ", $id, $ordinal);
  1902. }
  1903. $sql .= "END WHERE iid IN ($ids)";
  1904. $invoiceStore = new invoiceStore();
  1905. $invoiceStore->UpdateBatchInvoiceStore($sql);
  1906. // 批量生产操作日志
  1907. Doo::loadModel('invoiceOperationLog');
  1908. $sqlList = array();
  1909. foreach ($iida as $key => $value) {
  1910. $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 . '"),
  1911. ("' . 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 . '") ';
  1912. array_push($sqlList, $sql);
  1913. }
  1914. $iolSql = implode(',', $sqlList);
  1915. $sql = "INSERT INTO `CLD_invoiceOperationLog` (`date`, `operation`, `status`, `img`, `username`, `uid`, `category`, `iid`) VALUES " . $iolSql;
  1916. $invoiceOperationLog = new invoiceOperationLog();
  1917. $invoiceOperationLog->setInvoiceOperationLogBySql($sql);
  1918. Doo::loadModel('invoiceTraining');
  1919. $invoiceTraining = new invoiceTraining();
  1920. $item = array(
  1921. 'itid' => $trainId,
  1922. 'submitStatus' => 1
  1923. );
  1924. $invoiceTraining->setInvoiceTrainByCondition($item);
  1925. Doo::loadModel('staff');
  1926. $staff = new staff();
  1927. $username2 = $staff->getOne(array(
  1928. 'select' => 'wxid',
  1929. 'where' => 'sid=' . $pendingApprovalsSid,
  1930. 'asArray' => TRUE
  1931. ));
  1932. // 发送微信审批通知
  1933. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1934. $this->msgSend('', $title2, '', $username2['wxid'], $pendingApprovalsSid, 'approval');
  1935. if (!empty($invoiceFrom) && $invoiceFrom == 'electronic') {
  1936. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1937. } else {
  1938. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1939. }
  1940. }
  1941. /**
  1942. */
  1943. function invoiceStoreMailItemSet()
  1944. {
  1945. $softLock = $this->get_args('softLock') ? $this->get_args('softLock') : 0;
  1946. $softLockNum = $this->get_args('softLockNum') ? $this->get_args('softLockNum') : 0;
  1947. $contract = $this->get_args('contract') ? $this->get_args('contract') : 0;
  1948. $contractNum = $this->get_args('contractNum') ? $this->get_args('contractNum') : 0;
  1949. $instructions = $this->get_args('instructions') ? $this->get_args('instructions') : 0;
  1950. $instructionsNum = $this->get_args('instructionsNum') ? $this->get_args('instructionsNum') : 0;
  1951. $remittance = $this->get_args('remittance') ? $this->get_args('remittance') : 0;
  1952. $mailItems = $this->get_args('mailItems') ? $this->get_args('mailItems') : "";
  1953. $recipients = $this->get_args('recipients') ? $this->get_args('recipients') : "";
  1954. $recipientsPhone = $this->get_args('recipientsPhone') ? $this->get_args('recipientsPhone') : "";
  1955. $recipientsAddress = $this->get_args('recipientsAddress') ? $this->get_args('recipientsAddress') : "";
  1956. $invoiceFrom = $this->get_args('invoiceFrom') ? $this->get_args('invoiceFrom') : "";
  1957. Doo::loadClass('XDeode');
  1958. $XDeode = new XDeode(5);
  1959. $trainKey = $this->get_args('trainKey') ? $this->get_args('trainKey') : '';
  1960. $storeKey = $this->get_args('storeKey') ? $this->get_args('storeKey') : '';
  1961. $isid = $XDeode->decode($storeKey);
  1962. $trainId = $XDeode->decode($trainKey);
  1963. if (!is_numeric($isid))
  1964. die('illegal request');
  1965. Doo::loadModel('invoiceStore');
  1966. $invoiceStore = new invoiceStore();
  1967. $mailList = array(
  1968. 'mailItems' => $mailItems
  1969. );
  1970. $mailString = '发票x1,备注:' . $mailItems;
  1971. if (!empty($invoiceFrom) && $invoiceFrom == 'electronic') {
  1972. $mailString = '备注:' . $mailItems;
  1973. } else {
  1974. $mailList += array(
  1975. 'invoice' => 1,
  1976. );
  1977. }
  1978. if (!empty($softLock))
  1979. $mailList += array(
  1980. 'softLock' => $softLockNum
  1981. );
  1982. else
  1983. $mailList += array(
  1984. 'softLock' => 0
  1985. );
  1986. if (!empty($contract))
  1987. $mailList += array(
  1988. 'contract' => $contractNum
  1989. );
  1990. else
  1991. $mailList += array(
  1992. 'contract' => 0
  1993. );
  1994. if (!empty($instructions))
  1995. $mailList += array(
  1996. 'instructions' => $instructionsNum
  1997. );
  1998. else
  1999. $mailList += array(
  2000. 'instructions' => 0
  2001. );
  2002. if (!empty($remittance))
  2003. $mailList += array(
  2004. 'remittance' => $remittance
  2005. );
  2006. else
  2007. $mailList += array(
  2008. 'remittance' => ''
  2009. );
  2010. if (!empty($softLock))
  2011. $mailString .= ',软件锁x' . $softLockNum;
  2012. if (!empty($contract))
  2013. $mailString .= ',合同x' . $contractNum;
  2014. if (!empty($instructions))
  2015. $mailString .= ',说明书x' . $instructionsNum;
  2016. if (!empty($remittance))
  2017. $mailString .= ',汇款账号单';
  2018. $item = array(
  2019. 'isid' => $isid,
  2020. 'doPost' => 1,
  2021. 'mailItems' => $mailString,
  2022. 'mailItemsJson' => json_encode($mailList)
  2023. );
  2024. $invoiceStore->setInvoiceStoreByCondition($item);
  2025. if (!empty($invoiceFrom) && $invoiceFrom == 'electronic') {
  2026. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  2027. } else {
  2028. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  2029. }
  2030. }
  2031. /**
  2032. * 批量设置邮寄物品
  2033. */
  2034. function invoiceStoreBatchMailItemSet()
  2035. {
  2036. $softLock = $this->get_args('softLock') ? $this->get_args('softLock') : 0;
  2037. $softLockNum = $this->get_args('softLockNum') ? $this->get_args('softLockNum') : 0;
  2038. $contract = $this->get_args('contract') ? $this->get_args('contract') : 0;
  2039. $contractNum = $this->get_args('contractNum') ? $this->get_args('contractNum') : 0;
  2040. $instructions = $this->get_args('instructions') ? $this->get_args('instructions') : 0;
  2041. $instructionsNum = $this->get_args('instructionsNum') ? $this->get_args('instructionsNum') : 0;
  2042. $remittance = $this->get_args('remittance') ? $this->get_args('remittance') : 0;
  2043. $mailItems = $this->get_args('mailItems') ? $this->get_args('mailItems') : "";
  2044. $recipients = $this->get_args('recipients') ? $this->get_args('recipients') : "";
  2045. $recipientsPhone = $this->get_args('recipientsPhone') ? $this->get_args('recipientsPhone') : "";
  2046. $recipientsAddress = $this->get_args('recipientsAddress') ? $this->get_args('recipientsAddress') : "";
  2047. $invoiceFrom = $this->get_args('invoiceFrom') ? $this->get_args('invoiceFrom') : "";
  2048. Doo::loadClass('XDeode');
  2049. $XDeode = new XDeode(5);
  2050. $trainKey = $this->get_args('trainKey') ? $this->get_args('trainKey') : '';
  2051. $storeKey = $this->get_args('storeKey') ? $this->get_args('storeKey') : '';
  2052. if (empty($trainKey) || empty($storeKey))
  2053. die('illegal request-IdKey');
  2054. $isidKeyList = explode(',', $storeKey);
  2055. $isidList = array();
  2056. foreach ($isidKeyList as $value) {
  2057. $isid = $XDeode->decode($value);
  2058. if (!empty($isid) && is_numeric($isid))
  2059. array_push($isidList, $isid);
  2060. }
  2061. $isidString = implode(',', $isidList);
  2062. $trainId = $XDeode->decode($trainKey);
  2063. if (!is_numeric($isid))
  2064. die('illegal request');
  2065. Doo::loadModel('invoiceStore');
  2066. $invoiceStore = new invoiceStore();
  2067. $mailList = array(
  2068. 'mailItems' => $mailItems
  2069. );
  2070. $mailString = '发票x1,备注:' . $mailItems;
  2071. if (!empty($invoiceFrom) && $invoiceFrom == 'electronic') {
  2072. $mailString = '备注:' . $mailItems;
  2073. } else {
  2074. $mailList += array(
  2075. 'invoice' => 1,
  2076. );
  2077. }
  2078. if (!empty($softLock))
  2079. $mailList += array(
  2080. 'softLock' => $softLockNum
  2081. );
  2082. else
  2083. $mailList += array(
  2084. 'softLock' => 0
  2085. );
  2086. if (!empty($contract))
  2087. $mailList += array(
  2088. 'contract' => $contractNum
  2089. );
  2090. else
  2091. $mailList += array(
  2092. 'contract' => 0
  2093. );
  2094. if (!empty($instructions))
  2095. $mailList += array(
  2096. 'instructions' => $instructionsNum
  2097. );
  2098. else
  2099. $mailList += array(
  2100. 'instructions' => 0
  2101. );
  2102. if (!empty($remittance))
  2103. $mailList += array(
  2104. 'remittance' => $remittance
  2105. );
  2106. else
  2107. $mailList += array(
  2108. 'remittance' => ''
  2109. );
  2110. if (!empty($softLock))
  2111. $mailString .= ',软件锁x' . $softLockNum;
  2112. if (!empty($contract))
  2113. $mailString .= ',合同x' . $contractNum;
  2114. if (!empty($instructions))
  2115. $mailString .= ',说明书x' . $instructionsNum;
  2116. if (!empty($remittance))
  2117. $mailString .= ',汇款账号单';
  2118. $item = array(
  2119. 'doPost' => 1,
  2120. 'mailItems' => $mailString,
  2121. 'mailItemsJson' => json_encode($mailList)
  2122. );
  2123. $invoiceStore->setInvoiceStoreByCondition($item, $isidString);
  2124. if (!empty($invoiceFrom) && $invoiceFrom == 'electronic') {
  2125. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  2126. } else {
  2127. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  2128. }
  2129. }
  2130. /**
  2131. * 废弃
  2132. */
  2133. function ajaxGetMailItemByIstore()
  2134. {
  2135. Doo::loadClass('XDeode');
  2136. $XDeode = new XDeode(5);
  2137. $storeKey = $this->get_args('storeKey') ? $this->get_args('storeKey') : '';
  2138. $isid = $XDeode->decode($storeKey);
  2139. if (!is_numeric($isid))
  2140. die('illegal request');
  2141. Doo::loadModel('invoiceStore');
  2142. $invoiceStore = new invoiceStore();
  2143. $isDetail = $invoiceStore->getInvoiceStoreByIsid($isid);
  2144. $isDetail['mailItemsJson'] = json_decode($isDetail['mailItemsJson'], true);
  2145. echo json_encode($isDetail['mailItemsJson']);
  2146. exit();
  2147. }
  2148. /**
  2149. * 终止开票
  2150. */
  2151. function invoiceDroppedDo()
  2152. {
  2153. $droppedIidKey = $this->get_args('droppedIidKey') ? $this->get_args('droppedIidKey') : '';
  2154. Doo::loadModel('invoice');
  2155. $invoice = new invoice();
  2156. Doo::loadModel('invoiceOperationLog');
  2157. $invoiceOperationLog = new invoiceOperationLog();
  2158. $iid = $invoice->authcode($droppedIidKey);
  2159. if (!empty($iid) && !is_numeric($iid))
  2160. die('illegal request');
  2161. $item = array(
  2162. 'iid' => $iid,
  2163. 'status' => 4,
  2164. 'updateTime' => date("Y-m-d H:i:s")
  2165. );
  2166. $invoice->setInvoiceByCondition($item);
  2167. $item = array(
  2168. 'date' => date("Y-m-d H:i:s"),
  2169. 'operation' => '终止了开票',
  2170. 'status' => 4,
  2171. 'img' => $this->staff[0]['avatar'],
  2172. 'username' => $this->staff[0]['username'],
  2173. 'uid' => $this->staff[0]['sid'],
  2174. 'category' => $this->staff[0]['category'],
  2175. 'iid' => $iid
  2176. );
  2177. $invoiceOperationLog->setInvoiceOperationLog($item);
  2178. return "/invoice";
  2179. }
  2180. /**
  2181. * 更新退票的邮寄信息
  2182. */
  2183. function invoiceUntreadMailDo()
  2184. {
  2185. $untreadIidKey = $this->get_args('untreadIidKey') ? $this->get_args('untreadIidKey') : '';
  2186. $untreadCompany = $this->get_args('untreadCompany') ? $this->get_args('untreadCompany') : "";
  2187. $untreadNumber = $this->get_args('untreadNumber') ? $this->get_args('untreadNumber') : "";
  2188. $untreadItems = $this->get_args('untreadItems') ? $this->get_args('untreadItems') : "";
  2189. Doo::loadModel('invoice');
  2190. $invoice = new invoice();
  2191. $iid = $invoice->authcode($untreadIidKey);
  2192. if (!empty($iid) && !is_numeric($iid))
  2193. die('illegal request');
  2194. $item = array(
  2195. 'iid' => $iid,
  2196. 'untreadCompany' => $untreadCompany,
  2197. 'untreadNumber' => $untreadNumber,
  2198. 'untreadItems' => $untreadItems
  2199. );
  2200. $invoice->setInvoiceByCondition($item);
  2201. return "/invoice";
  2202. }
  2203. /**
  2204. * 申请退票 --
  2205. */
  2206. function invoiceUntreadDo()
  2207. {
  2208. $untreadIidKey = $this->get_args('untreadIidKey') ? $this->get_args('untreadIidKey') : '';
  2209. $untreadReason = $this->get_args('untreadReason') ? $this->get_args('untreadReason') : "";
  2210. $untreadPost = $this->get_args('untreadPost') ? $this->get_args('untreadPost') : 0;
  2211. Doo::loadModel('invoice');
  2212. $invoice = new invoice();
  2213. Doo::loadModel('invoiceOperationLog');
  2214. $invoiceOperationLog = new invoiceOperationLog();
  2215. Doo::loadModel('invoiceReceivables');
  2216. $invoiceReceivables = new invoiceReceivables();
  2217. $iid = $invoice->authcode($untreadIidKey);
  2218. if (!empty($iid) && !is_numeric($iid))
  2219. die('illegal request');
  2220. /*
  2221. * 需求变革 有绑定收款也可以退票 $lt = $invoiceReceivables->getInvoiceReceivablesByIid ( $untreadIidKey ); if (! empty ( $lt )) { header ( 'Content-Type:text/html;charset=utf-8' ); die ( '该发票有收款绑定,请先移除!' ); }
  2222. */
  2223. $item = array(
  2224. 'iid' => $iid,
  2225. 'untreadStatus' => 1,
  2226. 'untreadReason' => $untreadReason,
  2227. 'untreadPost' => $untreadPost,
  2228. 'updateTime' => date("Y-m-d H:i:s")
  2229. );
  2230. $invoice->setInvoiceByCondition($item);
  2231. $item = array(
  2232. 'date' => date("Y-m-d H:i:s"),
  2233. 'operation' => '申请退票',
  2234. 'status' => 7,
  2235. 'img' => $this->staff[0]['avatar'],
  2236. 'username' => $this->staff[0]['username'],
  2237. 'uid' => $this->staff[0]['sid'],
  2238. 'category' => $this->staff[0]['category'],
  2239. 'iid' => $iid
  2240. );
  2241. $invoiceOperationLog->setInvoiceOperationLog($item);
  2242. return "/invoice";
  2243. }
  2244. /**
  2245. * 删除已终止的开票
  2246. */
  2247. function invoiceDelDo()
  2248. {
  2249. Doo::loadModel('invoice');
  2250. $invoice = new invoice();
  2251. Doo::loadModel('invoiceOperationLog');
  2252. $invoiceOperationLog = new invoiceOperationLog();
  2253. Doo::loadClass('XDeode');
  2254. $XDeode = new XDeode(5);
  2255. $sid = $XDeode->decode($_COOKIE["staff"]);
  2256. $iid = isset($this->params['iid']) ? $this->params['iid'] : "";
  2257. $iid = $XDeode->decode($iid);
  2258. Doo::loadModel('invoiceStore');
  2259. $invoiceStore = new invoiceStore();
  2260. if (!is_numeric($iid))
  2261. die('illegal request');
  2262. $invoiceDetail = $invoice->getMyInvoice($sid, $iid);
  2263. if (empty($invoiceDetail))
  2264. die('illegal request');
  2265. $item = array(
  2266. 'iid' => $iid,
  2267. 'isDelete' => 1,
  2268. 'updateTime' => date("Y-m-d H:i:s")
  2269. );
  2270. $invoice->setInvoiceByCondition($item);
  2271. $item = array(
  2272. 'date' => date("Y-m-d H:i:s"),
  2273. 'operation' => '删除了已终止的发票',
  2274. 'status' => 4,
  2275. 'img' => $this->staff[0]['avatar'],
  2276. 'username' => $this->staff[0]['username'],
  2277. 'uid' => $this->staff[0]['sid'],
  2278. 'category' => $this->staff[0]['category'],
  2279. 'iid' => $iid
  2280. );
  2281. $invoiceOperationLog->setInvoiceOperationLog($item);
  2282. // 删除培训班发票仓库里的发票
  2283. $invoiceStore->delInvoiceStoreByIsid($invoiceDetail['isid']);
  2284. return "/invoice";
  2285. }
  2286. /**
  2287. */
  2288. function invoiceApproval()
  2289. {
  2290. Doo::loadModel('invoice');
  2291. $invoice = new invoice();
  2292. Doo::loadClass('XDeode');
  2293. $XDeode = new XDeode(5);
  2294. Doo::loadModel('staff');
  2295. $staff = new staff();
  2296. $invoiceList = $invoice->find(array(
  2297. 'where' => 'status=1 and pendingApprovals=' . $this->staff[0]['sid'],
  2298. 'desc' => 'iid',
  2299. 'limit' => 10,
  2300. 'asArray' => true
  2301. ));
  2302. foreach ($invoiceList as $key => $value) {
  2303. $invoiceList[$key]['iidKey'] = $XDeode->encode($value['iid']);
  2304. $lastApprover = json_decode($value['processApprovals'], true);
  2305. if (!empty($lastApprover)) {
  2306. $lastApproverKey = array_keys($lastApprover);
  2307. $lastApprover = end($lastApprover);
  2308. $staffDetail = $staff->getOne(array(
  2309. 'where' => 'sid=' . end($lastApproverKey),
  2310. 'asArray' => true
  2311. ));
  2312. $lastApprover['username'] = $staffDetail['username'];
  2313. }
  2314. $invoiceList[$key]['lastApprover'] = $lastApprover;
  2315. }
  2316. $ilist = $invoice->getInvoiceByProcessStatus();
  2317. foreach ($ilist as $key => $value) {
  2318. $ilist[$key]['iidKey'] = $XDeode->encode($value['iid']);
  2319. $lastApprover = json_decode($value['processApprovals'], true);
  2320. if (!empty($lastApprover)) {
  2321. $lastApproverKey = array_keys($lastApprover);
  2322. $lastApprover = end($lastApprover);
  2323. $staffDetail = $staff->getOne(array(
  2324. 'where' => 'sid=' . end($lastApproverKey),
  2325. 'asArray' => true
  2326. ));
  2327. $lastApprover['username'] = $staffDetail['username'];
  2328. }
  2329. $ilist[$key]['lastApprover'] = $lastApprover;
  2330. }
  2331. // print_r($ilist);
  2332. $this->data['invoiceList'] = $invoiceList;
  2333. $this->data['ilist'] = $ilist;
  2334. $this->data['memu'] = "invoice";
  2335. $this->data['staff'] = $this->staff;
  2336. $this->data['receiptMemu'] = 'invoiceApproval';
  2337. $this->render("/admin/invoiceApproval", $this->data);
  2338. }
  2339. function invoiceDetail()
  2340. {
  2341. Doo::loadClass('XDeode');
  2342. $XDeode = new XDeode(5);
  2343. $iid = isset($this->params['iid']) ? $this->params['iid'] : "";
  2344. $iid = $XDeode->decode($iid);
  2345. if (!is_numeric($iid))
  2346. die('illegal request');
  2347. Doo::loadModel('invoice');
  2348. $invoice = new invoice();
  2349. Doo::loadModel('invoiceOperationLog');
  2350. $invoiceOperationLog = new invoiceOperationLog();
  2351. $invoiceDetail = $invoice->getOne(array(
  2352. 'where' => 'status=1 and pendingApprovals=' . $this->staff[0]['sid'] . ' and iid=' . $iid,
  2353. 'asArray' => true
  2354. ));
  2355. if (empty($invoiceDetail))
  2356. die('illegal request');
  2357. if ($invoiceDetail['settlementType'] == 1) {
  2358. Doo::loadModel('invoiceTraining');
  2359. $invoiceTraining = new invoiceTraining();
  2360. $invoiceDetail['invoiceTraining'] = $invoiceTraining->getInvoiceTrainingByItid($invoiceDetail['trainId']);
  2361. }
  2362. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid($iid);
  2363. $this->data['invoiceDetail'] = $invoiceDetail;
  2364. $this->data['invoiceOperationLogList'] = $invoiceOperationLogList;
  2365. $this->data['INVOICEKEY'] = $invoice->authcode($invoiceDetail['iid'], '');
  2366. $this->data['memu'] = "invoice";
  2367. $this->data['staff'] = $this->staff;
  2368. $this->data['receiptMemu'] = 'invoiceApproval';
  2369. $this->render("/admin/invoiceApprovalDetail", $this->data);
  2370. }
  2371. /**
  2372. * 对发票进行审批,其中操作有终止,退回,同意动作。操作成功并记录下操作日志
  2373. *
  2374. * @since 1.0.0
  2375. * @var integer iid 开票ID 已加密
  2376. * @var integer status 发票审批状态
  2377. * @var integer opintion 审批发票的意见
  2378. * @return string 如操作成功返回审批首页
  2379. */
  2380. function invoiceApprovalDo()
  2381. {
  2382. Doo::loadModel('invoice');
  2383. $invoice = new invoice();
  2384. $iid = $this->get_args('invoiceKey') ? $this->get_args('invoiceKey') : "";
  2385. $status = $this->get_args('status') && is_numeric($this->get_args('status')) ? $this->get_args('status') : 0;
  2386. $opinion = $this->get_args('opinion') ? $this->get_args('opinion') : "";
  2387. $divApproval = $this->get_args('divApproval') ? $this->get_args('divApproval') : "";
  2388. $iid = $invoice->authcode($iid);
  2389. if (!is_numeric($iid))
  2390. die('illegal request');
  2391. // && ! empty ( $opinion )
  2392. if (!empty($iid) && !empty($status)) {
  2393. if (!($status == 2 || $status == 3 || $status == 4))
  2394. die('illegal request');
  2395. Doo::loadModel('invoiceOperationLog');
  2396. $invoiceOperationLog = new invoiceOperationLog();
  2397. $invoiceDetail = $invoice->getOne(array(
  2398. 'where' => 'status=1 and iid=' . $iid . ' and pendingApprovals=' . $this->staff[0]['sid'],
  2399. 'asArray' => true
  2400. ));
  2401. if (empty($invoiceDetail))
  2402. die('illegal request');
  2403. $processApprovals = json_decode($invoiceDetail['processApprovals'], true);
  2404. $invoiceManage = json_decode($invoiceDetail['invoiceManage'], true);
  2405. if ($status == 3) {
  2406. $invoice->status = $status;
  2407. $item = array(
  2408. 'operation' => $opinion
  2409. );
  2410. } else {
  2411. if (empty($processApprovals)) {
  2412. $processApprovals = array(
  2413. $this->staff[0]['sid'] => array(
  2414. 'date' => date("Y-m-d H:i:s"),
  2415. 'opinion' => $opinion,
  2416. 'status' => $status
  2417. )
  2418. );
  2419. // var_dump(next($invoiceManage));
  2420. $nextInvoiceManage = next($invoiceManage);
  2421. // print_r($nextInvoiceManage);
  2422. if ($status != 4 && $nextInvoiceManage !== false)
  2423. $invoice->pendingApprovals = $nextInvoiceManage[0];
  2424. $invoice->processApprovals = json_encode($processApprovals);
  2425. // var_dump($invoice);
  2426. // print_r($invoiceManage);
  2427. } else {
  2428. $processApprovals[$this->staff[0]['sid']] = array(
  2429. 'date' => date("Y-m-d H:i:s"),
  2430. 'opinion' => $opinion,
  2431. 'status' => $status
  2432. );
  2433. $pendingApprovals = 0;
  2434. foreach ($invoiceManage as $key => $value) {
  2435. if ($value[0] == $this->staff[0]['sid']) {
  2436. if (isset($invoiceManage[$key + 1]))
  2437. $pendingApprovals = $invoiceManage[$key + 1][0];
  2438. break;
  2439. }
  2440. }
  2441. if ($status != 4 && !empty($pendingApprovals))
  2442. $invoice->pendingApprovals = $pendingApprovals;
  2443. $invoice->processApprovals = json_encode($processApprovals);
  2444. }
  2445. $item = array(
  2446. 'operation' => $opinion
  2447. );
  2448. if (count($processApprovals) == count($invoiceManage) && $status != 4) {
  2449. $invoice->status = $status;
  2450. $invoice->pendingApprovals = 0;
  2451. $invoice->approvalTime = date("Y-m-d H:i:s");
  2452. } elseif ($status == 4) {
  2453. $invoice->status = $status;
  2454. $item = array(
  2455. 'operation' => $opinion
  2456. );
  2457. }
  2458. }
  2459. $invoice->updateTime = date("Y-m-d H:i:s");
  2460. $invoice->update(array(
  2461. 'where' => 'iid=' . $iid
  2462. ));
  2463. $item += array(
  2464. 'date' => date("Y-m-d H:i:s"),
  2465. 'img' => $this->staff[0]['avatar'],
  2466. 'username' => $this->staff[0]['username'],
  2467. 'uid' => $this->staff[0]['sid'],
  2468. 'category' => $this->staff[0]['category'],
  2469. 'status' => $status,
  2470. 'iid' => $iid
  2471. );
  2472. $invoiceOperationLog->setInvoiceOperationLog($item);
  2473. if (empty($divApproval))
  2474. return '/invoiceApproval';
  2475. else
  2476. return '/invoiceApprovalAchieve/PEND';
  2477. }
  2478. die('illegal request');
  2479. }
  2480. /**
  2481. * 展示需要打印的发票数据
  2482. *
  2483. * @since 1.0.0
  2484. */
  2485. function invoicePrint()
  2486. {
  2487. Doo::loadModel('invoice');
  2488. $invoice = new invoice();
  2489. Doo::loadClass('XDeode');
  2490. $XDeode = new XDeode(5);
  2491. Doo::loadModel('staff');
  2492. $staff = new staff();
  2493. $toPrint = $invoice->getPrintInvoiceByManage($this->staff[0]['sid'], 0);
  2494. $printed = $invoice->getPrintInvoiceByManage($this->staff[0]['sid'], 1);
  2495. foreach ($toPrint as $key => $value) {
  2496. $toPrint[$key]['iidKey'] = $XDeode->encode($value['iid']);
  2497. $lastApprover = json_decode($value['processApprovals'], true);
  2498. if (!empty($lastApprover)) {
  2499. $lastApproverKey = array_keys($lastApprover);
  2500. $lastApprover = end($lastApprover);
  2501. $staffDetail = $staff->getOne(array(
  2502. 'where' => 'sid=' . end($lastApproverKey),
  2503. 'asArray' => true
  2504. ));
  2505. $lastApprover['username'] = $staffDetail['username'];
  2506. }
  2507. $toPrint[$key]['lastApprover'] = $lastApprover;
  2508. }
  2509. foreach ($printed as $key => $value) {
  2510. $printed[$key]['iidKey'] = $XDeode->encode($value['iid']);
  2511. $lastApprover = json_decode($value['processApprovals'], true);
  2512. if (!empty($lastApprover)) {
  2513. $lastApproverKey = array_keys($lastApprover);
  2514. $lastApprover = end($lastApprover);
  2515. $staffDetail = $staff->getOne(array(
  2516. 'where' => 'sid=' . end($lastApproverKey),
  2517. 'asArray' => true
  2518. ));
  2519. $lastApprover['username'] = $staffDetail['username'];
  2520. }
  2521. $printed[$key]['lastApprover'] = $lastApprover;
  2522. }
  2523. $this->data['printed'] = $printed;
  2524. $this->data['toPrint'] = $toPrint;
  2525. $this->data['memu'] = "invoice";
  2526. $this->data['staff'] = $this->staff;
  2527. $this->data['receiptMemu'] = 'invoicePrint';
  2528. $this->render("/admin/invoicePrint", $this->data);
  2529. }
  2530. /**
  2531. * 展示发票打印的详情页面
  2532. *
  2533. * @since 1.0.0
  2534. */
  2535. function invoicePrintDetail()
  2536. {
  2537. Doo::loadClass('XDeode');
  2538. $XDeode = new XDeode(5);
  2539. $iid = isset($this->params['iid']) ? $this->params['iid'] : "";
  2540. $iid = $XDeode->decode($iid);
  2541. if (!is_numeric($iid))
  2542. die('illegal request');
  2543. Doo::loadModel('invoice');
  2544. $invoice = new invoice();
  2545. Doo::loadModel('invoiceOperationLog');
  2546. $invoiceOperationLog = new invoiceOperationLog();
  2547. Doo::loadModel('invoicePaper');
  2548. $invoicePaper = new invoicePaper();
  2549. $invoiceDetail = $invoice->getPrintInvoiceByManage($this->staff[0]['sid'], 0, $iid);
  2550. if (empty($invoiceDetail))
  2551. die('illegal request');
  2552. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType($invoiceDetail['invoiceType'], $invoiceDetail['invoiceForm']);
  2553. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid($iid);
  2554. if ($invoiceDetail['settlementType'] == 1) {
  2555. Doo::loadModel('invoiceTraining');
  2556. $invoiceTraining = new invoiceTraining();
  2557. $invoiceDetail['invoiceTraining'] = $invoiceTraining->getInvoiceTrainingByItid($invoiceDetail['trainId']);
  2558. }
  2559. $this->data['invoicePaperList'] = $invoicePaperList;
  2560. $this->data['invoiceDetail'] = $invoiceDetail;
  2561. $this->data['invoiceOperationLogList'] = $invoiceOperationLogList;
  2562. $this->data['INVOICEKEY'] = $invoice->authcode($invoiceDetail['iid'], '');
  2563. $this->data['memu'] = "invoice";
  2564. $this->data['staff'] = $this->staff;
  2565. $this->data['receiptMemu'] = 'invoicePrint';
  2566. $this->render("/admin/invoicePrintDetail", $this->data);
  2567. }
  2568. /**
  2569. * 所有待打印 发票
  2570. */
  2571. function invoicePrintStayAchieve()
  2572. {
  2573. Doo::loadModel('invoice');
  2574. $invoice = new invoice();
  2575. Doo::loadClass('XDeode');
  2576. $XDeode = new XDeode(5);
  2577. Doo::loadModel('staff');
  2578. $staff = new staff();
  2579. $MebSea = $this->get_args('MebSea') ? urldecode($this->get_args('MebSea')) : "";
  2580. $invoiceType = $this->get_args('invoiceType') ? $this->get_args('invoiceType') : "ALL";
  2581. $invoiceTrain = $this->get_args('invoiceTrain') ? $this->get_args('invoiceTrain') : "ALL";
  2582. $invoiceTrainName = $this->get_args('invoiceTrainName') ? $this->get_args('invoiceTrainName') : "ALL";
  2583. Doo::loadModel('invoiceTraining');
  2584. $invoiceTraining = new invoiceTraining();
  2585. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus();
  2586. $page_size = 12;
  2587. $page = isset($this->params['page']) && is_numeric($this->params['page']) ? $this->params['page'] : 1;
  2588. $status = isset($this->params['status']) ? $this->params['status'] : "ALL";
  2589. // $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : "ALL";
  2590. $get = "/" . $status;
  2591. $con = ' and status=2 ';
  2592. if ($status == 'TOPRINT')
  2593. $con = ' and status=2 and printStatus=0 ';
  2594. elseif ($status == 'PRINTED')
  2595. $con = ' and status=2 and printStatus=1';
  2596. if ($invoiceType == 'ORDINARY')
  2597. $con .= ' and invoiceType=0 and invoiceForm=0 ';
  2598. elseif ($invoiceType == 'SPECIAL') {
  2599. $con .= ' and invoiceType=1 ';
  2600. } elseif ($invoiceType == 'ELECTRON') {
  2601. $con .= ' and invoiceType=0 and invoiceForm=1 ';
  2602. }
  2603. if ($invoiceTrain == 'ORDINARY')
  2604. $con .= ' and trainId=0 ';
  2605. elseif ($invoiceTrain == 'TRAIN')
  2606. $con .= ' and trainId!=0 ';
  2607. if ($invoiceTrainName != 'ALL') {
  2608. $trainId = $XDeode->decode($invoiceTrainName);
  2609. if (is_numeric($trainId))
  2610. $con .= ' and trainId =' . $trainId;
  2611. }
  2612. $date = $this->get_args('date') ? $this->get_args('date') : "";
  2613. $dateArr = explode(':', $date);
  2614. $D1 = '';
  2615. $D2 = '';
  2616. if (!empty($date)) {
  2617. $D1 = $dateArr[0];
  2618. $D2 = $dateArr[1];
  2619. }
  2620. if (!empty($D1) && !empty($D2) && !empty($date)) {
  2621. $D1 = $D1 . ":00.00.00";
  2622. $D2 = $D2 . ":23.59.59";
  2623. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2624. }
  2625. if (!empty($MebSea)) {
  2626. $con .= ' and ( invoiceNo like "%' . $MebSea . '%" or invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  2627. }
  2628. $pageinfo['page'] = array(
  2629. 'previous' => ''
  2630. );
  2631. $get .= "?date=" . urlencode($date) . "&MebSea=" . urlencode($MebSea) . "&invoiceType=" . urlencode($invoiceType) . "&invoiceTrain=" . urlencode($invoiceTrain) . "";
  2632. $sql = " (untreadStatus=0 or untreadStatus=3 or untreadStatus=4) and moldManage like '%[\"" . $this->staff[0]['sid'] . "\",%'" . $con;
  2633. $action = "invoicePrintStayAchieve";
  2634. //echo $sql;
  2635. $pageinfo = $this->get_page("CLD_invoice", $sql, $page, $page_size, $action, $get, "");
  2636. $limit = $pageinfo['lower'] . ',' . $page_size;
  2637. $list = $invoice->getInvoiceByUntreadStatusPage($limit, $sql, 'desc', 5);
  2638. $this->data['trainList'] = $trainList;
  2639. $this->data['invoiceType'] = $invoiceType;
  2640. $this->data['invoiceTrain'] = $invoiceTrain;
  2641. $this->data['invoiceTrainName'] = $invoiceTrainName;
  2642. $this->data['MebSeaEn'] = $MebSea;
  2643. $this->data['MebSea'] = urlencode($MebSea);
  2644. $this->data['get'] = $get;
  2645. $this->data['page'] = $pageinfo;
  2646. $this->data['date'] = $date;
  2647. $this->data['status'] = $status;
  2648. $this->data['invoiceType'] = $invoiceType;
  2649. $this->data['memu'] = "invoice";
  2650. $this->data['staff'] = $this->staff;
  2651. foreach ($list as $key => $value) {
  2652. $list[$key]['iidKey'] = $XDeode->encode($value['iid']);
  2653. $lastApprover = json_decode($value['processApprovals'], true);
  2654. if (!empty($lastApprover)) {
  2655. $lastApproverKey = array_keys($lastApprover);
  2656. $lastApprover = end($lastApprover);
  2657. $staffDetail = $staff->getOne(array(
  2658. 'where' => 'sid=' . end($lastApproverKey),
  2659. 'asArray' => true
  2660. ));
  2661. $lastApprover['username'] = $staffDetail['username'];
  2662. }
  2663. $list[$key]['lastApprover'] = $lastApprover;
  2664. }
  2665. $this->data['receiptMemu'] = 'invoicePrint';
  2666. $this->data['list'] = $list;
  2667. $this->render("/admin/invoicePrintStayAchieve", $this->data);
  2668. }
  2669. /**
  2670. * 填写票号并完成打印
  2671. * @since 1.0.0
  2672. */
  2673. function invoicePrintDo()
  2674. {
  2675. Doo::loadModel('invoice');
  2676. $invoice = new invoice();
  2677. $iid = $this->get_args('invoiceKey') ? $this->get_args('invoiceKey') : "";
  2678. $invoiceNo = $this->get_args('invoiceNo') ? $this->get_args('invoiceNo') : "";
  2679. $invoicePrintType = $this->get_args('invoicePrintType') ? $this->get_args('invoicePrintType') : "";
  2680. $iid = $invoice->authcode($iid);
  2681. if (!is_numeric($iid))
  2682. die('illegal request-iid');
  2683. if (!empty($iid) && !empty($invoiceNo)) {
  2684. Doo::loadModel('invoiceOperationLog');
  2685. $invoiceOperationLog = new invoiceOperationLog();
  2686. Doo::loadModel('invoiceStatistics');
  2687. $invoiceStatistics = new invoiceStatistics();
  2688. $XDeode = new XDeode(5);
  2689. Doo::loadModel('invoicePaper');
  2690. $invoicePaper = new invoicePaper();
  2691. $invoicePrintDetail = $invoice->getInvoiceByPrint($iid);
  2692. if (empty($invoicePrintDetail))
  2693. die('illegal request-data_empty');
  2694. //
  2695. $ipid = $XDeode->decode($invoiceNo);
  2696. $paperDetail = $invoicePaper->getInvoicePaperByIpid($ipid);
  2697. if (empty($paperDetail))
  2698. die('illegal request-paper_empty');
  2699. $invoicePaper = new invoicePaper();
  2700. $item = array(
  2701. 'iid' => $iid,
  2702. 'ipid' => $ipid
  2703. );
  2704. $invoicePaper->setInvoicePaperByCondition($item);
  2705. $item = array(
  2706. 'iid' => $iid,
  2707. 'printStatus' => 1,
  2708. 'updateTime' => date("Y-m-d H:i:s"),
  2709. 'printer' => $this->staff[0]['username'],
  2710. 'printTime' => date("Y-m-d H:i:s"),
  2711. 'invoiceNo' => $paperDetail['invoiceNo']
  2712. );
  2713. $invoice->setInvoiceByCondition($item);
  2714. $item = array(
  2715. 'date' => date("Y-m-d H:i:s"),
  2716. 'operation' => '打印发票号:' . $paperDetail['invoiceNo'],
  2717. 'status' => 5,
  2718. 'img' => $this->staff[0]['avatar'],
  2719. 'username' => $this->staff[0]['username'],
  2720. 'uid' => $this->staff[0]['sid'],
  2721. 'category' => $this->staff[0]['category'],
  2722. 'iid' => $iid
  2723. );
  2724. $invoiceOperationLog->setInvoiceOperationLog($item);
  2725. // 去统计--负票不汇总
  2726. if ($invoicePrintDetail['untreadStatus'] != 4) {
  2727. $item = array(
  2728. 'date' => date("Y-m-d H:i:s"),
  2729. 'priceClass' => 1,
  2730. 'cid' => $invoicePrintDetail['cid'],
  2731. 'staff' => $invoicePrintDetail['sid'],
  2732. 'invoicePrice' => $invoicePrintDetail['invoicePrice']
  2733. );
  2734. $invoiceStatistics->setInvoiceStatisticsByCondition($item);
  2735. }
  2736. // 发送通知信息到微信-去除
  2737. // $this->setWXMsg($iid,'PRINT');
  2738. // 发票信息库
  2739. $this->autoUpdateInvoiceInfoBase($invoicePrintDetail);
  2740. // 申请人获取微信通知
  2741. Doo::loadModel('staff');
  2742. $staff = new staff();
  2743. Doo::loadClass('XDeode');
  2744. $XDeode = new XDeode(5);
  2745. $username2 = $staff->getOne(array(
  2746. 'select' => 'wxid',
  2747. 'where' => 'sid=' . $invoicePrintDetail['sid'],
  2748. 'asArray' => TRUE
  2749. ));
  2750. $title2 = '[结果]您的发票' . $invoicePrintDetail['invoiceSerial'] . '完成打印';
  2751. $msg = '';
  2752. $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/' . $XDeode->encode($invoicePrintDetail['iid']) . '.html';
  2753. $hfreult = $this->msgSend($msg, $title2, $url, $username2['wxid'], $invoicePrintDetail['sid'], 'print');
  2754. if (empty($invoicePrintType))
  2755. return "/invoicePrint";
  2756. else
  2757. return "/invoicePrintStayAchieve";
  2758. }
  2759. }
  2760. /**
  2761. * 需要邮寄的发票
  2762. * @since 1.0.0
  2763. */
  2764. function invoicePost()
  2765. {
  2766. Doo::loadModel('invoice');
  2767. $invoice = new invoice();
  2768. Doo::loadModel('express');
  2769. $express = new express();
  2770. $invoicePost = $invoice->getPostByInvoice();
  2771. $invoicePosted = $invoice->getPostByInvoice(1);
  2772. $expressList = $express->getExpressByAll();
  2773. $invoicePostExpress = "";
  2774. if (isset($_COOKIE["invoicePostExpress"]))
  2775. $invoicePostExpress = $_COOKIE["invoicePostExpress"];
  2776. $this->data['invoicePostExpress'] = $invoicePostExpress;
  2777. $this->data['expressList'] = $expressList;
  2778. $this->data['invoicePost'] = $invoicePost;
  2779. $this->data['invoicePosted'] = $invoicePosted;
  2780. $this->data['memu'] = "invoice";
  2781. $this->data['staff'] = $this->staff;
  2782. $this->data['receiptMemu'] = 'invoicePost';
  2783. $this->render("/admin/invoicePost", $this->data);
  2784. }
  2785. /**
  2786. * 添加发票邮寄信息
  2787. */
  2788. function invoiceExpressAddDo()
  2789. {
  2790. Doo::loadModel('invoice');
  2791. $invoice = new invoice();
  2792. $iid = $this->get_args('iidKey') ? $this->get_args('iidKey') : "";
  2793. $expressCompany = $this->get_args('express') ? $this->get_args('express') : "";
  2794. $expressNumber = $this->get_args('nu') ? $this->get_args('nu') : "";
  2795. $actualItems = $this->get_args('actualItems') ? $this->get_args('actualItems') : "";
  2796. $iid = $iid = $invoice->authcode($iid);
  2797. if (!is_numeric($iid) && empty($expressCompany) && empty($expressNumber) && empty($actualItems))
  2798. die('illegal request');
  2799. $invoicePrintDetail = $invoice->getInvoiceByIid($iid);
  2800. setcookie('invoicePostExpress', $expressNumber);
  2801. $item = array(
  2802. 'iid' => $iid,
  2803. 'postStatus' => 1,
  2804. 'updateTime' => date("Y-m-d H:i:s"),
  2805. 'postTime' => date("Y-m-d H:i:s"),
  2806. 'expressCompany' => $expressCompany,
  2807. 'expressNumber' => $expressNumber,
  2808. 'actualItems' => $actualItems,
  2809. 'poster' => $this->staff[0]['username']
  2810. );
  2811. $invoice->setInvoiceByCondition($item);
  2812. // 微信通知-去掉
  2813. // $this->setWXMsg ( $iid );
  2814. Doo::loadModel('staff');
  2815. $staff = new staff();
  2816. Doo::loadClass('XDeode');
  2817. $XDeode = new XDeode(5);
  2818. $username2 = $staff->getOne(array(
  2819. 'select' => 'wxid',
  2820. 'where' => 'sid=' . $invoicePrintDetail['sid'],
  2821. 'asArray' => TRUE
  2822. ));
  2823. $title2 = '[结果]您的发票' . $invoicePrintDetail['invoiceSerial'] . '已邮寄';
  2824. $expCom = explode(":", $invoicePrintDetail['expressCompany']);
  2825. if (empty($expCom))
  2826. $expCom[0] = '';
  2827. $msg = $expCom[0] . ':' . $invoicePrintDetail['expressNumber'] . '';
  2828. $url = 'https://m.kuaidi100.com/result.jsp?nu=' . $invoicePrintDetail['expressNumber'];
  2829. $hfreult = $this->msgSend($msg, $title2, $url, $username2['wxid'], $invoicePrintDetail['sid'], 'print');
  2830. return '/invoicePost';
  2831. }
  2832. function invoiceExpressUpdateDo()
  2833. {
  2834. Doo::loadModel('invoice');
  2835. $invoice = new invoice();
  2836. $action = $this->get_args('action') ? $this->get_args('action') : "";
  2837. $iid = $this->get_args('iidKey') ? $this->get_args('iidKey') : "";
  2838. $expressCompany = $this->get_args('express') ? $this->get_args('express') : "";
  2839. $expressNumber = $this->get_args('nu') ? $this->get_args('nu') : "";
  2840. $actualItems = $this->get_args('actualItems') ? $this->get_args('actualItems') : "";
  2841. $iid = $invoice->authcode($iid);
  2842. if (!is_numeric($iid) && empty($expressCompany) && empty($expressNumber) && empty($actualItems))
  2843. die('illegal request');
  2844. $item = array(
  2845. 'iid' => $iid,
  2846. 'updateTime' => date("Y-m-d H:i:s"),
  2847. 'expressCompany' => $expressCompany,
  2848. 'expressNumber' => $expressNumber,
  2849. 'actualItems' => $actualItems,
  2850. 'poster' => $this->staff[0]['username']
  2851. );
  2852. $invoice->setInvoiceByCondition($item);
  2853. return $action;
  2854. }
  2855. /**
  2856. * 可退票管理
  2857. */
  2858. function invoiceUntreadIsAchieve()
  2859. {
  2860. Doo::loadModel('invoice');
  2861. $invoice = new invoice();
  2862. $MebSea = $this->get_args('MebSea') ? $this->get_args('MebSea') : "";
  2863. /*
  2864. * Doo::loadClass ( 'XDeode' ); $XDeode = new XDeode ( 5 ); $page_size = 18; $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1; $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : ""; $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ); $dateArr = explode ( ':', $date ); $D1 = ''; $D2 = ''; if (! empty ( $date )) { $D1 = $dateArr [0]; $D2 = $dateArr [1]; } $con = ''; if (! empty ( $D1 ) && ! empty ( $D2 )) $con = ' and bindTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" '; // if ($date == 'MONTHO') // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)'; // elseif ($date == 'MONTHT') // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)'; // elseif ($date == 'MONTHY') // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)'; if (! empty ( $MebSea )) { $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )'; } $pageinfo ['page'] = array ( 'previous' => '' );
  2865. */
  2866. if (empty($MebSea)) { //
  2867. $con = ' and invoiceNo like "NULL" ';
  2868. } else {
  2869. $con = ' and (invoiceNo like "%' . $MebSea . '%" or invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  2870. }
  2871. // printStatus=1 and
  2872. $sql = " (untreadStatus=0 or untreadStatus=3) and status=2 and sid=" . $this->staff[0]['sid'] . $con;
  2873. /*
  2874. * $action = "invoiceUntreadIsAchieve"; $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" ); $limit = $pageinfo ['lower'] . ',' . $page_size;
  2875. */
  2876. $limit = '0,50';
  2877. $list = $invoice->getInvoiceByUntreadStatusPage($limit, $sql);
  2878. //print_r($list);
  2879. $this->data['MebSeaEn'] = $MebSea;
  2880. /*
  2881. * $this->data ['get'] = $get; $this->data ['page'] = $pageinfo; $this->data ['date'] = $date;
  2882. */
  2883. $this->data['list'] = $list;
  2884. $this->data['memu'] = "invoice";
  2885. $this->data['staff'] = $this->staff;
  2886. $this->data['receiptMemu'] = 'invoice';
  2887. $this->render("/admin/invoiceUntreadIsAchieve", $this->data);
  2888. }
  2889. // 已经退票的发票
  2890. function invoiceUntreadED()
  2891. {
  2892. Doo::loadModel('invoice');
  2893. $invoice = new invoice();
  2894. $MebSea = $this->get_args('MebSea') ? $this->get_args('MebSea') : "";
  2895. $invoiceType = $this->get_args('invoiceType') ? $this->get_args('invoiceType') : "";
  2896. Doo::loadClass('XDeode');
  2897. $XDeode = new XDeode(5);
  2898. $page_size = 18;
  2899. $page = isset($this->params['page']) && is_numeric($this->params['page']) ? $this->params['page'] : 1;
  2900. $date = $this->get_args('date') ? $this->get_args('date') : "";
  2901. $get = "?date=" . urlencode($date) . "&MebSea=" . urlencode($MebSea);
  2902. $dateArr = explode(':', $date);
  2903. $D1 = '';
  2904. $D2 = '';
  2905. if (!empty($date)) {
  2906. $D1 = $dateArr[0];
  2907. $D2 = $dateArr[1];
  2908. }
  2909. $con = '';
  2910. if (!empty($D1) && !empty($D2)) {
  2911. $con = ' and bindTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2912. }
  2913. // if ($date == 'MONTHO')
  2914. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  2915. // elseif ($date == 'MONTHT')
  2916. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  2917. // elseif ($date == 'MONTHY')
  2918. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  2919. if (!empty($MebSea)) {
  2920. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  2921. }
  2922. if ($invoiceType == 'ORDINARY') {
  2923. $con .= ' and invoiceType=0 ';
  2924. } elseif ($invoiceType == 'SPECIAL') {
  2925. $con .= ' and invoiceType=1 ';
  2926. }
  2927. $pageinfo['page'] = array(
  2928. 'previous' => ''
  2929. );
  2930. // printStatus=1 and
  2931. $sql = " (untreadStatus=2 ) and status=2 and sid=" . $this->staff[0]['sid'] . $con;
  2932. $action = "invoiceUntreadED";
  2933. $pageinfo = $this->get_page("CLD_invoice", $sql, $page, $page_size, $action, $get, "");
  2934. $limit = $pageinfo['lower'] . ',' . $page_size;
  2935. $list = $invoice->getInvoiceByUntreadStatusPage($limit, $sql);
  2936. // print_r($list);
  2937. $this->data['MebSeaEn'] = $MebSea;
  2938. $this->data['get'] = $get;
  2939. $this->data['page'] = $pageinfo;
  2940. $this->data['date'] = $date;
  2941. $this->data['invoiceType'] = $invoiceType;
  2942. $this->data['list'] = $list;
  2943. $this->data['memu'] = "invoice";
  2944. $this->data['staff'] = $this->staff;
  2945. $this->data['receiptMemu'] = 'invoice';
  2946. $this->render("/admin/invoiceUntreadED", $this->data);
  2947. }
  2948. /**
  2949. * 退票处理页面
  2950. */
  2951. function invoiceUntread()
  2952. {
  2953. Doo::loadModel('invoice');
  2954. $invoice = new invoice();
  2955. $untreadInvoice = $invoice->getInvoiceByUntreadStatus(1, 0, 50);
  2956. $establishedInvoice = $invoice->getInvoiceByUntreadStatus(2);
  2957. //print_r($establishedInvoice);
  2958. // foreach ( $establishedInvoice as $key => $value ) {
  2959. // // months
  2960. // $lossDate = strtotime ( "+1 month", strtotime ( $value ['OperationLog'] ['date'] ) );
  2961. // $nowDate = strtotime ( 'now' );
  2962. // $establishedInvoice [$key] ['lossShow'] = false;
  2963. // if ($lossDate < $nowDate)
  2964. // $establishedInvoice [$key] ['lossShow'] = true;
  2965. // }
  2966. $this->data['untreadInvoice'] = $untreadInvoice;
  2967. $this->data['establishedInvoice'] = $establishedInvoice;
  2968. $this->data['memu'] = "invoice";
  2969. $this->data['staff'] = $this->staff;
  2970. $this->data['receiptMemu'] = 'invoiceUntread';
  2971. $this->render("/admin/invoiceUntread", $this->data);
  2972. }
  2973. /**
  2974. * 确认收到退回的发票,开票状态为退回 //收款状态解绑,公司统计扣除入账额度
  2975. */
  2976. function invoiceUntreadEstablishedDo()
  2977. {
  2978. $untreadIidKey = $this->get_args('untreadIidKey') ? $this->get_args('untreadIidKey') : '';
  2979. Doo::loadModel('invoice');
  2980. $invoice = new invoice();
  2981. Doo::loadModel('invoiceOperationLog');
  2982. $invoiceOperationLog = new invoiceOperationLog();
  2983. Doo::loadModel('invoiceReceivables');
  2984. Doo::loadModel('invoiceStatistics');
  2985. $iid = $invoice->authcode($untreadIidKey);
  2986. if (!empty($iid) && !is_numeric($iid))
  2987. die('illegal request');
  2988. $invoiceDetails = $invoice->getInvoiceByIid($iid);
  2989. if ($invoiceDetails['untreadStatus'] != 1)
  2990. die('illegal request untreadStatus error !=1');
  2991. $item = array(
  2992. 'iid' => $iid,
  2993. // 'irid'=>'',
  2994. 'untreadStatus' => 2,
  2995. 'untreadTime' => date("Y-m-d H:i:s"),
  2996. 'updateTime' => date("Y-m-d H:i:s")
  2997. );
  2998. $invoice->setInvoiceByCondition($item);
  2999. $item = array(
  3000. 'date' => date("Y-m-d H:i:s"),
  3001. 'operation' => '已确认退票',
  3002. 'status' => 6,
  3003. 'img' => $this->staff[0]['avatar'],
  3004. 'username' => $this->staff[0]['username'],
  3005. 'uid' => $this->staff[0]['sid'],
  3006. 'category' => $this->staff[0]['category'],
  3007. 'iid' => $iid
  3008. );
  3009. $invoiceOperationLog->setInvoiceOperationLog($item);
  3010. // 收款解绑以及入账扣除 收款扣除
  3011. if (!empty($invoiceDetails['irid'])) {
  3012. $iridList = explode(',', $invoiceDetails['irid']);
  3013. foreach ($iridList as $value) {
  3014. $invoiceReceivables = new invoiceReceivables();
  3015. $irDetails = $invoiceReceivables->getOne(array(
  3016. 'where' => " irid=" . $value . ' ',
  3017. 'asArray' => TRUE
  3018. ));
  3019. $bindPrice = $irDetails['bindPrice'] - $invoiceDetails['invoicePrice'];
  3020. if ($bindPrice < 0) {
  3021. $bindPrice = 0;
  3022. }
  3023. $iidExtend = explode(',', $irDetails['iidExtend']);
  3024. $item = array(
  3025. 'irid' => $value,
  3026. 'bindStatus' => 0,
  3027. 'untreadStatus' => 1,
  3028. 'bindPrice' => $bindPrice,
  3029. 'untreadStaff' => $invoiceDetails['userName'],
  3030. 'unbundlingTime' => date("Y-m-d H:i:s"),
  3031. );
  3032. if ($irDetails['iid'] == $iid) {
  3033. $item += array(
  3034. 'iid' => 0
  3035. );
  3036. } else {
  3037. foreach ($iidExtend as $iek => $iev) {
  3038. if ($iev == $iid) {
  3039. unset($iidExtend[$iek]);
  3040. break;
  3041. }
  3042. }
  3043. if (empty($iidExtend)) {
  3044. $item += array(
  3045. 'iidExtend' => ''
  3046. );
  3047. } else {
  3048. $iidExtend = implode(",", $iidExtend);
  3049. $item += array(
  3050. 'iidExtend' => $iidExtend
  3051. );
  3052. }
  3053. }
  3054. $invoiceReceivables->setInvoiceReceivablesByCondition($item);
  3055. if (!empty($irDetails)) {
  3056. // 扣除入账
  3057. $invoiceStatistics = new invoiceStatistics();
  3058. $item = array(
  3059. 'date' => date('Y-m-d', strtotime($irDetails['receivablesDate'])),
  3060. 'priceClass' => 3,
  3061. 'cid' => $invoiceDetails['cid'],
  3062. 'staff' => $invoiceDetails['sid'],
  3063. 'accountPrice' => -$irDetails['receivablesPrice']
  3064. );
  3065. $invoiceStatistics->setInvoiceStatisticsByCondition($item);
  3066. // 扣除收款
  3067. $invoiceStatistics = new invoiceStatistics();
  3068. $item = array(
  3069. 'date' => date('Y-m-d', strtotime($irDetails['receivablesDate'])),
  3070. 'priceClass' => 2,
  3071. 'cid' => $invoiceDetails['cid'],
  3072. 'staff' => $invoiceDetails['sid'],
  3073. 'irid' => $irDetails['irid'],
  3074. 'receivablesPrice' => -$irDetails['receivablesPrice']
  3075. );
  3076. $invoiceStatistics->setInvoiceStatisticsByCondition($item);
  3077. }
  3078. // 解绑时删除收入流水--退票不删除流水
  3079. // Doo::loadModel ( 'wasteBook' );
  3080. // $wasteBook = new wasteBook ();
  3081. // $wasteBook->delete ( array (
  3082. // 'where' => 'dataID=' . $value . ' and accountType=7',
  3083. // 'limit' => 1
  3084. // ) );
  3085. }
  3086. }
  3087. return "/invoiceUntread";
  3088. }
  3089. function invoiceUntreadRecallDo()
  3090. {
  3091. $iidKey = isset($this->params['iidKey']) ? $this->params['iidKey'] : "";
  3092. Doo::loadModel('invoice');
  3093. $invoice = new invoice();
  3094. Doo::loadClass('XDeode');
  3095. $XDeode = new XDeode(5);
  3096. Doo::loadModel('invoiceOperationLog');
  3097. $invoiceOperationLog = new invoiceOperationLog();
  3098. $iid = $XDeode->decode($iidKey);
  3099. $invoiceDetail = $invoice->getInvoiceByIid($iid);
  3100. if (empty($invoiceDetail)) {
  3101. die('illegal request-DATANULL');
  3102. }
  3103. $item = array(
  3104. 'iid' => $iid,
  3105. 'untreadStatus' => 0
  3106. );
  3107. $invoice->setInvoiceByCondition($item);
  3108. $item = array(
  3109. 'date' => date("Y-m-d H:i:s"),
  3110. 'operation' => '撤回申请退票',
  3111. 'status' => 13,
  3112. 'img' => $this->staff[0]['avatar'],
  3113. 'username' => $this->staff[0]['username'],
  3114. 'uid' => $this->staff[0]['sid'],
  3115. 'category' => $this->staff[0]['category'],
  3116. 'iid' => $iid
  3117. );
  3118. $invoiceOperationLog->setInvoiceOperationLog($item);
  3119. return "/invoiceUntread";
  3120. }
  3121. /**
  3122. * 建立负票,关联原来发票
  3123. */
  3124. function invoiceLossDo()
  3125. {
  3126. $iidKey = $this->get_args('iidKey') ? $this->get_args('iidKey') : "";
  3127. if (!empty($iidKey)) {
  3128. Doo::loadClass('XDeode');
  3129. $XDeode = new XDeode(5);
  3130. Doo::loadModel('invoice');
  3131. $invoice = new invoice();
  3132. Doo::loadModel('invoiceOperationLog');
  3133. $invoiceOperationLog = new invoiceOperationLog();
  3134. $iidKey = $XDeode->decode($iidKey);
  3135. $invoiceDetail = $invoice->getInvoiceByIid($iidKey);
  3136. // 拷贝插入一条发票数据
  3137. $iid = $invoice->setInvoiceLoss($iidKey);
  3138. // 更新负票
  3139. if ($invoiceDetail['invoiceForm'] == 1) {
  3140. $invoiceSerial = "#FE" . date("Ymd") . mt_rand(1000, 9999);
  3141. } else {
  3142. $invoiceSerial = "#F" . date("Ymd") . mt_rand(1000, 9999);
  3143. }
  3144. $invoice = new invoice();
  3145. $item = array(
  3146. 'iid' => $iid,
  3147. 'sid' => $this->staff[0]['sid'],
  3148. 'userName' => $this->staff[0]['username'],
  3149. 'cid' => $this->staff[0]['cid'],
  3150. 'categoryName' => $this->staff[0]['category'],
  3151. 'invoiceQuantity' => -$invoiceDetail['invoiceQuantity'],
  3152. 'invoicePrice' => -$invoiceDetail['invoicePrice'],
  3153. 'invoiceSerial' => $invoiceSerial,
  3154. 'invoiceNo' => '',
  3155. 'printStatus' => 0,
  3156. 'untreadStatus' => 4,
  3157. // 关联发票号
  3158. 'lossIid' => $invoiceDetail['iid']
  3159. );
  3160. $invoice->setInvoiceByCondition($item);
  3161. // 更新原发票
  3162. $invoice = new invoice();
  3163. $item = array(
  3164. 'iid' => $invoiceDetail['iid'],
  3165. 'lossIid' => $iid
  3166. );
  3167. $invoice->setInvoiceByCondition($item);
  3168. // 操作日志
  3169. $item = array(
  3170. 'date' => date("Y-m-d H:i:s"),
  3171. 'operation' => "创建负票" . $invoiceSerial,
  3172. 'status' => 12,
  3173. 'img' => $this->staff[0]['avatar'],
  3174. 'username' => $this->staff[0]['username'],
  3175. 'uid' => $this->staff[0]['sid'],
  3176. 'category' => $this->staff[0]['category'],
  3177. 'iid' => $iid
  3178. );
  3179. $invoiceOperationLog->setInvoiceOperationLog($item);
  3180. // print_r($invoiceDetail);
  3181. // echo $iid;die;
  3182. }
  3183. return '/invoiceUntread';
  3184. }
  3185. /**
  3186. * 上传银行到账 收款文件
  3187. */
  3188. function invoiceReceivablesBankUpload()
  3189. {
  3190. $POST_MAX_SIZE = ini_get('post_max_size');
  3191. $unit = strtoupper(substr($POST_MAX_SIZE, -1));
  3192. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  3193. if ((int) $_SERVER['CONTENT_LENGTH'] > $multiplier * (int) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  3194. header("HTTP/1.1 500 Internal Server Error");
  3195. echo "POST exceeded maximum allowed size.";
  3196. exit(0);
  3197. }
  3198. // Settings
  3199. $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)
  3200. $upload_name = "Filedata";
  3201. $file_name = "";
  3202. $nk = time();
  3203. $file_name = $nk . '.' . $this->_GetFileEXT($_FILES[$upload_name]['name']); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  3204. if (!@move_uploaded_file($_FILES[$upload_name]["tmp_name"], $save_path . $file_name)) {
  3205. echo "文件无法保存.";
  3206. exit(0);
  3207. }
  3208. echo json_encode(array(
  3209. 'filename' => $file_name,
  3210. 'id' => $nk
  3211. ));
  3212. exit(0);
  3213. }
  3214. /**
  3215. * 解析银行到账收款execl并导入库中
  3216. */
  3217. function invoiceReceivablesImport()
  3218. {
  3219. $path = $this->get_args('bankName') ? $this->get_args('bankName') : "";
  3220. if ($path != "") {
  3221. Doo::loadModel('invoiceReceivables');
  3222. $invoiceReceivables = new invoiceReceivables();
  3223. Doo::loadClass('invoice.func');
  3224. Doo::loadModel('invoiceROLog');
  3225. $invoiceROLog = new invoiceROLog();
  3226. Doo::loadModel('invoiceStatistics');
  3227. $invoiceStatistics = new invoiceStatistics();
  3228. $exlArray = formatExcelToArrayBank(DOO::conf()->SITE_PATH . "upload/invoiceReceivablesBank/" . $path);
  3229. $bankBatchNumber = 'BBN_' . time();
  3230. Doo::db()->beginTransaction();
  3231. // 批量存储收款--由于必须获得收款ID,
  3232. $sql = 'INSERT INTO CLD_invoiceReceivables (OriginalPrice,receivablesPrice, receivablesMessage,receivablesSerial,receivablesBank,receivablesDate,inputStaff,date,receivablesCategory,receivablesStaff,bankBatchNumber,recepitTitleMark)
  3233. VALUES ';
  3234. $date = date("Y-m-d");
  3235. $receivablesList = array();
  3236. foreach ($exlArray as $key => $value) {
  3237. $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"] . '")';
  3238. array_push($receivablesList, $receivablesSql);
  3239. }
  3240. $sql = $sql . implode(',', $receivablesList);
  3241. // echo $sql;
  3242. Doo::db()->query($sql);
  3243. // 批量存储收款统计
  3244. // 获得刚刚导入数据的irid组-缺少办事处和人员
  3245. $iridList = $invoiceReceivables->getInvoiceReceivablesByBBN($bankBatchNumber);
  3246. // 没有irid 回滚所有操作
  3247. if (empty($iridList)) {
  3248. Doo::db()->rollBack();
  3249. header('Content-Type:text/html;charset=utf-8');
  3250. die('文档或数据不正确,请重新<a href="/invoiceReceivables">上传</a>.');
  3251. }
  3252. $sql = 'INSERT INTO CLD_invoiceStatistics (date, priceClass,irid,receivablesPrice)
  3253. VALUES ';
  3254. $statisticsList = array();
  3255. foreach ($iridList as $value) {
  3256. $statisticsSql = '("' . $date . '",2,' . $value['irid'] . ',' . $value["receivablesPrice"] . ')';
  3257. array_push($statisticsList, $statisticsSql);
  3258. }
  3259. $sql = $sql . implode(',', $statisticsList);
  3260. Doo::db()->query($sql);
  3261. // 批量存储操作日志
  3262. $sql = 'INSERT INTO CLD_invoiceROLog (operation, date,status,img, username,uid,category,irid)
  3263. VALUES ';
  3264. $ROLogList = array();
  3265. foreach ($iridList as $value) {
  3266. $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'] . '")';
  3267. array_push($ROLogList, $ROLogSql);
  3268. }
  3269. $sql = $sql . implode(',', $ROLogList);
  3270. Doo::db()->query($sql);
  3271. // 批量写入流水
  3272. $sql = 'INSERT INTO CLD_wasteBook (dataID, expensesType,accountType,accountPriceShow, accountPrice,accountBank,category,cid,name,sid,inputDate)
  3273. VALUES ';
  3274. $wasteBookList = array();
  3275. foreach ($iridList as $value) {
  3276. $accountBank = '';
  3277. if ($value['receivablesBank'] == '纵横广发') {
  3278. $accountBank = 'CGBDeposit';
  3279. } elseif ($value['receivablesBank'] == '纵横工行') {
  3280. $accountBank = 'ICBCDeposit';
  3281. } elseif ($value['receivablesBank'] == '华润银行') {
  3282. $accountBank = 'HUADeposit';
  3283. } elseif ($value['receivablesBank'] == '个人广发') {
  3284. $accountBank = 'PersonalDeposit';
  3285. }
  3286. $wasteBookSql = '("' . $value['irid'] . ' ",1,7,"' . $value['receivablesPrice'] . '","' . $value['receivablesPrice'] . '","' . $accountBank . '",
  3287. "' . $this->staff[0]['category'] . '","' . $this->staff[0]['cid'] . '","' . $this->staff[0]['username'] . '","' . $this->staff[0]['sid'] . '","' . date("Y-m-d H:i:s") . '")';
  3288. array_push($wasteBookList, $wasteBookSql);
  3289. }
  3290. $sql = $sql . implode(',', $wasteBookList);
  3291. Doo::db()->query($sql);
  3292. Doo::db()->commit();
  3293. return "/invoiceReceivables";
  3294. }
  3295. echo 'no file';
  3296. }
  3297. function invoiceReceivables()
  3298. {
  3299. $invoiceTC = $this->get_args('invoiceTC') ? $this->get_args('invoiceTC') : '';
  3300. Doo::loadModel('L_category');
  3301. $lCategory = new L_category();
  3302. Doo::loadModel('staff');
  3303. $staff = new staff();
  3304. Doo::loadModel('invoiceReceivables');
  3305. $invoiceReceivables = new invoiceReceivables();
  3306. Doo::loadModel('invoice');
  3307. $invoice = new invoice();
  3308. Doo::loadClass('XDeode');
  3309. $XDeode = new XDeode(5);
  3310. $category = $lCategory->getCategory();
  3311. $staffList = $staff->getStaffByCid($this->staff[0]['cid']);
  3312. $sql = 'bindStatus=1 and iid!=0';
  3313. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByNew(4, $sql);
  3314. // 获取未入账发票
  3315. $invoiceUnAccount = $invoice->getInvoiceByUnAccount($invoiceTC);
  3316. $invoiceExistAccount = $invoice->getInvoiceByUnAccount('', true);
  3317. foreach ($invoiceUnAccount as $key => $value) {
  3318. $invoiceUnAccount[$key]['iidKey'] = $XDeode->encode($value['iid']);
  3319. $lastApprover = json_decode($value['processApprovals'], true);
  3320. if (!empty($lastApprover)) {
  3321. $lastApproverKey = array_keys($lastApprover);
  3322. $lastApprover = end($lastApprover);
  3323. $staffDetail = $staff->getOne(array(
  3324. 'where' => 'sid=' . end($lastApproverKey),
  3325. 'asArray' => true
  3326. ));
  3327. $lastApprover['username'] = $staffDetail['username'];
  3328. }
  3329. $invoiceUnAccount[$key]['lastApprover'] = $lastApprover;
  3330. }
  3331. foreach ($invoiceExistAccount as $key => $value) {
  3332. // $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  3333. // if (empty ( $irList ))
  3334. // $irList [0] ['sumPrice'] = 0;
  3335. //$balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  3336. $invoiceExistAccount[$key]['existAccount'] = $value['invoicePrice'] - $value['invoiceBalance'];
  3337. //$invoiceExistAccount [$key] ['balance'] = $balance;
  3338. }
  3339. $receivablesInput = $invoiceReceivables->getInvoiceReceivablesByInput();
  3340. $halfList = $invoiceReceivables->getInvoiceReceivablesByHalf();
  3341. $this->data['halfList'] = $halfList;
  3342. $this->data['halfCount'] = count($halfList);
  3343. // print_r($receivablesList);
  3344. $this->data['receivablesDate'] = date("Y-m-d");
  3345. $this->data['ieaCount'] = count($invoiceExistAccount);
  3346. $this->data['invoiceExistAccount'] = $invoiceExistAccount;
  3347. $this->data['receivablesInput'] = $receivablesInput;
  3348. $this->data['year'] = date('Y');
  3349. $this->data['invoiceUnAccount'] = $invoiceUnAccount;
  3350. $this->data['receivablesList'] = $receivablesList;
  3351. $this->data['staffList'] = $staffList;
  3352. $this->data['category'] = $category;
  3353. $this->data['memu'] = "invoice";
  3354. $this->data['staff'] = $this->staff;
  3355. $this->data['receiptMemu'] = 'invoiceReceivables';
  3356. $this->render("/admin/invoiceReceivables", $this->data);
  3357. }
  3358. /**
  3359. * 设置收款认领地区
  3360. */
  3361. function setInvoiceReceivablesClaim()
  3362. {
  3363. $iridKey = $this->get_args('iridKey') ? $this->get_args('iridKey') : "";
  3364. $receivablesCategory = $this->get_args('receivablesCategory') ? $this->get_args('receivablesCategory') : "";
  3365. $action = $this->get_args('action') ? $this->get_args('action') : "";
  3366. if (!empty($iridKey) && !empty($receivablesCategory)) {
  3367. Doo::loadModel('invoiceReceivables');
  3368. $invoiceReceivables = new invoiceReceivables();
  3369. Doo::loadClass('XDeode');
  3370. $XDeode = new XDeode(5);
  3371. Doo::loadModel('invoiceROLog');
  3372. $invoiceROLog = new invoiceROLog();
  3373. $irid = $XDeode->decode($iridKey);
  3374. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid($irid);
  3375. if (empty($irDetail))
  3376. die('illegal request');
  3377. $item = array(
  3378. 'irid' => $irid,
  3379. 'receivablesCategory' => $receivablesCategory
  3380. );
  3381. if ($receivablesCategory != 'PUBLIC') {
  3382. $item += array(
  3383. 'confirmTime' => date("Y-m-d H:i:s"),
  3384. 'inputType' => 1
  3385. );
  3386. }
  3387. $invoiceReceivables = new invoiceReceivables();
  3388. $invoiceReceivables->setInvoiceReceivablesByCondition($item);
  3389. // 收款操作日志
  3390. $item = array(
  3391. 'operation' => $this->staff[0]['username'] . " 转入 公共待认领款项 ",
  3392. 'date' => date("Y-m-d"),
  3393. 'status' => 1,
  3394. 'img' => $this->staff[0]['avatar'],
  3395. 'username' => $this->staff[0]['username'],
  3396. 'uid' => $this->staff[0]['sid'],
  3397. 'category' => $this->staff[0]['category'],
  3398. 'irid' => $irid
  3399. );
  3400. $invoiceROLog->setInvoiceROLog($item);
  3401. if (empty($action))
  3402. return '/invoiceReceivables';
  3403. else
  3404. return "/invoiceReceivablesAS";
  3405. }
  3406. die('illegal request');
  3407. }
  3408. /**
  3409. * 新添加收款直接入账发票
  3410. */
  3411. function invoiceCompareClaimPrice()
  3412. {
  3413. // 收款录入
  3414. $iidKey = $this->get_args('iidKey') ? $this->get_args('iidKey') : "";
  3415. $receivablesPrice = $this->get_args('receivablesPrice') ? $this->get_args('receivablesPrice') : "";
  3416. $receivablesMessage = $this->get_args('receivablesMessage') ? $this->get_args('receivablesMessage') : "";
  3417. $receivablesBank = $this->get_args('receivablesBank') ? $this->get_args('receivablesBank') : "";
  3418. $receivablesDate = $this->get_args('receivablesDate') ? $this->get_args('receivablesDate') : "";
  3419. if (!empty($receivablesPrice) && !empty($receivablesMessage) && !empty($receivablesBank) && !empty($receivablesDate) && !empty($iidKey)) {
  3420. Doo::loadModel('invoiceReceivables');
  3421. $invoiceReceivables = new invoiceReceivables();
  3422. Doo::loadModel('invoiceROLog');
  3423. $invoiceROLog = new invoiceROLog();
  3424. Doo::loadModel('invoiceStatistics');
  3425. Doo::loadModel('invoice');
  3426. $invoice = new invoice();
  3427. Doo::loadModel('bill');
  3428. $bill = new bill();
  3429. Doo::loadClass('XDeode');
  3430. $XDeode = new XDeode(5);
  3431. Doo::loadModel('invoiceOperationLog');
  3432. $invoiceOperationLog = new invoiceOperationLog();
  3433. $iidKey = $XDeode->decode($iidKey);
  3434. $invoiceDetail = $invoice->getInvoiceByIid($iidKey);
  3435. if (!($invoiceDetail['status'] == 2 && $invoiceDetail['printStatus'] == 1 && $invoiceDetail['untreadStatus'] == 0))
  3436. die('illegal request');
  3437. $receivablesSerial = "#SK" . date("Ymd") . mt_rand(1000, 9999);
  3438. // 收款录入 并绑定发票
  3439. Doo::db()->beginTransaction();
  3440. //获得发票入账余额
  3441. //$bindInvicePrice=$invoiceReceivables->getSumOfReceivablesPrice ( $invoiceDetail['irid'] );
  3442. //$bindPrice=$invoiceDetail ['invoiceBalance']-$bindInvicePrice;
  3443. $bindStatus = 0;
  3444. $invoiceBalance = $invoiceDetail['invoicePrice'];
  3445. if ($invoiceDetail['invoiceBalance'] != 0) {
  3446. $invoiceBalance = $invoiceDetail['invoiceBalance'];
  3447. }
  3448. if ($receivablesPrice <= $invoiceBalance) {
  3449. $bindStatus = 1;
  3450. //$bindPrice=$receivablesPrice;
  3451. }
  3452. $titleMark = $invoiceDetail['invoiceTitle'];
  3453. if (!empty($invoiceDetail['invoiceCompany']))
  3454. $titleMark = $invoiceDetail['invoiceCompany'];
  3455. $item = array(
  3456. 'recepitTitleMark' => $titleMark,
  3457. 'bindStatus' => $bindStatus,
  3458. 'iid' => $invoiceDetail['iid'],
  3459. 'bindPrice' => $receivablesPrice,
  3460. 'bindDate' => date("Y-m-d H:i:s"),
  3461. 'receivablesPrice' => $receivablesPrice,
  3462. 'OriginalPrice' => $receivablesPrice,
  3463. 'receivablesMessage' => $receivablesMessage,
  3464. 'receivablesSerial' => $receivablesSerial,
  3465. 'receivablesBank' => $receivablesBank,
  3466. 'receivablesDate' => $receivablesDate,
  3467. 'inputStaff' => $this->staff[0]['username'],
  3468. 'accountClerk' => $this->staff[0]['username'],
  3469. 'date' => date("Y-m-d"),
  3470. 'receivablesCategory' => $invoiceDetail['cid'] . ':' . $invoiceDetail['categoryName'],
  3471. 'receivablesStaff' => $invoiceDetail['sid'] . '-' . $invoiceDetail['userName'],
  3472. 'confirmTime' => date("Y-m-d H:i:s")
  3473. );
  3474. $irid = $invoiceReceivables->addInvoiceReceivables($item);
  3475. $item = array();
  3476. // 收款操作日志
  3477. $item = array(
  3478. 'operation' => $this->staff[0]['username'] . " 转入 " . $invoiceDetail['userName']
  3479. );
  3480. $item += array(
  3481. 'date' => date("Y-m-d"),
  3482. 'status' => 1,
  3483. 'img' => $this->staff[0]['avatar'],
  3484. 'username' => $this->staff[0]['username'],
  3485. 'uid' => $this->staff[0]['sid'],
  3486. 'category' => $this->staff[0]['category'],
  3487. 'irid' => $irid
  3488. );
  3489. $invoiceROLog->setInvoiceROLog($item);
  3490. // 收款统计
  3491. $invoiceStatistics = new invoiceStatistics();
  3492. $item = array(
  3493. 'date' => $receivablesDate,
  3494. 'priceClass' => 2,
  3495. 'irid' => $irid,
  3496. 'cid' => $invoiceDetail['cid'],
  3497. 'staff' => $invoiceDetail['sid'],
  3498. 'receivablesPrice' => $receivablesPrice
  3499. );
  3500. $invoiceStatistics->setInvoiceStatisticsByCondition($item);
  3501. // 收款 入 发票
  3502. $detail = $invoiceDetail;
  3503. $iridString = "";
  3504. if (empty($detail['irid']))
  3505. $iridString = $irid;
  3506. else
  3507. $iridString = $detail['irid'] . ',' . $irid;
  3508. $item = array(
  3509. 'irid' => $iridString,
  3510. 'bindTime' => date("Y-m-d H:i:s"),
  3511. 'updateTime' => date("Y-m-d H:i:s"),
  3512. 'iid' => $detail['iid']
  3513. );
  3514. // $invoiceReceivables = new invoiceReceivables ();
  3515. // $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  3516. // $sumBind = $bindInvicePrice;
  3517. // $sumBalance=$invoiceReceivables->balanceOfReceivablesPrice($irid);
  3518. // $sum=$sumBind+$sumBalance;
  3519. // ;
  3520. if ($receivablesPrice >= $invoiceBalance) {
  3521. $item += array(
  3522. 'invoiceBalance' => 0,
  3523. 'untreadStatus' => 3
  3524. );
  3525. } else {
  3526. $item += array(
  3527. 'invoiceBalance' => $invoiceBalance - $receivablesPrice
  3528. );
  3529. }
  3530. $invoice->setInvoiceByCondition($item);
  3531. // 操作日志
  3532. $item = array(
  3533. 'date' => date("Y-m-d H:i:s"),
  3534. 'operation' => "收款入账" . $receivablesSerial . "到发票" . $detail['invoiceSerial'],
  3535. 'status' => 8,
  3536. 'img' => $this->staff[0]['avatar'],
  3537. 'username' => $this->staff[0]['username'],
  3538. 'uid' => $this->staff[0]['sid'],
  3539. 'category' => $this->staff[0]['category'],
  3540. 'iid' => $detail['iid']
  3541. );
  3542. $invoiceOperationLog->setInvoiceOperationLog($item);
  3543. // 入账汇总
  3544. $invoiceStatistics = new invoiceStatistics();
  3545. // $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $iridString );
  3546. // $accountPrice = 0;
  3547. // foreach ( $list as $key => $value ) {
  3548. // $accountPrice += $value ['receivablesPrice'];
  3549. // }
  3550. $item = array(
  3551. 'date' => $receivablesDate,
  3552. 'priceClass' => 3,
  3553. 'cid' => $invoiceDetail['cid'],
  3554. 'staff' => $invoiceDetail['sid'],
  3555. 'accountPrice' => $receivablesPrice
  3556. );
  3557. $invoiceStatistics->setInvoiceStatisticsByCondition($item);
  3558. //发票入账记录
  3559. $bill->iid = $invoiceDetail['iid'];
  3560. $bill->trainId = $invoiceDetail['trainId'];
  3561. $bill->irid = $irid;
  3562. $bill->create_time = date("Y-m-d H:i:s");
  3563. $bill->price = $invoiceBalance;
  3564. $bill->insert();
  3565. // 公司流水记录
  3566. Doo::loadModel('wasteBook');
  3567. $wasteBook = new wasteBook();
  3568. $abDetail = $wasteBook->getAccountBookByAid(1, 7, $irid);
  3569. $accountBank = $wasteBook->_getAccountBankEN($receivablesBank);
  3570. if (empty($abDetail)) {
  3571. $item = array(
  3572. 'dataID' => $irid,
  3573. 'expensesType' => 1,
  3574. 'accountType' => 7,
  3575. 'accountPrice' => $receivablesPrice,
  3576. 'accountPriceShow' => $receivablesPrice,
  3577. 'accountBank' => $accountBank,
  3578. 'cid' => $invoiceDetail['cid'],
  3579. 'category' => $invoiceDetail['categoryName'],
  3580. 'name' => $this->staff[0]['username'],
  3581. 'sid' => $this->staff[0]['sid'],
  3582. 'inputDate' => $receivablesDate //date ( "Y-m-d H:i:s" )
  3583. );
  3584. $wasteBook->setAccountBookStatistics($item);
  3585. }
  3586. Doo::db()->commit();
  3587. }
  3588. return '/invoiceReceivables';
  3589. }
  3590. /**
  3591. * 录入收款数据
  3592. * @return string
  3593. */
  3594. function invoiceReceivablesDo()
  3595. {
  3596. $receivablesPrice = $this->get_args('receivablesPrice') ? $this->get_args('receivablesPrice') : "";
  3597. $receivablesMessage = $this->get_args('receivablesMessage') ? $this->get_args('receivablesMessage') : "";
  3598. $receivablesBank = $this->get_args('receivablesBank') ? $this->get_args('receivablesBank') : "";
  3599. $receivablesDate = $this->get_args('receivablesDate') ? $this->get_args('receivablesDate') : "";
  3600. $receivablesCategory = $this->get_args('receivablesCategory') ? $this->get_args('receivablesCategory') : "";
  3601. $receivablesStaff = $receivablesStaff2 = $this->get_args('receivablesStaff') ? $this->get_args('receivablesStaff') : "";
  3602. Doo::loadModel('invoiceReceivables');
  3603. $invoiceReceivables = new invoiceReceivables();
  3604. Doo::loadModel('invoiceROLog');
  3605. $invoiceROLog = new invoiceROLog();
  3606. Doo::loadModel('invoiceStatistics');
  3607. $invoiceStatistics = new invoiceStatistics();
  3608. if (!empty($receivablesPrice) && !empty($receivablesMessage) && !empty($receivablesBank) && !empty($receivablesDate) && !empty($receivablesCategory) && !empty($receivablesStaff)) {
  3609. $item = array(
  3610. 'receivablesPrice' => $receivablesPrice,
  3611. 'OriginalPrice' => $receivablesPrice,
  3612. 'receivablesMessage' => $receivablesMessage,
  3613. 'receivablesSerial' => "#SK" . date("Ymd") . mt_rand(1000, 9999),
  3614. 'receivablesBank' => $receivablesBank,
  3615. 'receivablesDate' => $receivablesDate,
  3616. 'inputStaff' => $this->staff[0]['username'],
  3617. 'date' => date("Y-m-d"),
  3618. 'receivablesCategory' => $receivablesCategory,
  3619. 'receivablesStaff' => $receivablesStaff
  3620. );
  3621. if ($receivablesCategory != 'PUBLIC') {
  3622. $item += array(
  3623. 'confirmTime' => date("Y-m-d H:i:s"),
  3624. 'inputType' => 1
  3625. );
  3626. }
  3627. $irid = $invoiceReceivables->addInvoiceReceivables($item);
  3628. $item = array();
  3629. // 收款操作日志
  3630. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3631. $item = array(
  3632. 'operation' => $this->staff[0]['username'] . " 转入 公共待认领款项 "
  3633. );
  3634. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3635. $item = array(
  3636. 'operation' => $this->staff[0]['username'] . "转入 办事处待认领款项"
  3637. );
  3638. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3639. $receivablesStaff = explode('-', $receivablesStaff);
  3640. $item = array(
  3641. 'operation' => $this->staff[0]['username'] . " 转入 " . $receivablesStaff[1]
  3642. );
  3643. }
  3644. $item += array(
  3645. 'date' => date("Y-m-d"),
  3646. 'status' => 1,
  3647. 'img' => $this->staff[0]['avatar'],
  3648. 'username' => $this->staff[0]['username'],
  3649. 'uid' => $this->staff[0]['sid'],
  3650. 'category' => $this->staff[0]['category'],
  3651. 'irid' => $irid
  3652. );
  3653. $invoiceROLog->setInvoiceROLog($item);
  3654. $item = array(
  3655. 'date' => $receivablesDate,
  3656. 'priceClass' => 2,
  3657. 'irid' => $irid,
  3658. 'receivablesPrice' => $receivablesPrice
  3659. );
  3660. if ($receivablesCategory != 'PUBLIC') {
  3661. $receivablesCategory = explode(":", $receivablesCategory);
  3662. $item += array(
  3663. 'cid' => $receivablesCategory[0]
  3664. );
  3665. }
  3666. if ($receivablesStaff2 != 'PUBLIC') {
  3667. $receivablesStaff = explode("-", $receivablesStaff2);
  3668. $item += array(
  3669. 'staff' => $receivablesStaff[0]
  3670. );
  3671. }
  3672. $invoiceStatistics->setInvoiceStatisticsByCondition($item);
  3673. $toparty = $this->getWxidByCategory($receivablesCategory[1]);
  3674. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  3675. $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  3676. if ($toparty != 0)
  3677. $this->msgSendToparty($msg, '', '', $toparty, 'text');
  3678. // 公司流水记录
  3679. Doo::loadModel('wasteBook');
  3680. $wasteBook = new wasteBook();
  3681. $abDetail = $wasteBook->getAccountBookByAid(1, 7, $irid);
  3682. $accountBank = $wasteBook->_getAccountBankEN($receivablesBank);
  3683. $item = array(
  3684. 'dataID' => $irid,
  3685. 'expensesType' => 1,
  3686. 'accountType' => 7,
  3687. 'accountPriceShow' => $receivablesPrice,
  3688. 'accountPrice' => $receivablesPrice,
  3689. 'accountBank' => $accountBank,
  3690. 'category' => $this->staff[0]['category'],
  3691. 'cid' => $this->staff[0]['cid'],
  3692. 'name' => $this->staff[0]['username'],
  3693. 'sid' => $this->staff[0]['sid'],
  3694. 'inputDate' => $receivablesDate,
  3695. //'createAt'=>date ( "Y-m-d H:i:s" ) ,
  3696. 'synPaymentDate' => 1
  3697. );
  3698. $wasteBook->setAccountBookStatistics($item);
  3699. }
  3700. return "/invoiceReceivables";
  3701. }
  3702. /**
  3703. * 收款认领页面-包括公共认领 办事处认领 最近已认领数据
  3704. */
  3705. function invoiceReceivablesClaim()
  3706. {
  3707. Doo::loadModel('invoiceReceivables');
  3708. $invoiceReceivables = new invoiceReceivables();
  3709. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByClaim($this->staff[0]['cid'], $this->staff[0]['sid']);
  3710. $this->data['receivablesList'] = $receivablesList;
  3711. $this->data['memu'] = "invoice";
  3712. $this->data['staff'] = $this->staff;
  3713. $this->data['receiptMemu'] = 'invoiceReceivablesClaim';
  3714. $this->render("/admin/invoiceReceivablesClaim", $this->data);
  3715. }
  3716. function invoiceReceivablesTitleMarkSet()
  3717. {
  3718. $iridKey = $this->get_args('iridKey') ? $this->get_args('iridKey') : "";
  3719. $recepitTitleMark = $this->get_args('recepitTitleMark') ? $this->get_args('recepitTitleMark') : "";
  3720. if (empty($iridKey) || empty($recepitTitleMark))
  3721. die('illegal request');
  3722. Doo::loadModel('invoiceReceivables');
  3723. $invoiceReceivables = new invoiceReceivables();
  3724. Doo::loadClass('XDeode');
  3725. $XDeode = new XDeode(5);
  3726. $irid = $XDeode->decode($iridKey);
  3727. if (!is_numeric($irid))
  3728. die('illegal request');
  3729. $invoiceReceivables->recepitTitleMark = $recepitTitleMark;
  3730. $invoiceReceivables->update(array(
  3731. 'where' => 'irid = ' . $irid
  3732. ));
  3733. return '/invoiceReceivablesClaim';
  3734. }
  3735. /**
  3736. * 更新收款相关数据
  3737. */
  3738. function invoiceReceivablesUpdateClaim()
  3739. {
  3740. $receivablesPrice = $this->get_args('receivablesPrice') ? $this->get_args('receivablesPrice') : "";
  3741. $receivablesMessage = $this->get_args('receivablesMessage') ? $this->get_args('receivablesMessage') : "";
  3742. $receivablesBank = $this->get_args('receivablesBank') ? $this->get_args('receivablesBank') : "";
  3743. $receivablesDate = $this->get_args('receivablesDate') ? $this->get_args('receivablesDate') : "";
  3744. $receivablesCategory = $this->get_args('receivablesCategory') ? $this->get_args('receivablesCategory') : "";
  3745. $receivablesStaff = $receivablesStaff2 = $this->get_args('receivablesStaff') ? $this->get_args('receivablesStaff') : "";
  3746. $claimKey = $this->get_args('claimKey') ? $this->get_args('claimKey') : "";
  3747. if (empty($claimKey))
  3748. die('illegal request');
  3749. Doo::loadModel('invoiceReceivables');
  3750. $invoiceReceivables = new invoiceReceivables();
  3751. Doo::loadModel('invoiceROLog');
  3752. $invoiceROLog = new invoiceROLog();
  3753. $con = ' and iid=0 and bindStatus=0'; // and receivablesCategory!="PUBLIC" and receivablesStaff!="PUBLIC"
  3754. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid($claimKey, $con);
  3755. if (empty($detail))
  3756. die('illegal request');
  3757. $invoiceReceivables = new invoiceReceivables();
  3758. $item = array(
  3759. 'irid' => $detail['irid']
  3760. );
  3761. if ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3762. $item += array(
  3763. 'confirmTime' => date("Y-m-d H:i:s")
  3764. );
  3765. }
  3766. if (!empty($receivablesCategory))
  3767. $item += array(
  3768. 'receivablesCategory' => $receivablesCategory
  3769. );
  3770. if (!empty($receivablesStaff))
  3771. $item += array(
  3772. 'receivablesStaff' => $receivablesStaff
  3773. );
  3774. if (!empty($receivablesPrice))
  3775. $item += array(
  3776. 'receivablesPrice' => $receivablesPrice
  3777. );
  3778. if (!empty($receivablesMessage))
  3779. $item += array(
  3780. 'receivablesMessage' => $receivablesMessage
  3781. );
  3782. if (!empty($receivablesBank))
  3783. $item += array(
  3784. 'receivablesBank' => $receivablesBank
  3785. );
  3786. if (!empty($receivablesDate))
  3787. $item += array(
  3788. 'receivablesDate' => $receivablesDate
  3789. );
  3790. $invoiceReceivables->setInvoiceReceivablesByCondition($item);
  3791. // 收款操作日志
  3792. $item = array();
  3793. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3794. $item = array(
  3795. 'operation' => $this->staff[0]['username'] . " 转入 公共待认领款项 "
  3796. );
  3797. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3798. $item = array(
  3799. 'operation' => $this->staff[0]['username'] . "转入 办事处待认领款项"
  3800. );
  3801. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3802. $receivablesStaff = explode('-', $receivablesStaff);
  3803. $item = array(
  3804. 'operation' => $this->staff[0]['username'] . " 转入 " . $receivablesStaff[1]
  3805. );
  3806. }
  3807. $item += array(
  3808. 'date' => date("Y-m-d"),
  3809. 'status' => 1,
  3810. 'img' => $this->staff[0]['avatar'],
  3811. 'username' => $this->staff[0]['username'],
  3812. 'uid' => $this->staff[0]['sid'],
  3813. 'category' => $this->staff[0]['category'],
  3814. 'irid' => $detail['irid']
  3815. );
  3816. $invoiceROLog->setInvoiceROLog($item);
  3817. return '/invoiceReceivablesAS';
  3818. }
  3819. function invoiceReceivablesDelete()
  3820. {
  3821. $claimKey = $this->get_args('claimKey') ? $this->get_args('claimKey') : "";
  3822. $skll = $this->get_args('skll') ? $this->get_args('skll') : "";
  3823. if ($skll != '删除到款')
  3824. die('illegal request-未填写 删除到款');
  3825. if (empty($claimKey))
  3826. die('illegal request-收款key不正确');
  3827. Doo::loadModel('invoiceReceivables');
  3828. $invoiceReceivables = new invoiceReceivables();
  3829. $con = ' and bindStatus=0 ';
  3830. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid($claimKey, $con);
  3831. if (empty($detail))
  3832. die('illegal request-未找到该收款或者未解绑');
  3833. $invoiceReceivables->delInvoiceReceivablesByIrid($detail['irid']);
  3834. // 扣除收款汇总信息 汇总
  3835. Doo::loadModel('invoiceStatistics');
  3836. $invoiceStatistics = new invoiceStatistics();
  3837. $item = array(
  3838. 'date' => $detail['receivablesDate'],
  3839. 'priceClass' => 2,
  3840. 'irid' => $detail['irid'],
  3841. 'receivablesPrice' => -$detail['receivablesPrice']
  3842. );
  3843. if ($detail['receivablesCategory'] != 'PUBLIC') {
  3844. $receivablesCategory = explode(":", $detail['receivablesCategory']);
  3845. $item += array(
  3846. 'cid' => $receivablesCategory[0]
  3847. );
  3848. }
  3849. if ($detail['receivablesStaff'] != 'PUBLIC') {
  3850. $receivablesStaff = explode("-", $detail['receivablesStaff']);
  3851. $item += array(
  3852. 'staff' => $receivablesStaff[0]
  3853. );
  3854. }
  3855. $invoiceStatistics->setInvoiceStatisticsByCondition($item);
  3856. // 公司流水-删除时删除流水
  3857. Doo::loadModel('wasteBook');
  3858. $wasteBook = new wasteBook();
  3859. $wasteBook->delete(array(
  3860. 'where' => 'dataID=' . $detail['irid'] . ' and accountType=7',
  3861. 'limit' => 1
  3862. ));
  3863. return '/invoiceReceivablesAS';
  3864. }
  3865. /**
  3866. * 管理员录入的收款 ,确认认领到谁的名下.统计收款金额
  3867. */
  3868. function invoiceReceivablesAscription()
  3869. {
  3870. $irid = $this->get_args('key') ? $this->get_args('key') : "";
  3871. $recepitTitleMark = $this->get_args('recepitTitleMark') ? $this->get_args('recepitTitleMark') : "";
  3872. Doo::loadModel('invoiceReceivables');
  3873. $invoiceReceivables = new invoiceReceivables();
  3874. Doo::loadModel('invoiceROLog');
  3875. $invoiceROLog = new invoiceROLog();
  3876. Doo::loadModel('invoiceStatistics');
  3877. $invoiceStatistics = new invoiceStatistics();
  3878. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid($irid);
  3879. $irid = $invoiceReceivables->authcode($irid);
  3880. if (!empty($detail) && $detail['receivablesStaff'] == 'PUBLIC' && !empty($recepitTitleMark)) {
  3881. $item = array(
  3882. 'irid' => $detail['irid'],
  3883. 'receivablesCategory' => $this->staff[0]['cid'] . ":" . $this->staff[0]['category'],
  3884. 'receivablesStaff' => $this->staff[0]['sid'] . "-" . $this->staff[0]['username'],
  3885. 'confirmTime' => date("Y-m-d H:i:s"),
  3886. 'recepitTitleMark' => $recepitTitleMark,
  3887. 'adoptStaffId' => $this->staff[0]['sid'],
  3888. 'adoptStaffName' => $this->staff[0]['username'],
  3889. 'adoptDepartmentId' => $this->staff[0]['departmentId2'],
  3890. 'adoptDepartmentName' => $this->staff[0]['departmentName'],
  3891. 'source' => 1
  3892. );
  3893. $invoiceReceivables->setInvoiceReceivablesByCondition($item);
  3894. $item = array(
  3895. 'date' => date("Y-m-d"),
  3896. 'operation' => $this->staff[0]['username'] . " 认领 ",
  3897. 'status' => 2,
  3898. 'img' => $this->staff[0]['avatar'],
  3899. 'username' => $this->staff[0]['username'],
  3900. 'uid' => $this->staff[0]['sid'],
  3901. 'category' => $this->staff[0]['category'],
  3902. 'irid' => $irid
  3903. );
  3904. $invoiceROLog->setInvoiceROLog($item);
  3905. $item = array(
  3906. 'cid' => $this->staff[0]['cid'],
  3907. 'staff' => $this->staff[0]['sid']
  3908. );
  3909. $invoiceStatistics->updateInvoiceStatisticsByIrid($item, $detail['irid'], 2);
  3910. //更新流水的办事处
  3911. Doo::loadModel('wasteBook');
  3912. $wasteBook = new wasteBook();
  3913. $abDetail = $wasteBook->getAccountBookByAid(1, 7, $detail['irid']);
  3914. $wasteBook->wid = $abDetail['wid'];
  3915. $wasteBook->category = $this->staff[0]['category'];
  3916. $wasteBook->cid = $this->staff[0]['cid'];
  3917. $wasteBook->update();
  3918. }
  3919. return "/invoiceReceivablesClaim";
  3920. }
  3921. /**
  3922. */
  3923. function invoiceMyReceivables()
  3924. {
  3925. Doo::loadModel('invoiceReceivables');
  3926. $invoiceReceivables = new invoiceReceivables();
  3927. Doo::loadModel('invoiceStatistics');
  3928. $invoiceStatistics = new invoiceStatistics();
  3929. $isMonth = $invoiceStatistics->getStatisticsByMonth($this->staff[0]['sid']);
  3930. $year = date("Y");
  3931. $tmp_date = date("Ym");
  3932. $tmp_year = substr($tmp_date, 0, 4);
  3933. $tmp_mon = substr($tmp_date, 4, 2);
  3934. $tmp_forwardmonth = mktime(0, 0, 0, $tmp_mon - 1, 1, $tmp_year);
  3935. $fm_forward_month = date("m", $tmp_forwardmonth);
  3936. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . ".htm";
  3937. $htm = $this->showCache($path);
  3938. $list = $invoiceReceivables->getInvoiceReceivablesByClaim($this->staff[0]['cid'], $this->staff[0]['sid']);
  3939. $this->data['isMonth'] = $isMonth;
  3940. $this->data['htm'] = $htm;
  3941. $this->data['list'] = $list;
  3942. $this->data['memu'] = "invoice";
  3943. $this->data['staff'] = $this->staff;
  3944. $this->data['receiptMemu'] = 'invoiceMyReceivables';
  3945. $this->render("/admin/invoiceMyReceivables", $this->data);
  3946. }
  3947. /**
  3948. * 纸票管理
  3949. */
  3950. function invoicePaper()
  3951. {
  3952. $status = $this->get_args('status') ? $this->get_args('status') : 'ALL';
  3953. $invoiceType = $this->get_args('invoiceType') ? $this->get_args('invoiceType') : "ALL";
  3954. $date = $this->get_args('date') ? $this->get_args('date') : "";
  3955. $this->data['dateString'] = $date;
  3956. $this->data['status'] = $status;
  3957. $this->data['invoiceType'] = $invoiceType;
  3958. $this->data['memu'] = "invoice";
  3959. $this->data['staff'] = $this->staff;
  3960. $this->data['receiptMemu'] = 'invoicePaper';
  3961. $this->render("/admin/invoicePaper", $this->data);
  3962. }
  3963. /**
  3964. * 电子发票管理
  3965. */
  3966. function invoiceElectronic()
  3967. {
  3968. $status = $this->get_args('status') ? $this->get_args('status') : 'ALL';
  3969. $invoiceType = $this->get_args('invoiceType') ? $this->get_args('invoiceType') : "ALL";
  3970. $date = $this->get_args('date') ? $this->get_args('date') : "";
  3971. $this->data['dateString'] = $date;
  3972. $this->data['status'] = $status;
  3973. $this->data['invoiceType'] = $invoiceType;
  3974. $this->data['memu'] = "invoice";
  3975. $this->data['staff'] = $this->staff;
  3976. $this->data['receiptMemu'] = 'invoicePaper';
  3977. $this->render("/invoice/invoiceElectronic", $this->data);
  3978. }
  3979. /**
  3980. * 获得纸票分页数据
  3981. */
  3982. function ajaxGetinvoicePaperAchieve()
  3983. {
  3984. //include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  3985. Doo::loadModel('invoicePaper');
  3986. $invoicePaper = new invoicePaper();
  3987. $status = $this->get_args('status') ? $this->get_args('status') : 'ALL';
  3988. $invoiceType = $this->get_args('invoiceType') ? $this->get_args('invoiceType') : "ALL";
  3989. $invoiceForm = $this->get_args('invoiceForm') && is_numeric($this->get_args('invoiceForm')) ? $this->get_args('invoiceForm') : "0";
  3990. $invoiceTrain = $this->get_args('invoiceTrain') ? $this->get_args('invoiceTrain') : "ORDINARY";
  3991. $date = $this->get_args('date') ? $this->get_args('date') : "";
  3992. $page = $this->get_args('start') && is_numeric($this->get_args('start')) ? $this->get_args('start') : 0;
  3993. $draw = $this->get_args('draw') && is_numeric($this->get_args('draw')) ? $this->get_args('draw') : 1;
  3994. $length = $this->get_args('length') && is_numeric($this->get_args('length')) ? $this->get_args('length') : 10;
  3995. $MebSea = $this->get_args('search');
  3996. $MebSea = $MebSea['value'];
  3997. $page_size = $length;
  3998. $con = '';
  3999. if ($status == 'ALL')
  4000. $con = ' where 1 ';
  4001. elseif ($status == 'PRINTED')
  4002. $con = ' where a.iid!=0 '; // $con = ' where b.isDelete=0 and a.iid!=0 and b.status=2 and b.untreadStatus=0 ';
  4003. elseif ($status == 'UNPRINT')
  4004. $con = ' where a.iid=0 '; // $con = ' where b.isDelete=0 and a.iid=0 and b.status=2 and b.untreadStatus=0 ';
  4005. elseif ($status == 'TICKET')
  4006. $con = ' where b.isDelete=0 and b.untreadStatus=2';
  4007. if ($invoiceType == 'ORDINARY')
  4008. $con .= ' and a.invoiceType=0 ';
  4009. elseif ($invoiceType == 'SPECIAL')
  4010. $con .= ' and a.invoiceType=1 ';
  4011. if ($invoiceForm == 0) {
  4012. $con .= ' and a.invoiceForm=0 ';
  4013. } else {
  4014. $con .= ' and a.invoiceForm=1 ';
  4015. }
  4016. $dateArr = explode(':', $date);
  4017. $D1 = $dateString = '';
  4018. $D2 = '';
  4019. if (!empty($date)) {
  4020. $D1 = $dateArr[0];
  4021. if (isset($dateArr[1]))
  4022. $D2 = $dateArr[1];
  4023. else
  4024. $D2 = '';
  4025. $dateString = $D1 . " : " . $D2;
  4026. }
  4027. if (!empty($D1) && !empty($D2))
  4028. $con .= ' and b.printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4029. elseif (!empty($D1) && empty($D2))
  4030. $con .= ' and b.printTime like "%' . $D1 . '%" ';
  4031. if (!empty($MebSea))
  4032. $con .= ' and ( b.invoiceTitle like "%' . $MebSea . '%" or b.invoiceCompany like "%' . $MebSea . '%" or a.invoiceNo like "%' . $MebSea . '%" )';
  4033. $invoiceTotal = $invoicePaper->getInvoicePaperCount($invoiceForm);
  4034. $sql = ' ' . $con;
  4035. $limit = $page . ',' . $page_size;
  4036. $list = $invoicePaper->getInvoicePaper($limit, $sql, 'desc');
  4037. $paperList = array();
  4038. foreach ($list as $key => $value) {
  4039. $irDetail = array();
  4040. if ($value['iid'] == 0)
  4041. array_push($irDetail, '<a href="javascript:if(window.confirm(\'确认删除?\'))window.location=\'/invoicePaperDel/' . $value['ipidKey'] . '\'" >删除</a>');
  4042. else
  4043. array_push($irDetail, '');
  4044. array_push($irDetail, $value['invoiceCode']);
  4045. array_push($irDetail, $value['invoiceNo']);
  4046. array_push($irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value['iidKey'] . '\')" data-toggle="modal">' . $value['invoiceSerial'] . '</a>');
  4047. if ($value['invoiceType'] == 1)
  4048. array_push($irDetail, $value['invoiceCompany']);
  4049. else
  4050. array_push($irDetail, $value['invoiceTitle']);
  4051. if ($value['invoiceType'] == 1)
  4052. array_push($irDetail, '¥' . $value['invoicePrice'] . '<sup>专</sup>');
  4053. else
  4054. array_push($irDetail, '¥' . $value['invoicePrice']);
  4055. array_push($irDetail, $value['invoiceElement']);
  4056. array_push($irDetail, $value['categoryName'] . '-' . $value['userName']);
  4057. array_push($irDetail, $value['printTime']);
  4058. array_push($paperList, $irDetail);
  4059. }
  4060. // $approvalListJson = json_encode ( $approvalList );
  4061. $recordsFiltered = $invoiceTotal;
  4062. echo json_encode(array(
  4063. "draw" => intval($draw),
  4064. "recordsTotal" => intval($invoiceTotal),
  4065. "recordsFiltered" => intval($recordsFiltered),
  4066. "data" => $paperList
  4067. ), JSON_UNESCAPED_UNICODE);
  4068. }
  4069. function invoicePaperDel()
  4070. {
  4071. $ipidKey = isset($this->params['ipidKey']) ? $this->params['ipidKey'] : "";
  4072. $XDeode = new XDeode(5);
  4073. $ipid = $XDeode->decode($ipidKey);
  4074. if (empty($ipid))
  4075. die('illegal request');
  4076. Doo::loadModel('invoicePaper');
  4077. $invoicePaper = new invoicePaper();
  4078. $ipdetail = $invoicePaper->getInvoicePaperByIpid($ipid);
  4079. $invoicePaper->delete(array(
  4080. 'where' => 'ipid=' . $ipid . ' and iid=0',
  4081. 'limit' => 1
  4082. ));
  4083. if ($ipdetail['invoiceForm'] == 1) {
  4084. return '/invoiceElectronic';
  4085. } else {
  4086. return '/invoicePaper';
  4087. }
  4088. }
  4089. /**
  4090. * 添加纸质发票号
  4091. */
  4092. function invoicePaperAdd()
  4093. {
  4094. $invoiceType = $this->get_args('invoiceType') && is_numeric($this->get_args('invoiceType')) ? $this->get_args('invoiceType') : '0';
  4095. $invoiceCode = $this->get_args('invoiceCode') ? $this->get_args('invoiceCode') : "";
  4096. $invoiceNoStart = $this->get_args('invoiceNoStart') && is_numeric($this->get_args('invoiceNoStart')) ? $this->get_args('invoiceNoStart') : 0;
  4097. $invoiceNoTotal = $this->get_args('invoiceNoTotal') && is_numeric($this->get_args('invoiceNoTotal')) ? $this->get_args('invoiceNoTotal') : 0;
  4098. $invoiceForm = $this->get_args('invoiceForm') && is_numeric($this->get_args('invoiceForm')) ? $this->get_args('invoiceForm') : 0;
  4099. if ($invoiceType != '' && !empty($invoiceCode) && !empty($invoiceNoStart) && !empty($invoiceNoTotal)) {
  4100. $sum = $invoiceNoStart + $invoiceNoTotal;
  4101. if (empty($sum))
  4102. die('illegal request');
  4103. // echo $invoiceNoStart;
  4104. // echo $sum;
  4105. // echo strlen((int)$invoiceNoStart);
  4106. $sumLenght = strlen($invoiceNoStart) - strlen((int) $invoiceNoStart);
  4107. if ($invoiceType == 0 || $invoiceType == 1) {
  4108. } else {
  4109. die('illegal request invoiceType');
  4110. }
  4111. if ($invoiceForm == 1) {
  4112. $invoiceType = 0;
  4113. }
  4114. Doo::db()->beginTransaction();
  4115. // 批量存储纸质发票
  4116. $date = date("Y-m-d H:i:s");
  4117. $sql = 'INSERT INTO CLD_invoicePaper (invoiceType, invoiceCode,invoiceNo,date,invoiceForm)
  4118. VALUES ';
  4119. $paperList = array();
  4120. for ($invoiceNoStart; $invoiceNoStart <= $sum - 1; $invoiceNoStart++) {
  4121. // 数字前面自加0
  4122. $INLENGHT = strlen((int) $invoiceNoStart) + $sumLenght;
  4123. $var = sprintf("%0" . $INLENGHT . "d", $invoiceNoStart);
  4124. $paperSql = '(' . $invoiceType . ',"' . $invoiceCode . '","' . $var . '","' . $date . '","' . $invoiceForm . '")';
  4125. array_push($paperList, $paperSql);
  4126. }
  4127. if (empty($paperList))
  4128. die('illegal request');
  4129. $sql = $sql . implode(',', $paperList);
  4130. Doo::db()->query($sql);
  4131. Doo::db()->commit();
  4132. if ($invoiceForm == 1) {
  4133. return 'invoiceElectronic';
  4134. } else {
  4135. return 'invoicePaper';
  4136. }
  4137. }
  4138. die('illegal request');
  4139. }
  4140. /**
  4141. * 收款绑定发票 ,//一个收款只能绑定一个发票
  4142. */
  4143. function invoiceBindReceivables()
  4144. {
  4145. $claimKey = $this->get_args('key') ? $this->get_args('key') : "";
  4146. $invoiceKey = $this->get_args('invoiceKey') ? $this->get_args('invoiceKey') : "";
  4147. Doo::loadModel('invoice');
  4148. $invoice = new invoice();
  4149. Doo::loadModel('invoiceReceivables');
  4150. $invoiceReceivables = new invoiceReceivables();
  4151. Doo::loadModel('invoiceOperationLog');
  4152. $invoiceOperationLog = new invoiceOperationLog();
  4153. if (empty($invoiceKey) || empty($claimKey))
  4154. die('illegal request');
  4155. $detail = $invoice->getInvoiceByIid($invoiceKey);
  4156. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid($claimKey);
  4157. if (empty($detail) && empty($detailM))
  4158. die('illegal request');
  4159. if ($detail['untreadStatus'] == 3)
  4160. die('illegal request');
  4161. // 修改 绑定状态改为 金额
  4162. $invoiceReceivables = new invoiceReceivables();
  4163. $invoicePrice = $detail['invoicePrice'] + $detailM['bindPrice'];
  4164. $billPrice = 0;
  4165. if ($detailM['receivablesPrice'] > $invoicePrice) {
  4166. $item = array(
  4167. 'bindPrice' => $invoicePrice
  4168. );
  4169. $billPrice = $invoicePrice;
  4170. } elseif ($detailM['receivablesPrice'] <= $invoicePrice) { //发票金额大于收款金额,绑定金额为收款金额
  4171. $item = array(
  4172. 'bindPrice' => $detailM['receivablesPrice'],
  4173. 'bindStatus' => 1,
  4174. 'bindDate' => date("Y-m-d H:i:s")
  4175. );
  4176. $billPrice = $detailM['receivablesPrice'];
  4177. } else {
  4178. die('illegal request');
  4179. }
  4180. if ($detailM['iid'] == 0) {
  4181. $item += array(
  4182. 'iid' => $detail['iid']
  4183. );
  4184. } else {
  4185. $iidExtend = explode(',', $detailM['iidExtend']);
  4186. array_push($iidExtend, $detail['iid']);
  4187. $item += array(
  4188. 'iidExtend' => implode(',', $iidExtend)
  4189. );
  4190. }
  4191. $titleMark = $detail['invoiceTitle'];
  4192. if (!empty($detail['invoiceCompany']))
  4193. $titleMark = $detail['invoiceCompany'];
  4194. $item += array(
  4195. 'irid' => $detailM['irid'],
  4196. 'recepitTitleMark' => $titleMark,
  4197. 'accountClerk' => $this->staff[0]['username']
  4198. );
  4199. // 如何没有人收款 则自动绑定收款
  4200. if ($detailM['receivablesCategory'] == 'PUBLIC' || $detailM['receivablesStaff'] == 'PUBLIC') {
  4201. $item += array(
  4202. 'receivablesCategory' => $detail['cid'] . ':' . $detail['categoryName'],
  4203. 'receivablesStaff' => $detail['sid'] . '-' . $detail['userName']
  4204. );
  4205. }
  4206. $invoiceReceivables->setInvoiceReceivablesByCondition($item);
  4207. $iridString = "";
  4208. if (empty($detail['irid']))
  4209. $iridString = $detailM['irid'];
  4210. else
  4211. $iridString = $detail['irid'] . ',' . $detailM['irid'];
  4212. // $invoiceReceivables = new invoiceReceivables ();
  4213. // $sumBind = $invoiceReceivables->getSumOfReceivablesPrice ( $detail ['irid'] );
  4214. // //这个收款余额
  4215. // $sumBalance=$invoiceReceivables->balanceOfReceivablesPrice($detailM ['irid']);
  4216. // $sum=$sumBind+$sumBalance;
  4217. //这个收款余额
  4218. $sumBalance = $detailM['receivablesPrice'] - $detailM['bindPrice'];
  4219. // echo $detailM ['irid'].'/'.$sumBalance.'/'.$detail ['invoicePrice'];
  4220. // die;
  4221. $invoice = new invoice();
  4222. $item = array(
  4223. 'iid' => $detail['iid'],
  4224. 'irid' => $iridString
  4225. );
  4226. if ($detail['invoicePrice'] <= $sumBalance) {
  4227. $item += array(
  4228. 'invoiceBalance' => 0,
  4229. 'untreadStatus' => 3,
  4230. 'bindTime' => date("Y-m-d H:i:s")
  4231. );
  4232. } else {
  4233. $item += array(
  4234. 'invoiceBalance' => $detail['invoicePrice'] - $sumBalance,
  4235. );
  4236. }
  4237. // print_r($item);
  4238. // echo $sum;die;
  4239. $invoice->setInvoiceByCondition($item);
  4240. //发票入账记录
  4241. Doo::loadModel('bill');
  4242. $bill = new bill();
  4243. $bill->iid = $detail['iid'];
  4244. $bill->trainId = $detail['trainId'];
  4245. $bill->irid = $detailM['irid'];
  4246. $bill->create_time = date("Y-m-d H:i:s");
  4247. $bill->price = $billPrice;
  4248. $bill->insert();
  4249. // 操作日志
  4250. $item = array(
  4251. 'date' => date("Y-m-d H:i:s"),
  4252. 'operation' => "收款" . $detailM['receivablesSerial'] . "入账到发票" . $detail['invoiceSerial'],
  4253. 'status' => 8,
  4254. 'img' => $this->staff[0]['avatar'],
  4255. 'username' => $this->staff[0]['username'],
  4256. 'uid' => $this->staff[0]['sid'],
  4257. 'category' => $this->staff[0]['category'],
  4258. 'iid' => $detail['iid']
  4259. );
  4260. $invoiceOperationLog->setInvoiceOperationLog($item);
  4261. Doo::loadModel('invoiceStatistics');
  4262. $invoiceStatistics = new invoiceStatistics();
  4263. $item = array(
  4264. 'date' => $detailM['receivablesDate'],
  4265. 'priceClass' => 3,
  4266. 'cid' => $detail['cid'],
  4267. 'staff' => $detail['sid'],
  4268. 'accountPrice' => $detailM['receivablesPrice']
  4269. );
  4270. $invoiceStatistics->setInvoiceStatisticsByCondition($item);
  4271. //TODO
  4272. // 公司流水记录
  4273. // Doo::loadModel ( 'wasteBook' );
  4274. // $wasteBook = new wasteBook ();
  4275. // $abDetail = $wasteBook->getAccountBookByAid (1,8,$detail ['iid'] );
  4276. // $accountBank='';
  4277. // if ($detailM ['receivablesBank']=='纵横广发'){
  4278. // $accountBank='CGBDeposit';
  4279. // }elseif($detailM ['receivablesBank']=='纵横工行'){
  4280. // $accountBank='ICBCDeposit';
  4281. // }elseif($detailM ['receivablesBank']=='华润银行'){
  4282. // $accountBank='HUADeposit';
  4283. // }elseif($detailM ['receivablesBank']=='个人广发'){
  4284. // $accountBank='PersonalDeposit';
  4285. // }
  4286. // if (empty($abDetail)){
  4287. // $item = array (
  4288. // 'dataID' => $detail ['iid'],
  4289. // 'expensesType' => 1,
  4290. // 'accountType' => 8,
  4291. // 'accountPriceShow'=>$detail ['invoicePrice'],
  4292. // 'accountPrice'=>$detail ['invoicePrice'],
  4293. // 'accountBank'=>$accountBank,
  4294. // 'category'=>$this->staff[0]['category'],
  4295. // 'cid'=>$this->staff[0]['cid'],
  4296. // 'name'=>$this->staff[0]['username'],
  4297. // 'sid'=>$this->staff[0]['sid'],
  4298. // 'inputDate'=>date ( "Y-m-d H:i:s" )
  4299. // );
  4300. // $wasteBook->setAccountBookStatistics($item);
  4301. // }
  4302. return "/invoiceReceivables";
  4303. }
  4304. /**
  4305. * 核销 动作,确认入账统计 发票收款完成--需求更变 废弃 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"; }
  4306. */
  4307. function invoiceAggregate()
  4308. {
  4309. $year = $this->get_args('year') ? $this->get_args('year') : date("Y");
  4310. Doo::loadModel('invoiceStatistics');
  4311. $invoiceStatistics = new invoiceStatistics();
  4312. Doo::loadModel('L_category');
  4313. $Lcategory = new L_category();
  4314. $isList = $invoiceStatistics->getInvoiceStatisticsByYear($year);
  4315. $LcategoryList = $Lcategory->getCategory();
  4316. // print_r($isList);
  4317. $html = ""; // $invoicePriceCategory=0;$receivablesPriceCategory=0;$accountPriceCategory=0;
  4318. foreach ($LcategoryList as $key => $value) {
  4319. $html .= '<tr><th><a href="/invoiceAggregateCategory/' . $value['cidKey'] . '">' . $value['title'] . '</a></th>';
  4320. $month = 1;
  4321. $invoicePriceYear = 0;
  4322. $receivablesPriceYear = 0;
  4323. $accountPriceYear = 0;
  4324. for (; $month <= 12; $month++) {
  4325. $flag = true;
  4326. foreach ($isList['statisticsMonthCid'] as $k => $v) {
  4327. if ($value['cid'] == $v['cid'] && $month == $v['month']) {
  4328. $html .= '<td class="taR">¥' . $v['invoicePrice'] . '</td>
  4329. <td class="taR">¥' . $v['receivablesPrice'] . '</td>
  4330. <td class="taR"><b>¥' . $v['accountPrice'] . '</b></td>
  4331. ';
  4332. $invoicePriceYear += $v['invoicePrice'];
  4333. $receivablesPriceYear += $v['receivablesPrice'];
  4334. $accountPriceYear += $v['accountPrice'];
  4335. $flag = false;
  4336. break;
  4337. }
  4338. }
  4339. if ($flag)
  4340. $html .= '<td class="taR"></td>
  4341. <td class="taR"></td>
  4342. <td class="taR"><b></b></td>
  4343. ';
  4344. }
  4345. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  4346. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  4347. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  4348. ';
  4349. $html .= '</tr>';
  4350. }
  4351. $html .= '<tr><th><b class="colGreen">月合计</b></th>';
  4352. $invoicePriceYear = 0;
  4353. $receivablesPriceYear = 0;
  4354. $accountPriceYear = 0;
  4355. for ($month = 1; $month <= 12; $month++) {
  4356. $flag = true;
  4357. foreach ($isList['statisticsMonth'] as $k => $v) {
  4358. if ($month == $v['month']) {
  4359. $html .= '<td class="taR">¥' . $v['invoicePrice'] . '</td>
  4360. <td class="taR">¥' . $v['receivablesPrice'] . '</td>
  4361. <td class="taR"><b>¥' . $v['accountPrice'] . '</b></td>
  4362. ';
  4363. $invoicePriceYear += $v['invoicePrice'];
  4364. $receivablesPriceYear += $v['receivablesPrice'];
  4365. $accountPriceYear += $v['accountPrice'];
  4366. $flag = false;
  4367. break;
  4368. }
  4369. }
  4370. if ($flag) {
  4371. $html .= '<td class="taR"></td>
  4372. <td class="taR"></td>
  4373. <td class="taR"><b></b></td>
  4374. ';
  4375. }
  4376. }
  4377. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  4378. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  4379. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  4380. ';
  4381. $html .= '</tr>';
  4382. // print_r($isList);
  4383. $this->data['html'] = $html;
  4384. $this->data['LcategoryList'] = $LcategoryList;
  4385. $this->data['isList'] = $isList;
  4386. $this->data['year'] = $year;
  4387. $this->data['memu'] = "invoice";
  4388. $this->data['staff'] = $this->staff;
  4389. $this->data['receiptMemu'] = 'invoiceAggregate';
  4390. $this->render("/admin/invoiceAggregate", $this->data);
  4391. }
  4392. function invoiceAggregateStaff()
  4393. {
  4394. $year = $this->get_args('year') ? $this->get_args('year') : date("Y");
  4395. Doo::loadModel('invoiceStatistics');
  4396. $invoiceStatistics = new invoiceStatistics();
  4397. Doo::loadModel('L_category');
  4398. $Lcategory = new L_category();
  4399. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote($year);
  4400. $staffList = $invoiceStatistics->getInvoiceStatisticsByStaff($year);
  4401. $cStaff = $Lcategory->getCategoryStaff();
  4402. $html = '';
  4403. foreach ($cStaff as $key => $value) {
  4404. $categoryFir = true;
  4405. foreach ($value['staff'] as $k => $v) {
  4406. if ($categoryFir) {
  4407. $width = count($value['staff']) + 1;
  4408. $html .= '<tr><th rowspan="' . $width . '">' . $value['title'] . ' </th>';
  4409. $categoryFir = false;
  4410. } else
  4411. $html .= '<tr>';
  4412. $html .= '<th>' . $v['username'] . '</th>';
  4413. $invoicePriceStaffYear = 0;
  4414. $receivablesPriceStaffYear = 0;
  4415. $accountPriceStaffYear = 0;
  4416. for ($month = 1; $month <= 12; $month++) {
  4417. $flag = true;
  4418. foreach ($staffList['statisticsMonthStaff'] as $sl => $slv) {
  4419. if ($v['sid'] == $slv['staff'] && $month == $slv['month']) {
  4420. $html .= '<td class="taR">¥' . $slv['invoicePrice'] . '</td>
  4421. <td class="taR">¥' . $slv['receivablesPrice'] . '</td>
  4422. <td class="taR"><b>¥' . $slv['accountPrice'] . '</b></td>
  4423. ';
  4424. $invoicePriceStaffYear += $slv['invoicePrice'];
  4425. $receivablesPriceStaffYear += $slv['receivablesPrice'];
  4426. $accountPriceStaffYear += $slv['accountPrice'];
  4427. $flag = false;
  4428. break;
  4429. }
  4430. }
  4431. if ($flag)
  4432. $html .= '<td class="taR"></td>
  4433. <td class="taR"></td>
  4434. <td class="taR"><b></b></td>
  4435. ';
  4436. }
  4437. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  4438. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  4439. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  4440. ';
  4441. }
  4442. $html .= '</tr>';
  4443. // 小计
  4444. if (!empty($value['staff'])) {
  4445. $html .= '<tr><th class="taR">小计</th>';
  4446. $invoicePriceStaffYear = 0;
  4447. $receivablesPriceStaffYear = 0;
  4448. $accountPriceStaffYear = 0;
  4449. for ($month = 1; $month <= 12; $month++) {
  4450. $flag = true;
  4451. foreach ($staffList['statisticsMonthCid'] as $smc => $smcv) {
  4452. if ($value['cid'] == $smcv['cid'] && $month == $slv['month']) {
  4453. $html .= '<td class="taR">¥' . $smcv['invoicePrice'] . '</td>
  4454. <td class="taR">¥' . $smcv['receivablesPrice'] . '</td>
  4455. <td class="taR"><b>¥' . $smcv['accountPrice'] . '</b></td>
  4456. ';
  4457. $invoicePriceStaffYear += $slv['invoicePrice'];
  4458. $receivablesPriceStaffYear += $slv['receivablesPrice'];
  4459. $accountPriceStaffYear += $slv['accountPrice'];
  4460. $flag = false;
  4461. break;
  4462. }
  4463. }
  4464. if ($flag)
  4465. $html .= '<td class="taR"></td>
  4466. <td class="taR"></td>
  4467. <td class="taR"><b></b></td>
  4468. ';
  4469. }
  4470. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  4471. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  4472. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  4473. ';
  4474. $html .= '</tr>';
  4475. }
  4476. }
  4477. $html .= '<tr class="warning"><th colspan="2"><b class="colGreen" >月合计</b></th>';
  4478. $invoicePriceYear = 0;
  4479. $receivablesPriceYear = 0;
  4480. $accountPriceYear = 0;
  4481. for ($month = 1; $month <= 12; $month++) {
  4482. $flag = true;
  4483. foreach ($staffList['statisticsMonth'] as $k => $v) {
  4484. if ($month == $v['month']) {
  4485. $html .= '<td class="taR colRed">¥' . $v['invoicePrice'] . '</td>
  4486. <td class="taR colOrange">¥' . $v['receivablesPrice'] . '</td>
  4487. <td class="taR colGreen"><b>¥' . $v['accountPrice'] . '</b></td>
  4488. ';
  4489. $invoicePriceYear += $v['invoicePrice'];
  4490. $receivablesPriceYear += $v['receivablesPrice'];
  4491. $accountPriceYear += $v['accountPrice'];
  4492. $flag = false;
  4493. break;
  4494. }
  4495. }
  4496. if ($flag)
  4497. $html .= '<td class="taR"></td>
  4498. <td class="taR"></td>
  4499. <td class="taR"><b></b></td>
  4500. ';
  4501. }
  4502. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  4503. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  4504. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  4505. ';
  4506. $html .= '</tr>';
  4507. $this->data['html'] = $html;
  4508. $this->data['isList'] = $toteList;
  4509. $this->data['year'] = $year;
  4510. $this->data['memu'] = "invoice";
  4511. $this->data['staff'] = $this->staff;
  4512. $this->data['receiptMemu'] = 'invoiceAggregate';
  4513. $this->render("/admin/invoiceAggregateStaff", $this->data);
  4514. }
  4515. function invoiceAggregateCategory()
  4516. {
  4517. Doo::loadClass('XDeode');
  4518. $XDeode = new XDeode(5);
  4519. $cid = $cidKey = isset($this->params['cid']) ? $this->params['cid'] : "";
  4520. $cid = $XDeode->decode($cid);
  4521. if (!is_numeric($cid))
  4522. die('illegal request');
  4523. $year = $this->get_args('year') ? $this->get_args('year') : date("Y");
  4524. Doo::loadModel('invoiceStatistics');
  4525. $invoiceStatistics = new invoiceStatistics();
  4526. Doo::loadModel('staff');
  4527. $staff = new staff();
  4528. $list = $staff->getStaffByCid($cid);
  4529. $isCategory = $invoiceStatistics->getInvoiceStatisticsByStaff($year, $cid);
  4530. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote($year, $cid);
  4531. if (empty($list))
  4532. die('该办事处没有成员');
  4533. $htmlA = $htmlB = $htmlC = $html = '';
  4534. foreach ($list as $key => $value) {
  4535. $htmlA = '<tr><th rowspan="3">' . $value['username'] . '</th><th class="taC">开票</th>';
  4536. $htmlB = '<tr><th class="taC">收款</th>';
  4537. $htmlC = '<tr><th class="taC">入账</th>';
  4538. $invoicePriceStaffYear = 0;
  4539. $receivablesPriceStaffYear = 0;
  4540. $accountPriceStaffYear = 0;
  4541. for ($month = 1; $month <= 12; $month++) {
  4542. $flag = true;
  4543. foreach ($isCategory['statisticsMonthStaff'] as $k => $v) {
  4544. if ($value['sid'] == $v['staff'] && $month == $v['month']) {
  4545. $htmlA .= '<td class="taR">¥' . $v['invoicePrice'] . '</td>';
  4546. $htmlB .= '<td class="taR">¥' . $v['receivablesPrice'] . '</td>';
  4547. $htmlC .= '<td class="taR"><b>¥' . $v['accountPrice'] . '</b></td>';
  4548. $invoicePriceStaffYear += $v['invoicePrice'];
  4549. $receivablesPriceStaffYear += $v['receivablesPrice'];
  4550. $accountPriceStaffYear += $v['accountPrice'];
  4551. $flag = false;
  4552. break;
  4553. }
  4554. }
  4555. if ($flag) {
  4556. $htmlA .= '<td class="taR">-</td>';
  4557. $htmlB .= '<td class="taR">-</td>';
  4558. $htmlC .= '<td class="taR"><b>-</b></td>';
  4559. }
  4560. }
  4561. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  4562. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  4563. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  4564. $htmlA .= '</tr>';
  4565. $htmlB .= '</tr>';
  4566. $htmlC .= '</tr>';
  4567. $html .= $htmlA . $htmlB . $htmlC;
  4568. }
  4569. $htmlA = $htmlB = $htmlC = "";
  4570. $htmlA = '<tr><th rowspan="3">月合计</th><th class="taC">开票</th>';
  4571. $htmlB = '<tr><th class="taC">收款</th>';
  4572. $htmlC = '<tr><th class="taC">入账</th>';
  4573. $invoicePriceStaffYear = 0;
  4574. $receivablesPriceStaffYear = 0;
  4575. $accountPriceStaffYear = 0;
  4576. for ($month = 1; $month <= 12; $month++) {
  4577. $flag = true;
  4578. foreach ($isCategory['statisticsMonth'] as $k => $v) {
  4579. if ($month == $v['month']) {
  4580. $htmlA .= '<td class="taR colRed">¥' . $v['invoicePrice'] . '</td>';
  4581. $htmlB .= '<td class="taR colOrange">¥' . $v['receivablesPrice'] . '</td>';
  4582. $htmlC .= '<td class="taR colGreen"><b>¥' . $v['accountPrice'] . '</b></td>';
  4583. $invoicePriceStaffYear += $v['invoicePrice'];
  4584. $receivablesPriceStaffYear += $v['receivablesPrice'];
  4585. $accountPriceStaffYear += $v['accountPrice'];
  4586. $flag = false;
  4587. break;
  4588. }
  4589. }
  4590. if ($flag) {
  4591. $htmlA .= '<td class="taR">-</td>';
  4592. $htmlB .= '<td class="taR">-</td>';
  4593. $htmlC .= '<td class="taR"><b>-</b></td>';
  4594. }
  4595. }
  4596. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  4597. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  4598. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  4599. $htmlA .= '</tr>';
  4600. $htmlB .= '</tr>';
  4601. $htmlC .= '</tr>';
  4602. $html .= $htmlA . $htmlB . $htmlC;
  4603. $this->data['html'] = $html;
  4604. $this->data['cidKey'] = $cidKey;
  4605. $this->data['slist'] = $list;
  4606. $this->data['isList'] = $toteList;
  4607. $this->data['year'] = $year;
  4608. $this->data['memu'] = "invoice";
  4609. $this->data['staff'] = $this->staff;
  4610. $this->data['receiptMemu'] = 'invoiceAggregate';
  4611. $this->render("/admin/invoiceAggregateCategory", $this->data);
  4612. }
  4613. /**
  4614. * 办事处汇总信息
  4615. */
  4616. function invoiceAggregateCategoryDetail()
  4617. {
  4618. $cidKey = $this->get_args('cidKey') ? $this->get_args('cidKey') : '';
  4619. Doo::loadClass('XDeode');
  4620. $XDeode = new XDeode(5);
  4621. Doo::loadModel('invoiceStatistics');
  4622. $invoiceStatistics = new invoiceStatistics();
  4623. Doo::loadModel('L_category');
  4624. $category = new L_category();
  4625. Doo::loadModel('invoice');
  4626. $invoice = new invoice();
  4627. Doo::loadModel('staff');
  4628. $staff = new staff();
  4629. Doo::loadModel("invoiceCategoryManage");
  4630. $invoiceCategoryManage = new invoiceCategoryManage();
  4631. Doo::loadModel('invoiceReceivables');
  4632. $invoiceReceivables = new invoiceReceivables();
  4633. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff($this->staff[0]['sid']);
  4634. $cidList = array();
  4635. foreach ($imcStaff as $key => $value) {
  4636. array_push($cidList, $value['cid']);
  4637. if (empty($cidKey))
  4638. $cidKey = $XDeode->encode($value['cid']);
  4639. }
  4640. $categoryList = $category->getCategoryInCid(implode(',', $cidList));
  4641. $cid = $XDeode->decode($cidKey);
  4642. $month = date("m", strtotime("-1 month"));
  4643. $YearMonth = date("Y-m", strtotime("-1 month"));
  4644. $redis = new Redis();
  4645. $redis->connect('127.0.0.1', '6379');
  4646. $redisKey = ''; // date('Y-m-d').'_iacd_'.$cid;
  4647. $redisValue = ''; // $redis->lrange($redisKey, 0, -1);
  4648. if (empty($redisValue)) {
  4649. $isMC = $invoiceStatistics->getInvoiceStatistiscsMothByCategory($cid);
  4650. // $schedule = $invoice->getInvoiceScheduleByCid ( $cid );
  4651. // 1.获得获得办事处人员下的汇总
  4652. $slist = $staff->getStaffByCid($cid);
  4653. // 1-1上个月
  4654. $lastBeginTime = date("Y-m-d H:i:s", mktime(0, 0, 0, date("m") - 1, 1, date("Y")));
  4655. $lastEndTime = date("Y-m-d H:i:s", mktime(23, 59, 59, date("m"), date("d") - date("d"), date("Y")));
  4656. // 发票
  4657. $invoiceLastMonth = $invoice->getPrintTime($cid, $lastBeginTime, $lastEndTime);
  4658. // 收款
  4659. $invoiceReceivablesLastMonth = $invoiceReceivables->getConfirmTime($cid, $lastBeginTime, $lastEndTime);
  4660. // 入账
  4661. $creditLastMonth = $invoiceReceivables->getConfirmTimeCredit($cid, $lastBeginTime, $lastEndTime);
  4662. // $ismsbMonth = $invoiceStatistics->getISMSByCategoryByMonth ( $cid, $YearMonth );
  4663. // 2 当月汇总
  4664. $beginTime = date("Y-m-d H:i:s", mktime(0, 0, 0, date("m"), 1, date("Y")));
  4665. $endTime = date("Y-m-d H:i:s", mktime(23, 59, 59, date("m"), date("t"), date("Y")));
  4666. // 发票
  4667. $invoiceMonth = $invoice->getPrintTime($cid, $beginTime, $endTime);
  4668. // 收款
  4669. $invoiceReceivablesMonth = $invoiceReceivables->getConfirmTime($cid, $beginTime, $endTime);
  4670. // 入账
  4671. $creditMonth = $invoiceReceivables->getConfirmTimeCredit($cid, $beginTime, $endTime);
  4672. // $ismsb = $invoiceStatistics->getISMSByCategory ( $cid );
  4673. // 1-3全年汇总
  4674. $beginTime = date("Y-m-d H:i:s", mktime(0, 0, 0, 1, 1, date("Y")));
  4675. $endTime = date("Y-m-d H:i:s", mktime(23, 59, 59, 12, date("t"), date("Y")));
  4676. // 发票
  4677. $invoiceYear = $invoice->getPrintTime($cid, $beginTime, $endTime);
  4678. // 收款
  4679. $invoiceReceivablesYear = $invoiceReceivables->getConfirmTime($cid, $beginTime, $endTime);
  4680. // 入账
  4681. $creditYear = $invoiceReceivables->getConfirmTimeCredit($cid, $beginTime, $endTime);
  4682. // $ISAS = $invoiceStatistics->getISASByCategory ( $cid );
  4683. // 1-4完成度
  4684. // $scheduleStaff = $invoice->getInvoiceScheduleByCidGroupSid ( $cid );
  4685. //办事处每个人合计
  4686. foreach ($slist as $key => $value) {
  4687. $slist[$key]['invoicePrice'] = 0;
  4688. $slist[$key]['receivablesPrice'] = 0;
  4689. $slist[$key]['accountPrice'] = 0;
  4690. $slist[$key]['invoiceAllPrice'] = 0;
  4691. $slist[$key]['receivablesAllPrice'] = 0;
  4692. $slist[$key]['accountAllPrice'] = 0;
  4693. $slist[$key]['schedule'] = 0;
  4694. $slist[$key]['invoiceMonthPrice'] = 0;
  4695. $slist[$key]['receivablesMonthPrice'] = 0;
  4696. $slist[$key]['accountMonthPrice'] = 0;
  4697. // 3-1组合上一个月的发票金额
  4698. foreach ($invoiceLastMonth as $v) {
  4699. if ($value['sid'] == $v['sid']) {
  4700. $slist[$key]['invoiceMonthPrice'] = $v['invoicePrice'];
  4701. }
  4702. }
  4703. foreach ($invoiceReceivablesLastMonth as $v) {
  4704. $staffInfo = explode('-', $v['receivablesStaff']);
  4705. if ($value['sid'] == $staffInfo[0]) {
  4706. $slist[$key]['receivablesMonthPrice'] = $v['receivablesPrice'];
  4707. }
  4708. }
  4709. foreach ($creditLastMonth as $v) {
  4710. $staffInfo = explode('-', $v['receivablesStaff']);
  4711. if ($value['sid'] == $staffInfo[0]) {
  4712. $slist[$key]['accountMonthPrice'] = $v['receivablesPrice'];
  4713. }
  4714. }
  4715. //3-2 组合本月金额
  4716. foreach ($invoiceMonth as $v) {
  4717. if ($value['sid'] == $v['sid']) {
  4718. $slist[$key]['invoicePrice'] = $v['invoicePrice'];
  4719. }
  4720. }
  4721. foreach ($invoiceReceivablesMonth as $v) {
  4722. $staffInfo = explode('-', $v['receivablesStaff']);
  4723. if ($value['sid'] == $staffInfo[0]) {
  4724. $slist[$key]['receivablesPrice'] = $v['receivablesPrice'];
  4725. }
  4726. }
  4727. foreach ($creditMonth as $v) {
  4728. $staffInfo = explode('-', $v['receivablesStaff']);
  4729. if ($value['sid'] == $staffInfo[0]) {
  4730. $slist[$key]['accountPrice'] = $v['receivablesPrice'];
  4731. }
  4732. }
  4733. // 3-3 全年
  4734. foreach ($invoiceYear as $v) {
  4735. if ($value['sid'] == $v['sid']) {
  4736. $slist[$key]['invoiceAllPrice'] = $v['invoicePrice'];
  4737. }
  4738. }
  4739. foreach ($invoiceReceivablesYear as $v) {
  4740. $staffInfo = explode('-', $v['receivablesStaff']);
  4741. if ($value['sid'] == $staffInfo[0]) {
  4742. $slist[$key]['receivablesAllPrice'] = $v['receivablesPrice'];
  4743. }
  4744. }
  4745. foreach ($creditYear as $v) {
  4746. $staffInfo = explode('-', $v['receivablesStaff']);
  4747. if ($value['sid'] == $staffInfo[0]) {
  4748. $slist[$key]['accountAllPrice'] = $v['receivablesPrice'];
  4749. }
  4750. }
  4751. // foreach ( $ismsbMonth as $y => $l ) {
  4752. // if ($value ['sid'] == $l ['staff']) {
  4753. // // $slist [$key] ['invoiceMonthPrice'] = $l ['invoicePrice'];
  4754. // // $slist [$key] ['receivablesMonthPrice'] = $l ['receivablesPrice'];
  4755. // // $slist [$key] ['accountMonthPrice'] = $l ['accountPrice'];
  4756. // }
  4757. // }
  4758. // foreach ( $ismsb as $k => $v ) {
  4759. // if ($value ['sid'] == $v ['staff']) {
  4760. // $slist [$key] ['invoicePrice'] = $v ['invoicePrice'];
  4761. // $slist [$key] ['receivablesPrice'] = $v ['receivablesPrice'];
  4762. // $slist [$key] ['accountPrice'] = $v ['accountPrice'];
  4763. // }
  4764. // }
  4765. // foreach ( $ISAS as $e => $a ) {
  4766. // if ($value ['sid'] == $a ['staff']) {
  4767. // $slist [$key] ['invoiceAllPrice'] = $a ['invoicePrice'];
  4768. // $slist [$key] ['receivablesAllPrice'] = $a ['receivablesPrice'];
  4769. // $slist [$key] ['accountAllPrice'] = $a ['accountPrice'];
  4770. // }
  4771. // }
  4772. // if (isset ( $scheduleStaff [$value ['sid']] )){
  4773. // $slist [$key] ['schedule'] = $scheduleStaff [$value ['sid']];
  4774. // }
  4775. }
  4776. $this->data['cidKey'] = $cidKey;
  4777. // $schedule = ( int ) ($schedule * 100);
  4778. $this->data['slist'] = $slist;
  4779. $this->data['isMC'] = $isMC;
  4780. // $this->data ['schedule'] = $schedule;
  4781. $slist = json_encode($slist);
  4782. $isMC = json_encode($isMC);
  4783. // $schedule = json_encode ( $schedule );
  4784. // $redis->lpush ( $redisKey, $slist );
  4785. // $redis->lpush ( $redisKey, $isMC );
  4786. // $redis->lpush ( $redisKey, $schedule );
  4787. } else {
  4788. $this->data['cidKey'] = $cidKey;
  4789. $this->data['slist'] = json_decode($redisValue[2], true);
  4790. $this->data['isMC'] = json_decode($redisValue[1], true);
  4791. $this->data['schedule'] = json_decode($redisValue[0], true);
  4792. }
  4793. $this->data['month'] = $month;
  4794. $this->data['categoryList'] = $categoryList;
  4795. $this->data['memu'] = "invoice";
  4796. $this->data['staff'] = $this->staff;
  4797. $this->data['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4798. $this->render("/admin/invoiceAggregateCategoryDetail", $this->data);
  4799. }
  4800. /**
  4801. * 办事处人员汇总详情
  4802. */
  4803. function invoiceAggregateStaffDetail()
  4804. {
  4805. $sidKey = $this->get_args('sidKey') ? $this->get_args('sidKey') : '';
  4806. // $sidKey = isset ( $this->params ['sidKey'] ) ? $this->params ['sidKey'] : '';
  4807. Doo::loadClass('XDeode');
  4808. $XDeode = new XDeode(5);
  4809. Doo::loadModel('invoice');
  4810. $invoice = new invoice();
  4811. Doo::loadModel('staff');
  4812. $staff = new staff();
  4813. Doo::loadModel("invoiceCategoryManage");
  4814. $invoiceCategoryManage = new invoiceCategoryManage();
  4815. $sid = $XDeode->decode($sidKey);
  4816. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff($this->staff[0]['sid']);
  4817. $cidList = array();
  4818. foreach ($imcStaff as $key => $value) {
  4819. array_push($cidList, $value['cid']);
  4820. if (empty($cidKey))
  4821. $cidKey = $XDeode->encode($value['cid']);
  4822. }
  4823. $cidString = implode(',', $cidList);
  4824. $staffList = $staff->getStaffInCid($cidString);
  4825. $staffDetail = $staff->getStaffBySid($sid);
  4826. $MebSea = $this->get_args('MebSea') ? $this->get_args('MebSea') : "";
  4827. $page_size = 18;
  4828. $page = isset($this->params['page']) && is_numeric($this->params['page']) ? $this->params['page'] : 1;
  4829. $status = isset($this->params['status']) ? $this->params['status'] : 'All';
  4830. $BeginDate = date('Y-m-01', strtotime(date("Y-m-d")));
  4831. $endDate = date('Y-m-d', strtotime("$BeginDate +1 month -1 day"));
  4832. $date = $this->get_args('date') ? $this->get_args('date') : $BeginDate . " : " . $endDate;
  4833. $dateArr = explode(':', $date);
  4834. $D1 = '';
  4835. $D2 = '';
  4836. if (!empty($date)) {
  4837. $D1 = $dateArr[0] . " 00:00:00 ";
  4838. if (isset($dateArr[1]))
  4839. $D2 = $dateArr[1] . " 23:59:59 ";
  4840. else
  4841. $D2 = $dateArr[0] . " 23:59:59 "; // date ( "Y-m-d" );
  4842. // $D2 = $dateArr [1];
  4843. }
  4844. $con = ' status=2 ';
  4845. if (!empty($D1) && !empty($D2))
  4846. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4847. if ($status == 'UNRECORD')
  4848. $con .= ' and printStatus=1 and untreadStatus=0';
  4849. elseif ($status == 'RECORD')
  4850. $con .= ' and printStatus=1 and untreadStatus=3';
  4851. elseif ($status == 'BOUNCED')
  4852. $con .= ' and untreadStatus=2';
  4853. elseif ($status == 'PARTRECORD')
  4854. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  4855. elseif ($status == 'All') {
  4856. $con .= ' and ( untreadStatus=2 or untreadStatus=0 or untreadStatus=3 )';
  4857. }
  4858. $con .= ' and sid=' . $sid;
  4859. $get = "/" . $status . "?date=" . urlencode($date) . "&MebSea=" . urlencode($MebSea) . "&sidKey=" . urlencode($sidKey);
  4860. if (!empty($MebSea)) {
  4861. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  4862. }
  4863. $pageinfo['page'] = array(
  4864. 'previous' => ''
  4865. );
  4866. $pageinfo = $this->get_page("CLD_invoice", $con, $page, $page_size, "invoiceAggregateStaffDetail", $get, "");
  4867. $limit = $pageinfo['lower'] . ',' . $page_size;
  4868. $list = $invoice->getInvoiceByUntreadStatusPage($limit, $con);
  4869. $this->data['staffDetail'] = $staffDetail;
  4870. $this->data['staffList'] = $staffList;
  4871. $this->data['MebSeaEn'] = $MebSea;
  4872. $this->data['MebSea'] = urlencode($MebSea);
  4873. $this->data['date'] = $date;
  4874. $this->data['page'] = $pageinfo;
  4875. $this->data['get'] = $get;
  4876. $this->data['list'] = $list;
  4877. $this->data['status'] = $status;
  4878. $this->data['sidKey'] = $sidKey;
  4879. $this->data['memu'] = "invoice";
  4880. $this->data['staff'] = $this->staff;
  4881. $this->data['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4882. $this->render("/admin/invoiceAggregateStaffDetail", $this->data);
  4883. }
  4884. /**
  4885. * 办事处人员汇总收款情
  4886. */
  4887. function invoiceAggregateStaffReceivablesDetail()
  4888. {
  4889. $sidKey = $this->get_args('sidKey') ? $this->get_args('sidKey') : '';
  4890. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  4891. Doo::loadModel('invoiceReceivables');
  4892. $invoiceReceivables = new invoiceReceivables();
  4893. Doo::loadModel('staff');
  4894. $staff = new staff();
  4895. Doo::loadModel("invoiceCategoryManage");
  4896. $invoiceCategoryManage = new invoiceCategoryManage();
  4897. Doo::loadClass('XDeode');
  4898. $XDeode = new XDeode(5);
  4899. $sid = $XDeode->decode($sidKey);
  4900. $staffDetail = $staff->getStaffBySid($sid);
  4901. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff($this->staff[0]['sid']);
  4902. $cidList = array();
  4903. foreach ($imcStaff as $key => $value) {
  4904. array_push($cidList, $value['cid']);
  4905. if (empty($cidKey))
  4906. $cidKey = $XDeode->encode($value['cid']);
  4907. }
  4908. $cidString = implode(',', $cidList);
  4909. $staffList = $staff->getStaffInCid($cidString);
  4910. $MebSea = $this->get_args('MebSea') ? $this->get_args('MebSea') : "";
  4911. $timeType = $this->get_args('timeType') ? $this->get_args('timeType') : "CREATE";
  4912. $page_size = 10;
  4913. $page = isset($this->params['page']) && is_numeric($this->params['page']) ? $this->params['page'] : 1;
  4914. $status = isset($this->params['status']) ? $this->params['status'] : 'All';
  4915. if ($timeType == "BINDOTP") {
  4916. $status = 'Credited';
  4917. }
  4918. $BeginDate = date('Y-m-01', strtotime(date("Y-m-d")));
  4919. $endDate = date('Y-m-d', strtotime("$BeginDate +1 month -1 day"));
  4920. $date = $this->get_args('date') ? $this->get_args('date') : $BeginDate . " : " . $endDate;
  4921. $dateArr = explode(':', $date);
  4922. $D1 = '';
  4923. $D2 = '';
  4924. if (!empty($date)) {
  4925. $D1 = $dateArr[0] . " 00:00:00 ";
  4926. if (isset($dateArr[1]))
  4927. $D2 = $dateArr[1] . " 23:59:59 ";
  4928. else
  4929. $D2 = $dateArr[0] . " 23:59:59 "; // date ( "Y-m-d" );
  4930. }
  4931. $con = ' a.receivablesStaff like "%' . $staffDetail['username'] . '%" ';
  4932. $descField = 'a.bindDate';
  4933. if ($timeType == 'CREATE')
  4934. $descField = 'a.date';
  4935. if (!empty($D1) && !empty($D2))
  4936. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4937. elseif (!empty($D1) && empty($D2))
  4938. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  4939. if ($status == 'Unclaimed')
  4940. $con .= ' and a.bindStatus=0';
  4941. elseif ($status == 'Credited')
  4942. $con .= ' and a.bindStatus=1';
  4943. elseif ($status == 'Claim')
  4944. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  4945. elseif ($status == 'BBN')
  4946. $con .= ' and a.bindPrice>a.receivablesPrice';
  4947. $get = "/" . $status . "?date=" . urlencode($date) . "&MebSea=" . urlencode($MebSea) . "&sidKey=" . urlencode($sidKey);
  4948. if (!empty($MebSea)) {
  4949. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" )';
  4950. }
  4951. $pageinfo['page'] = array(
  4952. 'previous' => ''
  4953. );
  4954. // $sql = 'select group_concat(b.invoiceSerial) as invoiceSerial ,group_concat(b.iid) as invoiceId
  4955. // from CLD_invoiceReceivables as a left join CLD_invoice as b on
  4956. // find_in_set(b.iid,a.iidExtend) or a.iid=b.iid
  4957. // where ' . $con . ' group by a.irid ';
  4958. $pageinfo = $this->get_page("CLD_invoiceReceivables as a", $con, $page, $page_size, "invoiceAggregateStaffReceivablesDetail", $get, "");
  4959. //$pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceAggregateStaffReceivablesDetail", $get, "" );
  4960. $limit = $pageinfo['lower'] . ',' . $page_size;
  4961. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage($limit, $con, 'desc', $descField);
  4962. foreach ($list as $key => $value) {
  4963. $list[$key]['category'] = '';
  4964. if ($value['receivablesCategory'] != 'PUBLIC') {
  4965. $receivablesCategory = explode(":", $value['receivablesCategory']);
  4966. $list[$key]['category'] = $receivablesCategory[1];
  4967. }
  4968. }
  4969. // print_r($list);
  4970. $this->data['staffDetail'] = $staffDetail;
  4971. $this->data['sidKey'] = $sidKey;
  4972. $this->data['staffList'] = $staffList;
  4973. $this->data['timeType'] = $timeType;
  4974. $this->data['MebSeaEn'] = $MebSea;
  4975. $this->data['MebSea'] = urlencode($MebSea);
  4976. $this->data['date'] = $date;
  4977. $this->data['page'] = $pageinfo;
  4978. $this->data['get'] = $get;
  4979. $this->data['list'] = $list;
  4980. $this->data['status'] = $status;
  4981. $this->data['memu'] = "invoice";
  4982. $this->data['staff'] = $this->staff;
  4983. $this->data['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4984. $this->render("/admin/invoiceAggregateStaffReceivablesDetail", $this->data);
  4985. }
  4986. function invoiceAchieve()
  4987. {
  4988. Doo::loadModel('invoice');
  4989. $invoice = new invoice();
  4990. Doo::loadClass('XDeode');
  4991. $XDeode = new XDeode(5);
  4992. $sid = $XDeode->decode($_COOKIE["staff"]);
  4993. $MebSea = $this->get_args('MebSea') ? $this->get_args('MebSea') : "";
  4994. $page_size = 18;
  4995. $page = isset($this->params['page']) && is_numeric($this->params['page']) ? $this->params['page'] : 1;
  4996. $date = isset($this->params['date']) ? $this->params['date'] : 'MONTHO';
  4997. $get = "/" . $date;
  4998. $con = '';
  4999. if ($date == 'MONTHO')
  5000. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  5001. elseif ($date == 'MONTHT')
  5002. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  5003. elseif ($date == 'MONTHY')
  5004. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  5005. if (!empty($MebSea)) {
  5006. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  5007. $get .= "/" . $MebSea;
  5008. }
  5009. $pageinfo['page'] = array(
  5010. 'previous' => ''
  5011. );
  5012. $sql = 'status=2 and printStatus=1 and irid!="" and ( untreadStatus=3 or untreadStatus=0 ) and sid=' . $sid . $con;
  5013. $pageinfo = $this->get_page("CLD_invoice", $sql, $page, $page_size, "invoiceAchieve", $get, "");
  5014. $limit = $pageinfo['lower'] . ',' . $page_size;
  5015. $list = $invoice->getInvoiceByUntreadStatusPage($limit, $sql);
  5016. // print_r($pageinfo);
  5017. $this->data['MebSeaEn'] = $MebSea;
  5018. $this->data['MebSea'] = urlencode($MebSea);
  5019. $this->data['get'] = $get;
  5020. $this->data['page'] = $pageinfo;
  5021. $this->data['list'] = $list;
  5022. $this->data['date'] = $date;
  5023. $this->data['memu'] = "invoice";
  5024. $this->data['staff'] = $this->staff;
  5025. $this->data['receiptMemu'] = 'invoice';
  5026. $this->render("/admin/invoiceAchieve", $this->data);
  5027. }
  5028. /**
  5029. */
  5030. function invoiceMyUnAccountAchieve()
  5031. {
  5032. Doo::loadModel('invoice');
  5033. $invoice = new invoice();
  5034. Doo::loadClass('XDeode');
  5035. $XDeode = new XDeode(5);
  5036. $sid = $XDeode->decode($_COOKIE["staff"]);
  5037. $MebSea = $this->get_args('MebSea') ? $this->get_args('MebSea') : "";
  5038. $page_size = 18;
  5039. $page = isset($this->params['page']) && is_numeric($this->params['page']) ? $this->params['page'] : 1;
  5040. $date = $this->get_args('date') ? $this->get_args('date') : "";
  5041. $get = "?date=" . urlencode($date) . "&MebSea=" . urlencode($MebSea);
  5042. $dateArr = explode(':', $date);
  5043. $D1 = '';
  5044. $D2 = '';
  5045. if (!empty($date)) {
  5046. $D1 = $dateArr[0];
  5047. $D2 = $dateArr[1];
  5048. }
  5049. $con = '';
  5050. if (!empty($D1) && !empty($D2))
  5051. $con = ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  5052. if (!empty($MebSea)) {
  5053. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  5054. }
  5055. $pageinfo['page'] = array(
  5056. 'previous' => ''
  5057. );
  5058. // and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  5059. $sql = " status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid= " . $sid . $con;
  5060. $action = "invoiceMyUnAccountAchieve";
  5061. $pageinfo = $this->get_page("CLD_invoice", $sql, $page, $page_size, $action, $get, "");
  5062. $limit = $pageinfo['lower'] . ',' . $page_size;
  5063. $list = $invoice->getInvoiceByUntreadStatusPage($limit, $sql, 'desc', 'desc', 'printTime');
  5064. Doo::loadModel('express');
  5065. $express = new express();
  5066. $expressList = $express->getExpressByAll();
  5067. $this->data['expressList'] = $expressList;
  5068. // print_r($list);
  5069. $this->data['MebSeaEn'] = $MebSea;
  5070. $this->data['get'] = $get;
  5071. $this->data['page'] = $pageinfo;
  5072. $this->data['date'] = $date;
  5073. $this->data['list'] = $list;
  5074. $this->data['memu'] = "invoice";
  5075. $this->data['staff'] = $this->staff;
  5076. $this->data['receiptMemu'] = 'invoice';
  5077. $this->render("/admin/invoiceMyUnAccountAchieve", $this->data);
  5078. }
  5079. function invoiceReceivablesAchieve()
  5080. {
  5081. Doo::loadModel('invoiceReceivables');
  5082. $invoiceReceivables = new invoiceReceivables();
  5083. Doo::loadClass('XDeode');
  5084. $XDeode = new XDeode(5);
  5085. $sid = $XDeode->decode($_COOKIE["staff"]);
  5086. $MebSea = isset($this->params['MebSea']) ? urldecode($this->params['MebSea']) : '';
  5087. $page_size = 12;
  5088. $page = isset($this->params['page']) && is_numeric($this->params['page']) ? $this->params['page'] : 1;
  5089. $date = isset($this->params['date']) ? $this->params['date'] : 'MONTHO';
  5090. $get = "/" . $date;
  5091. $con = '';
  5092. if ($date == 'MONTHO')
  5093. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  5094. elseif ($date == 'MONTHT')
  5095. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  5096. elseif ($date == 'MONTHY')
  5097. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  5098. if (!empty($MebSea)) {
  5099. $con .= ' and ( receivablesMessage like "%' . $MebSea . '%" or receivablesPrice like "%' . $MebSea . '%" )';
  5100. $get .= "/" . $MebSea;
  5101. }
  5102. $pageinfo['page'] = array(
  5103. 'previous' => ''
  5104. );
  5105. $sql = " bindStatus=1 and receivablesStaff like '" . $sid . "-%' " . $con;
  5106. $pageinfo = $this->get_page("CLD_invoiceReceivables", $sql, $page, $page_size, "invoiceReceivablesAchieve", $get, "");
  5107. $limit = $pageinfo['lower'] . ',' . $page_size;
  5108. $list = $invoiceReceivables->getReceivablesByUntreadStatusPage($limit, $sql);
  5109. // print_r($pageinfo);
  5110. $this->data['MebSeaEn'] = $MebSea;
  5111. $this->data['MebSea'] = urlencode($MebSea);
  5112. $this->data['get'] = $get;
  5113. $this->data['page'] = $pageinfo;
  5114. $this->data['list'] = $list;
  5115. $this->data['date'] = $date;
  5116. $this->data['memu'] = "invoice";
  5117. $this->data['staff'] = $this->staff;
  5118. $this->data['receiptMemu'] = 'invoiceMyReceivables';
  5119. $this->render("/admin/invoiceReceivablesAchieve", $this->data);
  5120. }
  5121. /**
  5122. * 收款解绑
  5123. */
  5124. function invoiceUnBundLing()
  5125. {
  5126. $unBundKey = $this->get_args('unBundKey') ? $this->get_args('unBundKey') : '';
  5127. $iidKey = $this->get_args('iidKey') ? $this->get_args('iidKey') : '';
  5128. Doo::loadModel('invoice');
  5129. $invoice = new invoice();
  5130. Doo::loadModel('invoiceReceivables');
  5131. $invoiceReceivables = new invoiceReceivables();
  5132. Doo::loadModel('invoiceOperationLog');
  5133. $invoiceOperationLog = new invoiceOperationLog();
  5134. Doo::loadModel('invoiceROLog');
  5135. $invoiceROLog = new invoiceROLog();
  5136. Doo::loadModel('invoiceStatistics');
  5137. Doo::loadClass('XDeode');
  5138. $XDeode = new XDeode(5);
  5139. if (empty($iidKey) || empty($unBundKey))
  5140. die('illegal request');
  5141. $iid = $XDeode->decode($iidKey);
  5142. $irid = $invoice->authcode($unBundKey);
  5143. if ((!empty($irid) && !is_numeric($irid)) || (!empty($iid) && !is_numeric($iid)))
  5144. die('illegal request');
  5145. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid($irid);
  5146. $invoiceDetails = $invoice->getInvoiceByIid($iid);
  5147. if (empty($irDetails) || empty($invoiceDetails) || (empty($irDetails['iid']) && empty($irDetails['iidExtend'])) || $invoiceDetails['untreadStatus'] == 2)
  5148. die('illegal request');
  5149. // 收款
  5150. $item = array(
  5151. 'irid' => $irDetails['irid'],
  5152. 'bindPrice' => $irDetails['bindPrice'] - $invoiceDetails['invoicePrice'],
  5153. 'bindStatus' => 0
  5154. );
  5155. if ($irDetails['iid'] == $iid)
  5156. $item += array(
  5157. 'iid' => 0
  5158. );
  5159. else {
  5160. $iidExtend = explode(',', $irDetails['iidExtend']);
  5161. foreach ($iidExtend as $key => $value) {
  5162. if ($value == $iid)
  5163. unset($iidExtend[$key]);
  5164. }
  5165. $iidExtend = implode(',', $iidExtend);
  5166. $item += array(
  5167. 'iidExtend' => $iidExtend
  5168. );
  5169. }
  5170. $invoiceReceivables->setInvoiceReceivablesByCondition($item);
  5171. // 收款操作日志
  5172. $item = array(
  5173. 'operation' => $this->staff[0]['username'] . " 解绑 " . $irDetails['receivablesSerial'],
  5174. 'date' => date("Y-m-d"),
  5175. 'status' => 3,
  5176. 'img' => $this->staff[0]['avatar'],
  5177. 'username' => $this->staff[0]['username'],
  5178. 'uid' => $this->staff[0]['sid'],
  5179. 'category' => $this->staff[0]['category'],
  5180. 'irid' => $irid
  5181. );
  5182. $invoiceROLog->setInvoiceROLog($item);
  5183. // 扣除入账统计金额
  5184. $invoiceStatistics = new invoiceStatistics();
  5185. $item = array(
  5186. 'date' => date('Y-m-d', strtotime($irDetails['receivablesDate'])),
  5187. 'priceClass' => 3,
  5188. 'cid' => $invoiceDetails['cid'],
  5189. 'staff' => $invoiceDetails['sid'],
  5190. 'accountPrice' => -$invoiceDetails['invoicePrice']
  5191. );
  5192. $invoiceStatistics->setInvoiceStatisticsByCondition($item);
  5193. // 扣除收款统计金额
  5194. $invoiceStatistics = new invoiceStatistics();
  5195. $item = array(
  5196. 'date' => date('Y-m-d', strtotime($irDetails['receivablesDate'])),
  5197. 'priceClass' => 2,
  5198. 'cid' => $invoiceDetails['cid'],
  5199. 'staff' => $invoiceDetails['sid'],
  5200. 'irid' => $irDetails['irid'],
  5201. 'receivablesPrice' => -$invoiceDetails['invoicePrice']
  5202. );
  5203. $invoiceStatistics->setInvoiceStatisticsByCondition($item);
  5204. // 发票解绑去收款ID
  5205. $iridString = $invoiceDetails['irid'];
  5206. if (!empty($invoiceDetails['irid'])) {
  5207. $list = explode(',', $invoiceDetails['irid']);
  5208. foreach ($list as $key => $value) {
  5209. if ($value == $irDetails['irid']) {
  5210. unset($list[$key]);
  5211. break;
  5212. }
  5213. }
  5214. $iridString = implode(",", $list);
  5215. }
  5216. //解绑后余额 加回去
  5217. $invoiceBalance = $invoiceDetails['invoiceBalance'] + $irDetails['receivablesPrice'];
  5218. if ($invoiceBalance < 0) {
  5219. $invoiceBalance = 0;
  5220. }
  5221. if ($invoiceBalance > $invoiceDetails['invoicePrice']) {
  5222. $invoiceBalance = $invoiceDetails['invoicePrice'];
  5223. }
  5224. $item = array(
  5225. 'iid' => $invoiceDetails['iid'],
  5226. 'irid' => $iridString,
  5227. 'invoiceBalance' => $invoiceBalance,
  5228. 'updateTime' => date("Y-m-d H:i:s")
  5229. );
  5230. if ($invoiceDetails['untreadStatus'] == 3)
  5231. $item += array(
  5232. 'untreadStatus' => 0
  5233. );
  5234. $invoice->setInvoiceByCondition($item);
  5235. Doo::loadModel('bill');
  5236. $bill = new bill();
  5237. $bill->iid = $invoiceDetails['iid'];
  5238. $bill->trainId = $invoiceDetails['trainId'];
  5239. $bill->irid = $irDetails['irid'];
  5240. $bill->create_time = date("Y-m-d H:i:s");
  5241. $bill->price = -$invoiceDetails['invoicePrice'];
  5242. $bill->remark = '解绑-扣除入账';
  5243. $bill->insert();
  5244. $item = array(
  5245. 'date' => date("Y-m-d H:i:s"),
  5246. 'operation' => '解绑 收款 ' . $irDetails['receivablesSerial'],
  5247. 'status' => 11,
  5248. 'img' => $this->staff[0]['avatar'],
  5249. 'username' => $this->staff[0]['username'],
  5250. 'uid' => $this->staff[0]['sid'],
  5251. 'category' => $this->staff[0]['category'],
  5252. 'iid' => $invoiceDetails['iid']
  5253. );
  5254. $invoiceOperationLog->setInvoiceOperationLog($item);
  5255. // 公司流水-解绑时删除流水
  5256. // Doo::loadModel ( 'wasteBook' );
  5257. // $wasteBook = new wasteBook ();
  5258. // $wasteBook->delete ( array (
  5259. // 'where' => 'dataID=' . $irDetails ['irid'] . ' and accountType=7',
  5260. // 'limit' => 1
  5261. // ) );
  5262. // 银行
  5263. /*
  5264. * $abDetail = $wasteBook->getAccountBookByAid (2,7,$irDetails ['irid'] ); $accountBank=''; if ($irDetails ['receivablesBank']=='纵横广发'){ $accountBank='CGBDeposit'; }elseif($irDetails ['receivablesBank']=='纵横工行'){ $accountBank='ICBCDeposit'; }elseif($irDetails ['receivablesBank']=='华润银行'){ $accountBank='HUADeposit'; }elseif($irDetails ['receivablesBank']=='个人广发'){ $accountBank='PersonalDeposit'; } if (empty($abDetail)){ $item = array ( 'dataID' => $irDetails ['irid'], 'expensesType' => 2, 'accountType' => 7, 'accountPriceShow'=>$irDetails ['receivablesPrice'], 'accountPrice' => -$irDetails ['receivablesPrice'], 'accountBank'=>$accountBank, 'cid'=>$this->staff[0]['cid'], 'name'=>$this->staff[0]['username'], 'sid'=>$this->staff[0]['sid'], 'inputDate'=>date ( "Y-m-d H:i:s" ) ); $wasteBook->setAccountBookStatistics($item); }
  5265. */
  5266. return "/invoiceReceivablesAS";
  5267. }
  5268. /**
  5269. * 或者该收款下的所以发票
  5270. */
  5271. function ajaxGetInvoiceReceivablesByInvoice()
  5272. {
  5273. $irid = $this->get_args('postData') ? $this->get_args('postData') : '';
  5274. Doo::loadModel('invoice');
  5275. $invoice = new invoice();
  5276. Doo::loadModel('invoiceReceivables');
  5277. $invoiceReceivables = new invoiceReceivables();
  5278. $irid = $invoice->authcode($irid);
  5279. if (!empty($irid) && !is_numeric($irid))
  5280. die('illegal request');
  5281. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid($irid);
  5282. $iidString = $irDetails['iid'];
  5283. $iidExtend = array_filter(explode(',', $irDetails['iidExtend']));
  5284. if (!empty($irDetails['iidExtend']))
  5285. $iidString .= ',' . implode(',', $iidExtend);
  5286. $invoiceList = $invoice->getInvoiceInIid($iidString, 'iid,invoiceSerial,invoicePrice,invoiceTitle,invoiceCompany,invoiceElement');
  5287. $html = "";
  5288. foreach ($invoiceList as $key => $value) {
  5289. $title = $value['invoiceTitle'];
  5290. if (!empty($value['invoiceCompany']))
  5291. $title = $value['invoiceCompany'];
  5292. $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>';
  5293. }
  5294. echo json_encode(array(
  5295. 'status' => 1,
  5296. 'html' => $html
  5297. ));
  5298. }
  5299. /**
  5300. * 发票管理
  5301. */
  5302. function invoiceAS()
  5303. {
  5304. Doo::loadModel('invoice');
  5305. $invoice = new invoice();
  5306. Doo::loadModel('invoiceReceivables');
  5307. $invoiceReceivables = new invoiceReceivables();
  5308. $MebSea = $this->get_args('MebSea') ? $this->get_args('MebSea') : "";
  5309. $page_size = 18;
  5310. $page = isset($this->params['page']) && is_numeric($this->params['page']) ? $this->params['page'] : 1;
  5311. $status = isset($this->params['status']) ? $this->params['status'] : 'All';
  5312. $date = $this->get_args('date') ? $this->get_args('date') : "";
  5313. $dateArr = explode(':', $date);
  5314. $D1 = '';
  5315. $D2 = '';
  5316. if (!empty($date)) {
  5317. $D1 = $dateArr[0] . " 00:00:00 ";
  5318. if (isset($dateArr[1]))
  5319. $D2 = $dateArr[1] . " 23:59:59 ";
  5320. else
  5321. $D2 = $dateArr[0] . " 23:59:59 "; // date ( "Y-m-d" );
  5322. // $D2 = $dateArr [1];
  5323. }
  5324. $con = ' status=2 ';
  5325. if (!empty($D1) && !empty($D2))
  5326. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  5327. if ($status == 'UNRECORD')
  5328. $con .= ' and printStatus=1 and untreadStatus=0';
  5329. elseif ($status == 'BAD') {
  5330. $con .= ' and badDebt=1 ';
  5331. } elseif ($status == 'RECORD')
  5332. $con .= ' and printStatus=1 and untreadStatus=3';
  5333. elseif ($status == 'BOUNCED')
  5334. $con .= ' and untreadStatus=2';
  5335. elseif ($status == 'PARTRECORD')
  5336. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  5337. elseif ($status == 'All') {
  5338. $con .= ' and ( untreadStatus=2 or untreadStatus=1 or untreadStatus=0 or untreadStatus=3 )';
  5339. }
  5340. $get = "/" . $status . "?date=" . urlencode($date) . "&MebSea=" . urlencode($MebSea);
  5341. if (!empty($MebSea)) {
  5342. $con .= ' and ( invoiceSerial like "%' . $MebSea . '%" or invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  5343. }
  5344. $pageinfo['page'] = array(
  5345. 'previous' => ''
  5346. );
  5347. $pageinfo = $this->get_page("CLD_invoice", $con, $page, $page_size, "invoiceAS", $get, "");
  5348. $limit = $pageinfo['lower'] . ',' . $page_size;
  5349. $list = $invoice->getInvoiceByUntreadStatusPage($limit, $con);
  5350. $this->data['MebSeaEn'] = $MebSea;
  5351. $this->data['MebSea'] = urlencode($MebSea);
  5352. $this->data['date'] = $date;
  5353. $this->data['page'] = $pageinfo;
  5354. $this->data['get'] = $get;
  5355. $this->data['list'] = $list;
  5356. $this->data['status'] = $status;
  5357. $this->data['memu'] = "invoice";
  5358. $this->data['staff'] = $this->staff;
  5359. $this->data['receiptMemu'] = 'invoiceReceivables';
  5360. $this->render("/admin/invoiceAS", $this->data);
  5361. }
  5362. /**
  5363. * 收款管理
  5364. */
  5365. function invoiceReceivablesAS()
  5366. {
  5367. Doo::loadModel('invoiceReceivables');
  5368. $invoiceReceivables = new invoiceReceivables();
  5369. Doo::loadModel('L_category');
  5370. $lCategory = new L_category();
  5371. $category = $lCategory->getCategory();
  5372. $MebSea = $this->get_args('MebSea') ? $this->get_args('MebSea') : "";
  5373. $timeType = $this->get_args('timeType') ? $this->get_args('timeType') : "CREATE";
  5374. $page_size = 10;
  5375. $page = isset($this->params['page']) && is_numeric($this->params['page']) ? $this->params['page'] : 1;
  5376. $status = isset($this->params['status']) ? $this->params['status'] : 'All';
  5377. $date = $this->get_args('date') ? $this->get_args('date') : "";
  5378. $dateArr = explode(':', $date);
  5379. $D1 = '';
  5380. $D2 = '';
  5381. if (!empty($date)) {
  5382. $D1 = $dateArr[0]; // ." 00:00:00 ";
  5383. if (isset($dateArr[1]))
  5384. $D2 = $dateArr[1]; // ." 23:59:59 ";
  5385. else
  5386. $D2 = $dateArr[0]; // ." 23:59:59 ";//date ( "Y-m-d" );
  5387. }
  5388. $descField = 'a.receivablesDate';
  5389. if ($timeType == 'CREATE')
  5390. $descField = 'a.date';
  5391. $con = ' 1 ';
  5392. if (!empty($D1) && !empty($D2))
  5393. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  5394. elseif (!empty($D1) && empty($D2))
  5395. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  5396. if ($status == 'Unclaimed')
  5397. $con .= ' and a.bindStatus=0';
  5398. elseif ($status == 'Credited')
  5399. $con .= ' and a.bindStatus=1';
  5400. elseif ($status == 'Claim')
  5401. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  5402. elseif ($status == 'BBN')
  5403. $con .= ' and a.bankBatchNumber!=""';
  5404. elseif ($status == 'REFUND')
  5405. $con .= ' and ( (a.bindStatus=0 and a.refundLog!="" ) or a.bindStatus=2)';
  5406. $get = "/" . $status . "?date=" . urlencode($date) . "&MebSea=" . urlencode($MebSea);
  5407. if (!empty($MebSea)) {
  5408. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" or a.receivablesSerial like "%' . $MebSea . '%" )';
  5409. }
  5410. $pageinfo['page'] = array(
  5411. 'previous' => ''
  5412. );
  5413. // if(!empty($con)){
  5414. // $con=' where 1 '.$con;
  5415. // }
  5416. // $sql = 'select a.iid from CLD_invoiceReceivables as a
  5417. // ' . $con ;
  5418. $pageinfo = $this->get_page("CLD_invoiceReceivables as a", $con, $page, $page_size, "invoiceReceivablesAS", $get, "");
  5419. //echo $sql;
  5420. //$pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceReceivablesAS", $get, "" );
  5421. $limit = $pageinfo['lower'] . ',' . $page_size;
  5422. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage($limit, $con, 'desc', $descField);
  5423. foreach ($list as $key => $value) {
  5424. $list[$key]['category'] = '';
  5425. if ($value['receivablesCategory'] != 'PUBLIC') {
  5426. $receivablesCategory = explode(":", $value['receivablesCategory']);
  5427. $list[$key]['category'] = $receivablesCategory[1];
  5428. }
  5429. }
  5430. // print_r($list);
  5431. $this->data['category'] = $category;
  5432. $this->data['timeType'] = $timeType;
  5433. $this->data['MebSeaEn'] = $MebSea;
  5434. $this->data['MebSea'] = urlencode($MebSea);
  5435. $this->data['date'] = $date;
  5436. $this->data['page'] = $pageinfo;
  5437. $this->data['get'] = $get;
  5438. $this->data['list'] = $list;
  5439. $this->data['status'] = $status;
  5440. $this->data['memu'] = "invoice";
  5441. $this->data['staff'] = $this->staff;
  5442. $this->data['receiptMemu'] = 'invoiceReceivables';
  5443. $this->render("/admin/invoiceReceivablesAS", $this->data);
  5444. }
  5445. /**
  5446. * 删除一条收款
  5447. */
  5448. function delInvoiceReceivables()
  5449. {
  5450. $iridKey = $this->get_args('iridKey') ? $this->get_args('iridKey') : "";
  5451. if (empty($iridKey))
  5452. die('illegal request');
  5453. Doo::loadClass('XDeode');
  5454. $XDeode = new XDeode(5);
  5455. $irid = $XDeode->decode($iridKey);
  5456. Doo::loadModel('invoiceReceivables');
  5457. $invoiceReceivables = new invoiceReceivables();
  5458. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid($irid);
  5459. if (empty($detail))
  5460. die('illegal request');
  5461. $invoiceReceivables->delInvoiceReceivablesByIrid($detail['irid']);
  5462. // 扣除收款汇总信息 汇总
  5463. Doo::loadModel('invoiceStatistics');
  5464. $invoiceStatistics = new invoiceStatistics();
  5465. $item = array(
  5466. 'date' => $detail['receivablesDate'],
  5467. 'priceClass' => 2,
  5468. 'irid' => $detail['irid'],
  5469. 'receivablesPrice' => -$detail['receivablesPrice']
  5470. );
  5471. if ($detail['receivablesCategory'] != 'PUBLIC') {
  5472. $receivablesCategory = explode(":", $detail['receivablesCategory']);
  5473. $item += array(
  5474. 'cid' => $receivablesCategory[0]
  5475. );
  5476. }
  5477. if ($detail['receivablesStaff'] != 'PUBLIC') {
  5478. $receivablesStaff = explode("-", $detail['receivablesStaff']);
  5479. $item += array(
  5480. 'staff' => $receivablesStaff[0]
  5481. );
  5482. }
  5483. $invoiceStatistics->setInvoiceStatisticsByCondition($item);
  5484. return '/invoiceReceivablesAS';
  5485. }
  5486. /**
  5487. * 添加退款信息
  5488. */
  5489. function setInvoiceReceivablesRefund()
  5490. {
  5491. $iridKey = $this->get_args('iridKey') ? $this->get_args('iridKey') : '';
  5492. $refundType = $this->get_args('refundType') && is_numeric($this->get_args('refundType')) ? $this->get_args('refundType') : '0';
  5493. $refundCompany = $this->get_args('refundCompany') ? $this->get_args('refundCompany') : "";
  5494. $refundNumber = $this->get_args('refundNumber') ? $this->get_args('refundNumber') : "";
  5495. $refundPrice = $this->get_args('refundPrice') ? $this->get_args('refundPrice') : "";
  5496. $refundRemarks = $this->get_args('refundRemarks') ? $this->get_args('refundRemarks') : "";
  5497. if ($refundPrice < 0)
  5498. die('illegal request');
  5499. if (!empty($iridKey) && !empty($refundCompany) && !empty($refundNumber) && !empty($refundPrice)) {
  5500. Doo::loadModel('invoiceReceivables');
  5501. $invoiceReceivables = new invoiceReceivables();
  5502. Doo::loadModel('invoiceRefund');
  5503. $invoiceRefund = new invoiceRefund();
  5504. $irid = $invoiceReceivables->authcode($iridKey);
  5505. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid($irid);
  5506. if ($irDetail['receivablesPrice'] < $refundPrice)
  5507. die('illegal request');
  5508. $invoiceReceivables = new invoiceReceivables();
  5509. $refundLog = $this->staff[0]['username'] . ' 退款 <b class="colRed">¥' . $refundPrice . '</b>
  5510. <br/><a href="#refunded" onclick="getRefundByDetail(\'' . $iridKey . '\')" data-toggle="modal">退款信息</a> <br/>' . date("Y-m-d H:i:s") . '
  5511. ';
  5512. $item = array(
  5513. 'irid' => $irid,
  5514. 'refundCompany' => $refundCompany,
  5515. 'refundNumber' => $refundNumber,
  5516. 'refundPrice' => $refundPrice,
  5517. 'refundRemarks' => $refundRemarks,
  5518. 'refundLog' => $refundLog
  5519. );
  5520. if ($refundType == 1) {
  5521. $item += array(
  5522. 'refundType' => $refundType,
  5523. 'receivablesPrice' => $irDetail['receivablesPrice'] - $refundPrice,
  5524. 'bindStatus' => 2
  5525. );
  5526. } elseif ($refundType == 0 && $irDetail['receivablesPrice'] <= $refundPrice) {
  5527. $item += array(
  5528. 'refundType' => 1,
  5529. 'receivablesPrice' => $irDetail['receivablesPrice'] - $refundPrice,
  5530. 'bindStatus' => 2
  5531. );
  5532. } else {
  5533. $item += array(
  5534. 'refundType' => $refundType,
  5535. 'receivablesPrice' => $irDetail['receivablesPrice'] - $refundPrice
  5536. );
  5537. }
  5538. $invoiceReceivables->setInvoiceReceivablesByCondition($item);
  5539. // 添加退款记录
  5540. $item = array(
  5541. 'irid' => $irid,
  5542. 'refundType' => $refundType,
  5543. 'refundCompany' => $refundCompany,
  5544. 'refundNumber' => $refundNumber,
  5545. 'refundPrice' => $refundPrice,
  5546. 'refundLog' => $refundLog,
  5547. 'refundRemarks' => $refundRemarks,
  5548. 'date' => date("Y-m-d H:i:s")
  5549. );
  5550. $invoiceRefund->addInvoiceRefund($item);
  5551. // 扣除收款汇总信息 汇总
  5552. Doo::loadModel('invoiceStatistics');
  5553. $invoiceStatistics = new invoiceStatistics();
  5554. $item = array(
  5555. 'date' => $irDetail['receivablesDate'],
  5556. 'priceClass' => 2,
  5557. 'irid' => $irDetail['irid'],
  5558. 'receivablesPrice' => -$refundPrice
  5559. );
  5560. $receivablesCategory = array(0 => '', 1 => '');
  5561. if ($irDetail['receivablesCategory'] != 'PUBLIC') {
  5562. $receivablesCategory = explode(":", $irDetail['receivablesCategory']);
  5563. $item += array(
  5564. 'cid' => $receivablesCategory[0]
  5565. );
  5566. }
  5567. if ($irDetail['receivablesStaff'] != 'PUBLIC') {
  5568. $receivablesStaff = explode("-", $irDetail['receivablesStaff']);
  5569. $item += array(
  5570. 'staff' => $receivablesStaff[0]
  5571. );
  5572. }
  5573. $invoiceStatistics->setInvoiceStatisticsByCondition($item);
  5574. // 公司日常支出流水
  5575. Doo::loadModel('wasteBook');
  5576. $wasteBook = new wasteBook();
  5577. $accountBank = $wasteBook->_getAccountBankEN($irDetail['receivablesBank']);
  5578. $itemWaste = array(
  5579. 'accountPrice' => -$refundPrice,
  5580. 'expensesType' => 2,
  5581. 'accountType' => 11,
  5582. 'accountPriceShow' => $refundPrice,
  5583. 'dataID' => $irid,
  5584. 'accountBank' => $accountBank,
  5585. 'category' => $receivablesCategory[1],
  5586. 'cid' => $receivablesCategory[0],
  5587. 'name' => $this->staff[0]['username'],
  5588. 'sid' => $this->staff[0]['sid'],
  5589. 'inputDate' => date("Y-m-d H:i:s")
  5590. );
  5591. $wasteBook->setAccountBookStatistics($itemWaste);
  5592. return '/invoiceReceivablesAS';
  5593. }
  5594. die('illegal request');
  5595. }
  5596. function ajaxCheckInvoiceReceivablesRefund()
  5597. {
  5598. $iridKey = $this->get_args('iridKey') ? $this->get_args('iridKey') : '';
  5599. $refundPrice = $this->get_args('refundPrice') ? $this->get_args('refundPrice') : "";
  5600. if ($refundPrice < 0) {
  5601. echo json_encode(array(
  5602. 'error' => '金额不能为负'
  5603. ));
  5604. die();
  5605. }
  5606. if (!empty($refundPrice) && !empty($iridKey)) {
  5607. Doo::loadModel('invoiceReceivables');
  5608. $invoiceReceivables = new invoiceReceivables();
  5609. $irid = $invoiceReceivables->authcode($iridKey);
  5610. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid($irid);
  5611. if ($irDetail['receivablesPrice'] < $refundPrice) {
  5612. echo json_encode(array(
  5613. 'error' => '退款金额不能超过收款金额'
  5614. ));
  5615. die();
  5616. }
  5617. echo json_encode(array(
  5618. 'ok' => '可以使用!'
  5619. ));
  5620. die();
  5621. }
  5622. }
  5623. /**
  5624. * 获得收款退款信息
  5625. */
  5626. function getRefundByDetail()
  5627. {
  5628. $iridKey = $this->get_args('iridKey') ? $this->get_args('iridKey') : '';
  5629. Doo::loadModel('invoiceReceivables');
  5630. $invoiceReceivables = new invoiceReceivables();
  5631. if (!empty($iridKey)) {
  5632. $irid = $invoiceReceivables->authcode($iridKey);
  5633. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid($irid);
  5634. echo json_encode(array(
  5635. 'status' => 1,
  5636. 'irDetail' => $irDetail
  5637. ));
  5638. die();
  5639. }
  5640. echo json_encode(array(
  5641. 'status' => 2
  5642. ));
  5643. }
  5644. /**
  5645. * 根据收款序列号获得收款退款信息
  5646. */
  5647. function ajaxGetInvoiceReceivablesBySerial()
  5648. {
  5649. $receivablesSerial = $this->get_args('receivablesSerial') ? $this->get_args('receivablesSerial') : '';
  5650. if (!empty($receivablesSerial)) {
  5651. Doo::loadModel('invoiceReceivables');
  5652. $invoiceReceivables = new invoiceReceivables();
  5653. // , ' and refundLog=""'
  5654. $irDetail = $invoiceReceivables->getInvoiceReceivablesBySerial($receivablesSerial);
  5655. $html = '';
  5656. if (!empty($irDetail))
  5657. $html = '<td><b>¥' . $irDetail['receivablesPrice'] . '</b></td>
  5658. <td>' . $irDetail['receivablesMessage'] . '</td>
  5659. <td>' . $irDetail['receivablesBank'] . '<br>' . $irDetail['receivablesDate'] . '</td>
  5660. <td>' . $irDetail['title'] . '-' . $irDetail['username'] . '<br>' . $irDetail['confirmTime'] . '</td>
  5661. <td>' . $irDetail['recepitTitleMark'] . '
  5662. <input type="hidden" name="iridKey" id="iridKey" value="' . $irDetail['iridKey'] . '">
  5663. </td>';
  5664. echo json_encode(array(
  5665. 'status' => 1,
  5666. 'html' => $html,
  5667. 'irDetail' => $irDetail
  5668. ));
  5669. die();
  5670. }
  5671. echo json_encode(array(
  5672. 'status' => 2
  5673. ));
  5674. }
  5675. /**
  5676. * 绑定新收款
  5677. */
  5678. function relationNewInvoiceReceivables()
  5679. {
  5680. $iridKeyOld = $this->get_args('iridKeyOld') ? $this->get_args('iridKeyOld') : '';
  5681. $iridKey = $this->get_args('iridKey') ? $this->get_args('iridKey') : '';
  5682. if (!empty($iridKeyOld) && !empty($iridKey)) {
  5683. Doo::loadModel('invoiceReceivables');
  5684. $invoiceReceivables = new invoiceReceivables();
  5685. Doo::loadClass('XDeode');
  5686. $XDeode = new XDeode(5);
  5687. $irid = $XDeode->decode($iridKey);
  5688. $iridOld = $invoiceReceivables->authcode($iridKeyOld);
  5689. echo $irid . 'bbb' . $iridOld;
  5690. $oldIrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid($iridOld);
  5691. $IrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid($irid);
  5692. if (empty($oldIrDetail) || empty($IrDetail))
  5693. die('illegal request');
  5694. $relationLog = $this->staff[0]['username'] . ' 关联新款 <a href="#billing" onclick="invoiceReceivblesDivShow(\'' . $iridKey . '\',\'receivables\')" data-toggle="modal">' . $IrDetail['receivablesSerial'] . '</a>
  5695. <br/>' . date("Y-m-d H:i:s") . '
  5696. ';
  5697. $invoiceReceivables = new invoiceReceivables();
  5698. $item = array(
  5699. 'irid' => $iridOld,
  5700. 'relationIrid' => $irid,
  5701. 'relationLog' => $relationLog
  5702. );
  5703. $invoiceReceivables->setInvoiceReceivablesByCondition($item);
  5704. return '/invoiceReceivablesAS';
  5705. }
  5706. die('illegal request');
  5707. }
  5708. // function invoiceApprovalAchieve() {
  5709. // Doo::loadModel ( 'invoice' );
  5710. // $invoice = new invoice ();
  5711. // $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  5712. // $page_size = 12;
  5713. // $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5714. // $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  5715. // $get = "/" . $date;
  5716. // $con = '';
  5717. // if ($date == 'MONTHO')
  5718. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  5719. // elseif ($date == 'MONTHT')
  5720. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  5721. // elseif ($date == 'MONTHY')
  5722. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  5723. // if (! empty ( $MebSea )) {
  5724. // $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  5725. // $get .= "/" . $MebSea;
  5726. // }
  5727. // $pageinfo ['page'] = array (
  5728. // 'previous' => ''
  5729. // );
  5730. // $sql = '(status=1 or status=2 or status=3 or status=4) and processApprovals!=""' . $con; // echo $sql;
  5731. // $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", $get, "" );
  5732. // $limit = $pageinfo ['lower'] . ',' . $page_size;
  5733. // $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  5734. // // print_r($list);
  5735. // $this->data ['MebSeaEn'] = $MebSea;
  5736. // $this->data ['MebSea'] = urlencode ( $MebSea );
  5737. // $this->data ['get'] = $get;
  5738. // $this->data ['page'] = $pageinfo;
  5739. // $this->data ['list'] = $list;
  5740. // $this->data ['date'] = $date;
  5741. // $this->data ['memu'] = "invoice";
  5742. // $this->data ['staff'] = $this->staff;
  5743. // $this->data ['receiptMemu'] = 'invoiceApproval';
  5744. // $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  5745. // }
  5746. /**
  5747. * 获得审批发票的信息以及审批页面
  5748. */
  5749. function ajaxGetInvoiceApprovalDetail()
  5750. {
  5751. $serial = $this->get_args('serial') ? $this->get_args('serial') : "";
  5752. if (empty($serial)) {
  5753. echo json_encode(array(
  5754. 'status' => 2,
  5755. 'msg' => 'illegal request'
  5756. ));
  5757. die();
  5758. }
  5759. Doo::loadModel('invoice');
  5760. $invoice = new invoice();
  5761. Doo::loadModel('invoiceOperationLog');
  5762. $invoiceOperationLog = new invoiceOperationLog();
  5763. $detail = $invoice->getInvoiceByIsid($serial, $this->staff[0]['sid']);
  5764. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid($detail['iid']);
  5765. if (empty($detail))
  5766. $html = '';
  5767. else {
  5768. $html = '
  5769. <form action="/invoiceApprovalDo" method="post" name="invoiceApproval" class="nice-validator n-yellow" novalidate="novalidate">
  5770. <input type="hidden" name="invoiceKey" value="' . $detail['iidKeyXD'] . '">
  5771. <input type="hidden" name="status" value="">
  5772. <input type="hidden" name="divApproval" value="divApproval">
  5773. <div class="modal-dialog modal-lg">
  5774. <div class="modal-content"><div class="modal-header"><h3>发票审批详情</h3></div>
  5775. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  5776. <tr>
  5777. <th class="taC" width="150">发票审批</th><td><textarea name="opinion" style="width:98%" placeholder="在这写下您的审批意见,选填。"></textarea></td>
  5778. </tr>
  5779. <tr>
  5780. <th class="taC" width="150">开票流水号</th><td>' . $detail['invoiceSerial'] . '</td>
  5781. <th class="taC" width="150">提交时间</th><td>' . $detail['date'] . '</td>
  5782. </tr>
  5783. <tr>
  5784. <th class="taC" width="150">所在办事处</th><td>' . $detail['categoryName'] . '(' . $detail['userName'] . ')</td>
  5785. <th class="taC" width="150">开票内容</th><td>' . $detail['invoiceElement'] . '</td>
  5786. </tr>
  5787. <tr>
  5788. <th class="taC">发票备注</th><td colspan="3">' . $detail['remark'] . '
  5789. </td>
  5790. </tr>
  5791. <tr>
  5792. <th class="taC" width="150">数量</th><td><b>' . $detail['invoiceQuantity'] . '</b></td>
  5793. <th class="taC">单价</th><td><b>¥' . $detail['invoiceUnitPrice'] . '</b></td>
  5794. </tr>
  5795. <tr>
  5796. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail['invoicePrice'] . '</b></td>
  5797. </tr></tbody></table>';
  5798. if ($detail['invoiceType'] == 0)
  5799. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5800. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5801. <th class="taC" width="150">发票抬头</th><td >' . $detail['invoiceTitle'] . '</td>
  5802. <th class="taC" width="150">纳税人识别码</th><td>' . $detail['TIN'] . '</td>
  5803. </tr>';
  5804. else
  5805. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5806. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5807. <th class="taC" width="150">单位名称</th><td>' . $detail['invoiceCompany'] . '</td>
  5808. <th class="taC" width="150">纳税人识别码</th><td>' . $detail['TIN'] . '</td></tr>
  5809. ';
  5810. $html .= '<tr>
  5811. <th class="taC">注册地址</th><td>' . $detail['address'] . '</td>
  5812. <th class="taC">注册电话</th><td>' . $detail['phone'] . '</td>
  5813. </tr>
  5814. <tr>
  5815. <th class="taC">开户银行</th><td>' . $detail['bank'] . '</td>
  5816. <th class="taC">银行账号</th><td>' . $detail['bankAccount'] . '</td>
  5817. </tr></tbody></table>';
  5818. if ($detail['doPost'] == 1) {
  5819. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5820. <th class="taC" width="150">收件人</th><td>' . $detail['recipients'] . '</td>
  5821. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail['recipientsPhone'] . '</td>
  5822. </tr><tr>
  5823. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail['recipientsAddress'] . '</td>
  5824. </tr><tr>
  5825. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail['mailItems'] . '</td>
  5826. </tr>
  5827. ';
  5828. if ($detail['expressCom'] == 'SF')
  5829. $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>';
  5830. else
  5831. $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>';
  5832. $html .= '</tbody></table>';
  5833. }
  5834. if (!empty($invoiceOperationLogList)) {
  5835. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  5836. foreach ($invoiceOperationLogList as $key => $value) {
  5837. if ($value['status'] == 1 || $value['status'] == 2 || $value['status'] == 3 || $value['status'] == 4) {
  5838. $html .= '<blockquote><p><span class="colGray">' . $value['date'] . '</span>&nbsp;
  5839. ' . $value['category'] . '-' . $value['username'] . '&nbsp;';
  5840. if ($value['status'] == 2) {
  5841. $html .= '<span class="colGreen">同意</span>';
  5842. } elseif ($value['status'] == 3) {
  5843. $html .= '<span class="colOrange">退回</span>';
  5844. } elseif ($value['status'] == 5) {
  5845. $html .= '<span class="colGreen">打印</span>';
  5846. } elseif ($value['status'] == 4) {
  5847. $html .= '<span class="colRed">终止</span>';
  5848. }
  5849. $html .= $value['operation'] . '</p></blockquote>';
  5850. }
  5851. }
  5852. $html .= '</td></tr></tbody></table>';
  5853. }
  5854. $html .= '</div><div class="modal-footer">
  5855. <a href="javascript:void(0)" node-approval="approval" diss-data="2" class="button btn-done" data-placement="top" data-toggle="ctooltip" >同意</a>
  5856. <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>
  5857. <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>
  5858. <a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>
  5859. </form>
  5860. <script type="text/javascript">
  5861. $("a[node-approval^=\'approval\']").click(function() {
  5862. $("input[name=\'status\']").val($(this).attr("diss-data"));
  5863. $("form[name=\'invoiceApproval\']").submit();
  5864. });
  5865. </script>
  5866. ';
  5867. }
  5868. echo json_encode(array(
  5869. 'status' => 1,
  5870. 'html' => $html
  5871. ));
  5872. die();
  5873. }
  5874. /**
  5875. * 获得审批发票分页数据
  5876. */
  5877. function ajaxGetinvoiceApprovalAchieve()
  5878. {
  5879. Doo::loadModel('invoice');
  5880. $invoice = new invoice();
  5881. Doo::loadModel('staff');
  5882. $staff = new staff();
  5883. Doo::loadClass('XDeode');
  5884. $XDeode = new XDeode(5);
  5885. Doo::loadModel('invoiceTraining');
  5886. $invoiceTraining = new invoiceTraining();
  5887. $status = $this->get_args('status') ? $this->get_args('status') : 'ALL';
  5888. $invoiceType = $this->get_args('invoiceType') ? $this->get_args('invoiceType') : "ALL";
  5889. $invoiceTrain = $this->get_args('invoiceTrain') ? $this->get_args('invoiceTrain') : "ALL";
  5890. $invoiceTrainName = $this->get_args('invoiceTrainName') ? $this->get_args('invoiceTrainName') : "ALL";
  5891. $date = $this->get_args('date') ? $this->get_args('date') : "";
  5892. $page = $this->get_args('start') && is_numeric($this->get_args('start')) ? $this->get_args('start') : 0;
  5893. $draw = $this->get_args('draw') && is_numeric($this->get_args('draw')) ? $this->get_args('draw') : 1;
  5894. $length = $this->get_args('length') && is_numeric($this->get_args('length')) ? $this->get_args('length') : 10;
  5895. $MebSea = $this->get_args('search');
  5896. $MebSea = $MebSea['value'];
  5897. $page_size = $length;
  5898. $con = '';
  5899. if ($status == 'ALL')
  5900. $con = ' (status=1 or status=2 or status=3 or status=4) and isDelete=0 ';
  5901. elseif ($status == 'PEND')
  5902. $con = ' isDelete=0 and status=1';
  5903. elseif ($status == 'APPROVED')
  5904. $con = ' isDelete=0 and status=2';
  5905. if ($invoiceType == 'ORDINARY')
  5906. $con .= ' and invoiceType=0 ';
  5907. elseif ($invoiceType == 'SPECIAL')
  5908. $con .= ' and invoiceType=1 ';
  5909. if ($invoiceTrain == 'ORDINARY')
  5910. $con .= ' and trainId=0 ';
  5911. elseif ($invoiceTrain == 'TRAIN')
  5912. $con .= ' and trainId!=0 ';
  5913. if ($invoiceTrainName != 'ALL') {
  5914. $trainId = $XDeode->decode($invoiceTrainName);
  5915. if (is_numeric($trainId))
  5916. $con .= ' and trainId =' . $trainId;
  5917. }
  5918. $dateArr = explode(':', $date);
  5919. $D1 = $dateString = '';
  5920. $D2 = '';
  5921. if (!empty($date)) {
  5922. $D1 = $dateArr[0];
  5923. if (isset($dateArr[1]))
  5924. $D2 = $dateArr[1];
  5925. else
  5926. $D2 = '';
  5927. $dateString = $D1 . " : " . $D2;
  5928. }
  5929. if (!empty($D1) && !empty($D2))
  5930. $con .= ' and approvalTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  5931. elseif (!empty($D1) && empty($D2))
  5932. $con .= ' and approvalTime like "%' . $D1 . '%" ';
  5933. if (!empty($MebSea))
  5934. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceSerial like "%' . $MebSea . '%" )';
  5935. // /
  5936. $pageinfo['page'] = array(
  5937. 'previous' => ''
  5938. );
  5939. $sql = ' ' . $con;
  5940. $pageinfo = $this->get_page("CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", '', "");
  5941. $limit = $page . ',' . $page_size;
  5942. $list = $invoice->getInvoiceByUntreadStatusPage($limit, $sql, 'desc', 2);
  5943. $approvalList = array();
  5944. $html = '<script type="text/javascript">
  5945. </script>';
  5946. // 结算结束不能修改方式
  5947. Doo::loadModel('receipt');
  5948. $receipt = new receipt();
  5949. foreach ($list as $key => $value) {
  5950. $irDetail = array();
  5951. // 结算方式
  5952. $receiptDetail = array();
  5953. if ($value['trainId'] != 0) {
  5954. $receiptDetail = $receipt->getReceiptByinvoiceTrainId($value['trainId']);
  5955. }
  5956. if (!empty($receiptDetail)) {
  5957. if ($receiptDetail['status'] == 8 || $receiptDetail['status'] == 9) {
  5958. array_push($irDetail, '');
  5959. } else {
  5960. if ($value['status'] == 1 && $value['pendingApprovals'] == $this->staff[0]['sid']) {
  5961. array_push($irDetail, '<a href="#approvalInvice" onclick="nodeInvoiceApproval(\'' . $value['iidKeyK'] . '\')" data-toggle="modal">审批发票</a>');
  5962. } elseif ($value['status'] == 2) {
  5963. array_push($irDetail, '<a href="#editPay" class="fnSettlementType" data-iidKey="' . $value['iidKeyK'] . '" data-toggle="modal">结算方式</a>');
  5964. } else
  5965. array_push($irDetail, '');
  5966. }
  5967. } else {
  5968. if ($value['status'] == 2) {
  5969. array_push($irDetail, '<a href="#editPay" class="fnSettlementType" data-iidKey="' . $value['iidKeyK'] . '" data-toggle="modal">结算方式</a>');
  5970. } else {
  5971. if ($value['status'] == 1 && $value['pendingApprovals'] == $this->staff[0]['sid']) {
  5972. array_push($irDetail, '<a href="#approvalInvice" onclick="nodeInvoiceApproval(\'' . $value['iidKeyK'] . '\')" data-toggle="modal">审批发票</a>');
  5973. } else {
  5974. array_push($irDetail, '');
  5975. }
  5976. }
  5977. }
  5978. array_push($irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value['iidKeyK'] . '\')" data-toggle="modal">' . $value['invoiceSerial'] . '</a>');
  5979. if ($value['invoiceType'] == 1)
  5980. array_push($irDetail, $value['invoiceCompany']);
  5981. else
  5982. array_push($irDetail, $value['invoiceTitle']);
  5983. array_push($irDetail, $value['TIN']);
  5984. array_push($irDetail, $value['address'] . $value['phone']);
  5985. array_push($irDetail, $value['bank'] . $value['bankAccount']);
  5986. array_push($irDetail, $value['remark']);
  5987. array_push($irDetail, $value['invoiceElement']);
  5988. array_push($irDetail, $value['invoiceQuantity']);
  5989. array_push($irDetail, $value['invoiceUnitPrice']);
  5990. if ($value['invoiceType'] == 1) {
  5991. array_push($irDetail, '¥' . $value['invoicePrice'] . '<sup>专</sup>');
  5992. } else {
  5993. array_push($irDetail, '¥' . $value['invoicePrice']);
  5994. }
  5995. if ($value['settlementType'] == 0) {
  5996. array_push($irDetail, '软件销售');
  5997. } else {
  5998. $itDetail = $invoiceTraining->getInvoiceTrainingByItid($value['trainId']);
  5999. array_push($irDetail, $itDetail['trainName']);
  6000. }
  6001. array_push($irDetail, $value['recipients'] . $value['recipientsPhone']);
  6002. array_push($irDetail, $value['recipientsAddress']);
  6003. array_push($irDetail, $value['mailItems']);
  6004. array_push($irDetail, $value['userName'] . '&nbsp;' . $value['date']);
  6005. $fchtml = $value['OL']['operation'];
  6006. if (count($list) == $page_size)
  6007. $fchtml = $value['OL']['operation'] . $html;
  6008. // 最后的审批意见
  6009. array_push($irDetail, $fchtml);
  6010. if ($value['status'] == 2)
  6011. array_push($irDetail, '<span class="colGreen">同意</span>' . $value['OL']['username'] . $value['OL']['date']);
  6012. elseif ($value['status'] == 3)
  6013. array_push($irDetail, '<span class="colOrange">退回</span>' . $value['OL']['username'] . $value['OL']['date']);
  6014. elseif ($value['status'] == 4)
  6015. array_push($irDetail, '<span class="colRed">终止</span>' . $value['OL']['username'] . $value['OL']['date']);
  6016. else
  6017. array_push($irDetail, '');
  6018. array_push($approvalList, $irDetail);
  6019. }
  6020. // $approvalListJson = json_encode ( $approvalList );
  6021. $recordsFiltered = $pageinfo['total_data'];
  6022. echo json_encode(array(
  6023. "draw" => intval($draw),
  6024. "recordsTotal" => intval($pageinfo['total_data']),
  6025. "recordsFiltered" => intval($recordsFiltered),
  6026. "data" => $approvalList
  6027. ), JSON_UNESCAPED_UNICODE);
  6028. }
  6029. /**
  6030. * 审批发票查看更多--重构
  6031. */
  6032. function invoiceApprovalAchieve()
  6033. {
  6034. $status = isset($this->params['status']) ? $this->params['status'] : 'ALL';
  6035. $invoiceType = $this->get_args('invoiceType') ? $this->get_args('invoiceType') : "ALL";
  6036. $invoiceTrain = $this->get_args('invoiceTrain') ? $this->get_args('invoiceTrain') : "ALL";
  6037. $invoiceTrainName = $this->get_args('invoiceTrainName') ? $this->get_args('invoiceTrainName') : "ALL";
  6038. $date = $this->get_args('date') ? $this->get_args('date') : "";
  6039. Doo::loadModel('invoiceTraining');
  6040. $invoiceTraining = new invoiceTraining();
  6041. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus();
  6042. $this->data['trainList'] = $trainList;
  6043. $this->data['dateString'] = $date;
  6044. $this->data['status'] = $status;
  6045. $this->data['invoiceType'] = $invoiceType;
  6046. $this->data['invoiceTrain'] = $invoiceTrain;
  6047. $this->data['invoiceTrainName'] = $invoiceTrainName;
  6048. $this->data['memu'] = "invoice";
  6049. $this->data['staff'] = $this->staff;
  6050. $this->data['receiptMemu'] = 'invoiceApproval';
  6051. $this->render("/admin/invoiceApprovalAchieve", $this->data);
  6052. }
  6053. function invoiceTAchieve()
  6054. {
  6055. Doo::loadModel('invoice');
  6056. $invoice = new invoice();
  6057. Doo::loadClass('XDeode');
  6058. $XDeode = new XDeode(5);
  6059. Doo::loadModel('staff');
  6060. $staff = new staff();
  6061. $MebSea = isset($this->params['MebSea']) ? urldecode($this->params['MebSea']) : '';
  6062. $page_size = 12;
  6063. $page = isset($this->params['page']) && is_numeric($this->params['page']) ? $this->params['page'] : 1;
  6064. $date = isset($this->params['date']) ? $this->params['date'] : 'MONTHO';
  6065. $invoiceType = $this->get_args('invoiceType') ? $this->get_args('invoiceType') : "ALL";
  6066. $invoiceTrain = $this->get_args('invoiceTrain') ? $this->get_args('invoiceTrain') : "ALL";
  6067. $invoiceTrainName = $this->get_args('invoiceTrainName') ? $this->get_args('invoiceTrainName') : "ALL";
  6068. Doo::loadModel('invoiceTraining');
  6069. $invoiceTraining = new invoiceTraining();
  6070. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus();
  6071. $get = "/" . $date;
  6072. $con = '';
  6073. if ($date == 'MONTHO')
  6074. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  6075. elseif ($date == 'MONTHT')
  6076. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  6077. elseif ($date == 'MONTHY')
  6078. $con = ' and YEAR(updateTime) = YEAR(NOW())'; // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  6079. if ($invoiceType == 'ORDINARY')
  6080. $con .= ' and invoiceType=0 ';
  6081. elseif ($invoiceType == 'SPECIAL')
  6082. $con .= ' and invoiceType=1 ';
  6083. if ($invoiceTrain == 'ORDINARY')
  6084. $con .= ' and trainId=0 ';
  6085. elseif ($invoiceTrain == 'TRAIN')
  6086. $con .= ' and trainId!=0 ';
  6087. if ($invoiceTrainName != 'ALL') {
  6088. $trainId = $XDeode->decode($invoiceTrainName);
  6089. if (is_numeric($trainId))
  6090. $con .= ' and trainId =' . $trainId;
  6091. }
  6092. if (!empty($MebSea)) {
  6093. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  6094. $get .= "/" . $MebSea;
  6095. }
  6096. $pageinfo['page'] = array(
  6097. 'previous' => ''
  6098. );
  6099. $sql = "";
  6100. $action = "";
  6101. if ($this->ACTION == 'invoicePrintAchieve') {
  6102. $sql = "status=2 and printStatus=1 and moldManage like '%[\"" . $this->staff[0]['sid'] . "\",%'" . $con;
  6103. $action = "invoicePrintAchieve";
  6104. } elseif ($this->ACTION == 'invoicePostAchieve') {
  6105. // and untreadStatus=0
  6106. $sql = "postStatus=1 and doPost=1 and status=2 and isDelete=0" . $con;
  6107. $action = "invoicePostAchieve";
  6108. } elseif ($this->ACTION == 'invoiceUntreadAchieve') { // printStatus=1 and
  6109. $sql = " untreadStatus=2 and status=2 " . $con;
  6110. $action = "invoiceUntreadAchieve";
  6111. }
  6112. $pageinfo = $this->get_page("CLD_invoice", $sql, $page, $page_size, $action, $get, "");
  6113. $limit = $pageinfo['lower'] . ',' . $page_size;
  6114. $this->data['MebSeaEn'] = $MebSea;
  6115. $this->data['MebSea'] = urlencode($MebSea);
  6116. $this->data['get'] = $get;
  6117. $this->data['page'] = $pageinfo;
  6118. $this->data['trainList'] = $trainList;
  6119. $this->data['invoiceType'] = $invoiceType;
  6120. $this->data['invoiceTrain'] = $invoiceTrain;
  6121. $this->data['invoiceTrainName'] = $invoiceTrainName;
  6122. $this->data['date'] = $date;
  6123. $this->data['memu'] = "invoice";
  6124. $this->data['staff'] = $this->staff;
  6125. if ($this->ACTION == 'invoicePrintAchieve') {
  6126. $list = $invoice->getInvoiceByUntreadStatusPage($limit, $sql, 'desc', 5);
  6127. $this->data['receiptMemu'] = 'invoicePrint';
  6128. $this->data['list'] = $list;
  6129. $this->render("/admin/invoicePrintAchieve", $this->data);
  6130. } elseif ($this->ACTION == 'invoicePostAchieve') {
  6131. $list = $invoice->getInvoiceByUntreadStatusPage($limit, $sql);
  6132. Doo::loadModel('express');
  6133. $express = new express();
  6134. $expressList = $express->getExpressByAll();
  6135. $this->data['expressList'] = $expressList;
  6136. $this->data['receiptMemu'] = 'invoicePost';
  6137. $this->data['list'] = $list;
  6138. $this->render("/admin/invoicePostAchieve", $this->data);
  6139. } elseif ($this->ACTION == 'invoiceUntreadAchieve') {
  6140. $list = $invoice->getInvoiceByUntreadStatusPage($limit, $sql, 'desc', 'desc', 'untreadTime');
  6141. $this->data['receiptMemu'] = 'invoiceUntread';
  6142. $this->data['list'] = $list;
  6143. $this->render("/admin/invoiceUntreadAchieve", $this->data);
  6144. }
  6145. }
  6146. /**
  6147. * 公司应收款
  6148. */
  6149. function invoiceAggregateCompanyDetail()
  6150. {
  6151. $sidKey = $this->get_args('sidKey') ? $this->get_args('sidKey') : '';
  6152. $cidKey = $this->get_args('cidKey') ? $this->get_args('cidKey') : '';
  6153. $year = $this->get_args('year') ? $this->get_args('year') : 'ALL';
  6154. $month = $this->get_args('month') ? $this->get_args('month') : "";
  6155. $invoiceElement = $this->get_args('invoiceElement') ? $this->get_args('invoiceElement') : "";
  6156. $titleORno = $this->get_args('titleORno') ? $this->get_args('titleORno') : "";
  6157. Doo::loadClass('XDeode');
  6158. $XDeode = new XDeode(5);
  6159. Doo::loadModel('invoice');
  6160. $invoice = new invoice();
  6161. Doo::loadModel('staff');
  6162. $staff = new staff();
  6163. Doo::loadModel("invoiceCompanyManage");
  6164. $invoiceCompanyManage = new invoiceCompanyManage();
  6165. Doo::loadModel('L_category');
  6166. $category = new L_category();
  6167. $sid = '';
  6168. if (!empty($sidKey)) {
  6169. $sid = $XDeode->decode($sidKey);
  6170. }
  6171. $staffDetail = $staff->getStaffBySid($sid);
  6172. $cid = '';
  6173. if (!empty($cidKey)) {
  6174. $cid = $XDeode->decode($cidKey);
  6175. }
  6176. $imcStaff = $invoiceCompanyManage->getInvoiceCMByStaff($this->staff[0]['sid']);
  6177. $cidList = array();
  6178. foreach ($imcStaff as $key => $value) {
  6179. array_push($cidList, $value['cid']);
  6180. }
  6181. $categoryList = $category->getCategoryInCid(implode(',', $cidList));
  6182. $cidString = implode(',', $cidList);
  6183. if (empty($cid))
  6184. $staffList = $staff->getStaffInCid($cidString);
  6185. else
  6186. $staffList = $staff->getStaffByCidAll($cid); //
  6187. //$MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  6188. $page_size = 25;
  6189. $page = isset($this->params['page']) && is_numeric($this->params['page']) ? $this->params['page'] : 1;
  6190. $status = isset($this->params['status']) ? $this->params['status'] : 'All';
  6191. $con = ' status=2 and untreadStatus!=2 and invalid=0 and isDelete=0 and badDebt=0 ';
  6192. $statisticsCon = '';
  6193. if (!empty($year) && is_numeric($year))
  6194. $con .= ' and Year(printTime)=' . $year . '';
  6195. if (!empty($month) && is_numeric($month))
  6196. $con .= ' and Month(printTime)="' . $month . '" ';
  6197. if ($status == 'UNRECORD')
  6198. $con .= ' and printStatus=1 and untreadStatus=0';
  6199. elseif ($status == 'RECORD')
  6200. $con .= ' and printStatus=1 and untreadStatus=3';
  6201. elseif ($status == 'BOUNCED')
  6202. $con .= ' and untreadStatus=2';
  6203. elseif ($status == 'PARTRECORD')
  6204. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  6205. elseif ($status == 'All') {
  6206. $con .= ' and printStatus=1 and ( untreadStatus=0 or untreadStatus=3 )';
  6207. }
  6208. if (!empty($sid) && is_numeric($sid))
  6209. $con .= ' and sid=' . $sid;
  6210. if (!empty($cid) && is_numeric($cid))
  6211. $con .= ' and cid=' . $cid;
  6212. else
  6213. $con .= ' and cid in (' . $cidString . ')';
  6214. // 开票内容筛选
  6215. if (!empty($invoiceElement) && $invoiceElement != 'ALL') {
  6216. $con .= ' and invoiceElement="' . $invoiceElement . '"';
  6217. }
  6218. $get = "/" . $status . "?cidKey=" . $cidKey . "&sidKey=" . $sidKey . "&year=" . $year . "&month=" . $month
  6219. . "&invoiceElement=" . $invoiceElement . "&titleORno=" . urlencode($titleORno);
  6220. if (!empty($titleORno)) {
  6221. $con .= ' and ( invoiceTitle like "%' . $titleORno . '%" or invoiceCompany like "%' . $titleORno . '%" or invoiceNo like "%' . $titleORno . '%" )';
  6222. }
  6223. $pageinfo['page'] = array(
  6224. 'previous' => ''
  6225. );
  6226. $pageinfo = $this->get_page("CLD_invoice", $con, $page, $page_size, "invoiceAggregateCompanyDetail", $get, "");
  6227. $limit = $pageinfo['lower'] . ',' . $page_size;
  6228. // 应收款合计
  6229. $ics = $invoice->getInvoiceCompanyStatistics($con);
  6230. //,'desc','desc','printTime'
  6231. $list = $invoice->getInvoiceByUntreadStatusPage($limit, $con);
  6232. $totalPrice = array('invoicePrice' => 0.00, 'receivePrice' => 0.00, 'receivablesPrice' => 0.00);
  6233. foreach ($list as $key => $value) {
  6234. $totalPrice['invoicePrice'] = bcadd($totalPrice['invoicePrice'], $value['invoicePrice'], 2);
  6235. if ($value['sumPrice'] != 0) {
  6236. $totalPrice['receivePrice'] = bcadd($totalPrice['receivePrice'], $value['sumPrice'], 2);
  6237. }
  6238. if ($value['diffPrice'] != 0) {
  6239. $totalPrice['receivablesPrice'] = bcadd($totalPrice['receivablesPrice'], $value['diffPrice'], 2);
  6240. }
  6241. }
  6242. $this->data['totalPrice'] = $totalPrice;
  6243. $monthHtml = "";
  6244. if ($year != "ALL") {
  6245. for ($i = 1; $i <= 12; $i++) {
  6246. if ($i == $month)
  6247. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  6248. else
  6249. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  6250. }
  6251. }
  6252. $this->data['monthHtml'] = $monthHtml;
  6253. $this->data['year'] = $year;
  6254. $this->data['month'] = $month;
  6255. $this->data['ics'] = $ics;
  6256. $this->data['cidKey'] = $cidKey;
  6257. $this->data['sid'] = $sid;
  6258. $this->data['staffDetail'] = $staffDetail;
  6259. $this->data['staffList'] = $staffList;
  6260. $this->data['titleORnoEn'] = $titleORno;
  6261. $this->data['titleORno'] = urlencode($titleORno);
  6262. $this->data['invoiceDetail'] = array(
  6263. 'invoiceElement' => $invoiceElement
  6264. );
  6265. $this->data['page'] = $pageinfo;
  6266. $this->data['get'] = $get;
  6267. $this->data['list'] = $list;
  6268. $this->data['status'] = $status;
  6269. $this->data['categoryList'] = $categoryList;
  6270. $this->data['memu'] = "invoice";
  6271. $this->data['staff'] = $this->staff;
  6272. $this->data['receiptMemu'] = 'invoiceAggregateCompanyDetail';
  6273. $this->render("/admin/invoiceAggregateCompanyDetail", $this->data);
  6274. }
  6275. /**
  6276. * 获取一条收款信息
  6277. */
  6278. function ajaxGetInvoiceReceivables()
  6279. {
  6280. $irid = $this->get_args('key') ? $this->get_args('key') : "";
  6281. Doo::loadModel('invoiceReceivables');
  6282. $invoiceReceivables = new invoiceReceivables();
  6283. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid($irid);
  6284. echo json_encode(array(
  6285. 'status' => 1,
  6286. 'detail' => $detail
  6287. ));
  6288. }
  6289. /**
  6290. * 异步获取办事处用户
  6291. */
  6292. function ajaxGetStaffByCategory()
  6293. {
  6294. $cid = $this->get_args('cid') ? $this->get_args('cid') : "";
  6295. Doo::loadModel('staff');
  6296. $staff = new staff();
  6297. if ($cid == "PUBLIC") {
  6298. echo json_encode(array(
  6299. 'status' => 1,
  6300. 'html' => '<option value="PUBLIC">办事处待认领款项</option>'
  6301. ));
  6302. die();
  6303. }
  6304. if (!is_numeric($cid)) {
  6305. echo json_encode(array(
  6306. 'status' => 0,
  6307. 'msg' => 'illegal request'
  6308. ));
  6309. die();
  6310. }
  6311. $staffList = $staff->getStaffByCid($cid);
  6312. $html = '<option value="PUBLIC">办事处待认领款项</option>';
  6313. foreach ($staffList as $key => $value) {
  6314. $html .= '<option value="' . $value['sid'] . '-' . $value['username'] . '">' . $value['category'] . '-' . $value['username'] . '</option>';
  6315. }
  6316. echo json_encode(array(
  6317. 'status' => 1,
  6318. 'html' => $html
  6319. ));
  6320. }
  6321. /**
  6322. * 异步获取一条发票的邮寄信息
  6323. */
  6324. function ajaxGetInvoicePostDetail()
  6325. {
  6326. $iid = $this->get_args('iidKey') ? $this->get_args('iidKey') : "";
  6327. Doo::loadModel('invoice');
  6328. $invoice = new invoice();
  6329. $iid = $invoice->authcode($iid);
  6330. Doo::loadModel('express');
  6331. $express = new express();
  6332. $expressList = $express->getExpressByAll();
  6333. if (!is_numeric($iid)) {
  6334. echo json_encode(array(
  6335. 'status' => 0,
  6336. 'msg' => 'illegal request'
  6337. ));
  6338. die();
  6339. }
  6340. $select = "iid,recipients,recipientsPhone,recipientsAddress,mailItems,expressCompany,expressNumber,actualItems";
  6341. $invoiceDetail = $invoice->getInvoiceByIid($iid, $select);
  6342. $html = "";
  6343. foreach ($expressList as $key => $value) {
  6344. if ($value['company'] == $invoiceDetail['expressCompany'])
  6345. $html .= '<option selected value="' . $value['company'] . ':' . $value['com'] . '">' . $value['company'] . '</option>';
  6346. else
  6347. $html .= '<option value="' . $value['company'] . ':' . $value['com'] . '">' . $value['company'] . '</option>';
  6348. }
  6349. $invoiceDetail['eaHtml'] = $html;
  6350. echo json_encode(array(
  6351. 'status' => 1,
  6352. 'invoiceDetail' => $invoiceDetail
  6353. ));
  6354. }
  6355. /**
  6356. *
  6357. * @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 ) ); }
  6358. */
  6359. /**
  6360. *
  6361. * @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 ) ); }
  6362. */
  6363. /**
  6364. * 我的收款中 选择哪个发票入账,进行金额判断
  6365. */
  6366. function ajaxCompareInvoicePrice()
  6367. {
  6368. $claimKey = $this->get_args('claimKey') ? $this->get_args('claimKey') : "";
  6369. $invoiceKey = $this->get_args('invoiceKey') ? $this->get_args('invoiceKey') : "";
  6370. Doo::loadModel('invoice');
  6371. $invoice = new invoice();
  6372. Doo::loadModel('invoiceReceivables');
  6373. $invoiceReceivables = new invoiceReceivables();
  6374. $detail = $invoice->getInvoiceByIid($invoiceKey);
  6375. $keyList = explode(';', $claimKey);
  6376. $receivablesPrice = 0;
  6377. foreach ($keyList as $key => $value) {
  6378. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid($value);
  6379. $receivablesPrice += $detailM['receivablesPrice'];
  6380. }
  6381. if ($receivablesPrice > $detail['invoicePrice']) {
  6382. $price = $receivablesPrice - $detail['invoicePrice'];
  6383. echo json_encode(array(
  6384. 'status' => 1,
  6385. 'price' => $price
  6386. ));
  6387. } else
  6388. echo json_encode(array(
  6389. 'status' => 2
  6390. ));
  6391. }
  6392. /**
  6393. * 获得打印发票
  6394. */
  6395. function ajaxGetInvoiceInfoByPrint()
  6396. {
  6397. $serial = $this->get_args('serial') ? $this->get_args('serial') : "";
  6398. if (empty($serial)) {
  6399. echo json_encode(array(
  6400. 'status' => 2,
  6401. 'msg' => 'illegal request'
  6402. ));
  6403. die();
  6404. }
  6405. Doo::loadModel('invoice');
  6406. $invoice = new invoice();
  6407. Doo::loadModel('invoiceOperationLog');
  6408. $invoiceOperationLog = new invoiceOperationLog();
  6409. $detail = $invoice->getInvoiceByIsid($serial, $this->staff[0]['sid']);
  6410. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid($detail['iid']);
  6411. Doo::loadModel('invoicePaper');
  6412. $invoicePaper = new invoicePaper();
  6413. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType($detail['invoiceType']);
  6414. if (empty($detail))
  6415. $html = '';
  6416. else {
  6417. $html = '
  6418. <form action="/invoicePrintDo" method="post" name="invoicePrint" class="nice-validator n-yellow" onSubmit="return checkPrintForm()" novalidate="novalidate">
  6419. <input type="hidden" name="invoiceKey" value="' . $detail['iidKeyXD'] . '">
  6420. <input type="hidden" name="invoicePrintType" value="invoicePrintType">
  6421. <div class="modal-dialog modal-lg">
  6422. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  6423. <div class="modal-body saeaList">
  6424. <table class="table table-bordered table-condensed"><tbody>
  6425. <tr>
  6426. <th class="taC" width="150">开票流水号</th><td>' . $detail['invoiceSerial'] . '</td>
  6427. <th class="taC" width="150">提交时间</th><td>' . $detail['date'] . '</td>
  6428. </tr>
  6429. <tr>
  6430. <th class="taC" width="150">所在办事处</th><td>' . $detail['categoryName'] . '(' . $detail['userName'] . ')</td>
  6431. <th class="taC" width="150">开票内容</th><td>' . $detail['invoiceElement'] . '</td>
  6432. </tr>
  6433. <tr>
  6434. <th class="taC">发票备注</th><td colspan="3">' . $detail['remark'] . '
  6435. </td>
  6436. </tr>
  6437. <tr>
  6438. <th class="taC" width="150">数量</th><td><b>' . $detail['invoiceQuantity'] . '</b></td>
  6439. <th class="taC">单价</th><td><b>¥' . $detail['invoiceUnitPrice'] . '</b></td>
  6440. </tr>
  6441. <tr>
  6442. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail['invoicePrice'] . '</b></td>
  6443. </tr></tbody></table>';
  6444. if ($detail['invoiceType'] == 0)
  6445. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6446. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  6447. <th class="taC" width="150">发票抬头</th><td >' . $detail['invoiceTitle'] . '</td>
  6448. <th class="taC" width="150">纳税人识别码</th><td>' . $detail['TIN'] . '</td>
  6449. </tr>';
  6450. else
  6451. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6452. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  6453. <th class="taC" width="150">单位名称</th><td>' . $detail['invoiceCompany'] . '</td>
  6454. <th class="taC" width="150">纳税人识别码</th><td>' . $detail['TIN'] . '</td></tr>
  6455. ';
  6456. $html .= '<tr>
  6457. <th class="taC">注册地址</th><td>' . $detail['address'] . '</td>
  6458. <th class="taC">注册电话</th><td>' . $detail['phone'] . '</td>
  6459. </tr>
  6460. <tr>
  6461. <th class="taC">开户银行</th><td>' . $detail['bank'] . '</td>
  6462. <th class="taC">银行账号</th><td>' . $detail['bankAccount'] . '</td>
  6463. </tr></tbody></table>';
  6464. if ($detail['doPost'] == 1)
  6465. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  6466. <th class="taC" width="150">收件人</th><td>' . $detail['recipients'] . '</td>
  6467. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail['recipientsPhone'] . '</td>
  6468. </tr><tr>
  6469. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail['recipientsAddress'] . '</td>
  6470. </tr><tr>
  6471. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail['mailItems'] . '</td>
  6472. </tr></tbody></table>';
  6473. if (!empty($invoiceOperationLogList)) {
  6474. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th><th class="taC">发票打印</th></tr><tr><td>';
  6475. foreach ($invoiceOperationLogList as $key => $value) {
  6476. if ($value['status'] == 1 || $value['status'] == 2 || $value['status'] == 3 || $value['status'] == 4) {
  6477. $html .= '<blockquote><p><span class="colGray">' . $value['date'] . '</span>&nbsp;
  6478. ' . $value['category'] . '-' . $value['username'] . '&nbsp;';
  6479. if ($value['status'] == 2) {
  6480. $html .= '<span class="colGreen">同意</span>';
  6481. } elseif ($value['status'] == 3) {
  6482. $html .= '<span class="colOrange">退回</span>';
  6483. } elseif ($value['status'] == 5) {
  6484. $html .= '<span class="colGreen">打印</span>';
  6485. } elseif ($value['status'] == 4) {
  6486. $html .= '<span class="colRed">终止</span>';
  6487. }
  6488. $html .= $value['operation'] . '</p></blockquote>';
  6489. }
  6490. }
  6491. $html .= '</td>
  6492. <td><span class="colRed">*</span>
  6493. <select name="invoiceNo" id="invoiceNo" style="width:97%">';
  6494. foreach ($invoicePaperList as $key => $value) {
  6495. $html .= '<option value="' . $value['ipidKey'] . '">No.' . $value['invoiceNo'] . '</option>';
  6496. }
  6497. $html .= '</select>
  6498. <span class="red" id="p-msg"></span>
  6499. </td>
  6500. </tr></tbody></table>';
  6501. }
  6502. $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>
  6503. </div></div></form>
  6504. <link rel=stylesheet href="' . WEB_SITE_GLOBAL . 'css/jquery.validator.css">
  6505. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/jquery.validator.min.js"></script>
  6506. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/zh-CN.js"></script>
  6507. <script src="' . WEB_SITE_GLOBAL . 'js/invoice.validator.js"></script>
  6508. ';
  6509. }
  6510. echo json_encode(array(
  6511. 'status' => 1,
  6512. 'html' => $html
  6513. ));
  6514. die();
  6515. }
  6516. /**
  6517. * @ 获得与我有关收款数据 --需求变更 废弃 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 ) ); }
  6518. */
  6519. function ajaxGetInvoiceInfoByType()
  6520. {
  6521. $type = $this->get_args('type') ? $this->get_args('type') : "";
  6522. $serial = $this->get_args('serial') ? $this->get_args('serial') : "";
  6523. $loss = $this->get_args('loss') ? $this->get_args('loss') : false;
  6524. // include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  6525. if (empty($serial)) {
  6526. echo json_encode(array(
  6527. 'status' => 2,
  6528. 'msg' => 'illegal request'
  6529. ));
  6530. die();
  6531. }
  6532. if ($type == 'INVOICE') {
  6533. Doo::loadModel('invoice');
  6534. $invoice = new invoice();
  6535. Doo::loadModel('invoiceOperationLog');
  6536. $invoiceOperationLog = new invoiceOperationLog();
  6537. $detail = $invoice->getInvoiceByIsid($serial, $this->staff[0]['sid']);
  6538. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid($detail['iid']);
  6539. Doo::loadModel('invoicePaper');
  6540. $invoicePaper = new invoicePaper();
  6541. $invoicePaperDetail = $invoicePaper->getByIid($detail['iid']);
  6542. $invoiceCode = "";
  6543. if (!empty($invoicePaperDetail['invoiceCode'])) {
  6544. $invoiceCode = $invoicePaperDetail['invoiceCode'];
  6545. }
  6546. if (empty($detail))
  6547. $html = '';
  6548. else {
  6549. $html = '
  6550. <div class="modal-dialog modal-lg">
  6551. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  6552. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  6553. <tr>
  6554. <th class="taC" width="150">开票流水号</th><td>' . $detail['invoiceSerial'] . '</td>
  6555. <th class="taC" width="150">提交时间</th><td>' . $detail['date'] . '</td>
  6556. </tr>
  6557. <tr>
  6558. <th class="taC" width="150">所在办事处</th><td>' . $detail['categoryName'] . '(' . $detail['userName'] . ')</td>
  6559. <th class="taC" width="150">开票内容</th><td>' . $detail['invoiceElement'] . '</td>
  6560. </tr>
  6561. <tr>
  6562. <th class="taC">发票备注</th><td colspan="3">' . $detail['remark'] . '
  6563. </td>
  6564. </tr>
  6565. <tr>
  6566. <th class="taC" width="150">数量</th><td><b>' . $detail['invoiceQuantity'] . '</b></td>
  6567. <th class="taC">单价</th><td><b>¥' . $detail['invoiceUnitPrice'] . '</b></td>
  6568. </tr>
  6569. <tr>
  6570. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail['invoicePrice'] . '</b></td>
  6571. </tr>';
  6572. if ($detail['settlementType'] == 1) {
  6573. $html .= '<tr>
  6574. <th class="taC" width="150">结算方式</th><td colspan="3">培训班(<a href="/invoiceTrainingDetail/' . $detail['invoiceTraining']['trainingKey'] . '.html" target="_blank">' . $detail['invoiceTraining']['trainName'] . '</a>)</td>
  6575. </tr>';
  6576. } else {
  6577. $html .= '<tr>
  6578. <th class="taC" width="150">结算方式</th><td colspan="3">软件销售</td>
  6579. </tr>';
  6580. }
  6581. $html .= ' </tbody></table>';
  6582. if ($detail['invoiceType'] == 0) {
  6583. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6584. <tr><th colspan="4" class="taC">增值税普通发票';
  6585. if ($detail['invoiceForm'] == 1) {
  6586. $html .= '( <span class="colRed">电子发票</span> )';
  6587. }
  6588. $html .= '</th></tr><tr>
  6589. <th class="taC" width="150">发票抬头</th><td >' . $detail['invoiceTitle'] . '</td>
  6590. <th class="taC" width="150">纳税人识别码</th><td>' . $detail['TIN'] . '</td>
  6591. </tr>';
  6592. } else {
  6593. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6594. <tr><th colspan="4" class="taC">增值税专用发票';
  6595. if ($detail['invoiceForm'] == 1) {
  6596. $html .= '( <span class="colRed">电子发票</span> )';
  6597. }
  6598. $html .= '</th></tr><tr>
  6599. <th class="taC" width="150">单位名称</th><td>' . $detail['invoiceCompany'] . '</td>
  6600. <th class="taC" width="150">纳税人识别码</th><td>' . $detail['TIN'] . '</td></tr>
  6601. ';
  6602. }
  6603. $html .= '<tr>
  6604. <th class="taC">注册地址</th><td>' . $detail['address'] . '</td>
  6605. <th class="taC">注册电话</th><td>' . $detail['phone'] . '</td>
  6606. </tr>
  6607. <tr>
  6608. <th class="taC">开户银行</th><td>' . $detail['bank'] . '</td>
  6609. <th class="taC">银行账号</th><td>' . $detail['bankAccount'] . '</td>
  6610. </tr>
  6611. <tr>
  6612. <th class="taC">发票号</th><td>' . $detail['invoiceNo'] . '</td>
  6613. <th class="taC">发票代码</th><td>' . $invoiceCode . '</td>
  6614. </tr>
  6615. </tbody></table>';
  6616. if ($detail['doPost'] == 1) {
  6617. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  6618. <th class="taC" width="150">收件人</th><td>' . $detail['recipients'] . '</td>
  6619. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail['recipientsPhone'] . '</td>
  6620. </tr><tr>
  6621. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail['recipientsAddress'] . '</td>
  6622. </tr><tr>
  6623. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail['mailItems'] . '</td>
  6624. </tr>
  6625. ';
  6626. if ($detail['expressCom'] == 'SF')
  6627. $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>';
  6628. else
  6629. $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>';
  6630. $html .= '</tbody></table>';
  6631. }
  6632. if ($detail['invoiceForm'] == 1) {
  6633. $html .= '<table class="table table-bordered table-condensed">
  6634. <tbody><tr><th colspan="4" class="taC">电子发票发送方式</th></tr>
  6635. <tr>
  6636. <th class="taC" width="150">收件人手机</th><td>' . $detail['electronicPhone'] . '</td>
  6637. <th class="taC" width="150">收件人邮箱</th><td>' . $detail['electronicEmail'] . '</td>
  6638. </tr></tbody></table>';
  6639. }
  6640. if (!empty($invoiceOperationLogList)) {
  6641. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  6642. foreach ($invoiceOperationLogList as $key => $value) {
  6643. if ($value['status'] == 1 || $value['status'] == 2 || $value['status'] == 3 || $value['status'] == 4) {
  6644. $html .= '<blockquote><p><span class="colGray">' . $value['date'] . '</span>&nbsp;
  6645. ' . $value['category'] . '-' . $value['username'] . '&nbsp;';
  6646. if ($value['status'] == 2) {
  6647. $html .= '<span class="colGreen">同意</span>';
  6648. } elseif ($value['status'] == 3) {
  6649. $html .= '<span class="colOrange">退回</span>';
  6650. } elseif ($value['status'] == 5) {
  6651. $html .= '<span class="colGreen">打印</span>';
  6652. } elseif ($value['status'] == 4) {
  6653. $html .= '<span class="colRed">终止</span>';
  6654. }
  6655. $html .= $value['operation'] . '</p></blockquote>';
  6656. }
  6657. }
  6658. $html .= '</td></tr></tbody></table>';
  6659. }
  6660. $html .= '</div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  6661. }
  6662. echo json_encode(array(
  6663. 'status' => 1,
  6664. 'html' => $html
  6665. ));
  6666. die();
  6667. } elseif ($type == 'RECEIVABLES') {
  6668. Doo::loadModel('invoiceReceivables');
  6669. $invoiceReceivables = new invoiceReceivables();
  6670. Doo::loadModel('invoiceRefund');
  6671. $invoiceRefund = new invoiceRefund();
  6672. $detail = $invoiceReceivables->getInvoiceReceivablesByIrsid($serial);
  6673. $ireList = $invoiceRefund->getInvoiceRefundIrid($detail['irid']);
  6674. if (empty($detail))
  6675. $html = '';
  6676. else {
  6677. $html = '<div class="modal-dialog modal-lg"><div class="modal-content"><div class="modal-header"><h3>收款单详情</h3></div><div class="modal-body saeaList">
  6678. <table class="table table-bordered table-condensed">
  6679. <tbody><tr>
  6680. <th class="taC">收款流水号</th><td>' . $detail['receivablesSerial'] . '</td>
  6681. <th class="taC">录入收款</th><td>' . $detail['inputStaff'] . ' ' . $detail['date'] . '</td>
  6682. </tr><tr>
  6683. <th class="taC">收款金额</th><td><b>¥' . $detail['receivablesPrice'] . '</b></td>
  6684. <th class="taC">收款信息</th><td>' . $detail['receivablesMessage'] . '</td>
  6685. </tr>
  6686. <tr>
  6687. <th class="taC">收款银行</th><td>' . $detail['receivablesBank'] . '</td>
  6688. <th class="taC">银行到账</th><td>' . $detail['receivablesDate'] . '</td>
  6689. </tr>
  6690. <tr>
  6691. <th class="taC">认领收款</th><td colspan="3">' . $detail['inputStaff'] . ' 转入 ' . $detail['username'] . ' ' . $detail['confirmTime'] . '</td>
  6692. </tr>
  6693. </tbody></table>';
  6694. if (!empty($ireList)) {
  6695. $html .= '
  6696. <table class="table table-bordered table-condensed"><tbody><tr><th class="taC" colspan="5">退款记录</th></tr>
  6697. <tr>
  6698. <th class="taC">退款单位名称</th>
  6699. <th class="taC">退款的账号</th>
  6700. <th class="taC">退款金额</th>
  6701. <th class="taC">退款</th>
  6702. <th class="taC">备注</th>
  6703. </tr>
  6704. ';
  6705. foreach ($ireList as $key => $value) {
  6706. $refundLogList = explode("<br/>", $value['refundLog']);
  6707. $html .= '<tr>
  6708. <td>' . $value['refundCompany'] . '</td>
  6709. <td>' . $value['refundNumber'] . '</td>
  6710. <td><b class="colRed">¥' . $value['refundPrice'] . '</b></td>
  6711. <td>' . $refundLogList[0] . $refundLogList[2] . '</td>
  6712. <td>' . $value['refundRemarks'] . '</td>
  6713. </tr>
  6714. ';
  6715. }
  6716. }
  6717. $html .= '</tbody></table></div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  6718. }
  6719. echo json_encode(array(
  6720. 'status' => 1,
  6721. 'html' => $html
  6722. ));
  6723. die();
  6724. } elseif ($type == 'IRTC') {
  6725. Doo::loadModel('invoice');
  6726. $invoice = new invoice();
  6727. Doo::loadModel('invoiceOperationLog');
  6728. $invoiceOperationLog = new invoiceOperationLog();
  6729. // Doo::loadModel ( 'invoiceReceivables' );
  6730. // $invoiceReceivables = new invoiceReceivables ();
  6731. $detail = $invoice->getInvoiceByIsid($serial, $this->staff[0]['sid']);
  6732. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid($detail['iid']);
  6733. if (empty($detail))
  6734. $html = '';
  6735. else {
  6736. $receivablesPriceedHtml = '';
  6737. $receivablesPrice = $detail['invoicePrice'];
  6738. if (!empty($detail['irid'])) {
  6739. // $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $detail ['irid'] );
  6740. // if (empty ( $irList ))
  6741. // $irList [0] ['sumPrice'] = 0;
  6742. // $balance = $detail ['invoicePrice'] - $irList [0] ['sumPrice'];
  6743. $enteredPrice = $detail['invoicePrice'] - $detail['invoiceBalance'];
  6744. $receivablesPriceedHtml = '<table class="table table-bordered table-condensed"><tbody><tr>
  6745. <th class="taC">已入账金额</th><td><b class="colGreen" style="font-size:18px">¥' . $enteredPrice . '</b></td>
  6746. <th class="taC">剩余入账金额</th><td><b class="colRed" style="font-size:18px">¥' . $detail['invoiceBalance'] . '</b></td>
  6747. </tr></tbody></table>';
  6748. $receivablesPrice = $detail['invoiceBalance'];
  6749. }
  6750. if ($loss)
  6751. $detail['invoicePrice'] = -$detail['invoicePrice'];
  6752. $html = $receivablesPriceedHtml . '
  6753. <table class="table table-bordered table-condensed"><tbody>
  6754. <tr>
  6755. <th class="taC" width="150">开票流水号</th><td>' . $detail['invoiceSerial'] . '</td>
  6756. <th class="taC" width="150">提交时间</th><td>' . $detail['date'] . '</td>
  6757. </tr>
  6758. <tr>
  6759. <th class="taC" width="150">所在办事处</th><td>' . $detail['categoryName'] . '(' . $detail['userName'] . ')</td>
  6760. <th class="taC" width="150">开票内容</th><td>' . $detail['invoiceElement'] . '</td>
  6761. </tr>
  6762. <tr>
  6763. <th class="taC" width="150">发票备注</th><td colspan="3">' . $detail['remark'] . '</td>
  6764. </tr>
  6765. <tr>
  6766. <th class="taC" width="150">数量</th><td><b>' . $detail['invoiceQuantity'] . '</b></td>
  6767. <th class="taC">单价</th><td><b>¥' . $detail['invoiceUnitPrice'] . '</b></td>
  6768. </tr>
  6769. <tr>
  6770. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail['invoicePrice'] . '</b></td>
  6771. </tr>';
  6772. if ($detail['settlementType'] == 1) {
  6773. $html .= '<tr>
  6774. <th class="taC" width="150">结算方式</th><td colspan="3">培训班(<a href="/invoiceTrainingDetail/' . $detail['invoiceTraining']['trainingKey'] . '.html" target="_blank">' . $detail['invoiceTraining']['trainName'] . '</a>)</td>
  6775. </tr>';
  6776. } else {
  6777. $html .= '<tr>
  6778. <th class="taC" width="150">结算方式</th><td colspan="3">软件销售</td>
  6779. </tr>';
  6780. }
  6781. $html .= '</tbody></table>';
  6782. if ($detail['invoiceType'] == 0) {
  6783. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6784. <tr><th colspan="4" class="taC">增值税普通发票';
  6785. if ($detail['invoiceForm'] == 1) {
  6786. $html .= '( <span class="colRed">电子发票</span> )';
  6787. }
  6788. $html .= '</th></tr><tr>
  6789. <th class="taC" width="150">发票抬头</th><td >' . $detail['invoiceTitle'] . '</td>
  6790. <th class="taC" width="150">纳税人识别码</th><td>' . $detail['TIN'] . '</td>
  6791. </tr>';
  6792. $receivablesMessage = $detail['invoiceTitle'];
  6793. } else {
  6794. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6795. <tr><th colspan="4" class="taC">增值税专用发票';
  6796. if ($detail['invoiceForm'] == 1) {
  6797. $html .= '( <span class="colRed">电子发票</span> )';
  6798. }
  6799. $html .= '</th></tr><tr>
  6800. <th class="taC" width="150">单位名称</th><td>' . $detail['invoiceCompany'] . '</td>
  6801. <th class="taC" width="150">纳税人识别码</th><td>' . $detail['TIN'] . '</td></tr>
  6802. ';
  6803. $receivablesMessage = $detail['invoiceCompany'];
  6804. }
  6805. $html .= '<tr>
  6806. <th class="taC">注册地址</th><td>' . $detail['address'] . '</td>
  6807. <th class="taC">注册电话</th><td>' . $detail['phone'] . '</td>
  6808. </tr>
  6809. <tr>
  6810. <th class="taC">开户银行</th><td>' . $detail['bankAccount'] . '</td>
  6811. <th class="taC">银行账号</th><td>' . $detail['bank'] . '</td>
  6812. </tr></tbody></table>';
  6813. if ($detail['doPost'] == 1)
  6814. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  6815. <th class="taC" width="150">收件人</th><td>' . $detail['recipients'] . '</td>
  6816. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail['recipientsPhone'] . '</td>
  6817. </tr><tr>
  6818. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail['recipientsAddress'] . '</td>
  6819. </tr><tr>
  6820. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail['mailItems'] . '</td>
  6821. </tr></tbody></table>';
  6822. if (!empty($invoiceOperationLogList)) {
  6823. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  6824. foreach ($invoiceOperationLogList as $key => $value) {
  6825. if ($value['status'] == 1 || $value['status'] == 2 || $value['status'] == 3 || $value['status'] == 4) {
  6826. $html .= '<blockquote><p><span class="colGray">' . $value['date'] . '</span>&nbsp;
  6827. ' . $value['category'] . '-' . $value['username'] . '&nbsp;';
  6828. if ($value['status'] == 2) {
  6829. $html .= '<span class="colGreen">同意</span>';
  6830. } elseif ($value['status'] == 3) {
  6831. $html .= '<span class="colOrange">退回</span>';
  6832. } elseif ($value['status'] == 5) {
  6833. $html .= '<span class="colGreen">打印</span>';
  6834. }
  6835. $html .= $value['operation'] . '</p></blockquote>';
  6836. }
  6837. }
  6838. $html .= '</td></tr></tbody></table>';
  6839. }
  6840. }
  6841. echo json_encode(array(
  6842. 'status' => 1,
  6843. 'html' => $html,
  6844. 'receivablesPrice' => $receivablesPrice,
  6845. 'receivablesMessage' => $receivablesMessage,
  6846. 'receivablesDate' => date("Y-m-d"),
  6847. 'iidKey' => $serial
  6848. ));
  6849. die();
  6850. }
  6851. }
  6852. function ajaxGetInvoiceReceivablesByStaff()
  6853. {
  6854. $postData = $this->get_args('postData') ? $this->get_args('postData') : "";
  6855. if (empty($postData)) {
  6856. echo json_encode(array(
  6857. 'status' => 2,
  6858. 'msg' => 'illegal request'
  6859. ));
  6860. die();
  6861. }
  6862. Doo::loadModel('invoiceReceivables');
  6863. $invoiceReceivables = new invoiceReceivables();
  6864. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid($postData);
  6865. if (empty($detail)) {
  6866. echo json_encode(array(
  6867. 'status' => 2,
  6868. 'msg' => 'illegal request'
  6869. ));
  6870. die();
  6871. }
  6872. Doo::loadModel('L_category');
  6873. $lCategory = new L_category();
  6874. Doo::loadModel('staff');
  6875. $staff = new staff();
  6876. $staffList = $staff->getStaffByCid($detail['cid']);
  6877. $category = $lCategory->getCategory();
  6878. $categoryHtml = '<option post-data="PUBLIC" value="PUBLIC" >公共待认领款项</option>';
  6879. $staffHtml = '<option value="PUBLIC">办事处待认领款项</option>';
  6880. foreach ($category as $key => $value) {
  6881. $categoryHtml .= '<option post-data="' . $value['cid'] . '" value="' . $value['cid'] . ':' . $value['title'] . '" >' . $value['title'] . '</option>';
  6882. if ($value['cid'] == $detail['cid'])
  6883. $categoryHtml .= '<option selected post-data="' . $value['cid'] . '" value="' . $value['cid'] . ':' . $value['title'] . '" >' . $value['title'] . '</option>';
  6884. }
  6885. foreach ($staffList as $key => $value) {
  6886. $staffHtml .= '<option value="' . $value['sid'] . '-' . $value['username'] . '">' . $value['category'] . '-' . $value['username'] . '</option>';
  6887. if ($value['sid'] == $detail['sid'])
  6888. $staffHtml .= '<option selected value="' . $value['sid'] . '-' . $value['username'] . '">' . $value['category'] . '-' . $value['username'] . '</option>';
  6889. }
  6890. $rbankHtml = '<option value="广发银行珠海分行柠溪支行">广发银行珠海分行柠溪支行</option>';
  6891. echo json_encode(array(
  6892. 'status' => 1,
  6893. 'categoryHtml' => $categoryHtml,
  6894. 'staffHtml' => $staffHtml,
  6895. 'rbankHtml' => $rbankHtml,
  6896. 'detail' => $detail
  6897. ));
  6898. }
  6899. function ajaxGetInvoiceReceivablesByIrid()
  6900. {
  6901. $irid = $this->get_args('irid') ? $this->get_args('irid') : "";
  6902. if (empty($irid)) {
  6903. echo json_encode(array(
  6904. 'status' => 2,
  6905. 'msg' => 'illegal request'
  6906. ));
  6907. die();
  6908. }
  6909. Doo::loadModel('invoiceReceivables');
  6910. $invoiceReceivables = new invoiceReceivables();
  6911. Doo::loadModel('invoice');
  6912. $invoice = new invoice();
  6913. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid($irid); // 入账完成 待定 and postStatus=1
  6914. $flag = true;
  6915. $invoiceDetail = $invoice->getInvoiceByTitle($detail['recepitTitleMark'], 'EXACTLY', " and status=2 and printStatus=1 and untreadStatus=0 ", $flag); //
  6916. $bakDetail = array();
  6917. if ($flag === false) {
  6918. array_push($bakDetail, $invoiceDetail);
  6919. $invoiceDetail = $bakDetail;
  6920. }
  6921. $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>
  6922. <tr>
  6923. <td><b>¥' . $detail['receivablesPrice'] . '</b></td>
  6924. <td>' . $detail['receivablesMessage'] . '</td>
  6925. <td>' . $detail['receivablesBank'] . '<br>' . $detail['receivablesDate'] . '</td>
  6926. <td>' . $detail['title'] . '-' . $detail['username'] . '<br>' . $detail['confirmTime'] . '</td>
  6927. <td>' . $detail['recepitTitleMark'] . '</td>
  6928. </tr></tbody></table>';
  6929. $isInvoice = false;
  6930. $invoiceHtml = '';
  6931. if (empty($invoiceDetail)) {
  6932. $isInvoice = true;
  6933. } else {
  6934. $invoiceHtml = '<table class="table table-bordered table-condensed">
  6935. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody>';
  6936. foreach ($invoiceDetail as $key => $value) {
  6937. $invoiceHtml .= '<tr>';
  6938. if (!empty($value['invoiceType'])) {
  6939. $invoiceHtml .= '<td>' . $value['invoiceCompany'] . '</td>';
  6940. } else {
  6941. $invoiceHtml .= '<td>' . $value['invoiceTitle'] . '</td>';
  6942. }
  6943. if (!empty($value['invoiceType'])) {
  6944. $invoiceHtml .= '<td>' . $value['invoicePrice'] . '专</td>';
  6945. } else {
  6946. $invoiceHtml .= '<td>' . $value['invoicePrice'] . '</td>';
  6947. }
  6948. $invoiceHtml .= '
  6949. <td>' . $value['categoryName'] . $value['userName'] . ' ' . $value['date'] . '</td>
  6950. <td>' . $value['printer'] . ' ' . $value['printTime'] . '</td>
  6951. <td>' . $value['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir" data-ikey="' . $value['iidKey'] . '" href="javascript:void(0)">入账</a></td>
  6952. </tr>
  6953. ';
  6954. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString($value['irid']);
  6955. if (empty($irList))
  6956. $irList[0]['sumPrice'] = 0;
  6957. $balance = $value['invoicePrice'] - $irList[0]['sumPrice'];
  6958. $priceString = '';
  6959. if ($balance < $detail['receivablesPrice']) {
  6960. $priceString = '收款金额超过开票金额,';
  6961. }
  6962. if ($balance > $detail['receivablesPrice']) {
  6963. $priceString = '收款金额低于开票金额,';
  6964. }
  6965. }
  6966. $invoiceHtml .= '
  6967. <script>
  6968. $(\'a[bind-receivables^="ir"]\').click(function() {
  6969. var data = $(this).attr("data-ikey");
  6970. $("input[name=\'invoiceKey\']").val(data);
  6971. var invoiceKey=data;
  6972. if(invoiceKey==""){
  6973. alert("入账错误,请重新刷新页面");
  6974. return false;
  6975. }
  6976. if(window.confirm("' . $priceString . '确定入账吗?")){
  6977. $("#IBR").submit();
  6978. }else{
  6979. return false;
  6980. }
  6981. });
  6982. </script>
  6983. ';
  6984. $invoiceHtml .= '</tbody></table>';
  6985. }
  6986. echo json_encode(array(
  6987. 'status' => 1,
  6988. 'irkey' => $detail['iridEn'],
  6989. 'receivablesHtml' => $receivablesHtml,
  6990. 'isInvoice' => $isInvoice,
  6991. 'invoiceHtml' => $invoiceHtml
  6992. ));
  6993. }
  6994. function ajaxGetInvoiceReceivablesByTitle()
  6995. {
  6996. $title = $this->get_args('title') ? $this->get_args('title') : "";
  6997. if (empty($title)) {
  6998. echo json_encode(array(
  6999. 'status' => 2,
  7000. 'msg' => 'illegal request'
  7001. ));
  7002. die();
  7003. }
  7004. Doo::loadModel('invoice');
  7005. $invoice = new invoice();
  7006. $invoiceDetail = $invoice->getInvoiceByTitle($title, 'FUZZY', " and status=2 and printStatus=1 and untreadStatus=0 and (irid='' or irid is null) ", true);
  7007. $invoiceHtml = '';
  7008. if (!empty($invoiceDetail)) {
  7009. $invoiceHtml = '<table class="table table-bordered table-condensed">
  7010. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody><tr>';
  7011. foreach ($invoiceDetail as $key => $value) {
  7012. if (!empty($value['invoiceType'])) {
  7013. $invoiceHtml .= '<td>' . $value['invoiceCompany'] . '</td>';
  7014. } else {
  7015. $invoiceHtml .= '<td>' . $value['invoiceTitle'] . '</td>';
  7016. }
  7017. if (!empty($value['invoiceType'])) {
  7018. $invoiceHtml .= '<td>' . $value['invoicePrice'] . '专</td>';
  7019. } else {
  7020. $invoiceHtml .= '<td>' . $value['invoicePrice'] . '</td>';
  7021. }
  7022. $invoiceHtml .= '
  7023. <td>' . $value['categoryName'] . $value['userName'] . ' ' . $value['date'] . '</td>
  7024. <td>' . $value['printer'] . ' ' . $value['printTime'] . '</td>
  7025. <td>' . $value['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir' . $value['iidKeyXD'] . '" data-ikey="' . $value['iidKey'] . '" href="#">入账</a></td>
  7026. </tr>
  7027. ';
  7028. }
  7029. $invoiceHtml .= '</tbody></table>
  7030. <script>
  7031. $(\'a[bind-receivables^="ir"]\').click(function() {
  7032. var data = $(this).attr("data-ikey");
  7033. $("input[name=\'invoiceKey\']").val(data);
  7034. var invoiceKey=$("input[name=\'invoiceKey\']").val();
  7035. if(invoiceKey==""){
  7036. alert("入账错误,请重新刷新页面");
  7037. return false;
  7038. }
  7039. if(window.confirm("确定入账吗?")){
  7040. $("#IBR").submit();
  7041. }else{
  7042. return false;
  7043. }
  7044. });
  7045. </script>
  7046. ';
  7047. }
  7048. echo json_encode(array(
  7049. 'status' => 1,
  7050. 'invoiceHtml' => $invoiceHtml
  7051. ));
  7052. }
  7053. function ajaxInvoicePushNotice()
  7054. {
  7055. Doo::loadModel('invoice');
  7056. $invoice = new invoice();
  7057. $approval = $invoice->getOne(array(
  7058. 'where' => 'status=1 and pendingApprovals=' . $this->staff[0]['sid'],
  7059. 'desc' => 'iid',
  7060. 'asArray' => true
  7061. ));
  7062. $isNotice = false;
  7063. if (!empty($approval))
  7064. $isNotice = true;
  7065. $response = array(
  7066. 'error' => 0,
  7067. 'isNotice' => $isNotice
  7068. );
  7069. echo json_encode($response);
  7070. exit();
  7071. }
  7072. public function ajaxCheckInvoiceNoUniqueness()
  7073. {
  7074. $invoiceNo = $this->get_args('invoiceNo') ? $this->get_args('invoiceNo') : "";
  7075. Doo::loadModel('invoice');
  7076. $invoice = new invoice();
  7077. if (!empty($invoiceNo)) {
  7078. Doo::loadModel('invoicePaper');
  7079. $invoicePaper = new invoicePaper();
  7080. Doo::loadClass('XDeode');
  7081. $XDeode = new XDeode(5);
  7082. $ipid = $XDeode->decode($invoiceNo);
  7083. $paperDetail = $invoicePaper->getInvoicePaperByIpid($ipid);
  7084. $info = $invoice->getOne(array(
  7085. 'where' => "invoiceNo = '" . $paperDetail['invoiceNo'] . "'",
  7086. 'asArray' => TRUE
  7087. ));
  7088. if (!empty($info)) {
  7089. echo json_encode(array(
  7090. 'error' => '发票号已存在'
  7091. ));
  7092. die();
  7093. } else
  7094. echo json_encode(array(
  7095. 'ok' => '可以使用!'
  7096. ));
  7097. die();
  7098. }
  7099. }
  7100. function ajaxCheckInvoicePrice()
  7101. {
  7102. $receivablesPrice = $this->get_args('receivablesPrice') && is_numeric($this->get_args('receivablesPrice')) ? $this->get_args('receivablesPrice') : "";
  7103. $iidKey = $this->get_args('iidKey') ? $this->get_args('iidKey') : "";
  7104. Doo::loadModel('invoice');
  7105. $invoice = new invoice();
  7106. Doo::loadModel('invoiceReceivables');
  7107. $invoiceReceivables = new invoiceReceivables();
  7108. Doo::loadClass('XDeode');
  7109. $XDeode = new XDeode(5);
  7110. if (!empty($receivablesPrice) && !empty($iidKey)) {
  7111. $iidKey = $XDeode->decode($iidKey);
  7112. $info = $invoice->getInvoiceByIid($iidKey);
  7113. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString($info['irid']);
  7114. if (empty($irList))
  7115. $irList[0]['sumPrice'] = 0;
  7116. $balance = $info['invoicePrice'] - $irList[0]['sumPrice'];
  7117. if ($balance < $receivablesPrice) {
  7118. echo json_encode(array(
  7119. 'error' => '收款金额超过开票金额。'
  7120. ));
  7121. die();
  7122. }
  7123. if ($balance > $receivablesPrice) {
  7124. echo json_encode(array(
  7125. 'error' => '收款金额低于开票金额。'
  7126. ));
  7127. die();
  7128. }
  7129. }
  7130. }
  7131. function ajaxGetInvoiceByNew()
  7132. {
  7133. Doo::loadModel('invoice');
  7134. $invoice = new invoice();
  7135. $detail = $invoice->getInvoiceByNew($this->staff[0]['sid']);
  7136. echo json_encode(array(
  7137. 'status' => 1,
  7138. 'detail' => $detail
  7139. ));
  7140. }
  7141. /**
  7142. * 旧输入导入
  7143. */
  7144. function importInvoice()
  7145. {
  7146. $emsg = isset($this->params['emsg']) ? $this->params['emsg'] : "";
  7147. $data['emsg'] = "";
  7148. if ($emsg != "")
  7149. $data['emsg'] = "请填写完整的数据";
  7150. $data['time'] = time();
  7151. $this->render("/admin/invoiceImport", $data);
  7152. }
  7153. function uploadInvoice()
  7154. {
  7155. // move_uploaded_file($_FILES['Filedata']['tmp_name'], "/upload/".$_FILES['Filedata']['name']);
  7156. if (isset($_FILES['Filedata']['name'])) {
  7157. $file = $_FILES['Filedata']['tmp_name'];
  7158. $error = false;
  7159. if (!is_uploaded_file($file)) {
  7160. $error = '400 Bad Request';
  7161. }
  7162. if ($error) {
  7163. header('HTTP/1.0 ' . $error);
  7164. die('Error ' . $error);
  7165. } else {
  7166. include(DOO::conf()->SITE_PATH . 'protected/plugin/io.han.php');
  7167. $this->IoHandler = new IoHandler();
  7168. $pics = explode('.', $_FILES['Filedata']['name']);
  7169. // $filedir=$_POST['time'];
  7170. // 调用定义物理路径
  7171. $t = DOO::conf()->SITE_PATH . "upload/invoice/";
  7172. $this->IoHandler->MakeDir($t);
  7173. $filename = $this->_GetFileEXT($_FILES['Filedata']['name']);
  7174. if ($filename != 'xlsx')
  7175. return "";
  7176. // $upload_dir = $t."/".time().rand(10,100).".".$filename;
  7177. $upload_file = iconv("UTF-8", "GB2312", $_FILES["Filedata"]["name"]);
  7178. $upload_dir = $t . "/" . $upload_file;
  7179. $k = move_uploaded_file($file, $upload_dir);
  7180. if ($k) {
  7181. $m = round($_FILES['Filedata']['size'] / 1024 / 1024, 2);
  7182. echo $pics[0] . "." . $filename . "#" . $m . "#" . $_FILES['Filedata']['size'];
  7183. }
  7184. }
  7185. }
  7186. }
  7187. function importInvoiceDo()
  7188. {
  7189. $path = $this->get_args('path') ? $this->get_args('path') : "";
  7190. if ($path != "") {
  7191. Doo::loadModel('invoice');
  7192. Doo::loadModel('staff');
  7193. $staff = new staff();
  7194. Doo::loadModel('invoiceStatistics');
  7195. Doo::loadModel('invoiceOperationLog');
  7196. echo DOO::conf()->SITE_PATH . "upload/invoice/" . iconv("UTF-8", "GB2312", $path);
  7197. $exlArray = $this->_format_excel_to_array(DOO::conf()->SITE_PATH . "upload/invoice/" . $path);
  7198. // print_r ( $exlArray );
  7199. // die ();
  7200. // echo json_encode($exlArray);die;
  7201. foreach ($exlArray as $key => $value) {
  7202. // 开票
  7203. $invoice = new invoice();
  7204. $invoice->invoiceNo = $value['invoiceNo'];
  7205. $invoice->invoiceType = 0;
  7206. if ($value['invoiceType'] == '专')
  7207. $invoice->invoiceType = 1;
  7208. $invoice->invoicePrice = $value['invoicePrice'];
  7209. $invoice->invoiceQuantity = 1;
  7210. $invoice->invoiceUnitPrice = $value['invoicePrice'];
  7211. $invoice->invoiceTitle = $value['invoiceTitle'];
  7212. if ($value['invoiceType'] == '专')
  7213. $invoice->invoiceCompany = $value['invoiceTitle'];
  7214. $invoice->userName = $value['userName'];
  7215. $sDetail = $staff->getStaffByName($value['userName']);
  7216. $invoice->sid = $sDetail['sid'];
  7217. $invoice->cid = $sDetail['cid'];
  7218. $invoice->categoryName = $sDetail['category'];
  7219. $invoice->invoiceElement = $value['invoiceElement'];
  7220. $invoice->remark = $value['remark'];
  7221. $invoice->date = $value['date'];
  7222. $invoice->printTime = $value['date'];
  7223. $invoice->ipSource = 1;
  7224. $invoice->printStatus = 1;
  7225. $invoice->status = 2;
  7226. $invoice->postStatus = 1;
  7227. $invoice->untreadStatus = 0;
  7228. $invoice->invoiceSerial = "#F" . date("Ymd") . mt_rand(1000, 9999);
  7229. $iid = $invoice->insert();
  7230. // 汇总
  7231. $invoiceStatistics = new invoiceStatistics();
  7232. //
  7233. $item = array(
  7234. 'date' => $value['date'],
  7235. 'priceClass' => 1,
  7236. 'cid' => $sDetail['cid'],
  7237. 'staff' => $sDetail['sid'],
  7238. 'invoicePrice' => $value['invoicePrice']
  7239. );
  7240. $invoiceStatistics->setInvoiceStatisticsByCondition($item);
  7241. $invoiceOperationLog = new invoiceOperationLog();
  7242. $item = array(
  7243. 'date' => date("Y-m-d H:i:s"),
  7244. 'operation' => date("Y-m-d") . " 导入",
  7245. 'status' => 1,
  7246. 'img' => $sDetail['avatar'],
  7247. 'username' => $sDetail['username'],
  7248. 'uid' => $sDetail['sid'],
  7249. 'category' => $sDetail['category'],
  7250. 'iid' => $iid
  7251. );
  7252. $invoiceOperationLog->setInvoiceOperationLog($item);
  7253. }
  7254. return '/importInvoice?count=' . count($exlArray);
  7255. // return "/keyonline";
  7256. }
  7257. echo 'no file';
  7258. }
  7259. function importInvoiceReceivables()
  7260. {
  7261. $emsg = isset($this->params['emsg']) ? $this->params['emsg'] : "";
  7262. $data['emsg'] = "";
  7263. if ($emsg != "")
  7264. $data['emsg'] = "请填写完整的数据";
  7265. $data['time'] = time();
  7266. $this->render("/admin/invoiceReceivablesImport", $data);
  7267. }
  7268. // 导入入账数据
  7269. function importInvoiceReceivablesDo()
  7270. {
  7271. $path = $this->get_args('path') ? $this->get_args('path') : "";
  7272. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  7273. if ($path != "") {
  7274. Doo::loadModel('invoiceReceivables');
  7275. Doo::loadModel('invoice');
  7276. Doo::loadModel('staff');
  7277. $staff = new staff();
  7278. Doo::loadModel('invoiceStatistics');
  7279. // echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  7280. $exlArray = $this->_format_excel_to_array(DOO::conf()->SITE_PATH . "upload/invoice/" . iconv("UTF-8", "GB2312", $path), 'invoiceReceivables');
  7281. // print_r ( $exlArray );
  7282. // die ();
  7283. // echo json_encode($exlArray);die;
  7284. foreach ($exlArray as $key => $value) {
  7285. // 收款
  7286. $invoiceReceivables = new invoiceReceivables();
  7287. $invoice = new invoice();
  7288. $invoiceReceivables->bindStatus = 1;
  7289. $invoiceReceivables->receivablesPrice = $value['receivablesPrice'];
  7290. $invoiceReceivables->receivablesMessage = $value['receivablesMessage'];
  7291. $invoiceReceivables->receivablesBank = $value['receivablesBank'];
  7292. $invoiceReceivables->receivablesDate = $value['receivablesDate'];
  7293. $sDetail = $staff->getStaffByName($value['receivablesStaff']);
  7294. $invoiceReceivables->receivablesCategory = $sDetail['cid'] . ':' . $sDetail['category'];
  7295. $invoiceReceivables->receivablesStaff = $sDetail['sid'] . '-' . $sDetail['username'];
  7296. $invoiceReceivables->receivablesSerial = "#SK" . date("Ymd") . mt_rand(1000, 9999);
  7297. $invoiceReceivables->sourcePrice = $value['sourcePrice'];
  7298. $iDetail = $invoice->getInvoiceByInvoiceNo($value['invoiceNo']);
  7299. $invoiceReceivables->iid = $iDetail['iid'];
  7300. $irid = $invoiceReceivables->insert();
  7301. // 发票绑定收款
  7302. $detail = $iDetail;
  7303. $iridString = "";
  7304. if (empty($detail['irid']))
  7305. $iridString = $irid;
  7306. else
  7307. $iridString = $detail['irid'] . ',' . $irid;
  7308. $item = array(
  7309. 'irid' => $iridString,
  7310. 'iid' => $detail['iid']
  7311. );
  7312. $invoice->setInvoiceByCondition($item);
  7313. // 汇总
  7314. $invoiceStatistics = new invoiceStatistics();
  7315. // 扣除入账统计金额
  7316. $item = array(
  7317. 'date' => $value['receivablesDate'],
  7318. 'priceClass' => 3,
  7319. 'cid' => $sDetail['cid'],
  7320. 'staff' => $sDetail['sid'],
  7321. // 'irid' => $irid,
  7322. 'accountPrice' => $value['receivablesPrice']
  7323. );
  7324. $invoiceStatistics->setInvoiceStatisticsByCondition($item);
  7325. }
  7326. return '/importInvoiceReceivables?count=' . count($exlArray);
  7327. echo 'data count ' . count($exlArray);
  7328. die();
  7329. // return "/keyonline";
  7330. }
  7331. echo 'no file';
  7332. }
  7333. function formatExcelToArrayTrain($file_url = "")
  7334. {
  7335. if (!file_exists($file_url)) {
  7336. return array();
  7337. }
  7338. // Doo::loadClass ( 'PHPExcel' );
  7339. Doo::loadClass('PHPExcel1.7.9/PHPExcel');
  7340. $PHPExcel = new PHPExcel();
  7341. $PHPReader = new PHPExcel_Reader_Excel2007();
  7342. if (!$PHPReader->canRead($file_url)) {
  7343. $PHPReader = new PHPExcel_Reader_Excel5();
  7344. if (!$PHPReader->canRead($file_url)) {
  7345. echo 'no Excel';
  7346. return;
  7347. }
  7348. }
  7349. $PHPExcel = $PHPReader->load($file_url);
  7350. /* * 读取excel文件中的第一个工作表 */
  7351. $currentSheet = $PHPExcel->getSheet(0);
  7352. /* * 取得最大的列号 */
  7353. $allColumn = $currentSheet->getHighestColumn();
  7354. /* * 取得一共有多少行 */
  7355. $allRow = $currentSheet->getHighestRow();
  7356. $excel_array = array();
  7357. // die($file_url);
  7358. $conk = 2;
  7359. for ($currentRow = $conk; $currentRow <= $allRow; $currentRow++) {
  7360. $excel_column = array();
  7361. // 后期改进
  7362. if ($allColumn == 'AM')
  7363. $allColumn = 'Z';
  7364. /* * 从第A列开始输出 */
  7365. for ($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn++) {
  7366. $val = $currentSheet->getCellByColumnAndRow(ord($currentColumn) - 65, $currentRow)->getValue();
  7367. if ($val instanceof PHPExcel_RichText)
  7368. $val = $val->__toString();
  7369. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  7370. // $val = "'" . addslashes ( $val ) . "'";
  7371. if ($currentColumn == 'A') {
  7372. $excel_column['invoiceTitle'] = $val;
  7373. } elseif ($currentColumn == 'B')
  7374. $excel_column['invoiceType'] = $val;
  7375. elseif ($currentColumn == 'C') {
  7376. $excel_column['TIN'] = $val;
  7377. } elseif ($currentColumn == 'D') {
  7378. $excel_column['address'] = $val;
  7379. } elseif ($currentColumn == 'E') {
  7380. $excel_column['phone'] = $val;
  7381. } elseif ($currentColumn == 'F') {
  7382. $excel_column['bank'] = $val;
  7383. } elseif ($currentColumn == 'G') {
  7384. $excel_column['bankAccount'] = $val;
  7385. } elseif ($currentColumn == 'H') {
  7386. $excel_column['invoiceElement'] = $val;
  7387. } elseif ($currentColumn == 'I') {
  7388. $excel_column['invoiceQuantity'] = $val;
  7389. } elseif ($currentColumn == 'J') {
  7390. $excel_column['invoiceUnitPrice'] = $val;
  7391. } elseif ($currentColumn == 'K') {
  7392. $excel_column['remark'] = $val;
  7393. } elseif ($currentColumn == 'L') {
  7394. $excel_column['recipientsAddress'] = $val;
  7395. } elseif ($currentColumn == 'M') {
  7396. $excel_column['recipients'] = $val;
  7397. } elseif ($currentColumn == 'N') {
  7398. $excel_column['recipientsPhone'] = $val;
  7399. } elseif ($currentColumn == 'O') {
  7400. $excel_column['electronicPhone'] = $val;
  7401. } elseif ($currentColumn == 'P') {
  7402. $excel_column['electronicEmail'] = $val;
  7403. }
  7404. }
  7405. if (!empty($excel_column['invoiceTitle']) && !empty($excel_column['invoiceQuantity']) && !empty($excel_column['invoiceUnitPrice']))
  7406. array_push($excel_array, $excel_column);
  7407. }
  7408. return $excel_array;
  7409. }
  7410. /**
  7411. * 格式化excel文件为数组
  7412. * @param unknown_type $file_url
  7413. * @param unknown_type $mcid
  7414. */
  7415. function _format_excel_to_array($file_url = "", $sType = "")
  7416. {
  7417. if (!file_exists($file_url)) {
  7418. return array();
  7419. }
  7420. Doo::loadClass('PHPExcel');
  7421. // Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  7422. $PHPExcel = new PHPExcel();
  7423. $PHPReader = new PHPExcel_Reader_Excel2007();
  7424. if (!$PHPReader->canRead($file_url)) {
  7425. $PHPReader = new PHPExcel_Reader_Excel5();
  7426. if (!$PHPReader->canRead($file_url)) {
  7427. echo 'no Excel';
  7428. return;
  7429. }
  7430. }
  7431. $PHPExcel = $PHPReader->load($file_url);
  7432. /* * 读取excel文件中的第一个工作表 */
  7433. $currentSheet = $PHPExcel->getSheet(0);
  7434. /* * 取得最大的列号 */
  7435. $allColumn = $currentSheet->getHighestColumn();
  7436. /* * 取得一共有多少行 */
  7437. $allRow = $currentSheet->getHighestRow();
  7438. $excel_array = array();
  7439. // die($file_url);
  7440. $conk = 2;
  7441. for ($currentRow = $conk; $currentRow <= $allRow; $currentRow++) {
  7442. $excel_column = array();
  7443. // 后期改进
  7444. if ($allColumn == 'AM')
  7445. $allColumn = 'Z';
  7446. /* * 从第A列开始输出 */
  7447. for ($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn++) {
  7448. $val = $currentSheet->getCellByColumnAndRow(ord($currentColumn) - 65, $currentRow)->getValue();
  7449. if ($val instanceof PHPExcel_RichText)
  7450. $val = $val->__toString();
  7451. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  7452. // $val = "'" . addslashes ( $val ) . "'";
  7453. if ($sType == 'invoiceReceivables') {
  7454. if ($currentColumn == 'A')
  7455. $excel_column['invoiceNo'] = $val;
  7456. elseif ($currentColumn == 'B')
  7457. $excel_column['receivablesPrice'] = $val;
  7458. elseif ($currentColumn == 'C') {
  7459. $excel_column['receivablesMessage'] = $val;
  7460. } elseif ($currentColumn == 'D') {
  7461. $excel_column['receivablesBank'] = $val;
  7462. } elseif ($currentColumn == 'E') {
  7463. $excel_column['receivablesDate'] = $this->excelTime($val);
  7464. } elseif ($currentColumn == 'F') {
  7465. $excel_column['receivablesStaff'] = $val;
  7466. } elseif ($currentColumn == 'G') {
  7467. $excel_column['sourcePrice'] = $val;
  7468. }
  7469. } elseif ($sType == "invoiceTrain") {
  7470. if ($currentColumn == 'A') {
  7471. $excel_column['invoiceTitle'] = $val;
  7472. } elseif ($currentColumn == 'B')
  7473. $excel_column['invoiceType'] = $val;
  7474. elseif ($currentColumn == 'C') {
  7475. $excel_column['TIN'] = $val;
  7476. } elseif ($currentColumn == 'D') {
  7477. $excel_column['address'] = $val;
  7478. } elseif ($currentColumn == 'E') {
  7479. $excel_column['phone'] = $val;
  7480. } elseif ($currentColumn == 'F') {
  7481. $excel_column['bank'] = $val;
  7482. } elseif ($currentColumn == 'G') {
  7483. $excel_column['bankAccount'] = $val;
  7484. } elseif ($currentColumn == 'H') {
  7485. $excel_column['invoiceElement'] = $val;
  7486. } elseif ($currentColumn == 'I') {
  7487. $excel_column['invoiceQuantity'] = $val;
  7488. } elseif ($currentColumn == 'J') {
  7489. $excel_column['invoiceUnitPrice'] = $val;
  7490. } elseif ($currentColumn == 'K') {
  7491. $excel_column['remark'] = $val;
  7492. } elseif ($currentColumn == 'L') {
  7493. $excel_column['recipientsAddress'] = $val;
  7494. } elseif ($currentColumn == 'M') {
  7495. $excel_column['recipients'] = $val;
  7496. } elseif ($currentColumn == 'N') {
  7497. $excel_column['recipientsPhone'] = $val;
  7498. }
  7499. } else {
  7500. if ($currentColumn == 'A')
  7501. $excel_column['invoiceNo'] = $val;
  7502. elseif ($currentColumn == 'B')
  7503. $excel_column['invoiceType'] = $val;
  7504. elseif ($currentColumn == 'C') {
  7505. $excel_column['invoicePrice'] = $val;
  7506. } elseif ($currentColumn == 'D') {
  7507. $excel_column['invoiceTitle'] = $val;
  7508. } elseif ($currentColumn == 'E') {
  7509. $excel_column['userName'] = $val;
  7510. } elseif ($currentColumn == 'F') {
  7511. $excel_column['categoryName'] = $val;
  7512. } elseif ($currentColumn == 'G') {
  7513. $excel_column['invoiceElement'] = $val;
  7514. } elseif ($currentColumn == 'H') {
  7515. $excel_column['remark'] = $val;
  7516. } elseif ($currentColumn == 'I') {
  7517. $excel_column['date'] = $this->excelTime($val);
  7518. }
  7519. }
  7520. }
  7521. array_push($excel_array, $excel_column);
  7522. }
  7523. return $excel_array;
  7524. }
  7525. function excelTime($date, $time = false)
  7526. {
  7527. if (function_exists('GregorianToJD')) {
  7528. if (is_numeric($date)) {
  7529. $jd = GregorianToJD(1, 1, 1970);
  7530. $gregorian = JDToGregorian($jd + intval($date) - 25569);
  7531. $date = explode('/', $gregorian);
  7532. $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" : '');
  7533. return $date_str;
  7534. }
  7535. } else {
  7536. $date = $date > 25568 ? $date + 1 : 25569;
  7537. /* There was a bug if Converting date before 1-1-1970 (tstamp 0) */
  7538. $ofs = (70 * 365 + 17 + 2) * 86400;
  7539. $date = date("Y-m-d", ($date * 86400) - $ofs) . ($time ? " 00:00:00" : '');
  7540. }
  7541. return $date;
  7542. }
  7543. /**
  7544. * 旧输入导入
  7545. */
  7546. function _GetFileEXT($filename)
  7547. {
  7548. $pics = explode('.', $filename);
  7549. $num = count($pics);
  7550. return $pics[$num - 1];
  7551. }
  7552. function showCache($path = "", $sid = 0)
  7553. {
  7554. // if (file_exists ( $path )) {
  7555. // $htm = file_get_contents ( $path );
  7556. // } else {
  7557. Doo::loadModel('invoiceStatistics');
  7558. $invoiceStatistics = new invoiceStatistics();
  7559. $isBriefly = $invoiceStatistics->getBrieflyStatistics($sid);
  7560. $htm = '<tr><th class="taC">' . $isBriefly['statisticsMonth'][0]['month'] . '月累计开票</th>
  7561. <td>¥' . $isBriefly['statisticsMonth'][0]['invoicePrice'] . '</td>
  7562. <th class="taC">' . $isBriefly['statisticsMonth'][0]['month'] . '月累计入账</th>
  7563. <td>¥' . $isBriefly['statisticsMonth'][0]['accountPrice'] . '</td></tr>';
  7564. /*
  7565. * '<tr><th class="taC">今年累计开票</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['invoicePrice'] . '</td> <th class="taC">今年累计入账</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['accountPrice'] . '</td></tr>';
  7566. */
  7567. file_put_contents($path, $htm);
  7568. // }
  7569. return $htm;
  7570. }
  7571. /**
  7572. * 生成token
  7573. * @return string
  7574. */
  7575. function set_token()
  7576. {
  7577. $str = md5(uniqid(md5(microtime(true)), true)); // 生成一个不会重复的字符串
  7578. $str = sha1($str); // 加密
  7579. return $str;
  7580. }
  7581. /**
  7582. * 获取get或者POST值
  7583. *
  7584. * @param string $name 属性名称
  7585. * @return fixed 值
  7586. */
  7587. function get_args($name)
  7588. {
  7589. if (isset($_GET[$name])) {
  7590. if (is_array($_GET[$name]))
  7591. return $_GET[$name];
  7592. else
  7593. return addslashes($_GET[$name]);
  7594. } elseif (isset($_POST[$name])) {
  7595. if (is_array($_POST[$name]))
  7596. return $_POST[$name];
  7597. else
  7598. return addslashes($_POST[$name]);
  7599. } else
  7600. return false;
  7601. }
  7602. function SafeFilter(&$arr)
  7603. {
  7604. $ra = array(
  7605. '/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/',
  7606. '/script/',
  7607. '/javascript/',
  7608. '/vbscript/',
  7609. '/expression/',
  7610. '/applet/',
  7611. '/meta/',
  7612. '/xml/',
  7613. '/blink/',
  7614. '/link/',
  7615. '/style/',
  7616. '/embed/',
  7617. '/object/',
  7618. '/frame/',
  7619. '/layer/',
  7620. '/title/',
  7621. '/bgsound/',
  7622. '/base/',
  7623. '/onload/',
  7624. '/onunload/',
  7625. '/onchange/',
  7626. '/onsubmit/',
  7627. '/onreset/',
  7628. '/onselect/',
  7629. '/onblur/',
  7630. '/onfocus/',
  7631. '/onabort/',
  7632. '/onkeydown/',
  7633. '/onkeypress/',
  7634. '/onkeyup/',
  7635. '/onclick/',
  7636. '/ondblclick/',
  7637. '/onmousedown/',
  7638. '/onmousemove/',
  7639. '/onmouseout/',
  7640. '/onmouseover/',
  7641. '/onmouseup/',
  7642. '/onunload/'
  7643. );
  7644. if (is_array($arr)) {
  7645. foreach ($arr as $key => $value) {
  7646. if (!is_array($value)) {
  7647. if (!get_magic_quotes_gpc()) // 不对magic_quotes_gpc转义过的字符使用addslashes(),避免双重转义。
  7648. {
  7649. $value = addslashes($value); // 给单引号(')、双引号(")、反斜线(\)与 NUL(NULL 字符)加上反斜线转义
  7650. }
  7651. $value = preg_replace($ra, '', $value); // 删除非打印字符,粗暴式过滤xss可疑字符串
  7652. $arr[$key] = htmlentities(strip_tags($value)); // 去除 HTML 和 PHP 标记并转换为 HTML 实体
  7653. } else {
  7654. SafeFilter($arr[$key]);
  7655. }
  7656. }
  7657. }
  7658. }
  7659. /**
  7660. * Escape String
  7661. *
  7662. * @access public
  7663. * @param string
  7664. * @param bool whether or not the string will be used in a LIKE condition
  7665. * @return string
  7666. */
  7667. function escape_str($str, $like = FALSE)
  7668. {
  7669. if (is_array($str)) {
  7670. foreach ($str as $key => $val) {
  7671. $str[$key] = $this->escape_str($val, $like);
  7672. }
  7673. return $str;
  7674. }
  7675. var_dump(Doo::db()->getDbObject());
  7676. die();
  7677. if (function_exists('mysql_real_escape_string') and is_resource(Doo::db()->getDbObject())) { // Doo::db ()->getDbObject()
  7678. $str = mysql_real_escape_string($str, Doo::db()->getDbObject());
  7679. } elseif (function_exists('mysql_escape_string')) {
  7680. $str = mysql_escape_string($str);
  7681. } else {
  7682. $str = addslashes($str);
  7683. }
  7684. // escape LIKE condition wildcards
  7685. if ($like === TRUE) {
  7686. $str = str_replace(array(
  7687. '%',
  7688. '_'
  7689. ), array(
  7690. '\\%',
  7691. '\\_'
  7692. ), $str);
  7693. }
  7694. return $str;
  7695. }
  7696. /**
  7697. * 获得分页数据
  7698. * @param unknown_type $table
  7699. * @param unknown_type $condition
  7700. * @param unknown_type $on_page
  7701. * @param unknown_type $page_size
  7702. */
  7703. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page")
  7704. {
  7705. $page_c = "";
  7706. $page['previous'] = $this->get_previous($on_page);
  7707. $page['on_page'] = $on_page;
  7708. $total_count = $this->get_table_count($table, $condition);
  7709. $total = intval($total_count / $page_size);
  7710. $page['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  7711. $page['total_data'] = $total_count;
  7712. $page['next'] = $on_page == $page['total_page'] ? $page['total_page'] : $on_page + 1;
  7713. $i = 1;
  7714. $page_max = 1;
  7715. $page_width = 3;
  7716. if ($on_page >= $page_width) {
  7717. $page_max = intval($on_page / $page_width) + 1;
  7718. $i = intval($on_page / $page_width) * $page_width - 1;
  7719. }
  7720. for (; $i <= $page['total_page']; $i++) {
  7721. if ($i == $on_page)
  7722. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  7723. else
  7724. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  7725. if ($i == ($page_width * $page_max))
  7726. break;
  7727. }
  7728. $page['page'] = $page_c;
  7729. $page['lower'] = (--$on_page) * $page_size;
  7730. return $page;
  7731. }
  7732. /**
  7733. * 获取上一页
  7734. * @param unknown_type $on_page
  7735. */
  7736. function get_previous($on_page = 1)
  7737. {
  7738. return $on_page != 0 ? $on_page - 1 : $on_page;
  7739. }
  7740. /**
  7741. * 获取总页数
  7742. * @param unknown_type $table
  7743. * @param unknown_type $condition
  7744. */
  7745. public function get_table_count($table = "", $condition = "")
  7746. {
  7747. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  7748. $sql = "select count(*) as count from " . $table . " where " . $condition;
  7749. // echo $sql;die;
  7750. $query = Doo::db()->query($sql);
  7751. $result = $query->fetch();
  7752. return $result['count'];
  7753. }
  7754. function isInvoiceNew($type = "GLOBAL")
  7755. {
  7756. Doo::loadModel('invoice');
  7757. $invoice = new invoice();
  7758. Doo::loadModel('invoiceReceivables');
  7759. $invoiceReceivables = new invoiceReceivables();
  7760. Doo::loadModel('staff');
  7761. $staff = new staff();
  7762. $st = $staff->getUserByIdList($_COOKIE["staff"]);
  7763. // 我的发票待处理
  7764. $pendingInvoice = $invoice->getOne(array( // or (status=2 and printStatus=1 and untreadStatus=0 ) or (status=2 and printStatus=1 and untreadStatus=2 )
  7765. 'where' => "(status=3 or status=4) and isDelete=0 and sid=" . $st[0]['sid'],
  7766. 'desc' => 'iid',
  7767. 'asArray' => TRUE
  7768. ));
  7769. // 我的收款待入账
  7770. /*
  7771. * $myClaim = $invoiceReceivables->getOne ( array ( 'where' => " receivablesStaff like '" . $st [0] ['sid'] . "-%' and receivablesCategory like '" . $st [0] ['cid'] . ":%' and bindStatus=0", 'desc' => 'irid', 'asArray' => TRUE ) );
  7772. */
  7773. // 发票审批
  7774. $approval = $invoice->getOne(array(
  7775. 'where' => 'status=1 and pendingApprovals=' . $st[0]['sid'],
  7776. 'desc' => 'iid',
  7777. 'asArray' => true
  7778. ));
  7779. // 发票邮寄
  7780. $post = $invoice->getOne(array(
  7781. 'where' => "postStatus=0 and printStatus=1 and isDelete=0 and doPost=1 and status=2",
  7782. 'asArray' => TRUE
  7783. ));
  7784. // 发票打印
  7785. $print = $invoice->getOne(array(
  7786. 'where' => "status=2 and printStatus=0 and untreadStatus=0 and moldManage like '%[\"" . $st[0]['sid'] . "\",%'",
  7787. 'desc' => 'iid',
  7788. 'asArray' => TRUE
  7789. ));
  7790. // 发票退票 printStatus=1 and
  7791. $untread = $invoice->getOne(array(
  7792. 'where' => " untreadStatus=1 and status=2 ",
  7793. 'asArray' => TRUE
  7794. ));
  7795. $new = array(
  7796. 'GLOBAL' => FALSE,
  7797. 'pendingInvoice' => FALSE,
  7798. // 'myClaim' => FALSE,
  7799. 'approval' => FALSE,
  7800. 'post' => FALSE,
  7801. 'print' => FALSE,
  7802. 'untread' => FALSE
  7803. );
  7804. // || ! empty ( $myClaim )
  7805. if (!empty($pendingInvoice) || !empty($approval) || !empty($post) || !empty($print) || !empty($untread))
  7806. $new['GLOBAL'] = TRUE;
  7807. if (!empty($pendingInvoice))
  7808. $new['pendingInvoice'] = TRUE;
  7809. // if (! empty ( $myClaim ))
  7810. // $new ['myClaim'] = TRUE;
  7811. if (!empty($approval))
  7812. $new['approval'] = TRUE;
  7813. if (!empty($post))
  7814. $new['post'] = TRUE;
  7815. if (!empty($print))
  7816. $new['print'] = TRUE;
  7817. if (!empty($untread))
  7818. $new['untread'] = TRUE;
  7819. return $new;
  7820. }
  7821. function setWXMsg($rid, $typeMsg = '')
  7822. {
  7823. Doo::loadModel('invoice');
  7824. $invoice = new invoice();
  7825. $invoiceDetail = $invoice->getOne(array(
  7826. 'where' => 'iid=' . $rid,
  7827. 'asArray' => true
  7828. ));
  7829. if (!empty($invoiceDetail)) {
  7830. Doo::loadModel('staff');
  7831. $staff = new staff();
  7832. $staffmsg = $staff->getOne(array(
  7833. 'where' => "sid='" . $invoiceDetail['sid'] . "'",
  7834. 'asArray' => TRUE
  7835. ));
  7836. if (!empty($staffmsg['wxid'])) {
  7837. require_once(SITE_PATH . '/protected/class/client.php');
  7838. $client = new client('http://m.cld.smartcost.com.cn/');
  7839. $user = $staffmsg['wxid'];
  7840. $expCom = explode(":", $invoiceDetail['expressCompany']);
  7841. if (empty($expCom))
  7842. $expCom[0] = '';
  7843. $msg = "";
  7844. if (empty($typeMsg))
  7845. $msg = '太好了,您的发票' . $invoiceDetail['invoiceSerial'] . ' 已邮寄 ' . $expCom[0] . ' ,快递号: <a href="https://m.kuaidi100.com/result.jsp?nu=' . $invoiceDetail['expressNumber'] . '" >' . $invoiceDetail['expressNumber'] . '</a>';
  7846. elseif ($typeMsg == "PRINT")
  7847. $msg = '太好了,您的发票已打印完成。';
  7848. $result = $client->SendMsg($user, $msg, 'text');
  7849. }
  7850. }
  7851. }
  7852. /**
  7853. * 获取微信部门
  7854. * @param string $category
  7855. * @return number|mixed
  7856. */
  7857. function getToparty($category = '')
  7858. {
  7859. $token = $this->getAccessToken(); //
  7860. $result = json_decode($this->httpGet("https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token={$token}&id=5"), true);
  7861. $toparty = 0;
  7862. foreach ($result['department'] as $key => $value) {
  7863. if ($value['name'] == $category)
  7864. $toparty = $value['id'];
  7865. }
  7866. return $toparty;
  7867. }
  7868. /**
  7869. * 获得某部门下的用户
  7870. * @param string $toparty
  7871. */
  7872. function getUserByToparty($toparty = '')
  7873. {
  7874. $token = $this->getAccessToken(); //
  7875. $result = json_decode($this->httpGet("https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token={$token}&department_id={$toparty}"), true);
  7876. $userList = array();
  7877. foreach ($result['userlist'] as $key => $value) {
  7878. array_push($userList, "'" . $value['userid'] . "'");
  7879. }
  7880. return $userList;
  7881. }
  7882. function msgSendToparty($msg, $title, $url, $toparty, $text = '')
  7883. {
  7884. $token = $this->getAccessToken();
  7885. if ($text == 'text') {
  7886. $data = '{
  7887. "touser": "' . $toparty . '",
  7888. "toparty": "",
  7889. "totag": "",
  7890. "msgtype": "text",
  7891. "agentid": 1000002,
  7892. "text": {
  7893. "content": "' . $msg . '"
  7894. },
  7895. "safe":0
  7896. }';
  7897. }
  7898. $result = json_decode($this->httpPOST("https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data));
  7899. if ($result->errmsg != 'ok') {
  7900. return 0;
  7901. } else {
  7902. return 1;
  7903. }
  7904. }
  7905. /**
  7906. * 获得可以发送微信用户列表
  7907. * @param string $category
  7908. * @return string
  7909. */
  7910. function getWxidByCategory($category = "")
  7911. {
  7912. if (empty($category))
  7913. return "";
  7914. Doo::loadModel('staff');
  7915. $staff = new staff();
  7916. $toparty = $this->getToparty($category);
  7917. $wxList = array();
  7918. $wxString = "";
  7919. if (!empty($toparty)) {
  7920. $userList = $this->getUserByToparty($toparty);
  7921. $userCon = implode(',', $userList);
  7922. // echo $userCon;
  7923. $sidList = $staff->getStaffByWxid($userCon);
  7924. foreach ($sidList as $key => $value) {
  7925. $falg = $this->isSendNotification($value['sid'], 'receivables');
  7926. if ($falg) {
  7927. array_push($wxList, $value['wxid']);
  7928. }
  7929. }
  7930. $wxString = implode('|', $wxList);
  7931. }
  7932. return $wxString;
  7933. }
  7934. /**
  7935. * 读取发送信息规则判断是否需要发送
  7936. * @param number $sid
  7937. * @param string $sendType
  7938. * @return boolean
  7939. */
  7940. function isSendNotification($sid = 0, $sendType = '')
  7941. {
  7942. Doo::loadModel("notificationConf");
  7943. $notificationConf = new notificationConf();
  7944. $detail = $notificationConf->getNotificationConfBySid($sid);
  7945. $conf = array();
  7946. $sendFlag = true;
  7947. if (!empty($detail)) {
  7948. $conf = json_decode($detail['conf'], true);
  7949. if (!empty($sendType)) {
  7950. if (isset($conf[$sendType])) {
  7951. if ($conf[$sendType] == "CLOSE")
  7952. $sendFlag = false;
  7953. elseif ($conf[$sendType] == "Weekend") {
  7954. $day = date("w");
  7955. if (1 <= $day && 5 >= $day)
  7956. $sendFlag = false;
  7957. } elseif ($conf[$sendType] == "OneToFriday") {
  7958. $day = date("w");
  7959. if (0 == $day || 6 == $day)
  7960. $sendFlag = false;
  7961. }
  7962. }
  7963. } else
  7964. $sendFlag = false;
  7965. }
  7966. return $sendFlag;
  7967. }
  7968. /**
  7969. * 根据规则发送信息
  7970. * @param unknown $msg
  7971. * @param unknown $title
  7972. * @param unknown $url
  7973. * @param unknown $user
  7974. * @param string $text
  7975. * @return number
  7976. */
  7977. private function msgSend($msg, $title, $url, $user, $sid = 0, $sendType = '')
  7978. {
  7979. $token = $this->getAccessToken();
  7980. $falg = $this->isSendNotification($sid, $sendType);
  7981. // if ($text == 'text') {
  7982. // $data = '{
  7983. // "touser": "' . $user . '",
  7984. // "toparty": "",
  7985. // "totag": "",
  7986. // "msgtype": "text",
  7987. // "agentid": 1000002,
  7988. // "text": {
  7989. // "content": "' . $msg . '"
  7990. // },
  7991. // "safe":0
  7992. // }';
  7993. // } else {
  7994. $data = '{
  7995. "touser": "' . $user . '",
  7996. "toparty": "",
  7997. "totag": "",
  7998. "msgtype": "news",
  7999. "agentid": 1000002,
  8000. "news": {
  8001. "articles":[
  8002. {
  8003. "title": "' . $title . '",
  8004. "description": "' . $msg . '",
  8005. "url": "' . $url . '",
  8006. "picurl": ""
  8007. }
  8008. ]
  8009. }
  8010. }';
  8011. // }
  8012. if ($falg) {
  8013. $result = json_decode($this->httpPOST("https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data));
  8014. if ($result->errmsg != 'ok') {
  8015. return 0;
  8016. } else {
  8017. return 1;
  8018. }
  8019. } else
  8020. return 0;
  8021. }
  8022. private function getAccessToken()
  8023. {
  8024. // access_token 应该全局存储与更新,以下代码以写入到文件中做示例
  8025. // $file = './access_token.txt';
  8026. // $data = json_decode ( file_get_contents ( $file ) );
  8027. // if ($data->expire_time < time () or ! $data->expire_time) {
  8028. // 如果是企业号用以下URL获取access_token
  8029. $url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$this->appId&corpsecret=$this->appSecret";
  8030. // $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$this->appId&secret=$this->appSecret";
  8031. $res = json_decode($this->httpGet($url));
  8032. $access_token = $res->access_token;
  8033. // echo $access_token;
  8034. // if ($access_token) {
  8035. // $data->expire_time = time () + 7000;
  8036. // $data->access_token = $access_token;
  8037. // $fp = fopen ( $file, "w" );
  8038. // fwrite ( $fp, json_encode ( $data ) );
  8039. // fclose ( $fp );
  8040. // }
  8041. // } else {
  8042. // $access_token = $data->access_token;
  8043. // }
  8044. return $access_token;
  8045. }
  8046. private function httpGet($url)
  8047. {
  8048. $curl = curl_init();
  8049. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  8050. curl_setopt($curl, CURLOPT_TIMEOUT, 500);
  8051. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  8052. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  8053. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
  8054. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  8055. curl_setopt($curl, CURLOPT_URL, $url);
  8056. $res = curl_exec($curl);
  8057. curl_close($curl);
  8058. return $res;
  8059. }
  8060. private function httpPost($url, $data)
  8061. {
  8062. $curl = curl_init();
  8063. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  8064. curl_setopt($curl, CURLOPT_TIMEOUT, 500);
  8065. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  8066. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  8067. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
  8068. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  8069. curl_setopt($curl, CURLOPT_URL, $url);
  8070. curl_setopt($curl, CURLOPT_POST, 1);
  8071. curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  8072. $res = curl_exec($curl);
  8073. curl_close($curl);
  8074. return $res;
  8075. }
  8076. }