InvoiceController.php 311 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474
  1. <?php
  2. /**
  3. * 开票功能控制器
  4. * @author CP
  5. * @version 1.0
  6. * @namespace invoice
  7. * @package invoiceController
  8. */
  9. class InvoiceController extends DooController {
  10. public $staff;
  11. public $NEW;
  12. public $data;
  13. private $INVOICEKEY = "APPROVAL";
  14. private $INVOICECOLLECTPATH = "protected/cache/invoiceCollect/";
  15. private $ACTION = '';
  16. private $appId = 'wx3ee46531947a1384';
  17. private $appSecret = 'awGWzy3J5q_96VXKBLA2BQ9RpiT0LiPXnkMF-xV6h5o'; // awGWzy3J5q_96VXKBLA2BXU6mVCGynPGD-sxUCsdNDE //'PeiQVH8tbQE7pM9pVO4AIPlX9FFNpwu7O6Iy6VFcAVtpjTA3Qn42dbNmktBFkUHo';
  18. public function beforeRun($resource, $action) {
  19. Doo::loadModel ( "invoiceManage" );
  20. $invoiceManage = new invoiceManage ();
  21. Doo::loadClass ( 'XDeode' );
  22. $XDeode = new XDeode ( 5 );
  23. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  24. header ( 'Content-Type:text/html;charset=utf-8' );
  25. $moldList = $invoiceManage->getInvoiceByStaff ( $sid );
  26. if (empty ( $moldList )) {
  27. $flag = false;
  28. $uGroups = 'ordinary';
  29. if (Doo::acl ()->isAllowed ( $uGroups, $resource, $action )) {
  30. $flag = true;
  31. }
  32. } else {
  33. $flag = false;
  34. array_push ( $moldList, array (
  35. 'mold' => 'ordinary'
  36. ) );
  37. // 删除审批人后-加入权限问题-暂时关闭
  38. $fileInvoice = file_get_contents ( "protected/config/invoice/invoice.ini" );
  39. $fiML = json_decode ( $fileInvoice, true );
  40. if (empty ( $fiML ))
  41. $fiML = array ();
  42. foreach ( $fiML as $key => $value ) {
  43. $sidList = explode ( ',', $value );
  44. foreach ( $sidList as $k => $v ) {
  45. if ($v == $sid) {
  46. array_push ( $moldList, array (
  47. 'mold' => $key
  48. ) );
  49. break;
  50. }
  51. }
  52. }
  53. foreach ( $moldList as $value ) {
  54. if (Doo::acl ()->isAllowed ( $value ['mold'], $resource, $action )) {
  55. $flag = true;
  56. break;
  57. }
  58. }
  59. }
  60. /*
  61. * Doo::acl()->isAllowed($uGroups['groups'], $resource, $action);
  62. */
  63. // 单独判断办事处汇总的访问权限 invoiceAggregateCategoryDetail,invoiceAggregateStaffDetail
  64. if ($action == 'invoiceAggregateCategoryDetail' || $action == 'invoiceAggregateStaffDetail') {
  65. Doo::loadModel ( "invoiceCategoryManage" );
  66. $invoiceCategoryManage = new invoiceCategoryManage ();
  67. $icm = $invoiceCategoryManage->getInvoiceCMByStaff ( $sid );
  68. if (empty ( $icm ))
  69. die ( 'illegal request' );
  70. }
  71. // 单独判断应收款访问权限
  72. if ($action == 'invoiceAggregateCompanyDetail') {
  73. Doo::loadModel ( "invoiceCompanyManage" );
  74. $invoiceCompanyManage = new invoiceCompanyManage ();
  75. $icm = $invoiceCompanyManage->getInvoiceCMByStaff ( $sid );
  76. if (empty ( $icm ))
  77. die ( 'illegal request' );
  78. }
  79. // 主权限获得与判断
  80. Doo::loadModel ( 'staff' );
  81. $staff = new staff ();
  82. $detail = $staff->getStaffBySid ( $_COOKIE ["staff"] );
  83. $accessModular = 'INVOICE';
  84. if (empty ( $detail ['cldAccessArray'] ))
  85. die ( 'illegal request' );
  86. else {
  87. if (in_array ( $accessModular, $detail ['cldAccessArray'] )) {
  88. if (Doo::acl ()->isAllowed ( $accessModular, $resource, $action )) {
  89. $flag = true;
  90. } else {
  91. $flag = false;
  92. }
  93. } else {
  94. die ( 'illegal request' );
  95. }
  96. }
  97. if (! $flag)
  98. die ( 'illegal request' );
  99. }
  100. function __construct() {
  101. if (isset ( $_COOKIE ["staff"] )) {
  102. if (! empty ( $_COOKIE ["staff"] )) {
  103. Doo::loadModel ( 'staff' );
  104. $staff = new staff ();
  105. $uriPartsOrig = explode ( '/', $_SERVER ['REQUEST_URI'] );
  106. $this->ACTION = $uriPartsOrig [1];
  107. $this->data ['new'] = $this->isInvoiceNew ();
  108. $this->staff = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  109. $this->data ['isStaffCompleteMsg'] = false;
  110. $detail = $staff->checkStaffInfoIsComplete ( $_COOKIE ["staff"] );
  111. if (! empty ( $detail ))
  112. $this->data ['isStaffCompleteMsg'] = true;
  113. return "/";
  114. }
  115. }
  116. Doo::loadCore ( 'uri/DooUriRouter' );
  117. $router = new DooUriRouter ();
  118. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  119. if ($routeRs ['1'] != "login") {
  120. header ( 'Content-Type:text/html;charset=utf-8' );
  121. @header ( "Location: /login" );
  122. }
  123. }
  124. function testSend() {
  125. // 测试根据规则发送信息 普通发送
  126. // $pendingApprovalsSid = 41;
  127. // Doo::loadModel ( 'staff' );
  128. // $staff = new staff ();
  129. // $username2 = $staff->getOne ( array ( 'select' => 'wxid', 'where' => 'sid=' . $pendingApprovalsSid, 'asArray' => TRUE ) );
  130. // // 发送微信审批通知
  131. // $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  132. // $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  133. // Doo::loadModel ( 'staff' );
  134. // $staff = new staff ();
  135. // $toparty = $this->getToparty ( '广东办' );
  136. // $wxList = array ();
  137. // if (! empty ( $toparty )) {
  138. // $userList = $this->getUserByToparty ( $toparty );
  139. // $userCon = implode ( ',', $userList );
  140. // // echo $userCon;
  141. // $sidList = $staff->getStaffByWxid ( $userCon );
  142. // foreach ( $sidList as $key => $value ) {
  143. // $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  144. // if ($falg) {
  145. // array_push ( $wxList, $value ['wxid'] );
  146. // }
  147. // }
  148. // $wxString = implode ( '|', $wxList );
  149. // print_r ( $wxList );
  150. // echo $wxString;
  151. // }
  152. // 测试发送
  153. /*
  154. * //$toparty = $this->getWxidByCategory( $receivablesCategory [1] ); $toparty = $this->getToparty ( $receivablesCategory [1] ); $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。'; if ($toparty != 0) $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  155. */
  156. // print_r ( $userList );
  157. // $msTouser='caipin|outaozhen';
  158. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  159. // $title2 = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  160. // $hfreult = $this->msgSend ( '', $title2, '', 'outaozhen' );
  161. // $toparty= $this->getToparty('广东办');
  162. // $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  163. // $toparty = 26;
  164. // $msg = '';
  165. // $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/1.html';
  166. // $hfreult = $this->msgSendToparty ( $msg, '', '', $toparty,'text' );
  167. }
  168. function invoice() {
  169. Doo::loadModel ( 'invoice' );
  170. $invoice = new invoice ();
  171. Doo::loadModel ( 'express' );
  172. $express = new express ();
  173. $expressList = $express->getExpressByAll ();
  174. $this->data ['expressList'] = $expressList;
  175. // Doo::loadModel ( 'invoiceReceivables' );
  176. // $invoiceReceivables = new invoiceReceivables ();
  177. // $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  178. Doo::loadClass ( 'XDeode' );
  179. $XDeode = new XDeode ( 5 );
  180. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  181. Doo::loadModel ( 'invoiceStatistics' );
  182. $invoiceStatistics = new invoiceStatistics ();
  183. $isMonth = $invoiceStatistics->getStatisticsByMonth ( $sid );
  184. // 缓存统计结果
  185. $year = date ( "Y" );
  186. $tmp_date = date ( "Ym" );
  187. $tmp_year = substr ( $tmp_date, 0, 4 );
  188. $tmp_mon = substr ( $tmp_date, 4, 2 );
  189. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  190. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  191. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . "_" . $sid . ".htm";
  192. if (is_file ( $path ))
  193. $htm = file_get_contents ( $path );
  194. else
  195. $htm = $this->showCache ( $path, $sid );
  196. $invoiceList = $invoice->getMyInvoice ( $sid );
  197. $sql = 'status=2 and printStatus=1 and irid!="" and sid=' . $sid;
  198. $list = $invoice->getInvoiceByUntreadStatusPage ( 4, $sql );
  199. // 我的待入账发票 and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  200. $sql = "status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid=" . $sid;
  201. $myInvoiceUnAccount = $invoice->getInvoiceByUntreadStatusPage ( 4, $sql );
  202. // 获得已退票功能
  203. $untreadStatusList = $invoice->getMyInvoiceByUntreadStatus ( 2, 0, 5, $sid);
  204. $this->data ['untreadStatusList'] = $untreadStatusList;
  205. // print_r($untreadStatusList);
  206. $this->data ['isMonth'] = $isMonth;
  207. $this->data ['htm'] = $htm;
  208. $this->data ['invoiceList'] = $invoiceList;
  209. $this->data ['receivablesList'] = $list;
  210. $this->data ['myInvoiceUnAccount'] = $myInvoiceUnAccount;
  211. $this->data ['memu'] = "invoice";
  212. $this->data ['staff'] = $this->staff;
  213. $this->data ['receiptMemu'] = 'invoice';
  214. $this->render ( "/admin/invoice", $this->data );
  215. }
  216. function invoiceExpress() {
  217. $expressCom = isset ( $this->params ['expressCom'] ) ? $this->params ['expressCom'] : "";
  218. $expressNumber = isset ( $this->params ['expressNumber'] ) ? $this->params ['expressNumber'] : "";
  219. $this->data ['expressCom'] = $expressCom;
  220. $this->data ['expressNumber'] = $expressNumber;
  221. $this->render ( "/admin/invoiceExpress", $this->data );
  222. }
  223. function invoiceAdd() {
  224. session_start();
  225. Doo::loadModel ( 'invoice' );
  226. $invoice = new invoice ();
  227. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );
  228. Doo::loadModel ( 'L_category' );
  229. $lCategory = new L_category ();
  230. $category = $lCategory->find ( array (
  231. 'asArray' => true
  232. ) );
  233. $this->data ['category'] = $category;
  234. Doo::loadModel ( 'invoiceTraining' );
  235. $invoiceTraining = new invoiceTraining ();
  236. $itList = $invoiceTraining->getInvoiceTrainingByCid ( $this->staff [0] ['cid'] );
  237. Doo::loadModel ( 'receipt' );
  238. $receipt = new receipt ();
  239. foreach ( $itList as $key => $value ) { // 不展示已结算完结的培训班
  240. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $value ['itid'] );
  241. if (! empty ( $receiptDetail )) {
  242. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9) {
  243. unset ( $itList [$key] );
  244. }
  245. }
  246. }
  247. $this->data ['itList'] = $itList;
  248. $token=$this->set_token();
  249. $_SESSION['token_'.$this->staff[0]['sidKey']] = $token;
  250. $this->data ['token'] = $token;
  251. $this->data ['memu'] = "invoice";
  252. $this->data ['staff'] = $this->staff;
  253. $this->data ['receiptMemu'] = 'invoice';
  254. $this->render ( "/admin/invoiceAdd", $this->data );
  255. }
  256. function invoiceAddFill() {
  257. session_start();
  258. Doo::loadModel ( 'invoice' );
  259. $invoice = new invoice ();
  260. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );
  261. Doo::loadModel ( 'L_category' );
  262. $lCategory = new L_category ();
  263. $category = $lCategory->find ( array (
  264. 'asArray' => true
  265. ) );
  266. $this->data ['category'] = $category;
  267. Doo::loadModel ( 'invoiceTraining' );
  268. $invoiceTraining = new invoiceTraining ();
  269. $itList = $invoiceTraining->getInvoiceTrainingByCid ( $this->staff [0] ['cid'] );
  270. $this->data ['itList'] = $itList;
  271. Doo::loadModel ( 'invoice' );
  272. $invoice = new invoice ();
  273. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );
  274. $detail ['mailItemsArray'] = json_decode ( $detail ['mailItemsJson'], true );
  275. $token=$this->set_token();
  276. $_SESSION['token_'.$this->staff[0]['sidKey']] = $token;
  277. $this->data ['token'] = $token;
  278. $this->data ['invoiceDetail'] = $detail;
  279. $this->data ['memu'] = "invoice";
  280. $this->data ['staff'] = $this->staff;
  281. $this->data ['receiptMemu'] = 'invoice';
  282. $this->render ( "/admin/invoiceAddFill", $this->data );
  283. }
  284. /**
  285. * 提交一份开票申请,并记录下操作日志
  286. *
  287. * @since 1.0.0
  288. * @var integer cid 办事处ID
  289. * @var integer invoiceType 发票类型
  290. * @var integer doPost 是否邮寄
  291. * @var integer invoicePrice 开票金额
  292. * @var string invoiceElement 开票内容
  293. * @var string invoiceTitle 发票抬头
  294. * @var string invoiceCompany 单位名称
  295. * @var string TIN 纳税人识别码
  296. * @var string address 注册地址
  297. * @var string phone 注册电话
  298. * @var string bank 开户银行
  299. * @var string bankAccount 银行账户
  300. * @var string recipients 收件人
  301. * @var string recipientsPhone 收件人手机/电话
  302. * @var string recipientsAddress 收件地址
  303. * @var string mailItems 邮寄物品
  304. * @var string remark 备注
  305. * @return string 返回跳转开票主页路径
  306. */
  307. function invoiceAddDo() {
  308. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  309. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  310. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  311. //$invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  312. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  313. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  314. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  315. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  316. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  317. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  318. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  319. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  320. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  321. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  322. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  323. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  324. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  325. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  326. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  327. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  328. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  329. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  330. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  331. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  332. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  333. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  334. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  335. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  336. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  337. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  338. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  339. $trainId = $this->get_args ( 'trainId' ) ? $this->get_args ( 'trainId' ) : 0;
  340. $settlementType = $this->get_args ( 'settlementType' ) ? $this->get_args ( 'settlementType' ) : "";
  341. /*
  342. * $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;
  343. */
  344. $token = $this->get_args ( 'token' ) ? $this->get_args ( 'token' ) : "";
  345. if (empty($token)){
  346. die ( 'illegal request-token' );
  347. }else{
  348. session_start();
  349. if($_SESSION['token_'.$this->staff[0]['sidKey']]!=$token){
  350. header ( 'Content-Type:text/html;charset=utf-8' );
  351. die('请勿重复申请发票');
  352. }else{
  353. $_SESSION['token_'.$this->staff[0]['sidKey']]='';
  354. }
  355. }
  356. if ($invoiceType == 1) {
  357. $temporary = $invoiceQuantity * $invoiceUnitPrice;
  358. if ($temporary > 10000){
  359. header ( 'Content-Type:text/html;charset=utf-8' );
  360. die('专用发票总金额暂时不能超过10000.00(一万)元。');
  361. //die ( 'illegal request-Please priceError' );
  362. }
  363. }
  364. if (empty ( $this->staff [0] ))
  365. die ( 'illegal request-Please login' );
  366. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $settlementType )) {
  367. Doo::loadModel ( 'invoice' );
  368. $invoice = new invoice ();
  369. Doo::loadModel ( 'L_category' );
  370. $lCategory = new L_category ();
  371. Doo::loadModel ( 'invoiceManage' );
  372. $invoiceManage = new invoiceManage ();
  373. Doo::loadModel ( 'invoiceOperationLog' );
  374. $invoiceOperationLog = new invoiceOperationLog ();
  375. Doo::loadClass ( 'XDeode' );
  376. $XDeode = new XDeode ( 5 );
  377. $trainId = $XDeode->decode ( $trainId );
  378. $categoryDetil = $lCategory->getOne ( array (
  379. 'SELECT' => 'title',
  380. 'where' => 'cid=' . $cid,
  381. 'asArray' => true
  382. ) );
  383. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  384. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  385. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  386. // print_r(current($invoiceManageDetail ['staffList']));
  387. // die;
  388. $moldManage = array ();
  389. foreach ( $invoiceManageList as $key => $value ) {
  390. if ($value ['mold'] == '发票打印')
  391. $moldManage [$value ['mold']] = $value ['staffList'];
  392. elseif ($value ['mold'] == '发票邮寄')
  393. $moldManage [$value ['mold']] = $value ['staffList'];
  394. elseif ($value ['mold'] == '发票退票')
  395. $moldManage [$value ['mold']] = $value ['staffList'];
  396. }
  397. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  398. $st = '';
  399. if ($settlementType == 'SOFTWARE') {
  400. $st = 0;
  401. $trainId = 0;
  402. } elseif ($settlementType == 'TRAINING') {
  403. $st = 1;
  404. if (empty ( $trainId ) && ! is_numeric ( $trainId )) {
  405. die ( 'illegal request-trainingIdError' );
  406. }
  407. } else {
  408. die ( 'illegal request-settlementError' );
  409. }
  410. $item = array (
  411. 'cid' => $cid,
  412. 'categoryName' => $categoryDetil ['title'],
  413. 'invoiceElement' => $invoiceElement,
  414. 'invoiceQuantity' => $invoiceQuantity,
  415. 'invoiceUnitPrice' => $invoiceUnitPrice,
  416. 'invoicePrice' => $invoicePrice,
  417. 'invoiceType' => $invoiceType,
  418. 'settlementType' => $st,
  419. 'doPost' => $doPost,
  420. 'status' => 1,
  421. 'invoiceSerial' => "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  422. 'date' => date ( "Y-m-d H:i:s" ),
  423. 'updateTime' => date ( "Y-m-d H:i:s" ),
  424. 'sid' => $this->staff [0] ['sid'],
  425. 'userName' => $this->staff [0] ['username'],
  426. 'invoiceManage' => $invoiceManageDetail ['staff'],
  427. 'pendingApprovals' => $pendingApprovalsSid,
  428. 'moldManage' => json_encode ( $moldManage ),
  429. 'remark' => $remark,
  430. 'trainId' => $trainId
  431. );
  432. if ($invoiceType == 0)
  433. $item += array (
  434. 'invoiceTitle' => $invoiceTitle,
  435. 'TIN' => $TINT,
  436. 'address' => $addressT,
  437. 'phone' => $phoneT,
  438. 'bank' => $bankT,
  439. 'bankAccount' => $bankAccountT
  440. );
  441. else {
  442. $item += array (
  443. 'invoiceCompany' => $invoiceCompany,
  444. 'TIN' => $TIN,
  445. 'address' => $address,
  446. 'phone' => $phone,
  447. 'bank' => $bank,
  448. 'bankAccount' => $bankAccount
  449. );
  450. }
  451. if ($doPost == 1) {
  452. $mailList = array (
  453. 'invoice' => 1,
  454. 'mailItems' => $mailItems
  455. );
  456. if (! empty ( $softLock ))
  457. $mailList += array (
  458. 'softLock' => $softLockNum
  459. );
  460. else
  461. $mailList += array (
  462. 'softLock' => 0
  463. );
  464. if (! empty ( $contract ))
  465. $mailList += array (
  466. 'contract' => $contractNum
  467. );
  468. else
  469. $mailList += array (
  470. 'contract' => 0
  471. );
  472. if (! empty ( $instructions ))
  473. $mailList += array (
  474. 'instructions' => $instructionsNum
  475. );
  476. else
  477. $mailList += array (
  478. 'instructions' => 0
  479. );
  480. if (! empty ( $remittance ))
  481. $mailList += array (
  482. 'remittance' => $remittance
  483. );
  484. else
  485. $mailList += array (
  486. 'remittance' => ''
  487. );
  488. $mailString = '发票x1张,备注:' . $mailItems;
  489. if (! empty ( $softLock ))
  490. $mailString .= ',软件锁x' . $softLockNum . '个';
  491. if (! empty ( $contract ))
  492. $mailString .= ',合同x' . $contractNum . '份';
  493. if (! empty ( $instructions ))
  494. $mailString .= ',说明书x' . $instructionsNum . '本';
  495. if (! empty ( $remittance ))
  496. $mailString .= ',汇款账号单(张)';
  497. $item += array (
  498. 'recipients' => $recipients,
  499. 'recipientsPhone' => $recipientsPhone,
  500. 'recipientsAddress' => $recipientsAddress,
  501. 'mailItems' => $mailString,
  502. 'mailItemsJson' => json_encode ( $mailList )
  503. );
  504. }
  505. $iid = $invoice->addInvoice ( $item );
  506. // 如果是培训班结算 创建培训班发票到培训班备份中
  507. if (! empty ( $st ) && $st == 1) {
  508. Doo::loadModel ( 'invoiceStore' );
  509. $invoiceStore = new invoiceStore ();
  510. Doo::loadModel ( 'invoiceTraining' );
  511. $invoiceTraining = new invoiceTraining ();
  512. $isid = $invoiceStore->setInvoiceToInvoiceStore ( $iid );
  513. $itemIS = array (
  514. 'isid' => $isid,
  515. 'ipSource' => 1,
  516. 'apStatus' => 1,
  517. 'iid' => $iid
  518. );
  519. $invoiceStore->setInvoiceStoreByCondition ( $itemIS );
  520. // 更新培训班总数量
  521. $detailIT = $invoiceTraining->getInvoiceTrainingByItid ( $trainId );
  522. $item = array (
  523. 'itid' => $trainId,
  524. 'invoiceTotal' => $detailIT ['invoiceTotal'] + 1,
  525. 'submitStatus' => 1
  526. );
  527. $itid = $invoiceTraining->setInvoiceTrainByCondition ( $item );
  528. }
  529. // 操作日志
  530. $item = array (
  531. 'date' => date ( "Y-m-d H:i:s" ),
  532. 'operation' => "创建",
  533. 'status' => 1,
  534. 'img' => $this->staff [0] ['avatar'],
  535. 'username' => $this->staff [0] ['username'],
  536. 'uid' => $this->staff [0] ['sid'],
  537. 'category' => $this->staff [0] ['category'],
  538. 'iid' => $iid
  539. );
  540. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  541. $item = array (
  542. 'date' => date ( "Y-m-d H:i:s" ),
  543. 'operation' => "提交审批",
  544. 'status' => 1,
  545. 'img' => $this->staff [0] ['avatar'],
  546. 'username' => $this->staff [0] ['username'],
  547. 'uid' => $this->staff [0] ['sid'],
  548. 'category' => $this->staff [0] ['category'],
  549. 'iid' => $iid
  550. );
  551. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  552. Doo::loadModel ( 'staff' );
  553. $staff = new staff ();
  554. $username2 = $staff->getOne ( array (
  555. 'select' => 'wxid',
  556. 'where' => 'sid=' . $pendingApprovalsSid,
  557. 'asArray' => TRUE
  558. ) );
  559. // 发送微信审批通知
  560. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  561. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  562. }
  563. return "/invoice";
  564. }
  565. function invoiceEdit() {
  566. Doo::loadClass ( 'XDeode' );
  567. $XDeode = new XDeode ( 5 );
  568. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  569. $iid = $XDeode->decode ( $iid );
  570. if (! is_numeric ( $iid ))
  571. die ( 'illegal request' );
  572. Doo::loadModel ( 'invoice' );
  573. $invoice = new invoice ();
  574. Doo::loadModel ( 'invoiceOperationLog' );
  575. $invoiceOperationLog = new invoiceOperationLog ();
  576. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  577. $operation = $invoiceOperationLog->getInvoiceOperationByDropped ( $iid );
  578. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  579. $this->data ['operation'] = $operation;
  580. $this->data ['invoiceDetail'] = $invoiceDetail;
  581. $this->data ['memu'] = "invoice";
  582. $this->data ['staff'] = $this->staff;
  583. $this->data ['receiptMemu'] = 'invoice';
  584. $this->render ( "/admin/invoiceEdit", $this->data );
  585. }
  586. /**
  587. * 重新编辑退回的发票
  588. * @return string
  589. */
  590. function invoiceEditDo() {
  591. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  592. Doo::loadModel ( 'invoice' );
  593. $invoice = new invoice ();
  594. $iid = $invoice->authcode ( $iidKey );
  595. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  596. die ( 'illegal request' );
  597. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  598. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  599. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  600. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  601. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  602. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  603. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  604. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  605. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  606. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  607. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  608. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  609. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  610. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  611. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  612. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  613. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  614. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  615. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  616. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  617. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  618. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  619. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  620. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  621. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  622. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  623. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  624. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  625. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  626. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  627. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  628. if ($invoiceType == 1) {
  629. $temporary = $invoiceQuantity * $invoiceUnitPrice;
  630. if ($temporary > 10000)
  631. die ( 'illegal request-Please priceError' );
  632. }
  633. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  634. Doo::loadModel ( 'invoiceManage' );
  635. $invoiceManage = new invoiceManage ();
  636. Doo::loadModel ( 'invoiceOperationLog' );
  637. $invoiceOperationLog = new invoiceOperationLog ();
  638. Doo::loadModel ( 'invoiceStore' );
  639. $invoiceStore = new invoiceStore ();
  640. $cid = explode ( ':', $cid );
  641. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  642. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  643. $moldManage = array ();
  644. foreach ( $invoiceManageList as $key => $value ) {
  645. if ($value ['mold'] == '发票打印')
  646. $moldManage [$value ['mold']] = $value ['staffList'];
  647. elseif ($value ['mold'] == '发票邮寄')
  648. $moldManage [$value ['mold']] = $value ['staffList'];
  649. elseif ($value ['mold'] == '发票打印')
  650. $moldManage [$value ['mold']] = $value ['staffList'];
  651. }
  652. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  653. $item = array (
  654. 'iid' => $iid,
  655. 'cid' => $cid [0],
  656. 'categoryName' => $cid [1],
  657. 'invoiceElement' => $invoiceElement,
  658. 'invoiceQuantity' => $invoiceQuantity,
  659. 'invoiceUnitPrice' => $invoiceUnitPrice,
  660. 'invoicePrice' => $invoicePrice,
  661. 'invoiceType' => $invoiceType,
  662. 'doPost' => $doPost,
  663. 'status' => 1,
  664. 'updateTime' => date ( "Y-m-d H:i:s" ),
  665. 'remark' => $remark
  666. );
  667. if ($invoiceType == 0)
  668. $item += array (
  669. 'invoiceTitle' => $invoiceTitle,
  670. 'TIN' => $TINT,
  671. 'address' => $addressT,
  672. 'phone' => $phoneT,
  673. 'bank' => $bankT,
  674. 'bankAccount' => $bankAccountT
  675. );
  676. else {
  677. $item += array (
  678. 'invoiceCompany' => $invoiceCompany,
  679. 'TIN' => $TIN,
  680. 'address' => $address,
  681. 'phone' => $phone,
  682. 'bank' => $bank,
  683. 'bankAccount' => $bankAccount
  684. );
  685. }
  686. if ($doPost == 1) {
  687. $mailList = array (
  688. 'invoice' => 1,
  689. 'mailItems' => $mailItems
  690. );
  691. if (! empty ( $softLock ))
  692. $mailList += array (
  693. 'softLock' => $softLockNum
  694. );
  695. else
  696. $mailList += array (
  697. 'softLock' => '0'
  698. );
  699. if (! empty ( $contract ))
  700. $mailList += array (
  701. 'contract' => $contractNum
  702. );
  703. else
  704. $mailList += array (
  705. 'contract' => '0'
  706. );
  707. if (! empty ( $instructions ))
  708. $mailList += array (
  709. 'instructions' => $instructionsNum
  710. );
  711. else
  712. $mailList += array (
  713. 'instructions' => '0'
  714. );
  715. if (! empty ( $remittance ))
  716. $mailList += array (
  717. 'remittance' => $remittance
  718. );
  719. else
  720. $mailList += array (
  721. 'remittance' => ''
  722. );
  723. $mailString = '发票x1,备注:' . $mailItems;
  724. if (! empty ( $softLock ))
  725. $mailString .= ',软件锁x' . $softLockNum;
  726. if (! empty ( $contract ))
  727. $mailString .= ',合同x' . $contractNum;
  728. if (! empty ( $instructions ))
  729. $mailString .= ',说明书x' . $instructionsNum;
  730. if (! empty ( $remittance ))
  731. $mailString .= ',汇款账号单';
  732. $item += array (
  733. 'recipients' => $recipients,
  734. 'recipientsPhone' => $recipientsPhone,
  735. 'recipientsAddress' => $recipientsAddress,
  736. 'mailItems' => $mailString,
  737. 'mailItemsJson' => json_encode ( $mailList )
  738. );
  739. }
  740. $invoice->setInvoiceByCondition ( $item );
  741. //更新培训班仓库里的发票
  742. $detail=$invoice->getInvoiceByIid($iid);
  743. if (!empty($detail['isid'])){
  744. $invoiceStore->isid=$detail['isid'];
  745. $invoiceStore->invoiceQuantity=$invoiceQuantity;
  746. $invoiceStore->invoiceUnitPrice=$invoiceUnitPrice;
  747. $invoiceStore->invoicePrice=$invoicePrice;
  748. $invoiceStore->update();
  749. }
  750. $item = array (
  751. 'date' => date ( "Y-m-d H:i:s" ),
  752. 'operation' => "重新提交审批",
  753. 'status' => 1,
  754. 'img' => $this->staff [0] ['avatar'],
  755. 'username' => $this->staff [0] ['username'],
  756. 'uid' => $this->staff [0] ['sid'],
  757. 'category' => $this->staff [0] ['category'],
  758. 'iid' => $iid
  759. );
  760. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  761. }
  762. return "/invoice";
  763. }
  764. /**
  765. * 培训班
  766. */
  767. function invoiceTraining() {
  768. Doo::loadModel ( 'L_category' );
  769. $lCategory = new L_category ();
  770. Doo::loadModel ( 'invoiceTraining' );
  771. $invoiceTraining = new invoiceTraining ();
  772. Doo::loadModel ( 'invoiceTrainManage' );
  773. $invoiceTrainManage = new invoiceTrainManage ();
  774. $imcStaff = $invoiceTrainManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  775. $cidList = array ();
  776. foreach ( $imcStaff as $key => $value ) {
  777. array_push ( $cidList, $value ['cid'] );
  778. }
  779. if (empty ( $cidList )) {
  780. $cidString = $this->staff [0] ['cid'];
  781. } else {
  782. $cidString = implode ( ',', $cidList );
  783. $cidString .= $cidString . ',' . $this->staff [0] ['cid'];
  784. }
  785. $itTodoList = $invoiceTraining->getInvoiceTrainingByTodo ( '', $cidString, $this->staff [0] ['sid'] );
  786. $itedList = $invoiceTraining->getInvoiceTrainingByStatus ( 2, '', $cidString, $this->staff [0] ['sid'] );
  787. $category = $lCategory->getCategory ();
  788. $itid = array ();
  789. foreach ( $itTodoList as $key => $value ) {
  790. array_push ( $itid, $value ['itid'] );
  791. // 如果入账100%更新为已完成
  792. if ($itTodoList [$key] ['arriveSchedule'] >= 100) {
  793. $invoiceTraining = new invoiceTraining ();
  794. $invoiceTraining->itid = $value ['itid'];
  795. $invoiceTraining->status = 2;
  796. $invoiceTraining->update ();
  797. }
  798. }
  799. foreach ( $itedList as $value ) {
  800. array_push ( $itid, $value ['itid'] );
  801. }
  802. $itid = implode ( ',', $itid );
  803. $this->data ['itStatist'] = $invoiceTraining->getInvoiceTrainStatistics ( $itid );
  804. // print_r($itTodoList);
  805. $this->data ['trainCount'] = count ( $itTodoList ) + count ( $itedList );
  806. $this->data ['itTodoList'] = $itTodoList;
  807. $this->data ['itedList'] = $itedList;
  808. $this->data ['category'] = $category;
  809. $this->data ['memu'] = "invoice";
  810. $this->data ['staff'] = $this->staff;
  811. $this->data ['receiptMemu'] = 'invoiceTraining';
  812. $this->render ( "/admin/invoiceTraining", $this->data );
  813. }
  814. /**
  815. * 创建培训班
  816. */
  817. function invoiceTrainingAdd() {
  818. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  819. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  820. $trainDate = $this->get_args ( 'trainDate' ) ? $this->get_args ( 'trainDate' ) : "";
  821. if (empty ( $this->staff [0] ))
  822. die ( 'illegal request' );
  823. if (! empty ( $cid ) && ! empty ( $trainName ) && ! empty ( $trainDate )) {
  824. Doo::loadModel ( 'invoiceTraining' );
  825. $invoiceTraining = new invoiceTraining ();
  826. Doo::loadModel ( 'invoice' );
  827. $invoice = new invoice ();
  828. Doo::loadModel ( 'L_category' );
  829. $lCategory = new L_category ();
  830. Doo::loadModel ( 'invoiceManage' );
  831. $invoiceManage = new invoiceManage ();
  832. Doo::loadModel ( 'invoiceOperationLog' );
  833. $invoiceOperationLog = new invoiceOperationLog ();
  834. $item = array (
  835. 'cid' => $cid,
  836. 'trainName' => $trainName,
  837. 'trainDate' => $trainDate,
  838. 'creator' => $this->staff [0] ['sid'],
  839. 'creatorDate' => date ( "Y-m-d H:i:s" )
  840. );
  841. $itid = $invoiceTraining->addInvoiceTraining ( $item );
  842. }
  843. return "/invoiceTraining";
  844. }
  845. /**
  846. * 删除培训班
  847. */
  848. function invoiceTrainingDelDo() {
  849. $itid = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  850. if (! empty ( $itid )) {
  851. Doo::loadModel ( 'invoiceTraining' );
  852. $invoiceTraining = new invoiceTraining ();
  853. $invoiceTraining->delInvoiceTrainingByItid ( $itid );
  854. }
  855. return "/invoiceTraining";
  856. }
  857. /**
  858. * 培训班详情
  859. */
  860. function invoiceTrainingDetail() {
  861. $trainStatus = $this->get_args ( 'trainStatus' ) ? $this->get_args ( 'trainStatus' ) : "ALL";
  862. $itid = isset ( $this->params ['trainingKey'] ) ? $this->params ['trainingKey'] : "";
  863. Doo::loadModel ( 'invoiceTraining' );
  864. $invoiceTraining = new invoiceTraining ();
  865. Doo::loadModel ( 'invoiceStore' );
  866. $invoiceStore = new invoiceStore ();
  867. if (empty ( $itid ))
  868. die ( 'illegal request' );
  869. $con = ' (b.untreadStatus is null or b.untreadStatus!=2) and ';
  870. if ($trainStatus == "SUBED")
  871. $con = ' (b.untreadStatus is null ) and ';
  872. elseif ($trainStatus == "APPROVAL")
  873. $con = ' ( b.status=1 and b.untreadStatus!=2 ) and ';
  874. elseif ($trainStatus == "TICKET")
  875. $con = ' (b.printStatus=1 and b.status=2 and b.untreadStatus!=2) and ';
  876. elseif ($trainStatus == "TICKETING") {
  877. $con = ' (b.status=2 and b.untreadStatus=1) and ';
  878. }
  879. $detail = $invoiceTraining->getInvoiceTrainingByItid ( $itid );
  880. $isList = $invoiceStore->getinvoiceStoreByItid ( $itid, $con );
  881. // print_r($isList);
  882. $trainlist = array ();
  883. foreach ( $isList as $key => $value ) {
  884. $irDetail = array ();
  885. if ($value ['apStatus'] == 1) {
  886. // array_push ( $irDetail, '' );
  887. array_push ( $irDetail, '<input disabled type="checkbox" style="display:none" >' );
  888. } else {
  889. array_push ( $irDetail, '<input type="checkbox" class="hide" id="' . $value ['storeKey'] . '" name="isBox" value="' . $value ['storeKey'] . '" > <a href="/invoiceStoreEdit/' . $value ['storeKey'] . '.html">编辑</a>
  890. <a href="#confirm" onclick="invoiceStoreApproval(\'' . $value ['storeKey'] . '\')" data-toggle="modal">提交审批</a>
  891. <a href="#del" node-iStore="del" data-key="' . $value ['storeKey'] . '" onclick="invoiceStoreDel(\'' . $value ['storeKey'] . '\')" data-toggle="modal" class="colRed">移除</a>' );
  892. }
  893. array_push ( $irDetail, $value ['invoiceSerial'] );
  894. if ($value ['invoiceType'] == 1)
  895. array_push ( $irDetail, $value ['invoiceCompany'] );
  896. else
  897. array_push ( $irDetail, $value ['invoiceTitle'] );
  898. array_push ( $irDetail, $value ['TIN'] );
  899. array_push ( $irDetail, $value ['userName'] );
  900. if (empty ( $value ['mailItems'] ) && $value ['apStatus'] != 1) {
  901. array_push ( $irDetail, '<a href="#confirm-erro" onclick="invoiceStoreMail(\'' . $value ['storeKey'] . '\')" data-toggle="modal">设置邮寄物品</a>' );
  902. } else
  903. array_push ( $irDetail, $value ['mailItems'] );
  904. array_push ( $irDetail, $value ['recipientsAddress'] . $value ['recipients'] . $value ['recipientsPhone'] );
  905. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  906. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  907. array_push ( $irDetail, $value ['invoiceElement'] );
  908. array_push ( $irDetail, $value ['invoiceQuantity'] );
  909. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  910. if ($value ['invoiceType'] == 1)
  911. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  912. else
  913. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  914. array_push ( $irDetail, $value ['remark'] );
  915. if ($value ['status'] == 1)
  916. array_push ( $irDetail, '审批中' );
  917. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1)
  918. array_push ( $irDetail, '已出票' );
  919. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1 && $value ['printStatus'] != 'irid' && ($value ['untreadStatus'] == 3 || $value ['untreadStatus'] == 0))
  920. array_push ( $irDetail, '已入账' );
  921. else
  922. array_push ( $irDetail, '' );
  923. array_push ( $irDetail, $value ['invoiceNo'] );
  924. array_push ( $irDetail, $value ['printTime'] );
  925. $html = '';
  926. foreach ( $value ['invoiceReceivables'] as $value ) {
  927. $html .= '&nbsp;<a href="#billing" node-invoice="INFO" data-type="receivables" data-iskey="' . $value [2] . '" data-toggle="modal">' . $value [1] . '</a>';
  928. }
  929. array_push ( $irDetail, $html );
  930. array_push ( $trainlist, $irDetail );
  931. }
  932. $trainlistJson = json_encode ( $trainlist );
  933. if (empty ( $detail ))
  934. die ( 'illegal request' );
  935. // 培训班结算是否有和是否已经结算完成
  936. Doo::loadModel ( 'receipt' );
  937. $receipt = new receipt ();
  938. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $itid );
  939. $this->data ['receiptDetail'] = $receiptDetail;
  940. $this->data ['trainStatus'] = $trainStatus;
  941. $this->data ['itid'] = $itid;
  942. $this->data ['trainlistJson'] = $trainlistJson;
  943. $this->data ['iTrainDetail'] = $detail;
  944. $this->data ['memu'] = "invoice";
  945. $this->data ['staff'] = $this->staff;
  946. $this->data ['receiptMemu'] = 'invoiceTraining';
  947. $this->render ( "/admin/invoiceTrainingDetail", $this->data );
  948. }
  949. /**
  950. * 上传培训班发票
  951. * @return string
  952. */
  953. function invoiceTrainingUpload() {
  954. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  955. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  956. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  957. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  958. header ( "HTTP/1.1 500 Internal Server Error" );
  959. echo "POST exceeded maximum allowed size.";
  960. exit ( 0 );
  961. }
  962. // Settings
  963. $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)
  964. $upload_name = "Filedata";
  965. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  966. $extension_whitelist = array (
  967. "doc",
  968. "txt",
  969. "jpg",
  970. "gif",
  971. "png"
  972. ); // Allowed file extensions
  973. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  974. // Other variables
  975. $MAX_FILENAME_LENGTH = 260;
  976. $file_name = "";
  977. $file_extension = "";
  978. $uploadErrors = array (
  979. 0 => "文件上传成功",
  980. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  981. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  982. 3 => "上传的文件仅为部分文件",
  983. 4 => "没有文件上传",
  984. 6 => "缺少临时文件夹"
  985. );
  986. $nk = time ();
  987. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  988. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  989. echo "文件无法保存.";
  990. exit ( 0 );
  991. }
  992. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  993. echo json_encode ( array (
  994. 'filename' => $file_name,
  995. 'id' => $nk
  996. ) );
  997. exit ( 0 );
  998. }
  999. /**
  1000. * 导入发票临时仓库
  1001. */
  1002. function invoiceStoreImport() {
  1003. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  1004. $trainingKey = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  1005. $path = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  1006. if ($path != "" && ! empty ( $trainingKey )) {
  1007. Doo::loadModel ( 'invoiceStore' );
  1008. Doo::loadModel ( 'staff' );
  1009. $staff = new staff ();
  1010. Doo::loadModel ( 'invoiceTraining' );
  1011. $invoiceTraining = new invoiceTraining ();
  1012. Doo::loadClass ( 'XDeode' );
  1013. $XDeode = new XDeode ( 5 );
  1014. $itid = $XDeode->decode ( $trainingKey );
  1015. // 培训班结算是否有和是否已经结算完成
  1016. Doo::loadModel ( 'receipt' );
  1017. $receipt = new receipt ();
  1018. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $itid );
  1019. if (! empty ( $receiptDetail )) {
  1020. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9)
  1021. die ( 'illegal request--status' );
  1022. }
  1023. $exlArray = $this->formatExcelToArrayTrain ( DOO::conf ()->SITE_PATH . "upload/invoiceTraining/" . $path );
  1024. $userName = $this->staff [0] ['username'];
  1025. $sDetail = $staff->getStaffByName ( $userName );
  1026. // die('sdd');
  1027. // 可以优化
  1028. foreach ( $exlArray as $key => $value ) {
  1029. // 开票
  1030. $invoice = new invoiceStore ();
  1031. $invoice->trainId = $itid;
  1032. $invoice->invoiceType = 0;
  1033. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  1034. $invoice->invoiceType = 1;
  1035. $invoice->invoiceQuantity = $value ['invoiceQuantity'];
  1036. $invoice->invoiceUnitPrice = $value ['invoiceUnitPrice'];
  1037. $invoice->invoicePrice = $value ['invoiceQuantity'] * $value ['invoiceUnitPrice'];
  1038. $invoice->invoiceTitle = $value ['invoiceTitle'];
  1039. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  1040. $invoice->invoiceCompany = $value ['invoiceTitle'];
  1041. $invoice->userName = $userName;
  1042. $invoice->sid = $sDetail ['sid'];
  1043. $invoice->cid = $sDetail ['cid'];
  1044. $invoice->categoryName = $sDetail ['category'];
  1045. $invoice->invoiceElement = $value ['invoiceElement'];
  1046. $invoice->remark = $value ['remark'];
  1047. // $invoice->date = $value ['date'];
  1048. // $invoice->printTime = $value ['date'];
  1049. $invoice->ipSource = 1;
  1050. $invoice->printStatus = 0;
  1051. $invoice->status = 0;
  1052. $invoice->postStatus = 1;
  1053. $invoice->untreadStatus = 0;
  1054. // $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1055. $invoice->TIN = $value ['TIN'];
  1056. $invoice->address = $value ['address'];
  1057. $invoice->phone = $value ['phone'];
  1058. $invoice->bank = $value ['bank'];
  1059. $invoice->bankAccount = $value ['bankAccount'];
  1060. $invoice->recipientsAddress = $value ['recipientsAddress'];
  1061. $invoice->recipients = $value ['recipients'];
  1062. $invoice->recipientsPhone = $value ['recipientsPhone'];
  1063. $iid = $invoice->insert ();
  1064. }
  1065. // 加入发票总数量
  1066. $item = array (
  1067. 'itid' => $itid,
  1068. 'invoiceTotal' => count ( $exlArray )
  1069. );
  1070. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1071. return '/invoiceTrainingDetail/' . $trainingKey . ".html";
  1072. }
  1073. echo 'no file';
  1074. }
  1075. /**
  1076. * 编辑仓库里的发票
  1077. */
  1078. function invoiceStoreEdit() {
  1079. Doo::loadClass ( 'XDeode' );
  1080. $XDeode = new XDeode ( 5 );
  1081. $iid = isset ( $this->params ['storeKey'] ) ? $this->params ['storeKey'] : "";
  1082. $iid = $XDeode->decode ( $iid );
  1083. if (! is_numeric ( $iid ))
  1084. die ( 'illegal request' );
  1085. Doo::loadModel ( 'invoiceStore' );
  1086. $invoiceStore = new invoiceStore ();
  1087. $invoiceDetail = $invoiceStore->getInvoiceStoreByIsid ( $iid );
  1088. // print_r($invoiceDetail);
  1089. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  1090. $this->data ['invoiceDetail'] = $invoiceDetail;
  1091. $this->data ['memu'] = "invoice";
  1092. $this->data ['staff'] = $this->staff;
  1093. $this->data ['receiptMemu'] = 'invoiceTraining';
  1094. $this->render ( "/admin/invoiceStoreEdit", $this->data );
  1095. }
  1096. function invoiceStoreEditDo() {
  1097. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1098. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1099. Doo::loadModel ( 'invoiceStore' );
  1100. $invoice = new invoiceStore ();
  1101. Doo::loadClass ( 'XDeode' );
  1102. $XDeode = new XDeode ( 5 );
  1103. $iid = $XDeode->decode ( $storeKey );
  1104. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1105. die ( 'illegal request' );
  1106. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  1107. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  1108. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  1109. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  1110. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  1111. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  1112. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  1113. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  1114. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  1115. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  1116. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  1117. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  1118. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  1119. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  1120. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1121. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1122. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1123. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1124. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  1125. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  1126. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  1127. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  1128. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  1129. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  1130. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1131. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1132. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1133. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1134. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1135. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1136. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1137. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  1138. $cid = explode ( ':', $cid );
  1139. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  1140. $item = array (
  1141. 'isid' => $iid,
  1142. 'cid' => $cid [0],
  1143. 'categoryName' => $cid [1],
  1144. 'invoiceElement' => $invoiceElement,
  1145. 'invoiceQuantity' => $invoiceQuantity,
  1146. 'invoiceUnitPrice' => $invoiceUnitPrice,
  1147. 'invoicePrice' => $invoicePrice,
  1148. 'invoiceType' => $invoiceType,
  1149. 'doPost' => $doPost,
  1150. 'status' => 1,
  1151. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1152. 'remark' => $remark
  1153. );
  1154. if ($invoiceType == 0)
  1155. $item += array (
  1156. 'invoiceTitle' => $invoiceTitle,
  1157. 'TIN' => $TINT,
  1158. 'address' => $addressT,
  1159. 'phone' => $phoneT,
  1160. 'bank' => $bankT,
  1161. 'bankAccount' => $bankAccountT
  1162. );
  1163. else {
  1164. $item += array (
  1165. 'invoiceCompany' => $invoiceCompany,
  1166. 'TIN' => $TIN,
  1167. 'address' => $address,
  1168. 'phone' => $phone,
  1169. 'bank' => $bank,
  1170. 'bankAccount' => $bankAccount
  1171. );
  1172. }
  1173. if ($doPost == 1) {
  1174. $mailList = array (
  1175. 'invoice' => 1,
  1176. 'mailItems' => $mailItems
  1177. );
  1178. if (! empty ( $softLock ))
  1179. $mailList += array (
  1180. 'softLock' => $softLockNum
  1181. );
  1182. else
  1183. $mailList += array (
  1184. 'softLock' => '0'
  1185. );
  1186. if (! empty ( $contract ))
  1187. $mailList += array (
  1188. 'contract' => $contractNum
  1189. );
  1190. else
  1191. $mailList += array (
  1192. 'contract' => '0'
  1193. );
  1194. if (! empty ( $instructions ))
  1195. $mailList += array (
  1196. 'instructions' => $instructionsNum
  1197. );
  1198. else
  1199. $mailList += array (
  1200. 'instructions' => '0'
  1201. );
  1202. if (! empty ( $remittance ))
  1203. $mailList += array (
  1204. 'remittance' => $remittance
  1205. );
  1206. else
  1207. $mailList += array (
  1208. 'remittance' => ''
  1209. );
  1210. $mailString = '发票x1,备注:' . $mailItems;
  1211. if (! empty ( $softLock ))
  1212. $mailString .= ',软件锁x' . $softLockNum;
  1213. if (! empty ( $contract ))
  1214. $mailString .= ',合同x' . $contractNum;
  1215. if (! empty ( $instructions ))
  1216. $mailString .= ',说明书x' . $instructionsNum;
  1217. if (! empty ( $remittance ))
  1218. $mailString .= ',汇款账号单';
  1219. $item += array (
  1220. 'recipients' => $recipients,
  1221. 'recipientsPhone' => $recipientsPhone,
  1222. 'recipientsAddress' => $recipientsAddress,
  1223. 'mailItems' => $mailString,
  1224. 'mailItemsJson' => json_encode ( $mailList )
  1225. );
  1226. }
  1227. $invoice->setInvoiceStoreByCondition ( $item );
  1228. }
  1229. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1230. }
  1231. /**
  1232. *
  1233. * @return string
  1234. */
  1235. function invoiceStoreDelete() {
  1236. Doo::loadClass ( 'XDeode' );
  1237. $XDeode = new XDeode ( 5 );
  1238. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1239. $iStoreKey = $this->get_args ( 'iStoreKey' ) ? $this->get_args ( 'iStoreKey' ) : 0;
  1240. $isid = $XDeode->decode ( $iStoreKey );
  1241. $itid = $XDeode->decode ( $trainKey );
  1242. if (! is_numeric ( $isid ))
  1243. die ( 'illegal request' );
  1244. Doo::loadModel ( 'invoiceStore' );
  1245. $invoiceStore = new invoiceStore ();
  1246. $invoiceStore->delete ( array (
  1247. 'where' => 'isid=' . $isid,
  1248. 'limit' => 1
  1249. ) );
  1250. Doo::loadModel ( 'invoiceTraining' );
  1251. $invoiceTraining = new invoiceTraining ();
  1252. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1253. $item = array (
  1254. 'itid' => $itid,
  1255. 'invoiceTotal' => $itDetail ['invoiceTotal'] - 1
  1256. );
  1257. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1258. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1259. }
  1260. /**
  1261. * 批量删除库里发票
  1262. */
  1263. function invoiceStoreBatchDelete() {
  1264. Doo::loadClass ( 'XDeode' );
  1265. $XDeode = new XDeode ( 5 );
  1266. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1267. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1268. if (empty ( $trainKey ) || empty ( $storeKey ))
  1269. die ( 'illegal request-IdKey' );
  1270. $tid = $XDeode->decode ( $trainKey );
  1271. if (! is_numeric ( $tid ) && ! empty ( $storeKey ))
  1272. die ( 'illegal request' );
  1273. Doo::loadModel ( 'invoiceStore' );
  1274. $isidKeyList = explode ( ',', $storeKey );
  1275. $isidList = array ();
  1276. foreach ( $isidKeyList as $value ) {
  1277. $isid = $XDeode->decode ( $value );
  1278. if (! empty ( $isid ) && is_numeric ( $isid ))
  1279. array_push ( $isidList, $isid );
  1280. }
  1281. $isidString = implode ( ',', $isidList );
  1282. $invoiceStore = new invoiceStore ();
  1283. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,apStatus' );
  1284. $isidList = array ();
  1285. foreach ( $isList as $key => $value ) {
  1286. if ($value ['apStatus'] == 0)
  1287. array_push ( $isidList, $value ['isid'] );
  1288. }
  1289. $isidString = implode ( ',', $isidList );
  1290. // print_r($isList);
  1291. // echo $isidString;
  1292. $invoiceStore = new invoiceStore ();
  1293. $invoiceStore->delete ( array (
  1294. 'where' => "isid in ( " . $isidString . ")",
  1295. 'asArray' => TRUE
  1296. ) );
  1297. Doo::loadModel ( 'invoiceTraining' );
  1298. $invoiceTraining = new invoiceTraining ();
  1299. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1300. $item = array (
  1301. 'itid' => $tid,
  1302. 'invoiceTotal' => $itDetail ['invoiceTotal'] - count ( $isidList )
  1303. );
  1304. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1305. // echo $tid;
  1306. // echo $storeKey;
  1307. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1308. }
  1309. /**
  1310. * 仓库发票提交审批
  1311. * @return string
  1312. */
  1313. function invoiceStoreApproval() {
  1314. Doo::loadClass ( 'XDeode' );
  1315. $XDeode = new XDeode ( 5 );
  1316. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1317. $iStoreKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1318. $isid = $XDeode->decode ( $iStoreKey );
  1319. $trainId = $XDeode->decode ( $trainKey );
  1320. if (! is_numeric ( $isid ))
  1321. die ( 'illegal request' );
  1322. Doo::loadModel ( 'invoiceStore' );
  1323. Doo::loadModel ( 'invoice' );
  1324. $invoice = new invoice ();
  1325. // 加入限制必须填写入开票内容和邮寄物品
  1326. $invoiceStore = new invoiceStore ();
  1327. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid, 'isid,trainId ,invoiceElement,mailItemsJson' );
  1328. if (empty ( $isDetail ['invoiceElement'] ) || empty ( $isDetail ['mailItemsJson'] )) {
  1329. header ( 'Content-Type:text/html;charset=utf-8' );
  1330. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1331. }
  1332. // 拷贝插入一条发票数据
  1333. $invoiceStore = new invoiceStore ();
  1334. $iid = $invoiceStore->setInvoiceStoreToApproval ( $isid );
  1335. $invoiceStore = new invoiceStore ();
  1336. $item = array (
  1337. 'isid' => $isid,
  1338. 'iid' => $iid,
  1339. 'apStatus' => 1
  1340. );
  1341. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1342. Doo::loadModel ( 'invoiceManage' );
  1343. $invoiceManage = new invoiceManage ();
  1344. Doo::loadModel ( 'invoiceOperationLog' );
  1345. $invoiceOperationLog = new invoiceOperationLog ();
  1346. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1347. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1348. $moldManage = array ();
  1349. foreach ( $invoiceManageList as $key => $value ) {
  1350. if ($value ['mold'] == '发票打印')
  1351. $moldManage [$value ['mold']] = $value ['staffList'];
  1352. elseif ($value ['mold'] == '发票邮寄')
  1353. $moldManage [$value ['mold']] = $value ['staffList'];
  1354. elseif ($value ['mold'] == '发票退票')
  1355. $moldManage [$value ['mold']] = $value ['staffList'];
  1356. }
  1357. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1358. $item = array (
  1359. 'iid' => $iid,
  1360. 'isid' => $isid,
  1361. 'invoiceSerial' => "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  1362. 'date' => date ( "Y-m-d H:i:s" ),
  1363. 'status' => 1,
  1364. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1365. 'trainId' => $trainId,
  1366. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1367. 'moldManage' => json_encode ( $moldManage ),
  1368. 'settlementType' => 1,
  1369. 'pendingApprovals' => $pendingApprovalsSid
  1370. );
  1371. $invoice->setInvoiceByCondition ( $item );
  1372. Doo::loadModel ( 'invoiceTraining' );
  1373. $invoiceTraining = new invoiceTraining ();
  1374. $item = array (
  1375. 'itid' => $trainId,
  1376. 'submitStatus' => 1
  1377. );
  1378. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1379. $item = array (
  1380. 'date' => date ( "Y-m-d H:i:s" ),
  1381. 'operation' => "创建",
  1382. 'status' => 1,
  1383. 'img' => $this->staff [0] ['avatar'],
  1384. 'username' => $this->staff [0] ['username'],
  1385. 'uid' => $this->staff [0] ['sid'],
  1386. 'category' => $this->staff [0] ['category'],
  1387. 'iid' => $iid
  1388. );
  1389. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1390. $item = array (
  1391. 'date' => date ( "Y-m-d H:i:s" ),
  1392. 'operation' => "提交审批",
  1393. 'status' => 1,
  1394. 'img' => $this->staff [0] ['avatar'],
  1395. 'username' => $this->staff [0] ['username'],
  1396. 'uid' => $this->staff [0] ['sid'],
  1397. 'category' => $this->staff [0] ['category'],
  1398. 'iid' => $iid
  1399. );
  1400. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1401. Doo::loadModel ( 'staff' );
  1402. $staff = new staff ();
  1403. $username2 = $staff->getOne ( array (
  1404. 'select' => 'wxid',
  1405. 'where' => 'sid=' . $pendingApprovalsSid,
  1406. 'asArray' => TRUE
  1407. ) );
  1408. // 发送微信审批通知
  1409. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1410. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1411. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1412. }
  1413. /**
  1414. * 批量提交发票
  1415. * @return string
  1416. */
  1417. function invoiceStoreBatchApproval() {
  1418. Doo::loadClass ( 'XDeode' );
  1419. $XDeode = new XDeode ( 5 );
  1420. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1421. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1422. if (empty ( $trainKey ) || empty ( $storeKey ))
  1423. die ( 'illegal request-IdKey' );
  1424. $trainId = $XDeode->decode ( $trainKey );
  1425. $isidKeyList = explode ( ',', $storeKey );
  1426. $isidList = array ();
  1427. foreach ( $isidKeyList as $value ) {
  1428. $isid = $XDeode->decode ( $value );
  1429. if (! empty ( $isid ) && is_numeric ( $isid ))
  1430. array_push ( $isidList, $isid );
  1431. }
  1432. $isidString = implode ( ',', $isidList );
  1433. if (! is_numeric ( $trainId ))
  1434. die ( 'illegal request' );
  1435. Doo::loadModel ( 'invoiceStore' );
  1436. Doo::loadModel ( 'invoice' );
  1437. // 判断哪些已经加入审批过
  1438. // 加入限制必须填写入开票内容和邮寄物品
  1439. $invoiceStore = new invoiceStore ();
  1440. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,trainId ,invoiceElement,mailItemsJson' );
  1441. foreach ( $isList as $key => $value ) {
  1442. if (empty ( $value ['invoiceElement'] ) || empty ( $value ['mailItemsJson'] )) {
  1443. header ( 'Content-Type:text/html;charset=utf-8' );
  1444. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1445. }
  1446. }
  1447. // 拷贝插入一条发票数据
  1448. $invoiceStore = new invoiceStore ();
  1449. $invoiceStore->setInvoiceStoreBatchToApproval ( $isidString );
  1450. $invoiceStore = new invoiceStore ();
  1451. $item = array (
  1452. 'apStatus' => 1
  1453. );
  1454. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1455. // 获得正式发票ID
  1456. $invoice = new invoice ();
  1457. $iidList = $invoice->getInvoiceByIstoreid ( $isidString, 'iid,isid' );
  1458. $sqlList = array ();
  1459. $iidString = '';
  1460. $iida = array ();
  1461. foreach ( $iidList as $key => $value ) {
  1462. $sqlList [$value ['isid']] = $value ['iid'];
  1463. array_push ( $iida, $value ['iid'] );
  1464. }
  1465. $iidString = implode ( ',', $iida );
  1466. $ids = implode ( ',', array_keys ( $sqlList ) );
  1467. $sql = "UPDATE CLD_invoiceStore SET iid = CASE isid ";
  1468. foreach ( $sqlList as $id => $ordinal ) {
  1469. $sql .= sprintf ( "WHEN %d THEN %d ", $id, $ordinal );
  1470. }
  1471. $sql .= "END WHERE isid IN ($ids)";
  1472. $invoiceStore = new invoiceStore ();
  1473. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1474. Doo::loadModel ( 'invoiceManage' );
  1475. $invoiceManage = new invoiceManage ();
  1476. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1477. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1478. $moldManage = array ();
  1479. foreach ( $invoiceManageList as $key => $value ) {
  1480. if ($value ['mold'] == '发票打印')
  1481. $moldManage [$value ['mold']] = $value ['staffList'];
  1482. elseif ($value ['mold'] == '发票邮寄')
  1483. $moldManage [$value ['mold']] = $value ['staffList'];
  1484. elseif ($value ['mold'] == '发票退票')
  1485. $moldManage [$value ['mold']] = $value ['staffList'];
  1486. }
  1487. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1488. // 批量更新发票信息
  1489. $item = array (
  1490. 'date' => date ( "Y-m-d H:i:s" ),
  1491. 'status' => 1,
  1492. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1493. 'trainId' => $trainId,
  1494. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1495. 'moldManage' => json_encode ( $moldManage ),
  1496. 'settlementType' => 1,
  1497. 'pendingApprovals' => $pendingApprovalsSid
  1498. );
  1499. $invoice = new invoice ();
  1500. $invoice->BatchInvoiceByCondition ( $item, $iidString );
  1501. // 批量更新发票中仓库isid
  1502. $sql = "UPDATE CLD_invoiceStore SET isid = CASE iid ";
  1503. foreach ( $sqlList as $isid => $iid ) {
  1504. $sql .= sprintf ( "WHEN %d THEN %d ", $iid, $isid );
  1505. }
  1506. $sql .= "END WHERE iid IN ($iidString)";
  1507. $invoice = new invoice ();
  1508. $invoice->UpdateBatchInvoice ( $sql );
  1509. // 批量更新发票序列号
  1510. $sqlList = array ();
  1511. foreach ( $iida as $value ) {
  1512. $sqlList [$value] = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1513. }
  1514. $ids = implode ( ',', array_keys ( $sqlList ) );
  1515. $sql = "UPDATE CLD_invoice SET invoiceSerial = CASE iid ";
  1516. foreach ( $sqlList as $id => $ordinal ) {
  1517. $sql .= sprintf ( "WHEN %d THEN '%s' ", $id, $ordinal );
  1518. }
  1519. $sql .= "END WHERE iid IN ($ids)";
  1520. $invoiceStore = new invoiceStore ();
  1521. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1522. // 批量生产操作日志
  1523. Doo::loadModel ( 'invoiceOperationLog' );
  1524. $sqlList = array ();
  1525. foreach ( $iida as $key => $value ) {
  1526. $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 . '"),
  1527. ("' . 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 . '") ';
  1528. array_push ( $sqlList, $sql );
  1529. }
  1530. $iolSql = implode ( ',', $sqlList );
  1531. $sql = "INSERT INTO `CLD_invoiceOperationLog` (`date`, `operation`, `status`, `img`, `username`, `uid`, `category`, `iid`) VALUES " . $iolSql;
  1532. $invoiceOperationLog = new invoiceOperationLog ();
  1533. $invoiceOperationLog->setInvoiceOperationLogBySql ( $sql );
  1534. Doo::loadModel ( 'invoiceTraining' );
  1535. $invoiceTraining = new invoiceTraining ();
  1536. $item = array (
  1537. 'itid' => $trainId,
  1538. 'submitStatus' => 1
  1539. );
  1540. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1541. Doo::loadModel ( 'staff' );
  1542. $staff = new staff ();
  1543. $username2 = $staff->getOne ( array (
  1544. 'select' => 'wxid',
  1545. 'where' => 'sid=' . $pendingApprovalsSid,
  1546. 'asArray' => TRUE
  1547. ) );
  1548. // 发送微信审批通知
  1549. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1550. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1551. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1552. }
  1553. /**
  1554. */
  1555. function invoiceStoreMailItemSet() {
  1556. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1557. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1558. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1559. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1560. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1561. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1562. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1563. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1564. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1565. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1566. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1567. Doo::loadClass ( 'XDeode' );
  1568. $XDeode = new XDeode ( 5 );
  1569. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1570. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1571. $isid = $XDeode->decode ( $storeKey );
  1572. $trainId = $XDeode->decode ( $trainKey );
  1573. if (! is_numeric ( $isid ))
  1574. die ( 'illegal request' );
  1575. Doo::loadModel ( 'invoiceStore' );
  1576. $invoiceStore = new invoiceStore ();
  1577. $mailList = array (
  1578. 'invoice' => 1,
  1579. 'mailItems' => $mailItems
  1580. );
  1581. if (! empty ( $softLock ))
  1582. $mailList += array (
  1583. 'softLock' => $softLockNum
  1584. );
  1585. else
  1586. $mailList += array (
  1587. 'softLock' => 0
  1588. );
  1589. if (! empty ( $contract ))
  1590. $mailList += array (
  1591. 'contract' => $contractNum
  1592. );
  1593. else
  1594. $mailList += array (
  1595. 'contract' => 0
  1596. );
  1597. if (! empty ( $instructions ))
  1598. $mailList += array (
  1599. 'instructions' => $instructionsNum
  1600. );
  1601. else
  1602. $mailList += array (
  1603. 'instructions' => 0
  1604. );
  1605. if (! empty ( $remittance ))
  1606. $mailList += array (
  1607. 'remittance' => $remittance
  1608. );
  1609. else
  1610. $mailList += array (
  1611. 'remittance' => ''
  1612. );
  1613. $mailString = '发票x1,备注:' . $mailItems;
  1614. if (! empty ( $softLock ))
  1615. $mailString .= ',软件锁x' . $softLockNum;
  1616. if (! empty ( $contract ))
  1617. $mailString .= ',合同x' . $contractNum;
  1618. if (! empty ( $instructions ))
  1619. $mailString .= ',说明书x' . $instructionsNum;
  1620. if (! empty ( $remittance ))
  1621. $mailString .= ',汇款账号单';
  1622. $item = array (
  1623. 'isid' => $isid,
  1624. 'doPost' => 1,
  1625. 'mailItems' => $mailString,
  1626. 'mailItemsJson' => json_encode ( $mailList )
  1627. );
  1628. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1629. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1630. }
  1631. /**
  1632. * 批量设置邮寄物品
  1633. */
  1634. function invoiceStoreBatchMailItemSet() {
  1635. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1636. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1637. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1638. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1639. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1640. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1641. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1642. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1643. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1644. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1645. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1646. Doo::loadClass ( 'XDeode' );
  1647. $XDeode = new XDeode ( 5 );
  1648. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1649. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1650. if (empty ( $trainKey ) || empty ( $storeKey ))
  1651. die ( 'illegal request-IdKey' );
  1652. $isidKeyList = explode ( ',', $storeKey );
  1653. $isidList = array ();
  1654. foreach ( $isidKeyList as $value ) {
  1655. $isid = $XDeode->decode ( $value );
  1656. if (! empty ( $isid ) && is_numeric ( $isid ))
  1657. array_push ( $isidList, $isid );
  1658. }
  1659. $isidString = implode ( ',', $isidList );
  1660. $trainId = $XDeode->decode ( $trainKey );
  1661. if (! is_numeric ( $isid ))
  1662. die ( 'illegal request' );
  1663. Doo::loadModel ( 'invoiceStore' );
  1664. $invoiceStore = new invoiceStore ();
  1665. $mailList = array (
  1666. 'invoice' => 1,
  1667. 'mailItems' => $mailItems
  1668. );
  1669. if (! empty ( $softLock ))
  1670. $mailList += array (
  1671. 'softLock' => $softLockNum
  1672. );
  1673. else
  1674. $mailList += array (
  1675. 'softLock' => 0
  1676. );
  1677. if (! empty ( $contract ))
  1678. $mailList += array (
  1679. 'contract' => $contractNum
  1680. );
  1681. else
  1682. $mailList += array (
  1683. 'contract' => 0
  1684. );
  1685. if (! empty ( $instructions ))
  1686. $mailList += array (
  1687. 'instructions' => $instructionsNum
  1688. );
  1689. else
  1690. $mailList += array (
  1691. 'instructions' => 0
  1692. );
  1693. if (! empty ( $remittance ))
  1694. $mailList += array (
  1695. 'remittance' => $remittance
  1696. );
  1697. else
  1698. $mailList += array (
  1699. 'remittance' => ''
  1700. );
  1701. $mailString = '发票x1,备注:' . $mailItems;
  1702. if (! empty ( $softLock ))
  1703. $mailString .= ',软件锁x' . $softLockNum;
  1704. if (! empty ( $contract ))
  1705. $mailString .= ',合同x' . $contractNum;
  1706. if (! empty ( $instructions ))
  1707. $mailString .= ',说明书x' . $instructionsNum;
  1708. if (! empty ( $remittance ))
  1709. $mailString .= ',汇款账号单';
  1710. $item = array (
  1711. 'doPost' => 1,
  1712. 'mailItems' => $mailString,
  1713. 'mailItemsJson' => json_encode ( $mailList )
  1714. );
  1715. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1716. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1717. }
  1718. /**
  1719. * 废弃
  1720. */
  1721. function ajaxGetMailItemByIstore() {
  1722. Doo::loadClass ( 'XDeode' );
  1723. $XDeode = new XDeode ( 5 );
  1724. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1725. $isid = $XDeode->decode ( $storeKey );
  1726. if (! is_numeric ( $isid ))
  1727. die ( 'illegal request' );
  1728. Doo::loadModel ( 'invoiceStore' );
  1729. $invoiceStore = new invoiceStore ();
  1730. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid );
  1731. $isDetail ['mailItemsJson'] = json_decode ( $isDetail ['mailItemsJson'], true );
  1732. echo json_encode ( $isDetail ['mailItemsJson'] );
  1733. exit ();
  1734. }
  1735. /**
  1736. * 终止开票
  1737. */
  1738. function invoiceDroppedDo() {
  1739. $droppedIidKey = $this->get_args ( 'droppedIidKey' ) ? $this->get_args ( 'droppedIidKey' ) : '';
  1740. Doo::loadModel ( 'invoice' );
  1741. $invoice = new invoice ();
  1742. Doo::loadModel ( 'invoiceOperationLog' );
  1743. $invoiceOperationLog = new invoiceOperationLog ();
  1744. $iid = $invoice->authcode ( $droppedIidKey );
  1745. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1746. die ( 'illegal request' );
  1747. $item = array (
  1748. 'iid' => $iid,
  1749. 'status' => 4,
  1750. 'updateTime' => date ( "Y-m-d H:i:s" )
  1751. );
  1752. $invoice->setInvoiceByCondition ( $item );
  1753. $item = array (
  1754. 'date' => date ( "Y-m-d H:i:s" ),
  1755. 'operation' => '终止了开票',
  1756. 'status' => 4,
  1757. 'img' => $this->staff [0] ['avatar'],
  1758. 'username' => $this->staff [0] ['username'],
  1759. 'uid' => $this->staff [0] ['sid'],
  1760. 'category' => $this->staff [0] ['category'],
  1761. 'iid' => $iid
  1762. );
  1763. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1764. return "/invoice";
  1765. }
  1766. /**
  1767. * 更新退票的邮寄信息
  1768. */
  1769. function invoiceUntreadMailDo() {
  1770. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  1771. $untreadCompany = $this->get_args ( 'untreadCompany' ) ? $this->get_args ( 'untreadCompany' ) : "";
  1772. $untreadNumber = $this->get_args ( 'untreadNumber' ) ? $this->get_args ( 'untreadNumber' ) : "";
  1773. $untreadItems = $this->get_args ( 'untreadItems' ) ? $this->get_args ( 'untreadItems' ) : "";
  1774. Doo::loadModel ( 'invoice' );
  1775. $invoice = new invoice ();
  1776. $iid = $invoice->authcode ( $untreadIidKey );
  1777. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1778. die ( 'illegal request' );
  1779. $item = array (
  1780. 'iid' => $iid,
  1781. 'untreadCompany' => $untreadCompany,
  1782. 'untreadNumber' => $untreadNumber,
  1783. 'untreadItems' => $untreadItems
  1784. );
  1785. $invoice->setInvoiceByCondition ( $item );
  1786. return "/invoice";
  1787. }
  1788. /**
  1789. * 申请退票 --
  1790. */
  1791. function invoiceUntreadDo() {
  1792. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  1793. $untreadReason = $this->get_args ( 'untreadReason' ) ? $this->get_args ( 'untreadReason' ) : "";
  1794. $untreadPost = $this->get_args ( 'untreadPost' ) ? $this->get_args ( 'untreadPost' ) : "";
  1795. Doo::loadModel ( 'invoice' );
  1796. $invoice = new invoice ();
  1797. Doo::loadModel ( 'invoiceOperationLog' );
  1798. $invoiceOperationLog = new invoiceOperationLog ();
  1799. Doo::loadModel ( 'invoiceReceivables' );
  1800. $invoiceReceivables = new invoiceReceivables ();
  1801. $iid = $invoice->authcode ( $untreadIidKey );
  1802. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1803. die ( 'illegal request' );
  1804. /*
  1805. * 需求变革 有绑定收款也可以退票 $lt = $invoiceReceivables->getInvoiceReceivablesByIid ( $untreadIidKey ); if (! empty ( $lt )) { header ( 'Content-Type:text/html;charset=utf-8' ); die ( '该发票有收款绑定,请先移除!' ); }
  1806. */
  1807. $item = array (
  1808. 'iid' => $iid,
  1809. 'untreadStatus' => 1,
  1810. 'untreadReason' => $untreadReason,
  1811. 'untreadPost' => $untreadPost,
  1812. 'updateTime' => date ( "Y-m-d H:i:s" )
  1813. );
  1814. $invoice->setInvoiceByCondition ( $item );
  1815. $item = array (
  1816. 'date' => date ( "Y-m-d H:i:s" ),
  1817. 'operation' => '申请退票',
  1818. 'status' => 7,
  1819. 'img' => $this->staff [0] ['avatar'],
  1820. 'username' => $this->staff [0] ['username'],
  1821. 'uid' => $this->staff [0] ['sid'],
  1822. 'category' => $this->staff [0] ['category'],
  1823. 'iid' => $iid
  1824. );
  1825. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1826. return "/invoice";
  1827. }
  1828. /**
  1829. * 删除已终止的开票
  1830. */
  1831. function invoiceDelDo() {
  1832. Doo::loadModel ( 'invoice' );
  1833. $invoice = new invoice ();
  1834. Doo::loadModel ( 'invoiceOperationLog' );
  1835. $invoiceOperationLog = new invoiceOperationLog ();
  1836. Doo::loadClass ( 'XDeode' );
  1837. $XDeode = new XDeode ( 5 );
  1838. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  1839. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  1840. $iid = $XDeode->decode ( $iid );
  1841. Doo::loadModel ( 'invoiceStore' );
  1842. $invoiceStore = new invoiceStore ();
  1843. if (! is_numeric ( $iid ))
  1844. die ( 'illegal request' );
  1845. $invoiceDetail = $invoice->getMyInvoice ( $sid, $iid );
  1846. if (empty ( $invoiceDetail ))
  1847. die ( 'illegal request' );
  1848. $item = array (
  1849. 'iid' => $iid,
  1850. 'isDelete' => 1,
  1851. 'updateTime' => date ( "Y-m-d H:i:s" )
  1852. );
  1853. $invoice->setInvoiceByCondition ( $item );
  1854. $item = array (
  1855. 'date' => date ( "Y-m-d H:i:s" ),
  1856. 'operation' => '删除了已终止的发票',
  1857. 'status' => 4,
  1858. 'img' => $this->staff [0] ['avatar'],
  1859. 'username' => $this->staff [0] ['username'],
  1860. 'uid' => $this->staff [0] ['sid'],
  1861. 'category' => $this->staff [0] ['category'],
  1862. 'iid' => $iid
  1863. );
  1864. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1865. // 删除培训班发票仓库里的发票
  1866. $invoiceStore->delInvoiceStoreByIsid ( $invoiceDetail ['isid'] );
  1867. return "/invoice";
  1868. }
  1869. /**
  1870. */
  1871. function invoiceApproval() {
  1872. Doo::loadModel ( 'invoice' );
  1873. $invoice = new invoice ();
  1874. Doo::loadClass ( 'XDeode' );
  1875. $XDeode = new XDeode ( 5 );
  1876. Doo::loadModel ( 'staff' );
  1877. $staff = new staff ();
  1878. $invoiceList = $invoice->find ( array (
  1879. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  1880. 'desc' => 'iid',
  1881. 'limit' => 10,
  1882. 'asArray' => true
  1883. ) );
  1884. foreach ( $invoiceList as $key => $value ) {
  1885. $invoiceList [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1886. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1887. if (! empty ( $lastApprover )) {
  1888. $lastApproverKey = array_keys ( $lastApprover );
  1889. $lastApprover = end ( $lastApprover );
  1890. $staffDetail = $staff->getOne ( array (
  1891. 'where' => 'sid=' . end ( $lastApproverKey ),
  1892. 'asArray' => true
  1893. ) );
  1894. $lastApprover ['username'] = $staffDetail ['username'];
  1895. }
  1896. $invoiceList [$key] ['lastApprover'] = $lastApprover;
  1897. }
  1898. $ilist = $invoice->getInvoiceByProcessStatus ();
  1899. foreach ( $ilist as $key => $value ) {
  1900. $ilist [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1901. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1902. if (! empty ( $lastApprover )) {
  1903. $lastApproverKey = array_keys ( $lastApprover );
  1904. $lastApprover = end ( $lastApprover );
  1905. $staffDetail = $staff->getOne ( array (
  1906. 'where' => 'sid=' . end ( $lastApproverKey ),
  1907. 'asArray' => true
  1908. ) );
  1909. $lastApprover ['username'] = $staffDetail ['username'];
  1910. }
  1911. $ilist [$key] ['lastApprover'] = $lastApprover;
  1912. }
  1913. // print_r($ilist);
  1914. $this->data ['invoiceList'] = $invoiceList;
  1915. $this->data ['ilist'] = $ilist;
  1916. $this->data ['memu'] = "invoice";
  1917. $this->data ['staff'] = $this->staff;
  1918. $this->data ['receiptMemu'] = 'invoiceApproval';
  1919. $this->render ( "/admin/invoiceApproval", $this->data );
  1920. }
  1921. function invoiceDetail() {
  1922. Doo::loadClass ( 'XDeode' );
  1923. $XDeode = new XDeode ( 5 );
  1924. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  1925. $iid = $XDeode->decode ( $iid );
  1926. if (! is_numeric ( $iid ))
  1927. die ( 'illegal request' );
  1928. Doo::loadModel ( 'invoice' );
  1929. $invoice = new invoice ();
  1930. Doo::loadModel ( 'invoiceOperationLog' );
  1931. $invoiceOperationLog = new invoiceOperationLog ();
  1932. $invoiceDetail = $invoice->getOne ( array (
  1933. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'] . ' and iid=' . $iid,
  1934. 'asArray' => true
  1935. ) );
  1936. if (empty ( $invoiceDetail ))
  1937. die ( 'illegal request' );
  1938. if ($invoiceDetail ['settlementType'] == 1) {
  1939. Doo::loadModel ( 'invoiceTraining' );
  1940. $invoiceTraining = new invoiceTraining ();
  1941. $invoiceDetail ['invoiceTraining'] = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceDetail ['trainId'] );
  1942. }
  1943. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  1944. $this->data ['invoiceDetail'] = $invoiceDetail;
  1945. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  1946. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  1947. $this->data ['memu'] = "invoice";
  1948. $this->data ['staff'] = $this->staff;
  1949. $this->data ['receiptMemu'] = 'invoiceApproval';
  1950. $this->render ( "/admin/invoiceApprovalDetail", $this->data );
  1951. }
  1952. /**
  1953. * 对发票进行审批,其中操作有终止,退回,同意动作。操作成功并记录下操作日志
  1954. *
  1955. * @since 1.0.0
  1956. * @var integer iid 开票ID 已加密
  1957. * @var integer status 发票审批状态
  1958. * @var integer opintion 审批发票的意见
  1959. * @return string 如操作成功返回审批首页
  1960. */
  1961. function invoiceApprovalDo() {
  1962. Doo::loadModel ( 'invoice' );
  1963. $invoice = new invoice ();
  1964. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  1965. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  1966. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  1967. $divApproval = $this->get_args ( 'divApproval' ) ? $this->get_args ( 'divApproval' ) : "";
  1968. $iid = $invoice->authcode ( $iid );
  1969. if (! is_numeric ( $iid ))
  1970. die ( 'illegal request' );
  1971. // && ! empty ( $opinion )
  1972. if (! empty ( $iid ) && ! empty ( $status )) {
  1973. if (! ($status == 2 || $status == 3 || $status == 4))
  1974. die ( 'illegal request' );
  1975. Doo::loadModel ( 'invoiceOperationLog' );
  1976. $invoiceOperationLog = new invoiceOperationLog ();
  1977. $invoiceDetail = $invoice->getOne ( array (
  1978. 'where' => 'status=1 and iid=' . $iid . ' and pendingApprovals=' . $this->staff [0] ['sid'],
  1979. 'asArray' => true
  1980. ) );
  1981. if (empty ( $invoiceDetail ))
  1982. die ( 'illegal request' );
  1983. $processApprovals = json_decode ( $invoiceDetail ['processApprovals'], true );
  1984. $invoiceManage = json_decode ( $invoiceDetail ['invoiceManage'], true );
  1985. if ($status == 3) {
  1986. $invoice->status = $status;
  1987. $item = array (
  1988. 'operation' => $opinion
  1989. );
  1990. } else {
  1991. if (empty ( $processApprovals )) {
  1992. $processApprovals = array (
  1993. $this->staff [0] ['sid'] => array (
  1994. 'date' => date ( "Y-m-d H:i:s" ),
  1995. 'opinion' => $opinion,
  1996. 'status' => $status
  1997. )
  1998. );
  1999. // var_dump(next($invoiceManage));
  2000. $nextInvoiceManage = next ( $invoiceManage );
  2001. // print_r($nextInvoiceManage);
  2002. if ($status != 4 && $nextInvoiceManage !== false)
  2003. $invoice->pendingApprovals = $nextInvoiceManage [0];
  2004. $invoice->processApprovals = json_encode ( $processApprovals );
  2005. // var_dump($invoice);
  2006. // print_r($invoiceManage);
  2007. } else {
  2008. $processApprovals [$this->staff [0] ['sid']] = array (
  2009. 'date' => date ( "Y-m-d H:i:s" ),
  2010. 'opinion' => $opinion,
  2011. 'status' => $status
  2012. );
  2013. $pendingApprovals = 0;
  2014. foreach ( $invoiceManage as $key => $value ) {
  2015. if ($value [0] == $this->staff [0] ['sid']) {
  2016. if (isset ( $invoiceManage [$key + 1] ))
  2017. $pendingApprovals = $invoiceManage [$key + 1] [0];
  2018. break;
  2019. }
  2020. }
  2021. if ($status != 4 && ! empty ( $pendingApprovals ))
  2022. $invoice->pendingApprovals = $pendingApprovals;
  2023. $invoice->processApprovals = json_encode ( $processApprovals );
  2024. }
  2025. $item = array (
  2026. 'operation' => $opinion
  2027. );
  2028. if (count ( $processApprovals ) == count ( $invoiceManage ) && $status != 4) {
  2029. $invoice->status = $status;
  2030. $invoice->pendingApprovals = 0;
  2031. $invoice->approvalTime = date ( "Y-m-d H:i:s" );
  2032. } elseif ($status == 4) {
  2033. $invoice->status = $status;
  2034. $item = array (
  2035. 'operation' => $opinion
  2036. );
  2037. }
  2038. }
  2039. $invoice->updateTime = date ( "Y-m-d H:i:s" );
  2040. $invoice->update ( array (
  2041. 'where' => 'iid=' . $iid
  2042. ) );
  2043. $item += array (
  2044. 'date' => date ( "Y-m-d H:i:s" ),
  2045. 'img' => $this->staff [0] ['avatar'],
  2046. 'username' => $this->staff [0] ['username'],
  2047. 'uid' => $this->staff [0] ['sid'],
  2048. 'category' => $this->staff [0] ['category'],
  2049. 'status' => $status,
  2050. 'iid' => $iid
  2051. );
  2052. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2053. if (empty ( $divApproval ))
  2054. return '/invoiceApproval';
  2055. else
  2056. return '/invoiceApprovalAchieve/PEND';
  2057. }
  2058. die ( 'illegal request' );
  2059. }
  2060. /**
  2061. * 展示需要打印的发票数据
  2062. *
  2063. * @since 1.0.0
  2064. */
  2065. function invoicePrint() {
  2066. Doo::loadModel ( 'invoice' );
  2067. $invoice = new invoice ();
  2068. Doo::loadClass ( 'XDeode' );
  2069. $XDeode = new XDeode ( 5 );
  2070. Doo::loadModel ( 'staff' );
  2071. $staff = new staff ();
  2072. $toPrint = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0 );
  2073. $printed = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 1 );
  2074. foreach ( $toPrint as $key => $value ) {
  2075. $toPrint [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2076. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2077. if (! empty ( $lastApprover )) {
  2078. $lastApproverKey = array_keys ( $lastApprover );
  2079. $lastApprover = end ( $lastApprover );
  2080. $staffDetail = $staff->getOne ( array (
  2081. 'where' => 'sid=' . end ( $lastApproverKey ),
  2082. 'asArray' => true
  2083. ) );
  2084. $lastApprover ['username'] = $staffDetail ['username'];
  2085. }
  2086. $toPrint [$key] ['lastApprover'] = $lastApprover;
  2087. }
  2088. foreach ( $printed as $key => $value ) {
  2089. $printed [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2090. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2091. if (! empty ( $lastApprover )) {
  2092. $lastApproverKey = array_keys ( $lastApprover );
  2093. $lastApprover = end ( $lastApprover );
  2094. $staffDetail = $staff->getOne ( array (
  2095. 'where' => 'sid=' . end ( $lastApproverKey ),
  2096. 'asArray' => true
  2097. ) );
  2098. $lastApprover ['username'] = $staffDetail ['username'];
  2099. }
  2100. $printed [$key] ['lastApprover'] = $lastApprover;
  2101. }
  2102. $this->data ['printed'] = $printed;
  2103. $this->data ['toPrint'] = $toPrint;
  2104. $this->data ['memu'] = "invoice";
  2105. $this->data ['staff'] = $this->staff;
  2106. $this->data ['receiptMemu'] = 'invoicePrint';
  2107. $this->render ( "/admin/invoicePrint", $this->data );
  2108. }
  2109. /**
  2110. * 展示发票打印的详情页面
  2111. *
  2112. * @since 1.0.0
  2113. */
  2114. function invoicePrintDetail() {
  2115. Doo::loadClass ( 'XDeode' );
  2116. $XDeode = new XDeode ( 5 );
  2117. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  2118. $iid = $XDeode->decode ( $iid );
  2119. if (! is_numeric ( $iid ))
  2120. die ( 'illegal request' );
  2121. Doo::loadModel ( 'invoice' );
  2122. $invoice = new invoice ();
  2123. Doo::loadModel ( 'invoiceOperationLog' );
  2124. $invoiceOperationLog = new invoiceOperationLog ();
  2125. Doo::loadModel ( 'invoicePaper' );
  2126. $invoicePaper = new invoicePaper ();
  2127. $invoiceDetail = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0, $iid );
  2128. if (empty ( $invoiceDetail ))
  2129. die ( 'illegal request' );
  2130. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $invoiceDetail ['invoiceType'] );
  2131. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  2132. if ($invoiceDetail ['settlementType'] == 1) {
  2133. Doo::loadModel ( 'invoiceTraining' );
  2134. $invoiceTraining = new invoiceTraining ();
  2135. $invoiceDetail ['invoiceTraining'] = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceDetail ['trainId'] );
  2136. }
  2137. $this->data ['invoicePaperList'] = $invoicePaperList;
  2138. $this->data ['invoiceDetail'] = $invoiceDetail;
  2139. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  2140. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  2141. $this->data ['memu'] = "invoice";
  2142. $this->data ['staff'] = $this->staff;
  2143. $this->data ['receiptMemu'] = 'invoicePrint';
  2144. $this->render ( "/admin/invoicePrintDetail", $this->data );
  2145. }
  2146. /**
  2147. * 所有待打印 发票
  2148. */
  2149. function invoicePrintStayAchieve() {
  2150. Doo::loadModel ( 'invoice' );
  2151. $invoice = new invoice ();
  2152. Doo::loadClass ( 'XDeode' );
  2153. $XDeode = new XDeode ( 5 );
  2154. Doo::loadModel ( 'staff' );
  2155. $staff = new staff ();
  2156. $MebSea = $this->get_args ( 'MebSea' ) ? urldecode ( $this->get_args ( 'MebSea' ) ) : "";
  2157. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  2158. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  2159. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  2160. Doo::loadModel ( 'invoiceTraining' );
  2161. $invoiceTraining = new invoiceTraining ();
  2162. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  2163. $page_size = 12;
  2164. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2165. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : "ALL";
  2166. // $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : "ALL";
  2167. $get = "/" . $status;
  2168. $con = ' and status=2 ';
  2169. if ($status == 'TOPRINT')
  2170. $con = ' and status=2 and printStatus=0 ';
  2171. elseif ($status == 'PRINTED')
  2172. $con = ' and status=2 and printStatus=1';
  2173. if ($invoiceType == 'ORDINARY')
  2174. $con .= ' and invoiceType=0 ';
  2175. elseif ($invoiceType == 'SPECIAL')
  2176. $con .= ' and invoiceType=1 ';
  2177. if ($invoiceTrain == 'ORDINARY')
  2178. $con .= ' and trainId=0 ';
  2179. elseif ($invoiceTrain == 'TRAIN')
  2180. $con .= ' and trainId!=0 ';
  2181. if ($invoiceTrainName != 'ALL') {
  2182. $trainId = $XDeode->decode ( $invoiceTrainName );
  2183. if (is_numeric ( $trainId ))
  2184. $con .= ' and trainId =' . $trainId;
  2185. }
  2186. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2187. $dateArr = explode ( ':', $date );
  2188. $D1 = '';
  2189. $D2 = '';
  2190. if (! empty ( $date )) {
  2191. $D1 = $dateArr [0];
  2192. $D2 = $dateArr [1];
  2193. }
  2194. if (! empty ( $D1 ) && ! empty ( $D2 ) && ! empty ( $date ))
  2195. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2196. if (! empty ( $MebSea )) {
  2197. $con .= ' and ( invoiceNo like "%' . $MebSea . '%" or invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  2198. }
  2199. $pageinfo ['page'] = array (
  2200. 'previous' => ''
  2201. );
  2202. $get .= "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&invoiceType=" . urlencode ( $invoiceType ) . "&invoiceTrain=" . urlencode ( $invoiceTrain ) . "";
  2203. $sql = " (untreadStatus=0 or untreadStatus=3) and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  2204. $action = "invoicePrintStayAchieve";
  2205. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2206. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2207. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  2208. $this->data ['trainList'] = $trainList;
  2209. $this->data ['invoiceType'] = $invoiceType;
  2210. $this->data ['invoiceTrain'] = $invoiceTrain;
  2211. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  2212. $this->data ['MebSeaEn'] = $MebSea;
  2213. $this->data ['MebSea'] = urlencode ( $MebSea );
  2214. $this->data ['get'] = $get;
  2215. $this->data ['page'] = $pageinfo;
  2216. $this->data ['date'] = $date;
  2217. $this->data ['status'] = $status;
  2218. $this->data ['invoiceType'] = $invoiceType;
  2219. $this->data ['memu'] = "invoice";
  2220. $this->data ['staff'] = $this->staff;
  2221. foreach ( $list as $key => $value ) {
  2222. $list [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2223. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2224. if (! empty ( $lastApprover )) {
  2225. $lastApproverKey = array_keys ( $lastApprover );
  2226. $lastApprover = end ( $lastApprover );
  2227. $staffDetail = $staff->getOne ( array (
  2228. 'where' => 'sid=' . end ( $lastApproverKey ),
  2229. 'asArray' => true
  2230. ) );
  2231. $lastApprover ['username'] = $staffDetail ['username'];
  2232. }
  2233. $list [$key] ['lastApprover'] = $lastApprover;
  2234. }
  2235. $this->data ['receiptMemu'] = 'invoicePrint';
  2236. $this->data ['list'] = $list;
  2237. $this->render ( "/admin/invoicePrintStayAchieve", $this->data );
  2238. }
  2239. /**
  2240. * 填写票号并完成打印
  2241. * @since 1.0.0
  2242. */
  2243. function invoicePrintDo() {
  2244. Doo::loadModel ( 'invoice' );
  2245. $invoice = new invoice ();
  2246. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2247. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  2248. $invoicePrintType = $this->get_args ( 'invoicePrintType' ) ? $this->get_args ( 'invoicePrintType' ) : "";
  2249. $iid = $invoice->authcode ( $iid );
  2250. if (! is_numeric ( $iid ))
  2251. die ( 'illegal request' );
  2252. if (! empty ( $iid ) && ! empty ( $invoiceNo )) {
  2253. Doo::loadModel ( 'invoiceOperationLog' );
  2254. $invoiceOperationLog = new invoiceOperationLog ();
  2255. Doo::loadModel ( 'invoiceStatistics' );
  2256. $invoiceStatistics = new invoiceStatistics ();
  2257. $XDeode = new XDeode ( 5 );
  2258. Doo::loadModel ( 'invoicePaper' );
  2259. $invoicePaper = new invoicePaper ();
  2260. $invoicePrintDetail = $invoice->getInvoiceByPrint ( $iid );
  2261. if (empty ( $invoicePrintDetail ))
  2262. die ( 'illegal request' );
  2263. //
  2264. $ipid = $XDeode->decode ( $invoiceNo );
  2265. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  2266. if (empty ( $paperDetail ))
  2267. die ( 'illegal request' );
  2268. $invoicePaper = new invoicePaper ();
  2269. $item = array (
  2270. 'iid' => $iid,
  2271. 'ipid' => $ipid
  2272. );
  2273. $invoicePaper->setInvoicePaperByCondition ( $item );
  2274. $item = array (
  2275. 'iid' => $iid,
  2276. 'printStatus' => 1,
  2277. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2278. 'printer' => $this->staff [0] ['username'],
  2279. 'printTime' => date ( "Y-m-d H:i:s" ),
  2280. 'invoiceNo' => $paperDetail ['invoiceNo']
  2281. );
  2282. $invoice->setInvoiceByCondition ( $item );
  2283. $item = array (
  2284. 'date' => date ( "Y-m-d H:i:s" ),
  2285. 'operation' => '打印发票号:' . $paperDetail ['invoiceNo'],
  2286. 'status' => 5,
  2287. 'img' => $this->staff [0] ['avatar'],
  2288. 'username' => $this->staff [0] ['username'],
  2289. 'uid' => $this->staff [0] ['sid'],
  2290. 'category' => $this->staff [0] ['category'],
  2291. 'iid' => $iid
  2292. );
  2293. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2294. // 去统计--负票不汇总
  2295. if ($invoicePrintDetail ['untreadStatus'] != 4) {
  2296. $item = array (
  2297. 'date' => date ( "Y-m-d H:i:s" ),
  2298. 'priceClass' => 1,
  2299. 'cid' => $invoicePrintDetail ['cid'],
  2300. 'staff' => $invoicePrintDetail ['sid'],
  2301. 'invoicePrice' => $invoicePrintDetail ['invoicePrice']
  2302. );
  2303. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2304. }
  2305. // 发送通知信息到微信-去除
  2306. // $this->setWXMsg($iid,'PRINT');
  2307. // 申请人获取微信通知
  2308. Doo::loadModel ( 'staff' );
  2309. $staff = new staff ();
  2310. Doo::loadClass ( 'XDeode' );
  2311. $XDeode = new XDeode ( 5 );
  2312. $username2 = $staff->getOne ( array (
  2313. 'select' => 'wxid',
  2314. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2315. 'asArray' => TRUE
  2316. ) );
  2317. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '完成打印';
  2318. $msg = '';
  2319. $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/' . $XDeode->encode ( $invoicePrintDetail ['iid'] ) . '.html';
  2320. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2321. if (empty ( $invoicePrintType ))
  2322. return "/invoicePrint";
  2323. else
  2324. return "/invoicePrintStayAchieve";
  2325. }
  2326. }
  2327. /**
  2328. * 需要邮寄的发票
  2329. * @since 1.0.0
  2330. */
  2331. function invoicePost() {
  2332. Doo::loadModel ( 'invoice' );
  2333. $invoice = new invoice ();
  2334. Doo::loadModel ( 'express' );
  2335. $express = new express ();
  2336. $invoicePost = $invoice->getPostByInvoice ();
  2337. $invoicePosted = $invoice->getPostByInvoice ( 1 );
  2338. $expressList = $express->getExpressByAll ();
  2339. $invoicePostExpress = "";
  2340. if (isset ( $_COOKIE ["invoicePostExpress"] ))
  2341. $invoicePostExpress = $_COOKIE ["invoicePostExpress"];
  2342. $this->data ['invoicePostExpress'] = $invoicePostExpress;
  2343. $this->data ['expressList'] = $expressList;
  2344. $this->data ['invoicePost'] = $invoicePost;
  2345. $this->data ['invoicePosted'] = $invoicePosted;
  2346. $this->data ['memu'] = "invoice";
  2347. $this->data ['staff'] = $this->staff;
  2348. $this->data ['receiptMemu'] = 'invoicePost';
  2349. $this->render ( "/admin/invoicePost", $this->data );
  2350. }
  2351. /**
  2352. * 添加发票邮寄信息
  2353. */
  2354. function invoiceExpressAddDo() {
  2355. Doo::loadModel ( 'invoice' );
  2356. $invoice = new invoice ();
  2357. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2358. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2359. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2360. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2361. $iid = $iid = $invoice->authcode ( $iid );
  2362. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2363. die ( 'illegal request' );
  2364. $invoicePrintDetail = $invoice->getInvoiceByIid ( $iid );
  2365. setcookie ( 'invoicePostExpress', $expressNumber );
  2366. $item = array (
  2367. 'iid' => $iid,
  2368. 'postStatus' => 1,
  2369. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2370. 'postTime' => date ( "Y-m-d H:i:s" ),
  2371. 'expressCompany' => $expressCompany,
  2372. 'expressNumber' => $expressNumber,
  2373. 'actualItems' => $actualItems,
  2374. 'poster' => $this->staff [0] ['username']
  2375. );
  2376. $invoice->setInvoiceByCondition ( $item );
  2377. // 微信通知-去掉
  2378. // $this->setWXMsg ( $iid );
  2379. Doo::loadModel ( 'staff' );
  2380. $staff = new staff ();
  2381. Doo::loadClass ( 'XDeode' );
  2382. $XDeode = new XDeode ( 5 );
  2383. $username2 = $staff->getOne ( array (
  2384. 'select' => 'wxid',
  2385. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2386. 'asArray' => TRUE
  2387. ) );
  2388. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '已邮寄';
  2389. $expCom = explode ( ":", $invoicePrintDetail ['expressCompany'] );
  2390. if (empty ( $expCom ))
  2391. $expCom [0] = '';
  2392. $msg = $expCom [0] . ':' . $invoicePrintDetail ['expressNumber'] . '';
  2393. $url = 'https://m.kuaidi100.com/result.jsp?nu=' . $invoicePrintDetail ['expressNumber'];
  2394. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2395. return '/invoicePost';
  2396. }
  2397. function invoiceExpressUpdateDo() {
  2398. Doo::loadModel ( 'invoice' );
  2399. $invoice = new invoice ();
  2400. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  2401. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2402. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2403. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2404. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2405. $iid = $invoice->authcode ( $iid );
  2406. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2407. die ( 'illegal request' );
  2408. $item = array (
  2409. 'iid' => $iid,
  2410. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2411. 'expressCompany' => $expressCompany,
  2412. 'expressNumber' => $expressNumber,
  2413. 'actualItems' => $actualItems,
  2414. 'poster' => $this->staff [0] ['username']
  2415. );
  2416. $invoice->setInvoiceByCondition ( $item );
  2417. return $action;
  2418. }
  2419. /**
  2420. * 可退票管理
  2421. */
  2422. function invoiceUntreadIsAchieve() {
  2423. Doo::loadModel ( 'invoice' );
  2424. $invoice = new invoice ();
  2425. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2426. /*
  2427. * 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' => '' );
  2428. */
  2429. if (empty ( $MebSea )) {
  2430. $con = ' and invoiceNo like "NULL" ';
  2431. } else {
  2432. $con = ' and (invoiceNo like "%' . $MebSea . '%" or invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  2433. }
  2434. // printStatus=1 and
  2435. $sql = " (untreadStatus=0 or untreadStatus=3) and status=2 and sid=" . $this->staff [0] ['sid'] . $con;
  2436. /*
  2437. * $action = "invoiceUntreadIsAchieve"; $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" ); $limit = $pageinfo ['lower'] . ',' . $page_size;
  2438. */
  2439. $limit = '0,20';
  2440. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2441. // print_r($list);
  2442. $this->data ['MebSeaEn'] = $MebSea;
  2443. /*
  2444. * $this->data ['get'] = $get; $this->data ['page'] = $pageinfo; $this->data ['date'] = $date;
  2445. */
  2446. $this->data ['list'] = $list;
  2447. $this->data ['memu'] = "invoice";
  2448. $this->data ['staff'] = $this->staff;
  2449. $this->data ['receiptMemu'] = 'invoice';
  2450. $this->render ( "/admin/invoiceUntreadIsAchieve", $this->data );
  2451. }
  2452. // 已经退票的发票
  2453. function invoiceUntreadED() {
  2454. Doo::loadModel ( 'invoice' );
  2455. $invoice = new invoice ();
  2456. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2457. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "";
  2458. Doo::loadClass ( 'XDeode' );
  2459. $XDeode = new XDeode ( 5 );
  2460. $page_size = 18;
  2461. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2462. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2463. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  2464. $dateArr = explode ( ':', $date );
  2465. $D1 = '';
  2466. $D2 = '';
  2467. if (! empty ( $date )) {
  2468. $D1 = $dateArr [0];
  2469. $D2 = $dateArr [1];
  2470. }
  2471. $con = '';
  2472. if (! empty ( $D1 ) && ! empty ( $D2 )){
  2473. $con = ' and bindTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2474. }
  2475. // if ($date == 'MONTHO')
  2476. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  2477. // elseif ($date == 'MONTHT')
  2478. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  2479. // elseif ($date == 'MONTHY')
  2480. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  2481. if (! empty ( $MebSea )) {
  2482. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  2483. }
  2484. if ($invoiceType == 'ORDINARY'){
  2485. $con .= ' and invoiceType=0 ';
  2486. }elseif ($invoiceType == 'SPECIAL'){
  2487. $con .= ' and invoiceType=1 ';
  2488. }
  2489. $pageinfo ['page'] = array (
  2490. 'previous' => ''
  2491. );
  2492. // printStatus=1 and
  2493. $sql = " (untreadStatus=2 ) and status=2 and sid=" . $this->staff [0] ['sid'] . $con;
  2494. $action = "invoiceUntreadED";
  2495. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2496. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2497. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2498. // print_r($list);
  2499. $this->data ['MebSeaEn'] = $MebSea;
  2500. $this->data ['get'] = $get;
  2501. $this->data ['page'] = $pageinfo;
  2502. $this->data ['date'] = $date;
  2503. $this->data ['invoiceType'] = $invoiceType;
  2504. $this->data ['list'] = $list;
  2505. $this->data ['memu'] = "invoice";
  2506. $this->data ['staff'] = $this->staff;
  2507. $this->data ['receiptMemu'] = 'invoice';
  2508. $this->render ( "/admin/invoiceUntreadED", $this->data );
  2509. }
  2510. /**
  2511. * 退票处理页面
  2512. */
  2513. function invoiceUntread() {
  2514. Doo::loadModel ( 'invoice' );
  2515. $invoice = new invoice ();
  2516. $untreadInvoice = $invoice->getInvoiceByUntreadStatus ( 1, 0, 50 );
  2517. $establishedInvoice = $invoice->getInvoiceByUntreadStatus ( 2 );
  2518. foreach ( $establishedInvoice as $key => $value ) {
  2519. // months
  2520. $lossDate = strtotime ( "+1 month", strtotime ( $value ['OperationLog'] ['date'] ) );
  2521. $nowDate = strtotime ( 'now' );
  2522. $establishedInvoice [$key] ['lossShow'] = false;
  2523. if ($lossDate < $nowDate)
  2524. $establishedInvoice [$key] ['lossShow'] = true;
  2525. }
  2526. $this->data ['untreadInvoice'] = $untreadInvoice;
  2527. $this->data ['establishedInvoice'] = $establishedInvoice;
  2528. $this->data ['memu'] = "invoice";
  2529. $this->data ['staff'] = $this->staff;
  2530. $this->data ['receiptMemu'] = 'invoiceUntread';
  2531. $this->render ( "/admin/invoiceUntread", $this->data );
  2532. }
  2533. /**
  2534. * 确认收到退回的发票,开票状态为退回 //收款状态解绑,公司统计扣除入账额度
  2535. */
  2536. function invoiceUntreadEstablishedDo() {
  2537. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  2538. Doo::loadModel ( 'invoice' );
  2539. $invoice = new invoice ();
  2540. Doo::loadModel ( 'invoiceOperationLog' );
  2541. $invoiceOperationLog = new invoiceOperationLog ();
  2542. Doo::loadModel ( 'invoiceReceivables' );
  2543. Doo::loadModel ( 'invoiceStatistics' );
  2544. $iid = $invoice->authcode ( $untreadIidKey );
  2545. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2546. die ( 'illegal request' );
  2547. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  2548. if ($invoiceDetails ['untreadStatus'] != 1)
  2549. die ( 'illegal request' );
  2550. $item = array (
  2551. 'iid' => $iid,
  2552. // 'irid'=>'',
  2553. 'untreadStatus' => 2,
  2554. 'updateTime' => date ( "Y-m-d H:i:s" )
  2555. );
  2556. $invoice->setInvoiceByCondition ( $item );
  2557. $item = array (
  2558. 'date' => date ( "Y-m-d H:i:s" ),
  2559. 'operation' => '已确认退票',
  2560. 'status' => 6,
  2561. 'img' => $this->staff [0] ['avatar'],
  2562. 'username' => $this->staff [0] ['username'],
  2563. 'uid' => $this->staff [0] ['sid'],
  2564. 'category' => $this->staff [0] ['category'],
  2565. 'iid' => $iid
  2566. );
  2567. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2568. // 收款解绑以及入账扣除 收款扣除
  2569. if (! empty ( $invoiceDetails ['irid'] )) {
  2570. $iridList = explode ( ',', $invoiceDetails ['irid'] );
  2571. foreach ( $iridList as $value ) {
  2572. $invoiceReceivables = new invoiceReceivables ();
  2573. $irDetails = $invoiceReceivables->getOne ( array (
  2574. 'where' => " irid=" . $value . ' and bindStatus=1',
  2575. 'asArray' => TRUE
  2576. ) );
  2577. $item = array (
  2578. 'irid' => $value,
  2579. 'bindStatus' => 0,
  2580. 'untreadStatus' => 1,
  2581. 'untreadStaff' => $invoiceDetails ['userName'],
  2582. 'unbundlingTime' => date ( "Y-m-d H:i:s" ),
  2583. 'iid' => 0
  2584. );
  2585. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2586. if (! empty ( $irDetails )) {
  2587. // 扣除入账
  2588. $invoiceStatistics = new invoiceStatistics ();
  2589. $item = array (
  2590. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2591. 'priceClass' => 3,
  2592. 'cid' => $invoiceDetails ['cid'],
  2593. 'staff' => $invoiceDetails ['sid'],
  2594. 'accountPrice' => - $irDetails ['receivablesPrice']
  2595. );
  2596. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2597. // 扣除收款
  2598. $invoiceStatistics = new invoiceStatistics ();
  2599. $item = array (
  2600. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2601. 'priceClass' => 2,
  2602. 'cid' => $invoiceDetails ['cid'],
  2603. 'staff' => $invoiceDetails ['sid'],
  2604. 'irid' => $irDetails ['irid'],
  2605. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  2606. );
  2607. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2608. }
  2609. // 解绑时删除收入流水
  2610. Doo::loadModel ( 'wasteBook' );
  2611. $wasteBook = new wasteBook ();
  2612. $wasteBook->delete ( array (
  2613. 'where' => 'dataID=' . $value . ' and accountType=7',
  2614. 'limit' => 1
  2615. ) );
  2616. }
  2617. }
  2618. return "/invoiceUntread";
  2619. }
  2620. function invoiceUntreadRecallDo(){
  2621. $iidKey = isset ( $this->params ['iidKey'] ) ? $this->params ['iidKey'] : "";
  2622. Doo::loadModel ( 'invoice' );
  2623. $invoice = new invoice ();
  2624. Doo::loadClass ( 'XDeode' );
  2625. $XDeode = new XDeode ( 5 );
  2626. Doo::loadModel ( 'invoiceOperationLog' );
  2627. $invoiceOperationLog = new invoiceOperationLog ();
  2628. $iid = $XDeode->decode ( $iidKey );
  2629. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  2630. if (empty($invoiceDetail)){
  2631. die ( 'illegal request-DATANULL' );
  2632. }
  2633. $item = array (
  2634. 'iid' => $iid,
  2635. 'untreadStatus' => 0,
  2636. );
  2637. $invoice->setInvoiceByCondition ( $item );
  2638. $item = array (
  2639. 'date' => date ( "Y-m-d H:i:s" ),
  2640. 'operation' => '撤回申请退票',
  2641. 'status' => 13,
  2642. 'img' => $this->staff [0] ['avatar'],
  2643. 'username' => $this->staff [0] ['username'],
  2644. 'uid' => $this->staff [0] ['sid'],
  2645. 'category' => $this->staff [0] ['category'],
  2646. 'iid' => $iid
  2647. );
  2648. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2649. return "/invoiceUntread";
  2650. }
  2651. /**
  2652. * 建立负票,关联原来发票
  2653. */
  2654. function invoiceLossDo() {
  2655. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2656. if (! empty ( $iidKey )) {
  2657. Doo::loadClass ( 'XDeode' );
  2658. $XDeode = new XDeode ( 5 );
  2659. Doo::loadModel ( 'invoice' );
  2660. $invoice = new invoice ();
  2661. Doo::loadModel ( 'invoiceOperationLog' );
  2662. $invoiceOperationLog = new invoiceOperationLog ();
  2663. $iidKey = $XDeode->decode ( $iidKey );
  2664. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  2665. // 拷贝插入一条发票数据
  2666. $iid = $invoice->setInvoiceLoss ( $iidKey );
  2667. // 更新负票
  2668. $invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  2669. $invoice = new invoice ();
  2670. $item = array (
  2671. 'iid' => $iid,
  2672. 'sid' => $this->staff [0] ['sid'],
  2673. 'userName' => $this->staff [0] ['username'],
  2674. 'cid' => $this->staff [0] ['cid'],
  2675. 'categoryName' => $this->staff [0] ['category'],
  2676. 'invoiceQuantity' => - $invoiceDetail ['invoiceQuantity'],
  2677. 'invoicePrice' => - $invoiceDetail ['invoicePrice'],
  2678. 'invoiceSerial' => $invoiceSerial,
  2679. 'invoiceNo' => '',
  2680. 'printStatus' => 0,
  2681. 'untreadStatus' => 4,
  2682. // 关联发票号
  2683. 'lossIid' => $invoiceDetail ['iid']
  2684. );
  2685. $invoice->setInvoiceByCondition ( $item );
  2686. // 更新原发票
  2687. $invoice = new invoice ();
  2688. $item = array (
  2689. 'iid' => $invoiceDetail ['iid'],
  2690. 'lossIid' => $iid
  2691. );
  2692. $invoice->setInvoiceByCondition ( $item );
  2693. // 操作日志
  2694. $item = array (
  2695. 'date' => date ( "Y-m-d H:i:s" ),
  2696. 'operation' => "创建负票" . $invoiceSerial,
  2697. 'status' => 12,
  2698. 'img' => $this->staff [0] ['avatar'],
  2699. 'username' => $this->staff [0] ['username'],
  2700. 'uid' => $this->staff [0] ['sid'],
  2701. 'category' => $this->staff [0] ['category'],
  2702. 'iid' => $iid
  2703. );
  2704. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2705. // print_r($invoiceDetail);
  2706. // echo $iid;die;
  2707. }
  2708. return '/invoiceUntread';
  2709. }
  2710. /**
  2711. * 上传银行到账 收款文件
  2712. */
  2713. function invoiceReceivablesBankUpload() {
  2714. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  2715. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  2716. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  2717. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  2718. header ( "HTTP/1.1 500 Internal Server Error" );
  2719. echo "POST exceeded maximum allowed size.";
  2720. exit ( 0 );
  2721. }
  2722. // Settings
  2723. $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)
  2724. $upload_name = "Filedata";
  2725. $file_name = "";
  2726. $nk = time ();
  2727. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  2728. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  2729. echo "文件无法保存.";
  2730. exit ( 0 );
  2731. }
  2732. echo json_encode ( array (
  2733. 'filename' => $file_name,
  2734. 'id' => $nk
  2735. ) );
  2736. exit ( 0 );
  2737. }
  2738. /**
  2739. * 解析银行到账收款execl并导入库中
  2740. */
  2741. function invoiceReceivablesImport() {
  2742. $path = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  2743. if ($path != "") {
  2744. Doo::loadModel ( 'invoiceReceivables' );
  2745. $invoiceReceivables = new invoiceReceivables ();
  2746. Doo::loadClass ( 'invoice.func' );
  2747. Doo::loadModel ( 'invoiceROLog' );
  2748. $invoiceROLog = new invoiceROLog ();
  2749. Doo::loadModel ( 'invoiceStatistics' );
  2750. $invoiceStatistics = new invoiceStatistics ();
  2751. $exlArray = formatExcelToArrayBank ( DOO::conf ()->SITE_PATH . "upload/invoiceReceivablesBank/" . $path );
  2752. $bankBatchNumber = 'BBN_' . time ();
  2753. Doo::db ()->beginTransaction ();
  2754. // 批量存储收款--由于必须获得收款ID,
  2755. $sql = 'INSERT INTO CLD_invoiceReceivables (OriginalPrice,receivablesPrice, receivablesMessage,receivablesSerial,receivablesBank,receivablesDate,inputStaff,date,receivablesCategory,receivablesStaff,bankBatchNumber,recepitTitleMark)
  2756. VALUES ';
  2757. $date = date ( "Y-m-d" );
  2758. $receivablesList = array ();
  2759. foreach ( $exlArray as $key => $value ) {
  2760. $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"] . '")';
  2761. array_push ( $receivablesList, $receivablesSql );
  2762. }
  2763. $sql = $sql . implode ( ',', $receivablesList );
  2764. // echo $sql;
  2765. Doo::db ()->query ( $sql );
  2766. // 批量存储收款统计
  2767. // 获得刚刚导入数据的irid组-缺少办事处和人员
  2768. $iridList = $invoiceReceivables->getInvoiceReceivablesByBBN ( $bankBatchNumber );
  2769. // 没有irid 回滚所有操作
  2770. if (empty ( $iridList )) {
  2771. Doo::db ()->rollBack ();
  2772. header ( 'Content-Type:text/html;charset=utf-8' );
  2773. die ( '文档或数据不正确,请重新<a href="/invoiceReceivables">上传</a>.' );
  2774. }
  2775. $sql = 'INSERT INTO CLD_invoiceStatistics (date, priceClass,irid,receivablesPrice)
  2776. VALUES ';
  2777. $statisticsList = array ();
  2778. foreach ( $iridList as $value ) {
  2779. $statisticsSql = '("' . $date . '",2,' . $value ['irid'] . ',' . $value ["receivablesPrice"] . ')';
  2780. array_push ( $statisticsList, $statisticsSql );
  2781. }
  2782. $sql = $sql . implode ( ',', $statisticsList );
  2783. Doo::db ()->query ( $sql );
  2784. // 批量存储操作日志
  2785. $sql = 'INSERT INTO CLD_invoiceROLog (operation, date,status,img, username,uid,category,irid)
  2786. VALUES ';
  2787. $ROLogList = array ();
  2788. foreach ( $iridList as $value ) {
  2789. $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'] . '")';
  2790. array_push ( $ROLogList, $ROLogSql );
  2791. }
  2792. $sql = $sql . implode ( ',', $ROLogList );
  2793. Doo::db ()->query ( $sql );
  2794. // 批量写入流水
  2795. $sql = 'INSERT INTO CLD_wasteBook (dataID, expensesType,accountType,accountPriceShow, accountPrice,accountBank,category,cid,name,sid,inputDate)
  2796. VALUES ';
  2797. $wasteBookList = array ();
  2798. foreach ( $iridList as $value ) {
  2799. $accountBank = '';
  2800. if ($value ['receivablesBank'] == '纵横广发') {
  2801. $accountBank = 'CGBDeposit';
  2802. } elseif ($value ['receivablesBank'] == '纵横工行') {
  2803. $accountBank = 'ICBCDeposit';
  2804. } elseif ($value ['receivablesBank'] == '华润银行') {
  2805. $accountBank = 'HUADeposit';
  2806. } elseif ($value ['receivablesBank'] == '个人广发') {
  2807. $accountBank = 'PersonalDeposit';
  2808. }
  2809. $wasteBookSql = '("' . $value ['irid'] . ' ",1,7,"' . $value ['receivablesPrice'] . '","' . $value ['receivablesPrice'] . '","' . $accountBank . '",
  2810. "' . $this->staff [0] ['category'] . '","' . $this->staff [0] ['cid'] . '","' . $this->staff [0] ['username'] . '","' . $this->staff [0] ['sid'] . '","' . date ( "Y-m-d H:i:s" ) . '")';
  2811. array_push ( $wasteBookList, $wasteBookSql );
  2812. }
  2813. $sql = $sql . implode ( ',', $wasteBookList );
  2814. Doo::db ()->query ( $sql );
  2815. Doo::db ()->commit ();
  2816. return "/invoiceReceivables";
  2817. }
  2818. echo 'no file';
  2819. }
  2820. function invoiceReceivables() {
  2821. $invoiceTC = $this->get_args ( 'invoiceTC' ) ? $this->get_args ( 'invoiceTC' ) : '';
  2822. Doo::loadModel ( 'L_category' );
  2823. $lCategory = new L_category ();
  2824. Doo::loadModel ( 'staff' );
  2825. $staff = new staff ();
  2826. Doo::loadModel ( 'invoiceReceivables' );
  2827. $invoiceReceivables = new invoiceReceivables ();
  2828. Doo::loadModel ( 'invoice' );
  2829. $invoice = new invoice ();
  2830. Doo::loadClass ( 'XDeode' );
  2831. $XDeode = new XDeode ( 5 );
  2832. $category = $lCategory->getCategory ();
  2833. $staffList = $staff->getStaffByCid ( $this->staff [0] ['cid'] );
  2834. $sql = 'bindStatus=1 and iid!=0';
  2835. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByNew ( 4, $sql );
  2836. // 获取未入账发票
  2837. $invoiceUnAccount = $invoice->getInvoiceByUnAccount ( $invoiceTC );
  2838. $invoiceExistAccount = $invoice->getInvoiceByUnAccount ( '', true );
  2839. foreach ( $invoiceUnAccount as $key => $value ) {
  2840. $invoiceUnAccount [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2841. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2842. if (! empty ( $lastApprover )) {
  2843. $lastApproverKey = array_keys ( $lastApprover );
  2844. $lastApprover = end ( $lastApprover );
  2845. $staffDetail = $staff->getOne ( array (
  2846. 'where' => 'sid=' . end ( $lastApproverKey ),
  2847. 'asArray' => true
  2848. ) );
  2849. $lastApprover ['username'] = $staffDetail ['username'];
  2850. }
  2851. $invoiceUnAccount [$key] ['lastApprover'] = $lastApprover;
  2852. }
  2853. foreach ( $invoiceExistAccount as $key => $value ) {
  2854. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  2855. if (empty ( $irList ))
  2856. $irList [0] ['sumPrice'] = 0;
  2857. $balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  2858. $invoiceExistAccount [$key] ['existAccount'] = $irList [0] ['sumPrice'];
  2859. $invoiceExistAccount [$key] ['balance'] = $balance;
  2860. }
  2861. $receivablesInput = $invoiceReceivables->getInvoiceReceivablesByInput ();
  2862. $halfList = $invoiceReceivables->getInvoiceReceivablesByHalf ();
  2863. $this->data ['halfList'] = $halfList;
  2864. $this->data ['halfCount'] = count ( $halfList );
  2865. // print_r($receivablesList);
  2866. $this->data ['receivablesDate'] = date ( "Y-m-d" );
  2867. $this->data ['ieaCount'] = count ( $invoiceExistAccount );
  2868. $this->data ['invoiceExistAccount'] = $invoiceExistAccount;
  2869. $this->data ['receivablesInput'] = $receivablesInput;
  2870. $this->data ['year'] = date ( 'Y' );
  2871. $this->data ['invoiceUnAccount'] = $invoiceUnAccount;
  2872. $this->data ['receivablesList'] = $receivablesList;
  2873. $this->data ['staffList'] = $staffList;
  2874. $this->data ['category'] = $category;
  2875. $this->data ['memu'] = "invoice";
  2876. $this->data ['staff'] = $this->staff;
  2877. $this->data ['receiptMemu'] = 'invoiceReceivables';
  2878. $this->render ( "/admin/invoiceReceivables", $this->data );
  2879. }
  2880. /**
  2881. * 设置收款认领地区
  2882. */
  2883. function setInvoiceReceivablesClaim() {
  2884. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  2885. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  2886. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  2887. if (! empty ( $iridKey ) && ! empty ( $receivablesCategory )) {
  2888. Doo::loadModel ( 'invoiceReceivables' );
  2889. $invoiceReceivables = new invoiceReceivables ();
  2890. Doo::loadClass ( 'XDeode' );
  2891. $XDeode = new XDeode ( 5 );
  2892. Doo::loadModel ( 'invoiceROLog' );
  2893. $invoiceROLog = new invoiceROLog ();
  2894. $irid = $XDeode->decode ( $iridKey );
  2895. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  2896. if (empty ( $irDetail ))
  2897. die ( 'illegal request' );
  2898. $item = array (
  2899. 'irid' => $irid,
  2900. 'receivablesCategory' => $receivablesCategory
  2901. );
  2902. if ($receivablesCategory != 'PUBLIC') {
  2903. $item += array (
  2904. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  2905. 'inputType' => 1
  2906. );
  2907. }
  2908. $invoiceReceivables = new invoiceReceivables ();
  2909. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2910. // 收款操作日志
  2911. $item = array (
  2912. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 ",
  2913. 'date' => date ( "Y-m-d" ),
  2914. 'status' => 1,
  2915. 'img' => $this->staff [0] ['avatar'],
  2916. 'username' => $this->staff [0] ['username'],
  2917. 'uid' => $this->staff [0] ['sid'],
  2918. 'category' => $this->staff [0] ['category'],
  2919. 'irid' => $irid
  2920. );
  2921. $invoiceROLog->setInvoiceROLog ( $item );
  2922. if (empty ( $action ))
  2923. return '/invoiceReceivables';
  2924. else
  2925. return "/invoiceReceivablesAS";
  2926. }
  2927. die ( 'illegal request' );
  2928. }
  2929. /**
  2930. * 新添加收款直接入账发票
  2931. */
  2932. function invoiceCompareClaimPrice() {
  2933. // 收款录入
  2934. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2935. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  2936. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  2937. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  2938. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  2939. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $iidKey )) {
  2940. Doo::loadModel ( 'invoiceReceivables' );
  2941. $invoiceReceivables = new invoiceReceivables ();
  2942. Doo::loadModel ( 'invoiceROLog' );
  2943. $invoiceROLog = new invoiceROLog ();
  2944. Doo::loadModel ( 'invoiceStatistics' );
  2945. Doo::loadModel ( 'invoice' );
  2946. $invoice = new invoice ();
  2947. Doo::loadClass ( 'XDeode' );
  2948. $XDeode = new XDeode ( 5 );
  2949. Doo::loadModel ( 'invoiceOperationLog' );
  2950. $invoiceOperationLog = new invoiceOperationLog ();
  2951. $iidKey = $XDeode->decode ( $iidKey );
  2952. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  2953. if (! ($invoiceDetail ['status'] == 2 && $invoiceDetail ['printStatus'] == 1 && $invoiceDetail ['untreadStatus'] == 0))
  2954. die ( 'illegal request' );
  2955. $receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  2956. // 收款录入 并绑定发票
  2957. Doo::db ()->beginTransaction ();
  2958. $bindStatus = 0;
  2959. if ($receivablesPrice <= $invoiceDetail ['invoicePrice'])
  2960. $bindStatus = 1;
  2961. $titleMark = $invoiceDetail ['invoiceTitle'];
  2962. if (! empty ( $invoiceDetail ['invoiceCompany'] ))
  2963. $titleMark = $invoiceDetail ['invoiceCompany'];
  2964. $item = array (
  2965. 'recepitTitleMark' => $titleMark,
  2966. 'bindStatus' => $bindStatus,
  2967. 'iid' => $invoiceDetail ['iid'],
  2968. 'bindPrice' => $invoiceDetail ['invoicePrice'],
  2969. 'bindDate' => date ( "Y-m-d H:i:s" ),
  2970. 'receivablesPrice' => $receivablesPrice,
  2971. 'OriginalPrice' => $receivablesPrice,
  2972. 'receivablesMessage' => $receivablesMessage,
  2973. 'receivablesSerial' => $receivablesSerial,
  2974. 'receivablesBank' => $receivablesBank,
  2975. 'receivablesDate' => $receivablesDate,
  2976. 'inputStaff' => $this->staff [0] ['username'],
  2977. 'accountClerk' => $this->staff [0] ['username'],
  2978. 'date' => date ( "Y-m-d" ),
  2979. 'receivablesCategory' => $invoiceDetail ['cid'] . ':' . $invoiceDetail ['categoryName'],
  2980. 'receivablesStaff' => $invoiceDetail ['sid'] . '-' . $invoiceDetail ['userName'],
  2981. 'confirmTime' => date ( "Y-m-d H:i:s" )
  2982. );
  2983. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  2984. $item = array ();
  2985. // 收款操作日志
  2986. $item = array (
  2987. 'operation' => $this->staff [0] ['username'] . " 转入 " . $invoiceDetail ['userName']
  2988. );
  2989. $item += array (
  2990. 'date' => date ( "Y-m-d" ),
  2991. 'status' => 1,
  2992. 'img' => $this->staff [0] ['avatar'],
  2993. 'username' => $this->staff [0] ['username'],
  2994. 'uid' => $this->staff [0] ['sid'],
  2995. 'category' => $this->staff [0] ['category'],
  2996. 'irid' => $irid
  2997. );
  2998. $invoiceROLog->setInvoiceROLog ( $item );
  2999. // 收款统计
  3000. $invoiceStatistics = new invoiceStatistics ();
  3001. $item = array (
  3002. 'date' => $receivablesDate,
  3003. 'priceClass' => 2,
  3004. 'irid' => $irid,
  3005. 'cid' => $invoiceDetail ['cid'],
  3006. 'staff' => $invoiceDetail ['sid'],
  3007. 'receivablesPrice' => $receivablesPrice
  3008. );
  3009. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3010. // 收款 入 发票
  3011. $detail = $invoiceDetail;
  3012. $iridString = "";
  3013. if (empty ( $detail ['irid'] ))
  3014. $iridString = $irid;
  3015. else
  3016. $iridString = $detail ['irid'] . ',' . $irid;
  3017. $item = array (
  3018. 'irid' => $iridString,
  3019. 'bindTime' => date ( "Y-m-d H:i:s" ),
  3020. 'updateTime' => date ( "Y-m-d H:i:s" ),
  3021. 'iid' => $detail ['iid']
  3022. );
  3023. $invoiceReceivables = new invoiceReceivables ();
  3024. $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  3025. if ($detail ['invoicePrice'] <= $sum)
  3026. $item += array (
  3027. 'untreadStatus' => 3
  3028. );
  3029. $invoice->setInvoiceByCondition ( $item );
  3030. // 操作日志
  3031. $item = array (
  3032. 'date' => date ( "Y-m-d H:i:s" ),
  3033. 'operation' => "收款入账" . $receivablesSerial . "到发票" . $detail ['invoiceSerial'],
  3034. 'status' => 8,
  3035. 'img' => $this->staff [0] ['avatar'],
  3036. 'username' => $this->staff [0] ['username'],
  3037. 'uid' => $this->staff [0] ['sid'],
  3038. 'category' => $this->staff [0] ['category'],
  3039. 'iid' => $detail ['iid']
  3040. );
  3041. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3042. // 入账汇总
  3043. $invoiceStatistics = new invoiceStatistics ();
  3044. // $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $iridString );
  3045. // $accountPrice = 0;
  3046. // foreach ( $list as $key => $value ) {
  3047. // $accountPrice += $value ['receivablesPrice'];
  3048. // }
  3049. $item = array (
  3050. 'date' => $receivablesDate,
  3051. 'priceClass' => 3,
  3052. 'cid' => $invoiceDetail ['cid'],
  3053. 'staff' => $invoiceDetail ['sid'],
  3054. 'accountPrice' => $receivablesPrice
  3055. );
  3056. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3057. // 公司流水记录
  3058. Doo::loadModel ( 'wasteBook' );
  3059. $wasteBook = new wasteBook ();
  3060. $abDetail = $wasteBook->getAccountBookByAid ( 2, 7, $irid );
  3061. $accountBank = '';
  3062. if ($receivablesBank == '纵横广发') {
  3063. $accountBank = 'CGBDeposit';
  3064. } elseif ($receivablesBank == '纵横工行') {
  3065. $accountBank = 'ICBCDeposit';
  3066. } elseif ($receivablesBank == '华润银行') {
  3067. $accountBank = 'HUADeposit';
  3068. } elseif ($receivablesBank == '个人广发') {
  3069. $accountBank = 'PersonalDeposit';
  3070. }
  3071. if (empty ( $abDetail )) {
  3072. $item = array (
  3073. 'dataID' => $irid,
  3074. 'expensesType' => 1,
  3075. 'accountType' => 7,
  3076. 'accountPrice' => $receivablesPrice,
  3077. 'accountPriceShow' => $receivablesPrice,
  3078. 'accountBank' => $accountBank,
  3079. 'category' => $this->staff [0] ['category'],
  3080. 'cid' => $this->staff [0] ['cid'],
  3081. 'name' => $this->staff [0] ['username'],
  3082. 'sid' => $this->staff [0] ['sid'],
  3083. 'inputDate' => date ( "Y-m-d H:i:s" )
  3084. );
  3085. $wasteBook->setAccountBookStatistics ( $item );
  3086. }
  3087. Doo::db ()->commit ();
  3088. }
  3089. return '/invoiceReceivables';
  3090. }
  3091. /**
  3092. * 录入收款数据
  3093. * @return string
  3094. */
  3095. function invoiceReceivablesDo() {
  3096. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3097. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3098. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3099. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3100. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3101. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  3102. Doo::loadModel ( 'invoiceReceivables' );
  3103. $invoiceReceivables = new invoiceReceivables ();
  3104. Doo::loadModel ( 'invoiceROLog' );
  3105. $invoiceROLog = new invoiceROLog ();
  3106. Doo::loadModel ( 'invoiceStatistics' );
  3107. $invoiceStatistics = new invoiceStatistics ();
  3108. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $receivablesCategory ) && ! empty ( $receivablesStaff )) {
  3109. $item = array (
  3110. 'receivablesPrice' => $receivablesPrice,
  3111. 'OriginalPrice' => $receivablesPrice,
  3112. 'receivablesMessage' => $receivablesMessage,
  3113. 'receivablesSerial' => "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  3114. 'receivablesBank' => $receivablesBank,
  3115. 'receivablesDate' => $receivablesDate,
  3116. 'inputStaff' => $this->staff [0] ['username'],
  3117. 'date' => date ( "Y-m-d" ),
  3118. 'receivablesCategory' => $receivablesCategory,
  3119. 'receivablesStaff' => $receivablesStaff
  3120. );
  3121. if ($receivablesCategory != 'PUBLIC') {
  3122. $item += array (
  3123. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3124. 'inputType' => 1
  3125. );
  3126. }
  3127. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  3128. $item = array ();
  3129. // 收款操作日志
  3130. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3131. $item = array (
  3132. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  3133. );
  3134. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3135. $item = array (
  3136. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  3137. );
  3138. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3139. $receivablesStaff = explode ( '-', $receivablesStaff );
  3140. $item = array (
  3141. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  3142. );
  3143. }
  3144. $item += array (
  3145. 'date' => date ( "Y-m-d" ),
  3146. 'status' => 1,
  3147. 'img' => $this->staff [0] ['avatar'],
  3148. 'username' => $this->staff [0] ['username'],
  3149. 'uid' => $this->staff [0] ['sid'],
  3150. 'category' => $this->staff [0] ['category'],
  3151. 'irid' => $irid
  3152. );
  3153. $invoiceROLog->setInvoiceROLog ( $item );
  3154. $item = array (
  3155. 'date' => $receivablesDate,
  3156. 'priceClass' => 2,
  3157. 'irid' => $irid,
  3158. 'receivablesPrice' => $receivablesPrice
  3159. );
  3160. if ($receivablesCategory != 'PUBLIC') {
  3161. $receivablesCategory = explode ( ":", $receivablesCategory );
  3162. $item += array (
  3163. 'cid' => $receivablesCategory [0]
  3164. );
  3165. }
  3166. if ($receivablesStaff2 != 'PUBLIC') {
  3167. $receivablesStaff = explode ( "-", $receivablesStaff2 );
  3168. $item += array (
  3169. 'staff' => $receivablesStaff [0]
  3170. );
  3171. }
  3172. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3173. $toparty = $this->getWxidByCategory ( $receivablesCategory [1] );
  3174. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  3175. $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  3176. if ($toparty != 0)
  3177. $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  3178. // 公司流水记录
  3179. Doo::loadModel ( 'wasteBook' );
  3180. $wasteBook = new wasteBook ();
  3181. $abDetail = $wasteBook->getAccountBookByAid ( 1, 7, $irid );
  3182. $accountBank = '';
  3183. if ($receivablesBank == '纵横广发') {
  3184. $accountBank = 'CGBDeposit';
  3185. } elseif ($receivablesBank == '纵横工行') {
  3186. $accountBank = 'ICBCDeposit';
  3187. } elseif ($receivablesBank == '华润银行') {
  3188. $accountBank = 'HUADeposit';
  3189. } elseif ($receivablesBank == '个人广发') {
  3190. $accountBank = 'PersonalDeposit';
  3191. }
  3192. $item = array (
  3193. 'dataID' => $irid,
  3194. 'expensesType' => 1,
  3195. 'accountType' => 7,
  3196. 'accountPriceShow' => $receivablesPrice,
  3197. 'accountPrice' => $receivablesPrice,
  3198. 'accountBank' => $accountBank,
  3199. 'category' => $this->staff [0] ['category'],
  3200. 'cid' => $this->staff [0] ['cid'],
  3201. 'name' => $this->staff [0] ['username'],
  3202. 'sid' => $this->staff [0] ['sid'],
  3203. 'inputDate' => date ( "Y-m-d H:i:s" )
  3204. );
  3205. $wasteBook->setAccountBookStatistics ( $item );
  3206. }
  3207. return "/invoiceReceivables";
  3208. }
  3209. /**
  3210. * 收款认领页面-包括公共认领 办事处认领 最近已认领数据
  3211. */
  3212. function invoiceReceivablesClaim() {
  3213. Doo::loadModel ( 'invoiceReceivables' );
  3214. $invoiceReceivables = new invoiceReceivables ();
  3215. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  3216. $this->data ['receivablesList'] = $receivablesList;
  3217. $this->data ['memu'] = "invoice";
  3218. $this->data ['staff'] = $this->staff;
  3219. $this->data ['receiptMemu'] = 'invoiceReceivablesClaim';
  3220. $this->render ( "/admin/invoiceReceivablesClaim", $this->data );
  3221. }
  3222. function invoiceReceivablesTitleMarkSet() {
  3223. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  3224. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  3225. if (empty ( $iridKey ) || empty ( $recepitTitleMark ))
  3226. die ( 'illegal request' );
  3227. Doo::loadModel ( 'invoiceReceivables' );
  3228. $invoiceReceivables = new invoiceReceivables ();
  3229. Doo::loadClass ( 'XDeode' );
  3230. $XDeode = new XDeode ( 5 );
  3231. $irid = $XDeode->decode ( $iridKey );
  3232. if (! is_numeric ( $irid ))
  3233. die ( 'illegal request' );
  3234. $invoiceReceivables->recepitTitleMark = $recepitTitleMark;
  3235. $invoiceReceivables->update ( array (
  3236. 'where' => 'irid = ' . $irid
  3237. ) );
  3238. return '/invoiceReceivablesClaim';
  3239. }
  3240. /**
  3241. * 更新收款相关数据
  3242. */
  3243. function invoiceReceivablesUpdateClaim() {
  3244. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3245. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3246. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3247. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3248. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3249. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  3250. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  3251. if (empty ( $claimKey ))
  3252. die ( 'illegal request' );
  3253. Doo::loadModel ( 'invoiceReceivables' );
  3254. $invoiceReceivables = new invoiceReceivables ();
  3255. Doo::loadModel ( 'invoiceROLog' );
  3256. $invoiceROLog = new invoiceROLog ();
  3257. $con = ' and iid=0 and bindStatus=0'; // and receivablesCategory!="PUBLIC" and receivablesStaff!="PUBLIC"
  3258. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  3259. if (empty ( $detail ))
  3260. die ( 'illegal request' );
  3261. $invoiceReceivables = new invoiceReceivables ();
  3262. $item = array (
  3263. 'irid' => $detail ['irid']
  3264. );
  3265. if ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3266. $item += array (
  3267. 'confirmTime' => date ( "Y-m-d H:i:s" )
  3268. );
  3269. }
  3270. if (! empty ( $receivablesCategory ))
  3271. $item += array (
  3272. 'receivablesCategory' => $receivablesCategory
  3273. );
  3274. if (! empty ( $receivablesStaff ))
  3275. $item += array (
  3276. 'receivablesStaff' => $receivablesStaff
  3277. );
  3278. if (! empty ( $receivablesPrice ))
  3279. $item += array (
  3280. 'receivablesPrice' => $receivablesPrice
  3281. );
  3282. if (! empty ( $receivablesMessage ))
  3283. $item += array (
  3284. 'receivablesMessage' => $receivablesMessage
  3285. );
  3286. if (! empty ( $receivablesBank ))
  3287. $item += array (
  3288. 'receivablesBank' => $receivablesBank
  3289. );
  3290. if (! empty ( $receivablesDate ))
  3291. $item += array (
  3292. 'receivablesDate' => $receivablesDate
  3293. );
  3294. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3295. // 收款操作日志
  3296. $item = array ();
  3297. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3298. $item = array (
  3299. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  3300. );
  3301. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3302. $item = array (
  3303. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  3304. );
  3305. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3306. $receivablesStaff = explode ( '-', $receivablesStaff );
  3307. $item = array (
  3308. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  3309. );
  3310. }
  3311. $item += array (
  3312. 'date' => date ( "Y-m-d" ),
  3313. 'status' => 1,
  3314. 'img' => $this->staff [0] ['avatar'],
  3315. 'username' => $this->staff [0] ['username'],
  3316. 'uid' => $this->staff [0] ['sid'],
  3317. 'category' => $this->staff [0] ['category'],
  3318. 'irid' => $detail ['irid']
  3319. );
  3320. $invoiceROLog->setInvoiceROLog ( $item );
  3321. return '/invoiceReceivablesAS';
  3322. }
  3323. function invoiceReceivablesDelete() {
  3324. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  3325. $skll = $this->get_args ( 'skll' ) ? $this->get_args ( 'skll' ) : "";
  3326. if ($skll != '删除到款')
  3327. die ( 'illegal request' );
  3328. if (empty ( $claimKey ))
  3329. die ( 'illegal request' );
  3330. Doo::loadModel ( 'invoiceReceivables' );
  3331. $invoiceReceivables = new invoiceReceivables ();
  3332. $con = ' and bindStatus=0 ';
  3333. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  3334. if (empty ( $detail ))
  3335. die ( 'illegal request' );
  3336. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  3337. // 扣除收款汇总信息 汇总
  3338. Doo::loadModel ( 'invoiceStatistics' );
  3339. $invoiceStatistics = new invoiceStatistics ();
  3340. $item = array (
  3341. 'date' => $detail ['receivablesDate'],
  3342. 'priceClass' => 2,
  3343. 'irid' => $detail ['irid'],
  3344. 'receivablesPrice' => - $detail ['receivablesPrice']
  3345. );
  3346. if ($detail ['receivablesCategory'] != 'PUBLIC') {
  3347. $receivablesCategory = explode ( ":", $detail ['receivablesCategory'] );
  3348. $item += array (
  3349. 'cid' => $receivablesCategory [0]
  3350. );
  3351. }
  3352. if ($detail ['receivablesStaff'] != 'PUBLIC') {
  3353. $receivablesStaff = explode ( "-", $detail ['receivablesStaff'] );
  3354. $item += array (
  3355. 'staff' => $receivablesStaff [0]
  3356. );
  3357. }
  3358. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3359. // 公司流水-删除时删除流水
  3360. Doo::loadModel ( 'wasteBook' );
  3361. $wasteBook = new wasteBook ();
  3362. $wasteBook->delete ( array (
  3363. 'where' => 'dataID=' . $detail ['irid'] . ' and accountType=7',
  3364. 'limit' => 1
  3365. ) );
  3366. return '/invoiceReceivablesAS';
  3367. }
  3368. /**
  3369. * 管理员录入的收款 ,确认认领到谁的名下.统计收款金额
  3370. */
  3371. function invoiceReceivablesAscription() {
  3372. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  3373. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  3374. Doo::loadModel ( 'invoiceReceivables' );
  3375. $invoiceReceivables = new invoiceReceivables ();
  3376. Doo::loadModel ( 'invoiceROLog' );
  3377. $invoiceROLog = new invoiceROLog ();
  3378. Doo::loadModel ( 'invoiceStatistics' );
  3379. $invoiceStatistics = new invoiceStatistics ();
  3380. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  3381. if (! empty ( $detail ) && $detail ['receivablesStaff'] == 'PUBLIC' && ! empty ( $recepitTitleMark )) {
  3382. $item = array (
  3383. 'irid' => $detail ['irid'],
  3384. 'receivablesCategory' => $this->staff [0] ['cid'] . ":" . $this->staff [0] ['category'],
  3385. 'receivablesStaff' => $this->staff [0] ['sid'] . "-" . $this->staff [0] ['username'],
  3386. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3387. 'recepitTitleMark' => $recepitTitleMark,
  3388. 'source' => 1
  3389. );
  3390. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3391. $item = array (
  3392. 'date' => date ( "Y-m-d" ),
  3393. 'operation' => $this->staff [0] ['username'] . " 认领 ",
  3394. 'status' => 2,
  3395. 'img' => $this->staff [0] ['avatar'],
  3396. 'username' => $this->staff [0] ['username'],
  3397. 'uid' => $this->staff [0] ['sid'],
  3398. 'category' => $this->staff [0] ['category'],
  3399. 'irid' => $irid
  3400. );
  3401. $invoiceROLog->setInvoiceROLog ( $item );
  3402. $item = array (
  3403. 'cid' => $this->staff [0] ['cid'],
  3404. 'staff' => $this->staff [0] ['sid']
  3405. );
  3406. $invoiceStatistics->updateInvoiceStatisticsByIrid ( $item, $detail ['irid'], 2 );
  3407. }
  3408. return "/invoiceReceivablesClaim";
  3409. }
  3410. /**
  3411. */
  3412. function invoiceMyReceivables() {
  3413. Doo::loadModel ( 'invoiceReceivables' );
  3414. $invoiceReceivables = new invoiceReceivables ();
  3415. Doo::loadModel ( 'invoiceStatistics' );
  3416. $invoiceStatistics = new invoiceStatistics ();
  3417. $isMonth = $invoiceStatistics->getStatisticsByMonth ( $this->staff [0] ['sid'] );
  3418. $year = date ( "Y" );
  3419. $tmp_date = date ( "Ym" );
  3420. $tmp_year = substr ( $tmp_date, 0, 4 );
  3421. $tmp_mon = substr ( $tmp_date, 4, 2 );
  3422. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  3423. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  3424. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . ".htm";
  3425. $htm = $this->showCache ( $path );
  3426. $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  3427. $this->data ['isMonth'] = $isMonth;
  3428. $this->data ['htm'] = $htm;
  3429. $this->data ['list'] = $list;
  3430. $this->data ['memu'] = "invoice";
  3431. $this->data ['staff'] = $this->staff;
  3432. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  3433. $this->render ( "/admin/invoiceMyReceivables", $this->data );
  3434. }
  3435. /**
  3436. * 纸票管理
  3437. */
  3438. function invoicePaper() {
  3439. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3440. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3441. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3442. $this->data ['dateString'] = $date;
  3443. $this->data ['status'] = $status;
  3444. $this->data ['invoiceType'] = $invoiceType;
  3445. $this->data ['memu'] = "invoice";
  3446. $this->data ['staff'] = $this->staff;
  3447. $this->data ['receiptMemu'] = 'invoicePaper';
  3448. $this->render ( "/admin/invoicePaper", $this->data );
  3449. }
  3450. /**
  3451. * 获得纸票分页数据
  3452. */
  3453. function ajaxGetinvoicePaperAchieve() {
  3454. Doo::loadModel ( 'invoicePaper' );
  3455. $invoicePaper = new invoicePaper ();
  3456. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3457. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3458. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ORDINARY";
  3459. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3460. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  3461. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  3462. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  3463. $MebSea = $this->get_args ( 'search' );
  3464. $MebSea = $MebSea ['value'];
  3465. $page_size = $length;
  3466. $con = '';
  3467. if ($status == 'ALL')
  3468. $con = ' where 1 ';
  3469. elseif ($status == 'PRINTED')
  3470. $con = ' where a.iid!=0 '; // $con = ' where b.isDelete=0 and a.iid!=0 and b.status=2 and b.untreadStatus=0 ';
  3471. elseif ($status == 'UNPRINT')
  3472. $con = ' where a.iid=0 '; // $con = ' where b.isDelete=0 and a.iid=0 and b.status=2 and b.untreadStatus=0 ';
  3473. elseif ($status == 'TICKET')
  3474. $con = ' where b.isDelete=0 and b.untreadStatus=2';
  3475. if ($invoiceType == 'ORDINARY')
  3476. $con .= ' and a.invoiceType=0 ';
  3477. elseif ($invoiceType == 'SPECIAL')
  3478. $con .= ' and a.invoiceType=1 ';
  3479. $dateArr = explode ( ':', $date );
  3480. $D1 = $dateString = '';
  3481. $D2 = '';
  3482. if (! empty ( $date )) {
  3483. $D1 = $dateArr [0];
  3484. if (isset ( $dateArr [1] ))
  3485. $D2 = $dateArr [1];
  3486. else
  3487. $D2 = '';
  3488. $dateString = $D1 . " : " . $D2;
  3489. }
  3490. if (! empty ( $D1 ) && ! empty ( $D2 ))
  3491. $con .= ' and b.printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  3492. elseif (! empty ( $D1 ) && empty ( $D2 ))
  3493. $con .= ' and b.printTime like "%' . $D1 . '%" ';
  3494. if (! empty ( $MebSea ))
  3495. $con .= ' and ( b.invoiceTitle like "%' . $MebSea . '%" or b.invoiceCompany like "%' . $MebSea . '%" or a.invoiceNo like "%' . $MebSea . '%" )';
  3496. $invoiceTotal = $invoicePaper->getInvoicePaperCount ();
  3497. $sql = ' ' . $con;
  3498. $limit = $page . ',' . $page_size;
  3499. $list = $invoicePaper->getInvoicePaper ( $limit, $sql, 'desc' );
  3500. $paperList = array ();
  3501. foreach ( $list as $key => $value ) {
  3502. $irDetail = array ();
  3503. if ($value ['iid'] == 0)
  3504. array_push ( $irDetail, '<a href="javascript:if(window.confirm(\'确认删除?\'))window.location=\'/invoicePaperDel/' . $value ['ipidKey'] . '\'" >删除</a>' );
  3505. else
  3506. array_push ( $irDetail, '' );
  3507. array_push ( $irDetail, $value ['invoiceCode'] );
  3508. array_push ( $irDetail, $value ['invoiceNo'] );
  3509. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKey'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  3510. if ($value ['invoiceType'] == 1)
  3511. array_push ( $irDetail, $value ['invoiceCompany'] );
  3512. else
  3513. array_push ( $irDetail, $value ['invoiceTitle'] );
  3514. if ($value ['invoiceType'] == 1)
  3515. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  3516. else
  3517. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  3518. array_push ( $irDetail, $value ['invoiceElement'] );
  3519. array_push ( $irDetail, $value ['categoryName'] . '-' . $value ['userName'] );
  3520. array_push ( $irDetail, $value ['printTime'] );
  3521. array_push ( $paperList, $irDetail );
  3522. }
  3523. // $approvalListJson = json_encode ( $approvalList );
  3524. $recordsFiltered = $invoiceTotal;
  3525. echo json_encode ( array (
  3526. "draw" => intval ( $draw ),
  3527. "recordsTotal" => intval ( $invoiceTotal ),
  3528. "recordsFiltered" => intval ( $recordsFiltered ),
  3529. "data" => $paperList
  3530. ), JSON_UNESCAPED_UNICODE );
  3531. }
  3532. function invoicePaperDel() {
  3533. $ipidKey = isset ( $this->params ['ipidKey'] ) ? $this->params ['ipidKey'] : "";
  3534. $XDeode = new XDeode ( 5 );
  3535. $ipid = $XDeode->decode ( $ipidKey );
  3536. if (empty ( $ipid ))
  3537. die ( 'illegal request' );
  3538. Doo::loadModel ( 'invoicePaper' );
  3539. $invoicePaper = new invoicePaper ();
  3540. $invoicePaper->delete ( array (
  3541. 'where' => 'ipid=' . $ipid . ' and iid=0',
  3542. 'limit' => 1
  3543. ) );
  3544. return '/invoicePaper';
  3545. }
  3546. /**
  3547. * 添加纸质发票号
  3548. */
  3549. function invoicePaperAdd() {
  3550. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : '0';
  3551. $invoiceCode = $this->get_args ( 'invoiceCode' ) ? $this->get_args ( 'invoiceCode' ) : "";
  3552. $invoiceNoStart = $this->get_args ( 'invoiceNoStart' ) && is_numeric ( $this->get_args ( 'invoiceNoStart' ) ) ? $this->get_args ( 'invoiceNoStart' ) : 0;
  3553. $invoiceNoTotal = $this->get_args ( 'invoiceNoTotal' ) && is_numeric ( $this->get_args ( 'invoiceNoTotal' ) ) ? $this->get_args ( 'invoiceNoTotal' ) : 0;
  3554. if ($invoiceType != '' && ! empty ( $invoiceCode ) && ! empty ( $invoiceNoStart ) && ! empty ( $invoiceNoTotal )) {
  3555. $sum = $invoiceNoStart + $invoiceNoTotal;
  3556. if (empty ( $sum ))
  3557. die ( 'illegal request' );
  3558. // echo $invoiceNoStart;
  3559. // echo $sum;
  3560. // echo strlen((int)$invoiceNoStart);
  3561. $sumLenght = strlen ( $invoiceNoStart ) - strlen ( ( int ) $invoiceNoStart );
  3562. Doo::db ()->beginTransaction ();
  3563. // 批量存储纸质发票
  3564. $date = date ( "Y-m-d H:i:s" );
  3565. $sql = 'INSERT INTO CLD_invoicePaper (invoiceType, invoiceCode,invoiceNo,date)
  3566. VALUES ';
  3567. $paperList = array ();
  3568. for($invoiceNoStart; $invoiceNoStart <= $sum - 1; $invoiceNoStart ++) {
  3569. // 数字前面自加0
  3570. $INLENGHT = strlen ( ( int ) $invoiceNoStart ) + $sumLenght;
  3571. $var = sprintf ( "%0" . $INLENGHT . "d", $invoiceNoStart );
  3572. $paperSql = '(' . $invoiceType . ',"' . $invoiceCode . '","' . $var . '","' . $date . '")';
  3573. array_push ( $paperList, $paperSql );
  3574. }
  3575. if (empty ( $paperList ))
  3576. die ( 'illegal request' );
  3577. $sql = $sql . implode ( ',', $paperList );
  3578. Doo::db ()->query ( $sql );
  3579. Doo::db ()->commit ();
  3580. return 'invoicePaper';
  3581. }
  3582. die ( 'illegal request' );
  3583. }
  3584. /**
  3585. * 收款绑定发票 ,//一个收款只能绑定一个发票
  3586. */
  3587. function invoiceBindReceivables() {
  3588. $claimKey = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  3589. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  3590. Doo::loadModel ( 'invoice' );
  3591. $invoice = new invoice ();
  3592. Doo::loadModel ( 'invoiceReceivables' );
  3593. $invoiceReceivables = new invoiceReceivables ();
  3594. Doo::loadModel ( 'invoiceOperationLog' );
  3595. $invoiceOperationLog = new invoiceOperationLog ();
  3596. if (empty ( $invoiceKey ) || empty ( $claimKey ))
  3597. die ( 'illegal request' );
  3598. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  3599. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey );
  3600. if (empty ( $detail ) && empty ( $detailM ))
  3601. die ( 'illegal request' );
  3602. if ($detail ['untreadStatus'] == 3)
  3603. die ( 'illegal request' );
  3604. // 修改 绑定状态改为 金额
  3605. $invoiceReceivables = new invoiceReceivables ();
  3606. $invoicePrice = $detail ['invoicePrice'] + $detailM ['bindPrice'];
  3607. if ($detailM ['receivablesPrice'] > $invoicePrice) {
  3608. $item = array (
  3609. 'bindPrice' => $invoicePrice
  3610. );
  3611. } elseif ($detailM ['receivablesPrice'] <= $invoicePrice) {
  3612. $item = array (
  3613. 'bindPrice' => $invoicePrice,
  3614. 'bindStatus' => 1,
  3615. 'bindDate' => date ( "Y-m-d H:i:s" )
  3616. );
  3617. } else {
  3618. die ( 'illegal request' );
  3619. }
  3620. if ($detailM ['iid'] == 0) {
  3621. $item += array (
  3622. 'iid' => $detail ['iid']
  3623. );
  3624. } else {
  3625. $iidExtend = explode ( ',', $detailM ['iidExtend'] );
  3626. array_push ( $iidExtend, $detail ['iid'] );
  3627. $item += array (
  3628. 'iidExtend' => implode ( ',', $iidExtend )
  3629. );
  3630. }
  3631. $titleMark = $detail ['invoiceTitle'];
  3632. if (! empty ( $detail ['invoiceCompany'] ))
  3633. $titleMark = $detail ['invoiceCompany'];
  3634. $item += array (
  3635. 'irid' => $detailM ['irid'],
  3636. 'recepitTitleMark' => $titleMark,
  3637. 'accountClerk' => $this->staff [0] ['username']
  3638. );
  3639. // 如何没有人收款 则自动绑定收款
  3640. if ($detailM ['receivablesCategory'] == 'PUBLIC' || $detailM ['receivablesStaff'] == 'PUBLIC') {
  3641. $item += array (
  3642. 'receivablesCategory' => $detail ['cid'] . ':' . $detail ['categoryName'],
  3643. 'receivablesStaff' => $detail ['sid'] . '-' . $detail ['userName']
  3644. );
  3645. }
  3646. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3647. $iridString = "";
  3648. if (empty ( $detail ['irid'] ))
  3649. $iridString = $detailM ['irid'];
  3650. else
  3651. $iridString = $detail ['irid'] . ',' . $detailM ['irid'];
  3652. $item = array (
  3653. 'iid' => $detail ['iid'],
  3654. 'irid' => $iridString
  3655. );
  3656. $invoiceReceivables = new invoiceReceivables ();
  3657. $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  3658. if ($detail ['invoicePrice'] <= $sum)
  3659. $item += array (
  3660. 'untreadStatus' => 3,
  3661. 'bindTime' => date ( "Y-m-d H:i:s" )
  3662. );
  3663. // print_r($item);
  3664. // echo $sum;die;
  3665. $invoice->setInvoiceByCondition ( $item );
  3666. // 操作日志
  3667. $item = array (
  3668. 'date' => date ( "Y-m-d H:i:s" ),
  3669. 'operation' => "收款" . $detailM ['receivablesSerial'] . "入账到发票" . $detail ['invoiceSerial'],
  3670. 'status' => 8,
  3671. 'img' => $this->staff [0] ['avatar'],
  3672. 'username' => $this->staff [0] ['username'],
  3673. 'uid' => $this->staff [0] ['sid'],
  3674. 'category' => $this->staff [0] ['category'],
  3675. 'iid' => $detail ['iid']
  3676. );
  3677. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3678. Doo::loadModel ( 'invoiceStatistics' );
  3679. $invoiceStatistics = new invoiceStatistics ();
  3680. $item = array (
  3681. 'date' => $detailM ['receivablesDate'],
  3682. 'priceClass' => 3,
  3683. 'cid' => $detail ['cid'],
  3684. 'staff' => $detail ['sid'],
  3685. 'accountPrice' => $detailM ['receivablesPrice']
  3686. );
  3687. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3688. // 公司流水记录
  3689. // Doo::loadModel ( 'wasteBook' );
  3690. // $wasteBook = new wasteBook ();
  3691. // $abDetail = $wasteBook->getAccountBookByAid (1,8,$detail ['iid'] );
  3692. // $accountBank='';
  3693. // if ($detailM ['receivablesBank']=='纵横广发'){
  3694. // $accountBank='CGBDeposit';
  3695. // }elseif($detailM ['receivablesBank']=='纵横工行'){
  3696. // $accountBank='ICBCDeposit';
  3697. // }elseif($detailM ['receivablesBank']=='华润银行'){
  3698. // $accountBank='HUADeposit';
  3699. // }elseif($detailM ['receivablesBank']=='个人广发'){
  3700. // $accountBank='PersonalDeposit';
  3701. // }
  3702. // if (empty($abDetail)){
  3703. // $item = array (
  3704. // 'dataID' => $detail ['iid'],
  3705. // 'expensesType' => 1,
  3706. // 'accountType' => 8,
  3707. // 'accountPriceShow'=>$detail ['invoicePrice'],
  3708. // 'accountPrice'=>$detail ['invoicePrice'],
  3709. // 'accountBank'=>$accountBank,
  3710. // 'category'=>$this->staff[0]['category'],
  3711. // 'cid'=>$this->staff[0]['cid'],
  3712. // 'name'=>$this->staff[0]['username'],
  3713. // 'sid'=>$this->staff[0]['sid'],
  3714. // 'inputDate'=>date ( "Y-m-d H:i:s" )
  3715. // );
  3716. // $wasteBook->setAccountBookStatistics($item);
  3717. // }
  3718. return "/invoiceReceivables";
  3719. }
  3720. /**
  3721. * 核销 动作,确认入账统计 发票收款完成--需求更变 废弃 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"; }
  3722. */
  3723. function invoiceAggregate() {
  3724. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3725. Doo::loadModel ( 'invoiceStatistics' );
  3726. $invoiceStatistics = new invoiceStatistics ();
  3727. Doo::loadModel ( 'L_category' );
  3728. $Lcategory = new L_category ();
  3729. $isList = $invoiceStatistics->getInvoiceStatisticsByYear ( $year );
  3730. $LcategoryList = $Lcategory->getCategory ();
  3731. // print_r($isList);
  3732. $html = ""; // $invoicePriceCategory=0;$receivablesPriceCategory=0;$accountPriceCategory=0;
  3733. foreach ( $LcategoryList as $key => $value ) {
  3734. $html .= '<tr><th><a href="/invoiceAggregateCategory/' . $value ['cidKey'] . '">' . $value ['title'] . '</a></th>';
  3735. $month = 1;
  3736. $invoicePriceYear = 0;
  3737. $receivablesPriceYear = 0;
  3738. $accountPriceYear = 0;
  3739. for(; $month <= 12; $month ++) {
  3740. $flag = true;
  3741. foreach ( $isList ['statisticsMonthCid'] as $k => $v ) {
  3742. if ($value ['cid'] == $v ['cid'] && $month == $v ['month']) {
  3743. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  3744. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  3745. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  3746. ';
  3747. $invoicePriceYear += $v ['invoicePrice'];
  3748. $receivablesPriceYear += $v ['receivablesPrice'];
  3749. $accountPriceYear += $v ['accountPrice'];
  3750. $flag = false;
  3751. break;
  3752. }
  3753. }
  3754. if ($flag)
  3755. $html .= '<td class="taR"></td>
  3756. <td class="taR"></td>
  3757. <td class="taR"><b></b></td>
  3758. ';
  3759. }
  3760. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  3761. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  3762. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  3763. ';
  3764. $html .= '</tr>';
  3765. }
  3766. $html .= '<tr><th><b class="colGreen">月合计</b></th>';
  3767. $invoicePriceYear = 0;
  3768. $receivablesPriceYear = 0;
  3769. $accountPriceYear = 0;
  3770. for($month = 1; $month <= 12; $month ++) {
  3771. $flag = true;
  3772. foreach ( $isList ['statisticsMonth'] as $k => $v ) {
  3773. if ($month == $v ['month']) {
  3774. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  3775. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  3776. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  3777. ';
  3778. $invoicePriceYear += $v ['invoicePrice'];
  3779. $receivablesPriceYear += $v ['receivablesPrice'];
  3780. $accountPriceYear += $v ['accountPrice'];
  3781. $flag = false;
  3782. break;
  3783. }
  3784. }
  3785. if ($flag) {
  3786. $html .= '<td class="taR"></td>
  3787. <td class="taR"></td>
  3788. <td class="taR"><b></b></td>
  3789. ';
  3790. }
  3791. }
  3792. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  3793. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  3794. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  3795. ';
  3796. $html .= '</tr>';
  3797. // print_r($isList);
  3798. $this->data ['html'] = $html;
  3799. $this->data ['LcategoryList'] = $LcategoryList;
  3800. $this->data ['isList'] = $isList;
  3801. $this->data ['year'] = $year;
  3802. $this->data ['memu'] = "invoice";
  3803. $this->data ['staff'] = $this->staff;
  3804. $this->data ['receiptMemu'] = 'invoiceAggregate';
  3805. $this->render ( "/admin/invoiceAggregate", $this->data );
  3806. }
  3807. function invoiceAggregateStaff() {
  3808. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3809. Doo::loadModel ( 'invoiceStatistics' );
  3810. $invoiceStatistics = new invoiceStatistics ();
  3811. Doo::loadModel ( 'L_category' );
  3812. $Lcategory = new L_category ();
  3813. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year );
  3814. $staffList = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year );
  3815. $cStaff = $Lcategory->getCategoryStaff ();
  3816. $html = '';
  3817. foreach ( $cStaff as $key => $value ) {
  3818. $categoryFir = true;
  3819. foreach ( $value ['staff'] as $k => $v ) {
  3820. if ($categoryFir) {
  3821. $width = count ( $value ['staff'] ) + 1;
  3822. $html .= '<tr><th rowspan="' . $width . '">' . $value ['title'] . ' </th>';
  3823. $categoryFir = false;
  3824. } else
  3825. $html .= '<tr>';
  3826. $html .= '<th>' . $v ['username'] . '</th>';
  3827. $invoicePriceStaffYear = 0;
  3828. $receivablesPriceStaffYear = 0;
  3829. $accountPriceStaffYear = 0;
  3830. for($month = 1; $month <= 12; $month ++) {
  3831. $flag = true;
  3832. foreach ( $staffList ['statisticsMonthStaff'] as $sl => $slv ) {
  3833. if ($v ['sid'] == $slv ['staff'] && $month == $slv ['month']) {
  3834. $html .= '<td class="taR">¥' . $slv ['invoicePrice'] . '</td>
  3835. <td class="taR">¥' . $slv ['receivablesPrice'] . '</td>
  3836. <td class="taR"><b>¥' . $slv ['accountPrice'] . '</b></td>
  3837. ';
  3838. $invoicePriceStaffYear += $slv ['invoicePrice'];
  3839. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  3840. $accountPriceStaffYear += $slv ['accountPrice'];
  3841. $flag = false;
  3842. break;
  3843. }
  3844. }
  3845. if ($flag)
  3846. $html .= '<td class="taR"></td>
  3847. <td class="taR"></td>
  3848. <td class="taR"><b></b></td>
  3849. ';
  3850. }
  3851. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  3852. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  3853. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  3854. ';
  3855. }
  3856. $html .= '</tr>';
  3857. // 小计
  3858. if (! empty ( $value ['staff'] )) {
  3859. $html .= '<tr><th class="taR">小计</th>';
  3860. $invoicePriceStaffYear = 0;
  3861. $receivablesPriceStaffYear = 0;
  3862. $accountPriceStaffYear = 0;
  3863. for($month = 1; $month <= 12; $month ++) {
  3864. $flag = true;
  3865. foreach ( $staffList ['statisticsMonthCid'] as $smc => $smcv ) {
  3866. if ($value ['cid'] == $smcv ['cid'] && $month == $slv ['month']) {
  3867. $html .= '<td class="taR">¥' . $smcv ['invoicePrice'] . '</td>
  3868. <td class="taR">¥' . $smcv ['receivablesPrice'] . '</td>
  3869. <td class="taR"><b>¥' . $smcv ['accountPrice'] . '</b></td>
  3870. ';
  3871. $invoicePriceStaffYear += $slv ['invoicePrice'];
  3872. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  3873. $accountPriceStaffYear += $slv ['accountPrice'];
  3874. $flag = false;
  3875. break;
  3876. }
  3877. }
  3878. if ($flag)
  3879. $html .= '<td class="taR"></td>
  3880. <td class="taR"></td>
  3881. <td class="taR"><b></b></td>
  3882. ';
  3883. }
  3884. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  3885. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  3886. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  3887. ';
  3888. $html .= '</tr>';
  3889. }
  3890. }
  3891. $html .= '<tr class="warning"><th colspan="2"><b class="colGreen" >月合计</b></th>';
  3892. $invoicePriceYear = 0;
  3893. $receivablesPriceYear = 0;
  3894. $accountPriceYear = 0;
  3895. for($month = 1; $month <= 12; $month ++) {
  3896. $flag = true;
  3897. foreach ( $staffList ['statisticsMonth'] as $k => $v ) {
  3898. if ($month == $v ['month']) {
  3899. $html .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>
  3900. <td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>
  3901. <td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>
  3902. ';
  3903. $invoicePriceYear += $v ['invoicePrice'];
  3904. $receivablesPriceYear += $v ['receivablesPrice'];
  3905. $accountPriceYear += $v ['accountPrice'];
  3906. $flag = false;
  3907. break;
  3908. }
  3909. }
  3910. if ($flag)
  3911. $html .= '<td class="taR"></td>
  3912. <td class="taR"></td>
  3913. <td class="taR"><b></b></td>
  3914. ';
  3915. }
  3916. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  3917. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  3918. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  3919. ';
  3920. $html .= '</tr>';
  3921. $this->data ['html'] = $html;
  3922. $this->data ['isList'] = $toteList;
  3923. $this->data ['year'] = $year;
  3924. $this->data ['memu'] = "invoice";
  3925. $this->data ['staff'] = $this->staff;
  3926. $this->data ['receiptMemu'] = 'invoiceAggregate';
  3927. $this->render ( "/admin/invoiceAggregateStaff", $this->data );
  3928. }
  3929. function invoiceAggregateCategory() {
  3930. Doo::loadClass ( 'XDeode' );
  3931. $XDeode = new XDeode ( 5 );
  3932. $cid = $cidKey = isset ( $this->params ['cid'] ) ? $this->params ['cid'] : "";
  3933. $cid = $XDeode->decode ( $cid );
  3934. if (! is_numeric ( $cid ))
  3935. die ( 'illegal request' );
  3936. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3937. Doo::loadModel ( 'invoiceStatistics' );
  3938. $invoiceStatistics = new invoiceStatistics ();
  3939. Doo::loadModel ( 'staff' );
  3940. $staff = new staff ();
  3941. $list = $staff->getStaffByCid ( $cid );
  3942. $isCategory = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year, $cid );
  3943. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year, $cid );
  3944. if (empty ( $list ))
  3945. die ( '该办事处没有成员' );
  3946. $htmlA = $htmlB = $htmlC = $html = '';
  3947. foreach ( $list as $key => $value ) {
  3948. $htmlA = '<tr><th rowspan="3">' . $value ['username'] . '</th><th class="taC">开票</th>';
  3949. $htmlB = '<tr><th class="taC">收款</th>';
  3950. $htmlC = '<tr><th class="taC">入账</th>';
  3951. $invoicePriceStaffYear = 0;
  3952. $receivablesPriceStaffYear = 0;
  3953. $accountPriceStaffYear = 0;
  3954. for($month = 1; $month <= 12; $month ++) {
  3955. $flag = true;
  3956. foreach ( $isCategory ['statisticsMonthStaff'] as $k => $v ) {
  3957. if ($value ['sid'] == $v ['staff'] && $month == $v ['month']) {
  3958. $htmlA .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>';
  3959. $htmlB .= '<td class="taR">¥' . $v ['receivablesPrice'] . '</td>';
  3960. $htmlC .= '<td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>';
  3961. $invoicePriceStaffYear += $v ['invoicePrice'];
  3962. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  3963. $accountPriceStaffYear += $v ['accountPrice'];
  3964. $flag = false;
  3965. break;
  3966. }
  3967. }
  3968. if ($flag) {
  3969. $htmlA .= '<td class="taR">-</td>';
  3970. $htmlB .= '<td class="taR">-</td>';
  3971. $htmlC .= '<td class="taR"><b>-</b></td>';
  3972. }
  3973. }
  3974. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  3975. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  3976. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  3977. $htmlA .= '</tr>';
  3978. $htmlB .= '</tr>';
  3979. $htmlC .= '</tr>';
  3980. $html .= $htmlA . $htmlB . $htmlC;
  3981. }
  3982. $htmlA = $htmlB = $htmlC = "";
  3983. $htmlA = '<tr><th rowspan="3">月合计</th><th class="taC">开票</th>';
  3984. $htmlB = '<tr><th class="taC">收款</th>';
  3985. $htmlC = '<tr><th class="taC">入账</th>';
  3986. $invoicePriceStaffYear = 0;
  3987. $receivablesPriceStaffYear = 0;
  3988. $accountPriceStaffYear = 0;
  3989. for($month = 1; $month <= 12; $month ++) {
  3990. $flag = true;
  3991. foreach ( $isCategory ['statisticsMonth'] as $k => $v ) {
  3992. if ($month == $v ['month']) {
  3993. $htmlA .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>';
  3994. $htmlB .= '<td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>';
  3995. $htmlC .= '<td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>';
  3996. $invoicePriceStaffYear += $v ['invoicePrice'];
  3997. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  3998. $accountPriceStaffYear += $v ['accountPrice'];
  3999. $flag = false;
  4000. break;
  4001. }
  4002. }
  4003. if ($flag) {
  4004. $htmlA .= '<td class="taR">-</td>';
  4005. $htmlB .= '<td class="taR">-</td>';
  4006. $htmlC .= '<td class="taR"><b>-</b></td>';
  4007. }
  4008. }
  4009. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  4010. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  4011. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  4012. $htmlA .= '</tr>';
  4013. $htmlB .= '</tr>';
  4014. $htmlC .= '</tr>';
  4015. $html .= $htmlA . $htmlB . $htmlC;
  4016. $this->data ['html'] = $html;
  4017. $this->data ['cidKey'] = $cidKey;
  4018. $this->data ['slist'] = $list;
  4019. $this->data ['isList'] = $toteList;
  4020. $this->data ['year'] = $year;
  4021. $this->data ['memu'] = "invoice";
  4022. $this->data ['staff'] = $this->staff;
  4023. $this->data ['receiptMemu'] = 'invoiceAggregate';
  4024. $this->render ( "/admin/invoiceAggregateCategory", $this->data );
  4025. }
  4026. /**
  4027. * 办事处汇总信息
  4028. */
  4029. function invoiceAggregateCategoryDetail() {
  4030. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  4031. Doo::loadClass ( 'XDeode' );
  4032. $XDeode = new XDeode ( 5 );
  4033. Doo::loadModel ( 'invoiceStatistics' );
  4034. $invoiceStatistics = new invoiceStatistics ();
  4035. Doo::loadModel ( 'L_category' );
  4036. $category = new L_category ();
  4037. Doo::loadModel ( 'invoice' );
  4038. $invoice = new invoice ();
  4039. Doo::loadModel ( 'staff' );
  4040. $staff = new staff ();
  4041. Doo::loadModel ( "invoiceCategoryManage" );
  4042. $invoiceCategoryManage = new invoiceCategoryManage ();
  4043. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4044. $cidList = array ();
  4045. foreach ( $imcStaff as $key => $value ) {
  4046. array_push ( $cidList, $value ['cid'] );
  4047. if (empty ( $cidKey ))
  4048. $cidKey = $XDeode->encode ( $value ['cid'] );
  4049. }
  4050. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  4051. $cid = $XDeode->decode ( $cidKey );
  4052. $month = date ( "m", strtotime ( "-1 month" ) );
  4053. $YearMonth = date ( "Y-m", strtotime ( "-1 month" ) );
  4054. $redis = new Redis ();
  4055. $redis->connect ( '127.0.0.1', '6379' );
  4056. $redisKey = ''; // date('Y-m-d').'_iacd_'.$cid;
  4057. $redisValue = ''; // $redis->lrange($redisKey, 0, -1);
  4058. if (empty ( $redisValue )) {
  4059. $isMC = $invoiceStatistics->getInvoiceStatistiscsMothByCategory ( $cid );
  4060. $schedule = $invoice->getInvoiceScheduleByCid ( $cid );
  4061. // 获得办事处人员下的汇总
  4062. $slist = $staff->getStaffByCid ( $cid );
  4063. $ismsbMonth = $invoiceStatistics->getISMSByCategoryByMonth ( $cid, $YearMonth ); // 上一个月的汇总
  4064. $ismsb = $invoiceStatistics->getISMSByCategory ( $cid ); // 当月汇总
  4065. $ISAS = $invoiceStatistics->getISASByCategory ( $cid ); // 全部汇总
  4066. $scheduleStaff = $invoice->getInvoiceScheduleByCidGroupSid ( $cid ); // 完成度
  4067. foreach ( $slist as $key => $value ) {
  4068. $slist [$key] ['invoicePrice'] = 0;
  4069. $slist [$key] ['receivablesPrice'] = 0;
  4070. $slist [$key] ['accountPrice'] = 0;
  4071. $slist [$key] ['invoiceAllPrice'] = 0;
  4072. $slist [$key] ['receivablesAllPrice'] = 0;
  4073. $slist [$key] ['accountAllPrice'] = 0;
  4074. $slist [$key] ['schedule'] = 0;
  4075. $slist [$key] ['invoiceMonthPrice'] = 0;
  4076. $slist [$key] ['receivablesMonthPrice'] = 0;
  4077. $slist [$key] ['accountMonthPrice'] = 0;
  4078. foreach ( $ismsbMonth as $y => $l ) {
  4079. if ($value ['sid'] == $l ['staff']) {
  4080. $slist [$key] ['invoiceMonthPrice'] = $l ['invoicePrice'];
  4081. $slist [$key] ['receivablesMonthPrice'] = $l ['receivablesPrice'];
  4082. $slist [$key] ['accountMonthPrice'] = $l ['accountPrice'];
  4083. }
  4084. }
  4085. foreach ( $ismsb as $k => $v ) {
  4086. if ($value ['sid'] == $v ['staff']) {
  4087. $slist [$key] ['invoicePrice'] = $v ['invoicePrice'];
  4088. $slist [$key] ['receivablesPrice'] = $v ['receivablesPrice'];
  4089. $slist [$key] ['accountPrice'] = $v ['accountPrice'];
  4090. }
  4091. }
  4092. foreach ( $ISAS as $e => $a ) {
  4093. if ($value ['sid'] == $a ['staff']) {
  4094. $slist [$key] ['invoiceAllPrice'] = $a ['invoicePrice'];
  4095. $slist [$key] ['receivablesAllPrice'] = $a ['receivablesPrice'];
  4096. $slist [$key] ['accountAllPrice'] = $a ['accountPrice'];
  4097. }
  4098. }
  4099. if (isset ( $scheduleStaff [$value ['sid']] ))
  4100. $slist [$key] ['schedule'] = $scheduleStaff [$value ['sid']];
  4101. }
  4102. $this->data ['cidKey'] = $cidKey;
  4103. $schedule = ( int ) ($schedule * 100);
  4104. $this->data ['slist'] = $slist;
  4105. $this->data ['isMC'] = $isMC;
  4106. $this->data ['schedule'] = $schedule;
  4107. $slist = json_encode ( $slist );
  4108. $isMC = json_encode ( $isMC );
  4109. $schedule = json_encode ( $schedule );
  4110. $redis->lpush ( $redisKey, $slist );
  4111. $redis->lpush ( $redisKey, $isMC );
  4112. $redis->lpush ( $redisKey, $schedule );
  4113. } else {
  4114. $this->data ['cidKey'] = $cidKey;
  4115. $this->data ['slist'] = json_decode ( $redisValue [2], true );
  4116. $this->data ['isMC'] = json_decode ( $redisValue [1], true );
  4117. $this->data ['schedule'] = json_decode ( $redisValue [0], true );
  4118. }
  4119. $this->data ['month'] = $month;
  4120. $this->data ['categoryList'] = $categoryList;
  4121. $this->data ['memu'] = "invoice";
  4122. $this->data ['staff'] = $this->staff;
  4123. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4124. $this->render ( "/admin/invoiceAggregateCategoryDetail", $this->data );
  4125. }
  4126. /**
  4127. * 办事处人员汇总详情
  4128. */
  4129. function invoiceAggregateStaffDetail() {
  4130. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  4131. // $sidKey = isset ( $this->params ['sidKey'] ) ? $this->params ['sidKey'] : '';
  4132. Doo::loadClass ( 'XDeode' );
  4133. $XDeode = new XDeode ( 5 );
  4134. Doo::loadModel ( 'invoice' );
  4135. $invoice = new invoice ();
  4136. Doo::loadModel ( 'staff' );
  4137. $staff = new staff ();
  4138. Doo::loadModel ( "invoiceCategoryManage" );
  4139. $invoiceCategoryManage = new invoiceCategoryManage ();
  4140. $sid = $XDeode->decode ( $sidKey );
  4141. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4142. $cidList = array ();
  4143. foreach ( $imcStaff as $key => $value ) {
  4144. array_push ( $cidList, $value ['cid'] );
  4145. if (empty ( $cidKey ))
  4146. $cidKey = $XDeode->encode ( $value ['cid'] );
  4147. }
  4148. $cidString = implode ( ',', $cidList );
  4149. $staffList = $staff->getStaffInCid ( $cidString );
  4150. $staffDetail = $staff->getStaffBySid ( $sid );
  4151. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4152. $page_size = 18;
  4153. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4154. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4155. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  4156. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  4157. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  4158. $dateArr = explode ( ':', $date );
  4159. $D1 = '';
  4160. $D2 = '';
  4161. if (! empty ( $date )) {
  4162. $D1 = $dateArr [0] . " 00:00:00 ";
  4163. if (isset ( $dateArr [1] ))
  4164. $D2 = $dateArr [1] . " 23:59:59 ";
  4165. else
  4166. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4167. // $D2 = $dateArr [1];
  4168. }
  4169. $con = ' status=2 ';
  4170. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4171. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4172. if ($status == 'UNRECORD')
  4173. $con .= ' and printStatus=1 and untreadStatus=0';
  4174. elseif ($status == 'RECORD')
  4175. $con .= ' and printStatus=1 and untreadStatus=3';
  4176. elseif ($status == 'BOUNCED')
  4177. $con .= ' and untreadStatus=2';
  4178. elseif ($status == 'PARTRECORD')
  4179. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  4180. elseif ($status == 'All') {
  4181. $con .= ' and ( untreadStatus=2 or untreadStatus=0 or untreadStatus=3 )';
  4182. }
  4183. $con .= ' and sid=' . $sid;
  4184. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  4185. if (! empty ( $MebSea )) {
  4186. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  4187. }
  4188. $pageinfo ['page'] = array (
  4189. 'previous' => ''
  4190. );
  4191. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateStaffDetail", $get, "" );
  4192. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4193. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  4194. $this->data ['staffDetail'] = $staffDetail;
  4195. $this->data ['staffList'] = $staffList;
  4196. $this->data ['MebSeaEn'] = $MebSea;
  4197. $this->data ['MebSea'] = urlencode ( $MebSea );
  4198. $this->data ['date'] = $date;
  4199. $this->data ['page'] = $pageinfo;
  4200. $this->data ['get'] = $get;
  4201. $this->data ['list'] = $list;
  4202. $this->data ['status'] = $status;
  4203. $this->data ['sidKey'] = $sidKey;
  4204. $this->data ['memu'] = "invoice";
  4205. $this->data ['staff'] = $this->staff;
  4206. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4207. $this->render ( "/admin/invoiceAggregateStaffDetail", $this->data );
  4208. }
  4209. /**
  4210. * 办事处人员汇总收款情
  4211. */
  4212. function invoiceAggregateStaffReceivablesDetail() {
  4213. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  4214. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  4215. Doo::loadModel ( 'invoiceReceivables' );
  4216. $invoiceReceivables = new invoiceReceivables ();
  4217. Doo::loadModel ( 'staff' );
  4218. $staff = new staff ();
  4219. Doo::loadModel ( "invoiceCategoryManage" );
  4220. $invoiceCategoryManage = new invoiceCategoryManage ();
  4221. Doo::loadClass ( 'XDeode' );
  4222. $XDeode = new XDeode ( 5 );
  4223. $sid = $XDeode->decode ( $sidKey );
  4224. $staffDetail = $staff->getStaffBySid ( $sid );
  4225. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4226. $cidList = array ();
  4227. foreach ( $imcStaff as $key => $value ) {
  4228. array_push ( $cidList, $value ['cid'] );
  4229. if (empty ( $cidKey ))
  4230. $cidKey = $XDeode->encode ( $value ['cid'] );
  4231. }
  4232. $cidString = implode ( ',', $cidList );
  4233. $staffList = $staff->getStaffInCid ( $cidString );
  4234. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4235. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  4236. $page_size = 10;
  4237. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4238. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4239. if ($timeType == "BINDOTP") {
  4240. $status = 'Credited';
  4241. }
  4242. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  4243. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  4244. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  4245. $dateArr = explode ( ':', $date );
  4246. $D1 = '';
  4247. $D2 = '';
  4248. if (! empty ( $date )) {
  4249. $D1 = $dateArr [0] . " 00:00:00 ";
  4250. if (isset ( $dateArr [1] ))
  4251. $D2 = $dateArr [1] . " 23:59:59 ";
  4252. else
  4253. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4254. }
  4255. $con = ' a.receivablesStaff like "%' . $staffDetail ['username'] . '%" ';
  4256. $descField = 'a.bindDate';
  4257. if ($timeType == 'CREATE')
  4258. $descField = 'a.date';
  4259. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4260. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4261. elseif (! empty ( $D1 ) && empty ( $D2 ))
  4262. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  4263. if ($status == 'Unclaimed')
  4264. $con .= ' and a.bindStatus=0';
  4265. elseif ($status == 'Credited')
  4266. $con .= ' and a.bindStatus=1';
  4267. elseif ($status == 'Claim')
  4268. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  4269. elseif ($status == 'BBN')
  4270. $con .= ' and a.bindPrice>a.receivablesPrice';
  4271. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  4272. if (! empty ( $MebSea )) {
  4273. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" )';
  4274. }
  4275. $pageinfo ['page'] = array (
  4276. 'previous' => ''
  4277. );
  4278. $sql = 'select group_concat(b.invoiceSerial) as invoiceSerial ,group_concat(b.iid) as invoiceId
  4279. from CLD_invoiceReceivables as a left join CLD_invoice as b on
  4280. find_in_set(b.iid,a.iidExtend) or a.iid=b.iid
  4281. where ' . $con . ' group by a.irid ';
  4282. $pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceAggregateStaffReceivablesDetail", $get, "" );
  4283. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4284. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', 'printTime' );
  4285. foreach ( $list as $key => $value ) {
  4286. $list [$key] ['category'] = '';
  4287. if ($value ['receivablesCategory'] != 'PUBLIC') {
  4288. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  4289. $list [$key] ['category'] = $receivablesCategory [1];
  4290. }
  4291. }
  4292. // print_r($list);
  4293. $this->data ['staffDetail'] = $staffDetail;
  4294. $this->data ['sidKey'] = $sidKey;
  4295. $this->data ['staffList'] = $staffList;
  4296. $this->data ['timeType'] = $timeType;
  4297. $this->data ['MebSeaEn'] = $MebSea;
  4298. $this->data ['MebSea'] = urlencode ( $MebSea );
  4299. $this->data ['date'] = $date;
  4300. $this->data ['page'] = $pageinfo;
  4301. $this->data ['get'] = $get;
  4302. $this->data ['list'] = $list;
  4303. $this->data ['status'] = $status;
  4304. $this->data ['memu'] = "invoice";
  4305. $this->data ['staff'] = $this->staff;
  4306. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4307. $this->render ( "/admin/invoiceAggregateStaffReceivablesDetail", $this->data );
  4308. }
  4309. function invoiceAchieve() {
  4310. Doo::loadModel ( 'invoice' );
  4311. $invoice = new invoice ();
  4312. Doo::loadClass ( 'XDeode' );
  4313. $XDeode = new XDeode ( 5 );
  4314. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4315. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4316. $page_size = 18;
  4317. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4318. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4319. $get = "/" . $date;
  4320. $con = '';
  4321. if ($date == 'MONTHO')
  4322. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4323. elseif ($date == 'MONTHT')
  4324. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4325. elseif ($date == 'MONTHY')
  4326. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4327. if (! empty ( $MebSea )) {
  4328. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4329. $get .= "/" . $MebSea;
  4330. }
  4331. $pageinfo ['page'] = array (
  4332. 'previous' => ''
  4333. );
  4334. $sql = 'status=2 and printStatus=1 and irid!="" and ( untreadStatus=3 or untreadStatus=0 ) and sid=' . $sid . $con;
  4335. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceAchieve", $get, "" );
  4336. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4337. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  4338. // print_r($pageinfo);
  4339. $this->data ['MebSeaEn'] = $MebSea;
  4340. $this->data ['MebSea'] = urlencode ( $MebSea );
  4341. $this->data ['get'] = $get;
  4342. $this->data ['page'] = $pageinfo;
  4343. $this->data ['list'] = $list;
  4344. $this->data ['date'] = $date;
  4345. $this->data ['memu'] = "invoice";
  4346. $this->data ['staff'] = $this->staff;
  4347. $this->data ['receiptMemu'] = 'invoice';
  4348. $this->render ( "/admin/invoiceAchieve", $this->data );
  4349. }
  4350. /**
  4351. */
  4352. function invoiceMyUnAccountAchieve() {
  4353. Doo::loadModel ( 'invoice' );
  4354. $invoice = new invoice ();
  4355. Doo::loadClass ( 'XDeode' );
  4356. $XDeode = new XDeode ( 5 );
  4357. Doo::loadModel ( 'staff' );
  4358. $staff = new staff ();
  4359. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4360. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4361. $page_size = 18;
  4362. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4363. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4364. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4365. $dateArr = explode ( ':', $date );
  4366. $D1 = '';
  4367. $D2 = '';
  4368. if (! empty ( $date )) {
  4369. $D1 = $dateArr [0];
  4370. $D2 = $dateArr [1];
  4371. }
  4372. $con = '';
  4373. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4374. $con = ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4375. if (! empty ( $MebSea )) {
  4376. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4377. }
  4378. $pageinfo ['page'] = array (
  4379. 'previous' => ''
  4380. );
  4381. // and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  4382. $sql = " status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid= " . $sid . $con;
  4383. $action = "invoiceMyUnAccountAchieve";
  4384. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  4385. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4386. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql,'desc','desc','printTime' );
  4387. Doo::loadModel ( 'express' );
  4388. $express = new express ();
  4389. $expressList = $express->getExpressByAll ();
  4390. $this->data ['expressList'] = $expressList;
  4391. // print_r($list);
  4392. $this->data ['MebSeaEn'] = $MebSea;
  4393. $this->data ['get'] = $get;
  4394. $this->data ['page'] = $pageinfo;
  4395. $this->data ['date'] = $date;
  4396. $this->data ['list'] = $list;
  4397. $this->data ['memu'] = "invoice";
  4398. $this->data ['staff'] = $this->staff;
  4399. $this->data ['receiptMemu'] = 'invoice';
  4400. $this->render ( "/admin/invoiceMyUnAccountAchieve", $this->data );
  4401. }
  4402. function invoiceReceivablesAchieve() {
  4403. Doo::loadModel ( 'invoiceReceivables' );
  4404. $invoiceReceivables = new invoiceReceivables ();
  4405. Doo::loadClass ( 'XDeode' );
  4406. $XDeode = new XDeode ( 5 );
  4407. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4408. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  4409. $page_size = 12;
  4410. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4411. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4412. $get = "/" . $date;
  4413. $con = '';
  4414. if ($date == 'MONTHO')
  4415. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4416. elseif ($date == 'MONTHT')
  4417. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4418. elseif ($date == 'MONTHY')
  4419. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4420. if (! empty ( $MebSea )) {
  4421. $con .= ' and ( receivablesMessage like "%' . $MebSea . '%" or receivablesPrice like "%' . $MebSea . '%" )';
  4422. $get .= "/" . $MebSea;
  4423. }
  4424. $pageinfo ['page'] = array (
  4425. 'previous' => ''
  4426. );
  4427. $sql = " bindStatus=1 and receivablesStaff like '" . $sid . "-%' " . $con;
  4428. $pageinfo = $this->get_page ( "CLD_invoiceReceivables", $sql, $page, $page_size, "invoiceReceivablesAchieve", $get, "" );
  4429. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4430. $list = $invoiceReceivables->getReceivablesByUntreadStatusPage ( $limit, $sql );
  4431. // print_r($pageinfo);
  4432. $this->data ['MebSeaEn'] = $MebSea;
  4433. $this->data ['MebSea'] = urlencode ( $MebSea );
  4434. $this->data ['get'] = $get;
  4435. $this->data ['page'] = $pageinfo;
  4436. $this->data ['list'] = $list;
  4437. $this->data ['date'] = $date;
  4438. $this->data ['memu'] = "invoice";
  4439. $this->data ['staff'] = $this->staff;
  4440. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  4441. $this->render ( "/admin/invoiceReceivablesAchieve", $this->data );
  4442. }
  4443. /**
  4444. * 收款解绑
  4445. */
  4446. function invoiceUnBundLing() {
  4447. $unBundKey = $this->get_args ( 'unBundKey' ) ? $this->get_args ( 'unBundKey' ) : '';
  4448. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  4449. Doo::loadModel ( 'invoice' );
  4450. $invoice = new invoice ();
  4451. Doo::loadModel ( 'invoiceReceivables' );
  4452. $invoiceReceivables = new invoiceReceivables ();
  4453. Doo::loadModel ( 'invoiceOperationLog' );
  4454. $invoiceOperationLog = new invoiceOperationLog ();
  4455. Doo::loadModel ( 'invoiceROLog' );
  4456. $invoiceROLog = new invoiceROLog ();
  4457. Doo::loadModel ( 'invoiceStatistics' );
  4458. Doo::loadClass ( 'XDeode' );
  4459. $XDeode = new XDeode ( 5 );
  4460. if (empty ( $iidKey ) || empty ( $unBundKey ))
  4461. die ( 'illegal request' );
  4462. $iid = $XDeode->decode ( $iidKey );
  4463. $irid = $invoice->authcode ( $unBundKey );
  4464. if ((! empty ( $irid ) && ! is_numeric ( $irid )) || (! empty ( $iid ) && ! is_numeric ( $iid )))
  4465. die ( 'illegal request' );
  4466. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4467. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  4468. if (empty ( $irDetails ) || empty ( $invoiceDetails ) || (empty ( $irDetails ['iid'] ) && empty ( $irDetails ['iidExtend'] )) || $invoiceDetails ['untreadStatus'] == 2)
  4469. die ( 'illegal request' );
  4470. // 收款
  4471. $item = array (
  4472. 'irid' => $irDetails ['irid'],
  4473. 'bindPrice' => $irDetails ['bindPrice'] - $invoiceDetails ['invoicePrice'],
  4474. 'bindStatus' => 0
  4475. );
  4476. if ($irDetails ['iid'] == $iid)
  4477. $item += array (
  4478. 'iid' => 0
  4479. );
  4480. else {
  4481. $iidExtend = explode ( ',', $irDetails ['iidExtend'] );
  4482. foreach ( $iidExtend as $key => $value ) {
  4483. if ($value == $iid)
  4484. unset ( $iidExtend [$key] );
  4485. }
  4486. $iidExtend = implode ( ',', $iidExtend );
  4487. $item += array (
  4488. 'iidExtend' => $iidExtend
  4489. );
  4490. }
  4491. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4492. // 收款操作日志
  4493. $item = array (
  4494. 'operation' => $this->staff [0] ['username'] . " 解绑 " . $irDetails ['receivablesSerial'],
  4495. 'date' => date ( "Y-m-d" ),
  4496. 'status' => 3,
  4497. 'img' => $this->staff [0] ['avatar'],
  4498. 'username' => $this->staff [0] ['username'],
  4499. 'uid' => $this->staff [0] ['sid'],
  4500. 'category' => $this->staff [0] ['category'],
  4501. 'irid' => $irid
  4502. );
  4503. $invoiceROLog->setInvoiceROLog ( $item );
  4504. // 扣除入账统计金额
  4505. $invoiceStatistics = new invoiceStatistics ();
  4506. $item = array (
  4507. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  4508. 'priceClass' => 3,
  4509. 'cid' => $invoiceDetails ['cid'],
  4510. 'staff' => $invoiceDetails ['sid'],
  4511. 'accountPrice' => - $irDetails ['receivablesPrice']
  4512. );
  4513. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4514. // 扣除收款统计金额
  4515. $invoiceStatistics = new invoiceStatistics ();
  4516. $item = array (
  4517. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  4518. 'priceClass' => 2,
  4519. 'cid' => $invoiceDetails ['cid'],
  4520. 'staff' => $invoiceDetails ['sid'],
  4521. 'irid' => $irDetails ['irid'],
  4522. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  4523. );
  4524. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4525. // 发票解绑去收款ID
  4526. $iridString = $invoiceDetails ['irid'];
  4527. if (! empty ( $invoiceDetails ['irid'] )) {
  4528. $list = explode ( ',', $invoiceDetails ['irid'] );
  4529. foreach ( $list as $key => $value ) {
  4530. if ($value == $irDetails ['irid']) {
  4531. unset ( $list [$key] );
  4532. break;
  4533. }
  4534. }
  4535. $iridString = implode ( ",", $list );
  4536. }
  4537. $item = array (
  4538. 'iid' => $invoiceDetails ['iid'],
  4539. 'irid' => $iridString,
  4540. 'updateTime' => date ( "Y-m-d H:i:s" )
  4541. );
  4542. if ($invoiceDetails ['untreadStatus'] == 3)
  4543. $item += array (
  4544. 'untreadStatus' => 0
  4545. );
  4546. $invoice->setInvoiceByCondition ( $item );
  4547. $item = array (
  4548. 'date' => date ( "Y-m-d H:i:s" ),
  4549. 'operation' => '解绑 收款 ' . $irDetails ['receivablesSerial'],
  4550. 'status' => 11,
  4551. 'img' => $this->staff [0] ['avatar'],
  4552. 'username' => $this->staff [0] ['username'],
  4553. 'uid' => $this->staff [0] ['sid'],
  4554. 'category' => $this->staff [0] ['category'],
  4555. 'iid' => $invoiceDetails ['iid']
  4556. );
  4557. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  4558. // 公司流水-解绑时删除流水
  4559. Doo::loadModel ( 'wasteBook' );
  4560. $wasteBook = new wasteBook ();
  4561. // $wasteBook->delete ( array (
  4562. // 'where' => 'dataID=' . $irDetails ['irid'] . ' and accountType=7',
  4563. // 'limit' => 1
  4564. // ) );
  4565. // 银行
  4566. /*
  4567. * $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); }
  4568. */
  4569. return "/invoiceReceivablesAS";
  4570. }
  4571. /**
  4572. * 或者该收款下的所以发票
  4573. */
  4574. function ajaxGetInvoiceReceivablesByInvoice() {
  4575. $irid = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : '';
  4576. Doo::loadModel ( 'invoice' );
  4577. $invoice = new invoice ();
  4578. Doo::loadModel ( 'invoiceReceivables' );
  4579. $invoiceReceivables = new invoiceReceivables ();
  4580. $irid = $invoice->authcode ( $irid );
  4581. if (! empty ( $irid ) && ! is_numeric ( $irid ))
  4582. die ( 'illegal request' );
  4583. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4584. $iidString = $irDetails ['iid'];
  4585. $iidExtend = array_filter ( explode ( ',', $irDetails ['iidExtend'] ) );
  4586. if (! empty ( $irDetails ['iidExtend'] ))
  4587. $iidString .= ',' . implode ( ',', $iidExtend );
  4588. $invoiceList = $invoice->getInvoiceInIid ( $iidString, 'iid,invoiceSerial,invoicePrice,invoiceTitle,invoiceCompany,invoiceElement' );
  4589. $html = "";
  4590. foreach ( $invoiceList as $key => $value ) {
  4591. $title = $value ['invoiceTitle'];
  4592. if (! empty ( $value ['invoiceCompany'] ))
  4593. $title = $value ['invoiceCompany'];
  4594. $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>';
  4595. }
  4596. echo json_encode ( array (
  4597. 'status' => 1,
  4598. 'html' => $html
  4599. ) );
  4600. }
  4601. /**
  4602. * 发票管理
  4603. */
  4604. function invoiceAS() {
  4605. Doo::loadModel ( 'invoice' );
  4606. $invoice = new invoice ();
  4607. Doo::loadModel ( 'invoiceReceivables' );
  4608. $invoiceReceivables = new invoiceReceivables ();
  4609. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4610. $page_size = 18;
  4611. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4612. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4613. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4614. $dateArr = explode ( ':', $date );
  4615. $D1 = '';
  4616. $D2 = '';
  4617. if (! empty ( $date )) {
  4618. $D1 = $dateArr [0] . " 00:00:00 ";
  4619. if (isset ( $dateArr [1] ))
  4620. $D2 = $dateArr [1] . " 23:59:59 ";
  4621. else
  4622. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4623. // $D2 = $dateArr [1];
  4624. }
  4625. $con = ' status=2 ';
  4626. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4627. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4628. if ($status == 'UNRECORD')
  4629. $con .= ' and printStatus=1 and untreadStatus=0';
  4630. elseif ($status == 'RECORD')
  4631. $con .= ' and printStatus=1 and untreadStatus=3';
  4632. elseif ($status == 'BOUNCED')
  4633. $con .= ' and untreadStatus=2';
  4634. elseif ($status == 'PARTRECORD')
  4635. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  4636. elseif ($status == 'All') {
  4637. $con .= ' and ( untreadStatus=2 or untreadStatus=1 or untreadStatus=0 or untreadStatus=3 )';
  4638. }
  4639. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4640. if (! empty ( $MebSea )) {
  4641. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  4642. }
  4643. $pageinfo ['page'] = array (
  4644. 'previous' => ''
  4645. );
  4646. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAS", $get, "" );
  4647. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4648. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  4649. $this->data ['MebSeaEn'] = $MebSea;
  4650. $this->data ['MebSea'] = urlencode ( $MebSea );
  4651. $this->data ['date'] = $date;
  4652. $this->data ['page'] = $pageinfo;
  4653. $this->data ['get'] = $get;
  4654. $this->data ['list'] = $list;
  4655. $this->data ['status'] = $status;
  4656. $this->data ['memu'] = "invoice";
  4657. $this->data ['staff'] = $this->staff;
  4658. $this->data ['receiptMemu'] = 'invoiceReceivables';
  4659. $this->render ( "/admin/invoiceAS", $this->data );
  4660. }
  4661. /**
  4662. * 收款管理
  4663. */
  4664. function invoiceReceivablesAS() {
  4665. Doo::loadModel ( 'invoiceReceivables' );
  4666. $invoiceReceivables = new invoiceReceivables ();
  4667. Doo::loadModel ( 'L_category' );
  4668. $lCategory = new L_category ();
  4669. $category = $lCategory->getCategory ();
  4670. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4671. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  4672. $page_size = 10;
  4673. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4674. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4675. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4676. $dateArr = explode ( ':', $date );
  4677. $D1 = '';
  4678. $D2 = '';
  4679. if (! empty ( $date )) {
  4680. $D1 = $dateArr [0]; // ." 00:00:00 ";
  4681. if (isset ( $dateArr [1] ))
  4682. $D2 = $dateArr [1]; // ." 23:59:59 ";
  4683. else
  4684. $D2 = $dateArr [0]; // ." 23:59:59 ";//date ( "Y-m-d" );
  4685. }
  4686. $descField = 'a.receivablesDate';
  4687. if ($timeType == 'CREATE')
  4688. $descField = 'a.date';
  4689. $con = '1';
  4690. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4691. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4692. elseif (! empty ( $D1 ) && empty ( $D2 ))
  4693. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  4694. if ($status == 'Unclaimed')
  4695. $con .= ' and a.bindStatus=0';
  4696. elseif ($status == 'Credited')
  4697. $con .= ' and a.bindStatus=1';
  4698. elseif ($status == 'Claim')
  4699. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  4700. elseif ($status == 'BBN')
  4701. $con .= ' and a.bankBatchNumber!=""';
  4702. elseif ($status == 'REFUND')
  4703. $con .= ' and ( (a.bindStatus=0 and a.refundLog!="" ) or a.bindStatus=2)';
  4704. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4705. if (! empty ( $MebSea )) {
  4706. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" or a.receivablesSerial like "%' . $MebSea . '%" )';
  4707. }
  4708. $pageinfo ['page'] = array (
  4709. 'previous' => ''
  4710. );
  4711. $sql = 'select group_concat(b.invoiceSerial) as invoiceSerial ,group_concat(b.iid) as invoiceId
  4712. from CLD_invoiceReceivables as a left join CLD_invoice as b on
  4713. find_in_set(b.iid,a.iidExtend) or a.iid=b.iid
  4714. where ' . $con . ' group by a.irid ';
  4715. $pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceReceivablesAS", $get, "" );
  4716. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4717. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', $descField );
  4718. foreach ( $list as $key => $value ) {
  4719. $list [$key] ['category'] = '';
  4720. if ($value ['receivablesCategory'] != 'PUBLIC') {
  4721. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  4722. $list [$key] ['category'] = $receivablesCategory [1];
  4723. }
  4724. }
  4725. // print_r($list);
  4726. $this->data ['category'] = $category;
  4727. $this->data ['timeType'] = $timeType;
  4728. $this->data ['MebSeaEn'] = $MebSea;
  4729. $this->data ['MebSea'] = urlencode ( $MebSea );
  4730. $this->data ['date'] = $date;
  4731. $this->data ['page'] = $pageinfo;
  4732. $this->data ['get'] = $get;
  4733. $this->data ['list'] = $list;
  4734. $this->data ['status'] = $status;
  4735. $this->data ['memu'] = "invoice";
  4736. $this->data ['staff'] = $this->staff;
  4737. $this->data ['receiptMemu'] = 'invoiceReceivables';
  4738. $this->render ( "/admin/invoiceReceivablesAS", $this->data );
  4739. }
  4740. /**
  4741. * 删除一条收款
  4742. */
  4743. function delInvoiceReceivables() {
  4744. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  4745. if (empty ( $iridKey ))
  4746. die ( 'illegal request' );
  4747. Doo::loadClass ( 'XDeode' );
  4748. $XDeode = new XDeode ( 5 );
  4749. $irid = $XDeode->decode ( $iridKey );
  4750. Doo::loadModel ( 'invoiceReceivables' );
  4751. $invoiceReceivables = new invoiceReceivables ();
  4752. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4753. if (empty ( $detail ))
  4754. die ( 'illegal request' );
  4755. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  4756. // 扣除收款汇总信息 汇总
  4757. Doo::loadModel ( 'invoiceStatistics' );
  4758. $invoiceStatistics = new invoiceStatistics ();
  4759. $item = array (
  4760. 'date' => $detail ['receivablesDate'],
  4761. 'priceClass' => 2,
  4762. 'irid' => $detail ['irid'],
  4763. 'receivablesPrice' => - $detail ['receivablesPrice']
  4764. );
  4765. if ($detail ['receivablesCategory'] != 'PUBLIC') {
  4766. $receivablesCategory = explode ( ":", $detail ['receivablesCategory'] );
  4767. $item += array (
  4768. 'cid' => $receivablesCategory [0]
  4769. );
  4770. }
  4771. if ($detail ['receivablesStaff'] != 'PUBLIC') {
  4772. $receivablesStaff = explode ( "-", $detail ['receivablesStaff'] );
  4773. $item += array (
  4774. 'staff' => $receivablesStaff [0]
  4775. );
  4776. }
  4777. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4778. return '/invoiceReceivablesAS';
  4779. }
  4780. /**
  4781. * 添加退款信息
  4782. */
  4783. function setInvoiceReceivablesRefund() {
  4784. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  4785. $refundType = $this->get_args ( 'refundType' ) && is_numeric ( $this->get_args ( 'refundType' ) ) ? $this->get_args ( 'refundType' ) : '0';
  4786. $refundCompany = $this->get_args ( 'refundCompany' ) ? $this->get_args ( 'refundCompany' ) : "";
  4787. $refundNumber = $this->get_args ( 'refundNumber' ) ? $this->get_args ( 'refundNumber' ) : "";
  4788. $refundPrice = $this->get_args ( 'refundPrice' ) ? $this->get_args ( 'refundPrice' ) : "";
  4789. $refundRemarks = $this->get_args ( 'refundRemarks' ) ? $this->get_args ( 'refundRemarks' ) : "";
  4790. if ($refundPrice < 0)
  4791. die ( 'illegal request' );
  4792. if (! empty ( $iridKey ) && ! empty ( $refundCompany ) && ! empty ( $refundNumber ) && ! empty ( $refundPrice )) {
  4793. Doo::loadModel ( 'invoiceReceivables' );
  4794. $invoiceReceivables = new invoiceReceivables ();
  4795. Doo::loadModel ( 'invoiceRefund' );
  4796. $invoiceRefund = new invoiceRefund ();
  4797. $irid = $invoiceReceivables->authcode ( $iridKey );
  4798. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4799. if ($irDetail ['receivablesPrice'] < $refundPrice)
  4800. die ( 'illegal request' );
  4801. $invoiceReceivables = new invoiceReceivables ();
  4802. $refundLog = $this->staff [0] ['username'] . ' 退款 <b class="colRed">¥' . $refundPrice . '</b>
  4803. <br/><a href="#refunded" onclick="getRefundByDetail(\'' . $iridKey . '\')" data-toggle="modal">退款信息</a> <br/>' . date ( "Y-m-d H:i:s" ) . '
  4804. ';
  4805. $item = array (
  4806. 'irid' => $irid,
  4807. 'refundCompany' => $refundCompany,
  4808. 'refundNumber' => $refundNumber,
  4809. 'refundPrice' => $refundPrice,
  4810. 'refundRemarks' => $refundRemarks,
  4811. 'refundLog' => $refundLog
  4812. );
  4813. if ($refundType == 1) {
  4814. $item += array (
  4815. 'refundType' => $refundType,
  4816. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice,
  4817. 'bindStatus' => 2
  4818. );
  4819. } elseif ($refundType == 0 && $irDetail ['receivablesPrice'] <= $refundPrice) {
  4820. $item += array (
  4821. 'refundType' => 1,
  4822. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice,
  4823. 'bindStatus' => 2
  4824. );
  4825. } else {
  4826. $item += array (
  4827. 'refundType' => $refundType,
  4828. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice
  4829. );
  4830. }
  4831. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4832. // 添加退款记录
  4833. $item = array (
  4834. 'irid' => $irid,
  4835. 'refundType' => $refundType,
  4836. 'refundCompany' => $refundCompany,
  4837. 'refundNumber' => $refundNumber,
  4838. 'refundPrice' => $refundPrice,
  4839. 'refundLog' => $refundLog,
  4840. 'refundRemarks' => $refundRemarks,
  4841. 'date' => date ( "Y-m-d H:i:s" )
  4842. );
  4843. $invoiceRefund->addInvoiceRefund ( $item );
  4844. // 扣除收款汇总信息 汇总
  4845. Doo::loadModel ( 'invoiceStatistics' );
  4846. $invoiceStatistics = new invoiceStatistics ();
  4847. $item = array (
  4848. 'date' => $irDetail ['receivablesDate'],
  4849. 'priceClass' => 2,
  4850. 'irid' => $irDetail ['irid'],
  4851. 'receivablesPrice' => - $refundPrice
  4852. );
  4853. if ($irDetail ['receivablesCategory'] != 'PUBLIC') {
  4854. $receivablesCategory = explode ( ":", $irDetail ['receivablesCategory'] );
  4855. $item += array (
  4856. 'cid' => $receivablesCategory [0]
  4857. );
  4858. }
  4859. if ($irDetail ['receivablesStaff'] != 'PUBLIC') {
  4860. $receivablesStaff = explode ( "-", $irDetail ['receivablesStaff'] );
  4861. $item += array (
  4862. 'staff' => $receivablesStaff [0]
  4863. );
  4864. }
  4865. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4866. // 公司日常支出流水
  4867. Doo::loadModel ( 'wasteBook' );
  4868. $wasteBook = new wasteBook ();
  4869. $accountBank = '';
  4870. if ($irDetail ['receivablesBank'] == '纵横广发') {
  4871. $accountBank = 'CGBDeposit';
  4872. } elseif ($irDetail ['receivablesBank'] == '纵横工行') {
  4873. $accountBank = 'ICBCDeposit';
  4874. } elseif ($irDetail ['receivablesBank'] == '华润银行') {
  4875. $accountBank = 'HUADeposit';
  4876. } elseif ($irDetail ['receivablesBank'] == '个人广发') {
  4877. $accountBank = 'PersonalDeposit';
  4878. }
  4879. $itemWaste = array (
  4880. 'accountPrice' => - $refundPrice,
  4881. 'expensesType' => 2,
  4882. 'accountType' => 11,
  4883. 'accountPriceShow' => $refundPrice,
  4884. 'dataID' => $irid,
  4885. 'accountBank' => $accountBank,
  4886. 'category' => $this->staff [0] ['category'],
  4887. 'cid' => $this->staff [0] ['cid'],
  4888. 'name' => $this->staff [0] ['username'],
  4889. 'sid' => $this->staff [0] ['sid'],
  4890. 'inputDate' => date ( "Y-m-d H:i:s" )
  4891. );
  4892. $wasteBook->setAccountBookStatistics ( $itemWaste );
  4893. return '/invoiceReceivablesAS';
  4894. }
  4895. die ( 'illegal request' );
  4896. }
  4897. function ajaxCheckInvoiceReceivablesRefund() {
  4898. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  4899. $refundPrice = $this->get_args ( 'refundPrice' ) ? $this->get_args ( 'refundPrice' ) : "";
  4900. if ($refundPrice < 0) {
  4901. echo json_encode ( array (
  4902. 'error' => '金额不能为负'
  4903. ) );
  4904. die ();
  4905. }
  4906. if (! empty ( $refundPrice ) && ! empty ( $iridKey )) {
  4907. Doo::loadModel ( 'invoiceReceivables' );
  4908. $invoiceReceivables = new invoiceReceivables ();
  4909. $irid = $invoiceReceivables->authcode ( $iridKey );
  4910. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4911. if ($irDetail ['receivablesPrice'] < $refundPrice) {
  4912. echo json_encode ( array (
  4913. 'error' => '退款金额不能超过收款金额'
  4914. ) );
  4915. die ();
  4916. }
  4917. echo json_encode ( array (
  4918. 'ok' => '可以使用!'
  4919. ) );
  4920. die ();
  4921. }
  4922. }
  4923. /**
  4924. * 获得收款退款信息
  4925. */
  4926. function getRefundByDetail() {
  4927. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  4928. Doo::loadModel ( 'invoiceReceivables' );
  4929. $invoiceReceivables = new invoiceReceivables ();
  4930. if (! empty ( $iridKey )) {
  4931. $irid = $invoiceReceivables->authcode ( $iridKey );
  4932. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4933. echo json_encode ( array (
  4934. 'status' => 1,
  4935. 'irDetail' => $irDetail
  4936. ) );
  4937. die ();
  4938. }
  4939. echo json_encode ( array (
  4940. 'status' => 2
  4941. ) );
  4942. }
  4943. /**
  4944. * 根据收款序列号获得收款退款信息
  4945. */
  4946. function ajaxGetInvoiceReceivablesBySerial() {
  4947. $receivablesSerial = $this->get_args ( 'receivablesSerial' ) ? $this->get_args ( 'receivablesSerial' ) : '';
  4948. if (! empty ( $receivablesSerial )) {
  4949. Doo::loadModel ( 'invoiceReceivables' );
  4950. $invoiceReceivables = new invoiceReceivables ();
  4951. // , ' and refundLog=""'
  4952. $irDetail = $invoiceReceivables->getInvoiceReceivablesBySerial ( $receivablesSerial );
  4953. $html = '';
  4954. if (! empty ( $irDetail ))
  4955. $html = '<td><b>¥' . $irDetail ['receivablesPrice'] . '</b></td>
  4956. <td>' . $irDetail ['receivablesMessage'] . '</td>
  4957. <td>' . $irDetail ['receivablesBank'] . '<br>' . $irDetail ['receivablesDate'] . '</td>
  4958. <td>' . $irDetail ['title'] . '-' . $irDetail ['username'] . '<br>' . $irDetail ['confirmTime'] . '</td>
  4959. <td>' . $irDetail ['recepitTitleMark'] . '
  4960. <input type="hidden" name="iridKey" id="iridKey" value="' . $irDetail ['iridKey'] . '">
  4961. </td>';
  4962. echo json_encode ( array (
  4963. 'status' => 1,
  4964. 'html' => $html,
  4965. 'irDetail' => $irDetail
  4966. ) );
  4967. die ();
  4968. }
  4969. echo json_encode ( array (
  4970. 'status' => 2
  4971. ) );
  4972. }
  4973. /**
  4974. * 绑定新收款
  4975. */
  4976. function relationNewInvoiceReceivables() {
  4977. $iridKeyOld = $this->get_args ( 'iridKeyOld' ) ? $this->get_args ( 'iridKeyOld' ) : '';
  4978. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  4979. if (! empty ( $iridKeyOld ) && ! empty ( $iridKey )) {
  4980. Doo::loadModel ( 'invoiceReceivables' );
  4981. $invoiceReceivables = new invoiceReceivables ();
  4982. Doo::loadClass ( 'XDeode' );
  4983. $XDeode = new XDeode ( 5 );
  4984. $irid = $XDeode->decode ( $iridKey );
  4985. $iridOld = $invoiceReceivables->authcode ( $iridKeyOld );
  4986. echo $irid . 'bbb' . $iridOld;
  4987. $oldIrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $iridOld );
  4988. $IrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4989. if (empty ( $oldIrDetail ) || empty ( $IrDetail ))
  4990. die ( 'illegal request' );
  4991. $relationLog = $this->staff [0] ['username'] . ' 关联新款 <a href="#billing" onclick="invoiceReceivblesDivShow(\'' . $iridKey . '\',\'receivables\')" data-toggle="modal">' . $IrDetail ['receivablesSerial'] . '</a>
  4992. <br/>' . date ( "Y-m-d H:i:s" ) . '
  4993. ';
  4994. $invoiceReceivables = new invoiceReceivables ();
  4995. $item = array (
  4996. 'irid' => $iridOld,
  4997. 'relationIrid' => $irid,
  4998. 'relationLog' => $relationLog
  4999. );
  5000. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  5001. return '/invoiceReceivablesAS';
  5002. }
  5003. die ( 'illegal request' );
  5004. }
  5005. // function invoiceApprovalAchieve() {
  5006. // Doo::loadModel ( 'invoice' );
  5007. // $invoice = new invoice ();
  5008. // $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  5009. // $page_size = 12;
  5010. // $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5011. // $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  5012. // $get = "/" . $date;
  5013. // $con = '';
  5014. // if ($date == 'MONTHO')
  5015. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  5016. // elseif ($date == 'MONTHT')
  5017. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  5018. // elseif ($date == 'MONTHY')
  5019. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  5020. // if (! empty ( $MebSea )) {
  5021. // $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  5022. // $get .= "/" . $MebSea;
  5023. // }
  5024. // $pageinfo ['page'] = array (
  5025. // 'previous' => ''
  5026. // );
  5027. // $sql = '(status=1 or status=2 or status=3 or status=4) and processApprovals!=""' . $con; // echo $sql;
  5028. // $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", $get, "" );
  5029. // $limit = $pageinfo ['lower'] . ',' . $page_size;
  5030. // $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  5031. // // print_r($list);
  5032. // $this->data ['MebSeaEn'] = $MebSea;
  5033. // $this->data ['MebSea'] = urlencode ( $MebSea );
  5034. // $this->data ['get'] = $get;
  5035. // $this->data ['page'] = $pageinfo;
  5036. // $this->data ['list'] = $list;
  5037. // $this->data ['date'] = $date;
  5038. // $this->data ['memu'] = "invoice";
  5039. // $this->data ['staff'] = $this->staff;
  5040. // $this->data ['receiptMemu'] = 'invoiceApproval';
  5041. // $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  5042. // }
  5043. /**
  5044. * 获得审批发票的信息以及审批页面
  5045. */
  5046. function ajaxGetInvoiceApprovalDetail() {
  5047. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5048. if (empty ( $serial )) {
  5049. echo json_encode ( array (
  5050. 'status' => 2,
  5051. 'msg' => 'illegal request'
  5052. ) );
  5053. die ();
  5054. }
  5055. Doo::loadModel ( 'invoice' );
  5056. $invoice = new invoice ();
  5057. Doo::loadModel ( 'invoiceOperationLog' );
  5058. $invoiceOperationLog = new invoiceOperationLog ();
  5059. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5060. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5061. if (empty ( $detail ))
  5062. $html = '';
  5063. else {
  5064. $html = '
  5065. <form action="/invoiceApprovalDo" method="post" name="invoiceApproval" class="nice-validator n-yellow" novalidate="novalidate">
  5066. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  5067. <input type="hidden" name="status" value="">
  5068. <input type="hidden" name="divApproval" value="divApproval">
  5069. <div class="modal-dialog modal-lg">
  5070. <div class="modal-content"><div class="modal-header"><h3>发票审批详情</h3></div>
  5071. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  5072. <tr>
  5073. <th class="taC" width="150">发票审批</th><td><textarea name="opinion" style="width:98%" placeholder="在这写下您的审批意见,选填。"></textarea></td>
  5074. </tr>
  5075. <tr>
  5076. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5077. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5078. </tr>
  5079. <tr>
  5080. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5081. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5082. </tr>
  5083. <tr>
  5084. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5085. </td>
  5086. </tr>
  5087. <tr>
  5088. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5089. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5090. </tr>
  5091. <tr>
  5092. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5093. </tr></tbody></table>';
  5094. if ($detail ['invoiceType'] == 0)
  5095. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5096. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5097. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5098. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5099. </tr>';
  5100. else
  5101. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5102. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5103. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5104. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5105. ';
  5106. $html .= '<tr>
  5107. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5108. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5109. </tr>
  5110. <tr>
  5111. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5112. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5113. </tr></tbody></table>';
  5114. if ($detail ['doPost'] == 1) {
  5115. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5116. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5117. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5118. </tr><tr>
  5119. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5120. </tr><tr>
  5121. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5122. </tr>
  5123. ';
  5124. if ($detail ['expressCom'] == 'SF')
  5125. $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>';
  5126. else
  5127. $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>';
  5128. $html .= '</tbody></table>';
  5129. }
  5130. if (! empty ( $invoiceOperationLogList )) {
  5131. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  5132. foreach ( $invoiceOperationLogList as $key => $value ) {
  5133. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5134. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5135. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5136. if ($value ['status'] == 2) {
  5137. $html .= '<span class="colGreen">同意</span>';
  5138. } elseif ($value ['status'] == 3) {
  5139. $html .= '<span class="colOrange">退回</span>';
  5140. } elseif ($value ['status'] == 5) {
  5141. $html .= '<span class="colGreen">打印</span>';
  5142. } elseif ($value ['status'] == 4) {
  5143. $html .= '<span class="colRed">终止</span>';
  5144. }
  5145. $html .= $value ['operation'] . '</p></blockquote>';
  5146. }
  5147. }
  5148. $html .= '</td></tr></tbody></table>';
  5149. }
  5150. $html .= '</div><div class="modal-footer">
  5151. <a href="javascript:void(0)" node-approval="approval" diss-data="2" class="button btn-done" data-placement="top" data-toggle="ctooltip" >同意</a>
  5152. <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>
  5153. <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>
  5154. <a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>
  5155. </form>
  5156. <script type="text/javascript">
  5157. $("a[node-approval^=\'approval\']").click(function() {
  5158. $("input[name=\'status\']").val($(this).attr("diss-data"));
  5159. $("form[name=\'invoiceApproval\']").submit();
  5160. });
  5161. </script>
  5162. ';
  5163. }
  5164. echo json_encode ( array (
  5165. 'status' => 1,
  5166. 'html' => $html
  5167. ) );
  5168. die ();
  5169. }
  5170. /**
  5171. * 获得审批发票分页数据
  5172. */
  5173. function ajaxGetinvoiceApprovalAchieve() {
  5174. Doo::loadModel ( 'invoice' );
  5175. $invoice = new invoice ();
  5176. Doo::loadModel ( 'staff' );
  5177. $staff = new staff ();
  5178. Doo::loadClass ( 'XDeode' );
  5179. $XDeode = new XDeode ( 5 );
  5180. Doo::loadModel ( 'invoiceTraining' );
  5181. $invoiceTraining = new invoiceTraining ();
  5182. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  5183. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5184. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5185. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5186. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5187. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  5188. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  5189. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  5190. $MebSea = $this->get_args ( 'search' );
  5191. $MebSea = $MebSea ['value'];
  5192. $page_size = $length;
  5193. $con = '';
  5194. if ($status == 'ALL')
  5195. $con = ' (status=1 or status=2 or status=3 or status=4) and isDelete=0 ';
  5196. elseif ($status == 'PEND')
  5197. $con = ' isDelete=0 and status=1';
  5198. elseif ($status == 'APPROVED')
  5199. $con = ' isDelete=0 and status=2';
  5200. if ($invoiceType == 'ORDINARY')
  5201. $con .= ' and invoiceType=0 ';
  5202. elseif ($invoiceType == 'SPECIAL')
  5203. $con .= ' and invoiceType=1 ';
  5204. if ($invoiceTrain == 'ORDINARY')
  5205. $con .= ' and trainId=0 ';
  5206. elseif ($invoiceTrain == 'TRAIN')
  5207. $con .= ' and trainId!=0 ';
  5208. if ($invoiceTrainName != 'ALL') {
  5209. $trainId = $XDeode->decode ( $invoiceTrainName );
  5210. if (is_numeric ( $trainId ))
  5211. $con .= ' and trainId =' . $trainId;
  5212. }
  5213. $dateArr = explode ( ':', $date );
  5214. $D1 = $dateString = '';
  5215. $D2 = '';
  5216. if (! empty ( $date )) {
  5217. $D1 = $dateArr [0];
  5218. if (isset ( $dateArr [1] ))
  5219. $D2 = $dateArr [1];
  5220. else
  5221. $D2 = '';
  5222. $dateString = $D1 . " : " . $D2;
  5223. }
  5224. if (! empty ( $D1 ) && ! empty ( $D2 ))
  5225. $con .= ' and approvalTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  5226. elseif (! empty ( $D1 ) && empty ( $D2 ))
  5227. $con .= ' and approvalTime like "%' . $D1 . '%" ';
  5228. if (! empty ( $MebSea ))
  5229. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceSerial like "%' . $MebSea . '%" )';
  5230. // /
  5231. $pageinfo ['page'] = array (
  5232. 'previous' => ''
  5233. );
  5234. $sql = ' ' . $con;
  5235. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", '', "" );
  5236. $limit = $page . ',' . $page_size;
  5237. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  5238. $approvalList = array ();
  5239. $html = '<script type="text/javascript">
  5240. </script>';
  5241. //结算结束不能修改方式
  5242. Doo::loadModel ( 'receipt' );
  5243. $receipt = new receipt ();
  5244. foreach ( $list as $key => $value ) {
  5245. $irDetail = array ();
  5246. //结算方式
  5247. $receiptDetail=array();
  5248. if($value ['trainId']!=0){
  5249. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $value ['trainId'] );
  5250. }
  5251. if (! empty ( $receiptDetail )) {
  5252. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9) {
  5253. array_push ( $irDetail, '' );
  5254. }else{
  5255. if ($value ['status'] == 1 && $value ['pendingApprovals'] == $this->staff [0] ['sid']) {
  5256. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoiceApproval(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">审批发票</a>' );
  5257. }elseif($value ['status'] == 2){
  5258. array_push ( $irDetail, '<a href="#editPay" class="fnSettlementType" data-iidKey="' . $value ['iidKeyK'] . '" data-toggle="modal">结算方式</a>' );
  5259. } else
  5260. array_push ( $irDetail, '' );
  5261. }
  5262. }else{
  5263. if($value ['status'] == 2){
  5264. array_push ( $irDetail, '<a href="#editPay" class="fnSettlementType" data-iidKey="' . $value ['iidKeyK'] . '" data-toggle="modal">结算方式</a>' );
  5265. } else
  5266. array_push ( $irDetail, '' );
  5267. }
  5268. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  5269. if ($value ['invoiceType'] == 1)
  5270. array_push ( $irDetail, $value ['invoiceCompany'] );
  5271. else
  5272. array_push ( $irDetail, $value ['invoiceTitle'] );
  5273. array_push ( $irDetail, $value ['TIN'] );
  5274. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  5275. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  5276. array_push ( $irDetail, $value ['remark'] );
  5277. array_push ( $irDetail, $value ['invoiceElement'] );
  5278. array_push ( $irDetail, $value ['invoiceQuantity'] );
  5279. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  5280. if ($value ['invoiceType'] == 1){
  5281. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  5282. }else{
  5283. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  5284. }
  5285. if ($value ['settlementType'] == 0 ) {
  5286. array_push ( $irDetail, '软件销售' );
  5287. }else{
  5288. $itDetail=$invoiceTraining->getInvoiceTrainingByItid($value['trainId']);
  5289. array_push ( $irDetail, $itDetail['trainName'] );
  5290. }
  5291. array_push ( $irDetail, $value ['recipients'] . $value ['recipientsPhone'] );
  5292. array_push ( $irDetail, $value ['recipientsAddress'] );
  5293. array_push ( $irDetail, $value ['mailItems'] );
  5294. array_push ( $irDetail, $value ['userName'] . '&nbsp;' . $value ['date'] );
  5295. $fchtml = $value ['OL'] ['operation'];
  5296. if (count ( $list ) == $page_size)
  5297. $fchtml = $value ['OL'] ['operation'] . $html;
  5298. // 最后的审批意见
  5299. array_push ( $irDetail, $fchtml );
  5300. if ($value ['status'] == 2)
  5301. array_push ( $irDetail, '<span class="colGreen">同意</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5302. elseif ($value ['status'] == 3)
  5303. array_push ( $irDetail, '<span class="colOrange">退回</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5304. elseif ($value ['status'] == 4)
  5305. array_push ( $irDetail, '<span class="colRed">终止</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5306. else
  5307. array_push ( $irDetail, '' );
  5308. array_push ( $approvalList, $irDetail );
  5309. }
  5310. // $approvalListJson = json_encode ( $approvalList );
  5311. $recordsFiltered = $pageinfo ['total_data'];
  5312. echo json_encode ( array (
  5313. "draw" => intval ( $draw ),
  5314. "recordsTotal" => intval ( $pageinfo ['total_data'] ),
  5315. "recordsFiltered" => intval ( $recordsFiltered ),
  5316. "data" => $approvalList
  5317. ), JSON_UNESCAPED_UNICODE );
  5318. }
  5319. /**
  5320. * 审批发票查看更多--重构
  5321. */
  5322. function invoiceApprovalAchieve() {
  5323. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'ALL';
  5324. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5325. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5326. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5327. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5328. Doo::loadModel ( 'invoiceTraining' );
  5329. $invoiceTraining = new invoiceTraining ();
  5330. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  5331. $this->data ['trainList'] = $trainList;
  5332. $this->data ['dateString'] = $date;
  5333. $this->data ['status'] = $status;
  5334. $this->data ['invoiceType'] = $invoiceType;
  5335. $this->data ['invoiceTrain'] = $invoiceTrain;
  5336. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  5337. $this->data ['memu'] = "invoice";
  5338. $this->data ['staff'] = $this->staff;
  5339. $this->data ['receiptMemu'] = 'invoiceApproval';
  5340. $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  5341. }
  5342. function invoiceTAchieve() {
  5343. Doo::loadModel ( 'invoice' );
  5344. $invoice = new invoice ();
  5345. Doo::loadClass ( 'XDeode' );
  5346. $XDeode = new XDeode ( 5 );
  5347. Doo::loadModel ( 'staff' );
  5348. $staff = new staff ();
  5349. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  5350. $page_size = 12;
  5351. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5352. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  5353. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5354. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5355. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5356. Doo::loadModel ( 'invoiceTraining' );
  5357. $invoiceTraining = new invoiceTraining ();
  5358. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  5359. $get = "/" . $date;
  5360. $con = '';
  5361. if ($date == 'MONTHO')
  5362. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  5363. elseif ($date == 'MONTHT')
  5364. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  5365. elseif ($date == 'MONTHY')
  5366. $con = ' and YEAR(updateTime) = YEAR(NOW())'; // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  5367. if ($invoiceType == 'ORDINARY')
  5368. $con .= ' and invoiceType=0 ';
  5369. elseif ($invoiceType == 'SPECIAL')
  5370. $con .= ' and invoiceType=1 ';
  5371. if ($invoiceTrain == 'ORDINARY')
  5372. $con .= ' and trainId=0 ';
  5373. elseif ($invoiceTrain == 'TRAIN')
  5374. $con .= ' and trainId!=0 ';
  5375. if ($invoiceTrainName != 'ALL') {
  5376. $trainId = $XDeode->decode ( $invoiceTrainName );
  5377. if (is_numeric ( $trainId ))
  5378. $con .= ' and trainId =' . $trainId;
  5379. }
  5380. if (! empty ( $MebSea )) {
  5381. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  5382. $get .= "/" . $MebSea;
  5383. }
  5384. $pageinfo ['page'] = array (
  5385. 'previous' => ''
  5386. );
  5387. $sql = "";
  5388. $action = "";
  5389. if ($this->ACTION == 'invoicePrintAchieve') {
  5390. $sql = "status=2 and printStatus=1 and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  5391. $action = "invoicePrintAchieve";
  5392. } elseif ($this->ACTION == 'invoicePostAchieve') {
  5393. // and untreadStatus=0
  5394. $sql = "postStatus=1 and doPost=1 and status=2 and isDelete=0" . $con;
  5395. $action = "invoicePostAchieve";
  5396. } elseif ($this->ACTION == 'invoiceUntreadAchieve') { // printStatus=1 and
  5397. $sql = " untreadStatus=2 and status=2 " . $con;
  5398. $action = "invoiceUntreadAchieve";
  5399. }
  5400. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  5401. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5402. $this->data ['MebSeaEn'] = $MebSea;
  5403. $this->data ['MebSea'] = urlencode ( $MebSea );
  5404. $this->data ['get'] = $get;
  5405. $this->data ['page'] = $pageinfo;
  5406. $this->data ['trainList'] = $trainList;
  5407. $this->data ['invoiceType'] = $invoiceType;
  5408. $this->data ['invoiceTrain'] = $invoiceTrain;
  5409. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  5410. $this->data ['date'] = $date;
  5411. $this->data ['memu'] = "invoice";
  5412. $this->data ['staff'] = $this->staff;
  5413. if ($this->ACTION == 'invoicePrintAchieve') {
  5414. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  5415. $this->data ['receiptMemu'] = 'invoicePrint';
  5416. $this->data ['list'] = $list;
  5417. $this->render ( "/admin/invoicePrintAchieve", $this->data );
  5418. } elseif ($this->ACTION == 'invoicePostAchieve') {
  5419. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  5420. Doo::loadModel ( 'express' );
  5421. $express = new express ();
  5422. $expressList = $express->getExpressByAll ();
  5423. $this->data ['expressList'] = $expressList;
  5424. $this->data ['receiptMemu'] = 'invoicePost';
  5425. $this->data ['list'] = $list;
  5426. $this->render ( "/admin/invoicePostAchieve", $this->data );
  5427. } elseif ($this->ACTION == 'invoiceUntreadAchieve') {
  5428. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  5429. $this->data ['receiptMemu'] = 'invoiceUntread';
  5430. $this->data ['list'] = $list;
  5431. $this->render ( "/admin/invoiceUntreadAchieve", $this->data );
  5432. }
  5433. }
  5434. /**
  5435. * 公司应收款
  5436. */
  5437. function invoiceAggregateCompanyDetail() {
  5438. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  5439. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  5440. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : 'ALL';
  5441. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  5442. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  5443. Doo::loadClass ( 'XDeode' );
  5444. $XDeode = new XDeode ( 5 );
  5445. Doo::loadModel ( 'invoice' );
  5446. $invoice = new invoice ();
  5447. Doo::loadModel ( 'staff' );
  5448. $staff = new staff ();
  5449. Doo::loadModel ( "invoiceCompanyManage" );
  5450. $invoiceCompanyManage = new invoiceCompanyManage ();
  5451. Doo::loadModel ( 'L_category' );
  5452. $category = new L_category ();
  5453. $sid = '';
  5454. if (! empty ( $sidKey )) {
  5455. $sid = $XDeode->decode ( $sidKey );
  5456. }
  5457. $staffDetail = $staff->getStaffBySid ( $sid );
  5458. $cid = '';
  5459. if (! empty ( $cidKey )) {
  5460. $cid = $XDeode->decode ( $cidKey );
  5461. }
  5462. $imcStaff = $invoiceCompanyManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  5463. $cidList = array ();
  5464. foreach ( $imcStaff as $key => $value ) {
  5465. array_push ( $cidList, $value ['cid'] );
  5466. }
  5467. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  5468. $cidString = implode ( ',', $cidList );
  5469. if (empty ( $cid ))
  5470. $staffList = $staff->getStaffInCid ( $cidString );
  5471. else
  5472. $staffList = $staff->getStaffByCidAll ( $cid ); //
  5473. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  5474. $page_size = 25;
  5475. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5476. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  5477. $con = ' status=2 and untreadStatus!=2 ';
  5478. $statisticsCon = '';
  5479. if (! empty ( $year ) && is_numeric ( $year ))
  5480. $con .= ' and Year(printTime)=' . $year . '';
  5481. if (! empty ( $month ) && is_numeric ( $month ))
  5482. $con .= ' and Month(printTime)="' . $month . '" ';
  5483. if ($status == 'UNRECORD')
  5484. $con .= ' and printStatus=1 and untreadStatus=0';
  5485. elseif ($status == 'RECORD')
  5486. $con .= ' and printStatus=1 and untreadStatus=3';
  5487. elseif ($status == 'BOUNCED')
  5488. $con .= ' and untreadStatus=2';
  5489. elseif ($status == 'PARTRECORD')
  5490. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  5491. elseif ($status == 'All') {
  5492. $con .= ' and printStatus=1 and ( untreadStatus=0 or untreadStatus=3 )';
  5493. }
  5494. if (! empty ( $sid ) && is_numeric ( $sid ))
  5495. $con .= ' and sid=' . $sid;
  5496. if (! empty ( $cid ) && is_numeric ( $cid ))
  5497. $con .= ' and cid=' . $cid;
  5498. else
  5499. $con .= ' and cid in (' . $cidString . ')';
  5500. // 开票内容筛选
  5501. if (! empty ( $invoiceElement ) && $invoiceElement != 'ALL') {
  5502. $con .= ' and invoiceElement="' . $invoiceElement . '"';
  5503. }
  5504. $get = "/" . $status . "?cidKey=" . $cidKey . "&sidKey=" . $sidKey . "&year=" . $year . "&month=" . $month . "&invoiceElement=" . $invoiceElement;
  5505. if (! empty ( $MebSea )) {
  5506. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  5507. }
  5508. $pageinfo ['page'] = array (
  5509. 'previous' => ''
  5510. );
  5511. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateCompanyDetail", $get, "" );
  5512. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5513. // 应收款合计
  5514. $ics = $invoice->getInvoiceCompanyStatistics ( $con );
  5515. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  5516. $monthHtml = "";
  5517. if ($year != "ALL") {
  5518. for($i = 1; $i <= 12; $i ++) {
  5519. if ($i == $month)
  5520. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  5521. else
  5522. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  5523. }
  5524. }
  5525. $this->data ['monthHtml'] = $monthHtml;
  5526. $this->data ['year'] = $year;
  5527. $this->data ['month'] = $month;
  5528. $this->data ['ics'] = $ics;
  5529. $this->data ['cidKey'] = $cidKey;
  5530. $this->data ['sid'] = $sid;
  5531. $this->data ['staffDetail'] = $staffDetail;
  5532. $this->data ['staffList'] = $staffList;
  5533. $this->data ['MebSeaEn'] = $MebSea;
  5534. $this->data ['MebSea'] = urlencode ( $MebSea );
  5535. $this->data ['invoiceDetail'] = array (
  5536. 'invoiceElement' => $invoiceElement
  5537. );
  5538. $this->data ['page'] = $pageinfo;
  5539. $this->data ['get'] = $get;
  5540. $this->data ['list'] = $list;
  5541. $this->data ['status'] = $status;
  5542. $this->data ['categoryList'] = $categoryList;
  5543. $this->data ['memu'] = "invoice";
  5544. $this->data ['staff'] = $this->staff;
  5545. $this->data ['receiptMemu'] = 'invoiceAggregateCompanyDetail';
  5546. $this->render ( "/admin/invoiceAggregateCompanyDetail", $this->data );
  5547. }
  5548. /**
  5549. * 获取一条收款信息
  5550. */
  5551. function ajaxGetInvoiceReceivables() {
  5552. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  5553. Doo::loadModel ( 'invoiceReceivables' );
  5554. $invoiceReceivables = new invoiceReceivables ();
  5555. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5556. echo json_encode ( array (
  5557. 'status' => 1,
  5558. 'detail' => $detail
  5559. ) );
  5560. }
  5561. /**
  5562. * 异步获取办事处用户
  5563. */
  5564. function ajaxGetStaffByCategory() {
  5565. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "";
  5566. Doo::loadModel ( 'staff' );
  5567. $staff = new staff ();
  5568. if ($cid == "PUBLIC") {
  5569. echo json_encode ( array (
  5570. 'status' => 1,
  5571. 'html' => '<option value="PUBLIC">办事处待认领款项</option>'
  5572. ) );
  5573. die ();
  5574. }
  5575. if (! is_numeric ( $cid )) {
  5576. echo json_encode ( array (
  5577. 'status' => 0,
  5578. 'msg' => 'illegal request'
  5579. ) );
  5580. die ();
  5581. }
  5582. $staffList = $staff->getStaffByCid ( $cid );
  5583. $html = '<option value="PUBLIC">办事处待认领款项</option>';
  5584. foreach ( $staffList as $key => $value ) {
  5585. $html .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  5586. }
  5587. echo json_encode ( array (
  5588. 'status' => 1,
  5589. 'html' => $html
  5590. ) );
  5591. }
  5592. /**
  5593. * 异步获取一条发票的邮寄信息
  5594. */
  5595. function ajaxGetInvoicePostDetail() {
  5596. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  5597. Doo::loadModel ( 'invoice' );
  5598. $invoice = new invoice ();
  5599. $iid = $invoice->authcode ( $iid );
  5600. Doo::loadModel ( 'express' );
  5601. $express = new express ();
  5602. $expressList = $express->getExpressByAll ();
  5603. if (! is_numeric ( $iid )) {
  5604. echo json_encode ( array (
  5605. 'status' => 0,
  5606. 'msg' => 'illegal request'
  5607. ) );
  5608. die ();
  5609. }
  5610. $select = "iid,recipients,recipientsPhone,recipientsAddress,mailItems,expressCompany,expressNumber,actualItems";
  5611. $invoiceDetail = $invoice->getInvoiceByIid ( $iid, $select );
  5612. $html = "";
  5613. foreach ( $expressList as $key => $value ) {
  5614. if ($value ['company'] == $invoiceDetail ['expressCompany'])
  5615. $html .= '<option selected value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  5616. else
  5617. $html .= '<option value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  5618. }
  5619. $invoiceDetail ['eaHtml'] = $html;
  5620. echo json_encode ( array (
  5621. 'status' => 1,
  5622. 'invoiceDetail' => $invoiceDetail
  5623. ) );
  5624. }
  5625. /**
  5626. *
  5627. * @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 ) ); }
  5628. */
  5629. /**
  5630. *
  5631. * @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 ) ); }
  5632. */
  5633. /**
  5634. * 我的收款中 选择哪个发票入账,进行金额判断
  5635. */
  5636. function ajaxCompareInvoicePrice() {
  5637. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  5638. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  5639. Doo::loadModel ( 'invoice' );
  5640. $invoice = new invoice ();
  5641. Doo::loadModel ( 'invoiceReceivables' );
  5642. $invoiceReceivables = new invoiceReceivables ();
  5643. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  5644. $keyList = explode ( ';', $claimKey );
  5645. $receivablesPrice = 0;
  5646. foreach ( $keyList as $key => $value ) {
  5647. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $value );
  5648. $receivablesPrice += $detailM ['receivablesPrice'];
  5649. }
  5650. if ($receivablesPrice > $detail ['invoicePrice']) {
  5651. $price = $receivablesPrice - $detail ['invoicePrice'];
  5652. echo json_encode ( array (
  5653. 'status' => 1,
  5654. 'price' => $price
  5655. ) );
  5656. } else
  5657. echo json_encode ( array (
  5658. 'status' => 2
  5659. ) );
  5660. }
  5661. /**
  5662. * 获得打印发票
  5663. */
  5664. function ajaxGetInvoiceInfoByPrint() {
  5665. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5666. if (empty ( $serial )) {
  5667. echo json_encode ( array (
  5668. 'status' => 2,
  5669. 'msg' => 'illegal request'
  5670. ) );
  5671. die ();
  5672. }
  5673. Doo::loadModel ( 'invoice' );
  5674. $invoice = new invoice ();
  5675. Doo::loadModel ( 'invoiceOperationLog' );
  5676. $invoiceOperationLog = new invoiceOperationLog ();
  5677. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5678. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5679. Doo::loadModel ( 'invoicePaper' );
  5680. $invoicePaper = new invoicePaper ();
  5681. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $detail ['invoiceType'] );
  5682. if (empty ( $detail ))
  5683. $html = '';
  5684. else {
  5685. $html = '
  5686. <form action="/invoicePrintDo" method="post" name="invoicePrint" class="nice-validator n-yellow" onSubmit="return checkPrintForm()" novalidate="novalidate">
  5687. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  5688. <input type="hidden" name="invoicePrintType" value="invoicePrintType">
  5689. <div class="modal-dialog modal-lg">
  5690. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  5691. <div class="modal-body saeaList">
  5692. <table class="table table-bordered table-condensed"><tbody>
  5693. <tr>
  5694. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5695. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5696. </tr>
  5697. <tr>
  5698. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5699. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5700. </tr>
  5701. <tr>
  5702. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5703. </td>
  5704. </tr>
  5705. <tr>
  5706. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5707. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5708. </tr>
  5709. <tr>
  5710. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5711. </tr></tbody></table>';
  5712. if ($detail ['invoiceType'] == 0)
  5713. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5714. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5715. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5716. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5717. </tr>';
  5718. else
  5719. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5720. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5721. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5722. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5723. ';
  5724. $html .= '<tr>
  5725. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5726. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5727. </tr>
  5728. <tr>
  5729. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5730. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5731. </tr></tbody></table>';
  5732. if ($detail ['doPost'] == 1)
  5733. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5734. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5735. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5736. </tr><tr>
  5737. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5738. </tr><tr>
  5739. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5740. </tr></tbody></table>';
  5741. if (! empty ( $invoiceOperationLogList )) {
  5742. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th><th class="taC">发票打印</th></tr><tr><td>';
  5743. foreach ( $invoiceOperationLogList as $key => $value ) {
  5744. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5745. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5746. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5747. if ($value ['status'] == 2) {
  5748. $html .= '<span class="colGreen">同意</span>';
  5749. } elseif ($value ['status'] == 3) {
  5750. $html .= '<span class="colOrange">退回</span>';
  5751. } elseif ($value ['status'] == 5) {
  5752. $html .= '<span class="colGreen">打印</span>';
  5753. } elseif ($value ['status'] == 4) {
  5754. $html .= '<span class="colRed">终止</span>';
  5755. }
  5756. $html .= $value ['operation'] . '</p></blockquote>';
  5757. }
  5758. }
  5759. $html .= '</td>
  5760. <td><span class="colRed">*</span>
  5761. <select name="invoiceNo" id="invoiceNo" style="width:97%">';
  5762. foreach ( $invoicePaperList as $key => $value ) {
  5763. $html .= '<option value="' . $value ['ipidKey'] . '">No.' . $value ['invoiceNo'] . '</option>';
  5764. }
  5765. $html .= '</select>
  5766. <span class="red" id="p-msg"></span>
  5767. </td>
  5768. </tr></tbody></table>';
  5769. }
  5770. $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>
  5771. </div></div></form>
  5772. <link rel=stylesheet href="' . WEB_SITE_GLOBAL . 'css/jquery.validator.css">
  5773. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/jquery.validator.min.js"></script>
  5774. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/zh-CN.js"></script>
  5775. <script src="' . WEB_SITE_GLOBAL . 'js/invoice.validator.js"></script>
  5776. ';
  5777. }
  5778. echo json_encode ( array (
  5779. 'status' => 1,
  5780. 'html' => $html
  5781. ) );
  5782. die ();
  5783. }
  5784. /**
  5785. * @ 获得与我有关收款数据 --需求变更 废弃 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 ) ); }
  5786. */
  5787. function ajaxGetInvoiceInfoByType() {
  5788. $type = $this->get_args ( 'type' ) ? $this->get_args ( 'type' ) : "";
  5789. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5790. $loss = $this->get_args ( 'loss' ) ? $this->get_args ( 'loss' ) : false;
  5791. if (empty ( $serial )) {
  5792. echo json_encode ( array (
  5793. 'status' => 2,
  5794. 'msg' => 'illegal request'
  5795. ) );
  5796. die ();
  5797. }
  5798. if ($type == 'INVOICE') {
  5799. Doo::loadModel ( 'invoice' );
  5800. $invoice = new invoice ();
  5801. Doo::loadModel ( 'invoiceOperationLog' );
  5802. $invoiceOperationLog = new invoiceOperationLog ();
  5803. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5804. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5805. if (empty ( $detail ))
  5806. $html = '';
  5807. else {
  5808. $html = '
  5809. <div class="modal-dialog modal-lg">
  5810. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  5811. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  5812. <tr>
  5813. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5814. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5815. </tr>
  5816. <tr>
  5817. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5818. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5819. </tr>
  5820. <tr>
  5821. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5822. </td>
  5823. </tr>
  5824. <tr>
  5825. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5826. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5827. </tr>
  5828. <tr>
  5829. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5830. </tr>';
  5831. if ($detail ['settlementType'] == 1)
  5832. $html .= '<tr>
  5833. <th class="taC" width="150">结算方式</th><td colspan="3">培训班(<a href="/invoiceTrainingDetail/' . $detail ['invoiceTraining'] ['trainingKey'] . '.html" target="_blank">' . $detail ['invoiceTraining'] ['trainName'] . '</a>)</td>
  5834. </tr>';
  5835. else
  5836. $html .= '<tr>
  5837. <th class="taC" width="150">结算方式</th><td colspan="3">软件销售</td>
  5838. </tr>';
  5839. $html .= ' </tbody></table>';
  5840. if ($detail ['invoiceType'] == 0)
  5841. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5842. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5843. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5844. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5845. </tr>';
  5846. else
  5847. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5848. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5849. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5850. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5851. ';
  5852. $html .= '<tr>
  5853. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5854. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5855. </tr>
  5856. <tr>
  5857. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5858. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5859. </tr></tbody></table>';
  5860. if ($detail ['doPost'] == 1) {
  5861. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5862. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5863. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5864. </tr><tr>
  5865. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5866. </tr><tr>
  5867. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5868. </tr>
  5869. ';
  5870. if ($detail ['expressCom'] == 'SF')
  5871. $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>';
  5872. else
  5873. $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>';
  5874. $html .= '</tbody></table>';
  5875. }
  5876. if (! empty ( $invoiceOperationLogList )) {
  5877. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  5878. foreach ( $invoiceOperationLogList as $key => $value ) {
  5879. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5880. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5881. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5882. if ($value ['status'] == 2) {
  5883. $html .= '<span class="colGreen">同意</span>';
  5884. } elseif ($value ['status'] == 3) {
  5885. $html .= '<span class="colOrange">退回</span>';
  5886. } elseif ($value ['status'] == 5) {
  5887. $html .= '<span class="colGreen">打印</span>';
  5888. } elseif ($value ['status'] == 4) {
  5889. $html .= '<span class="colRed">终止</span>';
  5890. }
  5891. $html .= $value ['operation'] . '</p></blockquote>';
  5892. }
  5893. }
  5894. $html .= '</td></tr></tbody></table>';
  5895. }
  5896. $html .= '</div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  5897. }
  5898. echo json_encode ( array (
  5899. 'status' => 1,
  5900. 'html' => $html
  5901. ) );
  5902. die ();
  5903. } elseif ($type == 'RECEIVABLES') {
  5904. Doo::loadModel ( 'invoiceReceivables' );
  5905. $invoiceReceivables = new invoiceReceivables ();
  5906. Doo::loadModel ( 'invoiceRefund' );
  5907. $invoiceRefund = new invoiceRefund ();
  5908. $detail = $invoiceReceivables->getInvoiceReceivablesByIrsid ( $serial );
  5909. $ireList = $invoiceRefund->getInvoiceRefundIrid ( $detail ['irid'] );
  5910. if (empty ( $detail ))
  5911. $html = '';
  5912. else {
  5913. $html = '<div class="modal-dialog modal-lg"><div class="modal-content"><div class="modal-header"><h3>收款单详情</h3></div><div class="modal-body saeaList">
  5914. <table class="table table-bordered table-condensed">
  5915. <tbody><tr>
  5916. <th class="taC">收款流水号</th><td>' . $detail ['receivablesSerial'] . '</td>
  5917. <th class="taC">录入收款</th><td>' . $detail ['inputStaff'] . ' ' . $detail ['date'] . '</td>
  5918. </tr><tr>
  5919. <th class="taC">收款金额</th><td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  5920. <th class="taC">收款信息</th><td>' . $detail ['receivablesMessage'] . '</td>
  5921. </tr>
  5922. <tr>
  5923. <th class="taC">收款银行</th><td>' . $detail ['receivablesBank'] . '</td>
  5924. <th class="taC">银行到账</th><td>' . $detail ['receivablesDate'] . '</td>
  5925. </tr>
  5926. <tr>
  5927. <th class="taC">认领收款</th><td colspan="3">' . $detail ['inputStaff'] . ' 转入 ' . $detail ['username'] . ' ' . $detail ['confirmTime'] . '</td>
  5928. </tr>
  5929. </tbody></table>';
  5930. if (! empty ( $ireList )) {
  5931. $html .= '
  5932. <table class="table table-bordered table-condensed"><tbody><tr><th class="taC" colspan="5">退款记录</th></tr>
  5933. <tr>
  5934. <th class="taC">退款单位名称</th>
  5935. <th class="taC">退款的账号</th>
  5936. <th class="taC">退款金额</th>
  5937. <th class="taC">退款</th>
  5938. <th class="taC">备注</th>
  5939. </tr>
  5940. ';
  5941. foreach ( $ireList as $key => $value ) {
  5942. $refundLogList = explode ( "<br/>", $value ['refundLog'] );
  5943. $html .= '<tr>
  5944. <td>' . $value ['refundCompany'] . '</td>
  5945. <td>' . $value ['refundNumber'] . '</td>
  5946. <td><b class="colRed">¥' . $value ['refundPrice'] . '</b></td>
  5947. <td>' . $refundLogList [0] . $refundLogList [2] . '</td>
  5948. <td>' . $value ['refundRemarks'] . '</td>
  5949. </tr>
  5950. ';
  5951. }
  5952. }
  5953. $html .= '</tbody></table></div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  5954. }
  5955. echo json_encode ( array (
  5956. 'status' => 1,
  5957. 'html' => $html
  5958. ) );
  5959. die ();
  5960. } elseif ($type == 'IRTC') {
  5961. Doo::loadModel ( 'invoice' );
  5962. $invoice = new invoice ();
  5963. Doo::loadModel ( 'invoiceOperationLog' );
  5964. $invoiceOperationLog = new invoiceOperationLog ();
  5965. Doo::loadModel ( 'invoiceReceivables' );
  5966. $invoiceReceivables = new invoiceReceivables ();
  5967. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5968. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5969. if (empty ( $detail ))
  5970. $html = '';
  5971. else {
  5972. $receivablesPriceedHtml = '';
  5973. $receivablesPrice = $detail ['invoicePrice'];
  5974. if (! empty ( $detail ['irid'] )) {
  5975. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $detail ['irid'] );
  5976. if (empty ( $irList ))
  5977. $irList [0] ['sumPrice'] = 0;
  5978. $balance = $detail ['invoicePrice'] - $irList [0] ['sumPrice'];
  5979. $receivablesPriceedHtml = '<table class="table table-bordered table-condensed"><tbody><tr>
  5980. <th class="taC">已入账金额</th><td><b class="colGreen" style="font-size:18px">¥' . $irList [0] ['sumPrice'] . '</b></td>
  5981. <th class="taC">剩余入账金额</th><td><b class="colRed" style="font-size:18px">¥' . $balance . '</b></td>
  5982. </tr></tbody></table>';
  5983. $receivablesPrice = $balance;
  5984. }
  5985. if ($loss)
  5986. $detail ['invoicePrice'] = - $detail ['invoicePrice'];
  5987. $html = $receivablesPriceedHtml . '
  5988. <table class="table table-bordered table-condensed"><tbody>
  5989. <tr>
  5990. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5991. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5992. </tr>
  5993. <tr>
  5994. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5995. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5996. </tr>
  5997. <tr>
  5998. <th class="taC" width="150">发票备注</th><td colspan="3">' . $detail ['remark'] . '</td>
  5999. </tr>
  6000. <tr>
  6001. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  6002. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  6003. </tr>
  6004. <tr>
  6005. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  6006. </tr></tbody></table>';
  6007. if ($detail ['invoiceType'] == 0) {
  6008. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6009. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  6010. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  6011. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  6012. </tr>';
  6013. $receivablesMessage = $detail ['invoiceTitle'];
  6014. } else {
  6015. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6016. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  6017. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  6018. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  6019. ';
  6020. $receivablesMessage = $detail ['invoiceCompany'];
  6021. }
  6022. $html .= '<tr>
  6023. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  6024. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  6025. </tr>
  6026. <tr>
  6027. <th class="taC">开户银行</th><td>' . $detail ['bankAccount'] . '</td>
  6028. <th class="taC">银行账号</th><td>' . $detail ['bank'] . '</td>
  6029. </tr></tbody></table>';
  6030. if ($detail ['doPost'] == 1)
  6031. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  6032. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  6033. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  6034. </tr><tr>
  6035. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  6036. </tr><tr>
  6037. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  6038. </tr></tbody></table>';
  6039. if (! empty ( $invoiceOperationLogList )) {
  6040. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  6041. foreach ( $invoiceOperationLogList as $key => $value ) {
  6042. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  6043. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  6044. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  6045. if ($value ['status'] == 2) {
  6046. $html .= '<span class="colGreen">同意</span>';
  6047. } elseif ($value ['status'] == 3) {
  6048. $html .= '<span class="colOrange">退回</span>';
  6049. } elseif ($value ['status'] == 5) {
  6050. $html .= '<span class="colGreen">打印</span>';
  6051. }
  6052. $html .= $value ['operation'] . '</p></blockquote>';
  6053. }
  6054. }
  6055. $html .= '</td></tr></tbody></table>';
  6056. }
  6057. }
  6058. echo json_encode ( array (
  6059. 'status' => 1,
  6060. 'html' => $html,
  6061. 'receivablesPrice' => $receivablesPrice,
  6062. 'receivablesMessage' => $receivablesMessage,
  6063. 'receivablesDate' => date ( "Y-m-d" ),
  6064. 'iidKey' => $serial
  6065. ) );
  6066. die ();
  6067. }
  6068. }
  6069. function ajaxGetInvoiceReceivablesByStaff() {
  6070. $postData = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : "";
  6071. if (empty ( $postData )) {
  6072. echo json_encode ( array (
  6073. 'status' => 2,
  6074. 'msg' => 'illegal request'
  6075. ) );
  6076. die ();
  6077. }
  6078. Doo::loadModel ( 'invoiceReceivables' );
  6079. $invoiceReceivables = new invoiceReceivables ();
  6080. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $postData );
  6081. if (empty ( $detail )) {
  6082. echo json_encode ( array (
  6083. 'status' => 2,
  6084. 'msg' => 'illegal request'
  6085. ) );
  6086. die ();
  6087. }
  6088. Doo::loadModel ( 'L_category' );
  6089. $lCategory = new L_category ();
  6090. Doo::loadModel ( 'staff' );
  6091. $staff = new staff ();
  6092. $staffList = $staff->getStaffByCid ( $detail ['cid'] );
  6093. $category = $lCategory->getCategory ();
  6094. $categoryHtml = '<option post-data="PUBLIC" value="PUBLIC" >公共待认领款项</option>';
  6095. $staffHtml = '<option value="PUBLIC">办事处待认领款项</option>';
  6096. foreach ( $category as $key => $value ) {
  6097. $categoryHtml .= '<option post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  6098. if ($value ['cid'] == $detail ['cid'])
  6099. $categoryHtml .= '<option selected post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  6100. }
  6101. foreach ( $staffList as $key => $value ) {
  6102. $staffHtml .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  6103. if ($value ['sid'] == $detail ['sid'])
  6104. $staffHtml .= '<option selected value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  6105. }
  6106. $rbankHtml = '<option value="广发银行珠海分行柠溪支行">广发银行珠海分行柠溪支行</option>';
  6107. echo json_encode ( array (
  6108. 'status' => 1,
  6109. 'categoryHtml' => $categoryHtml,
  6110. 'staffHtml' => $staffHtml,
  6111. 'rbankHtml' => $rbankHtml,
  6112. 'detail' => $detail
  6113. ) );
  6114. }
  6115. function ajaxGetInvoiceReceivablesByIrid() {
  6116. $irid = $this->get_args ( 'irid' ) ? $this->get_args ( 'irid' ) : "";
  6117. if (empty ( $irid )) {
  6118. echo json_encode ( array (
  6119. 'status' => 2,
  6120. 'msg' => 'illegal request'
  6121. ) );
  6122. die ();
  6123. }
  6124. Doo::loadModel ( 'invoiceReceivables' );
  6125. $invoiceReceivables = new invoiceReceivables ();
  6126. Doo::loadModel ( 'invoice' );
  6127. $invoice = new invoice ();
  6128. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid ); // 入账完成 待定 and postStatus=1
  6129. $flag = true;
  6130. $invoiceDetail = $invoice->getInvoiceByTitle ( $detail ['recepitTitleMark'], 'EXACTLY', " and status=2 and printStatus=1 and untreadStatus=0 ", $flag ); //
  6131. $bakDetail = array ();
  6132. if ($flag === false) {
  6133. array_push ( $bakDetail, $invoiceDetail );
  6134. $invoiceDetail = $bakDetail;
  6135. }
  6136. $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>
  6137. <tr>
  6138. <td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  6139. <td>' . $detail ['receivablesMessage'] . '</td>
  6140. <td>' . $detail ['receivablesBank'] . '<br>' . $detail ['receivablesDate'] . '</td>
  6141. <td>' . $detail ['title'] . '-' . $detail ['username'] . '<br>' . $detail ['confirmTime'] . '</td>
  6142. <td>' . $detail ['recepitTitleMark'] . '</td>
  6143. </tr></tbody></table>';
  6144. $isInvoice = false;
  6145. $invoiceHtml = '';
  6146. if (empty ( $invoiceDetail )) {
  6147. $isInvoice = true;
  6148. } else {
  6149. $invoiceHtml = '<table class="table table-bordered table-condensed">
  6150. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody>';
  6151. foreach ( $invoiceDetail as $key => $value ) {
  6152. $invoiceHtml .= '<tr>';
  6153. if (! empty ( $value ['invoiceType'] )) {
  6154. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  6155. } else {
  6156. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  6157. }
  6158. if (! empty ( $value ['invoiceType'] )) {
  6159. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  6160. } else {
  6161. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  6162. }
  6163. $invoiceHtml .= '
  6164. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  6165. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  6166. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir" data-ikey="' . $value ['iidKey'] . '" href="javascript:void(0)">入账</a></td>
  6167. </tr>
  6168. ';
  6169. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  6170. if (empty ( $irList ))
  6171. $irList [0] ['sumPrice'] = 0;
  6172. $balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  6173. $priceString = '';
  6174. if ($balance < $detail ['receivablesPrice']) {
  6175. $priceString = '收款金额超过开票金额,';
  6176. }
  6177. if ($balance > $detail ['receivablesPrice']) {
  6178. $priceString = '收款金额低于开票金额,';
  6179. }
  6180. }
  6181. $invoiceHtml .= '
  6182. <script>
  6183. $(\'a[bind-receivables^="ir"]\').click(function() {
  6184. var data = $(this).attr("data-ikey");
  6185. $("input[name=\'invoiceKey\']").val(data);
  6186. var invoiceKey=data;
  6187. if(invoiceKey==""){
  6188. alert("入账错误,请重新刷新页面");
  6189. return false;
  6190. }
  6191. if(window.confirm("' . $priceString . '确定入账吗?")){
  6192. $("#IBR").submit();
  6193. }else{
  6194. return false;
  6195. }
  6196. });
  6197. </script>
  6198. ';
  6199. $invoiceHtml .= '</tbody></table>';
  6200. }
  6201. echo json_encode ( array (
  6202. 'status' => 1,
  6203. 'irkey' => $detail ['iridEn'],
  6204. 'receivablesHtml' => $receivablesHtml,
  6205. 'isInvoice' => $isInvoice,
  6206. 'invoiceHtml' => $invoiceHtml
  6207. ) );
  6208. }
  6209. function ajaxGetInvoiceReceivablesByTitle() {
  6210. $title = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  6211. if (empty ( $title )) {
  6212. echo json_encode ( array (
  6213. 'status' => 2,
  6214. 'msg' => 'illegal request'
  6215. ) );
  6216. die ();
  6217. }
  6218. Doo::loadModel ( 'invoice' );
  6219. $invoice = new invoice ();
  6220. $invoiceDetail = $invoice->getInvoiceByTitle ( $title, 'FUZZY', " and status=2 and printStatus=1 and untreadStatus=0 and irid='' ", true );
  6221. $invoiceHtml = '';
  6222. if (! empty ( $invoiceDetail )) {
  6223. $invoiceHtml = '<table class="table table-bordered table-condensed">
  6224. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody><tr>';
  6225. foreach ( $invoiceDetail as $key => $value ) {
  6226. if (! empty ( $value ['invoiceType'] )) {
  6227. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  6228. } else {
  6229. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  6230. }
  6231. if (! empty ( $value ['invoiceType'] )) {
  6232. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  6233. } else {
  6234. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  6235. }
  6236. $invoiceHtml .= '
  6237. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  6238. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  6239. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir' . $value ['iidKeyXD'] . '" data-ikey="' . $value ['iidKey'] . '" href="#">入账</a></td>
  6240. </tr>
  6241. ';
  6242. }
  6243. $invoiceHtml .= '</tbody></table>
  6244. <script>
  6245. $(\'a[bind-receivables^="ir"]\').click(function() {
  6246. var data = $(this).attr("data-ikey");
  6247. $("input[name=\'invoiceKey\']").val(data);
  6248. var invoiceKey=$("input[name=\'invoiceKey\']").val();
  6249. if(invoiceKey==""){
  6250. alert("入账错误,请重新刷新页面");
  6251. return false;
  6252. }
  6253. if(window.confirm("确定入账吗?")){
  6254. $("#IBR").submit();
  6255. }else{
  6256. return false;
  6257. }
  6258. });
  6259. </script>
  6260. ';
  6261. }
  6262. echo json_encode ( array (
  6263. 'status' => 1,
  6264. 'invoiceHtml' => $invoiceHtml
  6265. ) );
  6266. }
  6267. function ajaxInvoicePushNotice() {
  6268. Doo::loadModel ( 'invoice' );
  6269. $invoice = new invoice ();
  6270. $approval = $invoice->getOne ( array (
  6271. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  6272. 'desc' => 'iid',
  6273. 'asArray' => true
  6274. ) );
  6275. $isNotice = false;
  6276. if (! empty ( $approval ))
  6277. $isNotice = true;
  6278. $response = array (
  6279. 'error' => 0,
  6280. 'isNotice' => $isNotice
  6281. );
  6282. echo json_encode ( $response );
  6283. exit ();
  6284. }
  6285. public function ajaxCheckInvoiceNoUniqueness() {
  6286. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  6287. Doo::loadModel ( 'invoice' );
  6288. $invoice = new invoice ();
  6289. if (! empty ( $invoiceNo )) {
  6290. Doo::loadModel ( 'invoicePaper' );
  6291. $invoicePaper = new invoicePaper ();
  6292. Doo::loadClass ( 'XDeode' );
  6293. $XDeode = new XDeode ( 5 );
  6294. $ipid = $XDeode->decode ( $invoiceNo );
  6295. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  6296. $info = $invoice->getOne ( array (
  6297. 'where' => "invoiceNo = '" . $paperDetail ['invoiceNo'] . "'",
  6298. 'asArray' => TRUE
  6299. ) );
  6300. if (! empty ( $info )) {
  6301. echo json_encode ( array (
  6302. 'error' => '发票号已存在'
  6303. ) );
  6304. die ();
  6305. } else
  6306. echo json_encode ( array (
  6307. 'ok' => '可以使用!'
  6308. ) );
  6309. die ();
  6310. }
  6311. }
  6312. function ajaxCheckInvoicePrice() {
  6313. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) && is_numeric ( $this->get_args ( 'receivablesPrice' ) ) ? $this->get_args ( 'receivablesPrice' ) : "";
  6314. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  6315. Doo::loadModel ( 'invoice' );
  6316. $invoice = new invoice ();
  6317. Doo::loadModel ( 'invoiceReceivables' );
  6318. $invoiceReceivables = new invoiceReceivables ();
  6319. Doo::loadClass ( 'XDeode' );
  6320. $XDeode = new XDeode ( 5 );
  6321. if (! empty ( $receivablesPrice ) && ! empty ( $iidKey )) {
  6322. $iidKey = $XDeode->decode ( $iidKey );
  6323. $info = $invoice->getInvoiceByIid ( $iidKey );
  6324. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $info ['irid'] );
  6325. if (empty ( $irList ))
  6326. $irList [0] ['sumPrice'] = 0;
  6327. $balance = $info ['invoicePrice'] - $irList [0] ['sumPrice'];
  6328. if ($balance < $receivablesPrice) {
  6329. echo json_encode ( array (
  6330. 'error' => '收款金额超过开票金额。'
  6331. ) );
  6332. die ();
  6333. }
  6334. if ($balance > $receivablesPrice) {
  6335. echo json_encode ( array (
  6336. 'error' => '收款金额低于开票金额。'
  6337. ) );
  6338. die ();
  6339. }
  6340. }
  6341. }
  6342. function ajaxGetInvoiceByNew() {
  6343. Doo::loadModel ( 'invoice' );
  6344. $invoice = new invoice ();
  6345. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );
  6346. echo json_encode ( array (
  6347. 'status' => 1,
  6348. 'detail' => $detail
  6349. ) );
  6350. }
  6351. /**
  6352. * 旧输入导入
  6353. */
  6354. function importInvoice() {
  6355. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  6356. $data ['emsg'] = "";
  6357. if ($emsg != "")
  6358. $data ['emsg'] = "请填写完整的数据";
  6359. $data ['time'] = time ();
  6360. $this->render ( "/admin/invoiceImport", $data );
  6361. }
  6362. function uploadInvoice() {
  6363. // move_uploaded_file($_FILES['Filedata']['tmp_name'], "/upload/".$_FILES['Filedata']['name']);
  6364. if (isset ( $_FILES ['Filedata'] ['name'] )) {
  6365. $file = $_FILES ['Filedata'] ['tmp_name'];
  6366. $error = false;
  6367. if (! is_uploaded_file ( $file )) {
  6368. $error = '400 Bad Request';
  6369. }
  6370. if ($error) {
  6371. header ( 'HTTP/1.0 ' . $error );
  6372. die ( 'Error ' . $error );
  6373. } else {
  6374. include (DOO::conf ()->SITE_PATH . 'protected/plugin/io.han.php');
  6375. $this->IoHandler = new IoHandler ();
  6376. $pics = explode ( '.', $_FILES ['Filedata'] ['name'] );
  6377. // $filedir=$_POST['time'];
  6378. // 调用定义物理路径
  6379. $t = DOO::conf ()->SITE_PATH . "upload/invoice/";
  6380. $this->IoHandler->MakeDir ( $t );
  6381. $filename = $this->_GetFileEXT ( $_FILES ['Filedata'] ['name'] );
  6382. if ($filename != 'xlsx')
  6383. return "";
  6384. // $upload_dir = $t."/".time().rand(10,100).".".$filename;
  6385. $upload_file = iconv ( "UTF-8", "GB2312", $_FILES ["Filedata"] ["name"] );
  6386. $upload_dir = $t . "/" . $upload_file;
  6387. $k = move_uploaded_file ( $file, $upload_dir );
  6388. if ($k) {
  6389. $m = round ( $_FILES ['Filedata'] ['size'] / 1024 / 1024, 2 );
  6390. echo $pics [0] . "." . $filename . "#" . $m . "#" . $_FILES ['Filedata'] ['size'];
  6391. }
  6392. }
  6393. }
  6394. }
  6395. function importInvoiceDo() {
  6396. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  6397. if ($path != "") {
  6398. Doo::loadModel ( 'invoice' );
  6399. Doo::loadModel ( 'staff' );
  6400. $staff = new staff ();
  6401. Doo::loadModel ( 'invoiceStatistics' );
  6402. Doo::loadModel ( 'invoiceOperationLog' );
  6403. echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  6404. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . $path );
  6405. // print_r ( $exlArray );
  6406. // die ();
  6407. // echo json_encode($exlArray);die;
  6408. foreach ( $exlArray as $key => $value ) {
  6409. // 开票
  6410. $invoice = new invoice ();
  6411. $invoice->invoiceNo = $value ['invoiceNo'];
  6412. $invoice->invoiceType = 0;
  6413. if ($value ['invoiceType'] == '专')
  6414. $invoice->invoiceType = 1;
  6415. $invoice->invoicePrice = $value ['invoicePrice'];
  6416. $invoice->invoiceQuantity = 1;
  6417. $invoice->invoiceUnitPrice = $value ['invoicePrice'];
  6418. $invoice->invoiceTitle = $value ['invoiceTitle'];
  6419. if ($value ['invoiceType'] == '专')
  6420. $invoice->invoiceCompany = $value ['invoiceTitle'];
  6421. $invoice->userName = $value ['userName'];
  6422. $sDetail = $staff->getStaffByName ( $value ['userName'] );
  6423. $invoice->sid = $sDetail ['sid'];
  6424. $invoice->cid = $sDetail ['cid'];
  6425. $invoice->categoryName = $sDetail ['category'];
  6426. $invoice->invoiceElement = $value ['invoiceElement'];
  6427. $invoice->remark = $value ['remark'];
  6428. $invoice->date = $value ['date'];
  6429. $invoice->printTime = $value ['date'];
  6430. $invoice->ipSource = 1;
  6431. $invoice->printStatus = 1;
  6432. $invoice->status = 2;
  6433. $invoice->postStatus = 1;
  6434. $invoice->untreadStatus = 0;
  6435. $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  6436. $iid = $invoice->insert ();
  6437. // 汇总
  6438. $invoiceStatistics = new invoiceStatistics ();
  6439. //
  6440. $item = array (
  6441. 'date' => $value ['date'],
  6442. 'priceClass' => 1,
  6443. 'cid' => $sDetail ['cid'],
  6444. 'staff' => $sDetail ['sid'],
  6445. 'invoicePrice' => $value ['invoicePrice']
  6446. );
  6447. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  6448. $invoiceOperationLog = new invoiceOperationLog ();
  6449. $item = array (
  6450. 'date' => date ( "Y-m-d H:i:s" ),
  6451. 'operation' => date ( "Y-m-d" ) . " 导入",
  6452. 'status' => 1,
  6453. 'img' => $sDetail ['avatar'],
  6454. 'username' => $sDetail ['username'],
  6455. 'uid' => $sDetail ['sid'],
  6456. 'category' => $sDetail ['category'],
  6457. 'iid' => $iid
  6458. );
  6459. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  6460. }
  6461. return '/importInvoice?count=' . count ( $exlArray );
  6462. // return "/keyonline";
  6463. }
  6464. echo 'no file';
  6465. }
  6466. function importInvoiceReceivables() {
  6467. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  6468. $data ['emsg'] = "";
  6469. if ($emsg != "")
  6470. $data ['emsg'] = "请填写完整的数据";
  6471. $data ['time'] = time ();
  6472. $this->render ( "/admin/invoiceReceivablesImport", $data );
  6473. }
  6474. // 导入入账数据
  6475. function importInvoiceReceivablesDo() {
  6476. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  6477. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  6478. if ($path != "") {
  6479. Doo::loadModel ( 'invoiceReceivables' );
  6480. Doo::loadModel ( 'invoice' );
  6481. Doo::loadModel ( 'staff' );
  6482. $staff = new staff ();
  6483. Doo::loadModel ( 'invoiceStatistics' );
  6484. // echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  6485. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path ), 'invoiceReceivables' );
  6486. // print_r ( $exlArray );
  6487. // die ();
  6488. // echo json_encode($exlArray);die;
  6489. foreach ( $exlArray as $key => $value ) {
  6490. // 收款
  6491. $invoiceReceivables = new invoiceReceivables ();
  6492. $invoice = new invoice ();
  6493. $invoiceReceivables->bindStatus = 1;
  6494. $invoiceReceivables->receivablesPrice = $value ['receivablesPrice'];
  6495. $invoiceReceivables->receivablesMessage = $value ['receivablesMessage'];
  6496. $invoiceReceivables->receivablesBank = $value ['receivablesBank'];
  6497. $invoiceReceivables->receivablesDate = $value ['receivablesDate'];
  6498. $sDetail = $staff->getStaffByName ( $value ['receivablesStaff'] );
  6499. $invoiceReceivables->receivablesCategory = $sDetail ['cid'] . ':' . $sDetail ['category'];
  6500. $invoiceReceivables->receivablesStaff = $sDetail ['sid'] . '-' . $sDetail ['username'];
  6501. $invoiceReceivables->receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  6502. $invoiceReceivables->sourcePrice = $value ['sourcePrice'];
  6503. $iDetail = $invoice->getInvoiceByInvoiceNo ( $value ['invoiceNo'] );
  6504. $invoiceReceivables->iid = $iDetail ['iid'];
  6505. $irid = $invoiceReceivables->insert ();
  6506. // 发票绑定收款
  6507. $detail = $iDetail;
  6508. $iridString = "";
  6509. if (empty ( $detail ['irid'] ))
  6510. $iridString = $irid;
  6511. else
  6512. $iridString = $detail ['irid'] . ',' . $irid;
  6513. $item = array (
  6514. 'irid' => $iridString,
  6515. 'iid' => $detail ['iid']
  6516. );
  6517. $invoice->setInvoiceByCondition ( $item );
  6518. // 汇总
  6519. $invoiceStatistics = new invoiceStatistics ();
  6520. // 扣除入账统计金额
  6521. $item = array (
  6522. 'date' => $value ['receivablesDate'],
  6523. 'priceClass' => 3,
  6524. 'cid' => $sDetail ['cid'],
  6525. 'staff' => $sDetail ['sid'],
  6526. // 'irid' => $irid,
  6527. 'accountPrice' => $value ['receivablesPrice']
  6528. );
  6529. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  6530. }
  6531. return '/importInvoiceReceivables?count=' . count ( $exlArray );
  6532. echo 'data count ' . count ( $exlArray );
  6533. die ();
  6534. // return "/keyonline";
  6535. }
  6536. echo 'no file';
  6537. }
  6538. function formatExcelToArrayTrain($file_url = "") {
  6539. if (! file_exists ( $file_url )) {
  6540. return array ();
  6541. }
  6542. // Doo::loadClass ( 'PHPExcel' );
  6543. Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  6544. $PHPExcel = new PHPExcel ();
  6545. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  6546. if (! $PHPReader->canRead ( $file_url )) {
  6547. $PHPReader = new PHPExcel_Reader_Excel5 ();
  6548. if (! $PHPReader->canRead ( $file_url )) {
  6549. echo 'no Excel';
  6550. return;
  6551. }
  6552. }
  6553. $PHPExcel = $PHPReader->load ( $file_url );
  6554. /* * 读取excel文件中的第一个工作表 */
  6555. $currentSheet = $PHPExcel->getSheet ( 0 );
  6556. /* * 取得最大的列号 */
  6557. $allColumn = $currentSheet->getHighestColumn ();
  6558. /* * 取得一共有多少行 */
  6559. $allRow = $currentSheet->getHighestRow ();
  6560. $excel_array = array ();
  6561. // die($file_url);
  6562. $conk = 2;
  6563. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  6564. $excel_column = array ();
  6565. // 后期改进
  6566. if ($allColumn == 'AM')
  6567. $allColumn = 'Z';
  6568. /* * 从第A列开始输出 */
  6569. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  6570. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  6571. if ($val instanceof PHPExcel_RichText)
  6572. $val = $val->__toString ();
  6573. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  6574. // $val = "'" . addslashes ( $val ) . "'";
  6575. if ($currentColumn == 'A') {
  6576. $excel_column ['invoiceTitle'] = $val;
  6577. } elseif ($currentColumn == 'B')
  6578. $excel_column ['invoiceType'] = $val;
  6579. elseif ($currentColumn == 'C') {
  6580. $excel_column ['TIN'] = $val;
  6581. } elseif ($currentColumn == 'D') {
  6582. $excel_column ['address'] = $val;
  6583. } elseif ($currentColumn == 'E') {
  6584. $excel_column ['phone'] = $val;
  6585. } elseif ($currentColumn == 'F') {
  6586. $excel_column ['bank'] = $val;
  6587. } elseif ($currentColumn == 'G') {
  6588. $excel_column ['bankAccount'] = $val;
  6589. } elseif ($currentColumn == 'H') {
  6590. $excel_column ['invoiceElement'] = $val;
  6591. } elseif ($currentColumn == 'I') {
  6592. $excel_column ['invoiceQuantity'] = $val;
  6593. } elseif ($currentColumn == 'J') {
  6594. $excel_column ['invoiceUnitPrice'] = $val;
  6595. } elseif ($currentColumn == 'K') {
  6596. $excel_column ['remark'] = $val;
  6597. } elseif ($currentColumn == 'L') {
  6598. $excel_column ['recipientsAddress'] = $val;
  6599. } elseif ($currentColumn == 'M') {
  6600. $excel_column ['recipients'] = $val;
  6601. } elseif ($currentColumn == 'N') {
  6602. $excel_column ['recipientsPhone'] = $val;
  6603. }
  6604. }
  6605. if (! empty ( $excel_column ['invoiceTitle'] ) && ! empty ( $excel_column ['invoiceQuantity'] ) && ! empty ( $excel_column ['invoiceUnitPrice'] ))
  6606. array_push ( $excel_array, $excel_column );
  6607. }
  6608. return $excel_array;
  6609. }
  6610. /**
  6611. * 格式化excel文件为数组
  6612. * @param unknown_type $file_url
  6613. * @param unknown_type $mcid
  6614. */
  6615. function _format_excel_to_array($file_url = "", $sType = "") {
  6616. if (! file_exists ( $file_url )) {
  6617. return array ();
  6618. }
  6619. Doo::loadClass ( 'PHPExcel' );
  6620. // Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  6621. $PHPExcel = new PHPExcel ();
  6622. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  6623. if (! $PHPReader->canRead ( $file_url )) {
  6624. $PHPReader = new PHPExcel_Reader_Excel5 ();
  6625. if (! $PHPReader->canRead ( $file_url )) {
  6626. echo 'no Excel';
  6627. return;
  6628. }
  6629. }
  6630. $PHPExcel = $PHPReader->load ( $file_url );
  6631. /* * 读取excel文件中的第一个工作表 */
  6632. $currentSheet = $PHPExcel->getSheet ( 0 );
  6633. /* * 取得最大的列号 */
  6634. $allColumn = $currentSheet->getHighestColumn ();
  6635. /* * 取得一共有多少行 */
  6636. $allRow = $currentSheet->getHighestRow ();
  6637. $excel_array = array ();
  6638. // die($file_url);
  6639. $conk = 2;
  6640. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  6641. $excel_column = array ();
  6642. // 后期改进
  6643. if ($allColumn == 'AM')
  6644. $allColumn = 'Z';
  6645. /* * 从第A列开始输出 */
  6646. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  6647. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  6648. if ($val instanceof PHPExcel_RichText)
  6649. $val = $val->__toString ();
  6650. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  6651. // $val = "'" . addslashes ( $val ) . "'";
  6652. if ($sType == 'invoiceReceivables') {
  6653. if ($currentColumn == 'A')
  6654. $excel_column ['invoiceNo'] = $val;
  6655. elseif ($currentColumn == 'B')
  6656. $excel_column ['receivablesPrice'] = $val;
  6657. elseif ($currentColumn == 'C') {
  6658. $excel_column ['receivablesMessage'] = $val;
  6659. } elseif ($currentColumn == 'D') {
  6660. $excel_column ['receivablesBank'] = $val;
  6661. } elseif ($currentColumn == 'E') {
  6662. $excel_column ['receivablesDate'] = $this->excelTime ( $val );
  6663. } elseif ($currentColumn == 'F') {
  6664. $excel_column ['receivablesStaff'] = $val;
  6665. } elseif ($currentColumn == 'G') {
  6666. $excel_column ['sourcePrice'] = $val;
  6667. }
  6668. } elseif ($sType == "invoiceTrain") {
  6669. if ($currentColumn == 'A') {
  6670. $excel_column ['invoiceTitle'] = $val;
  6671. } elseif ($currentColumn == 'B')
  6672. $excel_column ['invoiceType'] = $val;
  6673. elseif ($currentColumn == 'C') {
  6674. $excel_column ['TIN'] = $val;
  6675. } elseif ($currentColumn == 'D') {
  6676. $excel_column ['address'] = $val;
  6677. } elseif ($currentColumn == 'E') {
  6678. $excel_column ['phone'] = $val;
  6679. } elseif ($currentColumn == 'F') {
  6680. $excel_column ['bank'] = $val;
  6681. } elseif ($currentColumn == 'G') {
  6682. $excel_column ['bankAccount'] = $val;
  6683. } elseif ($currentColumn == 'H') {
  6684. $excel_column ['invoiceElement'] = $val;
  6685. } elseif ($currentColumn == 'I') {
  6686. $excel_column ['invoiceQuantity'] = $val;
  6687. } elseif ($currentColumn == 'J') {
  6688. $excel_column ['invoiceUnitPrice'] = $val;
  6689. } elseif ($currentColumn == 'K') {
  6690. $excel_column ['remark'] = $val;
  6691. } elseif ($currentColumn == 'L') {
  6692. $excel_column ['recipientsAddress'] = $val;
  6693. } elseif ($currentColumn == 'M') {
  6694. $excel_column ['recipients'] = $val;
  6695. } elseif ($currentColumn == 'N') {
  6696. $excel_column ['recipientsPhone'] = $val;
  6697. }
  6698. } else {
  6699. if ($currentColumn == 'A')
  6700. $excel_column ['invoiceNo'] = $val;
  6701. elseif ($currentColumn == 'B')
  6702. $excel_column ['invoiceType'] = $val;
  6703. elseif ($currentColumn == 'C') {
  6704. $excel_column ['invoicePrice'] = $val;
  6705. } elseif ($currentColumn == 'D') {
  6706. $excel_column ['invoiceTitle'] = $val;
  6707. } elseif ($currentColumn == 'E') {
  6708. $excel_column ['userName'] = $val;
  6709. } elseif ($currentColumn == 'F') {
  6710. $excel_column ['categoryName'] = $val;
  6711. } elseif ($currentColumn == 'G') {
  6712. $excel_column ['invoiceElement'] = $val;
  6713. } elseif ($currentColumn == 'H') {
  6714. $excel_column ['remark'] = $val;
  6715. } elseif ($currentColumn == 'I') {
  6716. $excel_column ['date'] = $this->excelTime ( $val );
  6717. }
  6718. }
  6719. }
  6720. array_push ( $excel_array, $excel_column );
  6721. }
  6722. return $excel_array;
  6723. }
  6724. function excelTime($date, $time = false) {
  6725. if (function_exists ( 'GregorianToJD' )) {
  6726. if (is_numeric ( $date )) {
  6727. $jd = GregorianToJD ( 1, 1, 1970 );
  6728. $gregorian = JDToGregorian ( $jd + intval ( $date ) - 25569 );
  6729. $date = explode ( '/', $gregorian );
  6730. $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" : '');
  6731. return $date_str;
  6732. }
  6733. } else {
  6734. $date = $date > 25568 ? $date + 1 : 25569;
  6735. /* There was a bug if Converting date before 1-1-1970 (tstamp 0) */
  6736. $ofs = (70 * 365 + 17 + 2) * 86400;
  6737. $date = date ( "Y-m-d", ($date * 86400) - $ofs ) . ($time ? " 00:00:00" : '');
  6738. }
  6739. return $date;
  6740. }
  6741. /**
  6742. * 旧输入导入
  6743. */
  6744. function _GetFileEXT($filename) {
  6745. $pics = explode ( '.', $filename );
  6746. $num = count ( $pics );
  6747. return $pics [$num - 1];
  6748. }
  6749. function showCache($path = "", $sid = 0) {
  6750. // if (file_exists ( $path )) {
  6751. // $htm = file_get_contents ( $path );
  6752. // } else {
  6753. Doo::loadModel ( 'invoiceStatistics' );
  6754. $invoiceStatistics = new invoiceStatistics ();
  6755. $isBriefly = $invoiceStatistics->getBrieflyStatistics ( $sid );
  6756. $htm = '<tr><th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计开票</th>
  6757. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['invoicePrice'] . '</td>
  6758. <th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计入账</th>
  6759. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['accountPrice'] . '</td></tr>';
  6760. /*
  6761. * '<tr><th class="taC">今年累计开票</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['invoicePrice'] . '</td> <th class="taC">今年累计入账</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['accountPrice'] . '</td></tr>';
  6762. */
  6763. file_put_contents ( $path, $htm );
  6764. // }
  6765. return $htm;
  6766. }
  6767. /**
  6768. * 生成token
  6769. * @return string
  6770. */
  6771. function set_token()
  6772. {
  6773. $str = md5(uniqid(md5(microtime(true)),true)); //生成一个不会重复的字符串
  6774. $str = sha1($str); //加密
  6775. return $str;
  6776. }
  6777. /**
  6778. * 获取get或者POST值
  6779. *
  6780. * @param string $name 属性名称
  6781. * @return fixed 值
  6782. */
  6783. function get_args($name) {
  6784. if (isset ( $_GET [$name] )) {
  6785. if (is_array ( $_GET [$name] ))
  6786. return $_GET [$name];
  6787. else
  6788. return addslashes ( $_GET [$name] );
  6789. } elseif (isset ( $_POST [$name] )) {
  6790. if (is_array ( $_POST [$name] ))
  6791. return $_POST [$name];
  6792. else
  6793. return addslashes ( $_POST [$name] );
  6794. } else
  6795. return false;
  6796. }
  6797. function SafeFilter(&$arr) {
  6798. $ra = Array (
  6799. '/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/',
  6800. '/script/',
  6801. '/javascript/',
  6802. '/vbscript/',
  6803. '/expression/',
  6804. '/applet/',
  6805. '/meta/',
  6806. '/xml/',
  6807. '/blink/',
  6808. '/link/',
  6809. '/style/',
  6810. '/embed/',
  6811. '/object/',
  6812. '/frame/',
  6813. '/layer/',
  6814. '/title/',
  6815. '/bgsound/',
  6816. '/base/',
  6817. '/onload/',
  6818. '/onunload/',
  6819. '/onchange/',
  6820. '/onsubmit/',
  6821. '/onreset/',
  6822. '/onselect/',
  6823. '/onblur/',
  6824. '/onfocus/',
  6825. '/onabort/',
  6826. '/onkeydown/',
  6827. '/onkeypress/',
  6828. '/onkeyup/',
  6829. '/onclick/',
  6830. '/ondblclick/',
  6831. '/onmousedown/',
  6832. '/onmousemove/',
  6833. '/onmouseout/',
  6834. '/onmouseover/',
  6835. '/onmouseup/',
  6836. '/onunload/'
  6837. );
  6838. if (is_array ( $arr )) {
  6839. foreach ( $arr as $key => $value ) {
  6840. if (! is_array ( $value )) {
  6841. if (! get_magic_quotes_gpc ()) // 不对magic_quotes_gpc转义过的字符使用addslashes(),避免双重转义。
  6842. {
  6843. $value = addslashes ( $value ); // 给单引号(')、双引号(")、反斜线(\)与 NUL(NULL 字符)加上反斜线转义
  6844. }
  6845. $value = preg_replace ( $ra, '', $value ); // 删除非打印字符,粗暴式过滤xss可疑字符串
  6846. $arr [$key] = htmlentities ( strip_tags ( $value ) ); // 去除 HTML 和 PHP 标记并转换为 HTML 实体
  6847. } else {
  6848. SafeFilter ( $arr [$key] );
  6849. }
  6850. }
  6851. }
  6852. }
  6853. /**
  6854. * Escape String
  6855. *
  6856. * @access public
  6857. * @param string
  6858. * @param bool whether or not the string will be used in a LIKE condition
  6859. * @return string
  6860. */
  6861. function escape_str($str, $like = FALSE) {
  6862. if (is_array ( $str )) {
  6863. foreach ( $str as $key => $val ) {
  6864. $str [$key] = $this->escape_str ( $val, $like );
  6865. }
  6866. return $str;
  6867. }
  6868. var_dump ( Doo::db ()->getDbObject () );
  6869. die ();
  6870. if (function_exists ( 'mysql_real_escape_string' ) and is_resource ( Doo::db ()->getDbObject () )) { // Doo::db ()->getDbObject()
  6871. $str = mysql_real_escape_string ( $str, Doo::db ()->getDbObject () );
  6872. } elseif (function_exists ( 'mysql_escape_string' )) {
  6873. $str = mysql_escape_string ( $str );
  6874. } else {
  6875. $str = addslashes ( $str );
  6876. }
  6877. // escape LIKE condition wildcards
  6878. if ($like === TRUE) {
  6879. $str = str_replace ( array (
  6880. '%',
  6881. '_'
  6882. ), array (
  6883. '\\%',
  6884. '\\_'
  6885. ), $str );
  6886. }
  6887. return $str;
  6888. }
  6889. /**
  6890. * 获得分页数据
  6891. * @param unknown_type $table
  6892. * @param unknown_type $condition
  6893. * @param unknown_type $on_page
  6894. * @param unknown_type $page_size
  6895. */
  6896. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  6897. $page_c = "";
  6898. $page ['previous'] = $this->get_previous ( $on_page );
  6899. $page ['on_page'] = $on_page;
  6900. $total_count = $this->get_table_count ( $table, $condition );
  6901. $total = intval ( $total_count / $page_size );
  6902. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  6903. $page ['total_data'] = $total_count;
  6904. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  6905. $i = 1;
  6906. $page_max = 1;
  6907. $page_width = 3;
  6908. if ($on_page >= $page_width) {
  6909. $page_max = intval ( $on_page / $page_width ) + 1;
  6910. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  6911. }
  6912. for(; $i <= $page ['total_page']; $i ++) {
  6913. if ($i == $on_page)
  6914. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  6915. else
  6916. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  6917. if ($i == ($page_width * $page_max))
  6918. break;
  6919. }
  6920. $page ['page'] = $page_c;
  6921. $page ['lower'] = (-- $on_page) * $page_size;
  6922. return $page;
  6923. }
  6924. /**
  6925. * 获取上一页
  6926. * @param unknown_type $on_page
  6927. */
  6928. function get_previous($on_page = 1) {
  6929. return $on_page != 0 ? $on_page - 1 : $on_page;
  6930. }
  6931. /**
  6932. * 获取总页数
  6933. * @param unknown_type $table
  6934. * @param unknown_type $condition
  6935. */
  6936. public function get_table_count($table = "", $condition = "") {
  6937. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  6938. $sql = "select count(*) as count from " . $table . " where " . $condition;
  6939. // echo $sql;die;
  6940. $query = Doo::db ()->query ( $sql );
  6941. $result = $query->fetch ();
  6942. return $result ['count'];
  6943. }
  6944. /**
  6945. * 获得分页数据
  6946. * @param unknown_type $table
  6947. * @param unknown_type $condition
  6948. * @param unknown_type $on_page
  6949. * @param unknown_type $page_size
  6950. */
  6951. function getPageBySql($sql = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  6952. $page_c = "";
  6953. $page ['previous'] = $this->get_previous ( $on_page );
  6954. $page ['on_page'] = $on_page;
  6955. $total_count = $this->getTableCountBySql ( $sql );
  6956. $total = intval ( $total_count / $page_size );
  6957. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  6958. $page ['total_data'] = $total_count;
  6959. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  6960. $i = 1;
  6961. $page_max = 1;
  6962. $page_width = 3;
  6963. if ($on_page >= $page_width) {
  6964. $page_max = intval ( $on_page / $page_width ) + 1;
  6965. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  6966. }
  6967. for(; $i <= $page ['total_page']; $i ++) {
  6968. if ($i == $on_page)
  6969. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  6970. else
  6971. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  6972. if ($i == ($page_width * $page_max))
  6973. break;
  6974. }
  6975. $page ['page'] = $page_c;
  6976. $page ['lower'] = (-- $on_page) * $page_size;
  6977. return $page;
  6978. }
  6979. /**
  6980. * 获得总页数 sql
  6981. * @param string $type
  6982. * @return boolean[]
  6983. */
  6984. public function getTableCountBySql($sql = "") {
  6985. $query = Doo::db ()->query ( $sql );
  6986. $result = $query->fetchAll ();
  6987. return count ( $result );
  6988. }
  6989. function isInvoiceNew($type = "GLOBAL") {
  6990. Doo::loadModel ( 'invoice' );
  6991. $invoice = new invoice ();
  6992. Doo::loadModel ( 'invoiceReceivables' );
  6993. $invoiceReceivables = new invoiceReceivables ();
  6994. Doo::loadModel ( 'staff' );
  6995. $staff = new staff ();
  6996. $st = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  6997. // 我的发票待处理
  6998. $pendingInvoice = $invoice->getOne ( array ( // or (status=2 and printStatus=1 and untreadStatus=0 ) or (status=2 and printStatus=1 and untreadStatus=2 )
  6999. 'where' => "(status=3 or status=4) and isDelete=0 and sid=" . $st [0] ['sid'],
  7000. 'desc' => 'iid',
  7001. 'asArray' => TRUE
  7002. ) );
  7003. // 我的收款待入账
  7004. /*
  7005. * $myClaim = $invoiceReceivables->getOne ( array ( 'where' => " receivablesStaff like '" . $st [0] ['sid'] . "-%' and receivablesCategory like '" . $st [0] ['cid'] . ":%' and bindStatus=0", 'desc' => 'irid', 'asArray' => TRUE ) );
  7006. */
  7007. // 发票审批
  7008. $approval = $invoice->getOne ( array (
  7009. 'where' => 'status=1 and pendingApprovals=' . $st [0] ['sid'],
  7010. 'desc' => 'iid',
  7011. 'asArray' => true
  7012. ) );
  7013. // 发票邮寄
  7014. $post = $invoice->getOne ( array (
  7015. 'where' => "postStatus=0 and printStatus=1 and isDelete=0 and doPost=1 and status=2",
  7016. 'asArray' => TRUE
  7017. ) );
  7018. // 发票打印
  7019. $print = $invoice->getOne ( array (
  7020. 'where' => "status=2 and printStatus=0 and untreadStatus=0 and moldManage like '%[\"" . $st [0] ['sid'] . "\",%'",
  7021. 'desc' => 'iid',
  7022. 'asArray' => TRUE
  7023. ) );
  7024. // 发票退票 printStatus=1 and
  7025. $untread = $invoice->getOne ( array (
  7026. 'where' => " untreadStatus=1 and status=2 ",
  7027. 'asArray' => TRUE
  7028. ) );
  7029. $new = array (
  7030. 'GLOBAL' => FALSE,
  7031. 'pendingInvoice' => FALSE,
  7032. // 'myClaim' => FALSE,
  7033. 'approval' => FALSE,
  7034. 'post' => FALSE,
  7035. 'print' => FALSE,
  7036. 'untread' => FALSE
  7037. );
  7038. // || ! empty ( $myClaim )
  7039. if (! empty ( $pendingInvoice ) || ! empty ( $approval ) || ! empty ( $post ) || ! empty ( $print ) || ! empty ( $untread ))
  7040. $new ['GLOBAL'] = TRUE;
  7041. if (! empty ( $pendingInvoice ))
  7042. $new ['pendingInvoice'] = TRUE;
  7043. // if (! empty ( $myClaim ))
  7044. // $new ['myClaim'] = TRUE;
  7045. if (! empty ( $approval ))
  7046. $new ['approval'] = TRUE;
  7047. if (! empty ( $post ))
  7048. $new ['post'] = TRUE;
  7049. if (! empty ( $print ))
  7050. $new ['print'] = TRUE;
  7051. if (! empty ( $untread ))
  7052. $new ['untread'] = TRUE;
  7053. return $new;
  7054. }
  7055. function setWXMsg($rid, $typeMsg = '') {
  7056. Doo::loadModel ( 'invoice' );
  7057. $invoice = new invoice ();
  7058. $invoiceDetail = $invoice->getOne ( array (
  7059. 'where' => 'iid=' . $rid,
  7060. 'asArray' => true
  7061. ) );
  7062. if (! empty ( $invoiceDetail )) {
  7063. Doo::loadModel ( 'staff' );
  7064. $staff = new staff ();
  7065. $staffmsg = $staff->getOne ( array (
  7066. 'where' => "sid='" . $invoiceDetail ['sid'] . "'",
  7067. 'asArray' => TRUE
  7068. ) );
  7069. if (! empty ( $staffmsg ['wxid'] )) {
  7070. require_once (SITE_PATH . '/protected/class/client.php');
  7071. $client = new client ( 'http://m.cld.smartcost.com.cn/' );
  7072. $user = $staffmsg ['wxid'];
  7073. $expCom = explode ( ":", $invoiceDetail ['expressCompany'] );
  7074. if (empty ( $expCom ))
  7075. $expCom [0] = '';
  7076. $msg = "";
  7077. if (empty ( $typeMsg ))
  7078. $msg = '太好了,您的发票' . $invoiceDetail ['invoiceSerial'] . ' 已邮寄 ' . $expCom [0] . ' ,快递号: <a href="https://m.kuaidi100.com/result.jsp?nu=' . $invoiceDetail ['expressNumber'] . '" >' . $invoiceDetail ['expressNumber'] . '</a>';
  7079. elseif ($typeMsg == "PRINT")
  7080. $msg = '太好了,您的发票已打印完成。';
  7081. $result = $client->SendMsg ( $user, $msg, 'text' );
  7082. }
  7083. }
  7084. }
  7085. /**
  7086. * 获取微信部门
  7087. * @param string $category
  7088. * @return number|mixed
  7089. */
  7090. function getToparty($category = '') {
  7091. $token = $this->getAccessToken (); //
  7092. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token={$token}&id=5" ), true );
  7093. $toparty = 0;
  7094. foreach ( $result ['department'] as $key => $value ) {
  7095. if ($value ['name'] == $category)
  7096. $toparty = $value ['id'];
  7097. }
  7098. return $toparty;
  7099. }
  7100. /**
  7101. * 获得某部门下的用户
  7102. * @param string $toparty
  7103. */
  7104. function getUserByToparty($toparty = '') {
  7105. $token = $this->getAccessToken (); //
  7106. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token={$token}&department_id={$toparty}" ), true );
  7107. $userList = array ();
  7108. foreach ( $result ['userlist'] as $key => $value ) {
  7109. array_push ( $userList, "'" . $value ['userid'] . "'" );
  7110. }
  7111. return $userList;
  7112. }
  7113. function msgSendToparty($msg, $title, $url, $toparty, $text = '') {
  7114. $token = $this->getAccessToken ();
  7115. if ($text == 'text') {
  7116. $data = '{
  7117. "touser": "' . $toparty . '",
  7118. "toparty": "",
  7119. "totag": "",
  7120. "msgtype": "text",
  7121. "agentid": 1000002,
  7122. "text": {
  7123. "content": "' . $msg . '"
  7124. },
  7125. "safe":0
  7126. }';
  7127. }
  7128. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  7129. if ($result->errmsg != 'ok') {
  7130. return 0;
  7131. } else {
  7132. return 1;
  7133. }
  7134. }
  7135. /**
  7136. * 获得可以发送微信用户列表
  7137. * @param string $category
  7138. * @return string
  7139. */
  7140. function getWxidByCategory($category = "") {
  7141. if (empty ( $category ))
  7142. return "";
  7143. Doo::loadModel ( 'staff' );
  7144. $staff = new staff ();
  7145. $toparty = $this->getToparty ( $category );
  7146. $wxList = array ();
  7147. $wxString = "";
  7148. if (! empty ( $toparty )) {
  7149. $userList = $this->getUserByToparty ( $toparty );
  7150. $userCon = implode ( ',', $userList );
  7151. // echo $userCon;
  7152. $sidList = $staff->getStaffByWxid ( $userCon );
  7153. foreach ( $sidList as $key => $value ) {
  7154. $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  7155. if ($falg) {
  7156. array_push ( $wxList, $value ['wxid'] );
  7157. }
  7158. }
  7159. $wxString = implode ( '|', $wxList );
  7160. }
  7161. return $wxString;
  7162. }
  7163. /**
  7164. * 读取发送信息规则判断是否需要发送
  7165. * @param number $sid
  7166. * @param string $sendType
  7167. * @return boolean
  7168. */
  7169. function isSendNotification($sid = 0, $sendType = '') {
  7170. Doo::loadModel ( "notificationConf" );
  7171. $notificationConf = new notificationConf ();
  7172. $detail = $notificationConf->getNotificationConfBySid ( $sid );
  7173. $conf = array ();
  7174. $sendFlag = true;
  7175. if (! empty ( $detail )) {
  7176. $conf = json_decode ( $detail ['conf'], true );
  7177. if (! empty ( $sendType )) {
  7178. if (isset ( $conf [$sendType] )) {
  7179. if ($conf [$sendType] == "CLOSE")
  7180. $sendFlag = false;
  7181. elseif ($conf [$sendType] == "Weekend") {
  7182. $day = date ( "w" );
  7183. if (1 <= $day && 5 >= $day)
  7184. $sendFlag = false;
  7185. } elseif ($conf [$sendType] == "OneToFriday") {
  7186. $day = date ( "w" );
  7187. if (0 == $day || 6 == $day)
  7188. $sendFlag = false;
  7189. }
  7190. }
  7191. } else
  7192. $sendFlag = false;
  7193. }
  7194. return $sendFlag;
  7195. }
  7196. /**
  7197. * 根据规则发送信息
  7198. * @param unknown $msg
  7199. * @param unknown $title
  7200. * @param unknown $url
  7201. * @param unknown $user
  7202. * @param string $text
  7203. * @return number
  7204. */
  7205. private function msgSend($msg, $title, $url, $user, $sid = 0, $sendType = '') {
  7206. $token = $this->getAccessToken ();
  7207. $falg = $this->isSendNotification ( $sid, $sendType );
  7208. // if ($text == 'text') {
  7209. // $data = '{
  7210. // "touser": "' . $user . '",
  7211. // "toparty": "",
  7212. // "totag": "",
  7213. // "msgtype": "text",
  7214. // "agentid": 1000002,
  7215. // "text": {
  7216. // "content": "' . $msg . '"
  7217. // },
  7218. // "safe":0
  7219. // }';
  7220. // } else {
  7221. $data = '{
  7222. "touser": "' . $user . '",
  7223. "toparty": "",
  7224. "totag": "",
  7225. "msgtype": "news",
  7226. "agentid": 1000002,
  7227. "news": {
  7228. "articles":[
  7229. {
  7230. "title": "' . $title . '",
  7231. "description": "' . $msg . '",
  7232. "url": "' . $url . '",
  7233. "picurl": ""
  7234. }
  7235. ]
  7236. }
  7237. }';
  7238. // }
  7239. if ($falg) {
  7240. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  7241. if ($result->errmsg != 'ok') {
  7242. return 0;
  7243. } else {
  7244. return 1;
  7245. }
  7246. } else
  7247. return 0;
  7248. }
  7249. private function getAccessToken() {
  7250. // access_token 应该全局存储与更新,以下代码以写入到文件中做示例
  7251. // $file = './access_token.txt';
  7252. // $data = json_decode ( file_get_contents ( $file ) );
  7253. // if ($data->expire_time < time () or ! $data->expire_time) {
  7254. // 如果是企业号用以下URL获取access_token
  7255. $url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$this->appId&corpsecret=$this->appSecret";
  7256. // $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$this->appId&secret=$this->appSecret";
  7257. $res = json_decode ( $this->httpGet ( $url ) );
  7258. $access_token = $res->access_token;
  7259. // echo $access_token;
  7260. // if ($access_token) {
  7261. // $data->expire_time = time () + 7000;
  7262. // $data->access_token = $access_token;
  7263. // $fp = fopen ( $file, "w" );
  7264. // fwrite ( $fp, json_encode ( $data ) );
  7265. // fclose ( $fp );
  7266. // }
  7267. // } else {
  7268. // $access_token = $data->access_token;
  7269. // }
  7270. return $access_token;
  7271. }
  7272. private function httpGet($url) {
  7273. $curl = curl_init ();
  7274. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  7275. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  7276. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  7277. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  7278. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  7279. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  7280. curl_setopt ( $curl, CURLOPT_URL, $url );
  7281. $res = curl_exec ( $curl );
  7282. curl_close ( $curl );
  7283. return $res;
  7284. }
  7285. private function httpPost($url, $data) {
  7286. $curl = curl_init ();
  7287. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  7288. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  7289. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  7290. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  7291. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  7292. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  7293. curl_setopt ( $curl, CURLOPT_URL, $url );
  7294. curl_setopt ( $curl, CURLOPT_POST, 1 );
  7295. curl_setopt ( $curl, CURLOPT_POSTFIELDS, $data );
  7296. $res = curl_exec ( $curl );
  7297. curl_close ( $curl );
  7298. return $res;
  7299. }
  7300. }
  7301. ?>