InvoiceController.php 314 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573
  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-iacd' );
  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. $tokenTime=time().rand(5, 15);
  250. $_SESSION ['token_' . $this->staff [0] ['sidKey'].'_'.$tokenTime] = $token;
  251. $this->data ['token'] = $token;
  252. $this->data['tokenTime']=$tokenTime;
  253. $this->data ['memu'] = "invoice";
  254. $this->data ['staff'] = $this->staff;
  255. $this->data ['receiptMemu'] = 'invoice';
  256. $this->render ( "/admin/invoiceAdd", $this->data );
  257. }
  258. /**
  259. * 自更新发票信息库
  260. * @param unknown $invoicePrintDetail
  261. */
  262. function autoUpdateInvoiceInfoBase($invoicePrintDetail) {
  263. // 发票信息库
  264. Doo::loadModel ( 'invoiceInfoBase' );
  265. $invoiceInfoBase = new invoiceInfoBase ();
  266. $updateDate = strtotime ( $invoicePrintDetail ['date'] );
  267. $TIN = $invoicePrintDetail ['TIN'];
  268. $invoiceTitle = $invoicePrintDetail ['invoiceTitle'];
  269. if (empty ( $invoiceTitle ))
  270. $invoiceTitle = $invoicePrintDetail ['invoiceCompany'];
  271. $IIBList = $invoiceInfoBase->getInvoiceInfoByTT ( $TIN, $invoiceTitle );
  272. // 确认有该条发票信息
  273. $invoiceInfoBase = new invoiceInfoBase ();
  274. if (! empty ( $IIBList )) {
  275. // 发票库里的信息数量
  276. $IIBListCount = count ( $IIBList );
  277. if ($IIBListCount == 1) { // 更新发票--提交是最新的时间
  278. $item = array (
  279. 'iibID' => $IIBList [0] ['iibID'],
  280. 'invoiceTitle' => $invoiceTitle,
  281. 'TIN' => $TIN
  282. );
  283. if (! empty ( $invoicePrintDetail ['address'] )) {
  284. $item += array (
  285. 'address' => $invoicePrintDetail ['address']
  286. );
  287. }
  288. if (! empty ( $invoicePrintDetail ['phone'] )) {
  289. $item += array (
  290. 'phone' => $invoicePrintDetail ['phone']
  291. );
  292. }
  293. if (! empty ( $invoicePrintDetail ['bank'] )) {
  294. $item += array (
  295. 'bank' => $invoicePrintDetail ['bank']
  296. );
  297. }
  298. if (! empty ( $invoicePrintDetail ['bankAccount'] )) {
  299. $item += array (
  300. 'bankAccount' => $invoicePrintDetail ['bankAccount']
  301. );
  302. }
  303. if ($updateDate >= strtotime ($IIBList [0] ['updateDate'])) {
  304. $item += array (
  305. 'updateDate' => $invoicePrintDetail ['date']
  306. );
  307. $invoiceInfoBase->setInvoiceInfoBaseByCondition ( $item );
  308. }
  309. } else { // 删除多张发票,重新添加发票
  310. $iibIDStr = '';
  311. $iibID = array ();
  312. foreach ( $IIBList as $key => $value ) {
  313. array_push ( $iibID, $value ['iibID'] );
  314. }
  315. $iibIDStr = implode ( ",", $iibID ); // 删除
  316. $invoiceInfoBase->delInvoiceInfoBaseByIibStr ( $iibIDStr );
  317. $item = array (
  318. 'invoiceTitle' => $invoiceTitle,
  319. 'TIN' => $TIN,
  320. 'address' => $invoicePrintDetail ['address'],
  321. 'phone' => $invoicePrintDetail ['phone'],
  322. 'bank' => $invoicePrintDetail ['bank'],
  323. 'bankAccount' => $invoicePrintDetail ['bankAccount'],
  324. 'updateDate' => $invoicePrintDetail ['date']
  325. );
  326. $invoiceInfoBase->addInvoiceInfoBase ( $item );
  327. }
  328. } else { // 没有新增发票信息
  329. $item = array (
  330. 'invoiceTitle' => $invoiceTitle,
  331. 'TIN' => $TIN,
  332. 'address' => $invoicePrintDetail ['address'],
  333. 'phone' => $invoicePrintDetail ['phone'],
  334. 'bank' => $invoicePrintDetail ['bank'],
  335. 'bankAccount' => $invoicePrintDetail ['bankAccount'],
  336. 'updateDate' => $invoicePrintDetail ['date']
  337. );
  338. $invoiceInfoBase->addInvoiceInfoBase ( $item );
  339. }
  340. }
  341. function invoiceAddFill() {
  342. session_start ();
  343. Doo::loadModel ( 'L_category' );
  344. $lCategory = new L_category ();
  345. $category = $lCategory->find ( array (
  346. 'asArray' => true
  347. ) );
  348. $this->data ['category'] = $category;
  349. Doo::loadModel ( 'invoiceTraining' );
  350. $invoiceTraining = new invoiceTraining ();
  351. $itList = $invoiceTraining->getInvoiceTrainingByCid ( $this->staff [0] ['cid'] );
  352. $this->data ['itList'] = $itList;
  353. Doo::loadModel ( 'invoice' );
  354. $invoice = new invoice ();
  355. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );
  356. $detail ['mailItemsArray'] = json_decode ( $detail ['mailItemsJson'], true );
  357. $token = $this->set_token ();
  358. $tokenTime=time().rand(5, 15);
  359. $_SESSION ['token_' . $this->staff [0] ['sidKey'].'_'.$tokenTime] = $token;
  360. $this->data ['token'] = $token;
  361. $this->data['tokenTime']=$tokenTime;
  362. $this->data ['invoiceDetail'] = $detail;
  363. $this->data ['memu'] = "invoice";
  364. $this->data ['staff'] = $this->staff;
  365. $this->data ['receiptMemu'] = 'invoice';
  366. $this->render ( "/admin/invoiceAddFill", $this->data );
  367. }
  368. /**
  369. * 提交一份开票申请,并记录下操作日志
  370. *
  371. * @since 1.0.0
  372. * @var integer cid 办事处ID
  373. * @var integer invoiceType 发票类型
  374. * @var integer doPost 是否邮寄
  375. * @var integer invoicePrice 开票金额
  376. * @var string invoiceElement 开票内容
  377. * @var string invoiceTitle 发票抬头
  378. * @var string invoiceCompany 单位名称
  379. * @var string TIN 纳税人识别码
  380. * @var string address 注册地址
  381. * @var string phone 注册电话
  382. * @var string bank 开户银行
  383. * @var string bankAccount 银行账户
  384. * @var string recipients 收件人
  385. * @var string recipientsPhone 收件人手机/电话
  386. * @var string recipientsAddress 收件地址
  387. * @var string mailItems 邮寄物品
  388. * @var string remark 备注
  389. * @return string 返回跳转开票主页路径
  390. */
  391. function invoiceAddDo() {
  392. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  393. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  394. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  395. // $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  396. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  397. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  398. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  399. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  400. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  401. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  402. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  403. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  404. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  405. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  406. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  407. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  408. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  409. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  410. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  411. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  412. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  413. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  414. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  415. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  416. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  417. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  418. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  419. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  420. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  421. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  422. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  423. $trainId = $this->get_args ( 'trainId' ) ? $this->get_args ( 'trainId' ) : 0;
  424. $settlementType = $this->get_args ( 'settlementType' ) ? $this->get_args ( 'settlementType' ) : "";
  425. /*
  426. * $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;
  427. */
  428. $token = $this->get_args ( 'token' ) ? $this->get_args ( 'token' ) : "";
  429. $tokenTime = $this->get_args ( 'tokenTime' ) ? $this->get_args ( 'tokenTime' ) : "";
  430. if (empty ( $token )) {
  431. die ( 'illegal request-token' );
  432. } else {
  433. session_start ();
  434. $sessionKey='token_' . $this->staff [0] ['sidKey'].'_'.$tokenTime;
  435. header ( 'Content-Type:text/html;charset=utf-8' );
  436. if (!isset($_SESSION [$sessionKey])||empty($_SESSION [$sessionKey])) {
  437. die ( '请重新刷新发票申请页面' );
  438. }elseif($_SESSION [$sessionKey]=='repeat'){
  439. die ( '请勿重复申请发票' );
  440. } else {
  441. echo $_SESSION [$sessionKey].'<br/>'.$token;
  442. if ($_SESSION [$sessionKey] != $token){
  443. die ( '请勿重复申请发票' );
  444. }else{
  445. $_SESSION [$sessionKey] = 'repeat';
  446. }
  447. }
  448. }
  449. if ($invoiceType == 1) {
  450. $temporary = $invoiceQuantity * $invoiceUnitPrice;
  451. if ($temporary > 10000) {
  452. header ( 'Content-Type:text/html;charset=utf-8' );
  453. die ( '专用发票总金额暂时不能超过10000.00(一万)元。' );
  454. // die ( 'illegal request-Please priceError' );
  455. }
  456. }
  457. if (empty ( $this->staff [0] ))
  458. die ( 'illegal request-Please login' );
  459. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $settlementType )) {
  460. Doo::loadModel ( 'invoice' );
  461. $invoice = new invoice ();
  462. Doo::loadModel ( 'L_category' );
  463. $lCategory = new L_category ();
  464. Doo::loadModel ( 'invoiceManage' );
  465. $invoiceManage = new invoiceManage ();
  466. Doo::loadModel ( 'invoiceOperationLog' );
  467. $invoiceOperationLog = new invoiceOperationLog ();
  468. Doo::loadClass ( 'XDeode' );
  469. $XDeode = new XDeode ( 5 );
  470. $trainId = $XDeode->decode ( $trainId );
  471. $categoryDetil = $lCategory->getOne ( array (
  472. 'SELECT' => 'title',
  473. 'where' => 'cid=' . $cid,
  474. 'asArray' => true
  475. ) );
  476. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  477. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  478. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  479. // print_r(current($invoiceManageDetail ['staffList']));
  480. // die;
  481. $moldManage = array ();
  482. foreach ( $invoiceManageList as $key => $value ) {
  483. if ($value ['mold'] == '发票打印')
  484. $moldManage [$value ['mold']] = $value ['staffList'];
  485. elseif ($value ['mold'] == '发票邮寄')
  486. $moldManage [$value ['mold']] = $value ['staffList'];
  487. elseif ($value ['mold'] == '发票退票')
  488. $moldManage [$value ['mold']] = $value ['staffList'];
  489. }
  490. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  491. $st = '';
  492. if ($settlementType == 'SOFTWARE') {
  493. $st = 0;
  494. $trainId = 0;
  495. } elseif ($settlementType == 'TRAINING') {
  496. $st = 1;
  497. if (empty ( $trainId ) && ! is_numeric ( $trainId )) {
  498. die ( 'illegal request-trainingIdError' );
  499. }
  500. } else {
  501. die ( 'illegal request-settlementError' );
  502. }
  503. $item = array (
  504. 'cid' => $cid,
  505. 'categoryName' => $categoryDetil ['title'],
  506. 'invoiceElement' => $invoiceElement,
  507. 'invoiceQuantity' => $invoiceQuantity,
  508. 'invoiceUnitPrice' => $invoiceUnitPrice,
  509. 'invoicePrice' => $invoicePrice,
  510. 'invoiceType' => $invoiceType,
  511. 'settlementType' => $st,
  512. 'doPost' => $doPost,
  513. 'status' => 1,
  514. 'invoiceSerial' => "#F" . date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT),
  515. 'date' => date ( "Y-m-d H:i:s" ),
  516. 'updateTime' => date ( "Y-m-d H:i:s" ),
  517. 'sid' => $this->staff [0] ['sid'],
  518. 'userName' => $this->staff [0] ['username'],
  519. 'invoiceManage' => $invoiceManageDetail ['staff'],
  520. 'pendingApprovals' => $pendingApprovalsSid,
  521. 'moldManage' => json_encode ( $moldManage ),
  522. 'remark' => $remark,
  523. 'trainId' => $trainId
  524. );
  525. if ($invoiceType == 0)
  526. $item += array (
  527. 'invoiceTitle' => $invoiceTitle,
  528. 'TIN' => $TINT,
  529. 'address' => $addressT,
  530. 'phone' => $phoneT,
  531. 'bank' => $bankT,
  532. 'bankAccount' => $bankAccountT
  533. );
  534. else {
  535. $item += array (
  536. 'invoiceCompany' => $invoiceCompany,
  537. 'TIN' => $TIN,
  538. 'address' => $address,
  539. 'phone' => $phone,
  540. 'bank' => $bank,
  541. 'bankAccount' => $bankAccount
  542. );
  543. }
  544. if ($doPost == 1) {
  545. $mailList = array (
  546. 'invoice' => 1,
  547. 'mailItems' => $mailItems
  548. );
  549. if (! empty ( $softLock ))
  550. $mailList += array (
  551. 'softLock' => $softLockNum
  552. );
  553. else
  554. $mailList += array (
  555. 'softLock' => 0
  556. );
  557. if (! empty ( $contract ))
  558. $mailList += array (
  559. 'contract' => $contractNum
  560. );
  561. else
  562. $mailList += array (
  563. 'contract' => 0
  564. );
  565. if (! empty ( $instructions ))
  566. $mailList += array (
  567. 'instructions' => $instructionsNum
  568. );
  569. else
  570. $mailList += array (
  571. 'instructions' => 0
  572. );
  573. if (! empty ( $remittance ))
  574. $mailList += array (
  575. 'remittance' => $remittance
  576. );
  577. else
  578. $mailList += array (
  579. 'remittance' => ''
  580. );
  581. $mailString = '发票x1张,备注:' . $mailItems;
  582. if (! empty ( $softLock ))
  583. $mailString .= ',软件锁x' . $softLockNum . '个';
  584. if (! empty ( $contract ))
  585. $mailString .= ',合同x' . $contractNum . '份';
  586. if (! empty ( $instructions ))
  587. $mailString .= ',说明书x' . $instructionsNum . '本';
  588. if (! empty ( $remittance ))
  589. $mailString .= ',汇款账号单(张)';
  590. $item += array (
  591. 'recipients' => $recipients,
  592. 'recipientsPhone' => $recipientsPhone,
  593. 'recipientsAddress' => $recipientsAddress,
  594. 'mailItems' => $mailString,
  595. 'mailItemsJson' => json_encode ( $mailList )
  596. );
  597. }
  598. $iid = $invoice->addInvoice ( $item );
  599. // 如果是培训班结算 创建培训班发票到培训班备份中
  600. if (! empty ( $st ) && $st == 1) {
  601. Doo::loadModel ( 'invoiceStore' );
  602. $invoiceStore = new invoiceStore ();
  603. Doo::loadModel ( 'invoiceTraining' );
  604. $invoiceTraining = new invoiceTraining ();
  605. $isid = $invoiceStore->setInvoiceToInvoiceStore ( $iid );
  606. $itemIS = array (
  607. 'isid' => $isid,
  608. 'ipSource' => 1,
  609. 'apStatus' => 1,
  610. 'iid' => $iid
  611. );
  612. $invoiceStore->setInvoiceStoreByCondition ( $itemIS );
  613. // 更新培训班总数量
  614. $detailIT = $invoiceTraining->getInvoiceTrainingByItid ( $trainId );
  615. $item = array (
  616. 'itid' => $trainId,
  617. 'invoiceTotal' => $detailIT ['invoiceTotal'] + 1,
  618. 'submitStatus' => 1
  619. );
  620. $itid = $invoiceTraining->setInvoiceTrainByCondition ( $item );
  621. }
  622. // 操作日志
  623. $item = array (
  624. 'date' => date ( "Y-m-d H:i:s" ),
  625. 'operation' => "创建",
  626. 'status' => 1,
  627. 'img' => $this->staff [0] ['avatar'],
  628. 'username' => $this->staff [0] ['username'],
  629. 'uid' => $this->staff [0] ['sid'],
  630. 'category' => $this->staff [0] ['category'],
  631. 'iid' => $iid
  632. );
  633. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  634. $item = array (
  635. 'date' => date ( "Y-m-d H:i:s" ),
  636. 'operation' => "提交审批",
  637. 'status' => 1,
  638. 'img' => $this->staff [0] ['avatar'],
  639. 'username' => $this->staff [0] ['username'],
  640. 'uid' => $this->staff [0] ['sid'],
  641. 'category' => $this->staff [0] ['category'],
  642. 'iid' => $iid
  643. );
  644. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  645. Doo::loadModel ( 'staff' );
  646. $staff = new staff ();
  647. $username2 = $staff->getOne ( array (
  648. 'select' => 'wxid',
  649. 'where' => 'sid=' . $pendingApprovalsSid,
  650. 'asArray' => TRUE
  651. ) );
  652. // 发送微信审批通知
  653. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  654. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  655. }
  656. return "/invoice";
  657. }
  658. function invoiceEdit() {
  659. Doo::loadClass ( 'XDeode' );
  660. $XDeode = new XDeode ( 5 );
  661. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  662. $iid = $XDeode->decode ( $iid );
  663. if (! is_numeric ( $iid ))
  664. die ( 'illegal request' );
  665. Doo::loadModel ( 'invoice' );
  666. $invoice = new invoice ();
  667. Doo::loadModel ( 'invoiceOperationLog' );
  668. $invoiceOperationLog = new invoiceOperationLog ();
  669. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  670. $operation = $invoiceOperationLog->getInvoiceOperationByDropped ( $iid );
  671. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  672. $this->data ['operation'] = $operation;
  673. $this->data ['invoiceDetail'] = $invoiceDetail;
  674. $this->data ['memu'] = "invoice";
  675. $this->data ['staff'] = $this->staff;
  676. $this->data ['receiptMemu'] = 'invoice';
  677. $this->render ( "/admin/invoiceEdit", $this->data );
  678. }
  679. /**
  680. * 重新编辑退回的发票
  681. * @return string
  682. */
  683. function invoiceEditDo() {
  684. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  685. Doo::loadModel ( 'invoice' );
  686. $invoice = new invoice ();
  687. $iid = $invoice->authcode ( $iidKey );
  688. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  689. die ( 'illegal request' );
  690. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  691. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  692. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  693. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  694. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  695. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  696. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  697. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  698. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  699. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  700. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  701. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  702. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  703. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  704. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  705. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  706. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  707. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  708. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  709. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  710. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  711. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  712. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  713. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  714. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  715. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  716. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  717. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  718. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  719. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  720. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  721. if ($invoiceType == 1) {
  722. $temporary = $invoiceQuantity * $invoiceUnitPrice;
  723. if ($temporary > 10000)
  724. die ( 'illegal request-Please priceError' );
  725. }
  726. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  727. Doo::loadModel ( 'invoiceManage' );
  728. $invoiceManage = new invoiceManage ();
  729. Doo::loadModel ( 'invoiceOperationLog' );
  730. $invoiceOperationLog = new invoiceOperationLog ();
  731. Doo::loadModel ( 'invoiceStore' );
  732. $invoiceStore = new invoiceStore ();
  733. $cid = explode ( ':', $cid );
  734. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  735. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  736. $moldManage = array ();
  737. foreach ( $invoiceManageList as $key => $value ) {
  738. if ($value ['mold'] == '发票打印')
  739. $moldManage [$value ['mold']] = $value ['staffList'];
  740. elseif ($value ['mold'] == '发票邮寄')
  741. $moldManage [$value ['mold']] = $value ['staffList'];
  742. elseif ($value ['mold'] == '发票打印')
  743. $moldManage [$value ['mold']] = $value ['staffList'];
  744. }
  745. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  746. $item = array (
  747. 'iid' => $iid,
  748. 'cid' => $cid [0],
  749. 'categoryName' => $cid [1],
  750. 'invoiceElement' => $invoiceElement,
  751. 'invoiceQuantity' => $invoiceQuantity,
  752. 'invoiceUnitPrice' => $invoiceUnitPrice,
  753. 'invoicePrice' => $invoicePrice,
  754. 'invoiceType' => $invoiceType,
  755. 'doPost' => $doPost,
  756. 'status' => 1,
  757. 'updateTime' => date ( "Y-m-d H:i:s" ),
  758. 'remark' => $remark
  759. );
  760. if ($invoiceType == 0)
  761. $item += array (
  762. 'invoiceTitle' => $invoiceTitle,
  763. 'TIN' => $TINT,
  764. 'address' => $addressT,
  765. 'phone' => $phoneT,
  766. 'bank' => $bankT,
  767. 'bankAccount' => $bankAccountT
  768. );
  769. else {
  770. $item += array (
  771. 'invoiceCompany' => $invoiceCompany,
  772. 'TIN' => $TIN,
  773. 'address' => $address,
  774. 'phone' => $phone,
  775. 'bank' => $bank,
  776. 'bankAccount' => $bankAccount
  777. );
  778. }
  779. if ($doPost == 1) {
  780. $mailList = array (
  781. 'invoice' => 1,
  782. 'mailItems' => $mailItems
  783. );
  784. if (! empty ( $softLock ))
  785. $mailList += array (
  786. 'softLock' => $softLockNum
  787. );
  788. else
  789. $mailList += array (
  790. 'softLock' => '0'
  791. );
  792. if (! empty ( $contract ))
  793. $mailList += array (
  794. 'contract' => $contractNum
  795. );
  796. else
  797. $mailList += array (
  798. 'contract' => '0'
  799. );
  800. if (! empty ( $instructions ))
  801. $mailList += array (
  802. 'instructions' => $instructionsNum
  803. );
  804. else
  805. $mailList += array (
  806. 'instructions' => '0'
  807. );
  808. if (! empty ( $remittance ))
  809. $mailList += array (
  810. 'remittance' => $remittance
  811. );
  812. else
  813. $mailList += array (
  814. 'remittance' => ''
  815. );
  816. $mailString = '发票x1,备注:' . $mailItems;
  817. if (! empty ( $softLock ))
  818. $mailString .= ',软件锁x' . $softLockNum;
  819. if (! empty ( $contract ))
  820. $mailString .= ',合同x' . $contractNum;
  821. if (! empty ( $instructions ))
  822. $mailString .= ',说明书x' . $instructionsNum;
  823. if (! empty ( $remittance ))
  824. $mailString .= ',汇款账号单';
  825. $item += array (
  826. 'recipients' => $recipients,
  827. 'recipientsPhone' => $recipientsPhone,
  828. 'recipientsAddress' => $recipientsAddress,
  829. 'mailItems' => $mailString,
  830. 'mailItemsJson' => json_encode ( $mailList )
  831. );
  832. }
  833. $invoice->setInvoiceByCondition ( $item );
  834. // 更新培训班仓库里的发票
  835. $detail = $invoice->getInvoiceByIid ( $iid );
  836. if (! empty ( $detail ['isid'] )) {
  837. $invoiceStore->isid = $detail ['isid'];
  838. $invoiceStore->invoiceQuantity = $invoiceQuantity;
  839. $invoiceStore->invoiceUnitPrice = $invoiceUnitPrice;
  840. $invoiceStore->invoicePrice = $invoicePrice;
  841. $invoiceStore->update ();
  842. }
  843. $item = array (
  844. 'date' => date ( "Y-m-d H:i:s" ),
  845. 'operation' => "重新提交审批",
  846. 'status' => 1,
  847. 'img' => $this->staff [0] ['avatar'],
  848. 'username' => $this->staff [0] ['username'],
  849. 'uid' => $this->staff [0] ['sid'],
  850. 'category' => $this->staff [0] ['category'],
  851. 'iid' => $iid
  852. );
  853. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  854. }
  855. return "/invoice";
  856. }
  857. /**
  858. * 培训班
  859. */
  860. function invoiceTraining() {
  861. Doo::loadModel ( 'L_category' );
  862. $lCategory = new L_category ();
  863. Doo::loadModel ( 'invoiceTraining' );
  864. $invoiceTraining = new invoiceTraining ();
  865. Doo::loadModel ( 'invoiceTrainManage' );
  866. $invoiceTrainManage = new invoiceTrainManage ();
  867. $imcStaff = $invoiceTrainManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  868. $cidList = array ();
  869. foreach ( $imcStaff as $key => $value ) {
  870. array_push ( $cidList, $value ['cid'] );
  871. }
  872. if (empty ( $cidList )) {
  873. $cidString = $this->staff [0] ['cid'];
  874. } else {
  875. $cidString = implode ( ',', $cidList );
  876. $cidString .= $cidString . ',' . $this->staff [0] ['cid'];
  877. }
  878. $itTodoList = $invoiceTraining->getInvoiceTrainingByTodo ( '', $cidString, $this->staff [0] ['sid'] );
  879. $itedList = $invoiceTraining->getInvoiceTrainingByStatus ( 2, '', $cidString, $this->staff [0] ['sid'] );
  880. $category = $lCategory->getCategory ();
  881. $itid = array ();
  882. foreach ( $itTodoList as $key => $value ) {
  883. array_push ( $itid, $value ['itid'] );
  884. // 如果入账100%更新为已完成
  885. if ($itTodoList [$key] ['arriveSchedule'] >= 100) {
  886. $invoiceTraining = new invoiceTraining ();
  887. $invoiceTraining->itid = $value ['itid'];
  888. $invoiceTraining->status = 2;
  889. $invoiceTraining->update ();
  890. }
  891. }
  892. foreach ( $itedList as $value ) {
  893. array_push ( $itid, $value ['itid'] );
  894. }
  895. $itid = implode ( ',', $itid );
  896. $this->data ['itStatist'] = $invoiceTraining->getInvoiceTrainStatistics ( $itid );
  897. // print_r($itTodoList);
  898. $this->data ['trainCount'] = count ( $itTodoList ) + count ( $itedList );
  899. $this->data ['itTodoList'] = $itTodoList;
  900. $this->data ['itedList'] = $itedList;
  901. $this->data ['category'] = $category;
  902. $this->data ['memu'] = "invoice";
  903. $this->data ['staff'] = $this->staff;
  904. $this->data ['receiptMemu'] = 'invoiceTraining';
  905. $this->render ( "/admin/invoiceTraining", $this->data );
  906. }
  907. /**
  908. * 创建培训班
  909. */
  910. function invoiceTrainingAdd() {
  911. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  912. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  913. $trainDate = $this->get_args ( 'trainDate' ) ? $this->get_args ( 'trainDate' ) : "";
  914. if (empty ( $this->staff [0] ))
  915. die ( 'illegal request' );
  916. if (! empty ( $cid ) && ! empty ( $trainName ) && ! empty ( $trainDate )) {
  917. Doo::loadModel ( 'invoiceTraining' );
  918. $invoiceTraining = new invoiceTraining ();
  919. Doo::loadModel ( 'invoice' );
  920. $invoice = new invoice ();
  921. Doo::loadModel ( 'L_category' );
  922. $lCategory = new L_category ();
  923. Doo::loadModel ( 'invoiceManage' );
  924. $invoiceManage = new invoiceManage ();
  925. Doo::loadModel ( 'invoiceOperationLog' );
  926. $invoiceOperationLog = new invoiceOperationLog ();
  927. $item = array (
  928. 'cid' => $cid,
  929. 'trainName' => $trainName,
  930. 'trainDate' => $trainDate,
  931. 'creator' => $this->staff [0] ['sid'],
  932. 'creatorDate' => date ( "Y-m-d H:i:s" )
  933. );
  934. $itid = $invoiceTraining->addInvoiceTraining ( $item );
  935. }
  936. return "/invoiceTraining";
  937. }
  938. /**
  939. * 删除培训班
  940. */
  941. function invoiceTrainingDelDo() {
  942. $itid = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  943. if (! empty ( $itid )) {
  944. Doo::loadModel ( 'invoiceTraining' );
  945. $invoiceTraining = new invoiceTraining ();
  946. $invoiceTraining->delInvoiceTrainingByItid ( $itid );
  947. }
  948. return "/invoiceTraining";
  949. }
  950. /**
  951. * 培训班详情
  952. */
  953. function invoiceTrainingDetail() {
  954. $trainStatus = $this->get_args ( 'trainStatus' ) ? $this->get_args ( 'trainStatus' ) : "ALL";
  955. $itid = isset ( $this->params ['trainingKey'] ) ? $this->params ['trainingKey'] : "";
  956. Doo::loadModel ( 'invoiceTraining' );
  957. $invoiceTraining = new invoiceTraining ();
  958. Doo::loadModel ( 'invoiceStore' );
  959. $invoiceStore = new invoiceStore ();
  960. if (empty ( $itid ))
  961. die ( 'illegal request' );
  962. $con = ' (b.untreadStatus is null or b.untreadStatus!=2) and ';
  963. if ($trainStatus == "SUBED")
  964. $con = ' (b.untreadStatus is null ) and ';
  965. elseif ($trainStatus == "APPROVAL")
  966. $con = ' ( b.status=1 and b.untreadStatus!=2 ) and ';
  967. elseif ($trainStatus == "TICKET")
  968. $con = ' (b.printStatus=1 and b.status=2 and b.untreadStatus!=2) and ';
  969. elseif ($trainStatus == "TICKETING") {
  970. $con = ' (b.status=2 and b.untreadStatus=1) and ';
  971. }
  972. $detail = $invoiceTraining->getInvoiceTrainingByItid ( $itid );
  973. $isList = $invoiceStore->getinvoiceStoreByItid ( $itid, $con );
  974. //print_r($isList);
  975. $trainlist = array ();
  976. foreach ( $isList as $key => $value ) {
  977. $irDetail = array ();
  978. if ($value ['apStatus'] == 1) {
  979. // array_push ( $irDetail, '' );
  980. array_push ( $irDetail, '<input disabled type="checkbox" style="display:none" >' );
  981. } else {
  982. array_push ( $irDetail, '<input type="checkbox" class="hide" id="' . $value ['storeKey'] . '" name="isBox" value="' . $value ['storeKey'] . '" > <a href="/invoiceStoreEdit/' . $value ['storeKey'] . '.html">编辑</a>
  983. <a href="#confirm" onclick="invoiceStoreApproval(\'' . $value ['storeKey'] . '\')" data-toggle="modal">提交审批</a>
  984. <a href="#del" node-iStore="del" data-key="' . $value ['storeKey'] . '" onclick="invoiceStoreDel(\'' . $value ['storeKey'] . '\')" data-toggle="modal" class="colRed">移除</a>' );
  985. }
  986. array_push ( $irDetail, $value ['invoiceSerial'] );
  987. if ($value ['invoiceType'] == 1)
  988. array_push ( $irDetail, $value ['invoiceCompany'] );
  989. else
  990. array_push ( $irDetail, $value ['invoiceTitle'] );
  991. array_push ( $irDetail, $value ['TIN'] );
  992. array_push ( $irDetail, $value ['userName'] );
  993. if (empty ( $value ['mailItems'] ) && $value ['apStatus'] != 1) {
  994. array_push ( $irDetail, '<a href="#confirm-erro" onclick="invoiceStoreMail(\'' . $value ['storeKey'] . '\')" data-toggle="modal">设置邮寄物品</a>' );
  995. } else
  996. array_push ( $irDetail, $value ['mailItems'] );
  997. array_push ( $irDetail, $value ['recipientsAddress'] . $value ['recipients'] . $value ['recipientsPhone'] );
  998. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  999. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  1000. array_push ( $irDetail, $value ['invoiceElement'] );
  1001. array_push ( $irDetail, $value ['invoiceQuantity'] );
  1002. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  1003. if ($value ['invoiceType'] == 1)
  1004. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  1005. else
  1006. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  1007. array_push ( $irDetail, $value ['remark'] );
  1008. if ($value ['status'] == 1)
  1009. array_push ( $irDetail, '审批中' );
  1010. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1)
  1011. array_push ( $irDetail, '已出票' );
  1012. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1 && $value ['printStatus'] != 'irid' && ($value ['untreadStatus'] == 3 || $value ['untreadStatus'] == 0))
  1013. array_push ( $irDetail, '已入账' );
  1014. else
  1015. array_push ( $irDetail, '' );
  1016. array_push ( $irDetail, $value ['invoiceNo'] );
  1017. array_push ( $irDetail, $value ['printTime'] );
  1018. $html = '';
  1019. foreach ( $value ['invoiceReceivables'] as $value ) {
  1020. $html .= '&nbsp;<a href="#billing" node-invoice="INFO" data-type="receivables" data-iskey="' . $value [2] . '" data-toggle="modal">' . $value [1] . '</a>';
  1021. }
  1022. array_push ( $irDetail, $html );
  1023. array_push ( $trainlist, $irDetail );
  1024. }
  1025. $trainlistJson = json_encode ( $trainlist );
  1026. if (empty ( $detail ))
  1027. die ( 'illegal request' );
  1028. // 培训班结算是否有和是否已经结算完成
  1029. Doo::loadModel ( 'receipt' );
  1030. $receipt = new receipt ();
  1031. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $itid );
  1032. $this->data ['receiptDetail'] = $receiptDetail;
  1033. $this->data ['trainStatus'] = $trainStatus;
  1034. $this->data ['itid'] = $itid;
  1035. $this->data ['trainlistJson'] = $trainlistJson;
  1036. $this->data ['iTrainDetail'] = $detail;
  1037. $this->data ['memu'] = "invoice";
  1038. $this->data ['staff'] = $this->staff;
  1039. $this->data ['receiptMemu'] = 'invoiceTraining';
  1040. $this->render ( "/admin/invoiceTrainingDetail", $this->data );
  1041. }
  1042. /**
  1043. * 上传培训班发票
  1044. * @return string
  1045. */
  1046. function invoiceTrainingUpload() {
  1047. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  1048. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  1049. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  1050. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  1051. header ( "HTTP/1.1 500 Internal Server Error" );
  1052. echo "POST exceeded maximum allowed size.";
  1053. exit ( 0 );
  1054. }
  1055. // Settings
  1056. $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)
  1057. $upload_name = "Filedata";
  1058. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  1059. $extension_whitelist = array (
  1060. "doc",
  1061. "txt",
  1062. "jpg",
  1063. "gif",
  1064. "png"
  1065. ); // Allowed file extensions
  1066. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  1067. // Other variables
  1068. $MAX_FILENAME_LENGTH = 260;
  1069. $file_name = "";
  1070. $file_extension = "";
  1071. $uploadErrors = array (
  1072. 0 => "文件上传成功",
  1073. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  1074. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  1075. 3 => "上传的文件仅为部分文件",
  1076. 4 => "没有文件上传",
  1077. 6 => "缺少临时文件夹"
  1078. );
  1079. $nk = time ();
  1080. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  1081. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  1082. echo "文件无法保存.";
  1083. exit ( 0 );
  1084. }
  1085. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  1086. echo json_encode ( array (
  1087. 'filename' => $file_name,
  1088. 'id' => $nk
  1089. ) );
  1090. exit ( 0 );
  1091. }
  1092. /**
  1093. * 导入发票临时仓库
  1094. */
  1095. function invoiceStoreImport() {
  1096. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  1097. $trainingKey = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  1098. $path = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  1099. if ($path != "" && ! empty ( $trainingKey )) {
  1100. Doo::loadModel ( 'invoiceStore' );
  1101. Doo::loadModel ( 'staff' );
  1102. $staff = new staff ();
  1103. Doo::loadModel ( 'invoiceTraining' );
  1104. $invoiceTraining = new invoiceTraining ();
  1105. Doo::loadClass ( 'XDeode' );
  1106. $XDeode = new XDeode ( 5 );
  1107. $itid = $XDeode->decode ( $trainingKey );
  1108. // 培训班结算是否有和是否已经结算完成
  1109. Doo::loadModel ( 'receipt' );
  1110. $receipt = new receipt ();
  1111. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $itid );
  1112. if (! empty ( $receiptDetail )) {
  1113. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9)
  1114. die ( 'illegal request--status' );
  1115. }
  1116. $exlArray = $this->formatExcelToArrayTrain ( DOO::conf ()->SITE_PATH . "upload/invoiceTraining/" . $path );
  1117. $userName = $this->staff [0] ['username'];
  1118. $sDetail = $staff->getStaffByName ( $userName );
  1119. // die('sdd');
  1120. // 可以优化
  1121. foreach ( $exlArray as $key => $value ) {
  1122. // 开票
  1123. $invoice = new invoiceStore ();
  1124. $invoice->trainId = $itid;
  1125. $invoice->invoiceType = 0;
  1126. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  1127. $invoice->invoiceType = 1;
  1128. $invoice->invoiceQuantity = $value ['invoiceQuantity'];
  1129. $invoice->invoiceUnitPrice = $value ['invoiceUnitPrice'];
  1130. $invoice->invoicePrice = $value ['invoiceQuantity'] * $value ['invoiceUnitPrice'];
  1131. $invoice->invoiceTitle = $value ['invoiceTitle'];
  1132. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  1133. $invoice->invoiceCompany = $value ['invoiceTitle'];
  1134. $invoice->userName = $userName;
  1135. $invoice->sid = $sDetail ['sid'];
  1136. $invoice->cid = $sDetail ['cid'];
  1137. $invoice->categoryName = $sDetail ['category'];
  1138. $invoice->invoiceElement = $value ['invoiceElement'];
  1139. $invoice->remark = $value ['remark'];
  1140. // $invoice->date = $value ['date'];
  1141. // $invoice->printTime = $value ['date'];
  1142. $invoice->ipSource = 1;
  1143. $invoice->printStatus = 0;
  1144. $invoice->status = 0;
  1145. $invoice->postStatus = 1;
  1146. $invoice->untreadStatus = 0;
  1147. // $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1148. $invoice->TIN = $value ['TIN'];
  1149. $invoice->address = $value ['address'];
  1150. $invoice->phone = $value ['phone'];
  1151. $invoice->bank = $value ['bank'];
  1152. $invoice->bankAccount = $value ['bankAccount'];
  1153. $invoice->recipientsAddress = $value ['recipientsAddress'];
  1154. $invoice->recipients = $value ['recipients'];
  1155. $invoice->recipientsPhone = $value ['recipientsPhone'];
  1156. $iid = $invoice->insert ();
  1157. }
  1158. // 加入发票总数量
  1159. $item = array (
  1160. 'itid' => $itid,
  1161. 'invoiceTotal' => count ( $exlArray )
  1162. );
  1163. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1164. return '/invoiceTrainingDetail/' . $trainingKey . ".html";
  1165. }
  1166. echo 'no file';
  1167. }
  1168. /**
  1169. * 编辑仓库里的发票
  1170. */
  1171. function invoiceStoreEdit() {
  1172. Doo::loadClass ( 'XDeode' );
  1173. $XDeode = new XDeode ( 5 );
  1174. $iid = isset ( $this->params ['storeKey'] ) ? $this->params ['storeKey'] : "";
  1175. $iid = $XDeode->decode ( $iid );
  1176. if (! is_numeric ( $iid ))
  1177. die ( 'illegal request' );
  1178. Doo::loadModel ( 'invoiceStore' );
  1179. $invoiceStore = new invoiceStore ();
  1180. $invoiceDetail = $invoiceStore->getInvoiceStoreByIsid ( $iid );
  1181. // print_r($invoiceDetail);
  1182. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  1183. $this->data ['invoiceDetail'] = $invoiceDetail;
  1184. $this->data ['memu'] = "invoice";
  1185. $this->data ['staff'] = $this->staff;
  1186. $this->data ['receiptMemu'] = 'invoiceTraining';
  1187. $this->render ( "/admin/invoiceStoreEdit", $this->data );
  1188. }
  1189. function invoiceStoreEditDo() {
  1190. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1191. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1192. Doo::loadModel ( 'invoiceStore' );
  1193. $invoice = new invoiceStore ();
  1194. Doo::loadClass ( 'XDeode' );
  1195. $XDeode = new XDeode ( 5 );
  1196. $iid = $XDeode->decode ( $storeKey );
  1197. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1198. die ( 'illegal request' );
  1199. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  1200. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  1201. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  1202. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  1203. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  1204. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  1205. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  1206. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  1207. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  1208. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  1209. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  1210. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  1211. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  1212. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  1213. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1214. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1215. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1216. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1217. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  1218. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  1219. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  1220. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  1221. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  1222. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  1223. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1224. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1225. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1226. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1227. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1228. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1229. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1230. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  1231. $cid = explode ( ':', $cid );
  1232. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  1233. $item = array (
  1234. 'isid' => $iid,
  1235. 'cid' => $cid [0],
  1236. 'categoryName' => $cid [1],
  1237. 'invoiceElement' => $invoiceElement,
  1238. 'invoiceQuantity' => $invoiceQuantity,
  1239. 'invoiceUnitPrice' => $invoiceUnitPrice,
  1240. 'invoicePrice' => $invoicePrice,
  1241. 'invoiceType' => $invoiceType,
  1242. 'doPost' => $doPost,
  1243. 'status' => 1,
  1244. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1245. 'remark' => $remark
  1246. );
  1247. if ($invoiceType == 0)
  1248. $item += array (
  1249. 'invoiceTitle' => $invoiceTitle,
  1250. 'TIN' => $TINT,
  1251. 'address' => $addressT,
  1252. 'phone' => $phoneT,
  1253. 'bank' => $bankT,
  1254. 'bankAccount' => $bankAccountT
  1255. );
  1256. else {
  1257. $item += array (
  1258. 'invoiceCompany' => $invoiceCompany,
  1259. 'TIN' => $TIN,
  1260. 'address' => $address,
  1261. 'phone' => $phone,
  1262. 'bank' => $bank,
  1263. 'bankAccount' => $bankAccount
  1264. );
  1265. }
  1266. if ($doPost == 1) {
  1267. $mailList = array (
  1268. 'invoice' => 1,
  1269. 'mailItems' => $mailItems
  1270. );
  1271. if (! empty ( $softLock ))
  1272. $mailList += array (
  1273. 'softLock' => $softLockNum
  1274. );
  1275. else
  1276. $mailList += array (
  1277. 'softLock' => '0'
  1278. );
  1279. if (! empty ( $contract ))
  1280. $mailList += array (
  1281. 'contract' => $contractNum
  1282. );
  1283. else
  1284. $mailList += array (
  1285. 'contract' => '0'
  1286. );
  1287. if (! empty ( $instructions ))
  1288. $mailList += array (
  1289. 'instructions' => $instructionsNum
  1290. );
  1291. else
  1292. $mailList += array (
  1293. 'instructions' => '0'
  1294. );
  1295. if (! empty ( $remittance ))
  1296. $mailList += array (
  1297. 'remittance' => $remittance
  1298. );
  1299. else
  1300. $mailList += array (
  1301. 'remittance' => ''
  1302. );
  1303. $mailString = '发票x1,备注:' . $mailItems;
  1304. if (! empty ( $softLock ))
  1305. $mailString .= ',软件锁x' . $softLockNum;
  1306. if (! empty ( $contract ))
  1307. $mailString .= ',合同x' . $contractNum;
  1308. if (! empty ( $instructions ))
  1309. $mailString .= ',说明书x' . $instructionsNum;
  1310. if (! empty ( $remittance ))
  1311. $mailString .= ',汇款账号单';
  1312. $item += array (
  1313. 'recipients' => $recipients,
  1314. 'recipientsPhone' => $recipientsPhone,
  1315. 'recipientsAddress' => $recipientsAddress,
  1316. 'mailItems' => $mailString,
  1317. 'mailItemsJson' => json_encode ( $mailList )
  1318. );
  1319. }
  1320. $invoice->setInvoiceStoreByCondition ( $item );
  1321. }
  1322. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1323. }
  1324. /**
  1325. *
  1326. * @return string
  1327. */
  1328. function invoiceStoreDelete() {
  1329. Doo::loadClass ( 'XDeode' );
  1330. $XDeode = new XDeode ( 5 );
  1331. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1332. $iStoreKey = $this->get_args ( 'iStoreKey' ) ? $this->get_args ( 'iStoreKey' ) : 0;
  1333. $isid = $XDeode->decode ( $iStoreKey );
  1334. $itid = $XDeode->decode ( $trainKey );
  1335. if (! is_numeric ( $isid ))
  1336. die ( 'illegal request' );
  1337. Doo::loadModel ( 'invoiceStore' );
  1338. $invoiceStore = new invoiceStore ();
  1339. $invoiceStore->delete ( array (
  1340. 'where' => 'isid=' . $isid,
  1341. 'limit' => 1
  1342. ) );
  1343. Doo::loadModel ( 'invoiceTraining' );
  1344. $invoiceTraining = new invoiceTraining ();
  1345. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1346. $item = array (
  1347. 'itid' => $itid,
  1348. 'invoiceTotal' => $itDetail ['invoiceTotal'] - 1
  1349. );
  1350. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1351. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1352. }
  1353. /**
  1354. * 批量删除库里发票
  1355. */
  1356. function invoiceStoreBatchDelete() {
  1357. Doo::loadClass ( 'XDeode' );
  1358. $XDeode = new XDeode ( 5 );
  1359. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1360. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1361. if (empty ( $trainKey ) || empty ( $storeKey ))
  1362. die ( 'illegal request-IdKey' );
  1363. $tid = $XDeode->decode ( $trainKey );
  1364. if (! is_numeric ( $tid ) && ! empty ( $storeKey ))
  1365. die ( 'illegal request' );
  1366. Doo::loadModel ( 'invoiceStore' );
  1367. $isidKeyList = explode ( ',', $storeKey );
  1368. $isidList = array ();
  1369. foreach ( $isidKeyList as $value ) {
  1370. $isid = $XDeode->decode ( $value );
  1371. if (! empty ( $isid ) && is_numeric ( $isid ))
  1372. array_push ( $isidList, $isid );
  1373. }
  1374. $isidString = implode ( ',', $isidList );
  1375. $invoiceStore = new invoiceStore ();
  1376. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,apStatus' );
  1377. $isidList = array ();
  1378. foreach ( $isList as $key => $value ) {
  1379. if ($value ['apStatus'] == 0)
  1380. array_push ( $isidList, $value ['isid'] );
  1381. }
  1382. $isidString = implode ( ',', $isidList );
  1383. // print_r($isList);
  1384. // echo $isidString;
  1385. $invoiceStore = new invoiceStore ();
  1386. $invoiceStore->delete ( array (
  1387. 'where' => "isid in ( " . $isidString . ")",
  1388. 'asArray' => TRUE
  1389. ) );
  1390. Doo::loadModel ( 'invoiceTraining' );
  1391. $invoiceTraining = new invoiceTraining ();
  1392. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1393. $item = array (
  1394. 'itid' => $tid,
  1395. 'invoiceTotal' => $itDetail ['invoiceTotal'] - count ( $isidList )
  1396. );
  1397. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1398. // echo $tid;
  1399. // echo $storeKey;
  1400. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1401. }
  1402. /**
  1403. * 仓库发票提交审批
  1404. * @return string
  1405. */
  1406. function invoiceStoreApproval() {
  1407. Doo::loadClass ( 'XDeode' );
  1408. $XDeode = new XDeode ( 5 );
  1409. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1410. $iStoreKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1411. $isid = $XDeode->decode ( $iStoreKey );
  1412. $trainId = $XDeode->decode ( $trainKey );
  1413. if (! is_numeric ( $isid ))
  1414. die ( 'illegal request' );
  1415. Doo::loadModel ( 'invoiceStore' );
  1416. Doo::loadModel ( 'invoice' );
  1417. $invoice = new invoice ();
  1418. // 加入限制必须填写入开票内容和邮寄物品
  1419. $invoiceStore = new invoiceStore ();
  1420. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid, 'isid,trainId ,invoiceElement,mailItemsJson' );
  1421. if (empty ( $isDetail ['invoiceElement'] ) || empty ( $isDetail ['mailItemsJson'] )) {
  1422. header ( 'Content-Type:text/html;charset=utf-8' );
  1423. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1424. }
  1425. // 拷贝插入一条发票数据
  1426. $invoiceStore = new invoiceStore ();
  1427. $iid = $invoiceStore->setInvoiceStoreToApproval ( $isid );
  1428. $invoiceStore = new invoiceStore ();
  1429. $item = array (
  1430. 'isid' => $isid,
  1431. 'iid' => $iid,
  1432. 'apStatus' => 1
  1433. );
  1434. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1435. Doo::loadModel ( 'invoiceManage' );
  1436. $invoiceManage = new invoiceManage ();
  1437. Doo::loadModel ( 'invoiceOperationLog' );
  1438. $invoiceOperationLog = new invoiceOperationLog ();
  1439. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1440. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1441. $moldManage = array ();
  1442. foreach ( $invoiceManageList as $key => $value ) {
  1443. if ($value ['mold'] == '发票打印')
  1444. $moldManage [$value ['mold']] = $value ['staffList'];
  1445. elseif ($value ['mold'] == '发票邮寄')
  1446. $moldManage [$value ['mold']] = $value ['staffList'];
  1447. elseif ($value ['mold'] == '发票退票')
  1448. $moldManage [$value ['mold']] = $value ['staffList'];
  1449. }
  1450. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1451. $item = array (
  1452. 'iid' => $iid,
  1453. 'isid' => $isid,
  1454. 'invoiceSerial' => "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  1455. 'date' => date ( "Y-m-d H:i:s" ),
  1456. 'status' => 1,
  1457. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1458. 'trainId' => $trainId,
  1459. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1460. 'moldManage' => json_encode ( $moldManage ),
  1461. 'settlementType' => 1,
  1462. 'pendingApprovals' => $pendingApprovalsSid
  1463. );
  1464. $invoice->setInvoiceByCondition ( $item );
  1465. Doo::loadModel ( 'invoiceTraining' );
  1466. $invoiceTraining = new invoiceTraining ();
  1467. $item = array (
  1468. 'itid' => $trainId,
  1469. 'submitStatus' => 1
  1470. );
  1471. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1472. $item = array (
  1473. 'date' => date ( "Y-m-d H:i:s" ),
  1474. 'operation' => "创建",
  1475. 'status' => 1,
  1476. 'img' => $this->staff [0] ['avatar'],
  1477. 'username' => $this->staff [0] ['username'],
  1478. 'uid' => $this->staff [0] ['sid'],
  1479. 'category' => $this->staff [0] ['category'],
  1480. 'iid' => $iid
  1481. );
  1482. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1483. $item = array (
  1484. 'date' => date ( "Y-m-d H:i:s" ),
  1485. 'operation' => "提交审批",
  1486. 'status' => 1,
  1487. 'img' => $this->staff [0] ['avatar'],
  1488. 'username' => $this->staff [0] ['username'],
  1489. 'uid' => $this->staff [0] ['sid'],
  1490. 'category' => $this->staff [0] ['category'],
  1491. 'iid' => $iid
  1492. );
  1493. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1494. Doo::loadModel ( 'staff' );
  1495. $staff = new staff ();
  1496. $username2 = $staff->getOne ( array (
  1497. 'select' => 'wxid',
  1498. 'where' => 'sid=' . $pendingApprovalsSid,
  1499. 'asArray' => TRUE
  1500. ) );
  1501. // 发送微信审批通知
  1502. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1503. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1504. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1505. }
  1506. /**
  1507. * 批量提交发票
  1508. * @return string
  1509. */
  1510. function invoiceStoreBatchApproval() {
  1511. Doo::loadClass ( 'XDeode' );
  1512. $XDeode = new XDeode ( 5 );
  1513. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1514. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1515. if (empty ( $trainKey ) || empty ( $storeKey ))
  1516. die ( 'illegal request-IdKey' );
  1517. $trainId = $XDeode->decode ( $trainKey );
  1518. $isidKeyList = explode ( ',', $storeKey );
  1519. $isidList = array ();
  1520. foreach ( $isidKeyList as $value ) {
  1521. $isid = $XDeode->decode ( $value );
  1522. if (! empty ( $isid ) && is_numeric ( $isid ))
  1523. array_push ( $isidList, $isid );
  1524. }
  1525. $isidString = implode ( ',', $isidList );
  1526. if (! is_numeric ( $trainId ))
  1527. die ( 'illegal request' );
  1528. Doo::loadModel ( 'invoiceStore' );
  1529. Doo::loadModel ( 'invoice' );
  1530. // 判断哪些已经加入审批过
  1531. // 加入限制必须填写入开票内容和邮寄物品
  1532. $invoiceStore = new invoiceStore ();
  1533. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,trainId ,invoiceElement,mailItemsJson' );
  1534. foreach ( $isList as $key => $value ) {
  1535. if (empty ( $value ['invoiceElement'] ) || empty ( $value ['mailItemsJson'] )) {
  1536. header ( 'Content-Type:text/html;charset=utf-8' );
  1537. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1538. }
  1539. }
  1540. // 拷贝插入一条发票数据
  1541. $invoiceStore = new invoiceStore ();
  1542. $invoiceStore->setInvoiceStoreBatchToApproval ( $isidString );
  1543. $invoiceStore = new invoiceStore ();
  1544. $item = array (
  1545. 'apStatus' => 1
  1546. );
  1547. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1548. // 获得正式发票ID
  1549. $invoice = new invoice ();
  1550. $iidList = $invoice->getInvoiceByIstoreid ( $isidString, 'iid,isid' );
  1551. $sqlList = array ();
  1552. $iidString = '';
  1553. $iida = array ();
  1554. foreach ( $iidList as $key => $value ) {
  1555. $sqlList [$value ['isid']] = $value ['iid'];
  1556. array_push ( $iida, $value ['iid'] );
  1557. }
  1558. $iidString = implode ( ',', $iida );
  1559. $ids = implode ( ',', array_keys ( $sqlList ) );
  1560. $sql = "UPDATE CLD_invoiceStore SET iid = CASE isid ";
  1561. foreach ( $sqlList as $id => $ordinal ) {
  1562. $sql .= sprintf ( "WHEN %d THEN %d ", $id, $ordinal );
  1563. }
  1564. $sql .= "END WHERE isid IN ($ids)";
  1565. $invoiceStore = new invoiceStore ();
  1566. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1567. Doo::loadModel ( 'invoiceManage' );
  1568. $invoiceManage = new invoiceManage ();
  1569. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1570. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1571. $moldManage = array ();
  1572. foreach ( $invoiceManageList as $key => $value ) {
  1573. if ($value ['mold'] == '发票打印')
  1574. $moldManage [$value ['mold']] = $value ['staffList'];
  1575. elseif ($value ['mold'] == '发票邮寄')
  1576. $moldManage [$value ['mold']] = $value ['staffList'];
  1577. elseif ($value ['mold'] == '发票退票')
  1578. $moldManage [$value ['mold']] = $value ['staffList'];
  1579. }
  1580. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1581. // 批量更新发票信息
  1582. $item = array (
  1583. 'date' => date ( "Y-m-d H:i:s" ),
  1584. 'status' => 1,
  1585. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1586. 'trainId' => $trainId,
  1587. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1588. 'moldManage' => json_encode ( $moldManage ),
  1589. 'settlementType' => 1,
  1590. 'pendingApprovals' => $pendingApprovalsSid
  1591. );
  1592. $invoice = new invoice ();
  1593. $invoice->BatchInvoiceByCondition ( $item, $iidString );
  1594. // 批量更新发票中仓库isid
  1595. $sql = "UPDATE CLD_invoiceStore SET isid = CASE iid ";
  1596. foreach ( $sqlList as $isid => $iid ) {
  1597. $sql .= sprintf ( "WHEN %d THEN %d ", $iid, $isid );
  1598. }
  1599. $sql .= "END WHERE iid IN ($iidString)";
  1600. $invoice = new invoice ();
  1601. $invoice->UpdateBatchInvoice ( $sql );
  1602. // 批量更新发票序列号
  1603. $sqlList = array ();
  1604. foreach ( $iida as $value ) {
  1605. $sqlList [$value] = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1606. }
  1607. $ids = implode ( ',', array_keys ( $sqlList ) );
  1608. $sql = "UPDATE CLD_invoice SET invoiceSerial = CASE iid ";
  1609. foreach ( $sqlList as $id => $ordinal ) {
  1610. $sql .= sprintf ( "WHEN %d THEN '%s' ", $id, $ordinal );
  1611. }
  1612. $sql .= "END WHERE iid IN ($ids)";
  1613. $invoiceStore = new invoiceStore ();
  1614. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1615. // 批量生产操作日志
  1616. Doo::loadModel ( 'invoiceOperationLog' );
  1617. $sqlList = array ();
  1618. foreach ( $iida as $key => $value ) {
  1619. $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 . '"),
  1620. ("' . 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 . '") ';
  1621. array_push ( $sqlList, $sql );
  1622. }
  1623. $iolSql = implode ( ',', $sqlList );
  1624. $sql = "INSERT INTO `CLD_invoiceOperationLog` (`date`, `operation`, `status`, `img`, `username`, `uid`, `category`, `iid`) VALUES " . $iolSql;
  1625. $invoiceOperationLog = new invoiceOperationLog ();
  1626. $invoiceOperationLog->setInvoiceOperationLogBySql ( $sql );
  1627. Doo::loadModel ( 'invoiceTraining' );
  1628. $invoiceTraining = new invoiceTraining ();
  1629. $item = array (
  1630. 'itid' => $trainId,
  1631. 'submitStatus' => 1
  1632. );
  1633. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1634. Doo::loadModel ( 'staff' );
  1635. $staff = new staff ();
  1636. $username2 = $staff->getOne ( array (
  1637. 'select' => 'wxid',
  1638. 'where' => 'sid=' . $pendingApprovalsSid,
  1639. 'asArray' => TRUE
  1640. ) );
  1641. // 发送微信审批通知
  1642. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1643. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1644. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1645. }
  1646. /**
  1647. */
  1648. function invoiceStoreMailItemSet() {
  1649. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1650. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1651. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1652. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1653. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1654. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1655. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1656. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1657. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1658. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1659. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1660. Doo::loadClass ( 'XDeode' );
  1661. $XDeode = new XDeode ( 5 );
  1662. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1663. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1664. $isid = $XDeode->decode ( $storeKey );
  1665. $trainId = $XDeode->decode ( $trainKey );
  1666. if (! is_numeric ( $isid ))
  1667. die ( 'illegal request' );
  1668. Doo::loadModel ( 'invoiceStore' );
  1669. $invoiceStore = new invoiceStore ();
  1670. $mailList = array (
  1671. 'invoice' => 1,
  1672. 'mailItems' => $mailItems
  1673. );
  1674. if (! empty ( $softLock ))
  1675. $mailList += array (
  1676. 'softLock' => $softLockNum
  1677. );
  1678. else
  1679. $mailList += array (
  1680. 'softLock' => 0
  1681. );
  1682. if (! empty ( $contract ))
  1683. $mailList += array (
  1684. 'contract' => $contractNum
  1685. );
  1686. else
  1687. $mailList += array (
  1688. 'contract' => 0
  1689. );
  1690. if (! empty ( $instructions ))
  1691. $mailList += array (
  1692. 'instructions' => $instructionsNum
  1693. );
  1694. else
  1695. $mailList += array (
  1696. 'instructions' => 0
  1697. );
  1698. if (! empty ( $remittance ))
  1699. $mailList += array (
  1700. 'remittance' => $remittance
  1701. );
  1702. else
  1703. $mailList += array (
  1704. 'remittance' => ''
  1705. );
  1706. $mailString = '发票x1,备注:' . $mailItems;
  1707. if (! empty ( $softLock ))
  1708. $mailString .= ',软件锁x' . $softLockNum;
  1709. if (! empty ( $contract ))
  1710. $mailString .= ',合同x' . $contractNum;
  1711. if (! empty ( $instructions ))
  1712. $mailString .= ',说明书x' . $instructionsNum;
  1713. if (! empty ( $remittance ))
  1714. $mailString .= ',汇款账号单';
  1715. $item = array (
  1716. 'isid' => $isid,
  1717. 'doPost' => 1,
  1718. 'mailItems' => $mailString,
  1719. 'mailItemsJson' => json_encode ( $mailList )
  1720. );
  1721. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1722. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1723. }
  1724. /**
  1725. * 批量设置邮寄物品
  1726. */
  1727. function invoiceStoreBatchMailItemSet() {
  1728. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1729. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1730. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1731. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1732. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1733. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1734. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1735. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1736. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1737. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1738. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1739. Doo::loadClass ( 'XDeode' );
  1740. $XDeode = new XDeode ( 5 );
  1741. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1742. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1743. if (empty ( $trainKey ) || empty ( $storeKey ))
  1744. die ( 'illegal request-IdKey' );
  1745. $isidKeyList = explode ( ',', $storeKey );
  1746. $isidList = array ();
  1747. foreach ( $isidKeyList as $value ) {
  1748. $isid = $XDeode->decode ( $value );
  1749. if (! empty ( $isid ) && is_numeric ( $isid ))
  1750. array_push ( $isidList, $isid );
  1751. }
  1752. $isidString = implode ( ',', $isidList );
  1753. $trainId = $XDeode->decode ( $trainKey );
  1754. if (! is_numeric ( $isid ))
  1755. die ( 'illegal request' );
  1756. Doo::loadModel ( 'invoiceStore' );
  1757. $invoiceStore = new invoiceStore ();
  1758. $mailList = array (
  1759. 'invoice' => 1,
  1760. 'mailItems' => $mailItems
  1761. );
  1762. if (! empty ( $softLock ))
  1763. $mailList += array (
  1764. 'softLock' => $softLockNum
  1765. );
  1766. else
  1767. $mailList += array (
  1768. 'softLock' => 0
  1769. );
  1770. if (! empty ( $contract ))
  1771. $mailList += array (
  1772. 'contract' => $contractNum
  1773. );
  1774. else
  1775. $mailList += array (
  1776. 'contract' => 0
  1777. );
  1778. if (! empty ( $instructions ))
  1779. $mailList += array (
  1780. 'instructions' => $instructionsNum
  1781. );
  1782. else
  1783. $mailList += array (
  1784. 'instructions' => 0
  1785. );
  1786. if (! empty ( $remittance ))
  1787. $mailList += array (
  1788. 'remittance' => $remittance
  1789. );
  1790. else
  1791. $mailList += array (
  1792. 'remittance' => ''
  1793. );
  1794. $mailString = '发票x1,备注:' . $mailItems;
  1795. if (! empty ( $softLock ))
  1796. $mailString .= ',软件锁x' . $softLockNum;
  1797. if (! empty ( $contract ))
  1798. $mailString .= ',合同x' . $contractNum;
  1799. if (! empty ( $instructions ))
  1800. $mailString .= ',说明书x' . $instructionsNum;
  1801. if (! empty ( $remittance ))
  1802. $mailString .= ',汇款账号单';
  1803. $item = array (
  1804. 'doPost' => 1,
  1805. 'mailItems' => $mailString,
  1806. 'mailItemsJson' => json_encode ( $mailList )
  1807. );
  1808. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1809. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1810. }
  1811. /**
  1812. * 废弃
  1813. */
  1814. function ajaxGetMailItemByIstore() {
  1815. Doo::loadClass ( 'XDeode' );
  1816. $XDeode = new XDeode ( 5 );
  1817. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1818. $isid = $XDeode->decode ( $storeKey );
  1819. if (! is_numeric ( $isid ))
  1820. die ( 'illegal request' );
  1821. Doo::loadModel ( 'invoiceStore' );
  1822. $invoiceStore = new invoiceStore ();
  1823. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid );
  1824. $isDetail ['mailItemsJson'] = json_decode ( $isDetail ['mailItemsJson'], true );
  1825. echo json_encode ( $isDetail ['mailItemsJson'] );
  1826. exit ();
  1827. }
  1828. /**
  1829. * 终止开票
  1830. */
  1831. function invoiceDroppedDo() {
  1832. $droppedIidKey = $this->get_args ( 'droppedIidKey' ) ? $this->get_args ( 'droppedIidKey' ) : '';
  1833. Doo::loadModel ( 'invoice' );
  1834. $invoice = new invoice ();
  1835. Doo::loadModel ( 'invoiceOperationLog' );
  1836. $invoiceOperationLog = new invoiceOperationLog ();
  1837. $iid = $invoice->authcode ( $droppedIidKey );
  1838. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1839. die ( 'illegal request' );
  1840. $item = array (
  1841. 'iid' => $iid,
  1842. 'status' => 4,
  1843. 'updateTime' => date ( "Y-m-d H:i:s" )
  1844. );
  1845. $invoice->setInvoiceByCondition ( $item );
  1846. $item = array (
  1847. 'date' => date ( "Y-m-d H:i:s" ),
  1848. 'operation' => '终止了开票',
  1849. 'status' => 4,
  1850. 'img' => $this->staff [0] ['avatar'],
  1851. 'username' => $this->staff [0] ['username'],
  1852. 'uid' => $this->staff [0] ['sid'],
  1853. 'category' => $this->staff [0] ['category'],
  1854. 'iid' => $iid
  1855. );
  1856. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1857. return "/invoice";
  1858. }
  1859. /**
  1860. * 更新退票的邮寄信息
  1861. */
  1862. function invoiceUntreadMailDo() {
  1863. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  1864. $untreadCompany = $this->get_args ( 'untreadCompany' ) ? $this->get_args ( 'untreadCompany' ) : "";
  1865. $untreadNumber = $this->get_args ( 'untreadNumber' ) ? $this->get_args ( 'untreadNumber' ) : "";
  1866. $untreadItems = $this->get_args ( 'untreadItems' ) ? $this->get_args ( 'untreadItems' ) : "";
  1867. Doo::loadModel ( 'invoice' );
  1868. $invoice = new invoice ();
  1869. $iid = $invoice->authcode ( $untreadIidKey );
  1870. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1871. die ( 'illegal request' );
  1872. $item = array (
  1873. 'iid' => $iid,
  1874. 'untreadCompany' => $untreadCompany,
  1875. 'untreadNumber' => $untreadNumber,
  1876. 'untreadItems' => $untreadItems
  1877. );
  1878. $invoice->setInvoiceByCondition ( $item );
  1879. return "/invoice";
  1880. }
  1881. /**
  1882. * 申请退票 --
  1883. */
  1884. function invoiceUntreadDo() {
  1885. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  1886. $untreadReason = $this->get_args ( 'untreadReason' ) ? $this->get_args ( 'untreadReason' ) : "";
  1887. $untreadPost = $this->get_args ( 'untreadPost' ) ? $this->get_args ( 'untreadPost' ) : "";
  1888. Doo::loadModel ( 'invoice' );
  1889. $invoice = new invoice ();
  1890. Doo::loadModel ( 'invoiceOperationLog' );
  1891. $invoiceOperationLog = new invoiceOperationLog ();
  1892. Doo::loadModel ( 'invoiceReceivables' );
  1893. $invoiceReceivables = new invoiceReceivables ();
  1894. $iid = $invoice->authcode ( $untreadIidKey );
  1895. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1896. die ( 'illegal request' );
  1897. /*
  1898. * 需求变革 有绑定收款也可以退票 $lt = $invoiceReceivables->getInvoiceReceivablesByIid ( $untreadIidKey ); if (! empty ( $lt )) { header ( 'Content-Type:text/html;charset=utf-8' ); die ( '该发票有收款绑定,请先移除!' ); }
  1899. */
  1900. $item = array (
  1901. 'iid' => $iid,
  1902. 'untreadStatus' => 1,
  1903. 'untreadReason' => $untreadReason,
  1904. 'untreadPost' => $untreadPost,
  1905. 'updateTime' => date ( "Y-m-d H:i:s" )
  1906. );
  1907. $invoice->setInvoiceByCondition ( $item );
  1908. $item = array (
  1909. 'date' => date ( "Y-m-d H:i:s" ),
  1910. 'operation' => '申请退票',
  1911. 'status' => 7,
  1912. 'img' => $this->staff [0] ['avatar'],
  1913. 'username' => $this->staff [0] ['username'],
  1914. 'uid' => $this->staff [0] ['sid'],
  1915. 'category' => $this->staff [0] ['category'],
  1916. 'iid' => $iid
  1917. );
  1918. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1919. return "/invoice";
  1920. }
  1921. /**
  1922. * 删除已终止的开票
  1923. */
  1924. function invoiceDelDo() {
  1925. Doo::loadModel ( 'invoice' );
  1926. $invoice = new invoice ();
  1927. Doo::loadModel ( 'invoiceOperationLog' );
  1928. $invoiceOperationLog = new invoiceOperationLog ();
  1929. Doo::loadClass ( 'XDeode' );
  1930. $XDeode = new XDeode ( 5 );
  1931. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  1932. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  1933. $iid = $XDeode->decode ( $iid );
  1934. Doo::loadModel ( 'invoiceStore' );
  1935. $invoiceStore = new invoiceStore ();
  1936. if (! is_numeric ( $iid ))
  1937. die ( 'illegal request' );
  1938. $invoiceDetail = $invoice->getMyInvoice ( $sid, $iid );
  1939. if (empty ( $invoiceDetail ))
  1940. die ( 'illegal request' );
  1941. $item = array (
  1942. 'iid' => $iid,
  1943. 'isDelete' => 1,
  1944. 'updateTime' => date ( "Y-m-d H:i:s" )
  1945. );
  1946. $invoice->setInvoiceByCondition ( $item );
  1947. $item = array (
  1948. 'date' => date ( "Y-m-d H:i:s" ),
  1949. 'operation' => '删除了已终止的发票',
  1950. 'status' => 4,
  1951. 'img' => $this->staff [0] ['avatar'],
  1952. 'username' => $this->staff [0] ['username'],
  1953. 'uid' => $this->staff [0] ['sid'],
  1954. 'category' => $this->staff [0] ['category'],
  1955. 'iid' => $iid
  1956. );
  1957. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1958. // 删除培训班发票仓库里的发票
  1959. $invoiceStore->delInvoiceStoreByIsid ( $invoiceDetail ['isid'] );
  1960. return "/invoice";
  1961. }
  1962. /**
  1963. */
  1964. function invoiceApproval() {
  1965. Doo::loadModel ( 'invoice' );
  1966. $invoice = new invoice ();
  1967. Doo::loadClass ( 'XDeode' );
  1968. $XDeode = new XDeode ( 5 );
  1969. Doo::loadModel ( 'staff' );
  1970. $staff = new staff ();
  1971. $invoiceList = $invoice->find ( array (
  1972. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  1973. 'desc' => 'iid',
  1974. 'limit' => 10,
  1975. 'asArray' => true
  1976. ) );
  1977. foreach ( $invoiceList as $key => $value ) {
  1978. $invoiceList [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1979. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1980. if (! empty ( $lastApprover )) {
  1981. $lastApproverKey = array_keys ( $lastApprover );
  1982. $lastApprover = end ( $lastApprover );
  1983. $staffDetail = $staff->getOne ( array (
  1984. 'where' => 'sid=' . end ( $lastApproverKey ),
  1985. 'asArray' => true
  1986. ) );
  1987. $lastApprover ['username'] = $staffDetail ['username'];
  1988. }
  1989. $invoiceList [$key] ['lastApprover'] = $lastApprover;
  1990. }
  1991. $ilist = $invoice->getInvoiceByProcessStatus ();
  1992. foreach ( $ilist as $key => $value ) {
  1993. $ilist [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1994. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1995. if (! empty ( $lastApprover )) {
  1996. $lastApproverKey = array_keys ( $lastApprover );
  1997. $lastApprover = end ( $lastApprover );
  1998. $staffDetail = $staff->getOne ( array (
  1999. 'where' => 'sid=' . end ( $lastApproverKey ),
  2000. 'asArray' => true
  2001. ) );
  2002. $lastApprover ['username'] = $staffDetail ['username'];
  2003. }
  2004. $ilist [$key] ['lastApprover'] = $lastApprover;
  2005. }
  2006. // print_r($ilist);
  2007. $this->data ['invoiceList'] = $invoiceList;
  2008. $this->data ['ilist'] = $ilist;
  2009. $this->data ['memu'] = "invoice";
  2010. $this->data ['staff'] = $this->staff;
  2011. $this->data ['receiptMemu'] = 'invoiceApproval';
  2012. $this->render ( "/admin/invoiceApproval", $this->data );
  2013. }
  2014. function invoiceDetail() {
  2015. Doo::loadClass ( 'XDeode' );
  2016. $XDeode = new XDeode ( 5 );
  2017. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  2018. $iid = $XDeode->decode ( $iid );
  2019. if (! is_numeric ( $iid ))
  2020. die ( 'illegal request' );
  2021. Doo::loadModel ( 'invoice' );
  2022. $invoice = new invoice ();
  2023. Doo::loadModel ( 'invoiceOperationLog' );
  2024. $invoiceOperationLog = new invoiceOperationLog ();
  2025. $invoiceDetail = $invoice->getOne ( array (
  2026. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'] . ' and iid=' . $iid,
  2027. 'asArray' => true
  2028. ) );
  2029. if (empty ( $invoiceDetail ))
  2030. die ( 'illegal request' );
  2031. if ($invoiceDetail ['settlementType'] == 1) {
  2032. Doo::loadModel ( 'invoiceTraining' );
  2033. $invoiceTraining = new invoiceTraining ();
  2034. $invoiceDetail ['invoiceTraining'] = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceDetail ['trainId'] );
  2035. }
  2036. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  2037. $this->data ['invoiceDetail'] = $invoiceDetail;
  2038. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  2039. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  2040. $this->data ['memu'] = "invoice";
  2041. $this->data ['staff'] = $this->staff;
  2042. $this->data ['receiptMemu'] = 'invoiceApproval';
  2043. $this->render ( "/admin/invoiceApprovalDetail", $this->data );
  2044. }
  2045. /**
  2046. * 对发票进行审批,其中操作有终止,退回,同意动作。操作成功并记录下操作日志
  2047. *
  2048. * @since 1.0.0
  2049. * @var integer iid 开票ID 已加密
  2050. * @var integer status 发票审批状态
  2051. * @var integer opintion 审批发票的意见
  2052. * @return string 如操作成功返回审批首页
  2053. */
  2054. function invoiceApprovalDo() {
  2055. Doo::loadModel ( 'invoice' );
  2056. $invoice = new invoice ();
  2057. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2058. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  2059. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  2060. $divApproval = $this->get_args ( 'divApproval' ) ? $this->get_args ( 'divApproval' ) : "";
  2061. $iid = $invoice->authcode ( $iid );
  2062. if (! is_numeric ( $iid ))
  2063. die ( 'illegal request' );
  2064. // && ! empty ( $opinion )
  2065. if (! empty ( $iid ) && ! empty ( $status )) {
  2066. if (! ($status == 2 || $status == 3 || $status == 4))
  2067. die ( 'illegal request' );
  2068. Doo::loadModel ( 'invoiceOperationLog' );
  2069. $invoiceOperationLog = new invoiceOperationLog ();
  2070. $invoiceDetail = $invoice->getOne ( array (
  2071. 'where' => 'status=1 and iid=' . $iid . ' and pendingApprovals=' . $this->staff [0] ['sid'],
  2072. 'asArray' => true
  2073. ) );
  2074. if (empty ( $invoiceDetail ))
  2075. die ( 'illegal request' );
  2076. $processApprovals = json_decode ( $invoiceDetail ['processApprovals'], true );
  2077. $invoiceManage = json_decode ( $invoiceDetail ['invoiceManage'], true );
  2078. if ($status == 3) {
  2079. $invoice->status = $status;
  2080. $item = array (
  2081. 'operation' => $opinion
  2082. );
  2083. } else {
  2084. if (empty ( $processApprovals )) {
  2085. $processApprovals = array (
  2086. $this->staff [0] ['sid'] => array (
  2087. 'date' => date ( "Y-m-d H:i:s" ),
  2088. 'opinion' => $opinion,
  2089. 'status' => $status
  2090. )
  2091. );
  2092. // var_dump(next($invoiceManage));
  2093. $nextInvoiceManage = next ( $invoiceManage );
  2094. // print_r($nextInvoiceManage);
  2095. if ($status != 4 && $nextInvoiceManage !== false)
  2096. $invoice->pendingApprovals = $nextInvoiceManage [0];
  2097. $invoice->processApprovals = json_encode ( $processApprovals );
  2098. // var_dump($invoice);
  2099. // print_r($invoiceManage);
  2100. } else {
  2101. $processApprovals [$this->staff [0] ['sid']] = array (
  2102. 'date' => date ( "Y-m-d H:i:s" ),
  2103. 'opinion' => $opinion,
  2104. 'status' => $status
  2105. );
  2106. $pendingApprovals = 0;
  2107. foreach ( $invoiceManage as $key => $value ) {
  2108. if ($value [0] == $this->staff [0] ['sid']) {
  2109. if (isset ( $invoiceManage [$key + 1] ))
  2110. $pendingApprovals = $invoiceManage [$key + 1] [0];
  2111. break;
  2112. }
  2113. }
  2114. if ($status != 4 && ! empty ( $pendingApprovals ))
  2115. $invoice->pendingApprovals = $pendingApprovals;
  2116. $invoice->processApprovals = json_encode ( $processApprovals );
  2117. }
  2118. $item = array (
  2119. 'operation' => $opinion
  2120. );
  2121. if (count ( $processApprovals ) == count ( $invoiceManage ) && $status != 4) {
  2122. $invoice->status = $status;
  2123. $invoice->pendingApprovals = 0;
  2124. $invoice->approvalTime = date ( "Y-m-d H:i:s" );
  2125. } elseif ($status == 4) {
  2126. $invoice->status = $status;
  2127. $item = array (
  2128. 'operation' => $opinion
  2129. );
  2130. }
  2131. }
  2132. $invoice->updateTime = date ( "Y-m-d H:i:s" );
  2133. $invoice->update ( array (
  2134. 'where' => 'iid=' . $iid
  2135. ) );
  2136. $item += array (
  2137. 'date' => date ( "Y-m-d H:i:s" ),
  2138. 'img' => $this->staff [0] ['avatar'],
  2139. 'username' => $this->staff [0] ['username'],
  2140. 'uid' => $this->staff [0] ['sid'],
  2141. 'category' => $this->staff [0] ['category'],
  2142. 'status' => $status,
  2143. 'iid' => $iid
  2144. );
  2145. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2146. if (empty ( $divApproval ))
  2147. return '/invoiceApproval';
  2148. else
  2149. return '/invoiceApprovalAchieve/PEND';
  2150. }
  2151. die ( 'illegal request' );
  2152. }
  2153. /**
  2154. * 展示需要打印的发票数据
  2155. *
  2156. * @since 1.0.0
  2157. */
  2158. function invoicePrint() {
  2159. Doo::loadModel ( 'invoice' );
  2160. $invoice = new invoice ();
  2161. Doo::loadClass ( 'XDeode' );
  2162. $XDeode = new XDeode ( 5 );
  2163. Doo::loadModel ( 'staff' );
  2164. $staff = new staff ();
  2165. $toPrint = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0 );
  2166. $printed = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 1 );
  2167. foreach ( $toPrint as $key => $value ) {
  2168. $toPrint [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2169. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2170. if (! empty ( $lastApprover )) {
  2171. $lastApproverKey = array_keys ( $lastApprover );
  2172. $lastApprover = end ( $lastApprover );
  2173. $staffDetail = $staff->getOne ( array (
  2174. 'where' => 'sid=' . end ( $lastApproverKey ),
  2175. 'asArray' => true
  2176. ) );
  2177. $lastApprover ['username'] = $staffDetail ['username'];
  2178. }
  2179. $toPrint [$key] ['lastApprover'] = $lastApprover;
  2180. }
  2181. foreach ( $printed as $key => $value ) {
  2182. $printed [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2183. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2184. if (! empty ( $lastApprover )) {
  2185. $lastApproverKey = array_keys ( $lastApprover );
  2186. $lastApprover = end ( $lastApprover );
  2187. $staffDetail = $staff->getOne ( array (
  2188. 'where' => 'sid=' . end ( $lastApproverKey ),
  2189. 'asArray' => true
  2190. ) );
  2191. $lastApprover ['username'] = $staffDetail ['username'];
  2192. }
  2193. $printed [$key] ['lastApprover'] = $lastApprover;
  2194. }
  2195. $this->data ['printed'] = $printed;
  2196. $this->data ['toPrint'] = $toPrint;
  2197. $this->data ['memu'] = "invoice";
  2198. $this->data ['staff'] = $this->staff;
  2199. $this->data ['receiptMemu'] = 'invoicePrint';
  2200. $this->render ( "/admin/invoicePrint", $this->data );
  2201. }
  2202. /**
  2203. * 展示发票打印的详情页面
  2204. *
  2205. * @since 1.0.0
  2206. */
  2207. function invoicePrintDetail() {
  2208. Doo::loadClass ( 'XDeode' );
  2209. $XDeode = new XDeode ( 5 );
  2210. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  2211. $iid = $XDeode->decode ( $iid );
  2212. if (! is_numeric ( $iid ))
  2213. die ( 'illegal request' );
  2214. Doo::loadModel ( 'invoice' );
  2215. $invoice = new invoice ();
  2216. Doo::loadModel ( 'invoiceOperationLog' );
  2217. $invoiceOperationLog = new invoiceOperationLog ();
  2218. Doo::loadModel ( 'invoicePaper' );
  2219. $invoicePaper = new invoicePaper ();
  2220. $invoiceDetail = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0, $iid );
  2221. if (empty ( $invoiceDetail ))
  2222. die ( 'illegal request' );
  2223. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $invoiceDetail ['invoiceType'] );
  2224. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  2225. if ($invoiceDetail ['settlementType'] == 1) {
  2226. Doo::loadModel ( 'invoiceTraining' );
  2227. $invoiceTraining = new invoiceTraining ();
  2228. $invoiceDetail ['invoiceTraining'] = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceDetail ['trainId'] );
  2229. }
  2230. $this->data ['invoicePaperList'] = $invoicePaperList;
  2231. $this->data ['invoiceDetail'] = $invoiceDetail;
  2232. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  2233. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  2234. $this->data ['memu'] = "invoice";
  2235. $this->data ['staff'] = $this->staff;
  2236. $this->data ['receiptMemu'] = 'invoicePrint';
  2237. $this->render ( "/admin/invoicePrintDetail", $this->data );
  2238. }
  2239. /**
  2240. * 所有待打印 发票
  2241. */
  2242. function invoicePrintStayAchieve() {
  2243. Doo::loadModel ( 'invoice' );
  2244. $invoice = new invoice ();
  2245. Doo::loadClass ( 'XDeode' );
  2246. $XDeode = new XDeode ( 5 );
  2247. Doo::loadModel ( 'staff' );
  2248. $staff = new staff ();
  2249. $MebSea = $this->get_args ( 'MebSea' ) ? urldecode ( $this->get_args ( 'MebSea' ) ) : "";
  2250. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  2251. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  2252. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  2253. Doo::loadModel ( 'invoiceTraining' );
  2254. $invoiceTraining = new invoiceTraining ();
  2255. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  2256. $page_size = 12;
  2257. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2258. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : "ALL";
  2259. // $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : "ALL";
  2260. $get = "/" . $status;
  2261. $con = ' and status=2 ';
  2262. if ($status == 'TOPRINT')
  2263. $con = ' and status=2 and printStatus=0 ';
  2264. elseif ($status == 'PRINTED')
  2265. $con = ' and status=2 and printStatus=1';
  2266. if ($invoiceType == 'ORDINARY')
  2267. $con .= ' and invoiceType=0 ';
  2268. elseif ($invoiceType == 'SPECIAL')
  2269. $con .= ' and invoiceType=1 ';
  2270. if ($invoiceTrain == 'ORDINARY')
  2271. $con .= ' and trainId=0 ';
  2272. elseif ($invoiceTrain == 'TRAIN')
  2273. $con .= ' and trainId!=0 ';
  2274. if ($invoiceTrainName != 'ALL') {
  2275. $trainId = $XDeode->decode ( $invoiceTrainName );
  2276. if (is_numeric ( $trainId ))
  2277. $con .= ' and trainId =' . $trainId;
  2278. }
  2279. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2280. $dateArr = explode ( ':', $date );
  2281. $D1 = '';
  2282. $D2 = '';
  2283. if (! empty ( $date )) {
  2284. $D1 = $dateArr [0];
  2285. $D2 = $dateArr [1];
  2286. }
  2287. if (! empty ( $D1 ) && ! empty ( $D2 ) && ! empty ( $date ))
  2288. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2289. if (! empty ( $MebSea )) {
  2290. $con .= ' and ( invoiceNo like "%' . $MebSea . '%" or invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  2291. }
  2292. $pageinfo ['page'] = array (
  2293. 'previous' => ''
  2294. );
  2295. $get .= "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&invoiceType=" . urlencode ( $invoiceType ) . "&invoiceTrain=" . urlencode ( $invoiceTrain ) . "";
  2296. $sql = " (untreadStatus=0 or untreadStatus=3) and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  2297. $action = "invoicePrintStayAchieve";
  2298. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2299. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2300. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  2301. $this->data ['trainList'] = $trainList;
  2302. $this->data ['invoiceType'] = $invoiceType;
  2303. $this->data ['invoiceTrain'] = $invoiceTrain;
  2304. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  2305. $this->data ['MebSeaEn'] = $MebSea;
  2306. $this->data ['MebSea'] = urlencode ( $MebSea );
  2307. $this->data ['get'] = $get;
  2308. $this->data ['page'] = $pageinfo;
  2309. $this->data ['date'] = $date;
  2310. $this->data ['status'] = $status;
  2311. $this->data ['invoiceType'] = $invoiceType;
  2312. $this->data ['memu'] = "invoice";
  2313. $this->data ['staff'] = $this->staff;
  2314. foreach ( $list as $key => $value ) {
  2315. $list [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2316. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2317. if (! empty ( $lastApprover )) {
  2318. $lastApproverKey = array_keys ( $lastApprover );
  2319. $lastApprover = end ( $lastApprover );
  2320. $staffDetail = $staff->getOne ( array (
  2321. 'where' => 'sid=' . end ( $lastApproverKey ),
  2322. 'asArray' => true
  2323. ) );
  2324. $lastApprover ['username'] = $staffDetail ['username'];
  2325. }
  2326. $list [$key] ['lastApprover'] = $lastApprover;
  2327. }
  2328. $this->data ['receiptMemu'] = 'invoicePrint';
  2329. $this->data ['list'] = $list;
  2330. $this->render ( "/admin/invoicePrintStayAchieve", $this->data );
  2331. }
  2332. /**
  2333. * 填写票号并完成打印
  2334. * @since 1.0.0
  2335. */
  2336. function invoicePrintDo() {
  2337. Doo::loadModel ( 'invoice' );
  2338. $invoice = new invoice ();
  2339. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2340. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  2341. $invoicePrintType = $this->get_args ( 'invoicePrintType' ) ? $this->get_args ( 'invoicePrintType' ) : "";
  2342. $iid = $invoice->authcode ( $iid );
  2343. if (! is_numeric ( $iid ))
  2344. die ( 'illegal request' );
  2345. if (! empty ( $iid ) && ! empty ( $invoiceNo )) {
  2346. Doo::loadModel ( 'invoiceOperationLog' );
  2347. $invoiceOperationLog = new invoiceOperationLog ();
  2348. Doo::loadModel ( 'invoiceStatistics' );
  2349. $invoiceStatistics = new invoiceStatistics ();
  2350. $XDeode = new XDeode ( 5 );
  2351. Doo::loadModel ( 'invoicePaper' );
  2352. $invoicePaper = new invoicePaper ();
  2353. $invoicePrintDetail = $invoice->getInvoiceByPrint ( $iid );
  2354. if (empty ( $invoicePrintDetail ))
  2355. die ( 'illegal request' );
  2356. //
  2357. $ipid = $XDeode->decode ( $invoiceNo );
  2358. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  2359. if (empty ( $paperDetail ))
  2360. die ( 'illegal request' );
  2361. $invoicePaper = new invoicePaper ();
  2362. $item = array (
  2363. 'iid' => $iid,
  2364. 'ipid' => $ipid
  2365. );
  2366. $invoicePaper->setInvoicePaperByCondition ( $item );
  2367. $item = array (
  2368. 'iid' => $iid,
  2369. 'printStatus' => 1,
  2370. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2371. 'printer' => $this->staff [0] ['username'],
  2372. 'printTime' => date ( "Y-m-d H:i:s" ),
  2373. 'invoiceNo' => $paperDetail ['invoiceNo']
  2374. );
  2375. $invoice->setInvoiceByCondition ( $item );
  2376. $item = array (
  2377. 'date' => date ( "Y-m-d H:i:s" ),
  2378. 'operation' => '打印发票号:' . $paperDetail ['invoiceNo'],
  2379. 'status' => 5,
  2380. 'img' => $this->staff [0] ['avatar'],
  2381. 'username' => $this->staff [0] ['username'],
  2382. 'uid' => $this->staff [0] ['sid'],
  2383. 'category' => $this->staff [0] ['category'],
  2384. 'iid' => $iid
  2385. );
  2386. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2387. // 去统计--负票不汇总
  2388. if ($invoicePrintDetail ['untreadStatus'] != 4) {
  2389. $item = array (
  2390. 'date' => date ( "Y-m-d H:i:s" ),
  2391. 'priceClass' => 1,
  2392. 'cid' => $invoicePrintDetail ['cid'],
  2393. 'staff' => $invoicePrintDetail ['sid'],
  2394. 'invoicePrice' => $invoicePrintDetail ['invoicePrice']
  2395. );
  2396. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2397. }
  2398. // 发送通知信息到微信-去除
  2399. // $this->setWXMsg($iid,'PRINT');
  2400. // 发票信息库
  2401. $this->autoUpdateInvoiceInfoBase ( $invoicePrintDetail );
  2402. // 申请人获取微信通知
  2403. Doo::loadModel ( 'staff' );
  2404. $staff = new staff ();
  2405. Doo::loadClass ( 'XDeode' );
  2406. $XDeode = new XDeode ( 5 );
  2407. $username2 = $staff->getOne ( array (
  2408. 'select' => 'wxid',
  2409. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2410. 'asArray' => TRUE
  2411. ) );
  2412. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '完成打印';
  2413. $msg = '';
  2414. $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/' . $XDeode->encode ( $invoicePrintDetail ['iid'] ) . '.html';
  2415. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2416. if (empty ( $invoicePrintType ))
  2417. return "/invoicePrint";
  2418. else
  2419. return "/invoicePrintStayAchieve";
  2420. }
  2421. }
  2422. /**
  2423. * 需要邮寄的发票
  2424. * @since 1.0.0
  2425. */
  2426. function invoicePost() {
  2427. Doo::loadModel ( 'invoice' );
  2428. $invoice = new invoice ();
  2429. Doo::loadModel ( 'express' );
  2430. $express = new express ();
  2431. $invoicePost = $invoice->getPostByInvoice ();
  2432. $invoicePosted = $invoice->getPostByInvoice ( 1 );
  2433. $expressList = $express->getExpressByAll ();
  2434. $invoicePostExpress = "";
  2435. if (isset ( $_COOKIE ["invoicePostExpress"] ))
  2436. $invoicePostExpress = $_COOKIE ["invoicePostExpress"];
  2437. $this->data ['invoicePostExpress'] = $invoicePostExpress;
  2438. $this->data ['expressList'] = $expressList;
  2439. $this->data ['invoicePost'] = $invoicePost;
  2440. $this->data ['invoicePosted'] = $invoicePosted;
  2441. $this->data ['memu'] = "invoice";
  2442. $this->data ['staff'] = $this->staff;
  2443. $this->data ['receiptMemu'] = 'invoicePost';
  2444. $this->render ( "/admin/invoicePost", $this->data );
  2445. }
  2446. /**
  2447. * 添加发票邮寄信息
  2448. */
  2449. function invoiceExpressAddDo() {
  2450. Doo::loadModel ( 'invoice' );
  2451. $invoice = new invoice ();
  2452. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2453. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2454. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2455. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2456. $iid = $iid = $invoice->authcode ( $iid );
  2457. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2458. die ( 'illegal request' );
  2459. $invoicePrintDetail = $invoice->getInvoiceByIid ( $iid );
  2460. setcookie ( 'invoicePostExpress', $expressNumber );
  2461. $item = array (
  2462. 'iid' => $iid,
  2463. 'postStatus' => 1,
  2464. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2465. 'postTime' => date ( "Y-m-d H:i:s" ),
  2466. 'expressCompany' => $expressCompany,
  2467. 'expressNumber' => $expressNumber,
  2468. 'actualItems' => $actualItems,
  2469. 'poster' => $this->staff [0] ['username']
  2470. );
  2471. $invoice->setInvoiceByCondition ( $item );
  2472. // 微信通知-去掉
  2473. // $this->setWXMsg ( $iid );
  2474. Doo::loadModel ( 'staff' );
  2475. $staff = new staff ();
  2476. Doo::loadClass ( 'XDeode' );
  2477. $XDeode = new XDeode ( 5 );
  2478. $username2 = $staff->getOne ( array (
  2479. 'select' => 'wxid',
  2480. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2481. 'asArray' => TRUE
  2482. ) );
  2483. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '已邮寄';
  2484. $expCom = explode ( ":", $invoicePrintDetail ['expressCompany'] );
  2485. if (empty ( $expCom ))
  2486. $expCom [0] = '';
  2487. $msg = $expCom [0] . ':' . $invoicePrintDetail ['expressNumber'] . '';
  2488. $url = 'https://m.kuaidi100.com/result.jsp?nu=' . $invoicePrintDetail ['expressNumber'];
  2489. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2490. return '/invoicePost';
  2491. }
  2492. function invoiceExpressUpdateDo() {
  2493. Doo::loadModel ( 'invoice' );
  2494. $invoice = new invoice ();
  2495. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  2496. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2497. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2498. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2499. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2500. $iid = $invoice->authcode ( $iid );
  2501. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2502. die ( 'illegal request' );
  2503. $item = array (
  2504. 'iid' => $iid,
  2505. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2506. 'expressCompany' => $expressCompany,
  2507. 'expressNumber' => $expressNumber,
  2508. 'actualItems' => $actualItems,
  2509. 'poster' => $this->staff [0] ['username']
  2510. );
  2511. $invoice->setInvoiceByCondition ( $item );
  2512. return $action;
  2513. }
  2514. /**
  2515. * 可退票管理
  2516. */
  2517. function invoiceUntreadIsAchieve() {
  2518. Doo::loadModel ( 'invoice' );
  2519. $invoice = new invoice ();
  2520. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2521. /*
  2522. * 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' => '' );
  2523. */
  2524. if (empty ( $MebSea )) {//
  2525. $con = ' and invoiceNo like "NULL" ';
  2526. } else {
  2527. $con = ' and (invoiceNo like "%' . $MebSea . '%" or invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  2528. }
  2529. // printStatus=1 and
  2530. $sql = " (untreadStatus=0 or untreadStatus=3) and status=2 and sid=" . $this->staff [0] ['sid'] . $con;
  2531. /*
  2532. * $action = "invoiceUntreadIsAchieve"; $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" ); $limit = $pageinfo ['lower'] . ',' . $page_size;
  2533. */
  2534. $limit = '0,20';
  2535. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2536. // print_r($list);
  2537. $this->data ['MebSeaEn'] = $MebSea;
  2538. /*
  2539. * $this->data ['get'] = $get; $this->data ['page'] = $pageinfo; $this->data ['date'] = $date;
  2540. */
  2541. $this->data ['list'] = $list;
  2542. $this->data ['memu'] = "invoice";
  2543. $this->data ['staff'] = $this->staff;
  2544. $this->data ['receiptMemu'] = 'invoice';
  2545. $this->render ( "/admin/invoiceUntreadIsAchieve", $this->data );
  2546. }
  2547. // 已经退票的发票
  2548. function invoiceUntreadED() {
  2549. Doo::loadModel ( 'invoice' );
  2550. $invoice = new invoice ();
  2551. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2552. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "";
  2553. Doo::loadClass ( 'XDeode' );
  2554. $XDeode = new XDeode ( 5 );
  2555. $page_size = 18;
  2556. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2557. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2558. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  2559. $dateArr = explode ( ':', $date );
  2560. $D1 = '';
  2561. $D2 = '';
  2562. if (! empty ( $date )) {
  2563. $D1 = $dateArr [0];
  2564. $D2 = $dateArr [1];
  2565. }
  2566. $con = '';
  2567. if (! empty ( $D1 ) && ! empty ( $D2 )) {
  2568. $con = ' and bindTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2569. }
  2570. // if ($date == 'MONTHO')
  2571. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  2572. // elseif ($date == 'MONTHT')
  2573. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  2574. // elseif ($date == 'MONTHY')
  2575. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  2576. if (! empty ( $MebSea )) {
  2577. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  2578. }
  2579. if ($invoiceType == 'ORDINARY') {
  2580. $con .= ' and invoiceType=0 ';
  2581. } elseif ($invoiceType == 'SPECIAL') {
  2582. $con .= ' and invoiceType=1 ';
  2583. }
  2584. $pageinfo ['page'] = array (
  2585. 'previous' => ''
  2586. );
  2587. // printStatus=1 and
  2588. $sql = " (untreadStatus=2 ) and status=2 and sid=" . $this->staff [0] ['sid'] . $con;
  2589. $action = "invoiceUntreadED";
  2590. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2591. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2592. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2593. // print_r($list);
  2594. $this->data ['MebSeaEn'] = $MebSea;
  2595. $this->data ['get'] = $get;
  2596. $this->data ['page'] = $pageinfo;
  2597. $this->data ['date'] = $date;
  2598. $this->data ['invoiceType'] = $invoiceType;
  2599. $this->data ['list'] = $list;
  2600. $this->data ['memu'] = "invoice";
  2601. $this->data ['staff'] = $this->staff;
  2602. $this->data ['receiptMemu'] = 'invoice';
  2603. $this->render ( "/admin/invoiceUntreadED", $this->data );
  2604. }
  2605. /**
  2606. * 退票处理页面
  2607. */
  2608. function invoiceUntread() {
  2609. Doo::loadModel ( 'invoice' );
  2610. $invoice = new invoice ();
  2611. $untreadInvoice = $invoice->getInvoiceByUntreadStatus ( 1, 0, 50 );
  2612. $establishedInvoice = $invoice->getInvoiceByUntreadStatus ( 2 );
  2613. foreach ( $establishedInvoice as $key => $value ) {
  2614. // months
  2615. $lossDate = strtotime ( "+1 month", strtotime ( $value ['OperationLog'] ['date'] ) );
  2616. $nowDate = strtotime ( 'now' );
  2617. $establishedInvoice [$key] ['lossShow'] = false;
  2618. if ($lossDate < $nowDate)
  2619. $establishedInvoice [$key] ['lossShow'] = true;
  2620. }
  2621. $this->data ['untreadInvoice'] = $untreadInvoice;
  2622. $this->data ['establishedInvoice'] = $establishedInvoice;
  2623. $this->data ['memu'] = "invoice";
  2624. $this->data ['staff'] = $this->staff;
  2625. $this->data ['receiptMemu'] = 'invoiceUntread';
  2626. $this->render ( "/admin/invoiceUntread", $this->data );
  2627. }
  2628. /**
  2629. * 确认收到退回的发票,开票状态为退回 //收款状态解绑,公司统计扣除入账额度
  2630. */
  2631. function invoiceUntreadEstablishedDo() {
  2632. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  2633. Doo::loadModel ( 'invoice' );
  2634. $invoice = new invoice ();
  2635. Doo::loadModel ( 'invoiceOperationLog' );
  2636. $invoiceOperationLog = new invoiceOperationLog ();
  2637. Doo::loadModel ( 'invoiceReceivables' );
  2638. Doo::loadModel ( 'invoiceStatistics' );
  2639. $iid = $invoice->authcode ( $untreadIidKey );
  2640. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2641. die ( 'illegal request' );
  2642. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  2643. if ($invoiceDetails ['untreadStatus'] != 1)
  2644. die ( 'illegal request' );
  2645. $item = array (
  2646. 'iid' => $iid,
  2647. // 'irid'=>'',
  2648. 'untreadStatus' => 2,
  2649. 'updateTime' => date ( "Y-m-d H:i:s" )
  2650. );
  2651. $invoice->setInvoiceByCondition ( $item );
  2652. $item = array (
  2653. 'date' => date ( "Y-m-d H:i:s" ),
  2654. 'operation' => '已确认退票',
  2655. 'status' => 6,
  2656. 'img' => $this->staff [0] ['avatar'],
  2657. 'username' => $this->staff [0] ['username'],
  2658. 'uid' => $this->staff [0] ['sid'],
  2659. 'category' => $this->staff [0] ['category'],
  2660. 'iid' => $iid
  2661. );
  2662. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2663. // 收款解绑以及入账扣除 收款扣除
  2664. if (! empty ( $invoiceDetails ['irid'] )) {
  2665. $iridList = explode ( ',', $invoiceDetails ['irid'] );
  2666. foreach ( $iridList as $value ) {
  2667. $invoiceReceivables = new invoiceReceivables ();
  2668. $irDetails = $invoiceReceivables->getOne ( array (
  2669. 'where' => " irid=" . $value . ' and bindStatus=1',
  2670. 'asArray' => TRUE
  2671. ) );
  2672. $item = array (
  2673. 'irid' => $value,
  2674. 'bindStatus' => 0,
  2675. 'untreadStatus' => 1,
  2676. 'untreadStaff' => $invoiceDetails ['userName'],
  2677. 'unbundlingTime' => date ( "Y-m-d H:i:s" ),
  2678. 'iid' => 0
  2679. );
  2680. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2681. if (! empty ( $irDetails )) {
  2682. // 扣除入账
  2683. $invoiceStatistics = new invoiceStatistics ();
  2684. $item = array (
  2685. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2686. 'priceClass' => 3,
  2687. 'cid' => $invoiceDetails ['cid'],
  2688. 'staff' => $invoiceDetails ['sid'],
  2689. 'accountPrice' => - $irDetails ['receivablesPrice']
  2690. );
  2691. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2692. // 扣除收款
  2693. $invoiceStatistics = new invoiceStatistics ();
  2694. $item = array (
  2695. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2696. 'priceClass' => 2,
  2697. 'cid' => $invoiceDetails ['cid'],
  2698. 'staff' => $invoiceDetails ['sid'],
  2699. 'irid' => $irDetails ['irid'],
  2700. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  2701. );
  2702. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2703. }
  2704. // 解绑时删除收入流水
  2705. Doo::loadModel ( 'wasteBook' );
  2706. $wasteBook = new wasteBook ();
  2707. $wasteBook->delete ( array (
  2708. 'where' => 'dataID=' . $value . ' and accountType=7',
  2709. 'limit' => 1
  2710. ) );
  2711. }
  2712. }
  2713. return "/invoiceUntread";
  2714. }
  2715. function invoiceUntreadRecallDo() {
  2716. $iidKey = isset ( $this->params ['iidKey'] ) ? $this->params ['iidKey'] : "";
  2717. Doo::loadModel ( 'invoice' );
  2718. $invoice = new invoice ();
  2719. Doo::loadClass ( 'XDeode' );
  2720. $XDeode = new XDeode ( 5 );
  2721. Doo::loadModel ( 'invoiceOperationLog' );
  2722. $invoiceOperationLog = new invoiceOperationLog ();
  2723. $iid = $XDeode->decode ( $iidKey );
  2724. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  2725. if (empty ( $invoiceDetail )) {
  2726. die ( 'illegal request-DATANULL' );
  2727. }
  2728. $item = array (
  2729. 'iid' => $iid,
  2730. 'untreadStatus' => 0
  2731. );
  2732. $invoice->setInvoiceByCondition ( $item );
  2733. $item = array (
  2734. 'date' => date ( "Y-m-d H:i:s" ),
  2735. 'operation' => '撤回申请退票',
  2736. 'status' => 13,
  2737. 'img' => $this->staff [0] ['avatar'],
  2738. 'username' => $this->staff [0] ['username'],
  2739. 'uid' => $this->staff [0] ['sid'],
  2740. 'category' => $this->staff [0] ['category'],
  2741. 'iid' => $iid
  2742. );
  2743. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2744. return "/invoiceUntread";
  2745. }
  2746. /**
  2747. * 建立负票,关联原来发票
  2748. */
  2749. function invoiceLossDo() {
  2750. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2751. if (! empty ( $iidKey )) {
  2752. Doo::loadClass ( 'XDeode' );
  2753. $XDeode = new XDeode ( 5 );
  2754. Doo::loadModel ( 'invoice' );
  2755. $invoice = new invoice ();
  2756. Doo::loadModel ( 'invoiceOperationLog' );
  2757. $invoiceOperationLog = new invoiceOperationLog ();
  2758. $iidKey = $XDeode->decode ( $iidKey );
  2759. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  2760. // 拷贝插入一条发票数据
  2761. $iid = $invoice->setInvoiceLoss ( $iidKey );
  2762. // 更新负票
  2763. $invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  2764. $invoice = new invoice ();
  2765. $item = array (
  2766. 'iid' => $iid,
  2767. 'sid' => $this->staff [0] ['sid'],
  2768. 'userName' => $this->staff [0] ['username'],
  2769. 'cid' => $this->staff [0] ['cid'],
  2770. 'categoryName' => $this->staff [0] ['category'],
  2771. 'invoiceQuantity' => - $invoiceDetail ['invoiceQuantity'],
  2772. 'invoicePrice' => - $invoiceDetail ['invoicePrice'],
  2773. 'invoiceSerial' => $invoiceSerial,
  2774. 'invoiceNo' => '',
  2775. 'printStatus' => 0,
  2776. 'untreadStatus' => 4,
  2777. // 关联发票号
  2778. 'lossIid' => $invoiceDetail ['iid']
  2779. );
  2780. $invoice->setInvoiceByCondition ( $item );
  2781. // 更新原发票
  2782. $invoice = new invoice ();
  2783. $item = array (
  2784. 'iid' => $invoiceDetail ['iid'],
  2785. 'lossIid' => $iid
  2786. );
  2787. $invoice->setInvoiceByCondition ( $item );
  2788. // 操作日志
  2789. $item = array (
  2790. 'date' => date ( "Y-m-d H:i:s" ),
  2791. 'operation' => "创建负票" . $invoiceSerial,
  2792. 'status' => 12,
  2793. 'img' => $this->staff [0] ['avatar'],
  2794. 'username' => $this->staff [0] ['username'],
  2795. 'uid' => $this->staff [0] ['sid'],
  2796. 'category' => $this->staff [0] ['category'],
  2797. 'iid' => $iid
  2798. );
  2799. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2800. // print_r($invoiceDetail);
  2801. // echo $iid;die;
  2802. }
  2803. return '/invoiceUntread';
  2804. }
  2805. /**
  2806. * 上传银行到账 收款文件
  2807. */
  2808. function invoiceReceivablesBankUpload() {
  2809. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  2810. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  2811. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  2812. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  2813. header ( "HTTP/1.1 500 Internal Server Error" );
  2814. echo "POST exceeded maximum allowed size.";
  2815. exit ( 0 );
  2816. }
  2817. // Settings
  2818. $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)
  2819. $upload_name = "Filedata";
  2820. $file_name = "";
  2821. $nk = time ();
  2822. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  2823. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  2824. echo "文件无法保存.";
  2825. exit ( 0 );
  2826. }
  2827. echo json_encode ( array (
  2828. 'filename' => $file_name,
  2829. 'id' => $nk
  2830. ) );
  2831. exit ( 0 );
  2832. }
  2833. /**
  2834. * 解析银行到账收款execl并导入库中
  2835. */
  2836. function invoiceReceivablesImport() {
  2837. $path = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  2838. if ($path != "") {
  2839. Doo::loadModel ( 'invoiceReceivables' );
  2840. $invoiceReceivables = new invoiceReceivables ();
  2841. Doo::loadClass ( 'invoice.func' );
  2842. Doo::loadModel ( 'invoiceROLog' );
  2843. $invoiceROLog = new invoiceROLog ();
  2844. Doo::loadModel ( 'invoiceStatistics' );
  2845. $invoiceStatistics = new invoiceStatistics ();
  2846. $exlArray = formatExcelToArrayBank ( DOO::conf ()->SITE_PATH . "upload/invoiceReceivablesBank/" . $path );
  2847. $bankBatchNumber = 'BBN_' . time ();
  2848. Doo::db ()->beginTransaction ();
  2849. // 批量存储收款--由于必须获得收款ID,
  2850. $sql = 'INSERT INTO CLD_invoiceReceivables (OriginalPrice,receivablesPrice, receivablesMessage,receivablesSerial,receivablesBank,receivablesDate,inputStaff,date,receivablesCategory,receivablesStaff,bankBatchNumber,recepitTitleMark)
  2851. VALUES ';
  2852. $date = date ( "Y-m-d" );
  2853. $receivablesList = array ();
  2854. foreach ( $exlArray as $key => $value ) {
  2855. $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"] . '")';
  2856. array_push ( $receivablesList, $receivablesSql );
  2857. }
  2858. $sql = $sql . implode ( ',', $receivablesList );
  2859. // echo $sql;
  2860. Doo::db ()->query ( $sql );
  2861. // 批量存储收款统计
  2862. // 获得刚刚导入数据的irid组-缺少办事处和人员
  2863. $iridList = $invoiceReceivables->getInvoiceReceivablesByBBN ( $bankBatchNumber );
  2864. // 没有irid 回滚所有操作
  2865. if (empty ( $iridList )) {
  2866. Doo::db ()->rollBack ();
  2867. header ( 'Content-Type:text/html;charset=utf-8' );
  2868. die ( '文档或数据不正确,请重新<a href="/invoiceReceivables">上传</a>.' );
  2869. }
  2870. $sql = 'INSERT INTO CLD_invoiceStatistics (date, priceClass,irid,receivablesPrice)
  2871. VALUES ';
  2872. $statisticsList = array ();
  2873. foreach ( $iridList as $value ) {
  2874. $statisticsSql = '("' . $date . '",2,' . $value ['irid'] . ',' . $value ["receivablesPrice"] . ')';
  2875. array_push ( $statisticsList, $statisticsSql );
  2876. }
  2877. $sql = $sql . implode ( ',', $statisticsList );
  2878. Doo::db ()->query ( $sql );
  2879. // 批量存储操作日志
  2880. $sql = 'INSERT INTO CLD_invoiceROLog (operation, date,status,img, username,uid,category,irid)
  2881. VALUES ';
  2882. $ROLogList = array ();
  2883. foreach ( $iridList as $value ) {
  2884. $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'] . '")';
  2885. array_push ( $ROLogList, $ROLogSql );
  2886. }
  2887. $sql = $sql . implode ( ',', $ROLogList );
  2888. Doo::db ()->query ( $sql );
  2889. // 批量写入流水
  2890. $sql = 'INSERT INTO CLD_wasteBook (dataID, expensesType,accountType,accountPriceShow, accountPrice,accountBank,category,cid,name,sid,inputDate)
  2891. VALUES ';
  2892. $wasteBookList = array ();
  2893. foreach ( $iridList as $value ) {
  2894. $accountBank = '';
  2895. if ($value ['receivablesBank'] == '纵横广发') {
  2896. $accountBank = 'CGBDeposit';
  2897. } elseif ($value ['receivablesBank'] == '纵横工行') {
  2898. $accountBank = 'ICBCDeposit';
  2899. } elseif ($value ['receivablesBank'] == '华润银行') {
  2900. $accountBank = 'HUADeposit';
  2901. } elseif ($value ['receivablesBank'] == '个人广发') {
  2902. $accountBank = 'PersonalDeposit';
  2903. }
  2904. $wasteBookSql = '("' . $value ['irid'] . ' ",1,7,"' . $value ['receivablesPrice'] . '","' . $value ['receivablesPrice'] . '","' . $accountBank . '",
  2905. "' . $this->staff [0] ['category'] . '","' . $this->staff [0] ['cid'] . '","' . $this->staff [0] ['username'] . '","' . $this->staff [0] ['sid'] . '","' . date ( "Y-m-d H:i:s" ) . '")';
  2906. array_push ( $wasteBookList, $wasteBookSql );
  2907. }
  2908. $sql = $sql . implode ( ',', $wasteBookList );
  2909. Doo::db ()->query ( $sql );
  2910. Doo::db ()->commit ();
  2911. return "/invoiceReceivables";
  2912. }
  2913. echo 'no file';
  2914. }
  2915. function invoiceReceivables() {
  2916. $invoiceTC = $this->get_args ( 'invoiceTC' ) ? $this->get_args ( 'invoiceTC' ) : '';
  2917. Doo::loadModel ( 'L_category' );
  2918. $lCategory = new L_category ();
  2919. Doo::loadModel ( 'staff' );
  2920. $staff = new staff ();
  2921. Doo::loadModel ( 'invoiceReceivables' );
  2922. $invoiceReceivables = new invoiceReceivables ();
  2923. Doo::loadModel ( 'invoice' );
  2924. $invoice = new invoice ();
  2925. Doo::loadClass ( 'XDeode' );
  2926. $XDeode = new XDeode ( 5 );
  2927. $category = $lCategory->getCategory ();
  2928. $staffList = $staff->getStaffByCid ( $this->staff [0] ['cid'] );
  2929. $sql = 'bindStatus=1 and iid!=0';
  2930. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByNew ( 4, $sql );
  2931. // 获取未入账发票
  2932. $invoiceUnAccount = $invoice->getInvoiceByUnAccount ( $invoiceTC );
  2933. $invoiceExistAccount = $invoice->getInvoiceByUnAccount ( '', true );
  2934. foreach ( $invoiceUnAccount as $key => $value ) {
  2935. $invoiceUnAccount [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2936. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2937. if (! empty ( $lastApprover )) {
  2938. $lastApproverKey = array_keys ( $lastApprover );
  2939. $lastApprover = end ( $lastApprover );
  2940. $staffDetail = $staff->getOne ( array (
  2941. 'where' => 'sid=' . end ( $lastApproverKey ),
  2942. 'asArray' => true
  2943. ) );
  2944. $lastApprover ['username'] = $staffDetail ['username'];
  2945. }
  2946. $invoiceUnAccount [$key] ['lastApprover'] = $lastApprover;
  2947. }
  2948. foreach ( $invoiceExistAccount as $key => $value ) {
  2949. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  2950. if (empty ( $irList ))
  2951. $irList [0] ['sumPrice'] = 0;
  2952. $balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  2953. $invoiceExistAccount [$key] ['existAccount'] = $irList [0] ['sumPrice'];
  2954. $invoiceExistAccount [$key] ['balance'] = $balance;
  2955. }
  2956. $receivablesInput = $invoiceReceivables->getInvoiceReceivablesByInput ();
  2957. $halfList = $invoiceReceivables->getInvoiceReceivablesByHalf ();
  2958. $this->data ['halfList'] = $halfList;
  2959. $this->data ['halfCount'] = count ( $halfList );
  2960. // print_r($receivablesList);
  2961. $this->data ['receivablesDate'] = date ( "Y-m-d" );
  2962. $this->data ['ieaCount'] = count ( $invoiceExistAccount );
  2963. $this->data ['invoiceExistAccount'] = $invoiceExistAccount;
  2964. $this->data ['receivablesInput'] = $receivablesInput;
  2965. $this->data ['year'] = date ( 'Y' );
  2966. $this->data ['invoiceUnAccount'] = $invoiceUnAccount;
  2967. $this->data ['receivablesList'] = $receivablesList;
  2968. $this->data ['staffList'] = $staffList;
  2969. $this->data ['category'] = $category;
  2970. $this->data ['memu'] = "invoice";
  2971. $this->data ['staff'] = $this->staff;
  2972. $this->data ['receiptMemu'] = 'invoiceReceivables';
  2973. $this->render ( "/admin/invoiceReceivables", $this->data );
  2974. }
  2975. /**
  2976. * 设置收款认领地区
  2977. */
  2978. function setInvoiceReceivablesClaim() {
  2979. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  2980. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  2981. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  2982. if (! empty ( $iridKey ) && ! empty ( $receivablesCategory )) {
  2983. Doo::loadModel ( 'invoiceReceivables' );
  2984. $invoiceReceivables = new invoiceReceivables ();
  2985. Doo::loadClass ( 'XDeode' );
  2986. $XDeode = new XDeode ( 5 );
  2987. Doo::loadModel ( 'invoiceROLog' );
  2988. $invoiceROLog = new invoiceROLog ();
  2989. $irid = $XDeode->decode ( $iridKey );
  2990. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  2991. if (empty ( $irDetail ))
  2992. die ( 'illegal request' );
  2993. $item = array (
  2994. 'irid' => $irid,
  2995. 'receivablesCategory' => $receivablesCategory
  2996. );
  2997. if ($receivablesCategory != 'PUBLIC') {
  2998. $item += array (
  2999. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3000. 'inputType' => 1
  3001. );
  3002. }
  3003. $invoiceReceivables = new invoiceReceivables ();
  3004. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3005. // 收款操作日志
  3006. $item = array (
  3007. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 ",
  3008. 'date' => date ( "Y-m-d" ),
  3009. 'status' => 1,
  3010. 'img' => $this->staff [0] ['avatar'],
  3011. 'username' => $this->staff [0] ['username'],
  3012. 'uid' => $this->staff [0] ['sid'],
  3013. 'category' => $this->staff [0] ['category'],
  3014. 'irid' => $irid
  3015. );
  3016. $invoiceROLog->setInvoiceROLog ( $item );
  3017. if (empty ( $action ))
  3018. return '/invoiceReceivables';
  3019. else
  3020. return "/invoiceReceivablesAS";
  3021. }
  3022. die ( 'illegal request' );
  3023. }
  3024. /**
  3025. * 新添加收款直接入账发票
  3026. */
  3027. function invoiceCompareClaimPrice() {
  3028. // 收款录入
  3029. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  3030. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3031. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3032. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3033. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3034. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $iidKey )) {
  3035. Doo::loadModel ( 'invoiceReceivables' );
  3036. $invoiceReceivables = new invoiceReceivables ();
  3037. Doo::loadModel ( 'invoiceROLog' );
  3038. $invoiceROLog = new invoiceROLog ();
  3039. Doo::loadModel ( 'invoiceStatistics' );
  3040. Doo::loadModel ( 'invoice' );
  3041. $invoice = new invoice ();
  3042. Doo::loadClass ( 'XDeode' );
  3043. $XDeode = new XDeode ( 5 );
  3044. Doo::loadModel ( 'invoiceOperationLog' );
  3045. $invoiceOperationLog = new invoiceOperationLog ();
  3046. $iidKey = $XDeode->decode ( $iidKey );
  3047. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  3048. if (! ($invoiceDetail ['status'] == 2 && $invoiceDetail ['printStatus'] == 1 && $invoiceDetail ['untreadStatus'] == 0))
  3049. die ( 'illegal request' );
  3050. $receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  3051. // 收款录入 并绑定发票
  3052. Doo::db ()->beginTransaction ();
  3053. $bindStatus = 0;
  3054. if ($receivablesPrice <= $invoiceDetail ['invoicePrice']){
  3055. $bindStatus = 1;
  3056. }
  3057. $titleMark = $invoiceDetail ['invoiceTitle'];
  3058. if (! empty ( $invoiceDetail ['invoiceCompany'] ))
  3059. $titleMark = $invoiceDetail ['invoiceCompany'];
  3060. $item = array (
  3061. 'recepitTitleMark' => $titleMark,
  3062. 'bindStatus' => $bindStatus,
  3063. 'iid' => $invoiceDetail ['iid'],
  3064. 'bindPrice' => $invoiceDetail ['invoicePrice'],
  3065. 'bindDate' => date ( "Y-m-d H:i:s" ),
  3066. 'receivablesPrice' => $receivablesPrice,
  3067. 'OriginalPrice' => $receivablesPrice,
  3068. 'receivablesMessage' => $receivablesMessage,
  3069. 'receivablesSerial' => $receivablesSerial,
  3070. 'receivablesBank' => $receivablesBank,
  3071. 'receivablesDate' => $receivablesDate,
  3072. 'inputStaff' => $this->staff [0] ['username'],
  3073. 'accountClerk' => $this->staff [0] ['username'],
  3074. 'date' => date ( "Y-m-d" ),
  3075. 'receivablesCategory' => $invoiceDetail ['cid'] . ':' . $invoiceDetail ['categoryName'],
  3076. 'receivablesStaff' => $invoiceDetail ['sid'] . '-' . $invoiceDetail ['userName'],
  3077. 'confirmTime' => date ( "Y-m-d H:i:s" )
  3078. );
  3079. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  3080. $item = array ();
  3081. // 收款操作日志
  3082. $item = array (
  3083. 'operation' => $this->staff [0] ['username'] . " 转入 " . $invoiceDetail ['userName']
  3084. );
  3085. $item += array (
  3086. 'date' => date ( "Y-m-d" ),
  3087. 'status' => 1,
  3088. 'img' => $this->staff [0] ['avatar'],
  3089. 'username' => $this->staff [0] ['username'],
  3090. 'uid' => $this->staff [0] ['sid'],
  3091. 'category' => $this->staff [0] ['category'],
  3092. 'irid' => $irid
  3093. );
  3094. $invoiceROLog->setInvoiceROLog ( $item );
  3095. // 收款统计
  3096. $invoiceStatistics = new invoiceStatistics ();
  3097. $item = array (
  3098. 'date' => $receivablesDate,
  3099. 'priceClass' => 2,
  3100. 'irid' => $irid,
  3101. 'cid' => $invoiceDetail ['cid'],
  3102. 'staff' => $invoiceDetail ['sid'],
  3103. 'receivablesPrice' => $receivablesPrice
  3104. );
  3105. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3106. // 收款 入 发票
  3107. $detail = $invoiceDetail;
  3108. $iridString = "";
  3109. if (empty ( $detail ['irid'] ))
  3110. $iridString = $irid;
  3111. else
  3112. $iridString = $detail ['irid'] . ',' . $irid;
  3113. $item = array (
  3114. 'irid' => $iridString,
  3115. 'bindTime' => date ( "Y-m-d H:i:s" ),
  3116. 'updateTime' => date ( "Y-m-d H:i:s" ),
  3117. 'iid' => $detail ['iid']
  3118. );
  3119. $invoiceReceivables = new invoiceReceivables ();
  3120. $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  3121. if ($detail ['invoicePrice'] <= $sum)
  3122. $item += array (
  3123. 'untreadStatus' => 3
  3124. );
  3125. $invoice->setInvoiceByCondition ( $item );
  3126. // 操作日志
  3127. $item = array (
  3128. 'date' => date ( "Y-m-d H:i:s" ),
  3129. 'operation' => "收款入账" . $receivablesSerial . "到发票" . $detail ['invoiceSerial'],
  3130. 'status' => 8,
  3131. 'img' => $this->staff [0] ['avatar'],
  3132. 'username' => $this->staff [0] ['username'],
  3133. 'uid' => $this->staff [0] ['sid'],
  3134. 'category' => $this->staff [0] ['category'],
  3135. 'iid' => $detail ['iid']
  3136. );
  3137. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3138. // 入账汇总
  3139. $invoiceStatistics = new invoiceStatistics ();
  3140. // $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $iridString );
  3141. // $accountPrice = 0;
  3142. // foreach ( $list as $key => $value ) {
  3143. // $accountPrice += $value ['receivablesPrice'];
  3144. // }
  3145. $item = array (
  3146. 'date' => $receivablesDate,
  3147. 'priceClass' => 3,
  3148. 'cid' => $invoiceDetail ['cid'],
  3149. 'staff' => $invoiceDetail ['sid'],
  3150. 'accountPrice' => $receivablesPrice
  3151. );
  3152. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3153. // 公司流水记录
  3154. Doo::loadModel ( 'wasteBook' );
  3155. $wasteBook = new wasteBook ();
  3156. $abDetail = $wasteBook->getAccountBookByAid ( 2, 7, $irid );
  3157. $accountBank = '';
  3158. if ($receivablesBank == '纵横广发') {
  3159. $accountBank = 'CGBDeposit';
  3160. } elseif ($receivablesBank == '纵横工行') {
  3161. $accountBank = 'ICBCDeposit';
  3162. } elseif ($receivablesBank == '华润银行') {
  3163. $accountBank = 'HUADeposit';
  3164. } elseif ($receivablesBank == '个人广发') {
  3165. $accountBank = 'PersonalDeposit';
  3166. }
  3167. if (empty ( $abDetail )) {
  3168. $item = array (
  3169. 'dataID' => $irid,
  3170. 'expensesType' => 1,
  3171. 'accountType' => 7,
  3172. 'accountPrice' => $receivablesPrice,
  3173. 'accountPriceShow' => $receivablesPrice,
  3174. 'accountBank' => $accountBank,
  3175. 'category' => $this->staff [0] ['category'],
  3176. 'cid' => $this->staff [0] ['cid'],
  3177. 'name' => $this->staff [0] ['username'],
  3178. 'sid' => $this->staff [0] ['sid'],
  3179. 'inputDate' => date ( "Y-m-d H:i:s" )
  3180. );
  3181. $wasteBook->setAccountBookStatistics ( $item );
  3182. }
  3183. Doo::db ()->commit ();
  3184. }
  3185. return '/invoiceReceivables';
  3186. }
  3187. /**
  3188. * 录入收款数据
  3189. * @return string
  3190. */
  3191. function invoiceReceivablesDo() {
  3192. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3193. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3194. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3195. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3196. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3197. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  3198. Doo::loadModel ( 'invoiceReceivables' );
  3199. $invoiceReceivables = new invoiceReceivables ();
  3200. Doo::loadModel ( 'invoiceROLog' );
  3201. $invoiceROLog = new invoiceROLog ();
  3202. Doo::loadModel ( 'invoiceStatistics' );
  3203. $invoiceStatistics = new invoiceStatistics ();
  3204. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $receivablesCategory ) && ! empty ( $receivablesStaff )) {
  3205. $item = array (
  3206. 'receivablesPrice' => $receivablesPrice,
  3207. 'OriginalPrice' => $receivablesPrice,
  3208. 'receivablesMessage' => $receivablesMessage,
  3209. 'receivablesSerial' => "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  3210. 'receivablesBank' => $receivablesBank,
  3211. 'receivablesDate' => $receivablesDate,
  3212. 'inputStaff' => $this->staff [0] ['username'],
  3213. 'date' => date ( "Y-m-d" ),
  3214. 'receivablesCategory' => $receivablesCategory,
  3215. 'receivablesStaff' => $receivablesStaff
  3216. );
  3217. if ($receivablesCategory != 'PUBLIC') {
  3218. $item += array (
  3219. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3220. 'inputType' => 1
  3221. );
  3222. }
  3223. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  3224. $item = array ();
  3225. // 收款操作日志
  3226. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3227. $item = array (
  3228. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  3229. );
  3230. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3231. $item = array (
  3232. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  3233. );
  3234. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3235. $receivablesStaff = explode ( '-', $receivablesStaff );
  3236. $item = array (
  3237. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  3238. );
  3239. }
  3240. $item += array (
  3241. 'date' => date ( "Y-m-d" ),
  3242. 'status' => 1,
  3243. 'img' => $this->staff [0] ['avatar'],
  3244. 'username' => $this->staff [0] ['username'],
  3245. 'uid' => $this->staff [0] ['sid'],
  3246. 'category' => $this->staff [0] ['category'],
  3247. 'irid' => $irid
  3248. );
  3249. $invoiceROLog->setInvoiceROLog ( $item );
  3250. $item = array (
  3251. 'date' => $receivablesDate,
  3252. 'priceClass' => 2,
  3253. 'irid' => $irid,
  3254. 'receivablesPrice' => $receivablesPrice
  3255. );
  3256. if ($receivablesCategory != 'PUBLIC') {
  3257. $receivablesCategory = explode ( ":", $receivablesCategory );
  3258. $item += array (
  3259. 'cid' => $receivablesCategory [0]
  3260. );
  3261. }
  3262. if ($receivablesStaff2 != 'PUBLIC') {
  3263. $receivablesStaff = explode ( "-", $receivablesStaff2 );
  3264. $item += array (
  3265. 'staff' => $receivablesStaff [0]
  3266. );
  3267. }
  3268. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3269. $toparty = $this->getWxidByCategory ( $receivablesCategory [1] );
  3270. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  3271. $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  3272. if ($toparty != 0)
  3273. $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  3274. // 公司流水记录
  3275. Doo::loadModel ( 'wasteBook' );
  3276. $wasteBook = new wasteBook ();
  3277. $abDetail = $wasteBook->getAccountBookByAid ( 1, 7, $irid );
  3278. $accountBank = '';
  3279. if ($receivablesBank == '纵横广发') {
  3280. $accountBank = 'CGBDeposit';
  3281. } elseif ($receivablesBank == '纵横工行') {
  3282. $accountBank = 'ICBCDeposit';
  3283. } elseif ($receivablesBank == '华润银行') {
  3284. $accountBank = 'HUADeposit';
  3285. } elseif ($receivablesBank == '个人广发') {
  3286. $accountBank = 'PersonalDeposit';
  3287. }
  3288. $item = array (
  3289. 'dataID' => $irid,
  3290. 'expensesType' => 1,
  3291. 'accountType' => 7,
  3292. 'accountPriceShow' => $receivablesPrice,
  3293. 'accountPrice' => $receivablesPrice,
  3294. 'accountBank' => $accountBank,
  3295. 'category' => $this->staff [0] ['category'],
  3296. 'cid' => $this->staff [0] ['cid'],
  3297. 'name' => $this->staff [0] ['username'],
  3298. 'sid' => $this->staff [0] ['sid'],
  3299. 'inputDate' => date ( "Y-m-d H:i:s" )
  3300. );
  3301. $wasteBook->setAccountBookStatistics ( $item );
  3302. }
  3303. return "/invoiceReceivables";
  3304. }
  3305. /**
  3306. * 收款认领页面-包括公共认领 办事处认领 最近已认领数据
  3307. */
  3308. function invoiceReceivablesClaim() {
  3309. Doo::loadModel ( 'invoiceReceivables' );
  3310. $invoiceReceivables = new invoiceReceivables ();
  3311. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  3312. $this->data ['receivablesList'] = $receivablesList;
  3313. $this->data ['memu'] = "invoice";
  3314. $this->data ['staff'] = $this->staff;
  3315. $this->data ['receiptMemu'] = 'invoiceReceivablesClaim';
  3316. $this->render ( "/admin/invoiceReceivablesClaim", $this->data );
  3317. }
  3318. function invoiceReceivablesTitleMarkSet() {
  3319. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  3320. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  3321. if (empty ( $iridKey ) || empty ( $recepitTitleMark ))
  3322. die ( 'illegal request' );
  3323. Doo::loadModel ( 'invoiceReceivables' );
  3324. $invoiceReceivables = new invoiceReceivables ();
  3325. Doo::loadClass ( 'XDeode' );
  3326. $XDeode = new XDeode ( 5 );
  3327. $irid = $XDeode->decode ( $iridKey );
  3328. if (! is_numeric ( $irid ))
  3329. die ( 'illegal request' );
  3330. $invoiceReceivables->recepitTitleMark = $recepitTitleMark;
  3331. $invoiceReceivables->update ( array (
  3332. 'where' => 'irid = ' . $irid
  3333. ) );
  3334. return '/invoiceReceivablesClaim';
  3335. }
  3336. /**
  3337. * 更新收款相关数据
  3338. */
  3339. function invoiceReceivablesUpdateClaim() {
  3340. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3341. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3342. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3343. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3344. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3345. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  3346. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  3347. if (empty ( $claimKey ))
  3348. die ( 'illegal request' );
  3349. Doo::loadModel ( 'invoiceReceivables' );
  3350. $invoiceReceivables = new invoiceReceivables ();
  3351. Doo::loadModel ( 'invoiceROLog' );
  3352. $invoiceROLog = new invoiceROLog ();
  3353. $con = ' and iid=0 and bindStatus=0'; // and receivablesCategory!="PUBLIC" and receivablesStaff!="PUBLIC"
  3354. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  3355. if (empty ( $detail ))
  3356. die ( 'illegal request' );
  3357. $invoiceReceivables = new invoiceReceivables ();
  3358. $item = array (
  3359. 'irid' => $detail ['irid']
  3360. );
  3361. if ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3362. $item += array (
  3363. 'confirmTime' => date ( "Y-m-d H:i:s" )
  3364. );
  3365. }
  3366. if (! empty ( $receivablesCategory ))
  3367. $item += array (
  3368. 'receivablesCategory' => $receivablesCategory
  3369. );
  3370. if (! empty ( $receivablesStaff ))
  3371. $item += array (
  3372. 'receivablesStaff' => $receivablesStaff
  3373. );
  3374. if (! empty ( $receivablesPrice ))
  3375. $item += array (
  3376. 'receivablesPrice' => $receivablesPrice
  3377. );
  3378. if (! empty ( $receivablesMessage ))
  3379. $item += array (
  3380. 'receivablesMessage' => $receivablesMessage
  3381. );
  3382. if (! empty ( $receivablesBank ))
  3383. $item += array (
  3384. 'receivablesBank' => $receivablesBank
  3385. );
  3386. if (! empty ( $receivablesDate ))
  3387. $item += array (
  3388. 'receivablesDate' => $receivablesDate
  3389. );
  3390. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3391. // 收款操作日志
  3392. $item = array ();
  3393. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3394. $item = array (
  3395. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  3396. );
  3397. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3398. $item = array (
  3399. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  3400. );
  3401. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3402. $receivablesStaff = explode ( '-', $receivablesStaff );
  3403. $item = array (
  3404. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  3405. );
  3406. }
  3407. $item += array (
  3408. 'date' => date ( "Y-m-d" ),
  3409. 'status' => 1,
  3410. 'img' => $this->staff [0] ['avatar'],
  3411. 'username' => $this->staff [0] ['username'],
  3412. 'uid' => $this->staff [0] ['sid'],
  3413. 'category' => $this->staff [0] ['category'],
  3414. 'irid' => $detail ['irid']
  3415. );
  3416. $invoiceROLog->setInvoiceROLog ( $item );
  3417. return '/invoiceReceivablesAS';
  3418. }
  3419. function invoiceReceivablesDelete() {
  3420. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  3421. $skll = $this->get_args ( 'skll' ) ? $this->get_args ( 'skll' ) : "";
  3422. if ($skll != '删除到款')
  3423. die ( 'illegal request' );
  3424. if (empty ( $claimKey ))
  3425. die ( 'illegal request' );
  3426. Doo::loadModel ( 'invoiceReceivables' );
  3427. $invoiceReceivables = new invoiceReceivables ();
  3428. $con = ' and bindStatus=0 ';
  3429. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  3430. if (empty ( $detail ))
  3431. die ( 'illegal request' );
  3432. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  3433. // 扣除收款汇总信息 汇总
  3434. Doo::loadModel ( 'invoiceStatistics' );
  3435. $invoiceStatistics = new invoiceStatistics ();
  3436. $item = array (
  3437. 'date' => $detail ['receivablesDate'],
  3438. 'priceClass' => 2,
  3439. 'irid' => $detail ['irid'],
  3440. 'receivablesPrice' => - $detail ['receivablesPrice']
  3441. );
  3442. if ($detail ['receivablesCategory'] != 'PUBLIC') {
  3443. $receivablesCategory = explode ( ":", $detail ['receivablesCategory'] );
  3444. $item += array (
  3445. 'cid' => $receivablesCategory [0]
  3446. );
  3447. }
  3448. if ($detail ['receivablesStaff'] != 'PUBLIC') {
  3449. $receivablesStaff = explode ( "-", $detail ['receivablesStaff'] );
  3450. $item += array (
  3451. 'staff' => $receivablesStaff [0]
  3452. );
  3453. }
  3454. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3455. // 公司流水-删除时删除流水
  3456. Doo::loadModel ( 'wasteBook' );
  3457. $wasteBook = new wasteBook ();
  3458. $wasteBook->delete ( array (
  3459. 'where' => 'dataID=' . $detail ['irid'] . ' and accountType=7',
  3460. 'limit' => 1
  3461. ) );
  3462. return '/invoiceReceivablesAS';
  3463. }
  3464. /**
  3465. * 管理员录入的收款 ,确认认领到谁的名下.统计收款金额
  3466. */
  3467. function invoiceReceivablesAscription() {
  3468. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  3469. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  3470. Doo::loadModel ( 'invoiceReceivables' );
  3471. $invoiceReceivables = new invoiceReceivables ();
  3472. Doo::loadModel ( 'invoiceROLog' );
  3473. $invoiceROLog = new invoiceROLog ();
  3474. Doo::loadModel ( 'invoiceStatistics' );
  3475. $invoiceStatistics = new invoiceStatistics ();
  3476. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  3477. if (! empty ( $detail ) && $detail ['receivablesStaff'] == 'PUBLIC' && ! empty ( $recepitTitleMark )) {
  3478. $item = array (
  3479. 'irid' => $detail ['irid'],
  3480. 'receivablesCategory' => $this->staff [0] ['cid'] . ":" . $this->staff [0] ['category'],
  3481. 'receivablesStaff' => $this->staff [0] ['sid'] . "-" . $this->staff [0] ['username'],
  3482. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3483. 'recepitTitleMark' => $recepitTitleMark,
  3484. 'source' => 1
  3485. );
  3486. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3487. $item = array (
  3488. 'date' => date ( "Y-m-d" ),
  3489. 'operation' => $this->staff [0] ['username'] . " 认领 ",
  3490. 'status' => 2,
  3491. 'img' => $this->staff [0] ['avatar'],
  3492. 'username' => $this->staff [0] ['username'],
  3493. 'uid' => $this->staff [0] ['sid'],
  3494. 'category' => $this->staff [0] ['category'],
  3495. 'irid' => $irid
  3496. );
  3497. $invoiceROLog->setInvoiceROLog ( $item );
  3498. $item = array (
  3499. 'cid' => $this->staff [0] ['cid'],
  3500. 'staff' => $this->staff [0] ['sid']
  3501. );
  3502. $invoiceStatistics->updateInvoiceStatisticsByIrid ( $item, $detail ['irid'], 2 );
  3503. }
  3504. return "/invoiceReceivablesClaim";
  3505. }
  3506. /**
  3507. */
  3508. function invoiceMyReceivables() {
  3509. Doo::loadModel ( 'invoiceReceivables' );
  3510. $invoiceReceivables = new invoiceReceivables ();
  3511. Doo::loadModel ( 'invoiceStatistics' );
  3512. $invoiceStatistics = new invoiceStatistics ();
  3513. $isMonth = $invoiceStatistics->getStatisticsByMonth ( $this->staff [0] ['sid'] );
  3514. $year = date ( "Y" );
  3515. $tmp_date = date ( "Ym" );
  3516. $tmp_year = substr ( $tmp_date, 0, 4 );
  3517. $tmp_mon = substr ( $tmp_date, 4, 2 );
  3518. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  3519. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  3520. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . ".htm";
  3521. $htm = $this->showCache ( $path );
  3522. $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  3523. $this->data ['isMonth'] = $isMonth;
  3524. $this->data ['htm'] = $htm;
  3525. $this->data ['list'] = $list;
  3526. $this->data ['memu'] = "invoice";
  3527. $this->data ['staff'] = $this->staff;
  3528. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  3529. $this->render ( "/admin/invoiceMyReceivables", $this->data );
  3530. }
  3531. /**
  3532. * 纸票管理
  3533. */
  3534. function invoicePaper() {
  3535. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3536. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3537. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3538. $this->data ['dateString'] = $date;
  3539. $this->data ['status'] = $status;
  3540. $this->data ['invoiceType'] = $invoiceType;
  3541. $this->data ['memu'] = "invoice";
  3542. $this->data ['staff'] = $this->staff;
  3543. $this->data ['receiptMemu'] = 'invoicePaper';
  3544. $this->render ( "/admin/invoicePaper", $this->data );
  3545. }
  3546. /**
  3547. * 获得纸票分页数据
  3548. */
  3549. function ajaxGetinvoicePaperAchieve() {
  3550. Doo::loadModel ( 'invoicePaper' );
  3551. $invoicePaper = new invoicePaper ();
  3552. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3553. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3554. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ORDINARY";
  3555. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3556. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  3557. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  3558. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  3559. $MebSea = $this->get_args ( 'search' );
  3560. $MebSea = $MebSea ['value'];
  3561. $page_size = $length;
  3562. $con = '';
  3563. if ($status == 'ALL')
  3564. $con = ' where 1 ';
  3565. elseif ($status == 'PRINTED')
  3566. $con = ' where a.iid!=0 '; // $con = ' where b.isDelete=0 and a.iid!=0 and b.status=2 and b.untreadStatus=0 ';
  3567. elseif ($status == 'UNPRINT')
  3568. $con = ' where a.iid=0 '; // $con = ' where b.isDelete=0 and a.iid=0 and b.status=2 and b.untreadStatus=0 ';
  3569. elseif ($status == 'TICKET')
  3570. $con = ' where b.isDelete=0 and b.untreadStatus=2';
  3571. if ($invoiceType == 'ORDINARY')
  3572. $con .= ' and a.invoiceType=0 ';
  3573. elseif ($invoiceType == 'SPECIAL')
  3574. $con .= ' and a.invoiceType=1 ';
  3575. $dateArr = explode ( ':', $date );
  3576. $D1 = $dateString = '';
  3577. $D2 = '';
  3578. if (! empty ( $date )) {
  3579. $D1 = $dateArr [0];
  3580. if (isset ( $dateArr [1] ))
  3581. $D2 = $dateArr [1];
  3582. else
  3583. $D2 = '';
  3584. $dateString = $D1 . " : " . $D2;
  3585. }
  3586. if (! empty ( $D1 ) && ! empty ( $D2 ))
  3587. $con .= ' and b.printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  3588. elseif (! empty ( $D1 ) && empty ( $D2 ))
  3589. $con .= ' and b.printTime like "%' . $D1 . '%" ';
  3590. if (! empty ( $MebSea ))
  3591. $con .= ' and ( b.invoiceTitle like "%' . $MebSea . '%" or b.invoiceCompany like "%' . $MebSea . '%" or a.invoiceNo like "%' . $MebSea . '%" )';
  3592. $invoiceTotal = $invoicePaper->getInvoicePaperCount ();
  3593. $sql = ' ' . $con;
  3594. $limit = $page . ',' . $page_size;
  3595. $list = $invoicePaper->getInvoicePaper ( $limit, $sql, 'desc' );
  3596. $paperList = array ();
  3597. foreach ( $list as $key => $value ) {
  3598. $irDetail = array ();
  3599. if ($value ['iid'] == 0)
  3600. array_push ( $irDetail, '<a href="javascript:if(window.confirm(\'确认删除?\'))window.location=\'/invoicePaperDel/' . $value ['ipidKey'] . '\'" >删除</a>' );
  3601. else
  3602. array_push ( $irDetail, '' );
  3603. array_push ( $irDetail, $value ['invoiceCode'] );
  3604. array_push ( $irDetail, $value ['invoiceNo'] );
  3605. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKey'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  3606. if ($value ['invoiceType'] == 1)
  3607. array_push ( $irDetail, $value ['invoiceCompany'] );
  3608. else
  3609. array_push ( $irDetail, $value ['invoiceTitle'] );
  3610. if ($value ['invoiceType'] == 1)
  3611. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  3612. else
  3613. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  3614. array_push ( $irDetail, $value ['invoiceElement'] );
  3615. array_push ( $irDetail, $value ['categoryName'] . '-' . $value ['userName'] );
  3616. array_push ( $irDetail, $value ['printTime'] );
  3617. array_push ( $paperList, $irDetail );
  3618. }
  3619. // $approvalListJson = json_encode ( $approvalList );
  3620. $recordsFiltered = $invoiceTotal;
  3621. echo json_encode ( array (
  3622. "draw" => intval ( $draw ),
  3623. "recordsTotal" => intval ( $invoiceTotal ),
  3624. "recordsFiltered" => intval ( $recordsFiltered ),
  3625. "data" => $paperList
  3626. ), JSON_UNESCAPED_UNICODE );
  3627. }
  3628. function invoicePaperDel() {
  3629. $ipidKey = isset ( $this->params ['ipidKey'] ) ? $this->params ['ipidKey'] : "";
  3630. $XDeode = new XDeode ( 5 );
  3631. $ipid = $XDeode->decode ( $ipidKey );
  3632. if (empty ( $ipid ))
  3633. die ( 'illegal request' );
  3634. Doo::loadModel ( 'invoicePaper' );
  3635. $invoicePaper = new invoicePaper ();
  3636. $invoicePaper->delete ( array (
  3637. 'where' => 'ipid=' . $ipid . ' and iid=0',
  3638. 'limit' => 1
  3639. ) );
  3640. return '/invoicePaper';
  3641. }
  3642. /**
  3643. * 添加纸质发票号
  3644. */
  3645. function invoicePaperAdd() {
  3646. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : '0';
  3647. $invoiceCode = $this->get_args ( 'invoiceCode' ) ? $this->get_args ( 'invoiceCode' ) : "";
  3648. $invoiceNoStart = $this->get_args ( 'invoiceNoStart' ) && is_numeric ( $this->get_args ( 'invoiceNoStart' ) ) ? $this->get_args ( 'invoiceNoStart' ) : 0;
  3649. $invoiceNoTotal = $this->get_args ( 'invoiceNoTotal' ) && is_numeric ( $this->get_args ( 'invoiceNoTotal' ) ) ? $this->get_args ( 'invoiceNoTotal' ) : 0;
  3650. if ($invoiceType != '' && ! empty ( $invoiceCode ) && ! empty ( $invoiceNoStart ) && ! empty ( $invoiceNoTotal )) {
  3651. $sum = $invoiceNoStart + $invoiceNoTotal;
  3652. if (empty ( $sum ))
  3653. die ( 'illegal request' );
  3654. // echo $invoiceNoStart;
  3655. // echo $sum;
  3656. // echo strlen((int)$invoiceNoStart);
  3657. $sumLenght = strlen ( $invoiceNoStart ) - strlen ( ( int ) $invoiceNoStart );
  3658. Doo::db ()->beginTransaction ();
  3659. // 批量存储纸质发票
  3660. $date = date ( "Y-m-d H:i:s" );
  3661. $sql = 'INSERT INTO CLD_invoicePaper (invoiceType, invoiceCode,invoiceNo,date)
  3662. VALUES ';
  3663. $paperList = array ();
  3664. for($invoiceNoStart; $invoiceNoStart <= $sum - 1; $invoiceNoStart ++) {
  3665. // 数字前面自加0
  3666. $INLENGHT = strlen ( ( int ) $invoiceNoStart ) + $sumLenght;
  3667. $var = sprintf ( "%0" . $INLENGHT . "d", $invoiceNoStart );
  3668. $paperSql = '(' . $invoiceType . ',"' . $invoiceCode . '","' . $var . '","' . $date . '")';
  3669. array_push ( $paperList, $paperSql );
  3670. }
  3671. if (empty ( $paperList ))
  3672. die ( 'illegal request' );
  3673. $sql = $sql . implode ( ',', $paperList );
  3674. Doo::db ()->query ( $sql );
  3675. Doo::db ()->commit ();
  3676. return 'invoicePaper';
  3677. }
  3678. die ( 'illegal request' );
  3679. }
  3680. /**
  3681. * 收款绑定发票 ,//一个收款只能绑定一个发票
  3682. */
  3683. function invoiceBindReceivables() {
  3684. $claimKey = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  3685. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  3686. Doo::loadModel ( 'invoice' );
  3687. $invoice = new invoice ();
  3688. Doo::loadModel ( 'invoiceReceivables' );
  3689. $invoiceReceivables = new invoiceReceivables ();
  3690. Doo::loadModel ( 'invoiceOperationLog' );
  3691. $invoiceOperationLog = new invoiceOperationLog ();
  3692. if (empty ( $invoiceKey ) || empty ( $claimKey ))
  3693. die ( 'illegal request' );
  3694. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  3695. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey );
  3696. if (empty ( $detail ) && empty ( $detailM ))
  3697. die ( 'illegal request' );
  3698. if ($detail ['untreadStatus'] == 3)
  3699. die ( 'illegal request' );
  3700. // 修改 绑定状态改为 金额
  3701. $invoiceReceivables = new invoiceReceivables ();
  3702. $invoicePrice = $detail ['invoicePrice'] + $detailM ['bindPrice'];
  3703. if ($detailM ['receivablesPrice'] > $invoicePrice) {
  3704. $item = array (
  3705. 'bindPrice' => $invoicePrice
  3706. );
  3707. } elseif ($detailM ['receivablesPrice'] <= $invoicePrice) {
  3708. $item = array (
  3709. 'bindPrice' => $invoicePrice,
  3710. 'bindStatus' => 1,
  3711. 'bindDate' => date ( "Y-m-d H:i:s" )
  3712. );
  3713. } else {
  3714. die ( 'illegal request' );
  3715. }
  3716. if ($detailM ['iid'] == 0) {
  3717. $item += array (
  3718. 'iid' => $detail ['iid']
  3719. );
  3720. } else {
  3721. $iidExtend = explode ( ',', $detailM ['iidExtend'] );
  3722. array_push ( $iidExtend, $detail ['iid'] );
  3723. $item += array (
  3724. 'iidExtend' => implode ( ',', $iidExtend )
  3725. );
  3726. }
  3727. $titleMark = $detail ['invoiceTitle'];
  3728. if (! empty ( $detail ['invoiceCompany'] ))
  3729. $titleMark = $detail ['invoiceCompany'];
  3730. $item += array (
  3731. 'irid' => $detailM ['irid'],
  3732. 'recepitTitleMark' => $titleMark,
  3733. 'accountClerk' => $this->staff [0] ['username']
  3734. );
  3735. // 如何没有人收款 则自动绑定收款
  3736. if ($detailM ['receivablesCategory'] == 'PUBLIC' || $detailM ['receivablesStaff'] == 'PUBLIC') {
  3737. $item += array (
  3738. 'receivablesCategory' => $detail ['cid'] . ':' . $detail ['categoryName'],
  3739. 'receivablesStaff' => $detail ['sid'] . '-' . $detail ['userName']
  3740. );
  3741. }
  3742. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3743. $iridString = "";
  3744. if (empty ( $detail ['irid'] ))
  3745. $iridString = $detailM ['irid'];
  3746. else
  3747. $iridString = $detail ['irid'] . ',' . $detailM ['irid'];
  3748. $item = array (
  3749. 'iid' => $detail ['iid'],
  3750. 'irid' => $iridString
  3751. );
  3752. $invoiceReceivables = new invoiceReceivables ();
  3753. $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  3754. if ($detail ['invoicePrice'] <= $sum)
  3755. $item += array (
  3756. 'untreadStatus' => 3,
  3757. 'bindTime' => date ( "Y-m-d H:i:s" )
  3758. );
  3759. // print_r($item);
  3760. // echo $sum;die;
  3761. $invoice->setInvoiceByCondition ( $item );
  3762. // 操作日志
  3763. $item = array (
  3764. 'date' => date ( "Y-m-d H:i:s" ),
  3765. 'operation' => "收款" . $detailM ['receivablesSerial'] . "入账到发票" . $detail ['invoiceSerial'],
  3766. 'status' => 8,
  3767. 'img' => $this->staff [0] ['avatar'],
  3768. 'username' => $this->staff [0] ['username'],
  3769. 'uid' => $this->staff [0] ['sid'],
  3770. 'category' => $this->staff [0] ['category'],
  3771. 'iid' => $detail ['iid']
  3772. );
  3773. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3774. Doo::loadModel ( 'invoiceStatistics' );
  3775. $invoiceStatistics = new invoiceStatistics ();
  3776. $item = array (
  3777. 'date' => $detailM ['receivablesDate'],
  3778. 'priceClass' => 3,
  3779. 'cid' => $detail ['cid'],
  3780. 'staff' => $detail ['sid'],
  3781. 'accountPrice' => $detailM ['receivablesPrice']
  3782. );
  3783. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3784. // 公司流水记录
  3785. // Doo::loadModel ( 'wasteBook' );
  3786. // $wasteBook = new wasteBook ();
  3787. // $abDetail = $wasteBook->getAccountBookByAid (1,8,$detail ['iid'] );
  3788. // $accountBank='';
  3789. // if ($detailM ['receivablesBank']=='纵横广发'){
  3790. // $accountBank='CGBDeposit';
  3791. // }elseif($detailM ['receivablesBank']=='纵横工行'){
  3792. // $accountBank='ICBCDeposit';
  3793. // }elseif($detailM ['receivablesBank']=='华润银行'){
  3794. // $accountBank='HUADeposit';
  3795. // }elseif($detailM ['receivablesBank']=='个人广发'){
  3796. // $accountBank='PersonalDeposit';
  3797. // }
  3798. // if (empty($abDetail)){
  3799. // $item = array (
  3800. // 'dataID' => $detail ['iid'],
  3801. // 'expensesType' => 1,
  3802. // 'accountType' => 8,
  3803. // 'accountPriceShow'=>$detail ['invoicePrice'],
  3804. // 'accountPrice'=>$detail ['invoicePrice'],
  3805. // 'accountBank'=>$accountBank,
  3806. // 'category'=>$this->staff[0]['category'],
  3807. // 'cid'=>$this->staff[0]['cid'],
  3808. // 'name'=>$this->staff[0]['username'],
  3809. // 'sid'=>$this->staff[0]['sid'],
  3810. // 'inputDate'=>date ( "Y-m-d H:i:s" )
  3811. // );
  3812. // $wasteBook->setAccountBookStatistics($item);
  3813. // }
  3814. return "/invoiceReceivables";
  3815. }
  3816. /**
  3817. * 核销 动作,确认入账统计 发票收款完成--需求更变 废弃 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"; }
  3818. */
  3819. function invoiceAggregate() {
  3820. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3821. Doo::loadModel ( 'invoiceStatistics' );
  3822. $invoiceStatistics = new invoiceStatistics ();
  3823. Doo::loadModel ( 'L_category' );
  3824. $Lcategory = new L_category ();
  3825. $isList = $invoiceStatistics->getInvoiceStatisticsByYear ( $year );
  3826. $LcategoryList = $Lcategory->getCategory ();
  3827. // print_r($isList);
  3828. $html = ""; // $invoicePriceCategory=0;$receivablesPriceCategory=0;$accountPriceCategory=0;
  3829. foreach ( $LcategoryList as $key => $value ) {
  3830. $html .= '<tr><th><a href="/invoiceAggregateCategory/' . $value ['cidKey'] . '">' . $value ['title'] . '</a></th>';
  3831. $month = 1;
  3832. $invoicePriceYear = 0;
  3833. $receivablesPriceYear = 0;
  3834. $accountPriceYear = 0;
  3835. for(; $month <= 12; $month ++) {
  3836. $flag = true;
  3837. foreach ( $isList ['statisticsMonthCid'] as $k => $v ) {
  3838. if ($value ['cid'] == $v ['cid'] && $month == $v ['month']) {
  3839. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  3840. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  3841. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  3842. ';
  3843. $invoicePriceYear += $v ['invoicePrice'];
  3844. $receivablesPriceYear += $v ['receivablesPrice'];
  3845. $accountPriceYear += $v ['accountPrice'];
  3846. $flag = false;
  3847. break;
  3848. }
  3849. }
  3850. if ($flag)
  3851. $html .= '<td class="taR"></td>
  3852. <td class="taR"></td>
  3853. <td class="taR"><b></b></td>
  3854. ';
  3855. }
  3856. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  3857. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  3858. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  3859. ';
  3860. $html .= '</tr>';
  3861. }
  3862. $html .= '<tr><th><b class="colGreen">月合计</b></th>';
  3863. $invoicePriceYear = 0;
  3864. $receivablesPriceYear = 0;
  3865. $accountPriceYear = 0;
  3866. for($month = 1; $month <= 12; $month ++) {
  3867. $flag = true;
  3868. foreach ( $isList ['statisticsMonth'] as $k => $v ) {
  3869. if ($month == $v ['month']) {
  3870. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  3871. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  3872. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  3873. ';
  3874. $invoicePriceYear += $v ['invoicePrice'];
  3875. $receivablesPriceYear += $v ['receivablesPrice'];
  3876. $accountPriceYear += $v ['accountPrice'];
  3877. $flag = false;
  3878. break;
  3879. }
  3880. }
  3881. if ($flag) {
  3882. $html .= '<td class="taR"></td>
  3883. <td class="taR"></td>
  3884. <td class="taR"><b></b></td>
  3885. ';
  3886. }
  3887. }
  3888. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  3889. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  3890. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  3891. ';
  3892. $html .= '</tr>';
  3893. // print_r($isList);
  3894. $this->data ['html'] = $html;
  3895. $this->data ['LcategoryList'] = $LcategoryList;
  3896. $this->data ['isList'] = $isList;
  3897. $this->data ['year'] = $year;
  3898. $this->data ['memu'] = "invoice";
  3899. $this->data ['staff'] = $this->staff;
  3900. $this->data ['receiptMemu'] = 'invoiceAggregate';
  3901. $this->render ( "/admin/invoiceAggregate", $this->data );
  3902. }
  3903. function invoiceAggregateStaff() {
  3904. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3905. Doo::loadModel ( 'invoiceStatistics' );
  3906. $invoiceStatistics = new invoiceStatistics ();
  3907. Doo::loadModel ( 'L_category' );
  3908. $Lcategory = new L_category ();
  3909. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year );
  3910. $staffList = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year );
  3911. $cStaff = $Lcategory->getCategoryStaff ();
  3912. $html = '';
  3913. foreach ( $cStaff as $key => $value ) {
  3914. $categoryFir = true;
  3915. foreach ( $value ['staff'] as $k => $v ) {
  3916. if ($categoryFir) {
  3917. $width = count ( $value ['staff'] ) + 1;
  3918. $html .= '<tr><th rowspan="' . $width . '">' . $value ['title'] . ' </th>';
  3919. $categoryFir = false;
  3920. } else
  3921. $html .= '<tr>';
  3922. $html .= '<th>' . $v ['username'] . '</th>';
  3923. $invoicePriceStaffYear = 0;
  3924. $receivablesPriceStaffYear = 0;
  3925. $accountPriceStaffYear = 0;
  3926. for($month = 1; $month <= 12; $month ++) {
  3927. $flag = true;
  3928. foreach ( $staffList ['statisticsMonthStaff'] as $sl => $slv ) {
  3929. if ($v ['sid'] == $slv ['staff'] && $month == $slv ['month']) {
  3930. $html .= '<td class="taR">¥' . $slv ['invoicePrice'] . '</td>
  3931. <td class="taR">¥' . $slv ['receivablesPrice'] . '</td>
  3932. <td class="taR"><b>¥' . $slv ['accountPrice'] . '</b></td>
  3933. ';
  3934. $invoicePriceStaffYear += $slv ['invoicePrice'];
  3935. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  3936. $accountPriceStaffYear += $slv ['accountPrice'];
  3937. $flag = false;
  3938. break;
  3939. }
  3940. }
  3941. if ($flag)
  3942. $html .= '<td class="taR"></td>
  3943. <td class="taR"></td>
  3944. <td class="taR"><b></b></td>
  3945. ';
  3946. }
  3947. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  3948. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  3949. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  3950. ';
  3951. }
  3952. $html .= '</tr>';
  3953. // 小计
  3954. if (! empty ( $value ['staff'] )) {
  3955. $html .= '<tr><th class="taR">小计</th>';
  3956. $invoicePriceStaffYear = 0;
  3957. $receivablesPriceStaffYear = 0;
  3958. $accountPriceStaffYear = 0;
  3959. for($month = 1; $month <= 12; $month ++) {
  3960. $flag = true;
  3961. foreach ( $staffList ['statisticsMonthCid'] as $smc => $smcv ) {
  3962. if ($value ['cid'] == $smcv ['cid'] && $month == $slv ['month']) {
  3963. $html .= '<td class="taR">¥' . $smcv ['invoicePrice'] . '</td>
  3964. <td class="taR">¥' . $smcv ['receivablesPrice'] . '</td>
  3965. <td class="taR"><b>¥' . $smcv ['accountPrice'] . '</b></td>
  3966. ';
  3967. $invoicePriceStaffYear += $slv ['invoicePrice'];
  3968. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  3969. $accountPriceStaffYear += $slv ['accountPrice'];
  3970. $flag = false;
  3971. break;
  3972. }
  3973. }
  3974. if ($flag)
  3975. $html .= '<td class="taR"></td>
  3976. <td class="taR"></td>
  3977. <td class="taR"><b></b></td>
  3978. ';
  3979. }
  3980. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  3981. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  3982. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  3983. ';
  3984. $html .= '</tr>';
  3985. }
  3986. }
  3987. $html .= '<tr class="warning"><th colspan="2"><b class="colGreen" >月合计</b></th>';
  3988. $invoicePriceYear = 0;
  3989. $receivablesPriceYear = 0;
  3990. $accountPriceYear = 0;
  3991. for($month = 1; $month <= 12; $month ++) {
  3992. $flag = true;
  3993. foreach ( $staffList ['statisticsMonth'] as $k => $v ) {
  3994. if ($month == $v ['month']) {
  3995. $html .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>
  3996. <td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>
  3997. <td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>
  3998. ';
  3999. $invoicePriceYear += $v ['invoicePrice'];
  4000. $receivablesPriceYear += $v ['receivablesPrice'];
  4001. $accountPriceYear += $v ['accountPrice'];
  4002. $flag = false;
  4003. break;
  4004. }
  4005. }
  4006. if ($flag)
  4007. $html .= '<td class="taR"></td>
  4008. <td class="taR"></td>
  4009. <td class="taR"><b></b></td>
  4010. ';
  4011. }
  4012. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  4013. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  4014. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  4015. ';
  4016. $html .= '</tr>';
  4017. $this->data ['html'] = $html;
  4018. $this->data ['isList'] = $toteList;
  4019. $this->data ['year'] = $year;
  4020. $this->data ['memu'] = "invoice";
  4021. $this->data ['staff'] = $this->staff;
  4022. $this->data ['receiptMemu'] = 'invoiceAggregate';
  4023. $this->render ( "/admin/invoiceAggregateStaff", $this->data );
  4024. }
  4025. function invoiceAggregateCategory() {
  4026. Doo::loadClass ( 'XDeode' );
  4027. $XDeode = new XDeode ( 5 );
  4028. $cid = $cidKey = isset ( $this->params ['cid'] ) ? $this->params ['cid'] : "";
  4029. $cid = $XDeode->decode ( $cid );
  4030. if (! is_numeric ( $cid ))
  4031. die ( 'illegal request' );
  4032. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  4033. Doo::loadModel ( 'invoiceStatistics' );
  4034. $invoiceStatistics = new invoiceStatistics ();
  4035. Doo::loadModel ( 'staff' );
  4036. $staff = new staff ();
  4037. $list = $staff->getStaffByCid ( $cid );
  4038. $isCategory = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year, $cid );
  4039. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year, $cid );
  4040. if (empty ( $list ))
  4041. die ( '该办事处没有成员' );
  4042. $htmlA = $htmlB = $htmlC = $html = '';
  4043. foreach ( $list as $key => $value ) {
  4044. $htmlA = '<tr><th rowspan="3">' . $value ['username'] . '</th><th class="taC">开票</th>';
  4045. $htmlB = '<tr><th class="taC">收款</th>';
  4046. $htmlC = '<tr><th class="taC">入账</th>';
  4047. $invoicePriceStaffYear = 0;
  4048. $receivablesPriceStaffYear = 0;
  4049. $accountPriceStaffYear = 0;
  4050. for($month = 1; $month <= 12; $month ++) {
  4051. $flag = true;
  4052. foreach ( $isCategory ['statisticsMonthStaff'] as $k => $v ) {
  4053. if ($value ['sid'] == $v ['staff'] && $month == $v ['month']) {
  4054. $htmlA .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>';
  4055. $htmlB .= '<td class="taR">¥' . $v ['receivablesPrice'] . '</td>';
  4056. $htmlC .= '<td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>';
  4057. $invoicePriceStaffYear += $v ['invoicePrice'];
  4058. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  4059. $accountPriceStaffYear += $v ['accountPrice'];
  4060. $flag = false;
  4061. break;
  4062. }
  4063. }
  4064. if ($flag) {
  4065. $htmlA .= '<td class="taR">-</td>';
  4066. $htmlB .= '<td class="taR">-</td>';
  4067. $htmlC .= '<td class="taR"><b>-</b></td>';
  4068. }
  4069. }
  4070. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  4071. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  4072. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  4073. $htmlA .= '</tr>';
  4074. $htmlB .= '</tr>';
  4075. $htmlC .= '</tr>';
  4076. $html .= $htmlA . $htmlB . $htmlC;
  4077. }
  4078. $htmlA = $htmlB = $htmlC = "";
  4079. $htmlA = '<tr><th rowspan="3">月合计</th><th class="taC">开票</th>';
  4080. $htmlB = '<tr><th class="taC">收款</th>';
  4081. $htmlC = '<tr><th class="taC">入账</th>';
  4082. $invoicePriceStaffYear = 0;
  4083. $receivablesPriceStaffYear = 0;
  4084. $accountPriceStaffYear = 0;
  4085. for($month = 1; $month <= 12; $month ++) {
  4086. $flag = true;
  4087. foreach ( $isCategory ['statisticsMonth'] as $k => $v ) {
  4088. if ($month == $v ['month']) {
  4089. $htmlA .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>';
  4090. $htmlB .= '<td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>';
  4091. $htmlC .= '<td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>';
  4092. $invoicePriceStaffYear += $v ['invoicePrice'];
  4093. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  4094. $accountPriceStaffYear += $v ['accountPrice'];
  4095. $flag = false;
  4096. break;
  4097. }
  4098. }
  4099. if ($flag) {
  4100. $htmlA .= '<td class="taR">-</td>';
  4101. $htmlB .= '<td class="taR">-</td>';
  4102. $htmlC .= '<td class="taR"><b>-</b></td>';
  4103. }
  4104. }
  4105. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  4106. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  4107. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  4108. $htmlA .= '</tr>';
  4109. $htmlB .= '</tr>';
  4110. $htmlC .= '</tr>';
  4111. $html .= $htmlA . $htmlB . $htmlC;
  4112. $this->data ['html'] = $html;
  4113. $this->data ['cidKey'] = $cidKey;
  4114. $this->data ['slist'] = $list;
  4115. $this->data ['isList'] = $toteList;
  4116. $this->data ['year'] = $year;
  4117. $this->data ['memu'] = "invoice";
  4118. $this->data ['staff'] = $this->staff;
  4119. $this->data ['receiptMemu'] = 'invoiceAggregate';
  4120. $this->render ( "/admin/invoiceAggregateCategory", $this->data );
  4121. }
  4122. /**
  4123. * 办事处汇总信息
  4124. */
  4125. function invoiceAggregateCategoryDetail() {
  4126. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  4127. Doo::loadClass ( 'XDeode' );
  4128. $XDeode = new XDeode ( 5 );
  4129. Doo::loadModel ( 'invoiceStatistics' );
  4130. $invoiceStatistics = new invoiceStatistics ();
  4131. Doo::loadModel ( 'L_category' );
  4132. $category = new L_category ();
  4133. Doo::loadModel ( 'invoice' );
  4134. $invoice = new invoice ();
  4135. Doo::loadModel ( 'staff' );
  4136. $staff = new staff ();
  4137. Doo::loadModel ( "invoiceCategoryManage" );
  4138. $invoiceCategoryManage = new invoiceCategoryManage ();
  4139. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4140. $cidList = array ();
  4141. foreach ( $imcStaff as $key => $value ) {
  4142. array_push ( $cidList, $value ['cid'] );
  4143. if (empty ( $cidKey ))
  4144. $cidKey = $XDeode->encode ( $value ['cid'] );
  4145. }
  4146. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  4147. $cid = $XDeode->decode ( $cidKey );
  4148. $month = date ( "m", strtotime ( "-1 month" ) );
  4149. $YearMonth = date ( "Y-m", strtotime ( "-1 month" ) );
  4150. $redis = new Redis ();
  4151. $redis->connect ( '127.0.0.1', '6379' );
  4152. $redisKey = ''; // date('Y-m-d').'_iacd_'.$cid;
  4153. $redisValue = ''; // $redis->lrange($redisKey, 0, -1);
  4154. if (empty ( $redisValue )) {
  4155. $isMC = $invoiceStatistics->getInvoiceStatistiscsMothByCategory ( $cid );
  4156. $schedule = $invoice->getInvoiceScheduleByCid ( $cid );
  4157. // 获得办事处人员下的汇总
  4158. $slist = $staff->getStaffByCid ( $cid );
  4159. $ismsbMonth = $invoiceStatistics->getISMSByCategoryByMonth ( $cid, $YearMonth ); // 上一个月的汇总
  4160. $ismsb = $invoiceStatistics->getISMSByCategory ( $cid ); // 当月汇总
  4161. $ISAS = $invoiceStatistics->getISASByCategory ( $cid ); // 全部汇总
  4162. $scheduleStaff = $invoice->getInvoiceScheduleByCidGroupSid ( $cid ); // 完成度
  4163. foreach ( $slist as $key => $value ) {
  4164. $slist [$key] ['invoicePrice'] = 0;
  4165. $slist [$key] ['receivablesPrice'] = 0;
  4166. $slist [$key] ['accountPrice'] = 0;
  4167. $slist [$key] ['invoiceAllPrice'] = 0;
  4168. $slist [$key] ['receivablesAllPrice'] = 0;
  4169. $slist [$key] ['accountAllPrice'] = 0;
  4170. $slist [$key] ['schedule'] = 0;
  4171. $slist [$key] ['invoiceMonthPrice'] = 0;
  4172. $slist [$key] ['receivablesMonthPrice'] = 0;
  4173. $slist [$key] ['accountMonthPrice'] = 0;
  4174. foreach ( $ismsbMonth as $y => $l ) {
  4175. if ($value ['sid'] == $l ['staff']) {
  4176. $slist [$key] ['invoiceMonthPrice'] = $l ['invoicePrice'];
  4177. $slist [$key] ['receivablesMonthPrice'] = $l ['receivablesPrice'];
  4178. $slist [$key] ['accountMonthPrice'] = $l ['accountPrice'];
  4179. }
  4180. }
  4181. foreach ( $ismsb as $k => $v ) {
  4182. if ($value ['sid'] == $v ['staff']) {
  4183. $slist [$key] ['invoicePrice'] = $v ['invoicePrice'];
  4184. $slist [$key] ['receivablesPrice'] = $v ['receivablesPrice'];
  4185. $slist [$key] ['accountPrice'] = $v ['accountPrice'];
  4186. }
  4187. }
  4188. foreach ( $ISAS as $e => $a ) {
  4189. if ($value ['sid'] == $a ['staff']) {
  4190. $slist [$key] ['invoiceAllPrice'] = $a ['invoicePrice'];
  4191. $slist [$key] ['receivablesAllPrice'] = $a ['receivablesPrice'];
  4192. $slist [$key] ['accountAllPrice'] = $a ['accountPrice'];
  4193. }
  4194. }
  4195. if (isset ( $scheduleStaff [$value ['sid']] ))
  4196. $slist [$key] ['schedule'] = $scheduleStaff [$value ['sid']];
  4197. }
  4198. $this->data ['cidKey'] = $cidKey;
  4199. $schedule = ( int ) ($schedule * 100);
  4200. $this->data ['slist'] = $slist;
  4201. $this->data ['isMC'] = $isMC;
  4202. $this->data ['schedule'] = $schedule;
  4203. $slist = json_encode ( $slist );
  4204. $isMC = json_encode ( $isMC );
  4205. $schedule = json_encode ( $schedule );
  4206. $redis->lpush ( $redisKey, $slist );
  4207. $redis->lpush ( $redisKey, $isMC );
  4208. $redis->lpush ( $redisKey, $schedule );
  4209. } else {
  4210. $this->data ['cidKey'] = $cidKey;
  4211. $this->data ['slist'] = json_decode ( $redisValue [2], true );
  4212. $this->data ['isMC'] = json_decode ( $redisValue [1], true );
  4213. $this->data ['schedule'] = json_decode ( $redisValue [0], true );
  4214. }
  4215. $this->data ['month'] = $month;
  4216. $this->data ['categoryList'] = $categoryList;
  4217. $this->data ['memu'] = "invoice";
  4218. $this->data ['staff'] = $this->staff;
  4219. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4220. $this->render ( "/admin/invoiceAggregateCategoryDetail", $this->data );
  4221. }
  4222. /**
  4223. * 办事处人员汇总详情
  4224. */
  4225. function invoiceAggregateStaffDetail() {
  4226. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  4227. // $sidKey = isset ( $this->params ['sidKey'] ) ? $this->params ['sidKey'] : '';
  4228. Doo::loadClass ( 'XDeode' );
  4229. $XDeode = new XDeode ( 5 );
  4230. Doo::loadModel ( 'invoice' );
  4231. $invoice = new invoice ();
  4232. Doo::loadModel ( 'staff' );
  4233. $staff = new staff ();
  4234. Doo::loadModel ( "invoiceCategoryManage" );
  4235. $invoiceCategoryManage = new invoiceCategoryManage ();
  4236. $sid = $XDeode->decode ( $sidKey );
  4237. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4238. $cidList = array ();
  4239. foreach ( $imcStaff as $key => $value ) {
  4240. array_push ( $cidList, $value ['cid'] );
  4241. if (empty ( $cidKey ))
  4242. $cidKey = $XDeode->encode ( $value ['cid'] );
  4243. }
  4244. $cidString = implode ( ',', $cidList );
  4245. $staffList = $staff->getStaffInCid ( $cidString );
  4246. $staffDetail = $staff->getStaffBySid ( $sid );
  4247. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4248. $page_size = 18;
  4249. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4250. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4251. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  4252. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  4253. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  4254. $dateArr = explode ( ':', $date );
  4255. $D1 = '';
  4256. $D2 = '';
  4257. if (! empty ( $date )) {
  4258. $D1 = $dateArr [0] . " 00:00:00 ";
  4259. if (isset ( $dateArr [1] ))
  4260. $D2 = $dateArr [1] . " 23:59:59 ";
  4261. else
  4262. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4263. // $D2 = $dateArr [1];
  4264. }
  4265. $con = ' status=2 ';
  4266. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4267. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4268. if ($status == 'UNRECORD')
  4269. $con .= ' and printStatus=1 and untreadStatus=0';
  4270. elseif ($status == 'RECORD')
  4271. $con .= ' and printStatus=1 and untreadStatus=3';
  4272. elseif ($status == 'BOUNCED')
  4273. $con .= ' and untreadStatus=2';
  4274. elseif ($status == 'PARTRECORD')
  4275. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  4276. elseif ($status == 'All') {
  4277. $con .= ' and ( untreadStatus=2 or untreadStatus=0 or untreadStatus=3 )';
  4278. }
  4279. $con .= ' and sid=' . $sid;
  4280. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  4281. if (! empty ( $MebSea )) {
  4282. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  4283. }
  4284. $pageinfo ['page'] = array (
  4285. 'previous' => ''
  4286. );
  4287. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateStaffDetail", $get, "" );
  4288. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4289. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  4290. $this->data ['staffDetail'] = $staffDetail;
  4291. $this->data ['staffList'] = $staffList;
  4292. $this->data ['MebSeaEn'] = $MebSea;
  4293. $this->data ['MebSea'] = urlencode ( $MebSea );
  4294. $this->data ['date'] = $date;
  4295. $this->data ['page'] = $pageinfo;
  4296. $this->data ['get'] = $get;
  4297. $this->data ['list'] = $list;
  4298. $this->data ['status'] = $status;
  4299. $this->data ['sidKey'] = $sidKey;
  4300. $this->data ['memu'] = "invoice";
  4301. $this->data ['staff'] = $this->staff;
  4302. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4303. $this->render ( "/admin/invoiceAggregateStaffDetail", $this->data );
  4304. }
  4305. /**
  4306. * 办事处人员汇总收款情
  4307. */
  4308. function invoiceAggregateStaffReceivablesDetail() {
  4309. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  4310. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  4311. Doo::loadModel ( 'invoiceReceivables' );
  4312. $invoiceReceivables = new invoiceReceivables ();
  4313. Doo::loadModel ( 'staff' );
  4314. $staff = new staff ();
  4315. Doo::loadModel ( "invoiceCategoryManage" );
  4316. $invoiceCategoryManage = new invoiceCategoryManage ();
  4317. Doo::loadClass ( 'XDeode' );
  4318. $XDeode = new XDeode ( 5 );
  4319. $sid = $XDeode->decode ( $sidKey );
  4320. $staffDetail = $staff->getStaffBySid ( $sid );
  4321. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4322. $cidList = array ();
  4323. foreach ( $imcStaff as $key => $value ) {
  4324. array_push ( $cidList, $value ['cid'] );
  4325. if (empty ( $cidKey ))
  4326. $cidKey = $XDeode->encode ( $value ['cid'] );
  4327. }
  4328. $cidString = implode ( ',', $cidList );
  4329. $staffList = $staff->getStaffInCid ( $cidString );
  4330. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4331. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  4332. $page_size = 10;
  4333. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4334. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4335. if ($timeType == "BINDOTP") {
  4336. $status = 'Credited';
  4337. }
  4338. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  4339. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  4340. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  4341. $dateArr = explode ( ':', $date );
  4342. $D1 = '';
  4343. $D2 = '';
  4344. if (! empty ( $date )) {
  4345. $D1 = $dateArr [0] . " 00:00:00 ";
  4346. if (isset ( $dateArr [1] ))
  4347. $D2 = $dateArr [1] . " 23:59:59 ";
  4348. else
  4349. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4350. }
  4351. $con = ' a.receivablesStaff like "%' . $staffDetail ['username'] . '%" ';
  4352. $descField = 'a.bindDate';
  4353. if ($timeType == 'CREATE')
  4354. $descField = 'a.date';
  4355. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4356. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4357. elseif (! empty ( $D1 ) && empty ( $D2 ))
  4358. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  4359. if ($status == 'Unclaimed')
  4360. $con .= ' and a.bindStatus=0';
  4361. elseif ($status == 'Credited')
  4362. $con .= ' and a.bindStatus=1';
  4363. elseif ($status == 'Claim')
  4364. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  4365. elseif ($status == 'BBN')
  4366. $con .= ' and a.bindPrice>a.receivablesPrice';
  4367. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  4368. if (! empty ( $MebSea )) {
  4369. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" )';
  4370. }
  4371. $pageinfo ['page'] = array (
  4372. 'previous' => ''
  4373. );
  4374. $sql = 'select group_concat(b.invoiceSerial) as invoiceSerial ,group_concat(b.iid) as invoiceId
  4375. from CLD_invoiceReceivables as a left join CLD_invoice as b on
  4376. find_in_set(b.iid,a.iidExtend) or a.iid=b.iid
  4377. where ' . $con . ' group by a.irid ';
  4378. $pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceAggregateStaffReceivablesDetail", $get, "" );
  4379. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4380. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', 'printTime' );
  4381. foreach ( $list as $key => $value ) {
  4382. $list [$key] ['category'] = '';
  4383. if ($value ['receivablesCategory'] != 'PUBLIC') {
  4384. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  4385. $list [$key] ['category'] = $receivablesCategory [1];
  4386. }
  4387. }
  4388. // print_r($list);
  4389. $this->data ['staffDetail'] = $staffDetail;
  4390. $this->data ['sidKey'] = $sidKey;
  4391. $this->data ['staffList'] = $staffList;
  4392. $this->data ['timeType'] = $timeType;
  4393. $this->data ['MebSeaEn'] = $MebSea;
  4394. $this->data ['MebSea'] = urlencode ( $MebSea );
  4395. $this->data ['date'] = $date;
  4396. $this->data ['page'] = $pageinfo;
  4397. $this->data ['get'] = $get;
  4398. $this->data ['list'] = $list;
  4399. $this->data ['status'] = $status;
  4400. $this->data ['memu'] = "invoice";
  4401. $this->data ['staff'] = $this->staff;
  4402. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4403. $this->render ( "/admin/invoiceAggregateStaffReceivablesDetail", $this->data );
  4404. }
  4405. function invoiceAchieve() {
  4406. Doo::loadModel ( 'invoice' );
  4407. $invoice = new invoice ();
  4408. Doo::loadClass ( 'XDeode' );
  4409. $XDeode = new XDeode ( 5 );
  4410. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4411. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4412. $page_size = 18;
  4413. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4414. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4415. $get = "/" . $date;
  4416. $con = '';
  4417. if ($date == 'MONTHO')
  4418. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4419. elseif ($date == 'MONTHT')
  4420. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4421. elseif ($date == 'MONTHY')
  4422. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4423. if (! empty ( $MebSea )) {
  4424. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4425. $get .= "/" . $MebSea;
  4426. }
  4427. $pageinfo ['page'] = array (
  4428. 'previous' => ''
  4429. );
  4430. $sql = 'status=2 and printStatus=1 and irid!="" and ( untreadStatus=3 or untreadStatus=0 ) and sid=' . $sid . $con;
  4431. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceAchieve", $get, "" );
  4432. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4433. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  4434. // print_r($pageinfo);
  4435. $this->data ['MebSeaEn'] = $MebSea;
  4436. $this->data ['MebSea'] = urlencode ( $MebSea );
  4437. $this->data ['get'] = $get;
  4438. $this->data ['page'] = $pageinfo;
  4439. $this->data ['list'] = $list;
  4440. $this->data ['date'] = $date;
  4441. $this->data ['memu'] = "invoice";
  4442. $this->data ['staff'] = $this->staff;
  4443. $this->data ['receiptMemu'] = 'invoice';
  4444. $this->render ( "/admin/invoiceAchieve", $this->data );
  4445. }
  4446. /**
  4447. */
  4448. function invoiceMyUnAccountAchieve() {
  4449. Doo::loadModel ( 'invoice' );
  4450. $invoice = new invoice ();
  4451. Doo::loadClass ( 'XDeode' );
  4452. $XDeode = new XDeode ( 5 );
  4453. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4454. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4455. $page_size = 18;
  4456. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4457. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4458. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4459. $dateArr = explode ( ':', $date );
  4460. $D1 = '';
  4461. $D2 = '';
  4462. if (! empty ( $date )) {
  4463. $D1 = $dateArr [0];
  4464. $D2 = $dateArr [1];
  4465. }
  4466. $con = '';
  4467. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4468. $con = ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4469. if (! empty ( $MebSea )) {
  4470. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4471. }
  4472. $pageinfo ['page'] = array (
  4473. 'previous' => ''
  4474. );
  4475. // and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  4476. $sql = " status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid= " . $sid . $con;
  4477. $action = "invoiceMyUnAccountAchieve";
  4478. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  4479. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4480. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 'desc', 'printTime' );
  4481. Doo::loadModel ( 'express' );
  4482. $express = new express ();
  4483. $expressList = $express->getExpressByAll ();
  4484. $this->data ['expressList'] = $expressList;
  4485. // print_r($list);
  4486. $this->data ['MebSeaEn'] = $MebSea;
  4487. $this->data ['get'] = $get;
  4488. $this->data ['page'] = $pageinfo;
  4489. $this->data ['date'] = $date;
  4490. $this->data ['list'] = $list;
  4491. $this->data ['memu'] = "invoice";
  4492. $this->data ['staff'] = $this->staff;
  4493. $this->data ['receiptMemu'] = 'invoice';
  4494. $this->render ( "/admin/invoiceMyUnAccountAchieve", $this->data );
  4495. }
  4496. function invoiceReceivablesAchieve() {
  4497. Doo::loadModel ( 'invoiceReceivables' );
  4498. $invoiceReceivables = new invoiceReceivables ();
  4499. Doo::loadClass ( 'XDeode' );
  4500. $XDeode = new XDeode ( 5 );
  4501. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4502. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  4503. $page_size = 12;
  4504. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4505. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4506. $get = "/" . $date;
  4507. $con = '';
  4508. if ($date == 'MONTHO')
  4509. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4510. elseif ($date == 'MONTHT')
  4511. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4512. elseif ($date == 'MONTHY')
  4513. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4514. if (! empty ( $MebSea )) {
  4515. $con .= ' and ( receivablesMessage like "%' . $MebSea . '%" or receivablesPrice like "%' . $MebSea . '%" )';
  4516. $get .= "/" . $MebSea;
  4517. }
  4518. $pageinfo ['page'] = array (
  4519. 'previous' => ''
  4520. );
  4521. $sql = " bindStatus=1 and receivablesStaff like '" . $sid . "-%' " . $con;
  4522. $pageinfo = $this->get_page ( "CLD_invoiceReceivables", $sql, $page, $page_size, "invoiceReceivablesAchieve", $get, "" );
  4523. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4524. $list = $invoiceReceivables->getReceivablesByUntreadStatusPage ( $limit, $sql );
  4525. // print_r($pageinfo);
  4526. $this->data ['MebSeaEn'] = $MebSea;
  4527. $this->data ['MebSea'] = urlencode ( $MebSea );
  4528. $this->data ['get'] = $get;
  4529. $this->data ['page'] = $pageinfo;
  4530. $this->data ['list'] = $list;
  4531. $this->data ['date'] = $date;
  4532. $this->data ['memu'] = "invoice";
  4533. $this->data ['staff'] = $this->staff;
  4534. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  4535. $this->render ( "/admin/invoiceReceivablesAchieve", $this->data );
  4536. }
  4537. /**
  4538. * 收款解绑
  4539. */
  4540. function invoiceUnBundLing() {
  4541. $unBundKey = $this->get_args ( 'unBundKey' ) ? $this->get_args ( 'unBundKey' ) : '';
  4542. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  4543. Doo::loadModel ( 'invoice' );
  4544. $invoice = new invoice ();
  4545. Doo::loadModel ( 'invoiceReceivables' );
  4546. $invoiceReceivables = new invoiceReceivables ();
  4547. Doo::loadModel ( 'invoiceOperationLog' );
  4548. $invoiceOperationLog = new invoiceOperationLog ();
  4549. Doo::loadModel ( 'invoiceROLog' );
  4550. $invoiceROLog = new invoiceROLog ();
  4551. Doo::loadModel ( 'invoiceStatistics' );
  4552. Doo::loadClass ( 'XDeode' );
  4553. $XDeode = new XDeode ( 5 );
  4554. if (empty ( $iidKey ) || empty ( $unBundKey ))
  4555. die ( 'illegal request' );
  4556. $iid = $XDeode->decode ( $iidKey );
  4557. $irid = $invoice->authcode ( $unBundKey );
  4558. if ((! empty ( $irid ) && ! is_numeric ( $irid )) || (! empty ( $iid ) && ! is_numeric ( $iid )))
  4559. die ( 'illegal request' );
  4560. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4561. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  4562. if (empty ( $irDetails ) || empty ( $invoiceDetails ) || (empty ( $irDetails ['iid'] ) && empty ( $irDetails ['iidExtend'] )) || $invoiceDetails ['untreadStatus'] == 2)
  4563. die ( 'illegal request' );
  4564. // 收款
  4565. $item = array (
  4566. 'irid' => $irDetails ['irid'],
  4567. 'bindPrice' => $irDetails ['bindPrice'] - $invoiceDetails ['invoicePrice'],
  4568. 'bindStatus' => 0
  4569. );
  4570. if ($irDetails ['iid'] == $iid)
  4571. $item += array (
  4572. 'iid' => 0
  4573. );
  4574. else {
  4575. $iidExtend = explode ( ',', $irDetails ['iidExtend'] );
  4576. foreach ( $iidExtend as $key => $value ) {
  4577. if ($value == $iid)
  4578. unset ( $iidExtend [$key] );
  4579. }
  4580. $iidExtend = implode ( ',', $iidExtend );
  4581. $item += array (
  4582. 'iidExtend' => $iidExtend
  4583. );
  4584. }
  4585. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4586. // 收款操作日志
  4587. $item = array (
  4588. 'operation' => $this->staff [0] ['username'] . " 解绑 " . $irDetails ['receivablesSerial'],
  4589. 'date' => date ( "Y-m-d" ),
  4590. 'status' => 3,
  4591. 'img' => $this->staff [0] ['avatar'],
  4592. 'username' => $this->staff [0] ['username'],
  4593. 'uid' => $this->staff [0] ['sid'],
  4594. 'category' => $this->staff [0] ['category'],
  4595. 'irid' => $irid
  4596. );
  4597. $invoiceROLog->setInvoiceROLog ( $item );
  4598. // 扣除入账统计金额
  4599. $invoiceStatistics = new invoiceStatistics ();
  4600. $item = array (
  4601. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  4602. 'priceClass' => 3,
  4603. 'cid' => $invoiceDetails ['cid'],
  4604. 'staff' => $invoiceDetails ['sid'],
  4605. 'accountPrice' => - $irDetails ['receivablesPrice']
  4606. );
  4607. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4608. // 扣除收款统计金额
  4609. $invoiceStatistics = new invoiceStatistics ();
  4610. $item = array (
  4611. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  4612. 'priceClass' => 2,
  4613. 'cid' => $invoiceDetails ['cid'],
  4614. 'staff' => $invoiceDetails ['sid'],
  4615. 'irid' => $irDetails ['irid'],
  4616. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  4617. );
  4618. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4619. // 发票解绑去收款ID
  4620. $iridString = $invoiceDetails ['irid'];
  4621. if (! empty ( $invoiceDetails ['irid'] )) {
  4622. $list = explode ( ',', $invoiceDetails ['irid'] );
  4623. foreach ( $list as $key => $value ) {
  4624. if ($value == $irDetails ['irid']) {
  4625. unset ( $list [$key] );
  4626. break;
  4627. }
  4628. }
  4629. $iridString = implode ( ",", $list );
  4630. }
  4631. $item = array (
  4632. 'iid' => $invoiceDetails ['iid'],
  4633. 'irid' => $iridString,
  4634. 'updateTime' => date ( "Y-m-d H:i:s" )
  4635. );
  4636. if ($invoiceDetails ['untreadStatus'] == 3)
  4637. $item += array (
  4638. 'untreadStatus' => 0
  4639. );
  4640. $invoice->setInvoiceByCondition ( $item );
  4641. $item = array (
  4642. 'date' => date ( "Y-m-d H:i:s" ),
  4643. 'operation' => '解绑 收款 ' . $irDetails ['receivablesSerial'],
  4644. 'status' => 11,
  4645. 'img' => $this->staff [0] ['avatar'],
  4646. 'username' => $this->staff [0] ['username'],
  4647. 'uid' => $this->staff [0] ['sid'],
  4648. 'category' => $this->staff [0] ['category'],
  4649. 'iid' => $invoiceDetails ['iid']
  4650. );
  4651. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  4652. // 公司流水-解绑时删除流水
  4653. Doo::loadModel ( 'wasteBook' );
  4654. $wasteBook = new wasteBook ();
  4655. // $wasteBook->delete ( array (
  4656. // 'where' => 'dataID=' . $irDetails ['irid'] . ' and accountType=7',
  4657. // 'limit' => 1
  4658. // ) );
  4659. // 银行
  4660. /*
  4661. * $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); }
  4662. */
  4663. return "/invoiceReceivablesAS";
  4664. }
  4665. /**
  4666. * 或者该收款下的所以发票
  4667. */
  4668. function ajaxGetInvoiceReceivablesByInvoice() {
  4669. $irid = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : '';
  4670. Doo::loadModel ( 'invoice' );
  4671. $invoice = new invoice ();
  4672. Doo::loadModel ( 'invoiceReceivables' );
  4673. $invoiceReceivables = new invoiceReceivables ();
  4674. $irid = $invoice->authcode ( $irid );
  4675. if (! empty ( $irid ) && ! is_numeric ( $irid ))
  4676. die ( 'illegal request' );
  4677. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4678. $iidString = $irDetails ['iid'];
  4679. $iidExtend = array_filter ( explode ( ',', $irDetails ['iidExtend'] ) );
  4680. if (! empty ( $irDetails ['iidExtend'] ))
  4681. $iidString .= ',' . implode ( ',', $iidExtend );
  4682. $invoiceList = $invoice->getInvoiceInIid ( $iidString, 'iid,invoiceSerial,invoicePrice,invoiceTitle,invoiceCompany,invoiceElement' );
  4683. $html = "";
  4684. foreach ( $invoiceList as $key => $value ) {
  4685. $title = $value ['invoiceTitle'];
  4686. if (! empty ( $value ['invoiceCompany'] ))
  4687. $title = $value ['invoiceCompany'];
  4688. $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>';
  4689. }
  4690. echo json_encode ( array (
  4691. 'status' => 1,
  4692. 'html' => $html
  4693. ) );
  4694. }
  4695. /**
  4696. * 发票管理
  4697. */
  4698. function invoiceAS() {
  4699. Doo::loadModel ( 'invoice' );
  4700. $invoice = new invoice ();
  4701. Doo::loadModel ( 'invoiceReceivables' );
  4702. $invoiceReceivables = new invoiceReceivables ();
  4703. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4704. $page_size = 18;
  4705. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4706. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4707. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4708. $dateArr = explode ( ':', $date );
  4709. $D1 = '';
  4710. $D2 = '';
  4711. if (! empty ( $date )) {
  4712. $D1 = $dateArr [0] . " 00:00:00 ";
  4713. if (isset ( $dateArr [1] ))
  4714. $D2 = $dateArr [1] . " 23:59:59 ";
  4715. else
  4716. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4717. // $D2 = $dateArr [1];
  4718. }
  4719. $con = ' status=2 ';
  4720. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4721. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4722. if ($status == 'UNRECORD')
  4723. $con .= ' and printStatus=1 and untreadStatus=0';
  4724. elseif ($status == 'RECORD')
  4725. $con .= ' and printStatus=1 and untreadStatus=3';
  4726. elseif ($status == 'BOUNCED')
  4727. $con .= ' and untreadStatus=2';
  4728. elseif ($status == 'PARTRECORD')
  4729. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  4730. elseif ($status == 'All') {
  4731. $con .= ' and ( untreadStatus=2 or untreadStatus=1 or untreadStatus=0 or untreadStatus=3 )';
  4732. }
  4733. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4734. if (! empty ( $MebSea )) {
  4735. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  4736. }
  4737. $pageinfo ['page'] = array (
  4738. 'previous' => ''
  4739. );
  4740. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAS", $get, "" );
  4741. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4742. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  4743. $this->data ['MebSeaEn'] = $MebSea;
  4744. $this->data ['MebSea'] = urlencode ( $MebSea );
  4745. $this->data ['date'] = $date;
  4746. $this->data ['page'] = $pageinfo;
  4747. $this->data ['get'] = $get;
  4748. $this->data ['list'] = $list;
  4749. $this->data ['status'] = $status;
  4750. $this->data ['memu'] = "invoice";
  4751. $this->data ['staff'] = $this->staff;
  4752. $this->data ['receiptMemu'] = 'invoiceReceivables';
  4753. $this->render ( "/admin/invoiceAS", $this->data );
  4754. }
  4755. /**
  4756. * 收款管理
  4757. */
  4758. function invoiceReceivablesAS() {
  4759. Doo::loadModel ( 'invoiceReceivables' );
  4760. $invoiceReceivables = new invoiceReceivables ();
  4761. Doo::loadModel ( 'L_category' );
  4762. $lCategory = new L_category ();
  4763. $category = $lCategory->getCategory ();
  4764. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4765. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  4766. $page_size = 10;
  4767. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4768. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4769. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4770. $dateArr = explode ( ':', $date );
  4771. $D1 = '';
  4772. $D2 = '';
  4773. if (! empty ( $date )) {
  4774. $D1 = $dateArr [0]; // ." 00:00:00 ";
  4775. if (isset ( $dateArr [1] ))
  4776. $D2 = $dateArr [1]; // ." 23:59:59 ";
  4777. else
  4778. $D2 = $dateArr [0]; // ." 23:59:59 ";//date ( "Y-m-d" );
  4779. }
  4780. $descField = 'a.receivablesDate';
  4781. if ($timeType == 'CREATE')
  4782. $descField = 'a.date';
  4783. $con = '1';
  4784. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4785. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4786. elseif (! empty ( $D1 ) && empty ( $D2 ))
  4787. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  4788. if ($status == 'Unclaimed')
  4789. $con .= ' and a.bindStatus=0';
  4790. elseif ($status == 'Credited')
  4791. $con .= ' and a.bindStatus=1';
  4792. elseif ($status == 'Claim')
  4793. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  4794. elseif ($status == 'BBN')
  4795. $con .= ' and a.bankBatchNumber!=""';
  4796. elseif ($status == 'REFUND')
  4797. $con .= ' and ( (a.bindStatus=0 and a.refundLog!="" ) or a.bindStatus=2)';
  4798. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4799. if (! empty ( $MebSea )) {
  4800. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" or a.receivablesSerial like "%' . $MebSea . '%" )';
  4801. }
  4802. $pageinfo ['page'] = array (
  4803. 'previous' => ''
  4804. );
  4805. $sql = 'select group_concat(b.invoiceSerial) as invoiceSerial ,group_concat(b.iid) as invoiceId
  4806. from CLD_invoiceReceivables as a left join CLD_invoice as b on
  4807. find_in_set(b.iid,a.iidExtend) or a.iid=b.iid
  4808. where ' . $con . ' group by a.irid ';
  4809. $pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceReceivablesAS", $get, "" );
  4810. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4811. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', $descField );
  4812. foreach ( $list as $key => $value ) {
  4813. $list [$key] ['category'] = '';
  4814. if ($value ['receivablesCategory'] != 'PUBLIC') {
  4815. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  4816. $list [$key] ['category'] = $receivablesCategory [1];
  4817. }
  4818. }
  4819. // print_r($list);
  4820. $this->data ['category'] = $category;
  4821. $this->data ['timeType'] = $timeType;
  4822. $this->data ['MebSeaEn'] = $MebSea;
  4823. $this->data ['MebSea'] = urlencode ( $MebSea );
  4824. $this->data ['date'] = $date;
  4825. $this->data ['page'] = $pageinfo;
  4826. $this->data ['get'] = $get;
  4827. $this->data ['list'] = $list;
  4828. $this->data ['status'] = $status;
  4829. $this->data ['memu'] = "invoice";
  4830. $this->data ['staff'] = $this->staff;
  4831. $this->data ['receiptMemu'] = 'invoiceReceivables';
  4832. $this->render ( "/admin/invoiceReceivablesAS", $this->data );
  4833. }
  4834. /**
  4835. * 删除一条收款
  4836. */
  4837. function delInvoiceReceivables() {
  4838. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  4839. if (empty ( $iridKey ))
  4840. die ( 'illegal request' );
  4841. Doo::loadClass ( 'XDeode' );
  4842. $XDeode = new XDeode ( 5 );
  4843. $irid = $XDeode->decode ( $iridKey );
  4844. Doo::loadModel ( 'invoiceReceivables' );
  4845. $invoiceReceivables = new invoiceReceivables ();
  4846. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4847. if (empty ( $detail ))
  4848. die ( 'illegal request' );
  4849. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  4850. // 扣除收款汇总信息 汇总
  4851. Doo::loadModel ( 'invoiceStatistics' );
  4852. $invoiceStatistics = new invoiceStatistics ();
  4853. $item = array (
  4854. 'date' => $detail ['receivablesDate'],
  4855. 'priceClass' => 2,
  4856. 'irid' => $detail ['irid'],
  4857. 'receivablesPrice' => - $detail ['receivablesPrice']
  4858. );
  4859. if ($detail ['receivablesCategory'] != 'PUBLIC') {
  4860. $receivablesCategory = explode ( ":", $detail ['receivablesCategory'] );
  4861. $item += array (
  4862. 'cid' => $receivablesCategory [0]
  4863. );
  4864. }
  4865. if ($detail ['receivablesStaff'] != 'PUBLIC') {
  4866. $receivablesStaff = explode ( "-", $detail ['receivablesStaff'] );
  4867. $item += array (
  4868. 'staff' => $receivablesStaff [0]
  4869. );
  4870. }
  4871. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4872. return '/invoiceReceivablesAS';
  4873. }
  4874. /**
  4875. * 添加退款信息
  4876. */
  4877. function setInvoiceReceivablesRefund() {
  4878. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  4879. $refundType = $this->get_args ( 'refundType' ) && is_numeric ( $this->get_args ( 'refundType' ) ) ? $this->get_args ( 'refundType' ) : '0';
  4880. $refundCompany = $this->get_args ( 'refundCompany' ) ? $this->get_args ( 'refundCompany' ) : "";
  4881. $refundNumber = $this->get_args ( 'refundNumber' ) ? $this->get_args ( 'refundNumber' ) : "";
  4882. $refundPrice = $this->get_args ( 'refundPrice' ) ? $this->get_args ( 'refundPrice' ) : "";
  4883. $refundRemarks = $this->get_args ( 'refundRemarks' ) ? $this->get_args ( 'refundRemarks' ) : "";
  4884. if ($refundPrice < 0)
  4885. die ( 'illegal request' );
  4886. if (! empty ( $iridKey ) && ! empty ( $refundCompany ) && ! empty ( $refundNumber ) && ! empty ( $refundPrice )) {
  4887. Doo::loadModel ( 'invoiceReceivables' );
  4888. $invoiceReceivables = new invoiceReceivables ();
  4889. Doo::loadModel ( 'invoiceRefund' );
  4890. $invoiceRefund = new invoiceRefund ();
  4891. $irid = $invoiceReceivables->authcode ( $iridKey );
  4892. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4893. if ($irDetail ['receivablesPrice'] < $refundPrice)
  4894. die ( 'illegal request' );
  4895. $invoiceReceivables = new invoiceReceivables ();
  4896. $refundLog = $this->staff [0] ['username'] . ' 退款 <b class="colRed">¥' . $refundPrice . '</b>
  4897. <br/><a href="#refunded" onclick="getRefundByDetail(\'' . $iridKey . '\')" data-toggle="modal">退款信息</a> <br/>' . date ( "Y-m-d H:i:s" ) . '
  4898. ';
  4899. $item = array (
  4900. 'irid' => $irid,
  4901. 'refundCompany' => $refundCompany,
  4902. 'refundNumber' => $refundNumber,
  4903. 'refundPrice' => $refundPrice,
  4904. 'refundRemarks' => $refundRemarks,
  4905. 'refundLog' => $refundLog
  4906. );
  4907. if ($refundType == 1) {
  4908. $item += array (
  4909. 'refundType' => $refundType,
  4910. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice,
  4911. 'bindStatus' => 2
  4912. );
  4913. } elseif ($refundType == 0 && $irDetail ['receivablesPrice'] <= $refundPrice) {
  4914. $item += array (
  4915. 'refundType' => 1,
  4916. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice,
  4917. 'bindStatus' => 2
  4918. );
  4919. } else {
  4920. $item += array (
  4921. 'refundType' => $refundType,
  4922. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice
  4923. );
  4924. }
  4925. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4926. // 添加退款记录
  4927. $item = array (
  4928. 'irid' => $irid,
  4929. 'refundType' => $refundType,
  4930. 'refundCompany' => $refundCompany,
  4931. 'refundNumber' => $refundNumber,
  4932. 'refundPrice' => $refundPrice,
  4933. 'refundLog' => $refundLog,
  4934. 'refundRemarks' => $refundRemarks,
  4935. 'date' => date ( "Y-m-d H:i:s" )
  4936. );
  4937. $invoiceRefund->addInvoiceRefund ( $item );
  4938. // 扣除收款汇总信息 汇总
  4939. Doo::loadModel ( 'invoiceStatistics' );
  4940. $invoiceStatistics = new invoiceStatistics ();
  4941. $item = array (
  4942. 'date' => $irDetail ['receivablesDate'],
  4943. 'priceClass' => 2,
  4944. 'irid' => $irDetail ['irid'],
  4945. 'receivablesPrice' => - $refundPrice
  4946. );
  4947. if ($irDetail ['receivablesCategory'] != 'PUBLIC') {
  4948. $receivablesCategory = explode ( ":", $irDetail ['receivablesCategory'] );
  4949. $item += array (
  4950. 'cid' => $receivablesCategory [0]
  4951. );
  4952. }
  4953. if ($irDetail ['receivablesStaff'] != 'PUBLIC') {
  4954. $receivablesStaff = explode ( "-", $irDetail ['receivablesStaff'] );
  4955. $item += array (
  4956. 'staff' => $receivablesStaff [0]
  4957. );
  4958. }
  4959. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4960. // 公司日常支出流水
  4961. Doo::loadModel ( 'wasteBook' );
  4962. $wasteBook = new wasteBook ();
  4963. $accountBank = '';
  4964. if ($irDetail ['receivablesBank'] == '纵横广发') {
  4965. $accountBank = 'CGBDeposit';
  4966. } elseif ($irDetail ['receivablesBank'] == '纵横工行') {
  4967. $accountBank = 'ICBCDeposit';
  4968. } elseif ($irDetail ['receivablesBank'] == '华润银行') {
  4969. $accountBank = 'HUADeposit';
  4970. } elseif ($irDetail ['receivablesBank'] == '个人广发') {
  4971. $accountBank = 'PersonalDeposit';
  4972. }
  4973. $itemWaste = array (
  4974. 'accountPrice' => - $refundPrice,
  4975. 'expensesType' => 2,
  4976. 'accountType' => 11,
  4977. 'accountPriceShow' => $refundPrice,
  4978. 'dataID' => $irid,
  4979. 'accountBank' => $accountBank,
  4980. 'category' => $this->staff [0] ['category'],
  4981. 'cid' => $this->staff [0] ['cid'],
  4982. 'name' => $this->staff [0] ['username'],
  4983. 'sid' => $this->staff [0] ['sid'],
  4984. 'inputDate' => date ( "Y-m-d H:i:s" )
  4985. );
  4986. $wasteBook->setAccountBookStatistics ( $itemWaste );
  4987. return '/invoiceReceivablesAS';
  4988. }
  4989. die ( 'illegal request' );
  4990. }
  4991. function ajaxCheckInvoiceReceivablesRefund() {
  4992. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  4993. $refundPrice = $this->get_args ( 'refundPrice' ) ? $this->get_args ( 'refundPrice' ) : "";
  4994. if ($refundPrice < 0) {
  4995. echo json_encode ( array (
  4996. 'error' => '金额不能为负'
  4997. ) );
  4998. die ();
  4999. }
  5000. if (! empty ( $refundPrice ) && ! empty ( $iridKey )) {
  5001. Doo::loadModel ( 'invoiceReceivables' );
  5002. $invoiceReceivables = new invoiceReceivables ();
  5003. $irid = $invoiceReceivables->authcode ( $iridKey );
  5004. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5005. if ($irDetail ['receivablesPrice'] < $refundPrice) {
  5006. echo json_encode ( array (
  5007. 'error' => '退款金额不能超过收款金额'
  5008. ) );
  5009. die ();
  5010. }
  5011. echo json_encode ( array (
  5012. 'ok' => '可以使用!'
  5013. ) );
  5014. die ();
  5015. }
  5016. }
  5017. /**
  5018. * 获得收款退款信息
  5019. */
  5020. function getRefundByDetail() {
  5021. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5022. Doo::loadModel ( 'invoiceReceivables' );
  5023. $invoiceReceivables = new invoiceReceivables ();
  5024. if (! empty ( $iridKey )) {
  5025. $irid = $invoiceReceivables->authcode ( $iridKey );
  5026. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5027. echo json_encode ( array (
  5028. 'status' => 1,
  5029. 'irDetail' => $irDetail
  5030. ) );
  5031. die ();
  5032. }
  5033. echo json_encode ( array (
  5034. 'status' => 2
  5035. ) );
  5036. }
  5037. /**
  5038. * 根据收款序列号获得收款退款信息
  5039. */
  5040. function ajaxGetInvoiceReceivablesBySerial() {
  5041. $receivablesSerial = $this->get_args ( 'receivablesSerial' ) ? $this->get_args ( 'receivablesSerial' ) : '';
  5042. if (! empty ( $receivablesSerial )) {
  5043. Doo::loadModel ( 'invoiceReceivables' );
  5044. $invoiceReceivables = new invoiceReceivables ();
  5045. // , ' and refundLog=""'
  5046. $irDetail = $invoiceReceivables->getInvoiceReceivablesBySerial ( $receivablesSerial );
  5047. $html = '';
  5048. if (! empty ( $irDetail ))
  5049. $html = '<td><b>¥' . $irDetail ['receivablesPrice'] . '</b></td>
  5050. <td>' . $irDetail ['receivablesMessage'] . '</td>
  5051. <td>' . $irDetail ['receivablesBank'] . '<br>' . $irDetail ['receivablesDate'] . '</td>
  5052. <td>' . $irDetail ['title'] . '-' . $irDetail ['username'] . '<br>' . $irDetail ['confirmTime'] . '</td>
  5053. <td>' . $irDetail ['recepitTitleMark'] . '
  5054. <input type="hidden" name="iridKey" id="iridKey" value="' . $irDetail ['iridKey'] . '">
  5055. </td>';
  5056. echo json_encode ( array (
  5057. 'status' => 1,
  5058. 'html' => $html,
  5059. 'irDetail' => $irDetail
  5060. ) );
  5061. die ();
  5062. }
  5063. echo json_encode ( array (
  5064. 'status' => 2
  5065. ) );
  5066. }
  5067. /**
  5068. * 绑定新收款
  5069. */
  5070. function relationNewInvoiceReceivables() {
  5071. $iridKeyOld = $this->get_args ( 'iridKeyOld' ) ? $this->get_args ( 'iridKeyOld' ) : '';
  5072. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5073. if (! empty ( $iridKeyOld ) && ! empty ( $iridKey )) {
  5074. Doo::loadModel ( 'invoiceReceivables' );
  5075. $invoiceReceivables = new invoiceReceivables ();
  5076. Doo::loadClass ( 'XDeode' );
  5077. $XDeode = new XDeode ( 5 );
  5078. $irid = $XDeode->decode ( $iridKey );
  5079. $iridOld = $invoiceReceivables->authcode ( $iridKeyOld );
  5080. echo $irid . 'bbb' . $iridOld;
  5081. $oldIrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $iridOld );
  5082. $IrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5083. if (empty ( $oldIrDetail ) || empty ( $IrDetail ))
  5084. die ( 'illegal request' );
  5085. $relationLog = $this->staff [0] ['username'] . ' 关联新款 <a href="#billing" onclick="invoiceReceivblesDivShow(\'' . $iridKey . '\',\'receivables\')" data-toggle="modal">' . $IrDetail ['receivablesSerial'] . '</a>
  5086. <br/>' . date ( "Y-m-d H:i:s" ) . '
  5087. ';
  5088. $invoiceReceivables = new invoiceReceivables ();
  5089. $item = array (
  5090. 'irid' => $iridOld,
  5091. 'relationIrid' => $irid,
  5092. 'relationLog' => $relationLog
  5093. );
  5094. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  5095. return '/invoiceReceivablesAS';
  5096. }
  5097. die ( 'illegal request' );
  5098. }
  5099. // function invoiceApprovalAchieve() {
  5100. // Doo::loadModel ( 'invoice' );
  5101. // $invoice = new invoice ();
  5102. // $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  5103. // $page_size = 12;
  5104. // $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5105. // $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  5106. // $get = "/" . $date;
  5107. // $con = '';
  5108. // if ($date == 'MONTHO')
  5109. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  5110. // elseif ($date == 'MONTHT')
  5111. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  5112. // elseif ($date == 'MONTHY')
  5113. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  5114. // if (! empty ( $MebSea )) {
  5115. // $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  5116. // $get .= "/" . $MebSea;
  5117. // }
  5118. // $pageinfo ['page'] = array (
  5119. // 'previous' => ''
  5120. // );
  5121. // $sql = '(status=1 or status=2 or status=3 or status=4) and processApprovals!=""' . $con; // echo $sql;
  5122. // $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", $get, "" );
  5123. // $limit = $pageinfo ['lower'] . ',' . $page_size;
  5124. // $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  5125. // // print_r($list);
  5126. // $this->data ['MebSeaEn'] = $MebSea;
  5127. // $this->data ['MebSea'] = urlencode ( $MebSea );
  5128. // $this->data ['get'] = $get;
  5129. // $this->data ['page'] = $pageinfo;
  5130. // $this->data ['list'] = $list;
  5131. // $this->data ['date'] = $date;
  5132. // $this->data ['memu'] = "invoice";
  5133. // $this->data ['staff'] = $this->staff;
  5134. // $this->data ['receiptMemu'] = 'invoiceApproval';
  5135. // $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  5136. // }
  5137. /**
  5138. * 获得审批发票的信息以及审批页面
  5139. */
  5140. function ajaxGetInvoiceApprovalDetail() {
  5141. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5142. if (empty ( $serial )) {
  5143. echo json_encode ( array (
  5144. 'status' => 2,
  5145. 'msg' => 'illegal request'
  5146. ) );
  5147. die ();
  5148. }
  5149. Doo::loadModel ( 'invoice' );
  5150. $invoice = new invoice ();
  5151. Doo::loadModel ( 'invoiceOperationLog' );
  5152. $invoiceOperationLog = new invoiceOperationLog ();
  5153. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5154. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5155. if (empty ( $detail ))
  5156. $html = '';
  5157. else {
  5158. $html = '
  5159. <form action="/invoiceApprovalDo" method="post" name="invoiceApproval" class="nice-validator n-yellow" novalidate="novalidate">
  5160. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  5161. <input type="hidden" name="status" value="">
  5162. <input type="hidden" name="divApproval" value="divApproval">
  5163. <div class="modal-dialog modal-lg">
  5164. <div class="modal-content"><div class="modal-header"><h3>发票审批详情</h3></div>
  5165. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  5166. <tr>
  5167. <th class="taC" width="150">发票审批</th><td><textarea name="opinion" style="width:98%" placeholder="在这写下您的审批意见,选填。"></textarea></td>
  5168. </tr>
  5169. <tr>
  5170. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5171. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5172. </tr>
  5173. <tr>
  5174. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5175. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5176. </tr>
  5177. <tr>
  5178. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5179. </td>
  5180. </tr>
  5181. <tr>
  5182. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5183. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5184. </tr>
  5185. <tr>
  5186. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5187. </tr></tbody></table>';
  5188. if ($detail ['invoiceType'] == 0)
  5189. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5190. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5191. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5192. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5193. </tr>';
  5194. else
  5195. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5196. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5197. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5198. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5199. ';
  5200. $html .= '<tr>
  5201. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5202. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5203. </tr>
  5204. <tr>
  5205. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5206. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5207. </tr></tbody></table>';
  5208. if ($detail ['doPost'] == 1) {
  5209. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5210. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5211. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5212. </tr><tr>
  5213. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5214. </tr><tr>
  5215. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5216. </tr>
  5217. ';
  5218. if ($detail ['expressCom'] == 'SF')
  5219. $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>';
  5220. else
  5221. $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>';
  5222. $html .= '</tbody></table>';
  5223. }
  5224. if (! empty ( $invoiceOperationLogList )) {
  5225. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  5226. foreach ( $invoiceOperationLogList as $key => $value ) {
  5227. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5228. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5229. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5230. if ($value ['status'] == 2) {
  5231. $html .= '<span class="colGreen">同意</span>';
  5232. } elseif ($value ['status'] == 3) {
  5233. $html .= '<span class="colOrange">退回</span>';
  5234. } elseif ($value ['status'] == 5) {
  5235. $html .= '<span class="colGreen">打印</span>';
  5236. } elseif ($value ['status'] == 4) {
  5237. $html .= '<span class="colRed">终止</span>';
  5238. }
  5239. $html .= $value ['operation'] . '</p></blockquote>';
  5240. }
  5241. }
  5242. $html .= '</td></tr></tbody></table>';
  5243. }
  5244. $html .= '</div><div class="modal-footer">
  5245. <a href="javascript:void(0)" node-approval="approval" diss-data="2" class="button btn-done" data-placement="top" data-toggle="ctooltip" >同意</a>
  5246. <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>
  5247. <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>
  5248. <a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>
  5249. </form>
  5250. <script type="text/javascript">
  5251. $("a[node-approval^=\'approval\']").click(function() {
  5252. $("input[name=\'status\']").val($(this).attr("diss-data"));
  5253. $("form[name=\'invoiceApproval\']").submit();
  5254. });
  5255. </script>
  5256. ';
  5257. }
  5258. echo json_encode ( array (
  5259. 'status' => 1,
  5260. 'html' => $html
  5261. ) );
  5262. die ();
  5263. }
  5264. /**
  5265. * 获得审批发票分页数据
  5266. */
  5267. function ajaxGetinvoiceApprovalAchieve() {
  5268. Doo::loadModel ( 'invoice' );
  5269. $invoice = new invoice ();
  5270. Doo::loadModel ( 'staff' );
  5271. $staff = new staff ();
  5272. Doo::loadClass ( 'XDeode' );
  5273. $XDeode = new XDeode ( 5 );
  5274. Doo::loadModel ( 'invoiceTraining' );
  5275. $invoiceTraining = new invoiceTraining ();
  5276. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  5277. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5278. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5279. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5280. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5281. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  5282. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  5283. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  5284. $MebSea = $this->get_args ( 'search' );
  5285. $MebSea = $MebSea ['value'];
  5286. $page_size = $length;
  5287. $con = '';
  5288. if ($status == 'ALL')
  5289. $con = ' (status=1 or status=2 or status=3 or status=4) and isDelete=0 ';
  5290. elseif ($status == 'PEND')
  5291. $con = ' isDelete=0 and status=1';
  5292. elseif ($status == 'APPROVED')
  5293. $con = ' isDelete=0 and status=2';
  5294. if ($invoiceType == 'ORDINARY')
  5295. $con .= ' and invoiceType=0 ';
  5296. elseif ($invoiceType == 'SPECIAL')
  5297. $con .= ' and invoiceType=1 ';
  5298. if ($invoiceTrain == 'ORDINARY')
  5299. $con .= ' and trainId=0 ';
  5300. elseif ($invoiceTrain == 'TRAIN')
  5301. $con .= ' and trainId!=0 ';
  5302. if ($invoiceTrainName != 'ALL') {
  5303. $trainId = $XDeode->decode ( $invoiceTrainName );
  5304. if (is_numeric ( $trainId ))
  5305. $con .= ' and trainId =' . $trainId;
  5306. }
  5307. $dateArr = explode ( ':', $date );
  5308. $D1 = $dateString = '';
  5309. $D2 = '';
  5310. if (! empty ( $date )) {
  5311. $D1 = $dateArr [0];
  5312. if (isset ( $dateArr [1] ))
  5313. $D2 = $dateArr [1];
  5314. else
  5315. $D2 = '';
  5316. $dateString = $D1 . " : " . $D2;
  5317. }
  5318. if (! empty ( $D1 ) && ! empty ( $D2 ))
  5319. $con .= ' and approvalTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  5320. elseif (! empty ( $D1 ) && empty ( $D2 ))
  5321. $con .= ' and approvalTime like "%' . $D1 . '%" ';
  5322. if (! empty ( $MebSea ))
  5323. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceSerial like "%' . $MebSea . '%" )';
  5324. // /
  5325. $pageinfo ['page'] = array (
  5326. 'previous' => ''
  5327. );
  5328. $sql = ' ' . $con;
  5329. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", '', "" );
  5330. $limit = $page . ',' . $page_size;
  5331. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  5332. $approvalList = array ();
  5333. $html = '<script type="text/javascript">
  5334. </script>';
  5335. // 结算结束不能修改方式
  5336. Doo::loadModel ( 'receipt' );
  5337. $receipt = new receipt ();
  5338. foreach ( $list as $key => $value ) {
  5339. $irDetail = array ();
  5340. // 结算方式
  5341. $receiptDetail = array ();
  5342. if ($value ['trainId'] != 0) {
  5343. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $value ['trainId'] );
  5344. }
  5345. if (! empty ( $receiptDetail )) {
  5346. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9) {
  5347. array_push ( $irDetail, '' );
  5348. } else {
  5349. if ($value ['status'] == 1 && $value ['pendingApprovals'] == $this->staff [0] ['sid']) {
  5350. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoiceApproval(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">审批发票</a>' );
  5351. } elseif ($value ['status'] == 2) {
  5352. array_push ( $irDetail, '<a href="#editPay" class="fnSettlementType" data-iidKey="' . $value ['iidKeyK'] . '" data-toggle="modal">结算方式</a>' );
  5353. } else
  5354. array_push ( $irDetail, '' );
  5355. }
  5356. } else {
  5357. if ($value ['status'] == 2) {
  5358. array_push ( $irDetail, '<a href="#editPay" class="fnSettlementType" data-iidKey="' . $value ['iidKeyK'] . '" data-toggle="modal">结算方式</a>' );
  5359. } else
  5360. array_push ( $irDetail, '' );
  5361. }
  5362. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  5363. if ($value ['invoiceType'] == 1)
  5364. array_push ( $irDetail, $value ['invoiceCompany'] );
  5365. else
  5366. array_push ( $irDetail, $value ['invoiceTitle'] );
  5367. array_push ( $irDetail, $value ['TIN'] );
  5368. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  5369. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  5370. array_push ( $irDetail, $value ['remark'] );
  5371. array_push ( $irDetail, $value ['invoiceElement'] );
  5372. array_push ( $irDetail, $value ['invoiceQuantity'] );
  5373. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  5374. if ($value ['invoiceType'] == 1) {
  5375. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  5376. } else {
  5377. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  5378. }
  5379. if ($value ['settlementType'] == 0) {
  5380. array_push ( $irDetail, '软件销售' );
  5381. } else {
  5382. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $value ['trainId'] );
  5383. array_push ( $irDetail, $itDetail ['trainName'] );
  5384. }
  5385. array_push ( $irDetail, $value ['recipients'] . $value ['recipientsPhone'] );
  5386. array_push ( $irDetail, $value ['recipientsAddress'] );
  5387. array_push ( $irDetail, $value ['mailItems'] );
  5388. array_push ( $irDetail, $value ['userName'] . '&nbsp;' . $value ['date'] );
  5389. $fchtml = $value ['OL'] ['operation'];
  5390. if (count ( $list ) == $page_size)
  5391. $fchtml = $value ['OL'] ['operation'] . $html;
  5392. // 最后的审批意见
  5393. array_push ( $irDetail, $fchtml );
  5394. if ($value ['status'] == 2)
  5395. array_push ( $irDetail, '<span class="colGreen">同意</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5396. elseif ($value ['status'] == 3)
  5397. array_push ( $irDetail, '<span class="colOrange">退回</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5398. elseif ($value ['status'] == 4)
  5399. array_push ( $irDetail, '<span class="colRed">终止</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5400. else
  5401. array_push ( $irDetail, '' );
  5402. array_push ( $approvalList, $irDetail );
  5403. }
  5404. // $approvalListJson = json_encode ( $approvalList );
  5405. $recordsFiltered = $pageinfo ['total_data'];
  5406. echo json_encode ( array (
  5407. "draw" => intval ( $draw ),
  5408. "recordsTotal" => intval ( $pageinfo ['total_data'] ),
  5409. "recordsFiltered" => intval ( $recordsFiltered ),
  5410. "data" => $approvalList
  5411. ), JSON_UNESCAPED_UNICODE );
  5412. }
  5413. /**
  5414. * 审批发票查看更多--重构
  5415. */
  5416. function invoiceApprovalAchieve() {
  5417. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'ALL';
  5418. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5419. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5420. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5421. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5422. Doo::loadModel ( 'invoiceTraining' );
  5423. $invoiceTraining = new invoiceTraining ();
  5424. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  5425. $this->data ['trainList'] = $trainList;
  5426. $this->data ['dateString'] = $date;
  5427. $this->data ['status'] = $status;
  5428. $this->data ['invoiceType'] = $invoiceType;
  5429. $this->data ['invoiceTrain'] = $invoiceTrain;
  5430. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  5431. $this->data ['memu'] = "invoice";
  5432. $this->data ['staff'] = $this->staff;
  5433. $this->data ['receiptMemu'] = 'invoiceApproval';
  5434. $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  5435. }
  5436. function invoiceTAchieve() {
  5437. Doo::loadModel ( 'invoice' );
  5438. $invoice = new invoice ();
  5439. Doo::loadClass ( 'XDeode' );
  5440. $XDeode = new XDeode ( 5 );
  5441. Doo::loadModel ( 'staff' );
  5442. $staff = new staff ();
  5443. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  5444. $page_size = 12;
  5445. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5446. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  5447. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5448. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5449. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5450. Doo::loadModel ( 'invoiceTraining' );
  5451. $invoiceTraining = new invoiceTraining ();
  5452. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  5453. $get = "/" . $date;
  5454. $con = '';
  5455. if ($date == 'MONTHO')
  5456. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  5457. elseif ($date == 'MONTHT')
  5458. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  5459. elseif ($date == 'MONTHY')
  5460. $con = ' and YEAR(updateTime) = YEAR(NOW())'; // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  5461. if ($invoiceType == 'ORDINARY')
  5462. $con .= ' and invoiceType=0 ';
  5463. elseif ($invoiceType == 'SPECIAL')
  5464. $con .= ' and invoiceType=1 ';
  5465. if ($invoiceTrain == 'ORDINARY')
  5466. $con .= ' and trainId=0 ';
  5467. elseif ($invoiceTrain == 'TRAIN')
  5468. $con .= ' and trainId!=0 ';
  5469. if ($invoiceTrainName != 'ALL') {
  5470. $trainId = $XDeode->decode ( $invoiceTrainName );
  5471. if (is_numeric ( $trainId ))
  5472. $con .= ' and trainId =' . $trainId;
  5473. }
  5474. if (! empty ( $MebSea )) {
  5475. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  5476. $get .= "/" . $MebSea;
  5477. }
  5478. $pageinfo ['page'] = array (
  5479. 'previous' => ''
  5480. );
  5481. $sql = "";
  5482. $action = "";
  5483. if ($this->ACTION == 'invoicePrintAchieve') {
  5484. $sql = "status=2 and printStatus=1 and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  5485. $action = "invoicePrintAchieve";
  5486. } elseif ($this->ACTION == 'invoicePostAchieve') {
  5487. // and untreadStatus=0
  5488. $sql = "postStatus=1 and doPost=1 and status=2 and isDelete=0" . $con;
  5489. $action = "invoicePostAchieve";
  5490. } elseif ($this->ACTION == 'invoiceUntreadAchieve') { // printStatus=1 and
  5491. $sql = " untreadStatus=2 and status=2 " . $con;
  5492. $action = "invoiceUntreadAchieve";
  5493. }
  5494. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  5495. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5496. $this->data ['MebSeaEn'] = $MebSea;
  5497. $this->data ['MebSea'] = urlencode ( $MebSea );
  5498. $this->data ['get'] = $get;
  5499. $this->data ['page'] = $pageinfo;
  5500. $this->data ['trainList'] = $trainList;
  5501. $this->data ['invoiceType'] = $invoiceType;
  5502. $this->data ['invoiceTrain'] = $invoiceTrain;
  5503. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  5504. $this->data ['date'] = $date;
  5505. $this->data ['memu'] = "invoice";
  5506. $this->data ['staff'] = $this->staff;
  5507. if ($this->ACTION == 'invoicePrintAchieve') {
  5508. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  5509. $this->data ['receiptMemu'] = 'invoicePrint';
  5510. $this->data ['list'] = $list;
  5511. $this->render ( "/admin/invoicePrintAchieve", $this->data );
  5512. } elseif ($this->ACTION == 'invoicePostAchieve') {
  5513. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  5514. Doo::loadModel ( 'express' );
  5515. $express = new express ();
  5516. $expressList = $express->getExpressByAll ();
  5517. $this->data ['expressList'] = $expressList;
  5518. $this->data ['receiptMemu'] = 'invoicePost';
  5519. $this->data ['list'] = $list;
  5520. $this->render ( "/admin/invoicePostAchieve", $this->data );
  5521. } elseif ($this->ACTION == 'invoiceUntreadAchieve') {
  5522. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  5523. $this->data ['receiptMemu'] = 'invoiceUntread';
  5524. $this->data ['list'] = $list;
  5525. $this->render ( "/admin/invoiceUntreadAchieve", $this->data );
  5526. }
  5527. }
  5528. /**
  5529. * 公司应收款
  5530. */
  5531. function invoiceAggregateCompanyDetail() {
  5532. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  5533. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  5534. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : 'ALL';
  5535. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  5536. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  5537. Doo::loadClass ( 'XDeode' );
  5538. $XDeode = new XDeode ( 5 );
  5539. Doo::loadModel ( 'invoice' );
  5540. $invoice = new invoice ();
  5541. Doo::loadModel ( 'staff' );
  5542. $staff = new staff ();
  5543. Doo::loadModel ( "invoiceCompanyManage" );
  5544. $invoiceCompanyManage = new invoiceCompanyManage ();
  5545. Doo::loadModel ( 'L_category' );
  5546. $category = new L_category ();
  5547. $sid = '';
  5548. if (! empty ( $sidKey )) {
  5549. $sid = $XDeode->decode ( $sidKey );
  5550. }
  5551. $staffDetail = $staff->getStaffBySid ( $sid );
  5552. $cid = '';
  5553. if (! empty ( $cidKey )) {
  5554. $cid = $XDeode->decode ( $cidKey );
  5555. }
  5556. $imcStaff = $invoiceCompanyManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  5557. $cidList = array ();
  5558. foreach ( $imcStaff as $key => $value ) {
  5559. array_push ( $cidList, $value ['cid'] );
  5560. }
  5561. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  5562. $cidString = implode ( ',', $cidList );
  5563. if (empty ( $cid ))
  5564. $staffList = $staff->getStaffInCid ( $cidString );
  5565. else
  5566. $staffList = $staff->getStaffByCidAll ( $cid ); //
  5567. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  5568. $page_size = 25;
  5569. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5570. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  5571. $con = ' status=2 and untreadStatus!=2 ';
  5572. $statisticsCon = '';
  5573. if (! empty ( $year ) && is_numeric ( $year ))
  5574. $con .= ' and Year(printTime)=' . $year . '';
  5575. if (! empty ( $month ) && is_numeric ( $month ))
  5576. $con .= ' and Month(printTime)="' . $month . '" ';
  5577. if ($status == 'UNRECORD')
  5578. $con .= ' and printStatus=1 and untreadStatus=0';
  5579. elseif ($status == 'RECORD')
  5580. $con .= ' and printStatus=1 and untreadStatus=3';
  5581. elseif ($status == 'BOUNCED')
  5582. $con .= ' and untreadStatus=2';
  5583. elseif ($status == 'PARTRECORD')
  5584. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  5585. elseif ($status == 'All') {
  5586. $con .= ' and printStatus=1 and ( untreadStatus=0 or untreadStatus=3 )';
  5587. }
  5588. if (! empty ( $sid ) && is_numeric ( $sid ))
  5589. $con .= ' and sid=' . $sid;
  5590. if (! empty ( $cid ) && is_numeric ( $cid ))
  5591. $con .= ' and cid=' . $cid;
  5592. else
  5593. $con .= ' and cid in (' . $cidString . ')';
  5594. // 开票内容筛选
  5595. if (! empty ( $invoiceElement ) && $invoiceElement != 'ALL') {
  5596. $con .= ' and invoiceElement="' . $invoiceElement . '"';
  5597. }
  5598. $get = "/" . $status . "?cidKey=" . $cidKey . "&sidKey=" . $sidKey . "&year=" . $year . "&month=" . $month . "&invoiceElement=" . $invoiceElement;
  5599. if (! empty ( $MebSea )) {
  5600. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  5601. }
  5602. $pageinfo ['page'] = array (
  5603. 'previous' => ''
  5604. );
  5605. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateCompanyDetail", $get, "" );
  5606. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5607. // 应收款合计
  5608. $ics = $invoice->getInvoiceCompanyStatistics ( $con );
  5609. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  5610. $monthHtml = "";
  5611. if ($year != "ALL") {
  5612. for($i = 1; $i <= 12; $i ++) {
  5613. if ($i == $month)
  5614. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  5615. else
  5616. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  5617. }
  5618. }
  5619. $this->data ['monthHtml'] = $monthHtml;
  5620. $this->data ['year'] = $year;
  5621. $this->data ['month'] = $month;
  5622. $this->data ['ics'] = $ics;
  5623. $this->data ['cidKey'] = $cidKey;
  5624. $this->data ['sid'] = $sid;
  5625. $this->data ['staffDetail'] = $staffDetail;
  5626. $this->data ['staffList'] = $staffList;
  5627. $this->data ['MebSeaEn'] = $MebSea;
  5628. $this->data ['MebSea'] = urlencode ( $MebSea );
  5629. $this->data ['invoiceDetail'] = array (
  5630. 'invoiceElement' => $invoiceElement
  5631. );
  5632. $this->data ['page'] = $pageinfo;
  5633. $this->data ['get'] = $get;
  5634. $this->data ['list'] = $list;
  5635. $this->data ['status'] = $status;
  5636. $this->data ['categoryList'] = $categoryList;
  5637. $this->data ['memu'] = "invoice";
  5638. $this->data ['staff'] = $this->staff;
  5639. $this->data ['receiptMemu'] = 'invoiceAggregateCompanyDetail';
  5640. $this->render ( "/admin/invoiceAggregateCompanyDetail", $this->data );
  5641. }
  5642. /**
  5643. * 获取一条收款信息
  5644. */
  5645. function ajaxGetInvoiceReceivables() {
  5646. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  5647. Doo::loadModel ( 'invoiceReceivables' );
  5648. $invoiceReceivables = new invoiceReceivables ();
  5649. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5650. echo json_encode ( array (
  5651. 'status' => 1,
  5652. 'detail' => $detail
  5653. ) );
  5654. }
  5655. /**
  5656. * 异步获取办事处用户
  5657. */
  5658. function ajaxGetStaffByCategory() {
  5659. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "";
  5660. Doo::loadModel ( 'staff' );
  5661. $staff = new staff ();
  5662. if ($cid == "PUBLIC") {
  5663. echo json_encode ( array (
  5664. 'status' => 1,
  5665. 'html' => '<option value="PUBLIC">办事处待认领款项</option>'
  5666. ) );
  5667. die ();
  5668. }
  5669. if (! is_numeric ( $cid )) {
  5670. echo json_encode ( array (
  5671. 'status' => 0,
  5672. 'msg' => 'illegal request'
  5673. ) );
  5674. die ();
  5675. }
  5676. $staffList = $staff->getStaffByCid ( $cid );
  5677. $html = '<option value="PUBLIC">办事处待认领款项</option>';
  5678. foreach ( $staffList as $key => $value ) {
  5679. $html .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  5680. }
  5681. echo json_encode ( array (
  5682. 'status' => 1,
  5683. 'html' => $html
  5684. ) );
  5685. }
  5686. /**
  5687. * 异步获取一条发票的邮寄信息
  5688. */
  5689. function ajaxGetInvoicePostDetail() {
  5690. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  5691. Doo::loadModel ( 'invoice' );
  5692. $invoice = new invoice ();
  5693. $iid = $invoice->authcode ( $iid );
  5694. Doo::loadModel ( 'express' );
  5695. $express = new express ();
  5696. $expressList = $express->getExpressByAll ();
  5697. if (! is_numeric ( $iid )) {
  5698. echo json_encode ( array (
  5699. 'status' => 0,
  5700. 'msg' => 'illegal request'
  5701. ) );
  5702. die ();
  5703. }
  5704. $select = "iid,recipients,recipientsPhone,recipientsAddress,mailItems,expressCompany,expressNumber,actualItems";
  5705. $invoiceDetail = $invoice->getInvoiceByIid ( $iid, $select );
  5706. $html = "";
  5707. foreach ( $expressList as $key => $value ) {
  5708. if ($value ['company'] == $invoiceDetail ['expressCompany'])
  5709. $html .= '<option selected value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  5710. else
  5711. $html .= '<option value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  5712. }
  5713. $invoiceDetail ['eaHtml'] = $html;
  5714. echo json_encode ( array (
  5715. 'status' => 1,
  5716. 'invoiceDetail' => $invoiceDetail
  5717. ) );
  5718. }
  5719. /**
  5720. *
  5721. * @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 ) ); }
  5722. */
  5723. /**
  5724. *
  5725. * @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 ) ); }
  5726. */
  5727. /**
  5728. * 我的收款中 选择哪个发票入账,进行金额判断
  5729. */
  5730. function ajaxCompareInvoicePrice() {
  5731. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  5732. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  5733. Doo::loadModel ( 'invoice' );
  5734. $invoice = new invoice ();
  5735. Doo::loadModel ( 'invoiceReceivables' );
  5736. $invoiceReceivables = new invoiceReceivables ();
  5737. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  5738. $keyList = explode ( ';', $claimKey );
  5739. $receivablesPrice = 0;
  5740. foreach ( $keyList as $key => $value ) {
  5741. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $value );
  5742. $receivablesPrice += $detailM ['receivablesPrice'];
  5743. }
  5744. if ($receivablesPrice > $detail ['invoicePrice']) {
  5745. $price = $receivablesPrice - $detail ['invoicePrice'];
  5746. echo json_encode ( array (
  5747. 'status' => 1,
  5748. 'price' => $price
  5749. ) );
  5750. } else
  5751. echo json_encode ( array (
  5752. 'status' => 2
  5753. ) );
  5754. }
  5755. /**
  5756. * 获得打印发票
  5757. */
  5758. function ajaxGetInvoiceInfoByPrint() {
  5759. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5760. if (empty ( $serial )) {
  5761. echo json_encode ( array (
  5762. 'status' => 2,
  5763. 'msg' => 'illegal request'
  5764. ) );
  5765. die ();
  5766. }
  5767. Doo::loadModel ( 'invoice' );
  5768. $invoice = new invoice ();
  5769. Doo::loadModel ( 'invoiceOperationLog' );
  5770. $invoiceOperationLog = new invoiceOperationLog ();
  5771. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5772. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5773. Doo::loadModel ( 'invoicePaper' );
  5774. $invoicePaper = new invoicePaper ();
  5775. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $detail ['invoiceType'] );
  5776. if (empty ( $detail ))
  5777. $html = '';
  5778. else {
  5779. $html = '
  5780. <form action="/invoicePrintDo" method="post" name="invoicePrint" class="nice-validator n-yellow" onSubmit="return checkPrintForm()" novalidate="novalidate">
  5781. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  5782. <input type="hidden" name="invoicePrintType" value="invoicePrintType">
  5783. <div class="modal-dialog modal-lg">
  5784. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  5785. <div class="modal-body saeaList">
  5786. <table class="table table-bordered table-condensed"><tbody>
  5787. <tr>
  5788. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5789. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5790. </tr>
  5791. <tr>
  5792. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5793. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5794. </tr>
  5795. <tr>
  5796. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5797. </td>
  5798. </tr>
  5799. <tr>
  5800. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5801. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5802. </tr>
  5803. <tr>
  5804. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5805. </tr></tbody></table>';
  5806. if ($detail ['invoiceType'] == 0)
  5807. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5808. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5809. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5810. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5811. </tr>';
  5812. else
  5813. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5814. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5815. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5816. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5817. ';
  5818. $html .= '<tr>
  5819. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5820. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5821. </tr>
  5822. <tr>
  5823. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5824. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5825. </tr></tbody></table>';
  5826. if ($detail ['doPost'] == 1)
  5827. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5828. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5829. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5830. </tr><tr>
  5831. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5832. </tr><tr>
  5833. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5834. </tr></tbody></table>';
  5835. if (! empty ( $invoiceOperationLogList )) {
  5836. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th><th class="taC">发票打印</th></tr><tr><td>';
  5837. foreach ( $invoiceOperationLogList as $key => $value ) {
  5838. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5839. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5840. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5841. if ($value ['status'] == 2) {
  5842. $html .= '<span class="colGreen">同意</span>';
  5843. } elseif ($value ['status'] == 3) {
  5844. $html .= '<span class="colOrange">退回</span>';
  5845. } elseif ($value ['status'] == 5) {
  5846. $html .= '<span class="colGreen">打印</span>';
  5847. } elseif ($value ['status'] == 4) {
  5848. $html .= '<span class="colRed">终止</span>';
  5849. }
  5850. $html .= $value ['operation'] . '</p></blockquote>';
  5851. }
  5852. }
  5853. $html .= '</td>
  5854. <td><span class="colRed">*</span>
  5855. <select name="invoiceNo" id="invoiceNo" style="width:97%">';
  5856. foreach ( $invoicePaperList as $key => $value ) {
  5857. $html .= '<option value="' . $value ['ipidKey'] . '">No.' . $value ['invoiceNo'] . '</option>';
  5858. }
  5859. $html .= '</select>
  5860. <span class="red" id="p-msg"></span>
  5861. </td>
  5862. </tr></tbody></table>';
  5863. }
  5864. $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>
  5865. </div></div></form>
  5866. <link rel=stylesheet href="' . WEB_SITE_GLOBAL . 'css/jquery.validator.css">
  5867. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/jquery.validator.min.js"></script>
  5868. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/zh-CN.js"></script>
  5869. <script src="' . WEB_SITE_GLOBAL . 'js/invoice.validator.js"></script>
  5870. ';
  5871. }
  5872. echo json_encode ( array (
  5873. 'status' => 1,
  5874. 'html' => $html
  5875. ) );
  5876. die ();
  5877. }
  5878. /**
  5879. * @ 获得与我有关收款数据 --需求变更 废弃 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 ) ); }
  5880. */
  5881. function ajaxGetInvoiceInfoByType() {
  5882. $type = $this->get_args ( 'type' ) ? $this->get_args ( 'type' ) : "";
  5883. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5884. $loss = $this->get_args ( 'loss' ) ? $this->get_args ( 'loss' ) : false;
  5885. if (empty ( $serial )) {
  5886. echo json_encode ( array (
  5887. 'status' => 2,
  5888. 'msg' => 'illegal request'
  5889. ) );
  5890. die ();
  5891. }
  5892. if ($type == 'INVOICE') {
  5893. Doo::loadModel ( 'invoice' );
  5894. $invoice = new invoice ();
  5895. Doo::loadModel ( 'invoiceOperationLog' );
  5896. $invoiceOperationLog = new invoiceOperationLog ();
  5897. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5898. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5899. if (empty ( $detail ))
  5900. $html = '';
  5901. else {
  5902. $html = '
  5903. <div class="modal-dialog modal-lg">
  5904. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  5905. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  5906. <tr>
  5907. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5908. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5909. </tr>
  5910. <tr>
  5911. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5912. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5913. </tr>
  5914. <tr>
  5915. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5916. </td>
  5917. </tr>
  5918. <tr>
  5919. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5920. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5921. </tr>
  5922. <tr>
  5923. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5924. </tr>';
  5925. if ($detail ['settlementType'] == 1)
  5926. $html .= '<tr>
  5927. <th class="taC" width="150">结算方式</th><td colspan="3">培训班(<a href="/invoiceTrainingDetail/' . $detail ['invoiceTraining'] ['trainingKey'] . '.html" target="_blank">' . $detail ['invoiceTraining'] ['trainName'] . '</a>)</td>
  5928. </tr>';
  5929. else
  5930. $html .= '<tr>
  5931. <th class="taC" width="150">结算方式</th><td colspan="3">软件销售</td>
  5932. </tr>';
  5933. $html .= ' </tbody></table>';
  5934. if ($detail ['invoiceType'] == 0)
  5935. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5936. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5937. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5938. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5939. </tr>';
  5940. else
  5941. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5942. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5943. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5944. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5945. ';
  5946. $html .= '<tr>
  5947. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5948. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5949. </tr>
  5950. <tr>
  5951. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5952. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5953. </tr></tbody></table>';
  5954. if ($detail ['doPost'] == 1) {
  5955. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5956. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5957. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5958. </tr><tr>
  5959. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5960. </tr><tr>
  5961. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5962. </tr>
  5963. ';
  5964. if ($detail ['expressCom'] == 'SF')
  5965. $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>';
  5966. else
  5967. $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>';
  5968. $html .= '</tbody></table>';
  5969. }
  5970. if (! empty ( $invoiceOperationLogList )) {
  5971. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  5972. foreach ( $invoiceOperationLogList as $key => $value ) {
  5973. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5974. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5975. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5976. if ($value ['status'] == 2) {
  5977. $html .= '<span class="colGreen">同意</span>';
  5978. } elseif ($value ['status'] == 3) {
  5979. $html .= '<span class="colOrange">退回</span>';
  5980. } elseif ($value ['status'] == 5) {
  5981. $html .= '<span class="colGreen">打印</span>';
  5982. } elseif ($value ['status'] == 4) {
  5983. $html .= '<span class="colRed">终止</span>';
  5984. }
  5985. $html .= $value ['operation'] . '</p></blockquote>';
  5986. }
  5987. }
  5988. $html .= '</td></tr></tbody></table>';
  5989. }
  5990. $html .= '</div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  5991. }
  5992. echo json_encode ( array (
  5993. 'status' => 1,
  5994. 'html' => $html
  5995. ) );
  5996. die ();
  5997. } elseif ($type == 'RECEIVABLES') {
  5998. Doo::loadModel ( 'invoiceReceivables' );
  5999. $invoiceReceivables = new invoiceReceivables ();
  6000. Doo::loadModel ( 'invoiceRefund' );
  6001. $invoiceRefund = new invoiceRefund ();
  6002. $detail = $invoiceReceivables->getInvoiceReceivablesByIrsid ( $serial );
  6003. $ireList = $invoiceRefund->getInvoiceRefundIrid ( $detail ['irid'] );
  6004. if (empty ( $detail ))
  6005. $html = '';
  6006. else {
  6007. $html = '<div class="modal-dialog modal-lg"><div class="modal-content"><div class="modal-header"><h3>收款单详情</h3></div><div class="modal-body saeaList">
  6008. <table class="table table-bordered table-condensed">
  6009. <tbody><tr>
  6010. <th class="taC">收款流水号</th><td>' . $detail ['receivablesSerial'] . '</td>
  6011. <th class="taC">录入收款</th><td>' . $detail ['inputStaff'] . ' ' . $detail ['date'] . '</td>
  6012. </tr><tr>
  6013. <th class="taC">收款金额</th><td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  6014. <th class="taC">收款信息</th><td>' . $detail ['receivablesMessage'] . '</td>
  6015. </tr>
  6016. <tr>
  6017. <th class="taC">收款银行</th><td>' . $detail ['receivablesBank'] . '</td>
  6018. <th class="taC">银行到账</th><td>' . $detail ['receivablesDate'] . '</td>
  6019. </tr>
  6020. <tr>
  6021. <th class="taC">认领收款</th><td colspan="3">' . $detail ['inputStaff'] . ' 转入 ' . $detail ['username'] . ' ' . $detail ['confirmTime'] . '</td>
  6022. </tr>
  6023. </tbody></table>';
  6024. if (! empty ( $ireList )) {
  6025. $html .= '
  6026. <table class="table table-bordered table-condensed"><tbody><tr><th class="taC" colspan="5">退款记录</th></tr>
  6027. <tr>
  6028. <th class="taC">退款单位名称</th>
  6029. <th class="taC">退款的账号</th>
  6030. <th class="taC">退款金额</th>
  6031. <th class="taC">退款</th>
  6032. <th class="taC">备注</th>
  6033. </tr>
  6034. ';
  6035. foreach ( $ireList as $key => $value ) {
  6036. $refundLogList = explode ( "<br/>", $value ['refundLog'] );
  6037. $html .= '<tr>
  6038. <td>' . $value ['refundCompany'] . '</td>
  6039. <td>' . $value ['refundNumber'] . '</td>
  6040. <td><b class="colRed">¥' . $value ['refundPrice'] . '</b></td>
  6041. <td>' . $refundLogList [0] . $refundLogList [2] . '</td>
  6042. <td>' . $value ['refundRemarks'] . '</td>
  6043. </tr>
  6044. ';
  6045. }
  6046. }
  6047. $html .= '</tbody></table></div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  6048. }
  6049. echo json_encode ( array (
  6050. 'status' => 1,
  6051. 'html' => $html
  6052. ) );
  6053. die ();
  6054. } elseif ($type == 'IRTC') {
  6055. Doo::loadModel ( 'invoice' );
  6056. $invoice = new invoice ();
  6057. Doo::loadModel ( 'invoiceOperationLog' );
  6058. $invoiceOperationLog = new invoiceOperationLog ();
  6059. Doo::loadModel ( 'invoiceReceivables' );
  6060. $invoiceReceivables = new invoiceReceivables ();
  6061. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  6062. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  6063. if (empty ( $detail ))
  6064. $html = '';
  6065. else {
  6066. $receivablesPriceedHtml = '';
  6067. $receivablesPrice = $detail ['invoicePrice'];
  6068. if (! empty ( $detail ['irid'] )) {
  6069. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $detail ['irid'] );
  6070. if (empty ( $irList ))
  6071. $irList [0] ['sumPrice'] = 0;
  6072. $balance = $detail ['invoicePrice'] - $irList [0] ['sumPrice'];
  6073. $receivablesPriceedHtml = '<table class="table table-bordered table-condensed"><tbody><tr>
  6074. <th class="taC">已入账金额</th><td><b class="colGreen" style="font-size:18px">¥' . $irList [0] ['sumPrice'] . '</b></td>
  6075. <th class="taC">剩余入账金额</th><td><b class="colRed" style="font-size:18px">¥' . $balance . '</b></td>
  6076. </tr></tbody></table>';
  6077. $receivablesPrice = $balance;
  6078. }
  6079. if ($loss)
  6080. $detail ['invoicePrice'] = - $detail ['invoicePrice'];
  6081. $html = $receivablesPriceedHtml . '
  6082. <table class="table table-bordered table-condensed"><tbody>
  6083. <tr>
  6084. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  6085. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  6086. </tr>
  6087. <tr>
  6088. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  6089. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  6090. </tr>
  6091. <tr>
  6092. <th class="taC" width="150">发票备注</th><td colspan="3">' . $detail ['remark'] . '</td>
  6093. </tr>
  6094. <tr>
  6095. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  6096. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  6097. </tr>
  6098. <tr>
  6099. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  6100. </tr></tbody></table>';
  6101. if ($detail ['invoiceType'] == 0) {
  6102. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6103. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  6104. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  6105. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  6106. </tr>';
  6107. $receivablesMessage = $detail ['invoiceTitle'];
  6108. } else {
  6109. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6110. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  6111. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  6112. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  6113. ';
  6114. $receivablesMessage = $detail ['invoiceCompany'];
  6115. }
  6116. $html .= '<tr>
  6117. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  6118. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  6119. </tr>
  6120. <tr>
  6121. <th class="taC">开户银行</th><td>' . $detail ['bankAccount'] . '</td>
  6122. <th class="taC">银行账号</th><td>' . $detail ['bank'] . '</td>
  6123. </tr></tbody></table>';
  6124. if ($detail ['doPost'] == 1)
  6125. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  6126. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  6127. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  6128. </tr><tr>
  6129. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  6130. </tr><tr>
  6131. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  6132. </tr></tbody></table>';
  6133. if (! empty ( $invoiceOperationLogList )) {
  6134. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  6135. foreach ( $invoiceOperationLogList as $key => $value ) {
  6136. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  6137. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  6138. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  6139. if ($value ['status'] == 2) {
  6140. $html .= '<span class="colGreen">同意</span>';
  6141. } elseif ($value ['status'] == 3) {
  6142. $html .= '<span class="colOrange">退回</span>';
  6143. } elseif ($value ['status'] == 5) {
  6144. $html .= '<span class="colGreen">打印</span>';
  6145. }
  6146. $html .= $value ['operation'] . '</p></blockquote>';
  6147. }
  6148. }
  6149. $html .= '</td></tr></tbody></table>';
  6150. }
  6151. }
  6152. echo json_encode ( array (
  6153. 'status' => 1,
  6154. 'html' => $html,
  6155. 'receivablesPrice' => $receivablesPrice,
  6156. 'receivablesMessage' => $receivablesMessage,
  6157. 'receivablesDate' => date ( "Y-m-d" ),
  6158. 'iidKey' => $serial
  6159. ) );
  6160. die ();
  6161. }
  6162. }
  6163. function ajaxGetInvoiceReceivablesByStaff() {
  6164. $postData = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : "";
  6165. if (empty ( $postData )) {
  6166. echo json_encode ( array (
  6167. 'status' => 2,
  6168. 'msg' => 'illegal request'
  6169. ) );
  6170. die ();
  6171. }
  6172. Doo::loadModel ( 'invoiceReceivables' );
  6173. $invoiceReceivables = new invoiceReceivables ();
  6174. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $postData );
  6175. if (empty ( $detail )) {
  6176. echo json_encode ( array (
  6177. 'status' => 2,
  6178. 'msg' => 'illegal request'
  6179. ) );
  6180. die ();
  6181. }
  6182. Doo::loadModel ( 'L_category' );
  6183. $lCategory = new L_category ();
  6184. Doo::loadModel ( 'staff' );
  6185. $staff = new staff ();
  6186. $staffList = $staff->getStaffByCid ( $detail ['cid'] );
  6187. $category = $lCategory->getCategory ();
  6188. $categoryHtml = '<option post-data="PUBLIC" value="PUBLIC" >公共待认领款项</option>';
  6189. $staffHtml = '<option value="PUBLIC">办事处待认领款项</option>';
  6190. foreach ( $category as $key => $value ) {
  6191. $categoryHtml .= '<option post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  6192. if ($value ['cid'] == $detail ['cid'])
  6193. $categoryHtml .= '<option selected post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  6194. }
  6195. foreach ( $staffList as $key => $value ) {
  6196. $staffHtml .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  6197. if ($value ['sid'] == $detail ['sid'])
  6198. $staffHtml .= '<option selected value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  6199. }
  6200. $rbankHtml = '<option value="广发银行珠海分行柠溪支行">广发银行珠海分行柠溪支行</option>';
  6201. echo json_encode ( array (
  6202. 'status' => 1,
  6203. 'categoryHtml' => $categoryHtml,
  6204. 'staffHtml' => $staffHtml,
  6205. 'rbankHtml' => $rbankHtml,
  6206. 'detail' => $detail
  6207. ) );
  6208. }
  6209. function ajaxGetInvoiceReceivablesByIrid() {
  6210. $irid = $this->get_args ( 'irid' ) ? $this->get_args ( 'irid' ) : "";
  6211. if (empty ( $irid )) {
  6212. echo json_encode ( array (
  6213. 'status' => 2,
  6214. 'msg' => 'illegal request'
  6215. ) );
  6216. die ();
  6217. }
  6218. Doo::loadModel ( 'invoiceReceivables' );
  6219. $invoiceReceivables = new invoiceReceivables ();
  6220. Doo::loadModel ( 'invoice' );
  6221. $invoice = new invoice ();
  6222. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid ); // 入账完成 待定 and postStatus=1
  6223. $flag = true;
  6224. $invoiceDetail = $invoice->getInvoiceByTitle ( $detail ['recepitTitleMark'], 'EXACTLY', " and status=2 and printStatus=1 and untreadStatus=0 ", $flag ); //
  6225. $bakDetail = array ();
  6226. if ($flag === false) {
  6227. array_push ( $bakDetail, $invoiceDetail );
  6228. $invoiceDetail = $bakDetail;
  6229. }
  6230. $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>
  6231. <tr>
  6232. <td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  6233. <td>' . $detail ['receivablesMessage'] . '</td>
  6234. <td>' . $detail ['receivablesBank'] . '<br>' . $detail ['receivablesDate'] . '</td>
  6235. <td>' . $detail ['title'] . '-' . $detail ['username'] . '<br>' . $detail ['confirmTime'] . '</td>
  6236. <td>' . $detail ['recepitTitleMark'] . '</td>
  6237. </tr></tbody></table>';
  6238. $isInvoice = false;
  6239. $invoiceHtml = '';
  6240. if (empty ( $invoiceDetail )) {
  6241. $isInvoice = true;
  6242. } else {
  6243. $invoiceHtml = '<table class="table table-bordered table-condensed">
  6244. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody>';
  6245. foreach ( $invoiceDetail as $key => $value ) {
  6246. $invoiceHtml .= '<tr>';
  6247. if (! empty ( $value ['invoiceType'] )) {
  6248. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  6249. } else {
  6250. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  6251. }
  6252. if (! empty ( $value ['invoiceType'] )) {
  6253. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  6254. } else {
  6255. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  6256. }
  6257. $invoiceHtml .= '
  6258. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  6259. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  6260. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir" data-ikey="' . $value ['iidKey'] . '" href="javascript:void(0)">入账</a></td>
  6261. </tr>
  6262. ';
  6263. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  6264. if (empty ( $irList ))
  6265. $irList [0] ['sumPrice'] = 0;
  6266. $balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  6267. $priceString = '';
  6268. if ($balance < $detail ['receivablesPrice']) {
  6269. $priceString = '收款金额超过开票金额,';
  6270. }
  6271. if ($balance > $detail ['receivablesPrice']) {
  6272. $priceString = '收款金额低于开票金额,';
  6273. }
  6274. }
  6275. $invoiceHtml .= '
  6276. <script>
  6277. $(\'a[bind-receivables^="ir"]\').click(function() {
  6278. var data = $(this).attr("data-ikey");
  6279. $("input[name=\'invoiceKey\']").val(data);
  6280. var invoiceKey=data;
  6281. if(invoiceKey==""){
  6282. alert("入账错误,请重新刷新页面");
  6283. return false;
  6284. }
  6285. if(window.confirm("' . $priceString . '确定入账吗?")){
  6286. $("#IBR").submit();
  6287. }else{
  6288. return false;
  6289. }
  6290. });
  6291. </script>
  6292. ';
  6293. $invoiceHtml .= '</tbody></table>';
  6294. }
  6295. echo json_encode ( array (
  6296. 'status' => 1,
  6297. 'irkey' => $detail ['iridEn'],
  6298. 'receivablesHtml' => $receivablesHtml,
  6299. 'isInvoice' => $isInvoice,
  6300. 'invoiceHtml' => $invoiceHtml
  6301. ) );
  6302. }
  6303. function ajaxGetInvoiceReceivablesByTitle() {
  6304. $title = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  6305. if (empty ( $title )) {
  6306. echo json_encode ( array (
  6307. 'status' => 2,
  6308. 'msg' => 'illegal request'
  6309. ) );
  6310. die ();
  6311. }
  6312. Doo::loadModel ( 'invoice' );
  6313. $invoice = new invoice ();
  6314. $invoiceDetail = $invoice->getInvoiceByTitle ( $title, 'FUZZY', " and status=2 and printStatus=1 and untreadStatus=0 and irid='' ", true );
  6315. $invoiceHtml = '';
  6316. if (! empty ( $invoiceDetail )) {
  6317. $invoiceHtml = '<table class="table table-bordered table-condensed">
  6318. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody><tr>';
  6319. foreach ( $invoiceDetail as $key => $value ) {
  6320. if (! empty ( $value ['invoiceType'] )) {
  6321. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  6322. } else {
  6323. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  6324. }
  6325. if (! empty ( $value ['invoiceType'] )) {
  6326. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  6327. } else {
  6328. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  6329. }
  6330. $invoiceHtml .= '
  6331. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  6332. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  6333. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir' . $value ['iidKeyXD'] . '" data-ikey="' . $value ['iidKey'] . '" href="#">入账</a></td>
  6334. </tr>
  6335. ';
  6336. }
  6337. $invoiceHtml .= '</tbody></table>
  6338. <script>
  6339. $(\'a[bind-receivables^="ir"]\').click(function() {
  6340. var data = $(this).attr("data-ikey");
  6341. $("input[name=\'invoiceKey\']").val(data);
  6342. var invoiceKey=$("input[name=\'invoiceKey\']").val();
  6343. if(invoiceKey==""){
  6344. alert("入账错误,请重新刷新页面");
  6345. return false;
  6346. }
  6347. if(window.confirm("确定入账吗?")){
  6348. $("#IBR").submit();
  6349. }else{
  6350. return false;
  6351. }
  6352. });
  6353. </script>
  6354. ';
  6355. }
  6356. echo json_encode ( array (
  6357. 'status' => 1,
  6358. 'invoiceHtml' => $invoiceHtml
  6359. ) );
  6360. }
  6361. function ajaxInvoicePushNotice() {
  6362. Doo::loadModel ( 'invoice' );
  6363. $invoice = new invoice ();
  6364. $approval = $invoice->getOne ( array (
  6365. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  6366. 'desc' => 'iid',
  6367. 'asArray' => true
  6368. ) );
  6369. $isNotice = false;
  6370. if (! empty ( $approval ))
  6371. $isNotice = true;
  6372. $response = array (
  6373. 'error' => 0,
  6374. 'isNotice' => $isNotice
  6375. );
  6376. echo json_encode ( $response );
  6377. exit ();
  6378. }
  6379. public function ajaxCheckInvoiceNoUniqueness() {
  6380. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  6381. Doo::loadModel ( 'invoice' );
  6382. $invoice = new invoice ();
  6383. if (! empty ( $invoiceNo )) {
  6384. Doo::loadModel ( 'invoicePaper' );
  6385. $invoicePaper = new invoicePaper ();
  6386. Doo::loadClass ( 'XDeode' );
  6387. $XDeode = new XDeode ( 5 );
  6388. $ipid = $XDeode->decode ( $invoiceNo );
  6389. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  6390. $info = $invoice->getOne ( array (
  6391. 'where' => "invoiceNo = '" . $paperDetail ['invoiceNo'] . "'",
  6392. 'asArray' => TRUE
  6393. ) );
  6394. if (! empty ( $info )) {
  6395. echo json_encode ( array (
  6396. 'error' => '发票号已存在'
  6397. ) );
  6398. die ();
  6399. } else
  6400. echo json_encode ( array (
  6401. 'ok' => '可以使用!'
  6402. ) );
  6403. die ();
  6404. }
  6405. }
  6406. function ajaxCheckInvoicePrice() {
  6407. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) && is_numeric ( $this->get_args ( 'receivablesPrice' ) ) ? $this->get_args ( 'receivablesPrice' ) : "";
  6408. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  6409. Doo::loadModel ( 'invoice' );
  6410. $invoice = new invoice ();
  6411. Doo::loadModel ( 'invoiceReceivables' );
  6412. $invoiceReceivables = new invoiceReceivables ();
  6413. Doo::loadClass ( 'XDeode' );
  6414. $XDeode = new XDeode ( 5 );
  6415. if (! empty ( $receivablesPrice ) && ! empty ( $iidKey )) {
  6416. $iidKey = $XDeode->decode ( $iidKey );
  6417. $info = $invoice->getInvoiceByIid ( $iidKey );
  6418. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $info ['irid'] );
  6419. if (empty ( $irList ))
  6420. $irList [0] ['sumPrice'] = 0;
  6421. $balance = $info ['invoicePrice'] - $irList [0] ['sumPrice'];
  6422. if ($balance < $receivablesPrice) {
  6423. echo json_encode ( array (
  6424. 'error' => '收款金额超过开票金额。'
  6425. ) );
  6426. die ();
  6427. }
  6428. if ($balance > $receivablesPrice) {
  6429. echo json_encode ( array (
  6430. 'error' => '收款金额低于开票金额。'
  6431. ) );
  6432. die ();
  6433. }
  6434. }
  6435. }
  6436. function ajaxGetInvoiceByNew() {
  6437. Doo::loadModel ( 'invoice' );
  6438. $invoice = new invoice ();
  6439. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );
  6440. echo json_encode ( array (
  6441. 'status' => 1,
  6442. 'detail' => $detail
  6443. ) );
  6444. }
  6445. /**
  6446. * 旧输入导入
  6447. */
  6448. function importInvoice() {
  6449. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  6450. $data ['emsg'] = "";
  6451. if ($emsg != "")
  6452. $data ['emsg'] = "请填写完整的数据";
  6453. $data ['time'] = time ();
  6454. $this->render ( "/admin/invoiceImport", $data );
  6455. }
  6456. function uploadInvoice() {
  6457. // move_uploaded_file($_FILES['Filedata']['tmp_name'], "/upload/".$_FILES['Filedata']['name']);
  6458. if (isset ( $_FILES ['Filedata'] ['name'] )) {
  6459. $file = $_FILES ['Filedata'] ['tmp_name'];
  6460. $error = false;
  6461. if (! is_uploaded_file ( $file )) {
  6462. $error = '400 Bad Request';
  6463. }
  6464. if ($error) {
  6465. header ( 'HTTP/1.0 ' . $error );
  6466. die ( 'Error ' . $error );
  6467. } else {
  6468. include (DOO::conf ()->SITE_PATH . 'protected/plugin/io.han.php');
  6469. $this->IoHandler = new IoHandler ();
  6470. $pics = explode ( '.', $_FILES ['Filedata'] ['name'] );
  6471. // $filedir=$_POST['time'];
  6472. // 调用定义物理路径
  6473. $t = DOO::conf ()->SITE_PATH . "upload/invoice/";
  6474. $this->IoHandler->MakeDir ( $t );
  6475. $filename = $this->_GetFileEXT ( $_FILES ['Filedata'] ['name'] );
  6476. if ($filename != 'xlsx')
  6477. return "";
  6478. // $upload_dir = $t."/".time().rand(10,100).".".$filename;
  6479. $upload_file = iconv ( "UTF-8", "GB2312", $_FILES ["Filedata"] ["name"] );
  6480. $upload_dir = $t . "/" . $upload_file;
  6481. $k = move_uploaded_file ( $file, $upload_dir );
  6482. if ($k) {
  6483. $m = round ( $_FILES ['Filedata'] ['size'] / 1024 / 1024, 2 );
  6484. echo $pics [0] . "." . $filename . "#" . $m . "#" . $_FILES ['Filedata'] ['size'];
  6485. }
  6486. }
  6487. }
  6488. }
  6489. function importInvoiceDo() {
  6490. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  6491. if ($path != "") {
  6492. Doo::loadModel ( 'invoice' );
  6493. Doo::loadModel ( 'staff' );
  6494. $staff = new staff ();
  6495. Doo::loadModel ( 'invoiceStatistics' );
  6496. Doo::loadModel ( 'invoiceOperationLog' );
  6497. echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  6498. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . $path );
  6499. // print_r ( $exlArray );
  6500. // die ();
  6501. // echo json_encode($exlArray);die;
  6502. foreach ( $exlArray as $key => $value ) {
  6503. // 开票
  6504. $invoice = new invoice ();
  6505. $invoice->invoiceNo = $value ['invoiceNo'];
  6506. $invoice->invoiceType = 0;
  6507. if ($value ['invoiceType'] == '专')
  6508. $invoice->invoiceType = 1;
  6509. $invoice->invoicePrice = $value ['invoicePrice'];
  6510. $invoice->invoiceQuantity = 1;
  6511. $invoice->invoiceUnitPrice = $value ['invoicePrice'];
  6512. $invoice->invoiceTitle = $value ['invoiceTitle'];
  6513. if ($value ['invoiceType'] == '专')
  6514. $invoice->invoiceCompany = $value ['invoiceTitle'];
  6515. $invoice->userName = $value ['userName'];
  6516. $sDetail = $staff->getStaffByName ( $value ['userName'] );
  6517. $invoice->sid = $sDetail ['sid'];
  6518. $invoice->cid = $sDetail ['cid'];
  6519. $invoice->categoryName = $sDetail ['category'];
  6520. $invoice->invoiceElement = $value ['invoiceElement'];
  6521. $invoice->remark = $value ['remark'];
  6522. $invoice->date = $value ['date'];
  6523. $invoice->printTime = $value ['date'];
  6524. $invoice->ipSource = 1;
  6525. $invoice->printStatus = 1;
  6526. $invoice->status = 2;
  6527. $invoice->postStatus = 1;
  6528. $invoice->untreadStatus = 0;
  6529. $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  6530. $iid = $invoice->insert ();
  6531. // 汇总
  6532. $invoiceStatistics = new invoiceStatistics ();
  6533. //
  6534. $item = array (
  6535. 'date' => $value ['date'],
  6536. 'priceClass' => 1,
  6537. 'cid' => $sDetail ['cid'],
  6538. 'staff' => $sDetail ['sid'],
  6539. 'invoicePrice' => $value ['invoicePrice']
  6540. );
  6541. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  6542. $invoiceOperationLog = new invoiceOperationLog ();
  6543. $item = array (
  6544. 'date' => date ( "Y-m-d H:i:s" ),
  6545. 'operation' => date ( "Y-m-d" ) . " 导入",
  6546. 'status' => 1,
  6547. 'img' => $sDetail ['avatar'],
  6548. 'username' => $sDetail ['username'],
  6549. 'uid' => $sDetail ['sid'],
  6550. 'category' => $sDetail ['category'],
  6551. 'iid' => $iid
  6552. );
  6553. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  6554. }
  6555. return '/importInvoice?count=' . count ( $exlArray );
  6556. // return "/keyonline";
  6557. }
  6558. echo 'no file';
  6559. }
  6560. function importInvoiceReceivables() {
  6561. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  6562. $data ['emsg'] = "";
  6563. if ($emsg != "")
  6564. $data ['emsg'] = "请填写完整的数据";
  6565. $data ['time'] = time ();
  6566. $this->render ( "/admin/invoiceReceivablesImport", $data );
  6567. }
  6568. // 导入入账数据
  6569. function importInvoiceReceivablesDo() {
  6570. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  6571. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  6572. if ($path != "") {
  6573. Doo::loadModel ( 'invoiceReceivables' );
  6574. Doo::loadModel ( 'invoice' );
  6575. Doo::loadModel ( 'staff' );
  6576. $staff = new staff ();
  6577. Doo::loadModel ( 'invoiceStatistics' );
  6578. // echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  6579. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path ), 'invoiceReceivables' );
  6580. // print_r ( $exlArray );
  6581. // die ();
  6582. // echo json_encode($exlArray);die;
  6583. foreach ( $exlArray as $key => $value ) {
  6584. // 收款
  6585. $invoiceReceivables = new invoiceReceivables ();
  6586. $invoice = new invoice ();
  6587. $invoiceReceivables->bindStatus = 1;
  6588. $invoiceReceivables->receivablesPrice = $value ['receivablesPrice'];
  6589. $invoiceReceivables->receivablesMessage = $value ['receivablesMessage'];
  6590. $invoiceReceivables->receivablesBank = $value ['receivablesBank'];
  6591. $invoiceReceivables->receivablesDate = $value ['receivablesDate'];
  6592. $sDetail = $staff->getStaffByName ( $value ['receivablesStaff'] );
  6593. $invoiceReceivables->receivablesCategory = $sDetail ['cid'] . ':' . $sDetail ['category'];
  6594. $invoiceReceivables->receivablesStaff = $sDetail ['sid'] . '-' . $sDetail ['username'];
  6595. $invoiceReceivables->receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  6596. $invoiceReceivables->sourcePrice = $value ['sourcePrice'];
  6597. $iDetail = $invoice->getInvoiceByInvoiceNo ( $value ['invoiceNo'] );
  6598. $invoiceReceivables->iid = $iDetail ['iid'];
  6599. $irid = $invoiceReceivables->insert ();
  6600. // 发票绑定收款
  6601. $detail = $iDetail;
  6602. $iridString = "";
  6603. if (empty ( $detail ['irid'] ))
  6604. $iridString = $irid;
  6605. else
  6606. $iridString = $detail ['irid'] . ',' . $irid;
  6607. $item = array (
  6608. 'irid' => $iridString,
  6609. 'iid' => $detail ['iid']
  6610. );
  6611. $invoice->setInvoiceByCondition ( $item );
  6612. // 汇总
  6613. $invoiceStatistics = new invoiceStatistics ();
  6614. // 扣除入账统计金额
  6615. $item = array (
  6616. 'date' => $value ['receivablesDate'],
  6617. 'priceClass' => 3,
  6618. 'cid' => $sDetail ['cid'],
  6619. 'staff' => $sDetail ['sid'],
  6620. // 'irid' => $irid,
  6621. 'accountPrice' => $value ['receivablesPrice']
  6622. );
  6623. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  6624. }
  6625. return '/importInvoiceReceivables?count=' . count ( $exlArray );
  6626. echo 'data count ' . count ( $exlArray );
  6627. die ();
  6628. // return "/keyonline";
  6629. }
  6630. echo 'no file';
  6631. }
  6632. function formatExcelToArrayTrain($file_url = "") {
  6633. if (! file_exists ( $file_url )) {
  6634. return array ();
  6635. }
  6636. // Doo::loadClass ( 'PHPExcel' );
  6637. Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  6638. $PHPExcel = new PHPExcel ();
  6639. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  6640. if (! $PHPReader->canRead ( $file_url )) {
  6641. $PHPReader = new PHPExcel_Reader_Excel5 ();
  6642. if (! $PHPReader->canRead ( $file_url )) {
  6643. echo 'no Excel';
  6644. return;
  6645. }
  6646. }
  6647. $PHPExcel = $PHPReader->load ( $file_url );
  6648. /* * 读取excel文件中的第一个工作表 */
  6649. $currentSheet = $PHPExcel->getSheet ( 0 );
  6650. /* * 取得最大的列号 */
  6651. $allColumn = $currentSheet->getHighestColumn ();
  6652. /* * 取得一共有多少行 */
  6653. $allRow = $currentSheet->getHighestRow ();
  6654. $excel_array = array ();
  6655. // die($file_url);
  6656. $conk = 2;
  6657. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  6658. $excel_column = array ();
  6659. // 后期改进
  6660. if ($allColumn == 'AM')
  6661. $allColumn = 'Z';
  6662. /* * 从第A列开始输出 */
  6663. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  6664. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  6665. if ($val instanceof PHPExcel_RichText)
  6666. $val = $val->__toString ();
  6667. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  6668. // $val = "'" . addslashes ( $val ) . "'";
  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. }
  6699. if (! empty ( $excel_column ['invoiceTitle'] ) && ! empty ( $excel_column ['invoiceQuantity'] ) && ! empty ( $excel_column ['invoiceUnitPrice'] ))
  6700. array_push ( $excel_array, $excel_column );
  6701. }
  6702. return $excel_array;
  6703. }
  6704. /**
  6705. * 格式化excel文件为数组
  6706. * @param unknown_type $file_url
  6707. * @param unknown_type $mcid
  6708. */
  6709. function _format_excel_to_array($file_url = "", $sType = "") {
  6710. if (! file_exists ( $file_url )) {
  6711. return array ();
  6712. }
  6713. Doo::loadClass ( 'PHPExcel' );
  6714. // Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  6715. $PHPExcel = new PHPExcel ();
  6716. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  6717. if (! $PHPReader->canRead ( $file_url )) {
  6718. $PHPReader = new PHPExcel_Reader_Excel5 ();
  6719. if (! $PHPReader->canRead ( $file_url )) {
  6720. echo 'no Excel';
  6721. return;
  6722. }
  6723. }
  6724. $PHPExcel = $PHPReader->load ( $file_url );
  6725. /* * 读取excel文件中的第一个工作表 */
  6726. $currentSheet = $PHPExcel->getSheet ( 0 );
  6727. /* * 取得最大的列号 */
  6728. $allColumn = $currentSheet->getHighestColumn ();
  6729. /* * 取得一共有多少行 */
  6730. $allRow = $currentSheet->getHighestRow ();
  6731. $excel_array = array ();
  6732. // die($file_url);
  6733. $conk = 2;
  6734. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  6735. $excel_column = array ();
  6736. // 后期改进
  6737. if ($allColumn == 'AM')
  6738. $allColumn = 'Z';
  6739. /* * 从第A列开始输出 */
  6740. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  6741. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  6742. if ($val instanceof PHPExcel_RichText)
  6743. $val = $val->__toString ();
  6744. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  6745. // $val = "'" . addslashes ( $val ) . "'";
  6746. if ($sType == 'invoiceReceivables') {
  6747. if ($currentColumn == 'A')
  6748. $excel_column ['invoiceNo'] = $val;
  6749. elseif ($currentColumn == 'B')
  6750. $excel_column ['receivablesPrice'] = $val;
  6751. elseif ($currentColumn == 'C') {
  6752. $excel_column ['receivablesMessage'] = $val;
  6753. } elseif ($currentColumn == 'D') {
  6754. $excel_column ['receivablesBank'] = $val;
  6755. } elseif ($currentColumn == 'E') {
  6756. $excel_column ['receivablesDate'] = $this->excelTime ( $val );
  6757. } elseif ($currentColumn == 'F') {
  6758. $excel_column ['receivablesStaff'] = $val;
  6759. } elseif ($currentColumn == 'G') {
  6760. $excel_column ['sourcePrice'] = $val;
  6761. }
  6762. } elseif ($sType == "invoiceTrain") {
  6763. if ($currentColumn == 'A') {
  6764. $excel_column ['invoiceTitle'] = $val;
  6765. } elseif ($currentColumn == 'B')
  6766. $excel_column ['invoiceType'] = $val;
  6767. elseif ($currentColumn == 'C') {
  6768. $excel_column ['TIN'] = $val;
  6769. } elseif ($currentColumn == 'D') {
  6770. $excel_column ['address'] = $val;
  6771. } elseif ($currentColumn == 'E') {
  6772. $excel_column ['phone'] = $val;
  6773. } elseif ($currentColumn == 'F') {
  6774. $excel_column ['bank'] = $val;
  6775. } elseif ($currentColumn == 'G') {
  6776. $excel_column ['bankAccount'] = $val;
  6777. } elseif ($currentColumn == 'H') {
  6778. $excel_column ['invoiceElement'] = $val;
  6779. } elseif ($currentColumn == 'I') {
  6780. $excel_column ['invoiceQuantity'] = $val;
  6781. } elseif ($currentColumn == 'J') {
  6782. $excel_column ['invoiceUnitPrice'] = $val;
  6783. } elseif ($currentColumn == 'K') {
  6784. $excel_column ['remark'] = $val;
  6785. } elseif ($currentColumn == 'L') {
  6786. $excel_column ['recipientsAddress'] = $val;
  6787. } elseif ($currentColumn == 'M') {
  6788. $excel_column ['recipients'] = $val;
  6789. } elseif ($currentColumn == 'N') {
  6790. $excel_column ['recipientsPhone'] = $val;
  6791. }
  6792. } else {
  6793. if ($currentColumn == 'A')
  6794. $excel_column ['invoiceNo'] = $val;
  6795. elseif ($currentColumn == 'B')
  6796. $excel_column ['invoiceType'] = $val;
  6797. elseif ($currentColumn == 'C') {
  6798. $excel_column ['invoicePrice'] = $val;
  6799. } elseif ($currentColumn == 'D') {
  6800. $excel_column ['invoiceTitle'] = $val;
  6801. } elseif ($currentColumn == 'E') {
  6802. $excel_column ['userName'] = $val;
  6803. } elseif ($currentColumn == 'F') {
  6804. $excel_column ['categoryName'] = $val;
  6805. } elseif ($currentColumn == 'G') {
  6806. $excel_column ['invoiceElement'] = $val;
  6807. } elseif ($currentColumn == 'H') {
  6808. $excel_column ['remark'] = $val;
  6809. } elseif ($currentColumn == 'I') {
  6810. $excel_column ['date'] = $this->excelTime ( $val );
  6811. }
  6812. }
  6813. }
  6814. array_push ( $excel_array, $excel_column );
  6815. }
  6816. return $excel_array;
  6817. }
  6818. function excelTime($date, $time = false) {
  6819. if (function_exists ( 'GregorianToJD' )) {
  6820. if (is_numeric ( $date )) {
  6821. $jd = GregorianToJD ( 1, 1, 1970 );
  6822. $gregorian = JDToGregorian ( $jd + intval ( $date ) - 25569 );
  6823. $date = explode ( '/', $gregorian );
  6824. $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" : '');
  6825. return $date_str;
  6826. }
  6827. } else {
  6828. $date = $date > 25568 ? $date + 1 : 25569;
  6829. /* There was a bug if Converting date before 1-1-1970 (tstamp 0) */
  6830. $ofs = (70 * 365 + 17 + 2) * 86400;
  6831. $date = date ( "Y-m-d", ($date * 86400) - $ofs ) . ($time ? " 00:00:00" : '');
  6832. }
  6833. return $date;
  6834. }
  6835. /**
  6836. * 旧输入导入
  6837. */
  6838. function _GetFileEXT($filename) {
  6839. $pics = explode ( '.', $filename );
  6840. $num = count ( $pics );
  6841. return $pics [$num - 1];
  6842. }
  6843. function showCache($path = "", $sid = 0) {
  6844. // if (file_exists ( $path )) {
  6845. // $htm = file_get_contents ( $path );
  6846. // } else {
  6847. Doo::loadModel ( 'invoiceStatistics' );
  6848. $invoiceStatistics = new invoiceStatistics ();
  6849. $isBriefly = $invoiceStatistics->getBrieflyStatistics ( $sid );
  6850. $htm = '<tr><th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计开票</th>
  6851. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['invoicePrice'] . '</td>
  6852. <th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计入账</th>
  6853. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['accountPrice'] . '</td></tr>';
  6854. /*
  6855. * '<tr><th class="taC">今年累计开票</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['invoicePrice'] . '</td> <th class="taC">今年累计入账</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['accountPrice'] . '</td></tr>';
  6856. */
  6857. file_put_contents ( $path, $htm );
  6858. // }
  6859. return $htm;
  6860. }
  6861. /**
  6862. * 生成token
  6863. * @return string
  6864. */
  6865. function set_token() {
  6866. $str = md5 ( uniqid ( md5 ( microtime ( true ) ), true ) ); // 生成一个不会重复的字符串
  6867. $str = sha1 ( $str ); // 加密
  6868. return $str;
  6869. }
  6870. /**
  6871. * 获取get或者POST值
  6872. *
  6873. * @param string $name 属性名称
  6874. * @return fixed 值
  6875. */
  6876. function get_args($name) {
  6877. if (isset ( $_GET [$name] )) {
  6878. if (is_array ( $_GET [$name] ))
  6879. return $_GET [$name];
  6880. else
  6881. return addslashes ( $_GET [$name] );
  6882. } elseif (isset ( $_POST [$name] )) {
  6883. if (is_array ( $_POST [$name] ))
  6884. return $_POST [$name];
  6885. else
  6886. return addslashes ( $_POST [$name] );
  6887. } else
  6888. return false;
  6889. }
  6890. function SafeFilter(&$arr) {
  6891. $ra = Array (
  6892. '/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/',
  6893. '/script/',
  6894. '/javascript/',
  6895. '/vbscript/',
  6896. '/expression/',
  6897. '/applet/',
  6898. '/meta/',
  6899. '/xml/',
  6900. '/blink/',
  6901. '/link/',
  6902. '/style/',
  6903. '/embed/',
  6904. '/object/',
  6905. '/frame/',
  6906. '/layer/',
  6907. '/title/',
  6908. '/bgsound/',
  6909. '/base/',
  6910. '/onload/',
  6911. '/onunload/',
  6912. '/onchange/',
  6913. '/onsubmit/',
  6914. '/onreset/',
  6915. '/onselect/',
  6916. '/onblur/',
  6917. '/onfocus/',
  6918. '/onabort/',
  6919. '/onkeydown/',
  6920. '/onkeypress/',
  6921. '/onkeyup/',
  6922. '/onclick/',
  6923. '/ondblclick/',
  6924. '/onmousedown/',
  6925. '/onmousemove/',
  6926. '/onmouseout/',
  6927. '/onmouseover/',
  6928. '/onmouseup/',
  6929. '/onunload/'
  6930. );
  6931. if (is_array ( $arr )) {
  6932. foreach ( $arr as $key => $value ) {
  6933. if (! is_array ( $value )) {
  6934. if (! get_magic_quotes_gpc ()) // 不对magic_quotes_gpc转义过的字符使用addslashes(),避免双重转义。
  6935. {
  6936. $value = addslashes ( $value ); // 给单引号(')、双引号(")、反斜线(\)与 NUL(NULL 字符)加上反斜线转义
  6937. }
  6938. $value = preg_replace ( $ra, '', $value ); // 删除非打印字符,粗暴式过滤xss可疑字符串
  6939. $arr [$key] = htmlentities ( strip_tags ( $value ) ); // 去除 HTML 和 PHP 标记并转换为 HTML 实体
  6940. } else {
  6941. SafeFilter ( $arr [$key] );
  6942. }
  6943. }
  6944. }
  6945. }
  6946. /**
  6947. * Escape String
  6948. *
  6949. * @access public
  6950. * @param string
  6951. * @param bool whether or not the string will be used in a LIKE condition
  6952. * @return string
  6953. */
  6954. function escape_str($str, $like = FALSE) {
  6955. if (is_array ( $str )) {
  6956. foreach ( $str as $key => $val ) {
  6957. $str [$key] = $this->escape_str ( $val, $like );
  6958. }
  6959. return $str;
  6960. }
  6961. var_dump ( Doo::db ()->getDbObject () );
  6962. die ();
  6963. if (function_exists ( 'mysql_real_escape_string' ) and is_resource ( Doo::db ()->getDbObject () )) { // Doo::db ()->getDbObject()
  6964. $str = mysql_real_escape_string ( $str, Doo::db ()->getDbObject () );
  6965. } elseif (function_exists ( 'mysql_escape_string' )) {
  6966. $str = mysql_escape_string ( $str );
  6967. } else {
  6968. $str = addslashes ( $str );
  6969. }
  6970. // escape LIKE condition wildcards
  6971. if ($like === TRUE) {
  6972. $str = str_replace ( array (
  6973. '%',
  6974. '_'
  6975. ), array (
  6976. '\\%',
  6977. '\\_'
  6978. ), $str );
  6979. }
  6980. return $str;
  6981. }
  6982. /**
  6983. * 获得分页数据
  6984. * @param unknown_type $table
  6985. * @param unknown_type $condition
  6986. * @param unknown_type $on_page
  6987. * @param unknown_type $page_size
  6988. */
  6989. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  6990. $page_c = "";
  6991. $page ['previous'] = $this->get_previous ( $on_page );
  6992. $page ['on_page'] = $on_page;
  6993. $total_count = $this->get_table_count ( $table, $condition );
  6994. $total = intval ( $total_count / $page_size );
  6995. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  6996. $page ['total_data'] = $total_count;
  6997. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  6998. $i = 1;
  6999. $page_max = 1;
  7000. $page_width = 3;
  7001. if ($on_page >= $page_width) {
  7002. $page_max = intval ( $on_page / $page_width ) + 1;
  7003. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  7004. }
  7005. for(; $i <= $page ['total_page']; $i ++) {
  7006. if ($i == $on_page)
  7007. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  7008. else
  7009. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  7010. if ($i == ($page_width * $page_max))
  7011. break;
  7012. }
  7013. $page ['page'] = $page_c;
  7014. $page ['lower'] = (-- $on_page) * $page_size;
  7015. return $page;
  7016. }
  7017. /**
  7018. * 获取上一页
  7019. * @param unknown_type $on_page
  7020. */
  7021. function get_previous($on_page = 1) {
  7022. return $on_page != 0 ? $on_page - 1 : $on_page;
  7023. }
  7024. /**
  7025. * 获取总页数
  7026. * @param unknown_type $table
  7027. * @param unknown_type $condition
  7028. */
  7029. public function get_table_count($table = "", $condition = "") {
  7030. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  7031. $sql = "select count(*) as count from " . $table . " where " . $condition;
  7032. // echo $sql;die;
  7033. $query = Doo::db ()->query ( $sql );
  7034. $result = $query->fetch ();
  7035. return $result ['count'];
  7036. }
  7037. /**
  7038. * 获得分页数据
  7039. * @param unknown_type $table
  7040. * @param unknown_type $condition
  7041. * @param unknown_type $on_page
  7042. * @param unknown_type $page_size
  7043. */
  7044. function getPageBySql($sql = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  7045. $page_c = "";
  7046. $page ['previous'] = $this->get_previous ( $on_page );
  7047. $page ['on_page'] = $on_page;
  7048. $total_count = $this->getTableCountBySql ( $sql );
  7049. $total = intval ( $total_count / $page_size );
  7050. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  7051. $page ['total_data'] = $total_count;
  7052. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  7053. $i = 1;
  7054. $page_max = 1;
  7055. $page_width = 3;
  7056. if ($on_page >= $page_width) {
  7057. $page_max = intval ( $on_page / $page_width ) + 1;
  7058. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  7059. }
  7060. for(; $i <= $page ['total_page']; $i ++) {
  7061. if ($i == $on_page)
  7062. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  7063. else
  7064. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  7065. if ($i == ($page_width * $page_max))
  7066. break;
  7067. }
  7068. $page ['page'] = $page_c;
  7069. $page ['lower'] = (-- $on_page) * $page_size;
  7070. return $page;
  7071. }
  7072. /**
  7073. * 获得总页数 sql
  7074. * @param string $type
  7075. * @return boolean[]
  7076. */
  7077. public function getTableCountBySql($sql = "") {
  7078. $query = Doo::db ()->query ( $sql );
  7079. $result = $query->fetchAll ();
  7080. return count ( $result );
  7081. }
  7082. function isInvoiceNew($type = "GLOBAL") {
  7083. Doo::loadModel ( 'invoice' );
  7084. $invoice = new invoice ();
  7085. Doo::loadModel ( 'invoiceReceivables' );
  7086. $invoiceReceivables = new invoiceReceivables ();
  7087. Doo::loadModel ( 'staff' );
  7088. $staff = new staff ();
  7089. $st = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  7090. // 我的发票待处理
  7091. $pendingInvoice = $invoice->getOne ( array ( // or (status=2 and printStatus=1 and untreadStatus=0 ) or (status=2 and printStatus=1 and untreadStatus=2 )
  7092. 'where' => "(status=3 or status=4) and isDelete=0 and sid=" . $st [0] ['sid'],
  7093. 'desc' => 'iid',
  7094. 'asArray' => TRUE
  7095. ) );
  7096. // 我的收款待入账
  7097. /*
  7098. * $myClaim = $invoiceReceivables->getOne ( array ( 'where' => " receivablesStaff like '" . $st [0] ['sid'] . "-%' and receivablesCategory like '" . $st [0] ['cid'] . ":%' and bindStatus=0", 'desc' => 'irid', 'asArray' => TRUE ) );
  7099. */
  7100. // 发票审批
  7101. $approval = $invoice->getOne ( array (
  7102. 'where' => 'status=1 and pendingApprovals=' . $st [0] ['sid'],
  7103. 'desc' => 'iid',
  7104. 'asArray' => true
  7105. ) );
  7106. // 发票邮寄
  7107. $post = $invoice->getOne ( array (
  7108. 'where' => "postStatus=0 and printStatus=1 and isDelete=0 and doPost=1 and status=2",
  7109. 'asArray' => TRUE
  7110. ) );
  7111. // 发票打印
  7112. $print = $invoice->getOne ( array (
  7113. 'where' => "status=2 and printStatus=0 and untreadStatus=0 and moldManage like '%[\"" . $st [0] ['sid'] . "\",%'",
  7114. 'desc' => 'iid',
  7115. 'asArray' => TRUE
  7116. ) );
  7117. // 发票退票 printStatus=1 and
  7118. $untread = $invoice->getOne ( array (
  7119. 'where' => " untreadStatus=1 and status=2 ",
  7120. 'asArray' => TRUE
  7121. ) );
  7122. $new = array (
  7123. 'GLOBAL' => FALSE,
  7124. 'pendingInvoice' => FALSE,
  7125. // 'myClaim' => FALSE,
  7126. 'approval' => FALSE,
  7127. 'post' => FALSE,
  7128. 'print' => FALSE,
  7129. 'untread' => FALSE
  7130. );
  7131. // || ! empty ( $myClaim )
  7132. if (! empty ( $pendingInvoice ) || ! empty ( $approval ) || ! empty ( $post ) || ! empty ( $print ) || ! empty ( $untread ))
  7133. $new ['GLOBAL'] = TRUE;
  7134. if (! empty ( $pendingInvoice ))
  7135. $new ['pendingInvoice'] = TRUE;
  7136. // if (! empty ( $myClaim ))
  7137. // $new ['myClaim'] = TRUE;
  7138. if (! empty ( $approval ))
  7139. $new ['approval'] = TRUE;
  7140. if (! empty ( $post ))
  7141. $new ['post'] = TRUE;
  7142. if (! empty ( $print ))
  7143. $new ['print'] = TRUE;
  7144. if (! empty ( $untread ))
  7145. $new ['untread'] = TRUE;
  7146. return $new;
  7147. }
  7148. function setWXMsg($rid, $typeMsg = '') {
  7149. Doo::loadModel ( 'invoice' );
  7150. $invoice = new invoice ();
  7151. $invoiceDetail = $invoice->getOne ( array (
  7152. 'where' => 'iid=' . $rid,
  7153. 'asArray' => true
  7154. ) );
  7155. if (! empty ( $invoiceDetail )) {
  7156. Doo::loadModel ( 'staff' );
  7157. $staff = new staff ();
  7158. $staffmsg = $staff->getOne ( array (
  7159. 'where' => "sid='" . $invoiceDetail ['sid'] . "'",
  7160. 'asArray' => TRUE
  7161. ) );
  7162. if (! empty ( $staffmsg ['wxid'] )) {
  7163. require_once (SITE_PATH . '/protected/class/client.php');
  7164. $client = new client ( 'http://m.cld.smartcost.com.cn/' );
  7165. $user = $staffmsg ['wxid'];
  7166. $expCom = explode ( ":", $invoiceDetail ['expressCompany'] );
  7167. if (empty ( $expCom ))
  7168. $expCom [0] = '';
  7169. $msg = "";
  7170. if (empty ( $typeMsg ))
  7171. $msg = '太好了,您的发票' . $invoiceDetail ['invoiceSerial'] . ' 已邮寄 ' . $expCom [0] . ' ,快递号: <a href="https://m.kuaidi100.com/result.jsp?nu=' . $invoiceDetail ['expressNumber'] . '" >' . $invoiceDetail ['expressNumber'] . '</a>';
  7172. elseif ($typeMsg == "PRINT")
  7173. $msg = '太好了,您的发票已打印完成。';
  7174. $result = $client->SendMsg ( $user, $msg, 'text' );
  7175. }
  7176. }
  7177. }
  7178. /**
  7179. * 获取微信部门
  7180. * @param string $category
  7181. * @return number|mixed
  7182. */
  7183. function getToparty($category = '') {
  7184. $token = $this->getAccessToken (); //
  7185. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token={$token}&id=5" ), true );
  7186. $toparty = 0;
  7187. foreach ( $result ['department'] as $key => $value ) {
  7188. if ($value ['name'] == $category)
  7189. $toparty = $value ['id'];
  7190. }
  7191. return $toparty;
  7192. }
  7193. /**
  7194. * 获得某部门下的用户
  7195. * @param string $toparty
  7196. */
  7197. function getUserByToparty($toparty = '') {
  7198. $token = $this->getAccessToken (); //
  7199. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token={$token}&department_id={$toparty}" ), true );
  7200. $userList = array ();
  7201. foreach ( $result ['userlist'] as $key => $value ) {
  7202. array_push ( $userList, "'" . $value ['userid'] . "'" );
  7203. }
  7204. return $userList;
  7205. }
  7206. function msgSendToparty($msg, $title, $url, $toparty, $text = '') {
  7207. $token = $this->getAccessToken ();
  7208. if ($text == 'text') {
  7209. $data = '{
  7210. "touser": "' . $toparty . '",
  7211. "toparty": "",
  7212. "totag": "",
  7213. "msgtype": "text",
  7214. "agentid": 1000002,
  7215. "text": {
  7216. "content": "' . $msg . '"
  7217. },
  7218. "safe":0
  7219. }';
  7220. }
  7221. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  7222. if ($result->errmsg != 'ok') {
  7223. return 0;
  7224. } else {
  7225. return 1;
  7226. }
  7227. }
  7228. /**
  7229. * 获得可以发送微信用户列表
  7230. * @param string $category
  7231. * @return string
  7232. */
  7233. function getWxidByCategory($category = "") {
  7234. if (empty ( $category ))
  7235. return "";
  7236. Doo::loadModel ( 'staff' );
  7237. $staff = new staff ();
  7238. $toparty = $this->getToparty ( $category );
  7239. $wxList = array ();
  7240. $wxString = "";
  7241. if (! empty ( $toparty )) {
  7242. $userList = $this->getUserByToparty ( $toparty );
  7243. $userCon = implode ( ',', $userList );
  7244. // echo $userCon;
  7245. $sidList = $staff->getStaffByWxid ( $userCon );
  7246. foreach ( $sidList as $key => $value ) {
  7247. $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  7248. if ($falg) {
  7249. array_push ( $wxList, $value ['wxid'] );
  7250. }
  7251. }
  7252. $wxString = implode ( '|', $wxList );
  7253. }
  7254. return $wxString;
  7255. }
  7256. /**
  7257. * 读取发送信息规则判断是否需要发送
  7258. * @param number $sid
  7259. * @param string $sendType
  7260. * @return boolean
  7261. */
  7262. function isSendNotification($sid = 0, $sendType = '') {
  7263. Doo::loadModel ( "notificationConf" );
  7264. $notificationConf = new notificationConf ();
  7265. $detail = $notificationConf->getNotificationConfBySid ( $sid );
  7266. $conf = array ();
  7267. $sendFlag = true;
  7268. if (! empty ( $detail )) {
  7269. $conf = json_decode ( $detail ['conf'], true );
  7270. if (! empty ( $sendType )) {
  7271. if (isset ( $conf [$sendType] )) {
  7272. if ($conf [$sendType] == "CLOSE")
  7273. $sendFlag = false;
  7274. elseif ($conf [$sendType] == "Weekend") {
  7275. $day = date ( "w" );
  7276. if (1 <= $day && 5 >= $day)
  7277. $sendFlag = false;
  7278. } elseif ($conf [$sendType] == "OneToFriday") {
  7279. $day = date ( "w" );
  7280. if (0 == $day || 6 == $day)
  7281. $sendFlag = false;
  7282. }
  7283. }
  7284. } else
  7285. $sendFlag = false;
  7286. }
  7287. return $sendFlag;
  7288. }
  7289. /**
  7290. * 根据规则发送信息
  7291. * @param unknown $msg
  7292. * @param unknown $title
  7293. * @param unknown $url
  7294. * @param unknown $user
  7295. * @param string $text
  7296. * @return number
  7297. */
  7298. private function msgSend($msg, $title, $url, $user, $sid = 0, $sendType = '') {
  7299. $token = $this->getAccessToken ();
  7300. $falg = $this->isSendNotification ( $sid, $sendType );
  7301. // if ($text == 'text') {
  7302. // $data = '{
  7303. // "touser": "' . $user . '",
  7304. // "toparty": "",
  7305. // "totag": "",
  7306. // "msgtype": "text",
  7307. // "agentid": 1000002,
  7308. // "text": {
  7309. // "content": "' . $msg . '"
  7310. // },
  7311. // "safe":0
  7312. // }';
  7313. // } else {
  7314. $data = '{
  7315. "touser": "' . $user . '",
  7316. "toparty": "",
  7317. "totag": "",
  7318. "msgtype": "news",
  7319. "agentid": 1000002,
  7320. "news": {
  7321. "articles":[
  7322. {
  7323. "title": "' . $title . '",
  7324. "description": "' . $msg . '",
  7325. "url": "' . $url . '",
  7326. "picurl": ""
  7327. }
  7328. ]
  7329. }
  7330. }';
  7331. // }
  7332. if ($falg) {
  7333. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  7334. if ($result->errmsg != 'ok') {
  7335. return 0;
  7336. } else {
  7337. return 1;
  7338. }
  7339. } else
  7340. return 0;
  7341. }
  7342. private function getAccessToken() {
  7343. // access_token 应该全局存储与更新,以下代码以写入到文件中做示例
  7344. // $file = './access_token.txt';
  7345. // $data = json_decode ( file_get_contents ( $file ) );
  7346. // if ($data->expire_time < time () or ! $data->expire_time) {
  7347. // 如果是企业号用以下URL获取access_token
  7348. $url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$this->appId&corpsecret=$this->appSecret";
  7349. // $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$this->appId&secret=$this->appSecret";
  7350. $res = json_decode ( $this->httpGet ( $url ) );
  7351. $access_token = $res->access_token;
  7352. // echo $access_token;
  7353. // if ($access_token) {
  7354. // $data->expire_time = time () + 7000;
  7355. // $data->access_token = $access_token;
  7356. // $fp = fopen ( $file, "w" );
  7357. // fwrite ( $fp, json_encode ( $data ) );
  7358. // fclose ( $fp );
  7359. // }
  7360. // } else {
  7361. // $access_token = $data->access_token;
  7362. // }
  7363. return $access_token;
  7364. }
  7365. private function httpGet($url) {
  7366. $curl = curl_init ();
  7367. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  7368. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  7369. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  7370. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  7371. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  7372. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  7373. curl_setopt ( $curl, CURLOPT_URL, $url );
  7374. $res = curl_exec ( $curl );
  7375. curl_close ( $curl );
  7376. return $res;
  7377. }
  7378. private function httpPost($url, $data) {
  7379. $curl = curl_init ();
  7380. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  7381. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  7382. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  7383. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  7384. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  7385. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  7386. curl_setopt ( $curl, CURLOPT_URL, $url );
  7387. curl_setopt ( $curl, CURLOPT_POST, 1 );
  7388. curl_setopt ( $curl, CURLOPT_POSTFIELDS, $data );
  7389. $res = curl_exec ( $curl );
  7390. curl_close ( $curl );
  7391. return $res;
  7392. }
  7393. }
  7394. ?>