InvoiceController.php 314 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561
  1. <?php
  2. /**
  3. * 开票功能控制器
  4. * @author CP
  5. * @version 1.0
  6. * @namespace invoice
  7. * @package invoiceController
  8. */
  9. class InvoiceController extends DooController {
  10. public $staff;
  11. public $NEW;
  12. public $data;
  13. private $INVOICEKEY = "APPROVAL";
  14. private $INVOICECOLLECTPATH = "protected/cache/invoiceCollect/";
  15. private $ACTION = '';
  16. private $appId = 'wx3ee46531947a1384';
  17. private $appSecret = 'awGWzy3J5q_96VXKBLA2BQ9RpiT0LiPXnkMF-xV6h5o'; // awGWzy3J5q_96VXKBLA2BXU6mVCGynPGD-sxUCsdNDE //'PeiQVH8tbQE7pM9pVO4AIPlX9FFNpwu7O6Iy6VFcAVtpjTA3Qn42dbNmktBFkUHo';
  18. public function beforeRun($resource, $action) {
  19. Doo::loadModel ( "invoiceManage" );
  20. $invoiceManage = new invoiceManage ();
  21. Doo::loadClass ( 'XDeode' );
  22. $XDeode = new XDeode ( 5 );
  23. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  24. header ( 'Content-Type:text/html;charset=utf-8' );
  25. $moldList = $invoiceManage->getInvoiceByStaff ( $sid );
  26. if (empty ( $moldList )) {
  27. $flag = false;
  28. $uGroups = 'ordinary';
  29. if (Doo::acl ()->isAllowed ( $uGroups, $resource, $action )) {
  30. $flag = true;
  31. }
  32. } else {
  33. $flag = false;
  34. array_push ( $moldList, array (
  35. 'mold' => 'ordinary'
  36. ) );
  37. // 删除审批人后-加入权限问题-暂时关闭
  38. $fileInvoice = file_get_contents ( "protected/config/invoice/invoice.ini" );
  39. $fiML = json_decode ( $fileInvoice, true );
  40. if (empty ( $fiML ))
  41. $fiML = array ();
  42. foreach ( $fiML as $key => $value ) {
  43. $sidList = explode ( ',', $value );
  44. foreach ( $sidList as $k => $v ) {
  45. if ($v == $sid) {
  46. array_push ( $moldList, array (
  47. 'mold' => $key
  48. ) );
  49. break;
  50. }
  51. }
  52. }
  53. foreach ( $moldList as $value ) {
  54. if (Doo::acl ()->isAllowed ( $value ['mold'], $resource, $action )) {
  55. $flag = true;
  56. break;
  57. }
  58. }
  59. }
  60. /*
  61. * Doo::acl()->isAllowed($uGroups['groups'], $resource, $action);
  62. */
  63. // 单独判断办事处汇总的访问权限 invoiceAggregateCategoryDetail,invoiceAggregateStaffDetail
  64. if ($action == 'invoiceAggregateCategoryDetail' || $action == 'invoiceAggregateStaffDetail') {
  65. Doo::loadModel ( "invoiceCategoryManage" );
  66. $invoiceCategoryManage = new invoiceCategoryManage ();
  67. $icm = $invoiceCategoryManage->getInvoiceCMByStaff ( $sid );
  68. if (empty ( $icm ))
  69. die ( 'illegal request' );
  70. }
  71. // 单独判断应收款访问权限
  72. if ($action == 'invoiceAggregateCompanyDetail') {
  73. Doo::loadModel ( "invoiceCompanyManage" );
  74. $invoiceCompanyManage = new invoiceCompanyManage ();
  75. $icm = $invoiceCompanyManage->getInvoiceCMByStaff ( $sid );
  76. if (empty ( $icm ))
  77. die ( 'illegal request' );
  78. }
  79. // 主权限获得与判断
  80. Doo::loadModel ( 'staff' );
  81. $staff = new staff ();
  82. $detail = $staff->getStaffBySid ( $_COOKIE ["staff"] );
  83. $accessModular = 'INVOICE';
  84. if (empty ( $detail ['cldAccessArray'] ))
  85. die ( 'illegal request' );
  86. else {
  87. if (in_array ( $accessModular, $detail ['cldAccessArray'] )) {
  88. if (Doo::acl ()->isAllowed ( $accessModular, $resource, $action )) {
  89. $flag = true;
  90. } else {
  91. $flag = false;
  92. }
  93. } else {
  94. die ( 'illegal request' );
  95. }
  96. }
  97. if (! $flag)
  98. die ( 'illegal request' );
  99. }
  100. function __construct() {
  101. if (isset ( $_COOKIE ["staff"] )) {
  102. if (! empty ( $_COOKIE ["staff"] )) {
  103. Doo::loadModel ( 'staff' );
  104. $staff = new staff ();
  105. $uriPartsOrig = explode ( '/', $_SERVER ['REQUEST_URI'] );
  106. $this->ACTION = $uriPartsOrig [1];
  107. $this->data ['new'] = $this->isInvoiceNew ();
  108. $this->staff = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  109. $this->data ['isStaffCompleteMsg'] = false;
  110. $detail = $staff->checkStaffInfoIsComplete ( $_COOKIE ["staff"] );
  111. if (! empty ( $detail ))
  112. $this->data ['isStaffCompleteMsg'] = true;
  113. return "/";
  114. }
  115. }
  116. Doo::loadCore ( 'uri/DooUriRouter' );
  117. $router = new DooUriRouter ();
  118. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  119. if ($routeRs ['1'] != "login") {
  120. header ( 'Content-Type:text/html;charset=utf-8' );
  121. @header ( "Location: /login" );
  122. }
  123. }
  124. function testSend() {
  125. // 测试根据规则发送信息 普通发送
  126. // $pendingApprovalsSid = 41;
  127. // Doo::loadModel ( 'staff' );
  128. // $staff = new staff ();
  129. // $username2 = $staff->getOne ( array ( 'select' => 'wxid', 'where' => 'sid=' . $pendingApprovalsSid, 'asArray' => TRUE ) );
  130. // // 发送微信审批通知
  131. // $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  132. // $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  133. // Doo::loadModel ( 'staff' );
  134. // $staff = new staff ();
  135. // $toparty = $this->getToparty ( '广东办' );
  136. // $wxList = array ();
  137. // if (! empty ( $toparty )) {
  138. // $userList = $this->getUserByToparty ( $toparty );
  139. // $userCon = implode ( ',', $userList );
  140. // // echo $userCon;
  141. // $sidList = $staff->getStaffByWxid ( $userCon );
  142. // foreach ( $sidList as $key => $value ) {
  143. // $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  144. // if ($falg) {
  145. // array_push ( $wxList, $value ['wxid'] );
  146. // }
  147. // }
  148. // $wxString = implode ( '|', $wxList );
  149. // print_r ( $wxList );
  150. // echo $wxString;
  151. // }
  152. // 测试发送
  153. /*
  154. * //$toparty = $this->getWxidByCategory( $receivablesCategory [1] ); $toparty = $this->getToparty ( $receivablesCategory [1] ); $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。'; if ($toparty != 0) $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  155. */
  156. // print_r ( $userList );
  157. // $msTouser='caipin|outaozhen';
  158. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  159. // $title2 = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  160. // $hfreult = $this->msgSend ( '', $title2, '', 'outaozhen' );
  161. // $toparty= $this->getToparty('广东办');
  162. // $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  163. // $toparty = 26;
  164. // $msg = '';
  165. // $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/1.html';
  166. // $hfreult = $this->msgSendToparty ( $msg, '', '', $toparty,'text' );
  167. }
  168. function invoice() {
  169. Doo::loadModel ( 'invoice' );
  170. $invoice = new invoice ();
  171. Doo::loadModel ( 'express' );
  172. $express = new express ();
  173. $expressList = $express->getExpressByAll ();
  174. $this->data ['expressList'] = $expressList;
  175. // Doo::loadModel ( 'invoiceReceivables' );
  176. // $invoiceReceivables = new invoiceReceivables ();
  177. // $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  178. Doo::loadClass ( 'XDeode' );
  179. $XDeode = new XDeode ( 5 );
  180. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  181. Doo::loadModel ( 'invoiceStatistics' );
  182. $invoiceStatistics = new invoiceStatistics ();
  183. $isMonth = $invoiceStatistics->getStatisticsByMonth ( $sid );
  184. // 缓存统计结果
  185. $year = date ( "Y" );
  186. $tmp_date = date ( "Ym" );
  187. $tmp_year = substr ( $tmp_date, 0, 4 );
  188. $tmp_mon = substr ( $tmp_date, 4, 2 );
  189. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  190. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  191. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . "_" . $sid . ".htm";
  192. if (is_file ( $path ))
  193. $htm = file_get_contents ( $path );
  194. else
  195. $htm = $this->showCache ( $path, $sid );
  196. $invoiceList = $invoice->getMyInvoice ( $sid );
  197. $sql = 'status=2 and printStatus=1 and irid!="" and sid=' . $sid;
  198. $list = $invoice->getInvoiceByUntreadStatusPage ( 4, $sql );
  199. // 我的待入账发票 and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  200. $sql = "status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid=" . $sid;
  201. $myInvoiceUnAccount = $invoice->getInvoiceByUntreadStatusPage ( 4, $sql );
  202. // 获得已退票功能
  203. $untreadStatusList = $invoice->getMyInvoiceByUntreadStatus ( 2, 0, 5, $sid );
  204. $this->data ['untreadStatusList'] = $untreadStatusList;
  205. // print_r($untreadStatusList);
  206. $this->data ['isMonth'] = $isMonth;
  207. $this->data ['htm'] = $htm;
  208. $this->data ['invoiceList'] = $invoiceList;
  209. $this->data ['receivablesList'] = $list;
  210. $this->data ['myInvoiceUnAccount'] = $myInvoiceUnAccount;
  211. $this->data ['memu'] = "invoice";
  212. $this->data ['staff'] = $this->staff;
  213. $this->data ['receiptMemu'] = 'invoice';
  214. $this->render ( "/admin/invoice", $this->data );
  215. }
  216. function invoiceExpress() {
  217. $expressCom = isset ( $this->params ['expressCom'] ) ? $this->params ['expressCom'] : "";
  218. $expressNumber = isset ( $this->params ['expressNumber'] ) ? $this->params ['expressNumber'] : "";
  219. $this->data ['expressCom'] = $expressCom;
  220. $this->data ['expressNumber'] = $expressNumber;
  221. $this->render ( "/admin/invoiceExpress", $this->data );
  222. }
  223. function invoiceAdd() {
  224. session_start ();
  225. Doo::loadModel ( 'invoice' );
  226. $invoice = new invoice ();
  227. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );
  228. Doo::loadModel ( 'L_category' );
  229. $lCategory = new L_category ();
  230. $category = $lCategory->find ( array (
  231. 'asArray' => true
  232. ) );
  233. $this->data ['category'] = $category;
  234. Doo::loadModel ( 'invoiceTraining' );
  235. $invoiceTraining = new invoiceTraining ();
  236. $itList = $invoiceTraining->getInvoiceTrainingByCid ( $this->staff [0] ['cid'] );
  237. Doo::loadModel ( 'receipt' );
  238. $receipt = new receipt ();
  239. foreach ( $itList as $key => $value ) { // 不展示已结算完结的培训班
  240. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $value ['itid'] );
  241. if (! empty ( $receiptDetail )) {
  242. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9) {
  243. unset ( $itList [$key] );
  244. }
  245. }
  246. }
  247. $this->data ['itList'] = $itList;
  248. $token = $this->set_token ();
  249. $_SESSION ['token_' . $this->staff [0] ['sidKey']] = $token;
  250. $this->data ['token'] = $token;
  251. $this->data ['memu'] = "invoice";
  252. $this->data ['staff'] = $this->staff;
  253. $this->data ['receiptMemu'] = 'invoice';
  254. $this->render ( "/admin/invoiceAdd", $this->data );
  255. }
  256. /**
  257. * 自更新发票信息库
  258. * @param unknown $invoicePrintDetail
  259. */
  260. function autoUpdateInvoiceInfoBase($invoicePrintDetail) {
  261. // 发票信息库
  262. Doo::loadModel ( 'invoiceInfoBase' );
  263. $invoiceInfoBase = new invoiceInfoBase ();
  264. $updateDate = strtotime ( $invoicePrintDetail ['date'] );
  265. $TIN = $invoicePrintDetail ['TIN'];
  266. $invoiceTitle = $invoicePrintDetail ['invoiceTitle'];
  267. if (empty ( $invoiceTitle ))
  268. $invoiceTitle = $invoicePrintDetail ['invoiceCompany'];
  269. $IIBList = $invoiceInfoBase->getInvoiceInfoByTT ( $TIN, $invoiceTitle );
  270. // 确认有该条发票信息
  271. $invoiceInfoBase = new invoiceInfoBase ();
  272. if (! empty ( $IIBList )) {
  273. // 发票库里的信息数量
  274. $IIBListCount = count ( $IIBList );
  275. if ($IIBListCount == 1) { // 更新发票--提交是最新的时间
  276. $item = array (
  277. 'iibID' => $IIBList [0] ['iibID'],
  278. 'invoiceTitle' => $invoiceTitle,
  279. 'TIN' => $TIN
  280. );
  281. if (! empty ( $invoicePrintDetail ['address'] )) {
  282. $item += array (
  283. 'address' => $invoicePrintDetail ['address']
  284. );
  285. }
  286. if (! empty ( $invoicePrintDetail ['phone'] )) {
  287. $item += array (
  288. 'phone' => $invoicePrintDetail ['phone']
  289. );
  290. }
  291. if (! empty ( $invoicePrintDetail ['bank'] )) {
  292. $item += array (
  293. 'bank' => $invoicePrintDetail ['bank']
  294. );
  295. }
  296. if (! empty ( $invoicePrintDetail ['bankAccount'] )) {
  297. $item += array (
  298. 'bankAccount' => $invoicePrintDetail ['bankAccount']
  299. );
  300. }
  301. if ($updateDate >= strtotime ($IIBList [0] ['updateDate'])) {
  302. $item += array (
  303. 'updateDate' => $invoicePrintDetail ['date']
  304. );
  305. $invoiceInfoBase->setInvoiceInfoBaseByCondition ( $item );
  306. }
  307. } else { // 删除多张发票,重新添加发票
  308. $iibIDStr = '';
  309. $iibID = array ();
  310. foreach ( $IIBList as $key => $value ) {
  311. array_push ( $iibID, $value ['iibID'] );
  312. }
  313. $iibIDStr = implode ( ",", $iibID ); // 删除
  314. $invoiceInfoBase->delInvoiceInfoBaseByIibStr ( $iibIDStr );
  315. $item = array (
  316. 'invoiceTitle' => $invoiceTitle,
  317. 'TIN' => $TIN,
  318. 'address' => $invoicePrintDetail ['address'],
  319. 'phone' => $invoicePrintDetail ['phone'],
  320. 'bank' => $invoicePrintDetail ['bank'],
  321. 'bankAccount' => $invoicePrintDetail ['bankAccount'],
  322. 'updateDate' => $invoicePrintDetail ['date']
  323. );
  324. $invoiceInfoBase->addInvoiceInfoBase ( $item );
  325. }
  326. } else { // 没有新增发票信息
  327. $item = array (
  328. 'invoiceTitle' => $invoiceTitle,
  329. 'TIN' => $TIN,
  330. 'address' => $invoicePrintDetail ['address'],
  331. 'phone' => $invoicePrintDetail ['phone'],
  332. 'bank' => $invoicePrintDetail ['bank'],
  333. 'bankAccount' => $invoicePrintDetail ['bankAccount'],
  334. 'updateDate' => $invoicePrintDetail ['date']
  335. );
  336. $invoiceInfoBase->addInvoiceInfoBase ( $item );
  337. }
  338. }
  339. function invoiceAddFill() {
  340. session_start ();
  341. Doo::loadModel ( 'invoice' );
  342. $invoice = new invoice ();
  343. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );
  344. Doo::loadModel ( 'L_category' );
  345. $lCategory = new L_category ();
  346. $category = $lCategory->find ( array (
  347. 'asArray' => true
  348. ) );
  349. $this->data ['category'] = $category;
  350. Doo::loadModel ( 'invoiceTraining' );
  351. $invoiceTraining = new invoiceTraining ();
  352. $itList = $invoiceTraining->getInvoiceTrainingByCid ( $this->staff [0] ['cid'] );
  353. $this->data ['itList'] = $itList;
  354. Doo::loadModel ( 'invoice' );
  355. $invoice = new invoice ();
  356. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );
  357. $detail ['mailItemsArray'] = json_decode ( $detail ['mailItemsJson'], true );
  358. $token = $this->set_token ();
  359. $_SESSION ['token_' . $this->staff [0] ['sidKey']] = $token;
  360. $this->data ['token'] = $token;
  361. $this->data ['invoiceDetail'] = $detail;
  362. $this->data ['memu'] = "invoice";
  363. $this->data ['staff'] = $this->staff;
  364. $this->data ['receiptMemu'] = 'invoice';
  365. $this->render ( "/admin/invoiceAddFill", $this->data );
  366. }
  367. /**
  368. * 提交一份开票申请,并记录下操作日志
  369. *
  370. * @since 1.0.0
  371. * @var integer cid 办事处ID
  372. * @var integer invoiceType 发票类型
  373. * @var integer doPost 是否邮寄
  374. * @var integer invoicePrice 开票金额
  375. * @var string invoiceElement 开票内容
  376. * @var string invoiceTitle 发票抬头
  377. * @var string invoiceCompany 单位名称
  378. * @var string TIN 纳税人识别码
  379. * @var string address 注册地址
  380. * @var string phone 注册电话
  381. * @var string bank 开户银行
  382. * @var string bankAccount 银行账户
  383. * @var string recipients 收件人
  384. * @var string recipientsPhone 收件人手机/电话
  385. * @var string recipientsAddress 收件地址
  386. * @var string mailItems 邮寄物品
  387. * @var string remark 备注
  388. * @return string 返回跳转开票主页路径
  389. */
  390. function invoiceAddDo() {
  391. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  392. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  393. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  394. // $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  395. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  396. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  397. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  398. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  399. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  400. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  401. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  402. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  403. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  404. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  405. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  406. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  407. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  408. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  409. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  410. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  411. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  412. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  413. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  414. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  415. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  416. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  417. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  418. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  419. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  420. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  421. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  422. $trainId = $this->get_args ( 'trainId' ) ? $this->get_args ( 'trainId' ) : 0;
  423. $settlementType = $this->get_args ( 'settlementType' ) ? $this->get_args ( 'settlementType' ) : "";
  424. /*
  425. * $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;
  426. */
  427. $token = $this->get_args ( 'token' ) ? $this->get_args ( 'token' ) : "";
  428. if (empty ( $token )) {
  429. die ( 'illegal request-token' );
  430. } else {
  431. session_start ();
  432. if ($_SESSION ['token_' . $this->staff [0] ['sidKey']] != $token) {
  433. header ( 'Content-Type:text/html;charset=utf-8' );
  434. die ( '请勿重复申请发票' );
  435. } else {
  436. $_SESSION ['token_' . $this->staff [0] ['sidKey']] = '';
  437. }
  438. }
  439. if ($invoiceType == 1) {
  440. $temporary = $invoiceQuantity * $invoiceUnitPrice;
  441. if ($temporary > 10000) {
  442. header ( 'Content-Type:text/html;charset=utf-8' );
  443. die ( '专用发票总金额暂时不能超过10000.00(一万)元。' );
  444. // die ( 'illegal request-Please priceError' );
  445. }
  446. }
  447. if (empty ( $this->staff [0] ))
  448. die ( 'illegal request-Please login' );
  449. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $settlementType )) {
  450. Doo::loadModel ( 'invoice' );
  451. $invoice = new invoice ();
  452. Doo::loadModel ( 'L_category' );
  453. $lCategory = new L_category ();
  454. Doo::loadModel ( 'invoiceManage' );
  455. $invoiceManage = new invoiceManage ();
  456. Doo::loadModel ( 'invoiceOperationLog' );
  457. $invoiceOperationLog = new invoiceOperationLog ();
  458. Doo::loadClass ( 'XDeode' );
  459. $XDeode = new XDeode ( 5 );
  460. $trainId = $XDeode->decode ( $trainId );
  461. $categoryDetil = $lCategory->getOne ( array (
  462. 'SELECT' => 'title',
  463. 'where' => 'cid=' . $cid,
  464. 'asArray' => true
  465. ) );
  466. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  467. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  468. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  469. // print_r(current($invoiceManageDetail ['staffList']));
  470. // die;
  471. $moldManage = array ();
  472. foreach ( $invoiceManageList as $key => $value ) {
  473. if ($value ['mold'] == '发票打印')
  474. $moldManage [$value ['mold']] = $value ['staffList'];
  475. elseif ($value ['mold'] == '发票邮寄')
  476. $moldManage [$value ['mold']] = $value ['staffList'];
  477. elseif ($value ['mold'] == '发票退票')
  478. $moldManage [$value ['mold']] = $value ['staffList'];
  479. }
  480. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  481. $st = '';
  482. if ($settlementType == 'SOFTWARE') {
  483. $st = 0;
  484. $trainId = 0;
  485. } elseif ($settlementType == 'TRAINING') {
  486. $st = 1;
  487. if (empty ( $trainId ) && ! is_numeric ( $trainId )) {
  488. die ( 'illegal request-trainingIdError' );
  489. }
  490. } else {
  491. die ( 'illegal request-settlementError' );
  492. }
  493. $item = array (
  494. 'cid' => $cid,
  495. 'categoryName' => $categoryDetil ['title'],
  496. 'invoiceElement' => $invoiceElement,
  497. 'invoiceQuantity' => $invoiceQuantity,
  498. 'invoiceUnitPrice' => $invoiceUnitPrice,
  499. 'invoicePrice' => $invoicePrice,
  500. 'invoiceType' => $invoiceType,
  501. 'settlementType' => $st,
  502. 'doPost' => $doPost,
  503. 'status' => 1,
  504. 'invoiceSerial' => "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  505. 'date' => date ( "Y-m-d H:i:s" ),
  506. 'updateTime' => date ( "Y-m-d H:i:s" ),
  507. 'sid' => $this->staff [0] ['sid'],
  508. 'userName' => $this->staff [0] ['username'],
  509. 'invoiceManage' => $invoiceManageDetail ['staff'],
  510. 'pendingApprovals' => $pendingApprovalsSid,
  511. 'moldManage' => json_encode ( $moldManage ),
  512. 'remark' => $remark,
  513. 'trainId' => $trainId
  514. );
  515. if ($invoiceType == 0)
  516. $item += array (
  517. 'invoiceTitle' => $invoiceTitle,
  518. 'TIN' => $TINT,
  519. 'address' => $addressT,
  520. 'phone' => $phoneT,
  521. 'bank' => $bankT,
  522. 'bankAccount' => $bankAccountT
  523. );
  524. else {
  525. $item += array (
  526. 'invoiceCompany' => $invoiceCompany,
  527. 'TIN' => $TIN,
  528. 'address' => $address,
  529. 'phone' => $phone,
  530. 'bank' => $bank,
  531. 'bankAccount' => $bankAccount
  532. );
  533. }
  534. if ($doPost == 1) {
  535. $mailList = array (
  536. 'invoice' => 1,
  537. 'mailItems' => $mailItems
  538. );
  539. if (! empty ( $softLock ))
  540. $mailList += array (
  541. 'softLock' => $softLockNum
  542. );
  543. else
  544. $mailList += array (
  545. 'softLock' => 0
  546. );
  547. if (! empty ( $contract ))
  548. $mailList += array (
  549. 'contract' => $contractNum
  550. );
  551. else
  552. $mailList += array (
  553. 'contract' => 0
  554. );
  555. if (! empty ( $instructions ))
  556. $mailList += array (
  557. 'instructions' => $instructionsNum
  558. );
  559. else
  560. $mailList += array (
  561. 'instructions' => 0
  562. );
  563. if (! empty ( $remittance ))
  564. $mailList += array (
  565. 'remittance' => $remittance
  566. );
  567. else
  568. $mailList += array (
  569. 'remittance' => ''
  570. );
  571. $mailString = '发票x1张,备注:' . $mailItems;
  572. if (! empty ( $softLock ))
  573. $mailString .= ',软件锁x' . $softLockNum . '个';
  574. if (! empty ( $contract ))
  575. $mailString .= ',合同x' . $contractNum . '份';
  576. if (! empty ( $instructions ))
  577. $mailString .= ',说明书x' . $instructionsNum . '本';
  578. if (! empty ( $remittance ))
  579. $mailString .= ',汇款账号单(张)';
  580. $item += array (
  581. 'recipients' => $recipients,
  582. 'recipientsPhone' => $recipientsPhone,
  583. 'recipientsAddress' => $recipientsAddress,
  584. 'mailItems' => $mailString,
  585. 'mailItemsJson' => json_encode ( $mailList )
  586. );
  587. }
  588. $iid = $invoice->addInvoice ( $item );
  589. // 如果是培训班结算 创建培训班发票到培训班备份中
  590. if (! empty ( $st ) && $st == 1) {
  591. Doo::loadModel ( 'invoiceStore' );
  592. $invoiceStore = new invoiceStore ();
  593. Doo::loadModel ( 'invoiceTraining' );
  594. $invoiceTraining = new invoiceTraining ();
  595. $isid = $invoiceStore->setInvoiceToInvoiceStore ( $iid );
  596. $itemIS = array (
  597. 'isid' => $isid,
  598. 'ipSource' => 1,
  599. 'apStatus' => 1,
  600. 'iid' => $iid
  601. );
  602. $invoiceStore->setInvoiceStoreByCondition ( $itemIS );
  603. // 更新培训班总数量
  604. $detailIT = $invoiceTraining->getInvoiceTrainingByItid ( $trainId );
  605. $item = array (
  606. 'itid' => $trainId,
  607. 'invoiceTotal' => $detailIT ['invoiceTotal'] + 1,
  608. 'submitStatus' => 1
  609. );
  610. $itid = $invoiceTraining->setInvoiceTrainByCondition ( $item );
  611. }
  612. // 操作日志
  613. $item = array (
  614. 'date' => date ( "Y-m-d H:i:s" ),
  615. 'operation' => "创建",
  616. 'status' => 1,
  617. 'img' => $this->staff [0] ['avatar'],
  618. 'username' => $this->staff [0] ['username'],
  619. 'uid' => $this->staff [0] ['sid'],
  620. 'category' => $this->staff [0] ['category'],
  621. 'iid' => $iid
  622. );
  623. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  624. $item = array (
  625. 'date' => date ( "Y-m-d H:i:s" ),
  626. 'operation' => "提交审批",
  627. 'status' => 1,
  628. 'img' => $this->staff [0] ['avatar'],
  629. 'username' => $this->staff [0] ['username'],
  630. 'uid' => $this->staff [0] ['sid'],
  631. 'category' => $this->staff [0] ['category'],
  632. 'iid' => $iid
  633. );
  634. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  635. Doo::loadModel ( 'staff' );
  636. $staff = new staff ();
  637. $username2 = $staff->getOne ( array (
  638. 'select' => 'wxid',
  639. 'where' => 'sid=' . $pendingApprovalsSid,
  640. 'asArray' => TRUE
  641. ) );
  642. // 发送微信审批通知
  643. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  644. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  645. }
  646. return "/invoice";
  647. }
  648. function invoiceEdit() {
  649. Doo::loadClass ( 'XDeode' );
  650. $XDeode = new XDeode ( 5 );
  651. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  652. $iid = $XDeode->decode ( $iid );
  653. if (! is_numeric ( $iid ))
  654. die ( 'illegal request' );
  655. Doo::loadModel ( 'invoice' );
  656. $invoice = new invoice ();
  657. Doo::loadModel ( 'invoiceOperationLog' );
  658. $invoiceOperationLog = new invoiceOperationLog ();
  659. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  660. $operation = $invoiceOperationLog->getInvoiceOperationByDropped ( $iid );
  661. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  662. $this->data ['operation'] = $operation;
  663. $this->data ['invoiceDetail'] = $invoiceDetail;
  664. $this->data ['memu'] = "invoice";
  665. $this->data ['staff'] = $this->staff;
  666. $this->data ['receiptMemu'] = 'invoice';
  667. $this->render ( "/admin/invoiceEdit", $this->data );
  668. }
  669. /**
  670. * 重新编辑退回的发票
  671. * @return string
  672. */
  673. function invoiceEditDo() {
  674. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  675. Doo::loadModel ( 'invoice' );
  676. $invoice = new invoice ();
  677. $iid = $invoice->authcode ( $iidKey );
  678. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  679. die ( 'illegal request' );
  680. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  681. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  682. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  683. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  684. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  685. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  686. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  687. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  688. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  689. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  690. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  691. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  692. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  693. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  694. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  695. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  696. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  697. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  698. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  699. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  700. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  701. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  702. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  703. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  704. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  705. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  706. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  707. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  708. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  709. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  710. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  711. if ($invoiceType == 1) {
  712. $temporary = $invoiceQuantity * $invoiceUnitPrice;
  713. if ($temporary > 10000)
  714. die ( 'illegal request-Please priceError' );
  715. }
  716. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  717. Doo::loadModel ( 'invoiceManage' );
  718. $invoiceManage = new invoiceManage ();
  719. Doo::loadModel ( 'invoiceOperationLog' );
  720. $invoiceOperationLog = new invoiceOperationLog ();
  721. Doo::loadModel ( 'invoiceStore' );
  722. $invoiceStore = new invoiceStore ();
  723. $cid = explode ( ':', $cid );
  724. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  725. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  726. $moldManage = array ();
  727. foreach ( $invoiceManageList as $key => $value ) {
  728. if ($value ['mold'] == '发票打印')
  729. $moldManage [$value ['mold']] = $value ['staffList'];
  730. elseif ($value ['mold'] == '发票邮寄')
  731. $moldManage [$value ['mold']] = $value ['staffList'];
  732. elseif ($value ['mold'] == '发票打印')
  733. $moldManage [$value ['mold']] = $value ['staffList'];
  734. }
  735. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  736. $item = array (
  737. 'iid' => $iid,
  738. 'cid' => $cid [0],
  739. 'categoryName' => $cid [1],
  740. 'invoiceElement' => $invoiceElement,
  741. 'invoiceQuantity' => $invoiceQuantity,
  742. 'invoiceUnitPrice' => $invoiceUnitPrice,
  743. 'invoicePrice' => $invoicePrice,
  744. 'invoiceType' => $invoiceType,
  745. 'doPost' => $doPost,
  746. 'status' => 1,
  747. 'updateTime' => date ( "Y-m-d H:i:s" ),
  748. 'remark' => $remark
  749. );
  750. if ($invoiceType == 0)
  751. $item += array (
  752. 'invoiceTitle' => $invoiceTitle,
  753. 'TIN' => $TINT,
  754. 'address' => $addressT,
  755. 'phone' => $phoneT,
  756. 'bank' => $bankT,
  757. 'bankAccount' => $bankAccountT
  758. );
  759. else {
  760. $item += array (
  761. 'invoiceCompany' => $invoiceCompany,
  762. 'TIN' => $TIN,
  763. 'address' => $address,
  764. 'phone' => $phone,
  765. 'bank' => $bank,
  766. 'bankAccount' => $bankAccount
  767. );
  768. }
  769. if ($doPost == 1) {
  770. $mailList = array (
  771. 'invoice' => 1,
  772. 'mailItems' => $mailItems
  773. );
  774. if (! empty ( $softLock ))
  775. $mailList += array (
  776. 'softLock' => $softLockNum
  777. );
  778. else
  779. $mailList += array (
  780. 'softLock' => '0'
  781. );
  782. if (! empty ( $contract ))
  783. $mailList += array (
  784. 'contract' => $contractNum
  785. );
  786. else
  787. $mailList += array (
  788. 'contract' => '0'
  789. );
  790. if (! empty ( $instructions ))
  791. $mailList += array (
  792. 'instructions' => $instructionsNum
  793. );
  794. else
  795. $mailList += array (
  796. 'instructions' => '0'
  797. );
  798. if (! empty ( $remittance ))
  799. $mailList += array (
  800. 'remittance' => $remittance
  801. );
  802. else
  803. $mailList += array (
  804. 'remittance' => ''
  805. );
  806. $mailString = '发票x1,备注:' . $mailItems;
  807. if (! empty ( $softLock ))
  808. $mailString .= ',软件锁x' . $softLockNum;
  809. if (! empty ( $contract ))
  810. $mailString .= ',合同x' . $contractNum;
  811. if (! empty ( $instructions ))
  812. $mailString .= ',说明书x' . $instructionsNum;
  813. if (! empty ( $remittance ))
  814. $mailString .= ',汇款账号单';
  815. $item += array (
  816. 'recipients' => $recipients,
  817. 'recipientsPhone' => $recipientsPhone,
  818. 'recipientsAddress' => $recipientsAddress,
  819. 'mailItems' => $mailString,
  820. 'mailItemsJson' => json_encode ( $mailList )
  821. );
  822. }
  823. $invoice->setInvoiceByCondition ( $item );
  824. // 更新培训班仓库里的发票
  825. $detail = $invoice->getInvoiceByIid ( $iid );
  826. if (! empty ( $detail ['isid'] )) {
  827. $invoiceStore->isid = $detail ['isid'];
  828. $invoiceStore->invoiceQuantity = $invoiceQuantity;
  829. $invoiceStore->invoiceUnitPrice = $invoiceUnitPrice;
  830. $invoiceStore->invoicePrice = $invoicePrice;
  831. $invoiceStore->update ();
  832. }
  833. $item = array (
  834. 'date' => date ( "Y-m-d H:i:s" ),
  835. 'operation' => "重新提交审批",
  836. 'status' => 1,
  837. 'img' => $this->staff [0] ['avatar'],
  838. 'username' => $this->staff [0] ['username'],
  839. 'uid' => $this->staff [0] ['sid'],
  840. 'category' => $this->staff [0] ['category'],
  841. 'iid' => $iid
  842. );
  843. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  844. }
  845. return "/invoice";
  846. }
  847. /**
  848. * 培训班
  849. */
  850. function invoiceTraining() {
  851. Doo::loadModel ( 'L_category' );
  852. $lCategory = new L_category ();
  853. Doo::loadModel ( 'invoiceTraining' );
  854. $invoiceTraining = new invoiceTraining ();
  855. Doo::loadModel ( 'invoiceTrainManage' );
  856. $invoiceTrainManage = new invoiceTrainManage ();
  857. $imcStaff = $invoiceTrainManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  858. $cidList = array ();
  859. foreach ( $imcStaff as $key => $value ) {
  860. array_push ( $cidList, $value ['cid'] );
  861. }
  862. if (empty ( $cidList )) {
  863. $cidString = $this->staff [0] ['cid'];
  864. } else {
  865. $cidString = implode ( ',', $cidList );
  866. $cidString .= $cidString . ',' . $this->staff [0] ['cid'];
  867. }
  868. $itTodoList = $invoiceTraining->getInvoiceTrainingByTodo ( '', $cidString, $this->staff [0] ['sid'] );
  869. $itedList = $invoiceTraining->getInvoiceTrainingByStatus ( 2, '', $cidString, $this->staff [0] ['sid'] );
  870. $category = $lCategory->getCategory ();
  871. $itid = array ();
  872. foreach ( $itTodoList as $key => $value ) {
  873. array_push ( $itid, $value ['itid'] );
  874. // 如果入账100%更新为已完成
  875. if ($itTodoList [$key] ['arriveSchedule'] >= 100) {
  876. $invoiceTraining = new invoiceTraining ();
  877. $invoiceTraining->itid = $value ['itid'];
  878. $invoiceTraining->status = 2;
  879. $invoiceTraining->update ();
  880. }
  881. }
  882. foreach ( $itedList as $value ) {
  883. array_push ( $itid, $value ['itid'] );
  884. }
  885. $itid = implode ( ',', $itid );
  886. $this->data ['itStatist'] = $invoiceTraining->getInvoiceTrainStatistics ( $itid );
  887. // print_r($itTodoList);
  888. $this->data ['trainCount'] = count ( $itTodoList ) + count ( $itedList );
  889. $this->data ['itTodoList'] = $itTodoList;
  890. $this->data ['itedList'] = $itedList;
  891. $this->data ['category'] = $category;
  892. $this->data ['memu'] = "invoice";
  893. $this->data ['staff'] = $this->staff;
  894. $this->data ['receiptMemu'] = 'invoiceTraining';
  895. $this->render ( "/admin/invoiceTraining", $this->data );
  896. }
  897. /**
  898. * 创建培训班
  899. */
  900. function invoiceTrainingAdd() {
  901. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  902. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  903. $trainDate = $this->get_args ( 'trainDate' ) ? $this->get_args ( 'trainDate' ) : "";
  904. if (empty ( $this->staff [0] ))
  905. die ( 'illegal request' );
  906. if (! empty ( $cid ) && ! empty ( $trainName ) && ! empty ( $trainDate )) {
  907. Doo::loadModel ( 'invoiceTraining' );
  908. $invoiceTraining = new invoiceTraining ();
  909. Doo::loadModel ( 'invoice' );
  910. $invoice = new invoice ();
  911. Doo::loadModel ( 'L_category' );
  912. $lCategory = new L_category ();
  913. Doo::loadModel ( 'invoiceManage' );
  914. $invoiceManage = new invoiceManage ();
  915. Doo::loadModel ( 'invoiceOperationLog' );
  916. $invoiceOperationLog = new invoiceOperationLog ();
  917. $item = array (
  918. 'cid' => $cid,
  919. 'trainName' => $trainName,
  920. 'trainDate' => $trainDate,
  921. 'creator' => $this->staff [0] ['sid'],
  922. 'creatorDate' => date ( "Y-m-d H:i:s" )
  923. );
  924. $itid = $invoiceTraining->addInvoiceTraining ( $item );
  925. }
  926. return "/invoiceTraining";
  927. }
  928. /**
  929. * 删除培训班
  930. */
  931. function invoiceTrainingDelDo() {
  932. $itid = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  933. if (! empty ( $itid )) {
  934. Doo::loadModel ( 'invoiceTraining' );
  935. $invoiceTraining = new invoiceTraining ();
  936. $invoiceTraining->delInvoiceTrainingByItid ( $itid );
  937. }
  938. return "/invoiceTraining";
  939. }
  940. /**
  941. * 培训班详情
  942. */
  943. function invoiceTrainingDetail() {
  944. $trainStatus = $this->get_args ( 'trainStatus' ) ? $this->get_args ( 'trainStatus' ) : "ALL";
  945. $itid = isset ( $this->params ['trainingKey'] ) ? $this->params ['trainingKey'] : "";
  946. Doo::loadModel ( 'invoiceTraining' );
  947. $invoiceTraining = new invoiceTraining ();
  948. Doo::loadModel ( 'invoiceStore' );
  949. $invoiceStore = new invoiceStore ();
  950. if (empty ( $itid ))
  951. die ( 'illegal request' );
  952. $con = ' (b.untreadStatus is null or b.untreadStatus!=2) and ';
  953. if ($trainStatus == "SUBED")
  954. $con = ' (b.untreadStatus is null ) and ';
  955. elseif ($trainStatus == "APPROVAL")
  956. $con = ' ( b.status=1 and b.untreadStatus!=2 ) and ';
  957. elseif ($trainStatus == "TICKET")
  958. $con = ' (b.printStatus=1 and b.status=2 and b.untreadStatus!=2) and ';
  959. elseif ($trainStatus == "TICKETING") {
  960. $con = ' (b.status=2 and b.untreadStatus=1) and ';
  961. }
  962. $detail = $invoiceTraining->getInvoiceTrainingByItid ( $itid );
  963. $isList = $invoiceStore->getinvoiceStoreByItid ( $itid, $con );
  964. //print_r($isList);
  965. $trainlist = array ();
  966. foreach ( $isList as $key => $value ) {
  967. $irDetail = array ();
  968. if ($value ['apStatus'] == 1) {
  969. // array_push ( $irDetail, '' );
  970. array_push ( $irDetail, '<input disabled type="checkbox" style="display:none" >' );
  971. } else {
  972. array_push ( $irDetail, '<input type="checkbox" class="hide" id="' . $value ['storeKey'] . '" name="isBox" value="' . $value ['storeKey'] . '" > <a href="/invoiceStoreEdit/' . $value ['storeKey'] . '.html">编辑</a>
  973. <a href="#confirm" onclick="invoiceStoreApproval(\'' . $value ['storeKey'] . '\')" data-toggle="modal">提交审批</a>
  974. <a href="#del" node-iStore="del" data-key="' . $value ['storeKey'] . '" onclick="invoiceStoreDel(\'' . $value ['storeKey'] . '\')" data-toggle="modal" class="colRed">移除</a>' );
  975. }
  976. array_push ( $irDetail, $value ['invoiceSerial'] );
  977. if ($value ['invoiceType'] == 1)
  978. array_push ( $irDetail, $value ['invoiceCompany'] );
  979. else
  980. array_push ( $irDetail, $value ['invoiceTitle'] );
  981. array_push ( $irDetail, $value ['TIN'] );
  982. array_push ( $irDetail, $value ['userName'] );
  983. if (empty ( $value ['mailItems'] ) && $value ['apStatus'] != 1) {
  984. array_push ( $irDetail, '<a href="#confirm-erro" onclick="invoiceStoreMail(\'' . $value ['storeKey'] . '\')" data-toggle="modal">设置邮寄物品</a>' );
  985. } else
  986. array_push ( $irDetail, $value ['mailItems'] );
  987. array_push ( $irDetail, $value ['recipientsAddress'] . $value ['recipients'] . $value ['recipientsPhone'] );
  988. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  989. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  990. array_push ( $irDetail, $value ['invoiceElement'] );
  991. array_push ( $irDetail, $value ['invoiceQuantity'] );
  992. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  993. if ($value ['invoiceType'] == 1)
  994. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  995. else
  996. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  997. array_push ( $irDetail, $value ['remark'] );
  998. if ($value ['status'] == 1)
  999. array_push ( $irDetail, '审批中' );
  1000. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1)
  1001. array_push ( $irDetail, '已出票' );
  1002. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1 && $value ['printStatus'] != 'irid' && ($value ['untreadStatus'] == 3 || $value ['untreadStatus'] == 0))
  1003. array_push ( $irDetail, '已入账' );
  1004. else
  1005. array_push ( $irDetail, '' );
  1006. array_push ( $irDetail, $value ['invoiceNo'] );
  1007. array_push ( $irDetail, $value ['printTime'] );
  1008. $html = '';
  1009. foreach ( $value ['invoiceReceivables'] as $value ) {
  1010. $html .= '&nbsp;<a href="#billing" node-invoice="INFO" data-type="receivables" data-iskey="' . $value [2] . '" data-toggle="modal">' . $value [1] . '</a>';
  1011. }
  1012. array_push ( $irDetail, $html );
  1013. array_push ( $trainlist, $irDetail );
  1014. }
  1015. $trainlistJson = json_encode ( $trainlist );
  1016. if (empty ( $detail ))
  1017. die ( 'illegal request' );
  1018. // 培训班结算是否有和是否已经结算完成
  1019. Doo::loadModel ( 'receipt' );
  1020. $receipt = new receipt ();
  1021. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $itid );
  1022. $this->data ['receiptDetail'] = $receiptDetail;
  1023. $this->data ['trainStatus'] = $trainStatus;
  1024. $this->data ['itid'] = $itid;
  1025. $this->data ['trainlistJson'] = $trainlistJson;
  1026. $this->data ['iTrainDetail'] = $detail;
  1027. $this->data ['memu'] = "invoice";
  1028. $this->data ['staff'] = $this->staff;
  1029. $this->data ['receiptMemu'] = 'invoiceTraining';
  1030. $this->render ( "/admin/invoiceTrainingDetail", $this->data );
  1031. }
  1032. /**
  1033. * 上传培训班发票
  1034. * @return string
  1035. */
  1036. function invoiceTrainingUpload() {
  1037. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  1038. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  1039. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  1040. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  1041. header ( "HTTP/1.1 500 Internal Server Error" );
  1042. echo "POST exceeded maximum allowed size.";
  1043. exit ( 0 );
  1044. }
  1045. // Settings
  1046. $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)
  1047. $upload_name = "Filedata";
  1048. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  1049. $extension_whitelist = array (
  1050. "doc",
  1051. "txt",
  1052. "jpg",
  1053. "gif",
  1054. "png"
  1055. ); // Allowed file extensions
  1056. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  1057. // Other variables
  1058. $MAX_FILENAME_LENGTH = 260;
  1059. $file_name = "";
  1060. $file_extension = "";
  1061. $uploadErrors = array (
  1062. 0 => "文件上传成功",
  1063. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  1064. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  1065. 3 => "上传的文件仅为部分文件",
  1066. 4 => "没有文件上传",
  1067. 6 => "缺少临时文件夹"
  1068. );
  1069. $nk = time ();
  1070. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  1071. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  1072. echo "文件无法保存.";
  1073. exit ( 0 );
  1074. }
  1075. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  1076. echo json_encode ( array (
  1077. 'filename' => $file_name,
  1078. 'id' => $nk
  1079. ) );
  1080. exit ( 0 );
  1081. }
  1082. /**
  1083. * 导入发票临时仓库
  1084. */
  1085. function invoiceStoreImport() {
  1086. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  1087. $trainingKey = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  1088. $path = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  1089. if ($path != "" && ! empty ( $trainingKey )) {
  1090. Doo::loadModel ( 'invoiceStore' );
  1091. Doo::loadModel ( 'staff' );
  1092. $staff = new staff ();
  1093. Doo::loadModel ( 'invoiceTraining' );
  1094. $invoiceTraining = new invoiceTraining ();
  1095. Doo::loadClass ( 'XDeode' );
  1096. $XDeode = new XDeode ( 5 );
  1097. $itid = $XDeode->decode ( $trainingKey );
  1098. // 培训班结算是否有和是否已经结算完成
  1099. Doo::loadModel ( 'receipt' );
  1100. $receipt = new receipt ();
  1101. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $itid );
  1102. if (! empty ( $receiptDetail )) {
  1103. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9)
  1104. die ( 'illegal request--status' );
  1105. }
  1106. $exlArray = $this->formatExcelToArrayTrain ( DOO::conf ()->SITE_PATH . "upload/invoiceTraining/" . $path );
  1107. $userName = $this->staff [0] ['username'];
  1108. $sDetail = $staff->getStaffByName ( $userName );
  1109. // die('sdd');
  1110. // 可以优化
  1111. foreach ( $exlArray as $key => $value ) {
  1112. // 开票
  1113. $invoice = new invoiceStore ();
  1114. $invoice->trainId = $itid;
  1115. $invoice->invoiceType = 0;
  1116. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  1117. $invoice->invoiceType = 1;
  1118. $invoice->invoiceQuantity = $value ['invoiceQuantity'];
  1119. $invoice->invoiceUnitPrice = $value ['invoiceUnitPrice'];
  1120. $invoice->invoicePrice = $value ['invoiceQuantity'] * $value ['invoiceUnitPrice'];
  1121. $invoice->invoiceTitle = $value ['invoiceTitle'];
  1122. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  1123. $invoice->invoiceCompany = $value ['invoiceTitle'];
  1124. $invoice->userName = $userName;
  1125. $invoice->sid = $sDetail ['sid'];
  1126. $invoice->cid = $sDetail ['cid'];
  1127. $invoice->categoryName = $sDetail ['category'];
  1128. $invoice->invoiceElement = $value ['invoiceElement'];
  1129. $invoice->remark = $value ['remark'];
  1130. // $invoice->date = $value ['date'];
  1131. // $invoice->printTime = $value ['date'];
  1132. $invoice->ipSource = 1;
  1133. $invoice->printStatus = 0;
  1134. $invoice->status = 0;
  1135. $invoice->postStatus = 1;
  1136. $invoice->untreadStatus = 0;
  1137. // $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1138. $invoice->TIN = $value ['TIN'];
  1139. $invoice->address = $value ['address'];
  1140. $invoice->phone = $value ['phone'];
  1141. $invoice->bank = $value ['bank'];
  1142. $invoice->bankAccount = $value ['bankAccount'];
  1143. $invoice->recipientsAddress = $value ['recipientsAddress'];
  1144. $invoice->recipients = $value ['recipients'];
  1145. $invoice->recipientsPhone = $value ['recipientsPhone'];
  1146. $iid = $invoice->insert ();
  1147. }
  1148. // 加入发票总数量
  1149. $item = array (
  1150. 'itid' => $itid,
  1151. 'invoiceTotal' => count ( $exlArray )
  1152. );
  1153. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1154. return '/invoiceTrainingDetail/' . $trainingKey . ".html";
  1155. }
  1156. echo 'no file';
  1157. }
  1158. /**
  1159. * 编辑仓库里的发票
  1160. */
  1161. function invoiceStoreEdit() {
  1162. Doo::loadClass ( 'XDeode' );
  1163. $XDeode = new XDeode ( 5 );
  1164. $iid = isset ( $this->params ['storeKey'] ) ? $this->params ['storeKey'] : "";
  1165. $iid = $XDeode->decode ( $iid );
  1166. if (! is_numeric ( $iid ))
  1167. die ( 'illegal request' );
  1168. Doo::loadModel ( 'invoiceStore' );
  1169. $invoiceStore = new invoiceStore ();
  1170. $invoiceDetail = $invoiceStore->getInvoiceStoreByIsid ( $iid );
  1171. // print_r($invoiceDetail);
  1172. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  1173. $this->data ['invoiceDetail'] = $invoiceDetail;
  1174. $this->data ['memu'] = "invoice";
  1175. $this->data ['staff'] = $this->staff;
  1176. $this->data ['receiptMemu'] = 'invoiceTraining';
  1177. $this->render ( "/admin/invoiceStoreEdit", $this->data );
  1178. }
  1179. function invoiceStoreEditDo() {
  1180. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1181. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1182. Doo::loadModel ( 'invoiceStore' );
  1183. $invoice = new invoiceStore ();
  1184. Doo::loadClass ( 'XDeode' );
  1185. $XDeode = new XDeode ( 5 );
  1186. $iid = $XDeode->decode ( $storeKey );
  1187. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1188. die ( 'illegal request' );
  1189. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  1190. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  1191. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  1192. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  1193. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  1194. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  1195. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  1196. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  1197. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  1198. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  1199. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  1200. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  1201. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  1202. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  1203. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1204. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1205. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1206. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1207. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  1208. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  1209. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  1210. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  1211. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  1212. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  1213. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1214. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1215. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1216. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1217. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1218. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1219. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1220. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  1221. $cid = explode ( ':', $cid );
  1222. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  1223. $item = array (
  1224. 'isid' => $iid,
  1225. 'cid' => $cid [0],
  1226. 'categoryName' => $cid [1],
  1227. 'invoiceElement' => $invoiceElement,
  1228. 'invoiceQuantity' => $invoiceQuantity,
  1229. 'invoiceUnitPrice' => $invoiceUnitPrice,
  1230. 'invoicePrice' => $invoicePrice,
  1231. 'invoiceType' => $invoiceType,
  1232. 'doPost' => $doPost,
  1233. 'status' => 1,
  1234. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1235. 'remark' => $remark
  1236. );
  1237. if ($invoiceType == 0)
  1238. $item += array (
  1239. 'invoiceTitle' => $invoiceTitle,
  1240. 'TIN' => $TINT,
  1241. 'address' => $addressT,
  1242. 'phone' => $phoneT,
  1243. 'bank' => $bankT,
  1244. 'bankAccount' => $bankAccountT
  1245. );
  1246. else {
  1247. $item += array (
  1248. 'invoiceCompany' => $invoiceCompany,
  1249. 'TIN' => $TIN,
  1250. 'address' => $address,
  1251. 'phone' => $phone,
  1252. 'bank' => $bank,
  1253. 'bankAccount' => $bankAccount
  1254. );
  1255. }
  1256. if ($doPost == 1) {
  1257. $mailList = array (
  1258. 'invoice' => 1,
  1259. 'mailItems' => $mailItems
  1260. );
  1261. if (! empty ( $softLock ))
  1262. $mailList += array (
  1263. 'softLock' => $softLockNum
  1264. );
  1265. else
  1266. $mailList += array (
  1267. 'softLock' => '0'
  1268. );
  1269. if (! empty ( $contract ))
  1270. $mailList += array (
  1271. 'contract' => $contractNum
  1272. );
  1273. else
  1274. $mailList += array (
  1275. 'contract' => '0'
  1276. );
  1277. if (! empty ( $instructions ))
  1278. $mailList += array (
  1279. 'instructions' => $instructionsNum
  1280. );
  1281. else
  1282. $mailList += array (
  1283. 'instructions' => '0'
  1284. );
  1285. if (! empty ( $remittance ))
  1286. $mailList += array (
  1287. 'remittance' => $remittance
  1288. );
  1289. else
  1290. $mailList += array (
  1291. 'remittance' => ''
  1292. );
  1293. $mailString = '发票x1,备注:' . $mailItems;
  1294. if (! empty ( $softLock ))
  1295. $mailString .= ',软件锁x' . $softLockNum;
  1296. if (! empty ( $contract ))
  1297. $mailString .= ',合同x' . $contractNum;
  1298. if (! empty ( $instructions ))
  1299. $mailString .= ',说明书x' . $instructionsNum;
  1300. if (! empty ( $remittance ))
  1301. $mailString .= ',汇款账号单';
  1302. $item += array (
  1303. 'recipients' => $recipients,
  1304. 'recipientsPhone' => $recipientsPhone,
  1305. 'recipientsAddress' => $recipientsAddress,
  1306. 'mailItems' => $mailString,
  1307. 'mailItemsJson' => json_encode ( $mailList )
  1308. );
  1309. }
  1310. $invoice->setInvoiceStoreByCondition ( $item );
  1311. }
  1312. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1313. }
  1314. /**
  1315. *
  1316. * @return string
  1317. */
  1318. function invoiceStoreDelete() {
  1319. Doo::loadClass ( 'XDeode' );
  1320. $XDeode = new XDeode ( 5 );
  1321. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1322. $iStoreKey = $this->get_args ( 'iStoreKey' ) ? $this->get_args ( 'iStoreKey' ) : 0;
  1323. $isid = $XDeode->decode ( $iStoreKey );
  1324. $itid = $XDeode->decode ( $trainKey );
  1325. if (! is_numeric ( $isid ))
  1326. die ( 'illegal request' );
  1327. Doo::loadModel ( 'invoiceStore' );
  1328. $invoiceStore = new invoiceStore ();
  1329. $invoiceStore->delete ( array (
  1330. 'where' => 'isid=' . $isid,
  1331. 'limit' => 1
  1332. ) );
  1333. Doo::loadModel ( 'invoiceTraining' );
  1334. $invoiceTraining = new invoiceTraining ();
  1335. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1336. $item = array (
  1337. 'itid' => $itid,
  1338. 'invoiceTotal' => $itDetail ['invoiceTotal'] - 1
  1339. );
  1340. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1341. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1342. }
  1343. /**
  1344. * 批量删除库里发票
  1345. */
  1346. function invoiceStoreBatchDelete() {
  1347. Doo::loadClass ( 'XDeode' );
  1348. $XDeode = new XDeode ( 5 );
  1349. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1350. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1351. if (empty ( $trainKey ) || empty ( $storeKey ))
  1352. die ( 'illegal request-IdKey' );
  1353. $tid = $XDeode->decode ( $trainKey );
  1354. if (! is_numeric ( $tid ) && ! empty ( $storeKey ))
  1355. die ( 'illegal request' );
  1356. Doo::loadModel ( 'invoiceStore' );
  1357. $isidKeyList = explode ( ',', $storeKey );
  1358. $isidList = array ();
  1359. foreach ( $isidKeyList as $value ) {
  1360. $isid = $XDeode->decode ( $value );
  1361. if (! empty ( $isid ) && is_numeric ( $isid ))
  1362. array_push ( $isidList, $isid );
  1363. }
  1364. $isidString = implode ( ',', $isidList );
  1365. $invoiceStore = new invoiceStore ();
  1366. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,apStatus' );
  1367. $isidList = array ();
  1368. foreach ( $isList as $key => $value ) {
  1369. if ($value ['apStatus'] == 0)
  1370. array_push ( $isidList, $value ['isid'] );
  1371. }
  1372. $isidString = implode ( ',', $isidList );
  1373. // print_r($isList);
  1374. // echo $isidString;
  1375. $invoiceStore = new invoiceStore ();
  1376. $invoiceStore->delete ( array (
  1377. 'where' => "isid in ( " . $isidString . ")",
  1378. 'asArray' => TRUE
  1379. ) );
  1380. Doo::loadModel ( 'invoiceTraining' );
  1381. $invoiceTraining = new invoiceTraining ();
  1382. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1383. $item = array (
  1384. 'itid' => $tid,
  1385. 'invoiceTotal' => $itDetail ['invoiceTotal'] - count ( $isidList )
  1386. );
  1387. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1388. // echo $tid;
  1389. // echo $storeKey;
  1390. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1391. }
  1392. /**
  1393. * 仓库发票提交审批
  1394. * @return string
  1395. */
  1396. function invoiceStoreApproval() {
  1397. Doo::loadClass ( 'XDeode' );
  1398. $XDeode = new XDeode ( 5 );
  1399. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1400. $iStoreKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1401. $isid = $XDeode->decode ( $iStoreKey );
  1402. $trainId = $XDeode->decode ( $trainKey );
  1403. if (! is_numeric ( $isid ))
  1404. die ( 'illegal request' );
  1405. Doo::loadModel ( 'invoiceStore' );
  1406. Doo::loadModel ( 'invoice' );
  1407. $invoice = new invoice ();
  1408. // 加入限制必须填写入开票内容和邮寄物品
  1409. $invoiceStore = new invoiceStore ();
  1410. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid, 'isid,trainId ,invoiceElement,mailItemsJson' );
  1411. if (empty ( $isDetail ['invoiceElement'] ) || empty ( $isDetail ['mailItemsJson'] )) {
  1412. header ( 'Content-Type:text/html;charset=utf-8' );
  1413. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1414. }
  1415. // 拷贝插入一条发票数据
  1416. $invoiceStore = new invoiceStore ();
  1417. $iid = $invoiceStore->setInvoiceStoreToApproval ( $isid );
  1418. $invoiceStore = new invoiceStore ();
  1419. $item = array (
  1420. 'isid' => $isid,
  1421. 'iid' => $iid,
  1422. 'apStatus' => 1
  1423. );
  1424. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1425. Doo::loadModel ( 'invoiceManage' );
  1426. $invoiceManage = new invoiceManage ();
  1427. Doo::loadModel ( 'invoiceOperationLog' );
  1428. $invoiceOperationLog = new invoiceOperationLog ();
  1429. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1430. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1431. $moldManage = array ();
  1432. foreach ( $invoiceManageList as $key => $value ) {
  1433. if ($value ['mold'] == '发票打印')
  1434. $moldManage [$value ['mold']] = $value ['staffList'];
  1435. elseif ($value ['mold'] == '发票邮寄')
  1436. $moldManage [$value ['mold']] = $value ['staffList'];
  1437. elseif ($value ['mold'] == '发票退票')
  1438. $moldManage [$value ['mold']] = $value ['staffList'];
  1439. }
  1440. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1441. $item = array (
  1442. 'iid' => $iid,
  1443. 'isid' => $isid,
  1444. 'invoiceSerial' => "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  1445. 'date' => date ( "Y-m-d H:i:s" ),
  1446. 'status' => 1,
  1447. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1448. 'trainId' => $trainId,
  1449. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1450. 'moldManage' => json_encode ( $moldManage ),
  1451. 'settlementType' => 1,
  1452. 'pendingApprovals' => $pendingApprovalsSid
  1453. );
  1454. $invoice->setInvoiceByCondition ( $item );
  1455. Doo::loadModel ( 'invoiceTraining' );
  1456. $invoiceTraining = new invoiceTraining ();
  1457. $item = array (
  1458. 'itid' => $trainId,
  1459. 'submitStatus' => 1
  1460. );
  1461. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1462. $item = array (
  1463. 'date' => date ( "Y-m-d H:i:s" ),
  1464. 'operation' => "创建",
  1465. 'status' => 1,
  1466. 'img' => $this->staff [0] ['avatar'],
  1467. 'username' => $this->staff [0] ['username'],
  1468. 'uid' => $this->staff [0] ['sid'],
  1469. 'category' => $this->staff [0] ['category'],
  1470. 'iid' => $iid
  1471. );
  1472. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1473. $item = array (
  1474. 'date' => date ( "Y-m-d H:i:s" ),
  1475. 'operation' => "提交审批",
  1476. 'status' => 1,
  1477. 'img' => $this->staff [0] ['avatar'],
  1478. 'username' => $this->staff [0] ['username'],
  1479. 'uid' => $this->staff [0] ['sid'],
  1480. 'category' => $this->staff [0] ['category'],
  1481. 'iid' => $iid
  1482. );
  1483. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1484. Doo::loadModel ( 'staff' );
  1485. $staff = new staff ();
  1486. $username2 = $staff->getOne ( array (
  1487. 'select' => 'wxid',
  1488. 'where' => 'sid=' . $pendingApprovalsSid,
  1489. 'asArray' => TRUE
  1490. ) );
  1491. // 发送微信审批通知
  1492. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1493. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1494. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1495. }
  1496. /**
  1497. * 批量提交发票
  1498. * @return string
  1499. */
  1500. function invoiceStoreBatchApproval() {
  1501. Doo::loadClass ( 'XDeode' );
  1502. $XDeode = new XDeode ( 5 );
  1503. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1504. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1505. if (empty ( $trainKey ) || empty ( $storeKey ))
  1506. die ( 'illegal request-IdKey' );
  1507. $trainId = $XDeode->decode ( $trainKey );
  1508. $isidKeyList = explode ( ',', $storeKey );
  1509. $isidList = array ();
  1510. foreach ( $isidKeyList as $value ) {
  1511. $isid = $XDeode->decode ( $value );
  1512. if (! empty ( $isid ) && is_numeric ( $isid ))
  1513. array_push ( $isidList, $isid );
  1514. }
  1515. $isidString = implode ( ',', $isidList );
  1516. if (! is_numeric ( $trainId ))
  1517. die ( 'illegal request' );
  1518. Doo::loadModel ( 'invoiceStore' );
  1519. Doo::loadModel ( 'invoice' );
  1520. // 判断哪些已经加入审批过
  1521. // 加入限制必须填写入开票内容和邮寄物品
  1522. $invoiceStore = new invoiceStore ();
  1523. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,trainId ,invoiceElement,mailItemsJson' );
  1524. foreach ( $isList as $key => $value ) {
  1525. if (empty ( $value ['invoiceElement'] ) || empty ( $value ['mailItemsJson'] )) {
  1526. header ( 'Content-Type:text/html;charset=utf-8' );
  1527. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1528. }
  1529. }
  1530. // 拷贝插入一条发票数据
  1531. $invoiceStore = new invoiceStore ();
  1532. $invoiceStore->setInvoiceStoreBatchToApproval ( $isidString );
  1533. $invoiceStore = new invoiceStore ();
  1534. $item = array (
  1535. 'apStatus' => 1
  1536. );
  1537. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1538. // 获得正式发票ID
  1539. $invoice = new invoice ();
  1540. $iidList = $invoice->getInvoiceByIstoreid ( $isidString, 'iid,isid' );
  1541. $sqlList = array ();
  1542. $iidString = '';
  1543. $iida = array ();
  1544. foreach ( $iidList as $key => $value ) {
  1545. $sqlList [$value ['isid']] = $value ['iid'];
  1546. array_push ( $iida, $value ['iid'] );
  1547. }
  1548. $iidString = implode ( ',', $iida );
  1549. $ids = implode ( ',', array_keys ( $sqlList ) );
  1550. $sql = "UPDATE CLD_invoiceStore SET iid = CASE isid ";
  1551. foreach ( $sqlList as $id => $ordinal ) {
  1552. $sql .= sprintf ( "WHEN %d THEN %d ", $id, $ordinal );
  1553. }
  1554. $sql .= "END WHERE isid IN ($ids)";
  1555. $invoiceStore = new invoiceStore ();
  1556. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1557. Doo::loadModel ( 'invoiceManage' );
  1558. $invoiceManage = new invoiceManage ();
  1559. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1560. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1561. $moldManage = array ();
  1562. foreach ( $invoiceManageList as $key => $value ) {
  1563. if ($value ['mold'] == '发票打印')
  1564. $moldManage [$value ['mold']] = $value ['staffList'];
  1565. elseif ($value ['mold'] == '发票邮寄')
  1566. $moldManage [$value ['mold']] = $value ['staffList'];
  1567. elseif ($value ['mold'] == '发票退票')
  1568. $moldManage [$value ['mold']] = $value ['staffList'];
  1569. }
  1570. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1571. // 批量更新发票信息
  1572. $item = array (
  1573. 'date' => date ( "Y-m-d H:i:s" ),
  1574. 'status' => 1,
  1575. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1576. 'trainId' => $trainId,
  1577. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1578. 'moldManage' => json_encode ( $moldManage ),
  1579. 'settlementType' => 1,
  1580. 'pendingApprovals' => $pendingApprovalsSid
  1581. );
  1582. $invoice = new invoice ();
  1583. $invoice->BatchInvoiceByCondition ( $item, $iidString );
  1584. // 批量更新发票中仓库isid
  1585. $sql = "UPDATE CLD_invoiceStore SET isid = CASE iid ";
  1586. foreach ( $sqlList as $isid => $iid ) {
  1587. $sql .= sprintf ( "WHEN %d THEN %d ", $iid, $isid );
  1588. }
  1589. $sql .= "END WHERE iid IN ($iidString)";
  1590. $invoice = new invoice ();
  1591. $invoice->UpdateBatchInvoice ( $sql );
  1592. // 批量更新发票序列号
  1593. $sqlList = array ();
  1594. foreach ( $iida as $value ) {
  1595. $sqlList [$value] = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1596. }
  1597. $ids = implode ( ',', array_keys ( $sqlList ) );
  1598. $sql = "UPDATE CLD_invoice SET invoiceSerial = CASE iid ";
  1599. foreach ( $sqlList as $id => $ordinal ) {
  1600. $sql .= sprintf ( "WHEN %d THEN '%s' ", $id, $ordinal );
  1601. }
  1602. $sql .= "END WHERE iid IN ($ids)";
  1603. $invoiceStore = new invoiceStore ();
  1604. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1605. // 批量生产操作日志
  1606. Doo::loadModel ( 'invoiceOperationLog' );
  1607. $sqlList = array ();
  1608. foreach ( $iida as $key => $value ) {
  1609. $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 . '"),
  1610. ("' . 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 . '") ';
  1611. array_push ( $sqlList, $sql );
  1612. }
  1613. $iolSql = implode ( ',', $sqlList );
  1614. $sql = "INSERT INTO `CLD_invoiceOperationLog` (`date`, `operation`, `status`, `img`, `username`, `uid`, `category`, `iid`) VALUES " . $iolSql;
  1615. $invoiceOperationLog = new invoiceOperationLog ();
  1616. $invoiceOperationLog->setInvoiceOperationLogBySql ( $sql );
  1617. Doo::loadModel ( 'invoiceTraining' );
  1618. $invoiceTraining = new invoiceTraining ();
  1619. $item = array (
  1620. 'itid' => $trainId,
  1621. 'submitStatus' => 1
  1622. );
  1623. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1624. Doo::loadModel ( 'staff' );
  1625. $staff = new staff ();
  1626. $username2 = $staff->getOne ( array (
  1627. 'select' => 'wxid',
  1628. 'where' => 'sid=' . $pendingApprovalsSid,
  1629. 'asArray' => TRUE
  1630. ) );
  1631. // 发送微信审批通知
  1632. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1633. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1634. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1635. }
  1636. /**
  1637. */
  1638. function invoiceStoreMailItemSet() {
  1639. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1640. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1641. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1642. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1643. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1644. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1645. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1646. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1647. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1648. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1649. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1650. Doo::loadClass ( 'XDeode' );
  1651. $XDeode = new XDeode ( 5 );
  1652. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1653. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1654. $isid = $XDeode->decode ( $storeKey );
  1655. $trainId = $XDeode->decode ( $trainKey );
  1656. if (! is_numeric ( $isid ))
  1657. die ( 'illegal request' );
  1658. Doo::loadModel ( 'invoiceStore' );
  1659. $invoiceStore = new invoiceStore ();
  1660. $mailList = array (
  1661. 'invoice' => 1,
  1662. 'mailItems' => $mailItems
  1663. );
  1664. if (! empty ( $softLock ))
  1665. $mailList += array (
  1666. 'softLock' => $softLockNum
  1667. );
  1668. else
  1669. $mailList += array (
  1670. 'softLock' => 0
  1671. );
  1672. if (! empty ( $contract ))
  1673. $mailList += array (
  1674. 'contract' => $contractNum
  1675. );
  1676. else
  1677. $mailList += array (
  1678. 'contract' => 0
  1679. );
  1680. if (! empty ( $instructions ))
  1681. $mailList += array (
  1682. 'instructions' => $instructionsNum
  1683. );
  1684. else
  1685. $mailList += array (
  1686. 'instructions' => 0
  1687. );
  1688. if (! empty ( $remittance ))
  1689. $mailList += array (
  1690. 'remittance' => $remittance
  1691. );
  1692. else
  1693. $mailList += array (
  1694. 'remittance' => ''
  1695. );
  1696. $mailString = '发票x1,备注:' . $mailItems;
  1697. if (! empty ( $softLock ))
  1698. $mailString .= ',软件锁x' . $softLockNum;
  1699. if (! empty ( $contract ))
  1700. $mailString .= ',合同x' . $contractNum;
  1701. if (! empty ( $instructions ))
  1702. $mailString .= ',说明书x' . $instructionsNum;
  1703. if (! empty ( $remittance ))
  1704. $mailString .= ',汇款账号单';
  1705. $item = array (
  1706. 'isid' => $isid,
  1707. 'doPost' => 1,
  1708. 'mailItems' => $mailString,
  1709. 'mailItemsJson' => json_encode ( $mailList )
  1710. );
  1711. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1712. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1713. }
  1714. /**
  1715. * 批量设置邮寄物品
  1716. */
  1717. function invoiceStoreBatchMailItemSet() {
  1718. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1719. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1720. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1721. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1722. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1723. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1724. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1725. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1726. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1727. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1728. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1729. Doo::loadClass ( 'XDeode' );
  1730. $XDeode = new XDeode ( 5 );
  1731. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1732. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1733. if (empty ( $trainKey ) || empty ( $storeKey ))
  1734. die ( 'illegal request-IdKey' );
  1735. $isidKeyList = explode ( ',', $storeKey );
  1736. $isidList = array ();
  1737. foreach ( $isidKeyList as $value ) {
  1738. $isid = $XDeode->decode ( $value );
  1739. if (! empty ( $isid ) && is_numeric ( $isid ))
  1740. array_push ( $isidList, $isid );
  1741. }
  1742. $isidString = implode ( ',', $isidList );
  1743. $trainId = $XDeode->decode ( $trainKey );
  1744. if (! is_numeric ( $isid ))
  1745. die ( 'illegal request' );
  1746. Doo::loadModel ( 'invoiceStore' );
  1747. $invoiceStore = new invoiceStore ();
  1748. $mailList = array (
  1749. 'invoice' => 1,
  1750. 'mailItems' => $mailItems
  1751. );
  1752. if (! empty ( $softLock ))
  1753. $mailList += array (
  1754. 'softLock' => $softLockNum
  1755. );
  1756. else
  1757. $mailList += array (
  1758. 'softLock' => 0
  1759. );
  1760. if (! empty ( $contract ))
  1761. $mailList += array (
  1762. 'contract' => $contractNum
  1763. );
  1764. else
  1765. $mailList += array (
  1766. 'contract' => 0
  1767. );
  1768. if (! empty ( $instructions ))
  1769. $mailList += array (
  1770. 'instructions' => $instructionsNum
  1771. );
  1772. else
  1773. $mailList += array (
  1774. 'instructions' => 0
  1775. );
  1776. if (! empty ( $remittance ))
  1777. $mailList += array (
  1778. 'remittance' => $remittance
  1779. );
  1780. else
  1781. $mailList += array (
  1782. 'remittance' => ''
  1783. );
  1784. $mailString = '发票x1,备注:' . $mailItems;
  1785. if (! empty ( $softLock ))
  1786. $mailString .= ',软件锁x' . $softLockNum;
  1787. if (! empty ( $contract ))
  1788. $mailString .= ',合同x' . $contractNum;
  1789. if (! empty ( $instructions ))
  1790. $mailString .= ',说明书x' . $instructionsNum;
  1791. if (! empty ( $remittance ))
  1792. $mailString .= ',汇款账号单';
  1793. $item = array (
  1794. 'doPost' => 1,
  1795. 'mailItems' => $mailString,
  1796. 'mailItemsJson' => json_encode ( $mailList )
  1797. );
  1798. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1799. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1800. }
  1801. /**
  1802. * 废弃
  1803. */
  1804. function ajaxGetMailItemByIstore() {
  1805. Doo::loadClass ( 'XDeode' );
  1806. $XDeode = new XDeode ( 5 );
  1807. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1808. $isid = $XDeode->decode ( $storeKey );
  1809. if (! is_numeric ( $isid ))
  1810. die ( 'illegal request' );
  1811. Doo::loadModel ( 'invoiceStore' );
  1812. $invoiceStore = new invoiceStore ();
  1813. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid );
  1814. $isDetail ['mailItemsJson'] = json_decode ( $isDetail ['mailItemsJson'], true );
  1815. echo json_encode ( $isDetail ['mailItemsJson'] );
  1816. exit ();
  1817. }
  1818. /**
  1819. * 终止开票
  1820. */
  1821. function invoiceDroppedDo() {
  1822. $droppedIidKey = $this->get_args ( 'droppedIidKey' ) ? $this->get_args ( 'droppedIidKey' ) : '';
  1823. Doo::loadModel ( 'invoice' );
  1824. $invoice = new invoice ();
  1825. Doo::loadModel ( 'invoiceOperationLog' );
  1826. $invoiceOperationLog = new invoiceOperationLog ();
  1827. $iid = $invoice->authcode ( $droppedIidKey );
  1828. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1829. die ( 'illegal request' );
  1830. $item = array (
  1831. 'iid' => $iid,
  1832. 'status' => 4,
  1833. 'updateTime' => date ( "Y-m-d H:i:s" )
  1834. );
  1835. $invoice->setInvoiceByCondition ( $item );
  1836. $item = array (
  1837. 'date' => date ( "Y-m-d H:i:s" ),
  1838. 'operation' => '终止了开票',
  1839. 'status' => 4,
  1840. 'img' => $this->staff [0] ['avatar'],
  1841. 'username' => $this->staff [0] ['username'],
  1842. 'uid' => $this->staff [0] ['sid'],
  1843. 'category' => $this->staff [0] ['category'],
  1844. 'iid' => $iid
  1845. );
  1846. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1847. return "/invoice";
  1848. }
  1849. /**
  1850. * 更新退票的邮寄信息
  1851. */
  1852. function invoiceUntreadMailDo() {
  1853. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  1854. $untreadCompany = $this->get_args ( 'untreadCompany' ) ? $this->get_args ( 'untreadCompany' ) : "";
  1855. $untreadNumber = $this->get_args ( 'untreadNumber' ) ? $this->get_args ( 'untreadNumber' ) : "";
  1856. $untreadItems = $this->get_args ( 'untreadItems' ) ? $this->get_args ( 'untreadItems' ) : "";
  1857. Doo::loadModel ( 'invoice' );
  1858. $invoice = new invoice ();
  1859. $iid = $invoice->authcode ( $untreadIidKey );
  1860. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1861. die ( 'illegal request' );
  1862. $item = array (
  1863. 'iid' => $iid,
  1864. 'untreadCompany' => $untreadCompany,
  1865. 'untreadNumber' => $untreadNumber,
  1866. 'untreadItems' => $untreadItems
  1867. );
  1868. $invoice->setInvoiceByCondition ( $item );
  1869. return "/invoice";
  1870. }
  1871. /**
  1872. * 申请退票 --
  1873. */
  1874. function invoiceUntreadDo() {
  1875. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  1876. $untreadReason = $this->get_args ( 'untreadReason' ) ? $this->get_args ( 'untreadReason' ) : "";
  1877. $untreadPost = $this->get_args ( 'untreadPost' ) ? $this->get_args ( 'untreadPost' ) : "";
  1878. Doo::loadModel ( 'invoice' );
  1879. $invoice = new invoice ();
  1880. Doo::loadModel ( 'invoiceOperationLog' );
  1881. $invoiceOperationLog = new invoiceOperationLog ();
  1882. Doo::loadModel ( 'invoiceReceivables' );
  1883. $invoiceReceivables = new invoiceReceivables ();
  1884. $iid = $invoice->authcode ( $untreadIidKey );
  1885. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1886. die ( 'illegal request' );
  1887. /*
  1888. * 需求变革 有绑定收款也可以退票 $lt = $invoiceReceivables->getInvoiceReceivablesByIid ( $untreadIidKey ); if (! empty ( $lt )) { header ( 'Content-Type:text/html;charset=utf-8' ); die ( '该发票有收款绑定,请先移除!' ); }
  1889. */
  1890. $item = array (
  1891. 'iid' => $iid,
  1892. 'untreadStatus' => 1,
  1893. 'untreadReason' => $untreadReason,
  1894. 'untreadPost' => $untreadPost,
  1895. 'updateTime' => date ( "Y-m-d H:i:s" )
  1896. );
  1897. $invoice->setInvoiceByCondition ( $item );
  1898. $item = array (
  1899. 'date' => date ( "Y-m-d H:i:s" ),
  1900. 'operation' => '申请退票',
  1901. 'status' => 7,
  1902. 'img' => $this->staff [0] ['avatar'],
  1903. 'username' => $this->staff [0] ['username'],
  1904. 'uid' => $this->staff [0] ['sid'],
  1905. 'category' => $this->staff [0] ['category'],
  1906. 'iid' => $iid
  1907. );
  1908. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1909. return "/invoice";
  1910. }
  1911. /**
  1912. * 删除已终止的开票
  1913. */
  1914. function invoiceDelDo() {
  1915. Doo::loadModel ( 'invoice' );
  1916. $invoice = new invoice ();
  1917. Doo::loadModel ( 'invoiceOperationLog' );
  1918. $invoiceOperationLog = new invoiceOperationLog ();
  1919. Doo::loadClass ( 'XDeode' );
  1920. $XDeode = new XDeode ( 5 );
  1921. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  1922. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  1923. $iid = $XDeode->decode ( $iid );
  1924. Doo::loadModel ( 'invoiceStore' );
  1925. $invoiceStore = new invoiceStore ();
  1926. if (! is_numeric ( $iid ))
  1927. die ( 'illegal request' );
  1928. $invoiceDetail = $invoice->getMyInvoice ( $sid, $iid );
  1929. if (empty ( $invoiceDetail ))
  1930. die ( 'illegal request' );
  1931. $item = array (
  1932. 'iid' => $iid,
  1933. 'isDelete' => 1,
  1934. 'updateTime' => date ( "Y-m-d H:i:s" )
  1935. );
  1936. $invoice->setInvoiceByCondition ( $item );
  1937. $item = array (
  1938. 'date' => date ( "Y-m-d H:i:s" ),
  1939. 'operation' => '删除了已终止的发票',
  1940. 'status' => 4,
  1941. 'img' => $this->staff [0] ['avatar'],
  1942. 'username' => $this->staff [0] ['username'],
  1943. 'uid' => $this->staff [0] ['sid'],
  1944. 'category' => $this->staff [0] ['category'],
  1945. 'iid' => $iid
  1946. );
  1947. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1948. // 删除培训班发票仓库里的发票
  1949. $invoiceStore->delInvoiceStoreByIsid ( $invoiceDetail ['isid'] );
  1950. return "/invoice";
  1951. }
  1952. /**
  1953. */
  1954. function invoiceApproval() {
  1955. Doo::loadModel ( 'invoice' );
  1956. $invoice = new invoice ();
  1957. Doo::loadClass ( 'XDeode' );
  1958. $XDeode = new XDeode ( 5 );
  1959. Doo::loadModel ( 'staff' );
  1960. $staff = new staff ();
  1961. $invoiceList = $invoice->find ( array (
  1962. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  1963. 'desc' => 'iid',
  1964. 'limit' => 10,
  1965. 'asArray' => true
  1966. ) );
  1967. foreach ( $invoiceList as $key => $value ) {
  1968. $invoiceList [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1969. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1970. if (! empty ( $lastApprover )) {
  1971. $lastApproverKey = array_keys ( $lastApprover );
  1972. $lastApprover = end ( $lastApprover );
  1973. $staffDetail = $staff->getOne ( array (
  1974. 'where' => 'sid=' . end ( $lastApproverKey ),
  1975. 'asArray' => true
  1976. ) );
  1977. $lastApprover ['username'] = $staffDetail ['username'];
  1978. }
  1979. $invoiceList [$key] ['lastApprover'] = $lastApprover;
  1980. }
  1981. $ilist = $invoice->getInvoiceByProcessStatus ();
  1982. foreach ( $ilist as $key => $value ) {
  1983. $ilist [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1984. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1985. if (! empty ( $lastApprover )) {
  1986. $lastApproverKey = array_keys ( $lastApprover );
  1987. $lastApprover = end ( $lastApprover );
  1988. $staffDetail = $staff->getOne ( array (
  1989. 'where' => 'sid=' . end ( $lastApproverKey ),
  1990. 'asArray' => true
  1991. ) );
  1992. $lastApprover ['username'] = $staffDetail ['username'];
  1993. }
  1994. $ilist [$key] ['lastApprover'] = $lastApprover;
  1995. }
  1996. // print_r($ilist);
  1997. $this->data ['invoiceList'] = $invoiceList;
  1998. $this->data ['ilist'] = $ilist;
  1999. $this->data ['memu'] = "invoice";
  2000. $this->data ['staff'] = $this->staff;
  2001. $this->data ['receiptMemu'] = 'invoiceApproval';
  2002. $this->render ( "/admin/invoiceApproval", $this->data );
  2003. }
  2004. function invoiceDetail() {
  2005. Doo::loadClass ( 'XDeode' );
  2006. $XDeode = new XDeode ( 5 );
  2007. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  2008. $iid = $XDeode->decode ( $iid );
  2009. if (! is_numeric ( $iid ))
  2010. die ( 'illegal request' );
  2011. Doo::loadModel ( 'invoice' );
  2012. $invoice = new invoice ();
  2013. Doo::loadModel ( 'invoiceOperationLog' );
  2014. $invoiceOperationLog = new invoiceOperationLog ();
  2015. $invoiceDetail = $invoice->getOne ( array (
  2016. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'] . ' and iid=' . $iid,
  2017. 'asArray' => true
  2018. ) );
  2019. if (empty ( $invoiceDetail ))
  2020. die ( 'illegal request' );
  2021. if ($invoiceDetail ['settlementType'] == 1) {
  2022. Doo::loadModel ( 'invoiceTraining' );
  2023. $invoiceTraining = new invoiceTraining ();
  2024. $invoiceDetail ['invoiceTraining'] = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceDetail ['trainId'] );
  2025. }
  2026. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  2027. $this->data ['invoiceDetail'] = $invoiceDetail;
  2028. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  2029. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  2030. $this->data ['memu'] = "invoice";
  2031. $this->data ['staff'] = $this->staff;
  2032. $this->data ['receiptMemu'] = 'invoiceApproval';
  2033. $this->render ( "/admin/invoiceApprovalDetail", $this->data );
  2034. }
  2035. /**
  2036. * 对发票进行审批,其中操作有终止,退回,同意动作。操作成功并记录下操作日志
  2037. *
  2038. * @since 1.0.0
  2039. * @var integer iid 开票ID 已加密
  2040. * @var integer status 发票审批状态
  2041. * @var integer opintion 审批发票的意见
  2042. * @return string 如操作成功返回审批首页
  2043. */
  2044. function invoiceApprovalDo() {
  2045. Doo::loadModel ( 'invoice' );
  2046. $invoice = new invoice ();
  2047. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2048. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  2049. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  2050. $divApproval = $this->get_args ( 'divApproval' ) ? $this->get_args ( 'divApproval' ) : "";
  2051. $iid = $invoice->authcode ( $iid );
  2052. if (! is_numeric ( $iid ))
  2053. die ( 'illegal request' );
  2054. // && ! empty ( $opinion )
  2055. if (! empty ( $iid ) && ! empty ( $status )) {
  2056. if (! ($status == 2 || $status == 3 || $status == 4))
  2057. die ( 'illegal request' );
  2058. Doo::loadModel ( 'invoiceOperationLog' );
  2059. $invoiceOperationLog = new invoiceOperationLog ();
  2060. $invoiceDetail = $invoice->getOne ( array (
  2061. 'where' => 'status=1 and iid=' . $iid . ' and pendingApprovals=' . $this->staff [0] ['sid'],
  2062. 'asArray' => true
  2063. ) );
  2064. if (empty ( $invoiceDetail ))
  2065. die ( 'illegal request' );
  2066. $processApprovals = json_decode ( $invoiceDetail ['processApprovals'], true );
  2067. $invoiceManage = json_decode ( $invoiceDetail ['invoiceManage'], true );
  2068. if ($status == 3) {
  2069. $invoice->status = $status;
  2070. $item = array (
  2071. 'operation' => $opinion
  2072. );
  2073. } else {
  2074. if (empty ( $processApprovals )) {
  2075. $processApprovals = array (
  2076. $this->staff [0] ['sid'] => array (
  2077. 'date' => date ( "Y-m-d H:i:s" ),
  2078. 'opinion' => $opinion,
  2079. 'status' => $status
  2080. )
  2081. );
  2082. // var_dump(next($invoiceManage));
  2083. $nextInvoiceManage = next ( $invoiceManage );
  2084. // print_r($nextInvoiceManage);
  2085. if ($status != 4 && $nextInvoiceManage !== false)
  2086. $invoice->pendingApprovals = $nextInvoiceManage [0];
  2087. $invoice->processApprovals = json_encode ( $processApprovals );
  2088. // var_dump($invoice);
  2089. // print_r($invoiceManage);
  2090. } else {
  2091. $processApprovals [$this->staff [0] ['sid']] = array (
  2092. 'date' => date ( "Y-m-d H:i:s" ),
  2093. 'opinion' => $opinion,
  2094. 'status' => $status
  2095. );
  2096. $pendingApprovals = 0;
  2097. foreach ( $invoiceManage as $key => $value ) {
  2098. if ($value [0] == $this->staff [0] ['sid']) {
  2099. if (isset ( $invoiceManage [$key + 1] ))
  2100. $pendingApprovals = $invoiceManage [$key + 1] [0];
  2101. break;
  2102. }
  2103. }
  2104. if ($status != 4 && ! empty ( $pendingApprovals ))
  2105. $invoice->pendingApprovals = $pendingApprovals;
  2106. $invoice->processApprovals = json_encode ( $processApprovals );
  2107. }
  2108. $item = array (
  2109. 'operation' => $opinion
  2110. );
  2111. if (count ( $processApprovals ) == count ( $invoiceManage ) && $status != 4) {
  2112. $invoice->status = $status;
  2113. $invoice->pendingApprovals = 0;
  2114. $invoice->approvalTime = date ( "Y-m-d H:i:s" );
  2115. } elseif ($status == 4) {
  2116. $invoice->status = $status;
  2117. $item = array (
  2118. 'operation' => $opinion
  2119. );
  2120. }
  2121. }
  2122. $invoice->updateTime = date ( "Y-m-d H:i:s" );
  2123. $invoice->update ( array (
  2124. 'where' => 'iid=' . $iid
  2125. ) );
  2126. $item += array (
  2127. 'date' => date ( "Y-m-d H:i:s" ),
  2128. 'img' => $this->staff [0] ['avatar'],
  2129. 'username' => $this->staff [0] ['username'],
  2130. 'uid' => $this->staff [0] ['sid'],
  2131. 'category' => $this->staff [0] ['category'],
  2132. 'status' => $status,
  2133. 'iid' => $iid
  2134. );
  2135. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2136. if (empty ( $divApproval ))
  2137. return '/invoiceApproval';
  2138. else
  2139. return '/invoiceApprovalAchieve/PEND';
  2140. }
  2141. die ( 'illegal request' );
  2142. }
  2143. /**
  2144. * 展示需要打印的发票数据
  2145. *
  2146. * @since 1.0.0
  2147. */
  2148. function invoicePrint() {
  2149. Doo::loadModel ( 'invoice' );
  2150. $invoice = new invoice ();
  2151. Doo::loadClass ( 'XDeode' );
  2152. $XDeode = new XDeode ( 5 );
  2153. Doo::loadModel ( 'staff' );
  2154. $staff = new staff ();
  2155. $toPrint = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0 );
  2156. $printed = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 1 );
  2157. foreach ( $toPrint as $key => $value ) {
  2158. $toPrint [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2159. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2160. if (! empty ( $lastApprover )) {
  2161. $lastApproverKey = array_keys ( $lastApprover );
  2162. $lastApprover = end ( $lastApprover );
  2163. $staffDetail = $staff->getOne ( array (
  2164. 'where' => 'sid=' . end ( $lastApproverKey ),
  2165. 'asArray' => true
  2166. ) );
  2167. $lastApprover ['username'] = $staffDetail ['username'];
  2168. }
  2169. $toPrint [$key] ['lastApprover'] = $lastApprover;
  2170. }
  2171. foreach ( $printed as $key => $value ) {
  2172. $printed [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2173. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2174. if (! empty ( $lastApprover )) {
  2175. $lastApproverKey = array_keys ( $lastApprover );
  2176. $lastApprover = end ( $lastApprover );
  2177. $staffDetail = $staff->getOne ( array (
  2178. 'where' => 'sid=' . end ( $lastApproverKey ),
  2179. 'asArray' => true
  2180. ) );
  2181. $lastApprover ['username'] = $staffDetail ['username'];
  2182. }
  2183. $printed [$key] ['lastApprover'] = $lastApprover;
  2184. }
  2185. $this->data ['printed'] = $printed;
  2186. $this->data ['toPrint'] = $toPrint;
  2187. $this->data ['memu'] = "invoice";
  2188. $this->data ['staff'] = $this->staff;
  2189. $this->data ['receiptMemu'] = 'invoicePrint';
  2190. $this->render ( "/admin/invoicePrint", $this->data );
  2191. }
  2192. /**
  2193. * 展示发票打印的详情页面
  2194. *
  2195. * @since 1.0.0
  2196. */
  2197. function invoicePrintDetail() {
  2198. Doo::loadClass ( 'XDeode' );
  2199. $XDeode = new XDeode ( 5 );
  2200. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  2201. $iid = $XDeode->decode ( $iid );
  2202. if (! is_numeric ( $iid ))
  2203. die ( 'illegal request' );
  2204. Doo::loadModel ( 'invoice' );
  2205. $invoice = new invoice ();
  2206. Doo::loadModel ( 'invoiceOperationLog' );
  2207. $invoiceOperationLog = new invoiceOperationLog ();
  2208. Doo::loadModel ( 'invoicePaper' );
  2209. $invoicePaper = new invoicePaper ();
  2210. $invoiceDetail = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0, $iid );
  2211. if (empty ( $invoiceDetail ))
  2212. die ( 'illegal request' );
  2213. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $invoiceDetail ['invoiceType'] );
  2214. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  2215. if ($invoiceDetail ['settlementType'] == 1) {
  2216. Doo::loadModel ( 'invoiceTraining' );
  2217. $invoiceTraining = new invoiceTraining ();
  2218. $invoiceDetail ['invoiceTraining'] = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceDetail ['trainId'] );
  2219. }
  2220. $this->data ['invoicePaperList'] = $invoicePaperList;
  2221. $this->data ['invoiceDetail'] = $invoiceDetail;
  2222. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  2223. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  2224. $this->data ['memu'] = "invoice";
  2225. $this->data ['staff'] = $this->staff;
  2226. $this->data ['receiptMemu'] = 'invoicePrint';
  2227. $this->render ( "/admin/invoicePrintDetail", $this->data );
  2228. }
  2229. /**
  2230. * 所有待打印 发票
  2231. */
  2232. function invoicePrintStayAchieve() {
  2233. Doo::loadModel ( 'invoice' );
  2234. $invoice = new invoice ();
  2235. Doo::loadClass ( 'XDeode' );
  2236. $XDeode = new XDeode ( 5 );
  2237. Doo::loadModel ( 'staff' );
  2238. $staff = new staff ();
  2239. $MebSea = $this->get_args ( 'MebSea' ) ? urldecode ( $this->get_args ( 'MebSea' ) ) : "";
  2240. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  2241. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  2242. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  2243. Doo::loadModel ( 'invoiceTraining' );
  2244. $invoiceTraining = new invoiceTraining ();
  2245. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  2246. $page_size = 12;
  2247. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2248. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : "ALL";
  2249. // $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : "ALL";
  2250. $get = "/" . $status;
  2251. $con = ' and status=2 ';
  2252. if ($status == 'TOPRINT')
  2253. $con = ' and status=2 and printStatus=0 ';
  2254. elseif ($status == 'PRINTED')
  2255. $con = ' and status=2 and printStatus=1';
  2256. if ($invoiceType == 'ORDINARY')
  2257. $con .= ' and invoiceType=0 ';
  2258. elseif ($invoiceType == 'SPECIAL')
  2259. $con .= ' and invoiceType=1 ';
  2260. if ($invoiceTrain == 'ORDINARY')
  2261. $con .= ' and trainId=0 ';
  2262. elseif ($invoiceTrain == 'TRAIN')
  2263. $con .= ' and trainId!=0 ';
  2264. if ($invoiceTrainName != 'ALL') {
  2265. $trainId = $XDeode->decode ( $invoiceTrainName );
  2266. if (is_numeric ( $trainId ))
  2267. $con .= ' and trainId =' . $trainId;
  2268. }
  2269. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2270. $dateArr = explode ( ':', $date );
  2271. $D1 = '';
  2272. $D2 = '';
  2273. if (! empty ( $date )) {
  2274. $D1 = $dateArr [0];
  2275. $D2 = $dateArr [1];
  2276. }
  2277. if (! empty ( $D1 ) && ! empty ( $D2 ) && ! empty ( $date ))
  2278. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2279. if (! empty ( $MebSea )) {
  2280. $con .= ' and ( invoiceNo like "%' . $MebSea . '%" or invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  2281. }
  2282. $pageinfo ['page'] = array (
  2283. 'previous' => ''
  2284. );
  2285. $get .= "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&invoiceType=" . urlencode ( $invoiceType ) . "&invoiceTrain=" . urlencode ( $invoiceTrain ) . "";
  2286. $sql = " (untreadStatus=0 or untreadStatus=3) and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  2287. $action = "invoicePrintStayAchieve";
  2288. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2289. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2290. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  2291. $this->data ['trainList'] = $trainList;
  2292. $this->data ['invoiceType'] = $invoiceType;
  2293. $this->data ['invoiceTrain'] = $invoiceTrain;
  2294. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  2295. $this->data ['MebSeaEn'] = $MebSea;
  2296. $this->data ['MebSea'] = urlencode ( $MebSea );
  2297. $this->data ['get'] = $get;
  2298. $this->data ['page'] = $pageinfo;
  2299. $this->data ['date'] = $date;
  2300. $this->data ['status'] = $status;
  2301. $this->data ['invoiceType'] = $invoiceType;
  2302. $this->data ['memu'] = "invoice";
  2303. $this->data ['staff'] = $this->staff;
  2304. foreach ( $list as $key => $value ) {
  2305. $list [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2306. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2307. if (! empty ( $lastApprover )) {
  2308. $lastApproverKey = array_keys ( $lastApprover );
  2309. $lastApprover = end ( $lastApprover );
  2310. $staffDetail = $staff->getOne ( array (
  2311. 'where' => 'sid=' . end ( $lastApproverKey ),
  2312. 'asArray' => true
  2313. ) );
  2314. $lastApprover ['username'] = $staffDetail ['username'];
  2315. }
  2316. $list [$key] ['lastApprover'] = $lastApprover;
  2317. }
  2318. $this->data ['receiptMemu'] = 'invoicePrint';
  2319. $this->data ['list'] = $list;
  2320. $this->render ( "/admin/invoicePrintStayAchieve", $this->data );
  2321. }
  2322. /**
  2323. * 填写票号并完成打印
  2324. * @since 1.0.0
  2325. */
  2326. function invoicePrintDo() {
  2327. Doo::loadModel ( 'invoice' );
  2328. $invoice = new invoice ();
  2329. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2330. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  2331. $invoicePrintType = $this->get_args ( 'invoicePrintType' ) ? $this->get_args ( 'invoicePrintType' ) : "";
  2332. $iid = $invoice->authcode ( $iid );
  2333. if (! is_numeric ( $iid ))
  2334. die ( 'illegal request' );
  2335. if (! empty ( $iid ) && ! empty ( $invoiceNo )) {
  2336. Doo::loadModel ( 'invoiceOperationLog' );
  2337. $invoiceOperationLog = new invoiceOperationLog ();
  2338. Doo::loadModel ( 'invoiceStatistics' );
  2339. $invoiceStatistics = new invoiceStatistics ();
  2340. $XDeode = new XDeode ( 5 );
  2341. Doo::loadModel ( 'invoicePaper' );
  2342. $invoicePaper = new invoicePaper ();
  2343. $invoicePrintDetail = $invoice->getInvoiceByPrint ( $iid );
  2344. if (empty ( $invoicePrintDetail ))
  2345. die ( 'illegal request' );
  2346. //
  2347. $ipid = $XDeode->decode ( $invoiceNo );
  2348. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  2349. if (empty ( $paperDetail ))
  2350. die ( 'illegal request' );
  2351. $invoicePaper = new invoicePaper ();
  2352. $item = array (
  2353. 'iid' => $iid,
  2354. 'ipid' => $ipid
  2355. );
  2356. $invoicePaper->setInvoicePaperByCondition ( $item );
  2357. $item = array (
  2358. 'iid' => $iid,
  2359. 'printStatus' => 1,
  2360. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2361. 'printer' => $this->staff [0] ['username'],
  2362. 'printTime' => date ( "Y-m-d H:i:s" ),
  2363. 'invoiceNo' => $paperDetail ['invoiceNo']
  2364. );
  2365. $invoice->setInvoiceByCondition ( $item );
  2366. $item = array (
  2367. 'date' => date ( "Y-m-d H:i:s" ),
  2368. 'operation' => '打印发票号:' . $paperDetail ['invoiceNo'],
  2369. 'status' => 5,
  2370. 'img' => $this->staff [0] ['avatar'],
  2371. 'username' => $this->staff [0] ['username'],
  2372. 'uid' => $this->staff [0] ['sid'],
  2373. 'category' => $this->staff [0] ['category'],
  2374. 'iid' => $iid
  2375. );
  2376. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2377. // 去统计--负票不汇总
  2378. if ($invoicePrintDetail ['untreadStatus'] != 4) {
  2379. $item = array (
  2380. 'date' => date ( "Y-m-d H:i:s" ),
  2381. 'priceClass' => 1,
  2382. 'cid' => $invoicePrintDetail ['cid'],
  2383. 'staff' => $invoicePrintDetail ['sid'],
  2384. 'invoicePrice' => $invoicePrintDetail ['invoicePrice']
  2385. );
  2386. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2387. }
  2388. // 发送通知信息到微信-去除
  2389. // $this->setWXMsg($iid,'PRINT');
  2390. // 发票信息库
  2391. $this->autoUpdateInvoiceInfoBase ( $invoicePrintDetail );
  2392. // 申请人获取微信通知
  2393. Doo::loadModel ( 'staff' );
  2394. $staff = new staff ();
  2395. Doo::loadClass ( 'XDeode' );
  2396. $XDeode = new XDeode ( 5 );
  2397. $username2 = $staff->getOne ( array (
  2398. 'select' => 'wxid',
  2399. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2400. 'asArray' => TRUE
  2401. ) );
  2402. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '完成打印';
  2403. $msg = '';
  2404. $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/' . $XDeode->encode ( $invoicePrintDetail ['iid'] ) . '.html';
  2405. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2406. if (empty ( $invoicePrintType ))
  2407. return "/invoicePrint";
  2408. else
  2409. return "/invoicePrintStayAchieve";
  2410. }
  2411. }
  2412. /**
  2413. * 需要邮寄的发票
  2414. * @since 1.0.0
  2415. */
  2416. function invoicePost() {
  2417. Doo::loadModel ( 'invoice' );
  2418. $invoice = new invoice ();
  2419. Doo::loadModel ( 'express' );
  2420. $express = new express ();
  2421. $invoicePost = $invoice->getPostByInvoice ();
  2422. $invoicePosted = $invoice->getPostByInvoice ( 1 );
  2423. $expressList = $express->getExpressByAll ();
  2424. $invoicePostExpress = "";
  2425. if (isset ( $_COOKIE ["invoicePostExpress"] ))
  2426. $invoicePostExpress = $_COOKIE ["invoicePostExpress"];
  2427. $this->data ['invoicePostExpress'] = $invoicePostExpress;
  2428. $this->data ['expressList'] = $expressList;
  2429. $this->data ['invoicePost'] = $invoicePost;
  2430. $this->data ['invoicePosted'] = $invoicePosted;
  2431. $this->data ['memu'] = "invoice";
  2432. $this->data ['staff'] = $this->staff;
  2433. $this->data ['receiptMemu'] = 'invoicePost';
  2434. $this->render ( "/admin/invoicePost", $this->data );
  2435. }
  2436. /**
  2437. * 添加发票邮寄信息
  2438. */
  2439. function invoiceExpressAddDo() {
  2440. Doo::loadModel ( 'invoice' );
  2441. $invoice = new invoice ();
  2442. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2443. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2444. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2445. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2446. $iid = $iid = $invoice->authcode ( $iid );
  2447. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2448. die ( 'illegal request' );
  2449. $invoicePrintDetail = $invoice->getInvoiceByIid ( $iid );
  2450. setcookie ( 'invoicePostExpress', $expressNumber );
  2451. $item = array (
  2452. 'iid' => $iid,
  2453. 'postStatus' => 1,
  2454. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2455. 'postTime' => date ( "Y-m-d H:i:s" ),
  2456. 'expressCompany' => $expressCompany,
  2457. 'expressNumber' => $expressNumber,
  2458. 'actualItems' => $actualItems,
  2459. 'poster' => $this->staff [0] ['username']
  2460. );
  2461. $invoice->setInvoiceByCondition ( $item );
  2462. // 微信通知-去掉
  2463. // $this->setWXMsg ( $iid );
  2464. Doo::loadModel ( 'staff' );
  2465. $staff = new staff ();
  2466. Doo::loadClass ( 'XDeode' );
  2467. $XDeode = new XDeode ( 5 );
  2468. $username2 = $staff->getOne ( array (
  2469. 'select' => 'wxid',
  2470. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2471. 'asArray' => TRUE
  2472. ) );
  2473. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '已邮寄';
  2474. $expCom = explode ( ":", $invoicePrintDetail ['expressCompany'] );
  2475. if (empty ( $expCom ))
  2476. $expCom [0] = '';
  2477. $msg = $expCom [0] . ':' . $invoicePrintDetail ['expressNumber'] . '';
  2478. $url = 'https://m.kuaidi100.com/result.jsp?nu=' . $invoicePrintDetail ['expressNumber'];
  2479. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2480. return '/invoicePost';
  2481. }
  2482. function invoiceExpressUpdateDo() {
  2483. Doo::loadModel ( 'invoice' );
  2484. $invoice = new invoice ();
  2485. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  2486. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2487. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2488. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2489. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2490. $iid = $invoice->authcode ( $iid );
  2491. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2492. die ( 'illegal request' );
  2493. $item = array (
  2494. 'iid' => $iid,
  2495. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2496. 'expressCompany' => $expressCompany,
  2497. 'expressNumber' => $expressNumber,
  2498. 'actualItems' => $actualItems,
  2499. 'poster' => $this->staff [0] ['username']
  2500. );
  2501. $invoice->setInvoiceByCondition ( $item );
  2502. return $action;
  2503. }
  2504. /**
  2505. * 可退票管理
  2506. */
  2507. function invoiceUntreadIsAchieve() {
  2508. Doo::loadModel ( 'invoice' );
  2509. $invoice = new invoice ();
  2510. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2511. /*
  2512. * 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' => '' );
  2513. */
  2514. if (empty ( $MebSea )) {
  2515. $con = ' and invoiceNo like "NULL" ';
  2516. } else {
  2517. $con = ' and (invoiceNo like "%' . $MebSea . '%" or invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  2518. }
  2519. // printStatus=1 and
  2520. $sql = " (untreadStatus=0 or untreadStatus=3) and status=2 and sid=" . $this->staff [0] ['sid'] . $con;
  2521. /*
  2522. * $action = "invoiceUntreadIsAchieve"; $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" ); $limit = $pageinfo ['lower'] . ',' . $page_size;
  2523. */
  2524. $limit = '0,20';
  2525. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2526. // print_r($list);
  2527. $this->data ['MebSeaEn'] = $MebSea;
  2528. /*
  2529. * $this->data ['get'] = $get; $this->data ['page'] = $pageinfo; $this->data ['date'] = $date;
  2530. */
  2531. $this->data ['list'] = $list;
  2532. $this->data ['memu'] = "invoice";
  2533. $this->data ['staff'] = $this->staff;
  2534. $this->data ['receiptMemu'] = 'invoice';
  2535. $this->render ( "/admin/invoiceUntreadIsAchieve", $this->data );
  2536. }
  2537. // 已经退票的发票
  2538. function invoiceUntreadED() {
  2539. Doo::loadModel ( 'invoice' );
  2540. $invoice = new invoice ();
  2541. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2542. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "";
  2543. Doo::loadClass ( 'XDeode' );
  2544. $XDeode = new XDeode ( 5 );
  2545. $page_size = 18;
  2546. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2547. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2548. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  2549. $dateArr = explode ( ':', $date );
  2550. $D1 = '';
  2551. $D2 = '';
  2552. if (! empty ( $date )) {
  2553. $D1 = $dateArr [0];
  2554. $D2 = $dateArr [1];
  2555. }
  2556. $con = '';
  2557. if (! empty ( $D1 ) && ! empty ( $D2 )) {
  2558. $con = ' and bindTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2559. }
  2560. // if ($date == 'MONTHO')
  2561. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  2562. // elseif ($date == 'MONTHT')
  2563. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  2564. // elseif ($date == 'MONTHY')
  2565. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  2566. if (! empty ( $MebSea )) {
  2567. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  2568. }
  2569. if ($invoiceType == 'ORDINARY') {
  2570. $con .= ' and invoiceType=0 ';
  2571. } elseif ($invoiceType == 'SPECIAL') {
  2572. $con .= ' and invoiceType=1 ';
  2573. }
  2574. $pageinfo ['page'] = array (
  2575. 'previous' => ''
  2576. );
  2577. // printStatus=1 and
  2578. $sql = " (untreadStatus=2 ) and status=2 and sid=" . $this->staff [0] ['sid'] . $con;
  2579. $action = "invoiceUntreadED";
  2580. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2581. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2582. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2583. // print_r($list);
  2584. $this->data ['MebSeaEn'] = $MebSea;
  2585. $this->data ['get'] = $get;
  2586. $this->data ['page'] = $pageinfo;
  2587. $this->data ['date'] = $date;
  2588. $this->data ['invoiceType'] = $invoiceType;
  2589. $this->data ['list'] = $list;
  2590. $this->data ['memu'] = "invoice";
  2591. $this->data ['staff'] = $this->staff;
  2592. $this->data ['receiptMemu'] = 'invoice';
  2593. $this->render ( "/admin/invoiceUntreadED", $this->data );
  2594. }
  2595. /**
  2596. * 退票处理页面
  2597. */
  2598. function invoiceUntread() {
  2599. Doo::loadModel ( 'invoice' );
  2600. $invoice = new invoice ();
  2601. $untreadInvoice = $invoice->getInvoiceByUntreadStatus ( 1, 0, 50 );
  2602. $establishedInvoice = $invoice->getInvoiceByUntreadStatus ( 2 );
  2603. foreach ( $establishedInvoice as $key => $value ) {
  2604. // months
  2605. $lossDate = strtotime ( "+1 month", strtotime ( $value ['OperationLog'] ['date'] ) );
  2606. $nowDate = strtotime ( 'now' );
  2607. $establishedInvoice [$key] ['lossShow'] = false;
  2608. if ($lossDate < $nowDate)
  2609. $establishedInvoice [$key] ['lossShow'] = true;
  2610. }
  2611. $this->data ['untreadInvoice'] = $untreadInvoice;
  2612. $this->data ['establishedInvoice'] = $establishedInvoice;
  2613. $this->data ['memu'] = "invoice";
  2614. $this->data ['staff'] = $this->staff;
  2615. $this->data ['receiptMemu'] = 'invoiceUntread';
  2616. $this->render ( "/admin/invoiceUntread", $this->data );
  2617. }
  2618. /**
  2619. * 确认收到退回的发票,开票状态为退回 //收款状态解绑,公司统计扣除入账额度
  2620. */
  2621. function invoiceUntreadEstablishedDo() {
  2622. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  2623. Doo::loadModel ( 'invoice' );
  2624. $invoice = new invoice ();
  2625. Doo::loadModel ( 'invoiceOperationLog' );
  2626. $invoiceOperationLog = new invoiceOperationLog ();
  2627. Doo::loadModel ( 'invoiceReceivables' );
  2628. Doo::loadModel ( 'invoiceStatistics' );
  2629. $iid = $invoice->authcode ( $untreadIidKey );
  2630. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2631. die ( 'illegal request' );
  2632. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  2633. if ($invoiceDetails ['untreadStatus'] != 1)
  2634. die ( 'illegal request' );
  2635. $item = array (
  2636. 'iid' => $iid,
  2637. // 'irid'=>'',
  2638. 'untreadStatus' => 2,
  2639. 'updateTime' => date ( "Y-m-d H:i:s" )
  2640. );
  2641. $invoice->setInvoiceByCondition ( $item );
  2642. $item = array (
  2643. 'date' => date ( "Y-m-d H:i:s" ),
  2644. 'operation' => '已确认退票',
  2645. 'status' => 6,
  2646. 'img' => $this->staff [0] ['avatar'],
  2647. 'username' => $this->staff [0] ['username'],
  2648. 'uid' => $this->staff [0] ['sid'],
  2649. 'category' => $this->staff [0] ['category'],
  2650. 'iid' => $iid
  2651. );
  2652. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2653. // 收款解绑以及入账扣除 收款扣除
  2654. if (! empty ( $invoiceDetails ['irid'] )) {
  2655. $iridList = explode ( ',', $invoiceDetails ['irid'] );
  2656. foreach ( $iridList as $value ) {
  2657. $invoiceReceivables = new invoiceReceivables ();
  2658. $irDetails = $invoiceReceivables->getOne ( array (
  2659. 'where' => " irid=" . $value . ' and bindStatus=1',
  2660. 'asArray' => TRUE
  2661. ) );
  2662. $item = array (
  2663. 'irid' => $value,
  2664. 'bindStatus' => 0,
  2665. 'untreadStatus' => 1,
  2666. 'untreadStaff' => $invoiceDetails ['userName'],
  2667. 'unbundlingTime' => date ( "Y-m-d H:i:s" ),
  2668. 'iid' => 0
  2669. );
  2670. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2671. if (! empty ( $irDetails )) {
  2672. // 扣除入账
  2673. $invoiceStatistics = new invoiceStatistics ();
  2674. $item = array (
  2675. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2676. 'priceClass' => 3,
  2677. 'cid' => $invoiceDetails ['cid'],
  2678. 'staff' => $invoiceDetails ['sid'],
  2679. 'accountPrice' => - $irDetails ['receivablesPrice']
  2680. );
  2681. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2682. // 扣除收款
  2683. $invoiceStatistics = new invoiceStatistics ();
  2684. $item = array (
  2685. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2686. 'priceClass' => 2,
  2687. 'cid' => $invoiceDetails ['cid'],
  2688. 'staff' => $invoiceDetails ['sid'],
  2689. 'irid' => $irDetails ['irid'],
  2690. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  2691. );
  2692. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2693. }
  2694. // 解绑时删除收入流水
  2695. Doo::loadModel ( 'wasteBook' );
  2696. $wasteBook = new wasteBook ();
  2697. $wasteBook->delete ( array (
  2698. 'where' => 'dataID=' . $value . ' and accountType=7',
  2699. 'limit' => 1
  2700. ) );
  2701. }
  2702. }
  2703. return "/invoiceUntread";
  2704. }
  2705. function invoiceUntreadRecallDo() {
  2706. $iidKey = isset ( $this->params ['iidKey'] ) ? $this->params ['iidKey'] : "";
  2707. Doo::loadModel ( 'invoice' );
  2708. $invoice = new invoice ();
  2709. Doo::loadClass ( 'XDeode' );
  2710. $XDeode = new XDeode ( 5 );
  2711. Doo::loadModel ( 'invoiceOperationLog' );
  2712. $invoiceOperationLog = new invoiceOperationLog ();
  2713. $iid = $XDeode->decode ( $iidKey );
  2714. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  2715. if (empty ( $invoiceDetail )) {
  2716. die ( 'illegal request-DATANULL' );
  2717. }
  2718. $item = array (
  2719. 'iid' => $iid,
  2720. 'untreadStatus' => 0
  2721. );
  2722. $invoice->setInvoiceByCondition ( $item );
  2723. $item = array (
  2724. 'date' => date ( "Y-m-d H:i:s" ),
  2725. 'operation' => '撤回申请退票',
  2726. 'status' => 13,
  2727. 'img' => $this->staff [0] ['avatar'],
  2728. 'username' => $this->staff [0] ['username'],
  2729. 'uid' => $this->staff [0] ['sid'],
  2730. 'category' => $this->staff [0] ['category'],
  2731. 'iid' => $iid
  2732. );
  2733. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2734. return "/invoiceUntread";
  2735. }
  2736. /**
  2737. * 建立负票,关联原来发票
  2738. */
  2739. function invoiceLossDo() {
  2740. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2741. if (! empty ( $iidKey )) {
  2742. Doo::loadClass ( 'XDeode' );
  2743. $XDeode = new XDeode ( 5 );
  2744. Doo::loadModel ( 'invoice' );
  2745. $invoice = new invoice ();
  2746. Doo::loadModel ( 'invoiceOperationLog' );
  2747. $invoiceOperationLog = new invoiceOperationLog ();
  2748. $iidKey = $XDeode->decode ( $iidKey );
  2749. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  2750. // 拷贝插入一条发票数据
  2751. $iid = $invoice->setInvoiceLoss ( $iidKey );
  2752. // 更新负票
  2753. $invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  2754. $invoice = new invoice ();
  2755. $item = array (
  2756. 'iid' => $iid,
  2757. 'sid' => $this->staff [0] ['sid'],
  2758. 'userName' => $this->staff [0] ['username'],
  2759. 'cid' => $this->staff [0] ['cid'],
  2760. 'categoryName' => $this->staff [0] ['category'],
  2761. 'invoiceQuantity' => - $invoiceDetail ['invoiceQuantity'],
  2762. 'invoicePrice' => - $invoiceDetail ['invoicePrice'],
  2763. 'invoiceSerial' => $invoiceSerial,
  2764. 'invoiceNo' => '',
  2765. 'printStatus' => 0,
  2766. 'untreadStatus' => 4,
  2767. // 关联发票号
  2768. 'lossIid' => $invoiceDetail ['iid']
  2769. );
  2770. $invoice->setInvoiceByCondition ( $item );
  2771. // 更新原发票
  2772. $invoice = new invoice ();
  2773. $item = array (
  2774. 'iid' => $invoiceDetail ['iid'],
  2775. 'lossIid' => $iid
  2776. );
  2777. $invoice->setInvoiceByCondition ( $item );
  2778. // 操作日志
  2779. $item = array (
  2780. 'date' => date ( "Y-m-d H:i:s" ),
  2781. 'operation' => "创建负票" . $invoiceSerial,
  2782. 'status' => 12,
  2783. 'img' => $this->staff [0] ['avatar'],
  2784. 'username' => $this->staff [0] ['username'],
  2785. 'uid' => $this->staff [0] ['sid'],
  2786. 'category' => $this->staff [0] ['category'],
  2787. 'iid' => $iid
  2788. );
  2789. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2790. // print_r($invoiceDetail);
  2791. // echo $iid;die;
  2792. }
  2793. return '/invoiceUntread';
  2794. }
  2795. /**
  2796. * 上传银行到账 收款文件
  2797. */
  2798. function invoiceReceivablesBankUpload() {
  2799. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  2800. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  2801. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  2802. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  2803. header ( "HTTP/1.1 500 Internal Server Error" );
  2804. echo "POST exceeded maximum allowed size.";
  2805. exit ( 0 );
  2806. }
  2807. // Settings
  2808. $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)
  2809. $upload_name = "Filedata";
  2810. $file_name = "";
  2811. $nk = time ();
  2812. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  2813. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  2814. echo "文件无法保存.";
  2815. exit ( 0 );
  2816. }
  2817. echo json_encode ( array (
  2818. 'filename' => $file_name,
  2819. 'id' => $nk
  2820. ) );
  2821. exit ( 0 );
  2822. }
  2823. /**
  2824. * 解析银行到账收款execl并导入库中
  2825. */
  2826. function invoiceReceivablesImport() {
  2827. $path = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  2828. if ($path != "") {
  2829. Doo::loadModel ( 'invoiceReceivables' );
  2830. $invoiceReceivables = new invoiceReceivables ();
  2831. Doo::loadClass ( 'invoice.func' );
  2832. Doo::loadModel ( 'invoiceROLog' );
  2833. $invoiceROLog = new invoiceROLog ();
  2834. Doo::loadModel ( 'invoiceStatistics' );
  2835. $invoiceStatistics = new invoiceStatistics ();
  2836. $exlArray = formatExcelToArrayBank ( DOO::conf ()->SITE_PATH . "upload/invoiceReceivablesBank/" . $path );
  2837. $bankBatchNumber = 'BBN_' . time ();
  2838. Doo::db ()->beginTransaction ();
  2839. // 批量存储收款--由于必须获得收款ID,
  2840. $sql = 'INSERT INTO CLD_invoiceReceivables (OriginalPrice,receivablesPrice, receivablesMessage,receivablesSerial,receivablesBank,receivablesDate,inputStaff,date,receivablesCategory,receivablesStaff,bankBatchNumber,recepitTitleMark)
  2841. VALUES ';
  2842. $date = date ( "Y-m-d" );
  2843. $receivablesList = array ();
  2844. foreach ( $exlArray as $key => $value ) {
  2845. $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"] . '")';
  2846. array_push ( $receivablesList, $receivablesSql );
  2847. }
  2848. $sql = $sql . implode ( ',', $receivablesList );
  2849. // echo $sql;
  2850. Doo::db ()->query ( $sql );
  2851. // 批量存储收款统计
  2852. // 获得刚刚导入数据的irid组-缺少办事处和人员
  2853. $iridList = $invoiceReceivables->getInvoiceReceivablesByBBN ( $bankBatchNumber );
  2854. // 没有irid 回滚所有操作
  2855. if (empty ( $iridList )) {
  2856. Doo::db ()->rollBack ();
  2857. header ( 'Content-Type:text/html;charset=utf-8' );
  2858. die ( '文档或数据不正确,请重新<a href="/invoiceReceivables">上传</a>.' );
  2859. }
  2860. $sql = 'INSERT INTO CLD_invoiceStatistics (date, priceClass,irid,receivablesPrice)
  2861. VALUES ';
  2862. $statisticsList = array ();
  2863. foreach ( $iridList as $value ) {
  2864. $statisticsSql = '("' . $date . '",2,' . $value ['irid'] . ',' . $value ["receivablesPrice"] . ')';
  2865. array_push ( $statisticsList, $statisticsSql );
  2866. }
  2867. $sql = $sql . implode ( ',', $statisticsList );
  2868. Doo::db ()->query ( $sql );
  2869. // 批量存储操作日志
  2870. $sql = 'INSERT INTO CLD_invoiceROLog (operation, date,status,img, username,uid,category,irid)
  2871. VALUES ';
  2872. $ROLogList = array ();
  2873. foreach ( $iridList as $value ) {
  2874. $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'] . '")';
  2875. array_push ( $ROLogList, $ROLogSql );
  2876. }
  2877. $sql = $sql . implode ( ',', $ROLogList );
  2878. Doo::db ()->query ( $sql );
  2879. // 批量写入流水
  2880. $sql = 'INSERT INTO CLD_wasteBook (dataID, expensesType,accountType,accountPriceShow, accountPrice,accountBank,category,cid,name,sid,inputDate)
  2881. VALUES ';
  2882. $wasteBookList = array ();
  2883. foreach ( $iridList as $value ) {
  2884. $accountBank = '';
  2885. if ($value ['receivablesBank'] == '纵横广发') {
  2886. $accountBank = 'CGBDeposit';
  2887. } elseif ($value ['receivablesBank'] == '纵横工行') {
  2888. $accountBank = 'ICBCDeposit';
  2889. } elseif ($value ['receivablesBank'] == '华润银行') {
  2890. $accountBank = 'HUADeposit';
  2891. } elseif ($value ['receivablesBank'] == '个人广发') {
  2892. $accountBank = 'PersonalDeposit';
  2893. }
  2894. $wasteBookSql = '("' . $value ['irid'] . ' ",1,7,"' . $value ['receivablesPrice'] . '","' . $value ['receivablesPrice'] . '","' . $accountBank . '",
  2895. "' . $this->staff [0] ['category'] . '","' . $this->staff [0] ['cid'] . '","' . $this->staff [0] ['username'] . '","' . $this->staff [0] ['sid'] . '","' . date ( "Y-m-d H:i:s" ) . '")';
  2896. array_push ( $wasteBookList, $wasteBookSql );
  2897. }
  2898. $sql = $sql . implode ( ',', $wasteBookList );
  2899. Doo::db ()->query ( $sql );
  2900. Doo::db ()->commit ();
  2901. return "/invoiceReceivables";
  2902. }
  2903. echo 'no file';
  2904. }
  2905. function invoiceReceivables() {
  2906. $invoiceTC = $this->get_args ( 'invoiceTC' ) ? $this->get_args ( 'invoiceTC' ) : '';
  2907. Doo::loadModel ( 'L_category' );
  2908. $lCategory = new L_category ();
  2909. Doo::loadModel ( 'staff' );
  2910. $staff = new staff ();
  2911. Doo::loadModel ( 'invoiceReceivables' );
  2912. $invoiceReceivables = new invoiceReceivables ();
  2913. Doo::loadModel ( 'invoice' );
  2914. $invoice = new invoice ();
  2915. Doo::loadClass ( 'XDeode' );
  2916. $XDeode = new XDeode ( 5 );
  2917. $category = $lCategory->getCategory ();
  2918. $staffList = $staff->getStaffByCid ( $this->staff [0] ['cid'] );
  2919. $sql = 'bindStatus=1 and iid!=0';
  2920. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByNew ( 4, $sql );
  2921. // 获取未入账发票
  2922. $invoiceUnAccount = $invoice->getInvoiceByUnAccount ( $invoiceTC );
  2923. $invoiceExistAccount = $invoice->getInvoiceByUnAccount ( '', true );
  2924. foreach ( $invoiceUnAccount as $key => $value ) {
  2925. $invoiceUnAccount [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2926. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2927. if (! empty ( $lastApprover )) {
  2928. $lastApproverKey = array_keys ( $lastApprover );
  2929. $lastApprover = end ( $lastApprover );
  2930. $staffDetail = $staff->getOne ( array (
  2931. 'where' => 'sid=' . end ( $lastApproverKey ),
  2932. 'asArray' => true
  2933. ) );
  2934. $lastApprover ['username'] = $staffDetail ['username'];
  2935. }
  2936. $invoiceUnAccount [$key] ['lastApprover'] = $lastApprover;
  2937. }
  2938. foreach ( $invoiceExistAccount as $key => $value ) {
  2939. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  2940. if (empty ( $irList ))
  2941. $irList [0] ['sumPrice'] = 0;
  2942. $balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  2943. $invoiceExistAccount [$key] ['existAccount'] = $irList [0] ['sumPrice'];
  2944. $invoiceExistAccount [$key] ['balance'] = $balance;
  2945. }
  2946. $receivablesInput = $invoiceReceivables->getInvoiceReceivablesByInput ();
  2947. $halfList = $invoiceReceivables->getInvoiceReceivablesByHalf ();
  2948. $this->data ['halfList'] = $halfList;
  2949. $this->data ['halfCount'] = count ( $halfList );
  2950. // print_r($receivablesList);
  2951. $this->data ['receivablesDate'] = date ( "Y-m-d" );
  2952. $this->data ['ieaCount'] = count ( $invoiceExistAccount );
  2953. $this->data ['invoiceExistAccount'] = $invoiceExistAccount;
  2954. $this->data ['receivablesInput'] = $receivablesInput;
  2955. $this->data ['year'] = date ( 'Y' );
  2956. $this->data ['invoiceUnAccount'] = $invoiceUnAccount;
  2957. $this->data ['receivablesList'] = $receivablesList;
  2958. $this->data ['staffList'] = $staffList;
  2959. $this->data ['category'] = $category;
  2960. $this->data ['memu'] = "invoice";
  2961. $this->data ['staff'] = $this->staff;
  2962. $this->data ['receiptMemu'] = 'invoiceReceivables';
  2963. $this->render ( "/admin/invoiceReceivables", $this->data );
  2964. }
  2965. /**
  2966. * 设置收款认领地区
  2967. */
  2968. function setInvoiceReceivablesClaim() {
  2969. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  2970. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  2971. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  2972. if (! empty ( $iridKey ) && ! empty ( $receivablesCategory )) {
  2973. Doo::loadModel ( 'invoiceReceivables' );
  2974. $invoiceReceivables = new invoiceReceivables ();
  2975. Doo::loadClass ( 'XDeode' );
  2976. $XDeode = new XDeode ( 5 );
  2977. Doo::loadModel ( 'invoiceROLog' );
  2978. $invoiceROLog = new invoiceROLog ();
  2979. $irid = $XDeode->decode ( $iridKey );
  2980. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  2981. if (empty ( $irDetail ))
  2982. die ( 'illegal request' );
  2983. $item = array (
  2984. 'irid' => $irid,
  2985. 'receivablesCategory' => $receivablesCategory
  2986. );
  2987. if ($receivablesCategory != 'PUBLIC') {
  2988. $item += array (
  2989. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  2990. 'inputType' => 1
  2991. );
  2992. }
  2993. $invoiceReceivables = new invoiceReceivables ();
  2994. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2995. // 收款操作日志
  2996. $item = array (
  2997. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 ",
  2998. 'date' => date ( "Y-m-d" ),
  2999. 'status' => 1,
  3000. 'img' => $this->staff [0] ['avatar'],
  3001. 'username' => $this->staff [0] ['username'],
  3002. 'uid' => $this->staff [0] ['sid'],
  3003. 'category' => $this->staff [0] ['category'],
  3004. 'irid' => $irid
  3005. );
  3006. $invoiceROLog->setInvoiceROLog ( $item );
  3007. if (empty ( $action ))
  3008. return '/invoiceReceivables';
  3009. else
  3010. return "/invoiceReceivablesAS";
  3011. }
  3012. die ( 'illegal request' );
  3013. }
  3014. /**
  3015. * 新添加收款直接入账发票
  3016. */
  3017. function invoiceCompareClaimPrice() {
  3018. // 收款录入
  3019. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  3020. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3021. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3022. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3023. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3024. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $iidKey )) {
  3025. Doo::loadModel ( 'invoiceReceivables' );
  3026. $invoiceReceivables = new invoiceReceivables ();
  3027. Doo::loadModel ( 'invoiceROLog' );
  3028. $invoiceROLog = new invoiceROLog ();
  3029. Doo::loadModel ( 'invoiceStatistics' );
  3030. Doo::loadModel ( 'invoice' );
  3031. $invoice = new invoice ();
  3032. Doo::loadClass ( 'XDeode' );
  3033. $XDeode = new XDeode ( 5 );
  3034. Doo::loadModel ( 'invoiceOperationLog' );
  3035. $invoiceOperationLog = new invoiceOperationLog ();
  3036. $iidKey = $XDeode->decode ( $iidKey );
  3037. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  3038. if (! ($invoiceDetail ['status'] == 2 && $invoiceDetail ['printStatus'] == 1 && $invoiceDetail ['untreadStatus'] == 0))
  3039. die ( 'illegal request' );
  3040. $receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  3041. // 收款录入 并绑定发票
  3042. Doo::db ()->beginTransaction ();
  3043. $bindStatus = 0;
  3044. if ($receivablesPrice <= $invoiceDetail ['invoicePrice'])
  3045. $bindStatus = 1;
  3046. $titleMark = $invoiceDetail ['invoiceTitle'];
  3047. if (! empty ( $invoiceDetail ['invoiceCompany'] ))
  3048. $titleMark = $invoiceDetail ['invoiceCompany'];
  3049. $item = array (
  3050. 'recepitTitleMark' => $titleMark,
  3051. 'bindStatus' => $bindStatus,
  3052. 'iid' => $invoiceDetail ['iid'],
  3053. 'bindPrice' => $invoiceDetail ['invoicePrice'],
  3054. 'bindDate' => date ( "Y-m-d H:i:s" ),
  3055. 'receivablesPrice' => $receivablesPrice,
  3056. 'OriginalPrice' => $receivablesPrice,
  3057. 'receivablesMessage' => $receivablesMessage,
  3058. 'receivablesSerial' => $receivablesSerial,
  3059. 'receivablesBank' => $receivablesBank,
  3060. 'receivablesDate' => $receivablesDate,
  3061. 'inputStaff' => $this->staff [0] ['username'],
  3062. 'accountClerk' => $this->staff [0] ['username'],
  3063. 'date' => date ( "Y-m-d" ),
  3064. 'receivablesCategory' => $invoiceDetail ['cid'] . ':' . $invoiceDetail ['categoryName'],
  3065. 'receivablesStaff' => $invoiceDetail ['sid'] . '-' . $invoiceDetail ['userName'],
  3066. 'confirmTime' => date ( "Y-m-d H:i:s" )
  3067. );
  3068. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  3069. $item = array ();
  3070. // 收款操作日志
  3071. $item = array (
  3072. 'operation' => $this->staff [0] ['username'] . " 转入 " . $invoiceDetail ['userName']
  3073. );
  3074. $item += array (
  3075. 'date' => date ( "Y-m-d" ),
  3076. 'status' => 1,
  3077. 'img' => $this->staff [0] ['avatar'],
  3078. 'username' => $this->staff [0] ['username'],
  3079. 'uid' => $this->staff [0] ['sid'],
  3080. 'category' => $this->staff [0] ['category'],
  3081. 'irid' => $irid
  3082. );
  3083. $invoiceROLog->setInvoiceROLog ( $item );
  3084. // 收款统计
  3085. $invoiceStatistics = new invoiceStatistics ();
  3086. $item = array (
  3087. 'date' => $receivablesDate,
  3088. 'priceClass' => 2,
  3089. 'irid' => $irid,
  3090. 'cid' => $invoiceDetail ['cid'],
  3091. 'staff' => $invoiceDetail ['sid'],
  3092. 'receivablesPrice' => $receivablesPrice
  3093. );
  3094. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3095. // 收款 入 发票
  3096. $detail = $invoiceDetail;
  3097. $iridString = "";
  3098. if (empty ( $detail ['irid'] ))
  3099. $iridString = $irid;
  3100. else
  3101. $iridString = $detail ['irid'] . ',' . $irid;
  3102. $item = array (
  3103. 'irid' => $iridString,
  3104. 'bindTime' => date ( "Y-m-d H:i:s" ),
  3105. 'updateTime' => date ( "Y-m-d H:i:s" ),
  3106. 'iid' => $detail ['iid']
  3107. );
  3108. $invoiceReceivables = new invoiceReceivables ();
  3109. $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  3110. if ($detail ['invoicePrice'] <= $sum)
  3111. $item += array (
  3112. 'untreadStatus' => 3
  3113. );
  3114. $invoice->setInvoiceByCondition ( $item );
  3115. // 操作日志
  3116. $item = array (
  3117. 'date' => date ( "Y-m-d H:i:s" ),
  3118. 'operation' => "收款入账" . $receivablesSerial . "到发票" . $detail ['invoiceSerial'],
  3119. 'status' => 8,
  3120. 'img' => $this->staff [0] ['avatar'],
  3121. 'username' => $this->staff [0] ['username'],
  3122. 'uid' => $this->staff [0] ['sid'],
  3123. 'category' => $this->staff [0] ['category'],
  3124. 'iid' => $detail ['iid']
  3125. );
  3126. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3127. // 入账汇总
  3128. $invoiceStatistics = new invoiceStatistics ();
  3129. // $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $iridString );
  3130. // $accountPrice = 0;
  3131. // foreach ( $list as $key => $value ) {
  3132. // $accountPrice += $value ['receivablesPrice'];
  3133. // }
  3134. $item = array (
  3135. 'date' => $receivablesDate,
  3136. 'priceClass' => 3,
  3137. 'cid' => $invoiceDetail ['cid'],
  3138. 'staff' => $invoiceDetail ['sid'],
  3139. 'accountPrice' => $receivablesPrice
  3140. );
  3141. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3142. // 公司流水记录
  3143. Doo::loadModel ( 'wasteBook' );
  3144. $wasteBook = new wasteBook ();
  3145. $abDetail = $wasteBook->getAccountBookByAid ( 2, 7, $irid );
  3146. $accountBank = '';
  3147. if ($receivablesBank == '纵横广发') {
  3148. $accountBank = 'CGBDeposit';
  3149. } elseif ($receivablesBank == '纵横工行') {
  3150. $accountBank = 'ICBCDeposit';
  3151. } elseif ($receivablesBank == '华润银行') {
  3152. $accountBank = 'HUADeposit';
  3153. } elseif ($receivablesBank == '个人广发') {
  3154. $accountBank = 'PersonalDeposit';
  3155. }
  3156. if (empty ( $abDetail )) {
  3157. $item = array (
  3158. 'dataID' => $irid,
  3159. 'expensesType' => 1,
  3160. 'accountType' => 7,
  3161. 'accountPrice' => $receivablesPrice,
  3162. 'accountPriceShow' => $receivablesPrice,
  3163. 'accountBank' => $accountBank,
  3164. 'category' => $this->staff [0] ['category'],
  3165. 'cid' => $this->staff [0] ['cid'],
  3166. 'name' => $this->staff [0] ['username'],
  3167. 'sid' => $this->staff [0] ['sid'],
  3168. 'inputDate' => date ( "Y-m-d H:i:s" )
  3169. );
  3170. $wasteBook->setAccountBookStatistics ( $item );
  3171. }
  3172. Doo::db ()->commit ();
  3173. }
  3174. return '/invoiceReceivables';
  3175. }
  3176. /**
  3177. * 录入收款数据
  3178. * @return string
  3179. */
  3180. function invoiceReceivablesDo() {
  3181. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3182. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3183. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3184. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3185. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3186. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  3187. Doo::loadModel ( 'invoiceReceivables' );
  3188. $invoiceReceivables = new invoiceReceivables ();
  3189. Doo::loadModel ( 'invoiceROLog' );
  3190. $invoiceROLog = new invoiceROLog ();
  3191. Doo::loadModel ( 'invoiceStatistics' );
  3192. $invoiceStatistics = new invoiceStatistics ();
  3193. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $receivablesCategory ) && ! empty ( $receivablesStaff )) {
  3194. $item = array (
  3195. 'receivablesPrice' => $receivablesPrice,
  3196. 'OriginalPrice' => $receivablesPrice,
  3197. 'receivablesMessage' => $receivablesMessage,
  3198. 'receivablesSerial' => "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  3199. 'receivablesBank' => $receivablesBank,
  3200. 'receivablesDate' => $receivablesDate,
  3201. 'inputStaff' => $this->staff [0] ['username'],
  3202. 'date' => date ( "Y-m-d" ),
  3203. 'receivablesCategory' => $receivablesCategory,
  3204. 'receivablesStaff' => $receivablesStaff
  3205. );
  3206. if ($receivablesCategory != 'PUBLIC') {
  3207. $item += array (
  3208. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3209. 'inputType' => 1
  3210. );
  3211. }
  3212. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  3213. $item = array ();
  3214. // 收款操作日志
  3215. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3216. $item = array (
  3217. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  3218. );
  3219. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3220. $item = array (
  3221. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  3222. );
  3223. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3224. $receivablesStaff = explode ( '-', $receivablesStaff );
  3225. $item = array (
  3226. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  3227. );
  3228. }
  3229. $item += array (
  3230. 'date' => date ( "Y-m-d" ),
  3231. 'status' => 1,
  3232. 'img' => $this->staff [0] ['avatar'],
  3233. 'username' => $this->staff [0] ['username'],
  3234. 'uid' => $this->staff [0] ['sid'],
  3235. 'category' => $this->staff [0] ['category'],
  3236. 'irid' => $irid
  3237. );
  3238. $invoiceROLog->setInvoiceROLog ( $item );
  3239. $item = array (
  3240. 'date' => $receivablesDate,
  3241. 'priceClass' => 2,
  3242. 'irid' => $irid,
  3243. 'receivablesPrice' => $receivablesPrice
  3244. );
  3245. if ($receivablesCategory != 'PUBLIC') {
  3246. $receivablesCategory = explode ( ":", $receivablesCategory );
  3247. $item += array (
  3248. 'cid' => $receivablesCategory [0]
  3249. );
  3250. }
  3251. if ($receivablesStaff2 != 'PUBLIC') {
  3252. $receivablesStaff = explode ( "-", $receivablesStaff2 );
  3253. $item += array (
  3254. 'staff' => $receivablesStaff [0]
  3255. );
  3256. }
  3257. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3258. $toparty = $this->getWxidByCategory ( $receivablesCategory [1] );
  3259. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  3260. $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  3261. if ($toparty != 0)
  3262. $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  3263. // 公司流水记录
  3264. Doo::loadModel ( 'wasteBook' );
  3265. $wasteBook = new wasteBook ();
  3266. $abDetail = $wasteBook->getAccountBookByAid ( 1, 7, $irid );
  3267. $accountBank = '';
  3268. if ($receivablesBank == '纵横广发') {
  3269. $accountBank = 'CGBDeposit';
  3270. } elseif ($receivablesBank == '纵横工行') {
  3271. $accountBank = 'ICBCDeposit';
  3272. } elseif ($receivablesBank == '华润银行') {
  3273. $accountBank = 'HUADeposit';
  3274. } elseif ($receivablesBank == '个人广发') {
  3275. $accountBank = 'PersonalDeposit';
  3276. }
  3277. $item = array (
  3278. 'dataID' => $irid,
  3279. 'expensesType' => 1,
  3280. 'accountType' => 7,
  3281. 'accountPriceShow' => $receivablesPrice,
  3282. 'accountPrice' => $receivablesPrice,
  3283. 'accountBank' => $accountBank,
  3284. 'category' => $this->staff [0] ['category'],
  3285. 'cid' => $this->staff [0] ['cid'],
  3286. 'name' => $this->staff [0] ['username'],
  3287. 'sid' => $this->staff [0] ['sid'],
  3288. 'inputDate' => date ( "Y-m-d H:i:s" )
  3289. );
  3290. $wasteBook->setAccountBookStatistics ( $item );
  3291. }
  3292. return "/invoiceReceivables";
  3293. }
  3294. /**
  3295. * 收款认领页面-包括公共认领 办事处认领 最近已认领数据
  3296. */
  3297. function invoiceReceivablesClaim() {
  3298. Doo::loadModel ( 'invoiceReceivables' );
  3299. $invoiceReceivables = new invoiceReceivables ();
  3300. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  3301. $this->data ['receivablesList'] = $receivablesList;
  3302. $this->data ['memu'] = "invoice";
  3303. $this->data ['staff'] = $this->staff;
  3304. $this->data ['receiptMemu'] = 'invoiceReceivablesClaim';
  3305. $this->render ( "/admin/invoiceReceivablesClaim", $this->data );
  3306. }
  3307. function invoiceReceivablesTitleMarkSet() {
  3308. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  3309. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  3310. if (empty ( $iridKey ) || empty ( $recepitTitleMark ))
  3311. die ( 'illegal request' );
  3312. Doo::loadModel ( 'invoiceReceivables' );
  3313. $invoiceReceivables = new invoiceReceivables ();
  3314. Doo::loadClass ( 'XDeode' );
  3315. $XDeode = new XDeode ( 5 );
  3316. $irid = $XDeode->decode ( $iridKey );
  3317. if (! is_numeric ( $irid ))
  3318. die ( 'illegal request' );
  3319. $invoiceReceivables->recepitTitleMark = $recepitTitleMark;
  3320. $invoiceReceivables->update ( array (
  3321. 'where' => 'irid = ' . $irid
  3322. ) );
  3323. return '/invoiceReceivablesClaim';
  3324. }
  3325. /**
  3326. * 更新收款相关数据
  3327. */
  3328. function invoiceReceivablesUpdateClaim() {
  3329. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3330. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3331. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3332. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3333. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3334. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  3335. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  3336. if (empty ( $claimKey ))
  3337. die ( 'illegal request' );
  3338. Doo::loadModel ( 'invoiceReceivables' );
  3339. $invoiceReceivables = new invoiceReceivables ();
  3340. Doo::loadModel ( 'invoiceROLog' );
  3341. $invoiceROLog = new invoiceROLog ();
  3342. $con = ' and iid=0 and bindStatus=0'; // and receivablesCategory!="PUBLIC" and receivablesStaff!="PUBLIC"
  3343. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  3344. if (empty ( $detail ))
  3345. die ( 'illegal request' );
  3346. $invoiceReceivables = new invoiceReceivables ();
  3347. $item = array (
  3348. 'irid' => $detail ['irid']
  3349. );
  3350. if ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3351. $item += array (
  3352. 'confirmTime' => date ( "Y-m-d H:i:s" )
  3353. );
  3354. }
  3355. if (! empty ( $receivablesCategory ))
  3356. $item += array (
  3357. 'receivablesCategory' => $receivablesCategory
  3358. );
  3359. if (! empty ( $receivablesStaff ))
  3360. $item += array (
  3361. 'receivablesStaff' => $receivablesStaff
  3362. );
  3363. if (! empty ( $receivablesPrice ))
  3364. $item += array (
  3365. 'receivablesPrice' => $receivablesPrice
  3366. );
  3367. if (! empty ( $receivablesMessage ))
  3368. $item += array (
  3369. 'receivablesMessage' => $receivablesMessage
  3370. );
  3371. if (! empty ( $receivablesBank ))
  3372. $item += array (
  3373. 'receivablesBank' => $receivablesBank
  3374. );
  3375. if (! empty ( $receivablesDate ))
  3376. $item += array (
  3377. 'receivablesDate' => $receivablesDate
  3378. );
  3379. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3380. // 收款操作日志
  3381. $item = array ();
  3382. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3383. $item = array (
  3384. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  3385. );
  3386. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3387. $item = array (
  3388. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  3389. );
  3390. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3391. $receivablesStaff = explode ( '-', $receivablesStaff );
  3392. $item = array (
  3393. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  3394. );
  3395. }
  3396. $item += array (
  3397. 'date' => date ( "Y-m-d" ),
  3398. 'status' => 1,
  3399. 'img' => $this->staff [0] ['avatar'],
  3400. 'username' => $this->staff [0] ['username'],
  3401. 'uid' => $this->staff [0] ['sid'],
  3402. 'category' => $this->staff [0] ['category'],
  3403. 'irid' => $detail ['irid']
  3404. );
  3405. $invoiceROLog->setInvoiceROLog ( $item );
  3406. return '/invoiceReceivablesAS';
  3407. }
  3408. function invoiceReceivablesDelete() {
  3409. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  3410. $skll = $this->get_args ( 'skll' ) ? $this->get_args ( 'skll' ) : "";
  3411. if ($skll != '删除到款')
  3412. die ( 'illegal request' );
  3413. if (empty ( $claimKey ))
  3414. die ( 'illegal request' );
  3415. Doo::loadModel ( 'invoiceReceivables' );
  3416. $invoiceReceivables = new invoiceReceivables ();
  3417. $con = ' and bindStatus=0 ';
  3418. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  3419. if (empty ( $detail ))
  3420. die ( 'illegal request' );
  3421. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  3422. // 扣除收款汇总信息 汇总
  3423. Doo::loadModel ( 'invoiceStatistics' );
  3424. $invoiceStatistics = new invoiceStatistics ();
  3425. $item = array (
  3426. 'date' => $detail ['receivablesDate'],
  3427. 'priceClass' => 2,
  3428. 'irid' => $detail ['irid'],
  3429. 'receivablesPrice' => - $detail ['receivablesPrice']
  3430. );
  3431. if ($detail ['receivablesCategory'] != 'PUBLIC') {
  3432. $receivablesCategory = explode ( ":", $detail ['receivablesCategory'] );
  3433. $item += array (
  3434. 'cid' => $receivablesCategory [0]
  3435. );
  3436. }
  3437. if ($detail ['receivablesStaff'] != 'PUBLIC') {
  3438. $receivablesStaff = explode ( "-", $detail ['receivablesStaff'] );
  3439. $item += array (
  3440. 'staff' => $receivablesStaff [0]
  3441. );
  3442. }
  3443. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3444. // 公司流水-删除时删除流水
  3445. Doo::loadModel ( 'wasteBook' );
  3446. $wasteBook = new wasteBook ();
  3447. $wasteBook->delete ( array (
  3448. 'where' => 'dataID=' . $detail ['irid'] . ' and accountType=7',
  3449. 'limit' => 1
  3450. ) );
  3451. return '/invoiceReceivablesAS';
  3452. }
  3453. /**
  3454. * 管理员录入的收款 ,确认认领到谁的名下.统计收款金额
  3455. */
  3456. function invoiceReceivablesAscription() {
  3457. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  3458. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  3459. Doo::loadModel ( 'invoiceReceivables' );
  3460. $invoiceReceivables = new invoiceReceivables ();
  3461. Doo::loadModel ( 'invoiceROLog' );
  3462. $invoiceROLog = new invoiceROLog ();
  3463. Doo::loadModel ( 'invoiceStatistics' );
  3464. $invoiceStatistics = new invoiceStatistics ();
  3465. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  3466. if (! empty ( $detail ) && $detail ['receivablesStaff'] == 'PUBLIC' && ! empty ( $recepitTitleMark )) {
  3467. $item = array (
  3468. 'irid' => $detail ['irid'],
  3469. 'receivablesCategory' => $this->staff [0] ['cid'] . ":" . $this->staff [0] ['category'],
  3470. 'receivablesStaff' => $this->staff [0] ['sid'] . "-" . $this->staff [0] ['username'],
  3471. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3472. 'recepitTitleMark' => $recepitTitleMark,
  3473. 'source' => 1
  3474. );
  3475. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3476. $item = array (
  3477. 'date' => date ( "Y-m-d" ),
  3478. 'operation' => $this->staff [0] ['username'] . " 认领 ",
  3479. 'status' => 2,
  3480. 'img' => $this->staff [0] ['avatar'],
  3481. 'username' => $this->staff [0] ['username'],
  3482. 'uid' => $this->staff [0] ['sid'],
  3483. 'category' => $this->staff [0] ['category'],
  3484. 'irid' => $irid
  3485. );
  3486. $invoiceROLog->setInvoiceROLog ( $item );
  3487. $item = array (
  3488. 'cid' => $this->staff [0] ['cid'],
  3489. 'staff' => $this->staff [0] ['sid']
  3490. );
  3491. $invoiceStatistics->updateInvoiceStatisticsByIrid ( $item, $detail ['irid'], 2 );
  3492. }
  3493. return "/invoiceReceivablesClaim";
  3494. }
  3495. /**
  3496. */
  3497. function invoiceMyReceivables() {
  3498. Doo::loadModel ( 'invoiceReceivables' );
  3499. $invoiceReceivables = new invoiceReceivables ();
  3500. Doo::loadModel ( 'invoiceStatistics' );
  3501. $invoiceStatistics = new invoiceStatistics ();
  3502. $isMonth = $invoiceStatistics->getStatisticsByMonth ( $this->staff [0] ['sid'] );
  3503. $year = date ( "Y" );
  3504. $tmp_date = date ( "Ym" );
  3505. $tmp_year = substr ( $tmp_date, 0, 4 );
  3506. $tmp_mon = substr ( $tmp_date, 4, 2 );
  3507. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  3508. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  3509. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . ".htm";
  3510. $htm = $this->showCache ( $path );
  3511. $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  3512. $this->data ['isMonth'] = $isMonth;
  3513. $this->data ['htm'] = $htm;
  3514. $this->data ['list'] = $list;
  3515. $this->data ['memu'] = "invoice";
  3516. $this->data ['staff'] = $this->staff;
  3517. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  3518. $this->render ( "/admin/invoiceMyReceivables", $this->data );
  3519. }
  3520. /**
  3521. * 纸票管理
  3522. */
  3523. function invoicePaper() {
  3524. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3525. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3526. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3527. $this->data ['dateString'] = $date;
  3528. $this->data ['status'] = $status;
  3529. $this->data ['invoiceType'] = $invoiceType;
  3530. $this->data ['memu'] = "invoice";
  3531. $this->data ['staff'] = $this->staff;
  3532. $this->data ['receiptMemu'] = 'invoicePaper';
  3533. $this->render ( "/admin/invoicePaper", $this->data );
  3534. }
  3535. /**
  3536. * 获得纸票分页数据
  3537. */
  3538. function ajaxGetinvoicePaperAchieve() {
  3539. Doo::loadModel ( 'invoicePaper' );
  3540. $invoicePaper = new invoicePaper ();
  3541. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3542. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3543. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ORDINARY";
  3544. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3545. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  3546. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  3547. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  3548. $MebSea = $this->get_args ( 'search' );
  3549. $MebSea = $MebSea ['value'];
  3550. $page_size = $length;
  3551. $con = '';
  3552. if ($status == 'ALL')
  3553. $con = ' where 1 ';
  3554. elseif ($status == 'PRINTED')
  3555. $con = ' where a.iid!=0 '; // $con = ' where b.isDelete=0 and a.iid!=0 and b.status=2 and b.untreadStatus=0 ';
  3556. elseif ($status == 'UNPRINT')
  3557. $con = ' where a.iid=0 '; // $con = ' where b.isDelete=0 and a.iid=0 and b.status=2 and b.untreadStatus=0 ';
  3558. elseif ($status == 'TICKET')
  3559. $con = ' where b.isDelete=0 and b.untreadStatus=2';
  3560. if ($invoiceType == 'ORDINARY')
  3561. $con .= ' and a.invoiceType=0 ';
  3562. elseif ($invoiceType == 'SPECIAL')
  3563. $con .= ' and a.invoiceType=1 ';
  3564. $dateArr = explode ( ':', $date );
  3565. $D1 = $dateString = '';
  3566. $D2 = '';
  3567. if (! empty ( $date )) {
  3568. $D1 = $dateArr [0];
  3569. if (isset ( $dateArr [1] ))
  3570. $D2 = $dateArr [1];
  3571. else
  3572. $D2 = '';
  3573. $dateString = $D1 . " : " . $D2;
  3574. }
  3575. if (! empty ( $D1 ) && ! empty ( $D2 ))
  3576. $con .= ' and b.printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  3577. elseif (! empty ( $D1 ) && empty ( $D2 ))
  3578. $con .= ' and b.printTime like "%' . $D1 . '%" ';
  3579. if (! empty ( $MebSea ))
  3580. $con .= ' and ( b.invoiceTitle like "%' . $MebSea . '%" or b.invoiceCompany like "%' . $MebSea . '%" or a.invoiceNo like "%' . $MebSea . '%" )';
  3581. $invoiceTotal = $invoicePaper->getInvoicePaperCount ();
  3582. $sql = ' ' . $con;
  3583. $limit = $page . ',' . $page_size;
  3584. $list = $invoicePaper->getInvoicePaper ( $limit, $sql, 'desc' );
  3585. $paperList = array ();
  3586. foreach ( $list as $key => $value ) {
  3587. $irDetail = array ();
  3588. if ($value ['iid'] == 0)
  3589. array_push ( $irDetail, '<a href="javascript:if(window.confirm(\'确认删除?\'))window.location=\'/invoicePaperDel/' . $value ['ipidKey'] . '\'" >删除</a>' );
  3590. else
  3591. array_push ( $irDetail, '' );
  3592. array_push ( $irDetail, $value ['invoiceCode'] );
  3593. array_push ( $irDetail, $value ['invoiceNo'] );
  3594. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKey'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  3595. if ($value ['invoiceType'] == 1)
  3596. array_push ( $irDetail, $value ['invoiceCompany'] );
  3597. else
  3598. array_push ( $irDetail, $value ['invoiceTitle'] );
  3599. if ($value ['invoiceType'] == 1)
  3600. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  3601. else
  3602. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  3603. array_push ( $irDetail, $value ['invoiceElement'] );
  3604. array_push ( $irDetail, $value ['categoryName'] . '-' . $value ['userName'] );
  3605. array_push ( $irDetail, $value ['printTime'] );
  3606. array_push ( $paperList, $irDetail );
  3607. }
  3608. // $approvalListJson = json_encode ( $approvalList );
  3609. $recordsFiltered = $invoiceTotal;
  3610. echo json_encode ( array (
  3611. "draw" => intval ( $draw ),
  3612. "recordsTotal" => intval ( $invoiceTotal ),
  3613. "recordsFiltered" => intval ( $recordsFiltered ),
  3614. "data" => $paperList
  3615. ), JSON_UNESCAPED_UNICODE );
  3616. }
  3617. function invoicePaperDel() {
  3618. $ipidKey = isset ( $this->params ['ipidKey'] ) ? $this->params ['ipidKey'] : "";
  3619. $XDeode = new XDeode ( 5 );
  3620. $ipid = $XDeode->decode ( $ipidKey );
  3621. if (empty ( $ipid ))
  3622. die ( 'illegal request' );
  3623. Doo::loadModel ( 'invoicePaper' );
  3624. $invoicePaper = new invoicePaper ();
  3625. $invoicePaper->delete ( array (
  3626. 'where' => 'ipid=' . $ipid . ' and iid=0',
  3627. 'limit' => 1
  3628. ) );
  3629. return '/invoicePaper';
  3630. }
  3631. /**
  3632. * 添加纸质发票号
  3633. */
  3634. function invoicePaperAdd() {
  3635. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : '0';
  3636. $invoiceCode = $this->get_args ( 'invoiceCode' ) ? $this->get_args ( 'invoiceCode' ) : "";
  3637. $invoiceNoStart = $this->get_args ( 'invoiceNoStart' ) && is_numeric ( $this->get_args ( 'invoiceNoStart' ) ) ? $this->get_args ( 'invoiceNoStart' ) : 0;
  3638. $invoiceNoTotal = $this->get_args ( 'invoiceNoTotal' ) && is_numeric ( $this->get_args ( 'invoiceNoTotal' ) ) ? $this->get_args ( 'invoiceNoTotal' ) : 0;
  3639. if ($invoiceType != '' && ! empty ( $invoiceCode ) && ! empty ( $invoiceNoStart ) && ! empty ( $invoiceNoTotal )) {
  3640. $sum = $invoiceNoStart + $invoiceNoTotal;
  3641. if (empty ( $sum ))
  3642. die ( 'illegal request' );
  3643. // echo $invoiceNoStart;
  3644. // echo $sum;
  3645. // echo strlen((int)$invoiceNoStart);
  3646. $sumLenght = strlen ( $invoiceNoStart ) - strlen ( ( int ) $invoiceNoStart );
  3647. Doo::db ()->beginTransaction ();
  3648. // 批量存储纸质发票
  3649. $date = date ( "Y-m-d H:i:s" );
  3650. $sql = 'INSERT INTO CLD_invoicePaper (invoiceType, invoiceCode,invoiceNo,date)
  3651. VALUES ';
  3652. $paperList = array ();
  3653. for($invoiceNoStart; $invoiceNoStart <= $sum - 1; $invoiceNoStart ++) {
  3654. // 数字前面自加0
  3655. $INLENGHT = strlen ( ( int ) $invoiceNoStart ) + $sumLenght;
  3656. $var = sprintf ( "%0" . $INLENGHT . "d", $invoiceNoStart );
  3657. $paperSql = '(' . $invoiceType . ',"' . $invoiceCode . '","' . $var . '","' . $date . '")';
  3658. array_push ( $paperList, $paperSql );
  3659. }
  3660. if (empty ( $paperList ))
  3661. die ( 'illegal request' );
  3662. $sql = $sql . implode ( ',', $paperList );
  3663. Doo::db ()->query ( $sql );
  3664. Doo::db ()->commit ();
  3665. return 'invoicePaper';
  3666. }
  3667. die ( 'illegal request' );
  3668. }
  3669. /**
  3670. * 收款绑定发票 ,//一个收款只能绑定一个发票
  3671. */
  3672. function invoiceBindReceivables() {
  3673. $claimKey = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  3674. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  3675. Doo::loadModel ( 'invoice' );
  3676. $invoice = new invoice ();
  3677. Doo::loadModel ( 'invoiceReceivables' );
  3678. $invoiceReceivables = new invoiceReceivables ();
  3679. Doo::loadModel ( 'invoiceOperationLog' );
  3680. $invoiceOperationLog = new invoiceOperationLog ();
  3681. if (empty ( $invoiceKey ) || empty ( $claimKey ))
  3682. die ( 'illegal request' );
  3683. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  3684. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey );
  3685. if (empty ( $detail ) && empty ( $detailM ))
  3686. die ( 'illegal request' );
  3687. if ($detail ['untreadStatus'] == 3)
  3688. die ( 'illegal request' );
  3689. // 修改 绑定状态改为 金额
  3690. $invoiceReceivables = new invoiceReceivables ();
  3691. $invoicePrice = $detail ['invoicePrice'] + $detailM ['bindPrice'];
  3692. if ($detailM ['receivablesPrice'] > $invoicePrice) {
  3693. $item = array (
  3694. 'bindPrice' => $invoicePrice
  3695. );
  3696. } elseif ($detailM ['receivablesPrice'] <= $invoicePrice) {
  3697. $item = array (
  3698. 'bindPrice' => $invoicePrice,
  3699. 'bindStatus' => 1,
  3700. 'bindDate' => date ( "Y-m-d H:i:s" )
  3701. );
  3702. } else {
  3703. die ( 'illegal request' );
  3704. }
  3705. if ($detailM ['iid'] == 0) {
  3706. $item += array (
  3707. 'iid' => $detail ['iid']
  3708. );
  3709. } else {
  3710. $iidExtend = explode ( ',', $detailM ['iidExtend'] );
  3711. array_push ( $iidExtend, $detail ['iid'] );
  3712. $item += array (
  3713. 'iidExtend' => implode ( ',', $iidExtend )
  3714. );
  3715. }
  3716. $titleMark = $detail ['invoiceTitle'];
  3717. if (! empty ( $detail ['invoiceCompany'] ))
  3718. $titleMark = $detail ['invoiceCompany'];
  3719. $item += array (
  3720. 'irid' => $detailM ['irid'],
  3721. 'recepitTitleMark' => $titleMark,
  3722. 'accountClerk' => $this->staff [0] ['username']
  3723. );
  3724. // 如何没有人收款 则自动绑定收款
  3725. if ($detailM ['receivablesCategory'] == 'PUBLIC' || $detailM ['receivablesStaff'] == 'PUBLIC') {
  3726. $item += array (
  3727. 'receivablesCategory' => $detail ['cid'] . ':' . $detail ['categoryName'],
  3728. 'receivablesStaff' => $detail ['sid'] . '-' . $detail ['userName']
  3729. );
  3730. }
  3731. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3732. $iridString = "";
  3733. if (empty ( $detail ['irid'] ))
  3734. $iridString = $detailM ['irid'];
  3735. else
  3736. $iridString = $detail ['irid'] . ',' . $detailM ['irid'];
  3737. $item = array (
  3738. 'iid' => $detail ['iid'],
  3739. 'irid' => $iridString
  3740. );
  3741. $invoiceReceivables = new invoiceReceivables ();
  3742. $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  3743. if ($detail ['invoicePrice'] <= $sum)
  3744. $item += array (
  3745. 'untreadStatus' => 3,
  3746. 'bindTime' => date ( "Y-m-d H:i:s" )
  3747. );
  3748. // print_r($item);
  3749. // echo $sum;die;
  3750. $invoice->setInvoiceByCondition ( $item );
  3751. // 操作日志
  3752. $item = array (
  3753. 'date' => date ( "Y-m-d H:i:s" ),
  3754. 'operation' => "收款" . $detailM ['receivablesSerial'] . "入账到发票" . $detail ['invoiceSerial'],
  3755. 'status' => 8,
  3756. 'img' => $this->staff [0] ['avatar'],
  3757. 'username' => $this->staff [0] ['username'],
  3758. 'uid' => $this->staff [0] ['sid'],
  3759. 'category' => $this->staff [0] ['category'],
  3760. 'iid' => $detail ['iid']
  3761. );
  3762. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3763. Doo::loadModel ( 'invoiceStatistics' );
  3764. $invoiceStatistics = new invoiceStatistics ();
  3765. $item = array (
  3766. 'date' => $detailM ['receivablesDate'],
  3767. 'priceClass' => 3,
  3768. 'cid' => $detail ['cid'],
  3769. 'staff' => $detail ['sid'],
  3770. 'accountPrice' => $detailM ['receivablesPrice']
  3771. );
  3772. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3773. // 公司流水记录
  3774. // Doo::loadModel ( 'wasteBook' );
  3775. // $wasteBook = new wasteBook ();
  3776. // $abDetail = $wasteBook->getAccountBookByAid (1,8,$detail ['iid'] );
  3777. // $accountBank='';
  3778. // if ($detailM ['receivablesBank']=='纵横广发'){
  3779. // $accountBank='CGBDeposit';
  3780. // }elseif($detailM ['receivablesBank']=='纵横工行'){
  3781. // $accountBank='ICBCDeposit';
  3782. // }elseif($detailM ['receivablesBank']=='华润银行'){
  3783. // $accountBank='HUADeposit';
  3784. // }elseif($detailM ['receivablesBank']=='个人广发'){
  3785. // $accountBank='PersonalDeposit';
  3786. // }
  3787. // if (empty($abDetail)){
  3788. // $item = array (
  3789. // 'dataID' => $detail ['iid'],
  3790. // 'expensesType' => 1,
  3791. // 'accountType' => 8,
  3792. // 'accountPriceShow'=>$detail ['invoicePrice'],
  3793. // 'accountPrice'=>$detail ['invoicePrice'],
  3794. // 'accountBank'=>$accountBank,
  3795. // 'category'=>$this->staff[0]['category'],
  3796. // 'cid'=>$this->staff[0]['cid'],
  3797. // 'name'=>$this->staff[0]['username'],
  3798. // 'sid'=>$this->staff[0]['sid'],
  3799. // 'inputDate'=>date ( "Y-m-d H:i:s" )
  3800. // );
  3801. // $wasteBook->setAccountBookStatistics($item);
  3802. // }
  3803. return "/invoiceReceivables";
  3804. }
  3805. /**
  3806. * 核销 动作,确认入账统计 发票收款完成--需求更变 废弃 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"; }
  3807. */
  3808. function invoiceAggregate() {
  3809. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3810. Doo::loadModel ( 'invoiceStatistics' );
  3811. $invoiceStatistics = new invoiceStatistics ();
  3812. Doo::loadModel ( 'L_category' );
  3813. $Lcategory = new L_category ();
  3814. $isList = $invoiceStatistics->getInvoiceStatisticsByYear ( $year );
  3815. $LcategoryList = $Lcategory->getCategory ();
  3816. // print_r($isList);
  3817. $html = ""; // $invoicePriceCategory=0;$receivablesPriceCategory=0;$accountPriceCategory=0;
  3818. foreach ( $LcategoryList as $key => $value ) {
  3819. $html .= '<tr><th><a href="/invoiceAggregateCategory/' . $value ['cidKey'] . '">' . $value ['title'] . '</a></th>';
  3820. $month = 1;
  3821. $invoicePriceYear = 0;
  3822. $receivablesPriceYear = 0;
  3823. $accountPriceYear = 0;
  3824. for(; $month <= 12; $month ++) {
  3825. $flag = true;
  3826. foreach ( $isList ['statisticsMonthCid'] as $k => $v ) {
  3827. if ($value ['cid'] == $v ['cid'] && $month == $v ['month']) {
  3828. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  3829. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  3830. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  3831. ';
  3832. $invoicePriceYear += $v ['invoicePrice'];
  3833. $receivablesPriceYear += $v ['receivablesPrice'];
  3834. $accountPriceYear += $v ['accountPrice'];
  3835. $flag = false;
  3836. break;
  3837. }
  3838. }
  3839. if ($flag)
  3840. $html .= '<td class="taR"></td>
  3841. <td class="taR"></td>
  3842. <td class="taR"><b></b></td>
  3843. ';
  3844. }
  3845. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  3846. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  3847. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  3848. ';
  3849. $html .= '</tr>';
  3850. }
  3851. $html .= '<tr><th><b class="colGreen">月合计</b></th>';
  3852. $invoicePriceYear = 0;
  3853. $receivablesPriceYear = 0;
  3854. $accountPriceYear = 0;
  3855. for($month = 1; $month <= 12; $month ++) {
  3856. $flag = true;
  3857. foreach ( $isList ['statisticsMonth'] as $k => $v ) {
  3858. if ($month == $v ['month']) {
  3859. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  3860. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  3861. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  3862. ';
  3863. $invoicePriceYear += $v ['invoicePrice'];
  3864. $receivablesPriceYear += $v ['receivablesPrice'];
  3865. $accountPriceYear += $v ['accountPrice'];
  3866. $flag = false;
  3867. break;
  3868. }
  3869. }
  3870. if ($flag) {
  3871. $html .= '<td class="taR"></td>
  3872. <td class="taR"></td>
  3873. <td class="taR"><b></b></td>
  3874. ';
  3875. }
  3876. }
  3877. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  3878. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  3879. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  3880. ';
  3881. $html .= '</tr>';
  3882. // print_r($isList);
  3883. $this->data ['html'] = $html;
  3884. $this->data ['LcategoryList'] = $LcategoryList;
  3885. $this->data ['isList'] = $isList;
  3886. $this->data ['year'] = $year;
  3887. $this->data ['memu'] = "invoice";
  3888. $this->data ['staff'] = $this->staff;
  3889. $this->data ['receiptMemu'] = 'invoiceAggregate';
  3890. $this->render ( "/admin/invoiceAggregate", $this->data );
  3891. }
  3892. function invoiceAggregateStaff() {
  3893. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3894. Doo::loadModel ( 'invoiceStatistics' );
  3895. $invoiceStatistics = new invoiceStatistics ();
  3896. Doo::loadModel ( 'L_category' );
  3897. $Lcategory = new L_category ();
  3898. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year );
  3899. $staffList = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year );
  3900. $cStaff = $Lcategory->getCategoryStaff ();
  3901. $html = '';
  3902. foreach ( $cStaff as $key => $value ) {
  3903. $categoryFir = true;
  3904. foreach ( $value ['staff'] as $k => $v ) {
  3905. if ($categoryFir) {
  3906. $width = count ( $value ['staff'] ) + 1;
  3907. $html .= '<tr><th rowspan="' . $width . '">' . $value ['title'] . ' </th>';
  3908. $categoryFir = false;
  3909. } else
  3910. $html .= '<tr>';
  3911. $html .= '<th>' . $v ['username'] . '</th>';
  3912. $invoicePriceStaffYear = 0;
  3913. $receivablesPriceStaffYear = 0;
  3914. $accountPriceStaffYear = 0;
  3915. for($month = 1; $month <= 12; $month ++) {
  3916. $flag = true;
  3917. foreach ( $staffList ['statisticsMonthStaff'] as $sl => $slv ) {
  3918. if ($v ['sid'] == $slv ['staff'] && $month == $slv ['month']) {
  3919. $html .= '<td class="taR">¥' . $slv ['invoicePrice'] . '</td>
  3920. <td class="taR">¥' . $slv ['receivablesPrice'] . '</td>
  3921. <td class="taR"><b>¥' . $slv ['accountPrice'] . '</b></td>
  3922. ';
  3923. $invoicePriceStaffYear += $slv ['invoicePrice'];
  3924. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  3925. $accountPriceStaffYear += $slv ['accountPrice'];
  3926. $flag = false;
  3927. break;
  3928. }
  3929. }
  3930. if ($flag)
  3931. $html .= '<td class="taR"></td>
  3932. <td class="taR"></td>
  3933. <td class="taR"><b></b></td>
  3934. ';
  3935. }
  3936. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  3937. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  3938. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  3939. ';
  3940. }
  3941. $html .= '</tr>';
  3942. // 小计
  3943. if (! empty ( $value ['staff'] )) {
  3944. $html .= '<tr><th class="taR">小计</th>';
  3945. $invoicePriceStaffYear = 0;
  3946. $receivablesPriceStaffYear = 0;
  3947. $accountPriceStaffYear = 0;
  3948. for($month = 1; $month <= 12; $month ++) {
  3949. $flag = true;
  3950. foreach ( $staffList ['statisticsMonthCid'] as $smc => $smcv ) {
  3951. if ($value ['cid'] == $smcv ['cid'] && $month == $slv ['month']) {
  3952. $html .= '<td class="taR">¥' . $smcv ['invoicePrice'] . '</td>
  3953. <td class="taR">¥' . $smcv ['receivablesPrice'] . '</td>
  3954. <td class="taR"><b>¥' . $smcv ['accountPrice'] . '</b></td>
  3955. ';
  3956. $invoicePriceStaffYear += $slv ['invoicePrice'];
  3957. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  3958. $accountPriceStaffYear += $slv ['accountPrice'];
  3959. $flag = false;
  3960. break;
  3961. }
  3962. }
  3963. if ($flag)
  3964. $html .= '<td class="taR"></td>
  3965. <td class="taR"></td>
  3966. <td class="taR"><b></b></td>
  3967. ';
  3968. }
  3969. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  3970. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  3971. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  3972. ';
  3973. $html .= '</tr>';
  3974. }
  3975. }
  3976. $html .= '<tr class="warning"><th colspan="2"><b class="colGreen" >月合计</b></th>';
  3977. $invoicePriceYear = 0;
  3978. $receivablesPriceYear = 0;
  3979. $accountPriceYear = 0;
  3980. for($month = 1; $month <= 12; $month ++) {
  3981. $flag = true;
  3982. foreach ( $staffList ['statisticsMonth'] as $k => $v ) {
  3983. if ($month == $v ['month']) {
  3984. $html .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>
  3985. <td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>
  3986. <td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>
  3987. ';
  3988. $invoicePriceYear += $v ['invoicePrice'];
  3989. $receivablesPriceYear += $v ['receivablesPrice'];
  3990. $accountPriceYear += $v ['accountPrice'];
  3991. $flag = false;
  3992. break;
  3993. }
  3994. }
  3995. if ($flag)
  3996. $html .= '<td class="taR"></td>
  3997. <td class="taR"></td>
  3998. <td class="taR"><b></b></td>
  3999. ';
  4000. }
  4001. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  4002. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  4003. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  4004. ';
  4005. $html .= '</tr>';
  4006. $this->data ['html'] = $html;
  4007. $this->data ['isList'] = $toteList;
  4008. $this->data ['year'] = $year;
  4009. $this->data ['memu'] = "invoice";
  4010. $this->data ['staff'] = $this->staff;
  4011. $this->data ['receiptMemu'] = 'invoiceAggregate';
  4012. $this->render ( "/admin/invoiceAggregateStaff", $this->data );
  4013. }
  4014. function invoiceAggregateCategory() {
  4015. Doo::loadClass ( 'XDeode' );
  4016. $XDeode = new XDeode ( 5 );
  4017. $cid = $cidKey = isset ( $this->params ['cid'] ) ? $this->params ['cid'] : "";
  4018. $cid = $XDeode->decode ( $cid );
  4019. if (! is_numeric ( $cid ))
  4020. die ( 'illegal request' );
  4021. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  4022. Doo::loadModel ( 'invoiceStatistics' );
  4023. $invoiceStatistics = new invoiceStatistics ();
  4024. Doo::loadModel ( 'staff' );
  4025. $staff = new staff ();
  4026. $list = $staff->getStaffByCid ( $cid );
  4027. $isCategory = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year, $cid );
  4028. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year, $cid );
  4029. if (empty ( $list ))
  4030. die ( '该办事处没有成员' );
  4031. $htmlA = $htmlB = $htmlC = $html = '';
  4032. foreach ( $list as $key => $value ) {
  4033. $htmlA = '<tr><th rowspan="3">' . $value ['username'] . '</th><th class="taC">开票</th>';
  4034. $htmlB = '<tr><th class="taC">收款</th>';
  4035. $htmlC = '<tr><th class="taC">入账</th>';
  4036. $invoicePriceStaffYear = 0;
  4037. $receivablesPriceStaffYear = 0;
  4038. $accountPriceStaffYear = 0;
  4039. for($month = 1; $month <= 12; $month ++) {
  4040. $flag = true;
  4041. foreach ( $isCategory ['statisticsMonthStaff'] as $k => $v ) {
  4042. if ($value ['sid'] == $v ['staff'] && $month == $v ['month']) {
  4043. $htmlA .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>';
  4044. $htmlB .= '<td class="taR">¥' . $v ['receivablesPrice'] . '</td>';
  4045. $htmlC .= '<td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>';
  4046. $invoicePriceStaffYear += $v ['invoicePrice'];
  4047. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  4048. $accountPriceStaffYear += $v ['accountPrice'];
  4049. $flag = false;
  4050. break;
  4051. }
  4052. }
  4053. if ($flag) {
  4054. $htmlA .= '<td class="taR">-</td>';
  4055. $htmlB .= '<td class="taR">-</td>';
  4056. $htmlC .= '<td class="taR"><b>-</b></td>';
  4057. }
  4058. }
  4059. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  4060. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  4061. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  4062. $htmlA .= '</tr>';
  4063. $htmlB .= '</tr>';
  4064. $htmlC .= '</tr>';
  4065. $html .= $htmlA . $htmlB . $htmlC;
  4066. }
  4067. $htmlA = $htmlB = $htmlC = "";
  4068. $htmlA = '<tr><th rowspan="3">月合计</th><th class="taC">开票</th>';
  4069. $htmlB = '<tr><th class="taC">收款</th>';
  4070. $htmlC = '<tr><th class="taC">入账</th>';
  4071. $invoicePriceStaffYear = 0;
  4072. $receivablesPriceStaffYear = 0;
  4073. $accountPriceStaffYear = 0;
  4074. for($month = 1; $month <= 12; $month ++) {
  4075. $flag = true;
  4076. foreach ( $isCategory ['statisticsMonth'] as $k => $v ) {
  4077. if ($month == $v ['month']) {
  4078. $htmlA .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>';
  4079. $htmlB .= '<td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>';
  4080. $htmlC .= '<td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>';
  4081. $invoicePriceStaffYear += $v ['invoicePrice'];
  4082. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  4083. $accountPriceStaffYear += $v ['accountPrice'];
  4084. $flag = false;
  4085. break;
  4086. }
  4087. }
  4088. if ($flag) {
  4089. $htmlA .= '<td class="taR">-</td>';
  4090. $htmlB .= '<td class="taR">-</td>';
  4091. $htmlC .= '<td class="taR"><b>-</b></td>';
  4092. }
  4093. }
  4094. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  4095. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  4096. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  4097. $htmlA .= '</tr>';
  4098. $htmlB .= '</tr>';
  4099. $htmlC .= '</tr>';
  4100. $html .= $htmlA . $htmlB . $htmlC;
  4101. $this->data ['html'] = $html;
  4102. $this->data ['cidKey'] = $cidKey;
  4103. $this->data ['slist'] = $list;
  4104. $this->data ['isList'] = $toteList;
  4105. $this->data ['year'] = $year;
  4106. $this->data ['memu'] = "invoice";
  4107. $this->data ['staff'] = $this->staff;
  4108. $this->data ['receiptMemu'] = 'invoiceAggregate';
  4109. $this->render ( "/admin/invoiceAggregateCategory", $this->data );
  4110. }
  4111. /**
  4112. * 办事处汇总信息
  4113. */
  4114. function invoiceAggregateCategoryDetail() {
  4115. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  4116. Doo::loadClass ( 'XDeode' );
  4117. $XDeode = new XDeode ( 5 );
  4118. Doo::loadModel ( 'invoiceStatistics' );
  4119. $invoiceStatistics = new invoiceStatistics ();
  4120. Doo::loadModel ( 'L_category' );
  4121. $category = new L_category ();
  4122. Doo::loadModel ( 'invoice' );
  4123. $invoice = new invoice ();
  4124. Doo::loadModel ( 'staff' );
  4125. $staff = new staff ();
  4126. Doo::loadModel ( "invoiceCategoryManage" );
  4127. $invoiceCategoryManage = new invoiceCategoryManage ();
  4128. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4129. $cidList = array ();
  4130. foreach ( $imcStaff as $key => $value ) {
  4131. array_push ( $cidList, $value ['cid'] );
  4132. if (empty ( $cidKey ))
  4133. $cidKey = $XDeode->encode ( $value ['cid'] );
  4134. }
  4135. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  4136. $cid = $XDeode->decode ( $cidKey );
  4137. $month = date ( "m", strtotime ( "-1 month" ) );
  4138. $YearMonth = date ( "Y-m", strtotime ( "-1 month" ) );
  4139. $redis = new Redis ();
  4140. $redis->connect ( '127.0.0.1', '6379' );
  4141. $redisKey = ''; // date('Y-m-d').'_iacd_'.$cid;
  4142. $redisValue = ''; // $redis->lrange($redisKey, 0, -1);
  4143. if (empty ( $redisValue )) {
  4144. $isMC = $invoiceStatistics->getInvoiceStatistiscsMothByCategory ( $cid );
  4145. $schedule = $invoice->getInvoiceScheduleByCid ( $cid );
  4146. // 获得办事处人员下的汇总
  4147. $slist = $staff->getStaffByCid ( $cid );
  4148. $ismsbMonth = $invoiceStatistics->getISMSByCategoryByMonth ( $cid, $YearMonth ); // 上一个月的汇总
  4149. $ismsb = $invoiceStatistics->getISMSByCategory ( $cid ); // 当月汇总
  4150. $ISAS = $invoiceStatistics->getISASByCategory ( $cid ); // 全部汇总
  4151. $scheduleStaff = $invoice->getInvoiceScheduleByCidGroupSid ( $cid ); // 完成度
  4152. foreach ( $slist as $key => $value ) {
  4153. $slist [$key] ['invoicePrice'] = 0;
  4154. $slist [$key] ['receivablesPrice'] = 0;
  4155. $slist [$key] ['accountPrice'] = 0;
  4156. $slist [$key] ['invoiceAllPrice'] = 0;
  4157. $slist [$key] ['receivablesAllPrice'] = 0;
  4158. $slist [$key] ['accountAllPrice'] = 0;
  4159. $slist [$key] ['schedule'] = 0;
  4160. $slist [$key] ['invoiceMonthPrice'] = 0;
  4161. $slist [$key] ['receivablesMonthPrice'] = 0;
  4162. $slist [$key] ['accountMonthPrice'] = 0;
  4163. foreach ( $ismsbMonth as $y => $l ) {
  4164. if ($value ['sid'] == $l ['staff']) {
  4165. $slist [$key] ['invoiceMonthPrice'] = $l ['invoicePrice'];
  4166. $slist [$key] ['receivablesMonthPrice'] = $l ['receivablesPrice'];
  4167. $slist [$key] ['accountMonthPrice'] = $l ['accountPrice'];
  4168. }
  4169. }
  4170. foreach ( $ismsb as $k => $v ) {
  4171. if ($value ['sid'] == $v ['staff']) {
  4172. $slist [$key] ['invoicePrice'] = $v ['invoicePrice'];
  4173. $slist [$key] ['receivablesPrice'] = $v ['receivablesPrice'];
  4174. $slist [$key] ['accountPrice'] = $v ['accountPrice'];
  4175. }
  4176. }
  4177. foreach ( $ISAS as $e => $a ) {
  4178. if ($value ['sid'] == $a ['staff']) {
  4179. $slist [$key] ['invoiceAllPrice'] = $a ['invoicePrice'];
  4180. $slist [$key] ['receivablesAllPrice'] = $a ['receivablesPrice'];
  4181. $slist [$key] ['accountAllPrice'] = $a ['accountPrice'];
  4182. }
  4183. }
  4184. if (isset ( $scheduleStaff [$value ['sid']] ))
  4185. $slist [$key] ['schedule'] = $scheduleStaff [$value ['sid']];
  4186. }
  4187. $this->data ['cidKey'] = $cidKey;
  4188. $schedule = ( int ) ($schedule * 100);
  4189. $this->data ['slist'] = $slist;
  4190. $this->data ['isMC'] = $isMC;
  4191. $this->data ['schedule'] = $schedule;
  4192. $slist = json_encode ( $slist );
  4193. $isMC = json_encode ( $isMC );
  4194. $schedule = json_encode ( $schedule );
  4195. $redis->lpush ( $redisKey, $slist );
  4196. $redis->lpush ( $redisKey, $isMC );
  4197. $redis->lpush ( $redisKey, $schedule );
  4198. } else {
  4199. $this->data ['cidKey'] = $cidKey;
  4200. $this->data ['slist'] = json_decode ( $redisValue [2], true );
  4201. $this->data ['isMC'] = json_decode ( $redisValue [1], true );
  4202. $this->data ['schedule'] = json_decode ( $redisValue [0], true );
  4203. }
  4204. $this->data ['month'] = $month;
  4205. $this->data ['categoryList'] = $categoryList;
  4206. $this->data ['memu'] = "invoice";
  4207. $this->data ['staff'] = $this->staff;
  4208. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4209. $this->render ( "/admin/invoiceAggregateCategoryDetail", $this->data );
  4210. }
  4211. /**
  4212. * 办事处人员汇总详情
  4213. */
  4214. function invoiceAggregateStaffDetail() {
  4215. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  4216. // $sidKey = isset ( $this->params ['sidKey'] ) ? $this->params ['sidKey'] : '';
  4217. Doo::loadClass ( 'XDeode' );
  4218. $XDeode = new XDeode ( 5 );
  4219. Doo::loadModel ( 'invoice' );
  4220. $invoice = new invoice ();
  4221. Doo::loadModel ( 'staff' );
  4222. $staff = new staff ();
  4223. Doo::loadModel ( "invoiceCategoryManage" );
  4224. $invoiceCategoryManage = new invoiceCategoryManage ();
  4225. $sid = $XDeode->decode ( $sidKey );
  4226. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4227. $cidList = array ();
  4228. foreach ( $imcStaff as $key => $value ) {
  4229. array_push ( $cidList, $value ['cid'] );
  4230. if (empty ( $cidKey ))
  4231. $cidKey = $XDeode->encode ( $value ['cid'] );
  4232. }
  4233. $cidString = implode ( ',', $cidList );
  4234. $staffList = $staff->getStaffInCid ( $cidString );
  4235. $staffDetail = $staff->getStaffBySid ( $sid );
  4236. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4237. $page_size = 18;
  4238. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4239. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4240. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  4241. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  4242. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  4243. $dateArr = explode ( ':', $date );
  4244. $D1 = '';
  4245. $D2 = '';
  4246. if (! empty ( $date )) {
  4247. $D1 = $dateArr [0] . " 00:00:00 ";
  4248. if (isset ( $dateArr [1] ))
  4249. $D2 = $dateArr [1] . " 23:59:59 ";
  4250. else
  4251. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4252. // $D2 = $dateArr [1];
  4253. }
  4254. $con = ' status=2 ';
  4255. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4256. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4257. if ($status == 'UNRECORD')
  4258. $con .= ' and printStatus=1 and untreadStatus=0';
  4259. elseif ($status == 'RECORD')
  4260. $con .= ' and printStatus=1 and untreadStatus=3';
  4261. elseif ($status == 'BOUNCED')
  4262. $con .= ' and untreadStatus=2';
  4263. elseif ($status == 'PARTRECORD')
  4264. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  4265. elseif ($status == 'All') {
  4266. $con .= ' and ( untreadStatus=2 or untreadStatus=0 or untreadStatus=3 )';
  4267. }
  4268. $con .= ' and sid=' . $sid;
  4269. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  4270. if (! empty ( $MebSea )) {
  4271. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  4272. }
  4273. $pageinfo ['page'] = array (
  4274. 'previous' => ''
  4275. );
  4276. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateStaffDetail", $get, "" );
  4277. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4278. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  4279. $this->data ['staffDetail'] = $staffDetail;
  4280. $this->data ['staffList'] = $staffList;
  4281. $this->data ['MebSeaEn'] = $MebSea;
  4282. $this->data ['MebSea'] = urlencode ( $MebSea );
  4283. $this->data ['date'] = $date;
  4284. $this->data ['page'] = $pageinfo;
  4285. $this->data ['get'] = $get;
  4286. $this->data ['list'] = $list;
  4287. $this->data ['status'] = $status;
  4288. $this->data ['sidKey'] = $sidKey;
  4289. $this->data ['memu'] = "invoice";
  4290. $this->data ['staff'] = $this->staff;
  4291. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4292. $this->render ( "/admin/invoiceAggregateStaffDetail", $this->data );
  4293. }
  4294. /**
  4295. * 办事处人员汇总收款情
  4296. */
  4297. function invoiceAggregateStaffReceivablesDetail() {
  4298. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  4299. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  4300. Doo::loadModel ( 'invoiceReceivables' );
  4301. $invoiceReceivables = new invoiceReceivables ();
  4302. Doo::loadModel ( 'staff' );
  4303. $staff = new staff ();
  4304. Doo::loadModel ( "invoiceCategoryManage" );
  4305. $invoiceCategoryManage = new invoiceCategoryManage ();
  4306. Doo::loadClass ( 'XDeode' );
  4307. $XDeode = new XDeode ( 5 );
  4308. $sid = $XDeode->decode ( $sidKey );
  4309. $staffDetail = $staff->getStaffBySid ( $sid );
  4310. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4311. $cidList = array ();
  4312. foreach ( $imcStaff as $key => $value ) {
  4313. array_push ( $cidList, $value ['cid'] );
  4314. if (empty ( $cidKey ))
  4315. $cidKey = $XDeode->encode ( $value ['cid'] );
  4316. }
  4317. $cidString = implode ( ',', $cidList );
  4318. $staffList = $staff->getStaffInCid ( $cidString );
  4319. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4320. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  4321. $page_size = 10;
  4322. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4323. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4324. if ($timeType == "BINDOTP") {
  4325. $status = 'Credited';
  4326. }
  4327. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  4328. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  4329. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  4330. $dateArr = explode ( ':', $date );
  4331. $D1 = '';
  4332. $D2 = '';
  4333. if (! empty ( $date )) {
  4334. $D1 = $dateArr [0] . " 00:00:00 ";
  4335. if (isset ( $dateArr [1] ))
  4336. $D2 = $dateArr [1] . " 23:59:59 ";
  4337. else
  4338. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4339. }
  4340. $con = ' a.receivablesStaff like "%' . $staffDetail ['username'] . '%" ';
  4341. $descField = 'a.bindDate';
  4342. if ($timeType == 'CREATE')
  4343. $descField = 'a.date';
  4344. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4345. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4346. elseif (! empty ( $D1 ) && empty ( $D2 ))
  4347. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  4348. if ($status == 'Unclaimed')
  4349. $con .= ' and a.bindStatus=0';
  4350. elseif ($status == 'Credited')
  4351. $con .= ' and a.bindStatus=1';
  4352. elseif ($status == 'Claim')
  4353. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  4354. elseif ($status == 'BBN')
  4355. $con .= ' and a.bindPrice>a.receivablesPrice';
  4356. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  4357. if (! empty ( $MebSea )) {
  4358. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" )';
  4359. }
  4360. $pageinfo ['page'] = array (
  4361. 'previous' => ''
  4362. );
  4363. $sql = 'select group_concat(b.invoiceSerial) as invoiceSerial ,group_concat(b.iid) as invoiceId
  4364. from CLD_invoiceReceivables as a left join CLD_invoice as b on
  4365. find_in_set(b.iid,a.iidExtend) or a.iid=b.iid
  4366. where ' . $con . ' group by a.irid ';
  4367. $pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceAggregateStaffReceivablesDetail", $get, "" );
  4368. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4369. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', 'printTime' );
  4370. foreach ( $list as $key => $value ) {
  4371. $list [$key] ['category'] = '';
  4372. if ($value ['receivablesCategory'] != 'PUBLIC') {
  4373. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  4374. $list [$key] ['category'] = $receivablesCategory [1];
  4375. }
  4376. }
  4377. // print_r($list);
  4378. $this->data ['staffDetail'] = $staffDetail;
  4379. $this->data ['sidKey'] = $sidKey;
  4380. $this->data ['staffList'] = $staffList;
  4381. $this->data ['timeType'] = $timeType;
  4382. $this->data ['MebSeaEn'] = $MebSea;
  4383. $this->data ['MebSea'] = urlencode ( $MebSea );
  4384. $this->data ['date'] = $date;
  4385. $this->data ['page'] = $pageinfo;
  4386. $this->data ['get'] = $get;
  4387. $this->data ['list'] = $list;
  4388. $this->data ['status'] = $status;
  4389. $this->data ['memu'] = "invoice";
  4390. $this->data ['staff'] = $this->staff;
  4391. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4392. $this->render ( "/admin/invoiceAggregateStaffReceivablesDetail", $this->data );
  4393. }
  4394. function invoiceAchieve() {
  4395. Doo::loadModel ( 'invoice' );
  4396. $invoice = new invoice ();
  4397. Doo::loadClass ( 'XDeode' );
  4398. $XDeode = new XDeode ( 5 );
  4399. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4400. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4401. $page_size = 18;
  4402. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4403. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4404. $get = "/" . $date;
  4405. $con = '';
  4406. if ($date == 'MONTHO')
  4407. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4408. elseif ($date == 'MONTHT')
  4409. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4410. elseif ($date == 'MONTHY')
  4411. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4412. if (! empty ( $MebSea )) {
  4413. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4414. $get .= "/" . $MebSea;
  4415. }
  4416. $pageinfo ['page'] = array (
  4417. 'previous' => ''
  4418. );
  4419. $sql = 'status=2 and printStatus=1 and irid!="" and ( untreadStatus=3 or untreadStatus=0 ) and sid=' . $sid . $con;
  4420. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceAchieve", $get, "" );
  4421. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4422. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  4423. // print_r($pageinfo);
  4424. $this->data ['MebSeaEn'] = $MebSea;
  4425. $this->data ['MebSea'] = urlencode ( $MebSea );
  4426. $this->data ['get'] = $get;
  4427. $this->data ['page'] = $pageinfo;
  4428. $this->data ['list'] = $list;
  4429. $this->data ['date'] = $date;
  4430. $this->data ['memu'] = "invoice";
  4431. $this->data ['staff'] = $this->staff;
  4432. $this->data ['receiptMemu'] = 'invoice';
  4433. $this->render ( "/admin/invoiceAchieve", $this->data );
  4434. }
  4435. /**
  4436. */
  4437. function invoiceMyUnAccountAchieve() {
  4438. Doo::loadModel ( 'invoice' );
  4439. $invoice = new invoice ();
  4440. Doo::loadClass ( 'XDeode' );
  4441. $XDeode = new XDeode ( 5 );
  4442. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4443. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4444. $page_size = 18;
  4445. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4446. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4447. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4448. $dateArr = explode ( ':', $date );
  4449. $D1 = '';
  4450. $D2 = '';
  4451. if (! empty ( $date )) {
  4452. $D1 = $dateArr [0];
  4453. $D2 = $dateArr [1];
  4454. }
  4455. $con = '';
  4456. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4457. $con = ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4458. if (! empty ( $MebSea )) {
  4459. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4460. }
  4461. $pageinfo ['page'] = array (
  4462. 'previous' => ''
  4463. );
  4464. // and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  4465. $sql = " status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid= " . $sid . $con;
  4466. $action = "invoiceMyUnAccountAchieve";
  4467. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  4468. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4469. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 'desc', 'printTime' );
  4470. Doo::loadModel ( 'express' );
  4471. $express = new express ();
  4472. $expressList = $express->getExpressByAll ();
  4473. $this->data ['expressList'] = $expressList;
  4474. // print_r($list);
  4475. $this->data ['MebSeaEn'] = $MebSea;
  4476. $this->data ['get'] = $get;
  4477. $this->data ['page'] = $pageinfo;
  4478. $this->data ['date'] = $date;
  4479. $this->data ['list'] = $list;
  4480. $this->data ['memu'] = "invoice";
  4481. $this->data ['staff'] = $this->staff;
  4482. $this->data ['receiptMemu'] = 'invoice';
  4483. $this->render ( "/admin/invoiceMyUnAccountAchieve", $this->data );
  4484. }
  4485. function invoiceReceivablesAchieve() {
  4486. Doo::loadModel ( 'invoiceReceivables' );
  4487. $invoiceReceivables = new invoiceReceivables ();
  4488. Doo::loadClass ( 'XDeode' );
  4489. $XDeode = new XDeode ( 5 );
  4490. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4491. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  4492. $page_size = 12;
  4493. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4494. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4495. $get = "/" . $date;
  4496. $con = '';
  4497. if ($date == 'MONTHO')
  4498. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4499. elseif ($date == 'MONTHT')
  4500. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4501. elseif ($date == 'MONTHY')
  4502. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4503. if (! empty ( $MebSea )) {
  4504. $con .= ' and ( receivablesMessage like "%' . $MebSea . '%" or receivablesPrice like "%' . $MebSea . '%" )';
  4505. $get .= "/" . $MebSea;
  4506. }
  4507. $pageinfo ['page'] = array (
  4508. 'previous' => ''
  4509. );
  4510. $sql = " bindStatus=1 and receivablesStaff like '" . $sid . "-%' " . $con;
  4511. $pageinfo = $this->get_page ( "CLD_invoiceReceivables", $sql, $page, $page_size, "invoiceReceivablesAchieve", $get, "" );
  4512. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4513. $list = $invoiceReceivables->getReceivablesByUntreadStatusPage ( $limit, $sql );
  4514. // print_r($pageinfo);
  4515. $this->data ['MebSeaEn'] = $MebSea;
  4516. $this->data ['MebSea'] = urlencode ( $MebSea );
  4517. $this->data ['get'] = $get;
  4518. $this->data ['page'] = $pageinfo;
  4519. $this->data ['list'] = $list;
  4520. $this->data ['date'] = $date;
  4521. $this->data ['memu'] = "invoice";
  4522. $this->data ['staff'] = $this->staff;
  4523. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  4524. $this->render ( "/admin/invoiceReceivablesAchieve", $this->data );
  4525. }
  4526. /**
  4527. * 收款解绑
  4528. */
  4529. function invoiceUnBundLing() {
  4530. $unBundKey = $this->get_args ( 'unBundKey' ) ? $this->get_args ( 'unBundKey' ) : '';
  4531. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  4532. Doo::loadModel ( 'invoice' );
  4533. $invoice = new invoice ();
  4534. Doo::loadModel ( 'invoiceReceivables' );
  4535. $invoiceReceivables = new invoiceReceivables ();
  4536. Doo::loadModel ( 'invoiceOperationLog' );
  4537. $invoiceOperationLog = new invoiceOperationLog ();
  4538. Doo::loadModel ( 'invoiceROLog' );
  4539. $invoiceROLog = new invoiceROLog ();
  4540. Doo::loadModel ( 'invoiceStatistics' );
  4541. Doo::loadClass ( 'XDeode' );
  4542. $XDeode = new XDeode ( 5 );
  4543. if (empty ( $iidKey ) || empty ( $unBundKey ))
  4544. die ( 'illegal request' );
  4545. $iid = $XDeode->decode ( $iidKey );
  4546. $irid = $invoice->authcode ( $unBundKey );
  4547. if ((! empty ( $irid ) && ! is_numeric ( $irid )) || (! empty ( $iid ) && ! is_numeric ( $iid )))
  4548. die ( 'illegal request' );
  4549. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4550. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  4551. if (empty ( $irDetails ) || empty ( $invoiceDetails ) || (empty ( $irDetails ['iid'] ) && empty ( $irDetails ['iidExtend'] )) || $invoiceDetails ['untreadStatus'] == 2)
  4552. die ( 'illegal request' );
  4553. // 收款
  4554. $item = array (
  4555. 'irid' => $irDetails ['irid'],
  4556. 'bindPrice' => $irDetails ['bindPrice'] - $invoiceDetails ['invoicePrice'],
  4557. 'bindStatus' => 0
  4558. );
  4559. if ($irDetails ['iid'] == $iid)
  4560. $item += array (
  4561. 'iid' => 0
  4562. );
  4563. else {
  4564. $iidExtend = explode ( ',', $irDetails ['iidExtend'] );
  4565. foreach ( $iidExtend as $key => $value ) {
  4566. if ($value == $iid)
  4567. unset ( $iidExtend [$key] );
  4568. }
  4569. $iidExtend = implode ( ',', $iidExtend );
  4570. $item += array (
  4571. 'iidExtend' => $iidExtend
  4572. );
  4573. }
  4574. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4575. // 收款操作日志
  4576. $item = array (
  4577. 'operation' => $this->staff [0] ['username'] . " 解绑 " . $irDetails ['receivablesSerial'],
  4578. 'date' => date ( "Y-m-d" ),
  4579. 'status' => 3,
  4580. 'img' => $this->staff [0] ['avatar'],
  4581. 'username' => $this->staff [0] ['username'],
  4582. 'uid' => $this->staff [0] ['sid'],
  4583. 'category' => $this->staff [0] ['category'],
  4584. 'irid' => $irid
  4585. );
  4586. $invoiceROLog->setInvoiceROLog ( $item );
  4587. // 扣除入账统计金额
  4588. $invoiceStatistics = new invoiceStatistics ();
  4589. $item = array (
  4590. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  4591. 'priceClass' => 3,
  4592. 'cid' => $invoiceDetails ['cid'],
  4593. 'staff' => $invoiceDetails ['sid'],
  4594. 'accountPrice' => - $irDetails ['receivablesPrice']
  4595. );
  4596. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4597. // 扣除收款统计金额
  4598. $invoiceStatistics = new invoiceStatistics ();
  4599. $item = array (
  4600. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  4601. 'priceClass' => 2,
  4602. 'cid' => $invoiceDetails ['cid'],
  4603. 'staff' => $invoiceDetails ['sid'],
  4604. 'irid' => $irDetails ['irid'],
  4605. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  4606. );
  4607. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4608. // 发票解绑去收款ID
  4609. $iridString = $invoiceDetails ['irid'];
  4610. if (! empty ( $invoiceDetails ['irid'] )) {
  4611. $list = explode ( ',', $invoiceDetails ['irid'] );
  4612. foreach ( $list as $key => $value ) {
  4613. if ($value == $irDetails ['irid']) {
  4614. unset ( $list [$key] );
  4615. break;
  4616. }
  4617. }
  4618. $iridString = implode ( ",", $list );
  4619. }
  4620. $item = array (
  4621. 'iid' => $invoiceDetails ['iid'],
  4622. 'irid' => $iridString,
  4623. 'updateTime' => date ( "Y-m-d H:i:s" )
  4624. );
  4625. if ($invoiceDetails ['untreadStatus'] == 3)
  4626. $item += array (
  4627. 'untreadStatus' => 0
  4628. );
  4629. $invoice->setInvoiceByCondition ( $item );
  4630. $item = array (
  4631. 'date' => date ( "Y-m-d H:i:s" ),
  4632. 'operation' => '解绑 收款 ' . $irDetails ['receivablesSerial'],
  4633. 'status' => 11,
  4634. 'img' => $this->staff [0] ['avatar'],
  4635. 'username' => $this->staff [0] ['username'],
  4636. 'uid' => $this->staff [0] ['sid'],
  4637. 'category' => $this->staff [0] ['category'],
  4638. 'iid' => $invoiceDetails ['iid']
  4639. );
  4640. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  4641. // 公司流水-解绑时删除流水
  4642. Doo::loadModel ( 'wasteBook' );
  4643. $wasteBook = new wasteBook ();
  4644. // $wasteBook->delete ( array (
  4645. // 'where' => 'dataID=' . $irDetails ['irid'] . ' and accountType=7',
  4646. // 'limit' => 1
  4647. // ) );
  4648. // 银行
  4649. /*
  4650. * $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); }
  4651. */
  4652. return "/invoiceReceivablesAS";
  4653. }
  4654. /**
  4655. * 或者该收款下的所以发票
  4656. */
  4657. function ajaxGetInvoiceReceivablesByInvoice() {
  4658. $irid = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : '';
  4659. Doo::loadModel ( 'invoice' );
  4660. $invoice = new invoice ();
  4661. Doo::loadModel ( 'invoiceReceivables' );
  4662. $invoiceReceivables = new invoiceReceivables ();
  4663. $irid = $invoice->authcode ( $irid );
  4664. if (! empty ( $irid ) && ! is_numeric ( $irid ))
  4665. die ( 'illegal request' );
  4666. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4667. $iidString = $irDetails ['iid'];
  4668. $iidExtend = array_filter ( explode ( ',', $irDetails ['iidExtend'] ) );
  4669. if (! empty ( $irDetails ['iidExtend'] ))
  4670. $iidString .= ',' . implode ( ',', $iidExtend );
  4671. $invoiceList = $invoice->getInvoiceInIid ( $iidString, 'iid,invoiceSerial,invoicePrice,invoiceTitle,invoiceCompany,invoiceElement' );
  4672. $html = "";
  4673. foreach ( $invoiceList as $key => $value ) {
  4674. $title = $value ['invoiceTitle'];
  4675. if (! empty ( $value ['invoiceCompany'] ))
  4676. $title = $value ['invoiceCompany'];
  4677. $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>';
  4678. }
  4679. echo json_encode ( array (
  4680. 'status' => 1,
  4681. 'html' => $html
  4682. ) );
  4683. }
  4684. /**
  4685. * 发票管理
  4686. */
  4687. function invoiceAS() {
  4688. Doo::loadModel ( 'invoice' );
  4689. $invoice = new invoice ();
  4690. Doo::loadModel ( 'invoiceReceivables' );
  4691. $invoiceReceivables = new invoiceReceivables ();
  4692. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4693. $page_size = 18;
  4694. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4695. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4696. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4697. $dateArr = explode ( ':', $date );
  4698. $D1 = '';
  4699. $D2 = '';
  4700. if (! empty ( $date )) {
  4701. $D1 = $dateArr [0] . " 00:00:00 ";
  4702. if (isset ( $dateArr [1] ))
  4703. $D2 = $dateArr [1] . " 23:59:59 ";
  4704. else
  4705. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4706. // $D2 = $dateArr [1];
  4707. }
  4708. $con = ' status=2 ';
  4709. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4710. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4711. if ($status == 'UNRECORD')
  4712. $con .= ' and printStatus=1 and untreadStatus=0';
  4713. elseif ($status == 'RECORD')
  4714. $con .= ' and printStatus=1 and untreadStatus=3';
  4715. elseif ($status == 'BOUNCED')
  4716. $con .= ' and untreadStatus=2';
  4717. elseif ($status == 'PARTRECORD')
  4718. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  4719. elseif ($status == 'All') {
  4720. $con .= ' and ( untreadStatus=2 or untreadStatus=1 or untreadStatus=0 or untreadStatus=3 )';
  4721. }
  4722. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4723. if (! empty ( $MebSea )) {
  4724. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  4725. }
  4726. $pageinfo ['page'] = array (
  4727. 'previous' => ''
  4728. );
  4729. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAS", $get, "" );
  4730. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4731. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  4732. $this->data ['MebSeaEn'] = $MebSea;
  4733. $this->data ['MebSea'] = urlencode ( $MebSea );
  4734. $this->data ['date'] = $date;
  4735. $this->data ['page'] = $pageinfo;
  4736. $this->data ['get'] = $get;
  4737. $this->data ['list'] = $list;
  4738. $this->data ['status'] = $status;
  4739. $this->data ['memu'] = "invoice";
  4740. $this->data ['staff'] = $this->staff;
  4741. $this->data ['receiptMemu'] = 'invoiceReceivables';
  4742. $this->render ( "/admin/invoiceAS", $this->data );
  4743. }
  4744. /**
  4745. * 收款管理
  4746. */
  4747. function invoiceReceivablesAS() {
  4748. Doo::loadModel ( 'invoiceReceivables' );
  4749. $invoiceReceivables = new invoiceReceivables ();
  4750. Doo::loadModel ( 'L_category' );
  4751. $lCategory = new L_category ();
  4752. $category = $lCategory->getCategory ();
  4753. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4754. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  4755. $page_size = 10;
  4756. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4757. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4758. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4759. $dateArr = explode ( ':', $date );
  4760. $D1 = '';
  4761. $D2 = '';
  4762. if (! empty ( $date )) {
  4763. $D1 = $dateArr [0]; // ." 00:00:00 ";
  4764. if (isset ( $dateArr [1] ))
  4765. $D2 = $dateArr [1]; // ." 23:59:59 ";
  4766. else
  4767. $D2 = $dateArr [0]; // ." 23:59:59 ";//date ( "Y-m-d" );
  4768. }
  4769. $descField = 'a.receivablesDate';
  4770. if ($timeType == 'CREATE')
  4771. $descField = 'a.date';
  4772. $con = '1';
  4773. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4774. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4775. elseif (! empty ( $D1 ) && empty ( $D2 ))
  4776. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  4777. if ($status == 'Unclaimed')
  4778. $con .= ' and a.bindStatus=0';
  4779. elseif ($status == 'Credited')
  4780. $con .= ' and a.bindStatus=1';
  4781. elseif ($status == 'Claim')
  4782. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  4783. elseif ($status == 'BBN')
  4784. $con .= ' and a.bankBatchNumber!=""';
  4785. elseif ($status == 'REFUND')
  4786. $con .= ' and ( (a.bindStatus=0 and a.refundLog!="" ) or a.bindStatus=2)';
  4787. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4788. if (! empty ( $MebSea )) {
  4789. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" or a.receivablesSerial like "%' . $MebSea . '%" )';
  4790. }
  4791. $pageinfo ['page'] = array (
  4792. 'previous' => ''
  4793. );
  4794. $sql = 'select group_concat(b.invoiceSerial) as invoiceSerial ,group_concat(b.iid) as invoiceId
  4795. from CLD_invoiceReceivables as a left join CLD_invoice as b on
  4796. find_in_set(b.iid,a.iidExtend) or a.iid=b.iid
  4797. where ' . $con . ' group by a.irid ';
  4798. $pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceReceivablesAS", $get, "" );
  4799. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4800. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', $descField );
  4801. foreach ( $list as $key => $value ) {
  4802. $list [$key] ['category'] = '';
  4803. if ($value ['receivablesCategory'] != 'PUBLIC') {
  4804. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  4805. $list [$key] ['category'] = $receivablesCategory [1];
  4806. }
  4807. }
  4808. // print_r($list);
  4809. $this->data ['category'] = $category;
  4810. $this->data ['timeType'] = $timeType;
  4811. $this->data ['MebSeaEn'] = $MebSea;
  4812. $this->data ['MebSea'] = urlencode ( $MebSea );
  4813. $this->data ['date'] = $date;
  4814. $this->data ['page'] = $pageinfo;
  4815. $this->data ['get'] = $get;
  4816. $this->data ['list'] = $list;
  4817. $this->data ['status'] = $status;
  4818. $this->data ['memu'] = "invoice";
  4819. $this->data ['staff'] = $this->staff;
  4820. $this->data ['receiptMemu'] = 'invoiceReceivables';
  4821. $this->render ( "/admin/invoiceReceivablesAS", $this->data );
  4822. }
  4823. /**
  4824. * 删除一条收款
  4825. */
  4826. function delInvoiceReceivables() {
  4827. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  4828. if (empty ( $iridKey ))
  4829. die ( 'illegal request' );
  4830. Doo::loadClass ( 'XDeode' );
  4831. $XDeode = new XDeode ( 5 );
  4832. $irid = $XDeode->decode ( $iridKey );
  4833. Doo::loadModel ( 'invoiceReceivables' );
  4834. $invoiceReceivables = new invoiceReceivables ();
  4835. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4836. if (empty ( $detail ))
  4837. die ( 'illegal request' );
  4838. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  4839. // 扣除收款汇总信息 汇总
  4840. Doo::loadModel ( 'invoiceStatistics' );
  4841. $invoiceStatistics = new invoiceStatistics ();
  4842. $item = array (
  4843. 'date' => $detail ['receivablesDate'],
  4844. 'priceClass' => 2,
  4845. 'irid' => $detail ['irid'],
  4846. 'receivablesPrice' => - $detail ['receivablesPrice']
  4847. );
  4848. if ($detail ['receivablesCategory'] != 'PUBLIC') {
  4849. $receivablesCategory = explode ( ":", $detail ['receivablesCategory'] );
  4850. $item += array (
  4851. 'cid' => $receivablesCategory [0]
  4852. );
  4853. }
  4854. if ($detail ['receivablesStaff'] != 'PUBLIC') {
  4855. $receivablesStaff = explode ( "-", $detail ['receivablesStaff'] );
  4856. $item += array (
  4857. 'staff' => $receivablesStaff [0]
  4858. );
  4859. }
  4860. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4861. return '/invoiceReceivablesAS';
  4862. }
  4863. /**
  4864. * 添加退款信息
  4865. */
  4866. function setInvoiceReceivablesRefund() {
  4867. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  4868. $refundType = $this->get_args ( 'refundType' ) && is_numeric ( $this->get_args ( 'refundType' ) ) ? $this->get_args ( 'refundType' ) : '0';
  4869. $refundCompany = $this->get_args ( 'refundCompany' ) ? $this->get_args ( 'refundCompany' ) : "";
  4870. $refundNumber = $this->get_args ( 'refundNumber' ) ? $this->get_args ( 'refundNumber' ) : "";
  4871. $refundPrice = $this->get_args ( 'refundPrice' ) ? $this->get_args ( 'refundPrice' ) : "";
  4872. $refundRemarks = $this->get_args ( 'refundRemarks' ) ? $this->get_args ( 'refundRemarks' ) : "";
  4873. if ($refundPrice < 0)
  4874. die ( 'illegal request' );
  4875. if (! empty ( $iridKey ) && ! empty ( $refundCompany ) && ! empty ( $refundNumber ) && ! empty ( $refundPrice )) {
  4876. Doo::loadModel ( 'invoiceReceivables' );
  4877. $invoiceReceivables = new invoiceReceivables ();
  4878. Doo::loadModel ( 'invoiceRefund' );
  4879. $invoiceRefund = new invoiceRefund ();
  4880. $irid = $invoiceReceivables->authcode ( $iridKey );
  4881. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4882. if ($irDetail ['receivablesPrice'] < $refundPrice)
  4883. die ( 'illegal request' );
  4884. $invoiceReceivables = new invoiceReceivables ();
  4885. $refundLog = $this->staff [0] ['username'] . ' 退款 <b class="colRed">¥' . $refundPrice . '</b>
  4886. <br/><a href="#refunded" onclick="getRefundByDetail(\'' . $iridKey . '\')" data-toggle="modal">退款信息</a> <br/>' . date ( "Y-m-d H:i:s" ) . '
  4887. ';
  4888. $item = array (
  4889. 'irid' => $irid,
  4890. 'refundCompany' => $refundCompany,
  4891. 'refundNumber' => $refundNumber,
  4892. 'refundPrice' => $refundPrice,
  4893. 'refundRemarks' => $refundRemarks,
  4894. 'refundLog' => $refundLog
  4895. );
  4896. if ($refundType == 1) {
  4897. $item += array (
  4898. 'refundType' => $refundType,
  4899. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice,
  4900. 'bindStatus' => 2
  4901. );
  4902. } elseif ($refundType == 0 && $irDetail ['receivablesPrice'] <= $refundPrice) {
  4903. $item += array (
  4904. 'refundType' => 1,
  4905. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice,
  4906. 'bindStatus' => 2
  4907. );
  4908. } else {
  4909. $item += array (
  4910. 'refundType' => $refundType,
  4911. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice
  4912. );
  4913. }
  4914. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4915. // 添加退款记录
  4916. $item = array (
  4917. 'irid' => $irid,
  4918. 'refundType' => $refundType,
  4919. 'refundCompany' => $refundCompany,
  4920. 'refundNumber' => $refundNumber,
  4921. 'refundPrice' => $refundPrice,
  4922. 'refundLog' => $refundLog,
  4923. 'refundRemarks' => $refundRemarks,
  4924. 'date' => date ( "Y-m-d H:i:s" )
  4925. );
  4926. $invoiceRefund->addInvoiceRefund ( $item );
  4927. // 扣除收款汇总信息 汇总
  4928. Doo::loadModel ( 'invoiceStatistics' );
  4929. $invoiceStatistics = new invoiceStatistics ();
  4930. $item = array (
  4931. 'date' => $irDetail ['receivablesDate'],
  4932. 'priceClass' => 2,
  4933. 'irid' => $irDetail ['irid'],
  4934. 'receivablesPrice' => - $refundPrice
  4935. );
  4936. if ($irDetail ['receivablesCategory'] != 'PUBLIC') {
  4937. $receivablesCategory = explode ( ":", $irDetail ['receivablesCategory'] );
  4938. $item += array (
  4939. 'cid' => $receivablesCategory [0]
  4940. );
  4941. }
  4942. if ($irDetail ['receivablesStaff'] != 'PUBLIC') {
  4943. $receivablesStaff = explode ( "-", $irDetail ['receivablesStaff'] );
  4944. $item += array (
  4945. 'staff' => $receivablesStaff [0]
  4946. );
  4947. }
  4948. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4949. // 公司日常支出流水
  4950. Doo::loadModel ( 'wasteBook' );
  4951. $wasteBook = new wasteBook ();
  4952. $accountBank = '';
  4953. if ($irDetail ['receivablesBank'] == '纵横广发') {
  4954. $accountBank = 'CGBDeposit';
  4955. } elseif ($irDetail ['receivablesBank'] == '纵横工行') {
  4956. $accountBank = 'ICBCDeposit';
  4957. } elseif ($irDetail ['receivablesBank'] == '华润银行') {
  4958. $accountBank = 'HUADeposit';
  4959. } elseif ($irDetail ['receivablesBank'] == '个人广发') {
  4960. $accountBank = 'PersonalDeposit';
  4961. }
  4962. $itemWaste = array (
  4963. 'accountPrice' => - $refundPrice,
  4964. 'expensesType' => 2,
  4965. 'accountType' => 11,
  4966. 'accountPriceShow' => $refundPrice,
  4967. 'dataID' => $irid,
  4968. 'accountBank' => $accountBank,
  4969. 'category' => $this->staff [0] ['category'],
  4970. 'cid' => $this->staff [0] ['cid'],
  4971. 'name' => $this->staff [0] ['username'],
  4972. 'sid' => $this->staff [0] ['sid'],
  4973. 'inputDate' => date ( "Y-m-d H:i:s" )
  4974. );
  4975. $wasteBook->setAccountBookStatistics ( $itemWaste );
  4976. return '/invoiceReceivablesAS';
  4977. }
  4978. die ( 'illegal request' );
  4979. }
  4980. function ajaxCheckInvoiceReceivablesRefund() {
  4981. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  4982. $refundPrice = $this->get_args ( 'refundPrice' ) ? $this->get_args ( 'refundPrice' ) : "";
  4983. if ($refundPrice < 0) {
  4984. echo json_encode ( array (
  4985. 'error' => '金额不能为负'
  4986. ) );
  4987. die ();
  4988. }
  4989. if (! empty ( $refundPrice ) && ! empty ( $iridKey )) {
  4990. Doo::loadModel ( 'invoiceReceivables' );
  4991. $invoiceReceivables = new invoiceReceivables ();
  4992. $irid = $invoiceReceivables->authcode ( $iridKey );
  4993. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4994. if ($irDetail ['receivablesPrice'] < $refundPrice) {
  4995. echo json_encode ( array (
  4996. 'error' => '退款金额不能超过收款金额'
  4997. ) );
  4998. die ();
  4999. }
  5000. echo json_encode ( array (
  5001. 'ok' => '可以使用!'
  5002. ) );
  5003. die ();
  5004. }
  5005. }
  5006. /**
  5007. * 获得收款退款信息
  5008. */
  5009. function getRefundByDetail() {
  5010. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5011. Doo::loadModel ( 'invoiceReceivables' );
  5012. $invoiceReceivables = new invoiceReceivables ();
  5013. if (! empty ( $iridKey )) {
  5014. $irid = $invoiceReceivables->authcode ( $iridKey );
  5015. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5016. echo json_encode ( array (
  5017. 'status' => 1,
  5018. 'irDetail' => $irDetail
  5019. ) );
  5020. die ();
  5021. }
  5022. echo json_encode ( array (
  5023. 'status' => 2
  5024. ) );
  5025. }
  5026. /**
  5027. * 根据收款序列号获得收款退款信息
  5028. */
  5029. function ajaxGetInvoiceReceivablesBySerial() {
  5030. $receivablesSerial = $this->get_args ( 'receivablesSerial' ) ? $this->get_args ( 'receivablesSerial' ) : '';
  5031. if (! empty ( $receivablesSerial )) {
  5032. Doo::loadModel ( 'invoiceReceivables' );
  5033. $invoiceReceivables = new invoiceReceivables ();
  5034. // , ' and refundLog=""'
  5035. $irDetail = $invoiceReceivables->getInvoiceReceivablesBySerial ( $receivablesSerial );
  5036. $html = '';
  5037. if (! empty ( $irDetail ))
  5038. $html = '<td><b>¥' . $irDetail ['receivablesPrice'] . '</b></td>
  5039. <td>' . $irDetail ['receivablesMessage'] . '</td>
  5040. <td>' . $irDetail ['receivablesBank'] . '<br>' . $irDetail ['receivablesDate'] . '</td>
  5041. <td>' . $irDetail ['title'] . '-' . $irDetail ['username'] . '<br>' . $irDetail ['confirmTime'] . '</td>
  5042. <td>' . $irDetail ['recepitTitleMark'] . '
  5043. <input type="hidden" name="iridKey" id="iridKey" value="' . $irDetail ['iridKey'] . '">
  5044. </td>';
  5045. echo json_encode ( array (
  5046. 'status' => 1,
  5047. 'html' => $html,
  5048. 'irDetail' => $irDetail
  5049. ) );
  5050. die ();
  5051. }
  5052. echo json_encode ( array (
  5053. 'status' => 2
  5054. ) );
  5055. }
  5056. /**
  5057. * 绑定新收款
  5058. */
  5059. function relationNewInvoiceReceivables() {
  5060. $iridKeyOld = $this->get_args ( 'iridKeyOld' ) ? $this->get_args ( 'iridKeyOld' ) : '';
  5061. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5062. if (! empty ( $iridKeyOld ) && ! empty ( $iridKey )) {
  5063. Doo::loadModel ( 'invoiceReceivables' );
  5064. $invoiceReceivables = new invoiceReceivables ();
  5065. Doo::loadClass ( 'XDeode' );
  5066. $XDeode = new XDeode ( 5 );
  5067. $irid = $XDeode->decode ( $iridKey );
  5068. $iridOld = $invoiceReceivables->authcode ( $iridKeyOld );
  5069. echo $irid . 'bbb' . $iridOld;
  5070. $oldIrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $iridOld );
  5071. $IrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5072. if (empty ( $oldIrDetail ) || empty ( $IrDetail ))
  5073. die ( 'illegal request' );
  5074. $relationLog = $this->staff [0] ['username'] . ' 关联新款 <a href="#billing" onclick="invoiceReceivblesDivShow(\'' . $iridKey . '\',\'receivables\')" data-toggle="modal">' . $IrDetail ['receivablesSerial'] . '</a>
  5075. <br/>' . date ( "Y-m-d H:i:s" ) . '
  5076. ';
  5077. $invoiceReceivables = new invoiceReceivables ();
  5078. $item = array (
  5079. 'irid' => $iridOld,
  5080. 'relationIrid' => $irid,
  5081. 'relationLog' => $relationLog
  5082. );
  5083. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  5084. return '/invoiceReceivablesAS';
  5085. }
  5086. die ( 'illegal request' );
  5087. }
  5088. // function invoiceApprovalAchieve() {
  5089. // Doo::loadModel ( 'invoice' );
  5090. // $invoice = new invoice ();
  5091. // $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  5092. // $page_size = 12;
  5093. // $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5094. // $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  5095. // $get = "/" . $date;
  5096. // $con = '';
  5097. // if ($date == 'MONTHO')
  5098. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  5099. // elseif ($date == 'MONTHT')
  5100. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  5101. // elseif ($date == 'MONTHY')
  5102. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  5103. // if (! empty ( $MebSea )) {
  5104. // $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  5105. // $get .= "/" . $MebSea;
  5106. // }
  5107. // $pageinfo ['page'] = array (
  5108. // 'previous' => ''
  5109. // );
  5110. // $sql = '(status=1 or status=2 or status=3 or status=4) and processApprovals!=""' . $con; // echo $sql;
  5111. // $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", $get, "" );
  5112. // $limit = $pageinfo ['lower'] . ',' . $page_size;
  5113. // $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  5114. // // print_r($list);
  5115. // $this->data ['MebSeaEn'] = $MebSea;
  5116. // $this->data ['MebSea'] = urlencode ( $MebSea );
  5117. // $this->data ['get'] = $get;
  5118. // $this->data ['page'] = $pageinfo;
  5119. // $this->data ['list'] = $list;
  5120. // $this->data ['date'] = $date;
  5121. // $this->data ['memu'] = "invoice";
  5122. // $this->data ['staff'] = $this->staff;
  5123. // $this->data ['receiptMemu'] = 'invoiceApproval';
  5124. // $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  5125. // }
  5126. /**
  5127. * 获得审批发票的信息以及审批页面
  5128. */
  5129. function ajaxGetInvoiceApprovalDetail() {
  5130. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5131. if (empty ( $serial )) {
  5132. echo json_encode ( array (
  5133. 'status' => 2,
  5134. 'msg' => 'illegal request'
  5135. ) );
  5136. die ();
  5137. }
  5138. Doo::loadModel ( 'invoice' );
  5139. $invoice = new invoice ();
  5140. Doo::loadModel ( 'invoiceOperationLog' );
  5141. $invoiceOperationLog = new invoiceOperationLog ();
  5142. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5143. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5144. if (empty ( $detail ))
  5145. $html = '';
  5146. else {
  5147. $html = '
  5148. <form action="/invoiceApprovalDo" method="post" name="invoiceApproval" class="nice-validator n-yellow" novalidate="novalidate">
  5149. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  5150. <input type="hidden" name="status" value="">
  5151. <input type="hidden" name="divApproval" value="divApproval">
  5152. <div class="modal-dialog modal-lg">
  5153. <div class="modal-content"><div class="modal-header"><h3>发票审批详情</h3></div>
  5154. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  5155. <tr>
  5156. <th class="taC" width="150">发票审批</th><td><textarea name="opinion" style="width:98%" placeholder="在这写下您的审批意见,选填。"></textarea></td>
  5157. </tr>
  5158. <tr>
  5159. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5160. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5161. </tr>
  5162. <tr>
  5163. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5164. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5165. </tr>
  5166. <tr>
  5167. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5168. </td>
  5169. </tr>
  5170. <tr>
  5171. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5172. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5173. </tr>
  5174. <tr>
  5175. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5176. </tr></tbody></table>';
  5177. if ($detail ['invoiceType'] == 0)
  5178. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5179. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5180. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5181. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5182. </tr>';
  5183. else
  5184. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5185. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5186. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5187. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5188. ';
  5189. $html .= '<tr>
  5190. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5191. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5192. </tr>
  5193. <tr>
  5194. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5195. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5196. </tr></tbody></table>';
  5197. if ($detail ['doPost'] == 1) {
  5198. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5199. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5200. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5201. </tr><tr>
  5202. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5203. </tr><tr>
  5204. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5205. </tr>
  5206. ';
  5207. if ($detail ['expressCom'] == 'SF')
  5208. $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>';
  5209. else
  5210. $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>';
  5211. $html .= '</tbody></table>';
  5212. }
  5213. if (! empty ( $invoiceOperationLogList )) {
  5214. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  5215. foreach ( $invoiceOperationLogList as $key => $value ) {
  5216. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5217. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5218. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5219. if ($value ['status'] == 2) {
  5220. $html .= '<span class="colGreen">同意</span>';
  5221. } elseif ($value ['status'] == 3) {
  5222. $html .= '<span class="colOrange">退回</span>';
  5223. } elseif ($value ['status'] == 5) {
  5224. $html .= '<span class="colGreen">打印</span>';
  5225. } elseif ($value ['status'] == 4) {
  5226. $html .= '<span class="colRed">终止</span>';
  5227. }
  5228. $html .= $value ['operation'] . '</p></blockquote>';
  5229. }
  5230. }
  5231. $html .= '</td></tr></tbody></table>';
  5232. }
  5233. $html .= '</div><div class="modal-footer">
  5234. <a href="javascript:void(0)" node-approval="approval" diss-data="2" class="button btn-done" data-placement="top" data-toggle="ctooltip" >同意</a>
  5235. <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>
  5236. <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>
  5237. <a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>
  5238. </form>
  5239. <script type="text/javascript">
  5240. $("a[node-approval^=\'approval\']").click(function() {
  5241. $("input[name=\'status\']").val($(this).attr("diss-data"));
  5242. $("form[name=\'invoiceApproval\']").submit();
  5243. });
  5244. </script>
  5245. ';
  5246. }
  5247. echo json_encode ( array (
  5248. 'status' => 1,
  5249. 'html' => $html
  5250. ) );
  5251. die ();
  5252. }
  5253. /**
  5254. * 获得审批发票分页数据
  5255. */
  5256. function ajaxGetinvoiceApprovalAchieve() {
  5257. Doo::loadModel ( 'invoice' );
  5258. $invoice = new invoice ();
  5259. Doo::loadModel ( 'staff' );
  5260. $staff = new staff ();
  5261. Doo::loadClass ( 'XDeode' );
  5262. $XDeode = new XDeode ( 5 );
  5263. Doo::loadModel ( 'invoiceTraining' );
  5264. $invoiceTraining = new invoiceTraining ();
  5265. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  5266. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5267. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5268. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5269. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5270. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  5271. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  5272. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  5273. $MebSea = $this->get_args ( 'search' );
  5274. $MebSea = $MebSea ['value'];
  5275. $page_size = $length;
  5276. $con = '';
  5277. if ($status == 'ALL')
  5278. $con = ' (status=1 or status=2 or status=3 or status=4) and isDelete=0 ';
  5279. elseif ($status == 'PEND')
  5280. $con = ' isDelete=0 and status=1';
  5281. elseif ($status == 'APPROVED')
  5282. $con = ' isDelete=0 and status=2';
  5283. if ($invoiceType == 'ORDINARY')
  5284. $con .= ' and invoiceType=0 ';
  5285. elseif ($invoiceType == 'SPECIAL')
  5286. $con .= ' and invoiceType=1 ';
  5287. if ($invoiceTrain == 'ORDINARY')
  5288. $con .= ' and trainId=0 ';
  5289. elseif ($invoiceTrain == 'TRAIN')
  5290. $con .= ' and trainId!=0 ';
  5291. if ($invoiceTrainName != 'ALL') {
  5292. $trainId = $XDeode->decode ( $invoiceTrainName );
  5293. if (is_numeric ( $trainId ))
  5294. $con .= ' and trainId =' . $trainId;
  5295. }
  5296. $dateArr = explode ( ':', $date );
  5297. $D1 = $dateString = '';
  5298. $D2 = '';
  5299. if (! empty ( $date )) {
  5300. $D1 = $dateArr [0];
  5301. if (isset ( $dateArr [1] ))
  5302. $D2 = $dateArr [1];
  5303. else
  5304. $D2 = '';
  5305. $dateString = $D1 . " : " . $D2;
  5306. }
  5307. if (! empty ( $D1 ) && ! empty ( $D2 ))
  5308. $con .= ' and approvalTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  5309. elseif (! empty ( $D1 ) && empty ( $D2 ))
  5310. $con .= ' and approvalTime like "%' . $D1 . '%" ';
  5311. if (! empty ( $MebSea ))
  5312. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceSerial like "%' . $MebSea . '%" )';
  5313. // /
  5314. $pageinfo ['page'] = array (
  5315. 'previous' => ''
  5316. );
  5317. $sql = ' ' . $con;
  5318. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", '', "" );
  5319. $limit = $page . ',' . $page_size;
  5320. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  5321. $approvalList = array ();
  5322. $html = '<script type="text/javascript">
  5323. </script>';
  5324. // 结算结束不能修改方式
  5325. Doo::loadModel ( 'receipt' );
  5326. $receipt = new receipt ();
  5327. foreach ( $list as $key => $value ) {
  5328. $irDetail = array ();
  5329. // 结算方式
  5330. $receiptDetail = array ();
  5331. if ($value ['trainId'] != 0) {
  5332. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $value ['trainId'] );
  5333. }
  5334. if (! empty ( $receiptDetail )) {
  5335. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9) {
  5336. array_push ( $irDetail, '' );
  5337. } else {
  5338. if ($value ['status'] == 1 && $value ['pendingApprovals'] == $this->staff [0] ['sid']) {
  5339. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoiceApproval(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">审批发票</a>' );
  5340. } elseif ($value ['status'] == 2) {
  5341. array_push ( $irDetail, '<a href="#editPay" class="fnSettlementType" data-iidKey="' . $value ['iidKeyK'] . '" data-toggle="modal">结算方式</a>' );
  5342. } else
  5343. array_push ( $irDetail, '' );
  5344. }
  5345. } else {
  5346. if ($value ['status'] == 2) {
  5347. array_push ( $irDetail, '<a href="#editPay" class="fnSettlementType" data-iidKey="' . $value ['iidKeyK'] . '" data-toggle="modal">结算方式</a>' );
  5348. } else
  5349. array_push ( $irDetail, '' );
  5350. }
  5351. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  5352. if ($value ['invoiceType'] == 1)
  5353. array_push ( $irDetail, $value ['invoiceCompany'] );
  5354. else
  5355. array_push ( $irDetail, $value ['invoiceTitle'] );
  5356. array_push ( $irDetail, $value ['TIN'] );
  5357. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  5358. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  5359. array_push ( $irDetail, $value ['remark'] );
  5360. array_push ( $irDetail, $value ['invoiceElement'] );
  5361. array_push ( $irDetail, $value ['invoiceQuantity'] );
  5362. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  5363. if ($value ['invoiceType'] == 1) {
  5364. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  5365. } else {
  5366. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  5367. }
  5368. if ($value ['settlementType'] == 0) {
  5369. array_push ( $irDetail, '软件销售' );
  5370. } else {
  5371. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $value ['trainId'] );
  5372. array_push ( $irDetail, $itDetail ['trainName'] );
  5373. }
  5374. array_push ( $irDetail, $value ['recipients'] . $value ['recipientsPhone'] );
  5375. array_push ( $irDetail, $value ['recipientsAddress'] );
  5376. array_push ( $irDetail, $value ['mailItems'] );
  5377. array_push ( $irDetail, $value ['userName'] . '&nbsp;' . $value ['date'] );
  5378. $fchtml = $value ['OL'] ['operation'];
  5379. if (count ( $list ) == $page_size)
  5380. $fchtml = $value ['OL'] ['operation'] . $html;
  5381. // 最后的审批意见
  5382. array_push ( $irDetail, $fchtml );
  5383. if ($value ['status'] == 2)
  5384. array_push ( $irDetail, '<span class="colGreen">同意</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5385. elseif ($value ['status'] == 3)
  5386. array_push ( $irDetail, '<span class="colOrange">退回</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5387. elseif ($value ['status'] == 4)
  5388. array_push ( $irDetail, '<span class="colRed">终止</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5389. else
  5390. array_push ( $irDetail, '' );
  5391. array_push ( $approvalList, $irDetail );
  5392. }
  5393. // $approvalListJson = json_encode ( $approvalList );
  5394. $recordsFiltered = $pageinfo ['total_data'];
  5395. echo json_encode ( array (
  5396. "draw" => intval ( $draw ),
  5397. "recordsTotal" => intval ( $pageinfo ['total_data'] ),
  5398. "recordsFiltered" => intval ( $recordsFiltered ),
  5399. "data" => $approvalList
  5400. ), JSON_UNESCAPED_UNICODE );
  5401. }
  5402. /**
  5403. * 审批发票查看更多--重构
  5404. */
  5405. function invoiceApprovalAchieve() {
  5406. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'ALL';
  5407. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5408. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5409. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5410. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5411. Doo::loadModel ( 'invoiceTraining' );
  5412. $invoiceTraining = new invoiceTraining ();
  5413. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  5414. $this->data ['trainList'] = $trainList;
  5415. $this->data ['dateString'] = $date;
  5416. $this->data ['status'] = $status;
  5417. $this->data ['invoiceType'] = $invoiceType;
  5418. $this->data ['invoiceTrain'] = $invoiceTrain;
  5419. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  5420. $this->data ['memu'] = "invoice";
  5421. $this->data ['staff'] = $this->staff;
  5422. $this->data ['receiptMemu'] = 'invoiceApproval';
  5423. $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  5424. }
  5425. function invoiceTAchieve() {
  5426. Doo::loadModel ( 'invoice' );
  5427. $invoice = new invoice ();
  5428. Doo::loadClass ( 'XDeode' );
  5429. $XDeode = new XDeode ( 5 );
  5430. Doo::loadModel ( 'staff' );
  5431. $staff = new staff ();
  5432. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  5433. $page_size = 12;
  5434. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5435. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  5436. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5437. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5438. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5439. Doo::loadModel ( 'invoiceTraining' );
  5440. $invoiceTraining = new invoiceTraining ();
  5441. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  5442. $get = "/" . $date;
  5443. $con = '';
  5444. if ($date == 'MONTHO')
  5445. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  5446. elseif ($date == 'MONTHT')
  5447. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  5448. elseif ($date == 'MONTHY')
  5449. $con = ' and YEAR(updateTime) = YEAR(NOW())'; // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  5450. if ($invoiceType == 'ORDINARY')
  5451. $con .= ' and invoiceType=0 ';
  5452. elseif ($invoiceType == 'SPECIAL')
  5453. $con .= ' and invoiceType=1 ';
  5454. if ($invoiceTrain == 'ORDINARY')
  5455. $con .= ' and trainId=0 ';
  5456. elseif ($invoiceTrain == 'TRAIN')
  5457. $con .= ' and trainId!=0 ';
  5458. if ($invoiceTrainName != 'ALL') {
  5459. $trainId = $XDeode->decode ( $invoiceTrainName );
  5460. if (is_numeric ( $trainId ))
  5461. $con .= ' and trainId =' . $trainId;
  5462. }
  5463. if (! empty ( $MebSea )) {
  5464. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  5465. $get .= "/" . $MebSea;
  5466. }
  5467. $pageinfo ['page'] = array (
  5468. 'previous' => ''
  5469. );
  5470. $sql = "";
  5471. $action = "";
  5472. if ($this->ACTION == 'invoicePrintAchieve') {
  5473. $sql = "status=2 and printStatus=1 and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  5474. $action = "invoicePrintAchieve";
  5475. } elseif ($this->ACTION == 'invoicePostAchieve') {
  5476. // and untreadStatus=0
  5477. $sql = "postStatus=1 and doPost=1 and status=2 and isDelete=0" . $con;
  5478. $action = "invoicePostAchieve";
  5479. } elseif ($this->ACTION == 'invoiceUntreadAchieve') { // printStatus=1 and
  5480. $sql = " untreadStatus=2 and status=2 " . $con;
  5481. $action = "invoiceUntreadAchieve";
  5482. }
  5483. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  5484. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5485. $this->data ['MebSeaEn'] = $MebSea;
  5486. $this->data ['MebSea'] = urlencode ( $MebSea );
  5487. $this->data ['get'] = $get;
  5488. $this->data ['page'] = $pageinfo;
  5489. $this->data ['trainList'] = $trainList;
  5490. $this->data ['invoiceType'] = $invoiceType;
  5491. $this->data ['invoiceTrain'] = $invoiceTrain;
  5492. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  5493. $this->data ['date'] = $date;
  5494. $this->data ['memu'] = "invoice";
  5495. $this->data ['staff'] = $this->staff;
  5496. if ($this->ACTION == 'invoicePrintAchieve') {
  5497. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  5498. $this->data ['receiptMemu'] = 'invoicePrint';
  5499. $this->data ['list'] = $list;
  5500. $this->render ( "/admin/invoicePrintAchieve", $this->data );
  5501. } elseif ($this->ACTION == 'invoicePostAchieve') {
  5502. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  5503. Doo::loadModel ( 'express' );
  5504. $express = new express ();
  5505. $expressList = $express->getExpressByAll ();
  5506. $this->data ['expressList'] = $expressList;
  5507. $this->data ['receiptMemu'] = 'invoicePost';
  5508. $this->data ['list'] = $list;
  5509. $this->render ( "/admin/invoicePostAchieve", $this->data );
  5510. } elseif ($this->ACTION == 'invoiceUntreadAchieve') {
  5511. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  5512. $this->data ['receiptMemu'] = 'invoiceUntread';
  5513. $this->data ['list'] = $list;
  5514. $this->render ( "/admin/invoiceUntreadAchieve", $this->data );
  5515. }
  5516. }
  5517. /**
  5518. * 公司应收款
  5519. */
  5520. function invoiceAggregateCompanyDetail() {
  5521. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  5522. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  5523. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : 'ALL';
  5524. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  5525. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  5526. Doo::loadClass ( 'XDeode' );
  5527. $XDeode = new XDeode ( 5 );
  5528. Doo::loadModel ( 'invoice' );
  5529. $invoice = new invoice ();
  5530. Doo::loadModel ( 'staff' );
  5531. $staff = new staff ();
  5532. Doo::loadModel ( "invoiceCompanyManage" );
  5533. $invoiceCompanyManage = new invoiceCompanyManage ();
  5534. Doo::loadModel ( 'L_category' );
  5535. $category = new L_category ();
  5536. $sid = '';
  5537. if (! empty ( $sidKey )) {
  5538. $sid = $XDeode->decode ( $sidKey );
  5539. }
  5540. $staffDetail = $staff->getStaffBySid ( $sid );
  5541. $cid = '';
  5542. if (! empty ( $cidKey )) {
  5543. $cid = $XDeode->decode ( $cidKey );
  5544. }
  5545. $imcStaff = $invoiceCompanyManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  5546. $cidList = array ();
  5547. foreach ( $imcStaff as $key => $value ) {
  5548. array_push ( $cidList, $value ['cid'] );
  5549. }
  5550. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  5551. $cidString = implode ( ',', $cidList );
  5552. if (empty ( $cid ))
  5553. $staffList = $staff->getStaffInCid ( $cidString );
  5554. else
  5555. $staffList = $staff->getStaffByCidAll ( $cid ); //
  5556. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  5557. $page_size = 25;
  5558. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5559. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  5560. $con = ' status=2 and untreadStatus!=2 ';
  5561. $statisticsCon = '';
  5562. if (! empty ( $year ) && is_numeric ( $year ))
  5563. $con .= ' and Year(printTime)=' . $year . '';
  5564. if (! empty ( $month ) && is_numeric ( $month ))
  5565. $con .= ' and Month(printTime)="' . $month . '" ';
  5566. if ($status == 'UNRECORD')
  5567. $con .= ' and printStatus=1 and untreadStatus=0';
  5568. elseif ($status == 'RECORD')
  5569. $con .= ' and printStatus=1 and untreadStatus=3';
  5570. elseif ($status == 'BOUNCED')
  5571. $con .= ' and untreadStatus=2';
  5572. elseif ($status == 'PARTRECORD')
  5573. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  5574. elseif ($status == 'All') {
  5575. $con .= ' and printStatus=1 and ( untreadStatus=0 or untreadStatus=3 )';
  5576. }
  5577. if (! empty ( $sid ) && is_numeric ( $sid ))
  5578. $con .= ' and sid=' . $sid;
  5579. if (! empty ( $cid ) && is_numeric ( $cid ))
  5580. $con .= ' and cid=' . $cid;
  5581. else
  5582. $con .= ' and cid in (' . $cidString . ')';
  5583. // 开票内容筛选
  5584. if (! empty ( $invoiceElement ) && $invoiceElement != 'ALL') {
  5585. $con .= ' and invoiceElement="' . $invoiceElement . '"';
  5586. }
  5587. $get = "/" . $status . "?cidKey=" . $cidKey . "&sidKey=" . $sidKey . "&year=" . $year . "&month=" . $month . "&invoiceElement=" . $invoiceElement;
  5588. if (! empty ( $MebSea )) {
  5589. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  5590. }
  5591. $pageinfo ['page'] = array (
  5592. 'previous' => ''
  5593. );
  5594. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateCompanyDetail", $get, "" );
  5595. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5596. // 应收款合计
  5597. $ics = $invoice->getInvoiceCompanyStatistics ( $con );
  5598. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  5599. $monthHtml = "";
  5600. if ($year != "ALL") {
  5601. for($i = 1; $i <= 12; $i ++) {
  5602. if ($i == $month)
  5603. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  5604. else
  5605. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  5606. }
  5607. }
  5608. $this->data ['monthHtml'] = $monthHtml;
  5609. $this->data ['year'] = $year;
  5610. $this->data ['month'] = $month;
  5611. $this->data ['ics'] = $ics;
  5612. $this->data ['cidKey'] = $cidKey;
  5613. $this->data ['sid'] = $sid;
  5614. $this->data ['staffDetail'] = $staffDetail;
  5615. $this->data ['staffList'] = $staffList;
  5616. $this->data ['MebSeaEn'] = $MebSea;
  5617. $this->data ['MebSea'] = urlencode ( $MebSea );
  5618. $this->data ['invoiceDetail'] = array (
  5619. 'invoiceElement' => $invoiceElement
  5620. );
  5621. $this->data ['page'] = $pageinfo;
  5622. $this->data ['get'] = $get;
  5623. $this->data ['list'] = $list;
  5624. $this->data ['status'] = $status;
  5625. $this->data ['categoryList'] = $categoryList;
  5626. $this->data ['memu'] = "invoice";
  5627. $this->data ['staff'] = $this->staff;
  5628. $this->data ['receiptMemu'] = 'invoiceAggregateCompanyDetail';
  5629. $this->render ( "/admin/invoiceAggregateCompanyDetail", $this->data );
  5630. }
  5631. /**
  5632. * 获取一条收款信息
  5633. */
  5634. function ajaxGetInvoiceReceivables() {
  5635. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  5636. Doo::loadModel ( 'invoiceReceivables' );
  5637. $invoiceReceivables = new invoiceReceivables ();
  5638. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5639. echo json_encode ( array (
  5640. 'status' => 1,
  5641. 'detail' => $detail
  5642. ) );
  5643. }
  5644. /**
  5645. * 异步获取办事处用户
  5646. */
  5647. function ajaxGetStaffByCategory() {
  5648. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "";
  5649. Doo::loadModel ( 'staff' );
  5650. $staff = new staff ();
  5651. if ($cid == "PUBLIC") {
  5652. echo json_encode ( array (
  5653. 'status' => 1,
  5654. 'html' => '<option value="PUBLIC">办事处待认领款项</option>'
  5655. ) );
  5656. die ();
  5657. }
  5658. if (! is_numeric ( $cid )) {
  5659. echo json_encode ( array (
  5660. 'status' => 0,
  5661. 'msg' => 'illegal request'
  5662. ) );
  5663. die ();
  5664. }
  5665. $staffList = $staff->getStaffByCid ( $cid );
  5666. $html = '<option value="PUBLIC">办事处待认领款项</option>';
  5667. foreach ( $staffList as $key => $value ) {
  5668. $html .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  5669. }
  5670. echo json_encode ( array (
  5671. 'status' => 1,
  5672. 'html' => $html
  5673. ) );
  5674. }
  5675. /**
  5676. * 异步获取一条发票的邮寄信息
  5677. */
  5678. function ajaxGetInvoicePostDetail() {
  5679. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  5680. Doo::loadModel ( 'invoice' );
  5681. $invoice = new invoice ();
  5682. $iid = $invoice->authcode ( $iid );
  5683. Doo::loadModel ( 'express' );
  5684. $express = new express ();
  5685. $expressList = $express->getExpressByAll ();
  5686. if (! is_numeric ( $iid )) {
  5687. echo json_encode ( array (
  5688. 'status' => 0,
  5689. 'msg' => 'illegal request'
  5690. ) );
  5691. die ();
  5692. }
  5693. $select = "iid,recipients,recipientsPhone,recipientsAddress,mailItems,expressCompany,expressNumber,actualItems";
  5694. $invoiceDetail = $invoice->getInvoiceByIid ( $iid, $select );
  5695. $html = "";
  5696. foreach ( $expressList as $key => $value ) {
  5697. if ($value ['company'] == $invoiceDetail ['expressCompany'])
  5698. $html .= '<option selected value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  5699. else
  5700. $html .= '<option value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  5701. }
  5702. $invoiceDetail ['eaHtml'] = $html;
  5703. echo json_encode ( array (
  5704. 'status' => 1,
  5705. 'invoiceDetail' => $invoiceDetail
  5706. ) );
  5707. }
  5708. /**
  5709. *
  5710. * @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 ) ); }
  5711. */
  5712. /**
  5713. *
  5714. * @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 ) ); }
  5715. */
  5716. /**
  5717. * 我的收款中 选择哪个发票入账,进行金额判断
  5718. */
  5719. function ajaxCompareInvoicePrice() {
  5720. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  5721. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  5722. Doo::loadModel ( 'invoice' );
  5723. $invoice = new invoice ();
  5724. Doo::loadModel ( 'invoiceReceivables' );
  5725. $invoiceReceivables = new invoiceReceivables ();
  5726. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  5727. $keyList = explode ( ';', $claimKey );
  5728. $receivablesPrice = 0;
  5729. foreach ( $keyList as $key => $value ) {
  5730. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $value );
  5731. $receivablesPrice += $detailM ['receivablesPrice'];
  5732. }
  5733. if ($receivablesPrice > $detail ['invoicePrice']) {
  5734. $price = $receivablesPrice - $detail ['invoicePrice'];
  5735. echo json_encode ( array (
  5736. 'status' => 1,
  5737. 'price' => $price
  5738. ) );
  5739. } else
  5740. echo json_encode ( array (
  5741. 'status' => 2
  5742. ) );
  5743. }
  5744. /**
  5745. * 获得打印发票
  5746. */
  5747. function ajaxGetInvoiceInfoByPrint() {
  5748. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5749. if (empty ( $serial )) {
  5750. echo json_encode ( array (
  5751. 'status' => 2,
  5752. 'msg' => 'illegal request'
  5753. ) );
  5754. die ();
  5755. }
  5756. Doo::loadModel ( 'invoice' );
  5757. $invoice = new invoice ();
  5758. Doo::loadModel ( 'invoiceOperationLog' );
  5759. $invoiceOperationLog = new invoiceOperationLog ();
  5760. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5761. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5762. Doo::loadModel ( 'invoicePaper' );
  5763. $invoicePaper = new invoicePaper ();
  5764. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $detail ['invoiceType'] );
  5765. if (empty ( $detail ))
  5766. $html = '';
  5767. else {
  5768. $html = '
  5769. <form action="/invoicePrintDo" method="post" name="invoicePrint" class="nice-validator n-yellow" onSubmit="return checkPrintForm()" novalidate="novalidate">
  5770. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  5771. <input type="hidden" name="invoicePrintType" value="invoicePrintType">
  5772. <div class="modal-dialog modal-lg">
  5773. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  5774. <div class="modal-body saeaList">
  5775. <table class="table table-bordered table-condensed"><tbody>
  5776. <tr>
  5777. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5778. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5779. </tr>
  5780. <tr>
  5781. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5782. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5783. </tr>
  5784. <tr>
  5785. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5786. </td>
  5787. </tr>
  5788. <tr>
  5789. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5790. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5791. </tr>
  5792. <tr>
  5793. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5794. </tr></tbody></table>';
  5795. if ($detail ['invoiceType'] == 0)
  5796. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5797. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5798. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5799. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5800. </tr>';
  5801. else
  5802. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5803. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5804. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5805. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5806. ';
  5807. $html .= '<tr>
  5808. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5809. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5810. </tr>
  5811. <tr>
  5812. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5813. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5814. </tr></tbody></table>';
  5815. if ($detail ['doPost'] == 1)
  5816. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5817. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5818. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5819. </tr><tr>
  5820. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5821. </tr><tr>
  5822. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5823. </tr></tbody></table>';
  5824. if (! empty ( $invoiceOperationLogList )) {
  5825. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th><th class="taC">发票打印</th></tr><tr><td>';
  5826. foreach ( $invoiceOperationLogList as $key => $value ) {
  5827. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5828. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5829. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5830. if ($value ['status'] == 2) {
  5831. $html .= '<span class="colGreen">同意</span>';
  5832. } elseif ($value ['status'] == 3) {
  5833. $html .= '<span class="colOrange">退回</span>';
  5834. } elseif ($value ['status'] == 5) {
  5835. $html .= '<span class="colGreen">打印</span>';
  5836. } elseif ($value ['status'] == 4) {
  5837. $html .= '<span class="colRed">终止</span>';
  5838. }
  5839. $html .= $value ['operation'] . '</p></blockquote>';
  5840. }
  5841. }
  5842. $html .= '</td>
  5843. <td><span class="colRed">*</span>
  5844. <select name="invoiceNo" id="invoiceNo" style="width:97%">';
  5845. foreach ( $invoicePaperList as $key => $value ) {
  5846. $html .= '<option value="' . $value ['ipidKey'] . '">No.' . $value ['invoiceNo'] . '</option>';
  5847. }
  5848. $html .= '</select>
  5849. <span class="red" id="p-msg"></span>
  5850. </td>
  5851. </tr></tbody></table>';
  5852. }
  5853. $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>
  5854. </div></div></form>
  5855. <link rel=stylesheet href="' . WEB_SITE_GLOBAL . 'css/jquery.validator.css">
  5856. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/jquery.validator.min.js"></script>
  5857. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/zh-CN.js"></script>
  5858. <script src="' . WEB_SITE_GLOBAL . 'js/invoice.validator.js"></script>
  5859. ';
  5860. }
  5861. echo json_encode ( array (
  5862. 'status' => 1,
  5863. 'html' => $html
  5864. ) );
  5865. die ();
  5866. }
  5867. /**
  5868. * @ 获得与我有关收款数据 --需求变更 废弃 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 ) ); }
  5869. */
  5870. function ajaxGetInvoiceInfoByType() {
  5871. $type = $this->get_args ( 'type' ) ? $this->get_args ( 'type' ) : "";
  5872. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5873. $loss = $this->get_args ( 'loss' ) ? $this->get_args ( 'loss' ) : false;
  5874. if (empty ( $serial )) {
  5875. echo json_encode ( array (
  5876. 'status' => 2,
  5877. 'msg' => 'illegal request'
  5878. ) );
  5879. die ();
  5880. }
  5881. if ($type == 'INVOICE') {
  5882. Doo::loadModel ( 'invoice' );
  5883. $invoice = new invoice ();
  5884. Doo::loadModel ( 'invoiceOperationLog' );
  5885. $invoiceOperationLog = new invoiceOperationLog ();
  5886. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5887. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5888. if (empty ( $detail ))
  5889. $html = '';
  5890. else {
  5891. $html = '
  5892. <div class="modal-dialog modal-lg">
  5893. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  5894. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  5895. <tr>
  5896. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5897. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5898. </tr>
  5899. <tr>
  5900. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5901. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5902. </tr>
  5903. <tr>
  5904. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5905. </td>
  5906. </tr>
  5907. <tr>
  5908. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5909. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5910. </tr>
  5911. <tr>
  5912. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5913. </tr>';
  5914. if ($detail ['settlementType'] == 1)
  5915. $html .= '<tr>
  5916. <th class="taC" width="150">结算方式</th><td colspan="3">培训班(<a href="/invoiceTrainingDetail/' . $detail ['invoiceTraining'] ['trainingKey'] . '.html" target="_blank">' . $detail ['invoiceTraining'] ['trainName'] . '</a>)</td>
  5917. </tr>';
  5918. else
  5919. $html .= '<tr>
  5920. <th class="taC" width="150">结算方式</th><td colspan="3">软件销售</td>
  5921. </tr>';
  5922. $html .= ' </tbody></table>';
  5923. if ($detail ['invoiceType'] == 0)
  5924. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5925. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5926. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5927. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5928. </tr>';
  5929. else
  5930. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5931. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5932. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5933. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5934. ';
  5935. $html .= '<tr>
  5936. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5937. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5938. </tr>
  5939. <tr>
  5940. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5941. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5942. </tr></tbody></table>';
  5943. if ($detail ['doPost'] == 1) {
  5944. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5945. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5946. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5947. </tr><tr>
  5948. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5949. </tr><tr>
  5950. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5951. </tr>
  5952. ';
  5953. if ($detail ['expressCom'] == 'SF')
  5954. $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>';
  5955. else
  5956. $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>';
  5957. $html .= '</tbody></table>';
  5958. }
  5959. if (! empty ( $invoiceOperationLogList )) {
  5960. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  5961. foreach ( $invoiceOperationLogList as $key => $value ) {
  5962. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5963. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5964. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5965. if ($value ['status'] == 2) {
  5966. $html .= '<span class="colGreen">同意</span>';
  5967. } elseif ($value ['status'] == 3) {
  5968. $html .= '<span class="colOrange">退回</span>';
  5969. } elseif ($value ['status'] == 5) {
  5970. $html .= '<span class="colGreen">打印</span>';
  5971. } elseif ($value ['status'] == 4) {
  5972. $html .= '<span class="colRed">终止</span>';
  5973. }
  5974. $html .= $value ['operation'] . '</p></blockquote>';
  5975. }
  5976. }
  5977. $html .= '</td></tr></tbody></table>';
  5978. }
  5979. $html .= '</div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  5980. }
  5981. echo json_encode ( array (
  5982. 'status' => 1,
  5983. 'html' => $html
  5984. ) );
  5985. die ();
  5986. } elseif ($type == 'RECEIVABLES') {
  5987. Doo::loadModel ( 'invoiceReceivables' );
  5988. $invoiceReceivables = new invoiceReceivables ();
  5989. Doo::loadModel ( 'invoiceRefund' );
  5990. $invoiceRefund = new invoiceRefund ();
  5991. $detail = $invoiceReceivables->getInvoiceReceivablesByIrsid ( $serial );
  5992. $ireList = $invoiceRefund->getInvoiceRefundIrid ( $detail ['irid'] );
  5993. if (empty ( $detail ))
  5994. $html = '';
  5995. else {
  5996. $html = '<div class="modal-dialog modal-lg"><div class="modal-content"><div class="modal-header"><h3>收款单详情</h3></div><div class="modal-body saeaList">
  5997. <table class="table table-bordered table-condensed">
  5998. <tbody><tr>
  5999. <th class="taC">收款流水号</th><td>' . $detail ['receivablesSerial'] . '</td>
  6000. <th class="taC">录入收款</th><td>' . $detail ['inputStaff'] . ' ' . $detail ['date'] . '</td>
  6001. </tr><tr>
  6002. <th class="taC">收款金额</th><td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  6003. <th class="taC">收款信息</th><td>' . $detail ['receivablesMessage'] . '</td>
  6004. </tr>
  6005. <tr>
  6006. <th class="taC">收款银行</th><td>' . $detail ['receivablesBank'] . '</td>
  6007. <th class="taC">银行到账</th><td>' . $detail ['receivablesDate'] . '</td>
  6008. </tr>
  6009. <tr>
  6010. <th class="taC">认领收款</th><td colspan="3">' . $detail ['inputStaff'] . ' 转入 ' . $detail ['username'] . ' ' . $detail ['confirmTime'] . '</td>
  6011. </tr>
  6012. </tbody></table>';
  6013. if (! empty ( $ireList )) {
  6014. $html .= '
  6015. <table class="table table-bordered table-condensed"><tbody><tr><th class="taC" colspan="5">退款记录</th></tr>
  6016. <tr>
  6017. <th class="taC">退款单位名称</th>
  6018. <th class="taC">退款的账号</th>
  6019. <th class="taC">退款金额</th>
  6020. <th class="taC">退款</th>
  6021. <th class="taC">备注</th>
  6022. </tr>
  6023. ';
  6024. foreach ( $ireList as $key => $value ) {
  6025. $refundLogList = explode ( "<br/>", $value ['refundLog'] );
  6026. $html .= '<tr>
  6027. <td>' . $value ['refundCompany'] . '</td>
  6028. <td>' . $value ['refundNumber'] . '</td>
  6029. <td><b class="colRed">¥' . $value ['refundPrice'] . '</b></td>
  6030. <td>' . $refundLogList [0] . $refundLogList [2] . '</td>
  6031. <td>' . $value ['refundRemarks'] . '</td>
  6032. </tr>
  6033. ';
  6034. }
  6035. }
  6036. $html .= '</tbody></table></div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  6037. }
  6038. echo json_encode ( array (
  6039. 'status' => 1,
  6040. 'html' => $html
  6041. ) );
  6042. die ();
  6043. } elseif ($type == 'IRTC') {
  6044. Doo::loadModel ( 'invoice' );
  6045. $invoice = new invoice ();
  6046. Doo::loadModel ( 'invoiceOperationLog' );
  6047. $invoiceOperationLog = new invoiceOperationLog ();
  6048. Doo::loadModel ( 'invoiceReceivables' );
  6049. $invoiceReceivables = new invoiceReceivables ();
  6050. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  6051. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  6052. if (empty ( $detail ))
  6053. $html = '';
  6054. else {
  6055. $receivablesPriceedHtml = '';
  6056. $receivablesPrice = $detail ['invoicePrice'];
  6057. if (! empty ( $detail ['irid'] )) {
  6058. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $detail ['irid'] );
  6059. if (empty ( $irList ))
  6060. $irList [0] ['sumPrice'] = 0;
  6061. $balance = $detail ['invoicePrice'] - $irList [0] ['sumPrice'];
  6062. $receivablesPriceedHtml = '<table class="table table-bordered table-condensed"><tbody><tr>
  6063. <th class="taC">已入账金额</th><td><b class="colGreen" style="font-size:18px">¥' . $irList [0] ['sumPrice'] . '</b></td>
  6064. <th class="taC">剩余入账金额</th><td><b class="colRed" style="font-size:18px">¥' . $balance . '</b></td>
  6065. </tr></tbody></table>';
  6066. $receivablesPrice = $balance;
  6067. }
  6068. if ($loss)
  6069. $detail ['invoicePrice'] = - $detail ['invoicePrice'];
  6070. $html = $receivablesPriceedHtml . '
  6071. <table class="table table-bordered table-condensed"><tbody>
  6072. <tr>
  6073. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  6074. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  6075. </tr>
  6076. <tr>
  6077. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  6078. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  6079. </tr>
  6080. <tr>
  6081. <th class="taC" width="150">发票备注</th><td colspan="3">' . $detail ['remark'] . '</td>
  6082. </tr>
  6083. <tr>
  6084. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  6085. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  6086. </tr>
  6087. <tr>
  6088. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  6089. </tr></tbody></table>';
  6090. if ($detail ['invoiceType'] == 0) {
  6091. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6092. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  6093. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  6094. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  6095. </tr>';
  6096. $receivablesMessage = $detail ['invoiceTitle'];
  6097. } else {
  6098. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6099. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  6100. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  6101. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  6102. ';
  6103. $receivablesMessage = $detail ['invoiceCompany'];
  6104. }
  6105. $html .= '<tr>
  6106. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  6107. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  6108. </tr>
  6109. <tr>
  6110. <th class="taC">开户银行</th><td>' . $detail ['bankAccount'] . '</td>
  6111. <th class="taC">银行账号</th><td>' . $detail ['bank'] . '</td>
  6112. </tr></tbody></table>';
  6113. if ($detail ['doPost'] == 1)
  6114. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  6115. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  6116. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  6117. </tr><tr>
  6118. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  6119. </tr><tr>
  6120. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  6121. </tr></tbody></table>';
  6122. if (! empty ( $invoiceOperationLogList )) {
  6123. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  6124. foreach ( $invoiceOperationLogList as $key => $value ) {
  6125. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  6126. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  6127. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  6128. if ($value ['status'] == 2) {
  6129. $html .= '<span class="colGreen">同意</span>';
  6130. } elseif ($value ['status'] == 3) {
  6131. $html .= '<span class="colOrange">退回</span>';
  6132. } elseif ($value ['status'] == 5) {
  6133. $html .= '<span class="colGreen">打印</span>';
  6134. }
  6135. $html .= $value ['operation'] . '</p></blockquote>';
  6136. }
  6137. }
  6138. $html .= '</td></tr></tbody></table>';
  6139. }
  6140. }
  6141. echo json_encode ( array (
  6142. 'status' => 1,
  6143. 'html' => $html,
  6144. 'receivablesPrice' => $receivablesPrice,
  6145. 'receivablesMessage' => $receivablesMessage,
  6146. 'receivablesDate' => date ( "Y-m-d" ),
  6147. 'iidKey' => $serial
  6148. ) );
  6149. die ();
  6150. }
  6151. }
  6152. function ajaxGetInvoiceReceivablesByStaff() {
  6153. $postData = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : "";
  6154. if (empty ( $postData )) {
  6155. echo json_encode ( array (
  6156. 'status' => 2,
  6157. 'msg' => 'illegal request'
  6158. ) );
  6159. die ();
  6160. }
  6161. Doo::loadModel ( 'invoiceReceivables' );
  6162. $invoiceReceivables = new invoiceReceivables ();
  6163. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $postData );
  6164. if (empty ( $detail )) {
  6165. echo json_encode ( array (
  6166. 'status' => 2,
  6167. 'msg' => 'illegal request'
  6168. ) );
  6169. die ();
  6170. }
  6171. Doo::loadModel ( 'L_category' );
  6172. $lCategory = new L_category ();
  6173. Doo::loadModel ( 'staff' );
  6174. $staff = new staff ();
  6175. $staffList = $staff->getStaffByCid ( $detail ['cid'] );
  6176. $category = $lCategory->getCategory ();
  6177. $categoryHtml = '<option post-data="PUBLIC" value="PUBLIC" >公共待认领款项</option>';
  6178. $staffHtml = '<option value="PUBLIC">办事处待认领款项</option>';
  6179. foreach ( $category as $key => $value ) {
  6180. $categoryHtml .= '<option post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  6181. if ($value ['cid'] == $detail ['cid'])
  6182. $categoryHtml .= '<option selected post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  6183. }
  6184. foreach ( $staffList as $key => $value ) {
  6185. $staffHtml .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  6186. if ($value ['sid'] == $detail ['sid'])
  6187. $staffHtml .= '<option selected value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  6188. }
  6189. $rbankHtml = '<option value="广发银行珠海分行柠溪支行">广发银行珠海分行柠溪支行</option>';
  6190. echo json_encode ( array (
  6191. 'status' => 1,
  6192. 'categoryHtml' => $categoryHtml,
  6193. 'staffHtml' => $staffHtml,
  6194. 'rbankHtml' => $rbankHtml,
  6195. 'detail' => $detail
  6196. ) );
  6197. }
  6198. function ajaxGetInvoiceReceivablesByIrid() {
  6199. $irid = $this->get_args ( 'irid' ) ? $this->get_args ( 'irid' ) : "";
  6200. if (empty ( $irid )) {
  6201. echo json_encode ( array (
  6202. 'status' => 2,
  6203. 'msg' => 'illegal request'
  6204. ) );
  6205. die ();
  6206. }
  6207. Doo::loadModel ( 'invoiceReceivables' );
  6208. $invoiceReceivables = new invoiceReceivables ();
  6209. Doo::loadModel ( 'invoice' );
  6210. $invoice = new invoice ();
  6211. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid ); // 入账完成 待定 and postStatus=1
  6212. $flag = true;
  6213. $invoiceDetail = $invoice->getInvoiceByTitle ( $detail ['recepitTitleMark'], 'EXACTLY', " and status=2 and printStatus=1 and untreadStatus=0 ", $flag ); //
  6214. $bakDetail = array ();
  6215. if ($flag === false) {
  6216. array_push ( $bakDetail, $invoiceDetail );
  6217. $invoiceDetail = $bakDetail;
  6218. }
  6219. $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>
  6220. <tr>
  6221. <td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  6222. <td>' . $detail ['receivablesMessage'] . '</td>
  6223. <td>' . $detail ['receivablesBank'] . '<br>' . $detail ['receivablesDate'] . '</td>
  6224. <td>' . $detail ['title'] . '-' . $detail ['username'] . '<br>' . $detail ['confirmTime'] . '</td>
  6225. <td>' . $detail ['recepitTitleMark'] . '</td>
  6226. </tr></tbody></table>';
  6227. $isInvoice = false;
  6228. $invoiceHtml = '';
  6229. if (empty ( $invoiceDetail )) {
  6230. $isInvoice = true;
  6231. } else {
  6232. $invoiceHtml = '<table class="table table-bordered table-condensed">
  6233. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody>';
  6234. foreach ( $invoiceDetail as $key => $value ) {
  6235. $invoiceHtml .= '<tr>';
  6236. if (! empty ( $value ['invoiceType'] )) {
  6237. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  6238. } else {
  6239. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  6240. }
  6241. if (! empty ( $value ['invoiceType'] )) {
  6242. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  6243. } else {
  6244. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  6245. }
  6246. $invoiceHtml .= '
  6247. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  6248. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  6249. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir" data-ikey="' . $value ['iidKey'] . '" href="javascript:void(0)">入账</a></td>
  6250. </tr>
  6251. ';
  6252. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  6253. if (empty ( $irList ))
  6254. $irList [0] ['sumPrice'] = 0;
  6255. $balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  6256. $priceString = '';
  6257. if ($balance < $detail ['receivablesPrice']) {
  6258. $priceString = '收款金额超过开票金额,';
  6259. }
  6260. if ($balance > $detail ['receivablesPrice']) {
  6261. $priceString = '收款金额低于开票金额,';
  6262. }
  6263. }
  6264. $invoiceHtml .= '
  6265. <script>
  6266. $(\'a[bind-receivables^="ir"]\').click(function() {
  6267. var data = $(this).attr("data-ikey");
  6268. $("input[name=\'invoiceKey\']").val(data);
  6269. var invoiceKey=data;
  6270. if(invoiceKey==""){
  6271. alert("入账错误,请重新刷新页面");
  6272. return false;
  6273. }
  6274. if(window.confirm("' . $priceString . '确定入账吗?")){
  6275. $("#IBR").submit();
  6276. }else{
  6277. return false;
  6278. }
  6279. });
  6280. </script>
  6281. ';
  6282. $invoiceHtml .= '</tbody></table>';
  6283. }
  6284. echo json_encode ( array (
  6285. 'status' => 1,
  6286. 'irkey' => $detail ['iridEn'],
  6287. 'receivablesHtml' => $receivablesHtml,
  6288. 'isInvoice' => $isInvoice,
  6289. 'invoiceHtml' => $invoiceHtml
  6290. ) );
  6291. }
  6292. function ajaxGetInvoiceReceivablesByTitle() {
  6293. $title = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  6294. if (empty ( $title )) {
  6295. echo json_encode ( array (
  6296. 'status' => 2,
  6297. 'msg' => 'illegal request'
  6298. ) );
  6299. die ();
  6300. }
  6301. Doo::loadModel ( 'invoice' );
  6302. $invoice = new invoice ();
  6303. $invoiceDetail = $invoice->getInvoiceByTitle ( $title, 'FUZZY', " and status=2 and printStatus=1 and untreadStatus=0 and irid='' ", true );
  6304. $invoiceHtml = '';
  6305. if (! empty ( $invoiceDetail )) {
  6306. $invoiceHtml = '<table class="table table-bordered table-condensed">
  6307. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody><tr>';
  6308. foreach ( $invoiceDetail as $key => $value ) {
  6309. if (! empty ( $value ['invoiceType'] )) {
  6310. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  6311. } else {
  6312. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  6313. }
  6314. if (! empty ( $value ['invoiceType'] )) {
  6315. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  6316. } else {
  6317. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  6318. }
  6319. $invoiceHtml .= '
  6320. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  6321. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  6322. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir' . $value ['iidKeyXD'] . '" data-ikey="' . $value ['iidKey'] . '" href="#">入账</a></td>
  6323. </tr>
  6324. ';
  6325. }
  6326. $invoiceHtml .= '</tbody></table>
  6327. <script>
  6328. $(\'a[bind-receivables^="ir"]\').click(function() {
  6329. var data = $(this).attr("data-ikey");
  6330. $("input[name=\'invoiceKey\']").val(data);
  6331. var invoiceKey=$("input[name=\'invoiceKey\']").val();
  6332. if(invoiceKey==""){
  6333. alert("入账错误,请重新刷新页面");
  6334. return false;
  6335. }
  6336. if(window.confirm("确定入账吗?")){
  6337. $("#IBR").submit();
  6338. }else{
  6339. return false;
  6340. }
  6341. });
  6342. </script>
  6343. ';
  6344. }
  6345. echo json_encode ( array (
  6346. 'status' => 1,
  6347. 'invoiceHtml' => $invoiceHtml
  6348. ) );
  6349. }
  6350. function ajaxInvoicePushNotice() {
  6351. Doo::loadModel ( 'invoice' );
  6352. $invoice = new invoice ();
  6353. $approval = $invoice->getOne ( array (
  6354. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  6355. 'desc' => 'iid',
  6356. 'asArray' => true
  6357. ) );
  6358. $isNotice = false;
  6359. if (! empty ( $approval ))
  6360. $isNotice = true;
  6361. $response = array (
  6362. 'error' => 0,
  6363. 'isNotice' => $isNotice
  6364. );
  6365. echo json_encode ( $response );
  6366. exit ();
  6367. }
  6368. public function ajaxCheckInvoiceNoUniqueness() {
  6369. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  6370. Doo::loadModel ( 'invoice' );
  6371. $invoice = new invoice ();
  6372. if (! empty ( $invoiceNo )) {
  6373. Doo::loadModel ( 'invoicePaper' );
  6374. $invoicePaper = new invoicePaper ();
  6375. Doo::loadClass ( 'XDeode' );
  6376. $XDeode = new XDeode ( 5 );
  6377. $ipid = $XDeode->decode ( $invoiceNo );
  6378. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  6379. $info = $invoice->getOne ( array (
  6380. 'where' => "invoiceNo = '" . $paperDetail ['invoiceNo'] . "'",
  6381. 'asArray' => TRUE
  6382. ) );
  6383. if (! empty ( $info )) {
  6384. echo json_encode ( array (
  6385. 'error' => '发票号已存在'
  6386. ) );
  6387. die ();
  6388. } else
  6389. echo json_encode ( array (
  6390. 'ok' => '可以使用!'
  6391. ) );
  6392. die ();
  6393. }
  6394. }
  6395. function ajaxCheckInvoicePrice() {
  6396. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) && is_numeric ( $this->get_args ( 'receivablesPrice' ) ) ? $this->get_args ( 'receivablesPrice' ) : "";
  6397. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  6398. Doo::loadModel ( 'invoice' );
  6399. $invoice = new invoice ();
  6400. Doo::loadModel ( 'invoiceReceivables' );
  6401. $invoiceReceivables = new invoiceReceivables ();
  6402. Doo::loadClass ( 'XDeode' );
  6403. $XDeode = new XDeode ( 5 );
  6404. if (! empty ( $receivablesPrice ) && ! empty ( $iidKey )) {
  6405. $iidKey = $XDeode->decode ( $iidKey );
  6406. $info = $invoice->getInvoiceByIid ( $iidKey );
  6407. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $info ['irid'] );
  6408. if (empty ( $irList ))
  6409. $irList [0] ['sumPrice'] = 0;
  6410. $balance = $info ['invoicePrice'] - $irList [0] ['sumPrice'];
  6411. if ($balance < $receivablesPrice) {
  6412. echo json_encode ( array (
  6413. 'error' => '收款金额超过开票金额。'
  6414. ) );
  6415. die ();
  6416. }
  6417. if ($balance > $receivablesPrice) {
  6418. echo json_encode ( array (
  6419. 'error' => '收款金额低于开票金额。'
  6420. ) );
  6421. die ();
  6422. }
  6423. }
  6424. }
  6425. function ajaxGetInvoiceByNew() {
  6426. Doo::loadModel ( 'invoice' );
  6427. $invoice = new invoice ();
  6428. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );
  6429. echo json_encode ( array (
  6430. 'status' => 1,
  6431. 'detail' => $detail
  6432. ) );
  6433. }
  6434. /**
  6435. * 旧输入导入
  6436. */
  6437. function importInvoice() {
  6438. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  6439. $data ['emsg'] = "";
  6440. if ($emsg != "")
  6441. $data ['emsg'] = "请填写完整的数据";
  6442. $data ['time'] = time ();
  6443. $this->render ( "/admin/invoiceImport", $data );
  6444. }
  6445. function uploadInvoice() {
  6446. // move_uploaded_file($_FILES['Filedata']['tmp_name'], "/upload/".$_FILES['Filedata']['name']);
  6447. if (isset ( $_FILES ['Filedata'] ['name'] )) {
  6448. $file = $_FILES ['Filedata'] ['tmp_name'];
  6449. $error = false;
  6450. if (! is_uploaded_file ( $file )) {
  6451. $error = '400 Bad Request';
  6452. }
  6453. if ($error) {
  6454. header ( 'HTTP/1.0 ' . $error );
  6455. die ( 'Error ' . $error );
  6456. } else {
  6457. include (DOO::conf ()->SITE_PATH . 'protected/plugin/io.han.php');
  6458. $this->IoHandler = new IoHandler ();
  6459. $pics = explode ( '.', $_FILES ['Filedata'] ['name'] );
  6460. // $filedir=$_POST['time'];
  6461. // 调用定义物理路径
  6462. $t = DOO::conf ()->SITE_PATH . "upload/invoice/";
  6463. $this->IoHandler->MakeDir ( $t );
  6464. $filename = $this->_GetFileEXT ( $_FILES ['Filedata'] ['name'] );
  6465. if ($filename != 'xlsx')
  6466. return "";
  6467. // $upload_dir = $t."/".time().rand(10,100).".".$filename;
  6468. $upload_file = iconv ( "UTF-8", "GB2312", $_FILES ["Filedata"] ["name"] );
  6469. $upload_dir = $t . "/" . $upload_file;
  6470. $k = move_uploaded_file ( $file, $upload_dir );
  6471. if ($k) {
  6472. $m = round ( $_FILES ['Filedata'] ['size'] / 1024 / 1024, 2 );
  6473. echo $pics [0] . "." . $filename . "#" . $m . "#" . $_FILES ['Filedata'] ['size'];
  6474. }
  6475. }
  6476. }
  6477. }
  6478. function importInvoiceDo() {
  6479. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  6480. if ($path != "") {
  6481. Doo::loadModel ( 'invoice' );
  6482. Doo::loadModel ( 'staff' );
  6483. $staff = new staff ();
  6484. Doo::loadModel ( 'invoiceStatistics' );
  6485. Doo::loadModel ( 'invoiceOperationLog' );
  6486. echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  6487. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . $path );
  6488. // print_r ( $exlArray );
  6489. // die ();
  6490. // echo json_encode($exlArray);die;
  6491. foreach ( $exlArray as $key => $value ) {
  6492. // 开票
  6493. $invoice = new invoice ();
  6494. $invoice->invoiceNo = $value ['invoiceNo'];
  6495. $invoice->invoiceType = 0;
  6496. if ($value ['invoiceType'] == '专')
  6497. $invoice->invoiceType = 1;
  6498. $invoice->invoicePrice = $value ['invoicePrice'];
  6499. $invoice->invoiceQuantity = 1;
  6500. $invoice->invoiceUnitPrice = $value ['invoicePrice'];
  6501. $invoice->invoiceTitle = $value ['invoiceTitle'];
  6502. if ($value ['invoiceType'] == '专')
  6503. $invoice->invoiceCompany = $value ['invoiceTitle'];
  6504. $invoice->userName = $value ['userName'];
  6505. $sDetail = $staff->getStaffByName ( $value ['userName'] );
  6506. $invoice->sid = $sDetail ['sid'];
  6507. $invoice->cid = $sDetail ['cid'];
  6508. $invoice->categoryName = $sDetail ['category'];
  6509. $invoice->invoiceElement = $value ['invoiceElement'];
  6510. $invoice->remark = $value ['remark'];
  6511. $invoice->date = $value ['date'];
  6512. $invoice->printTime = $value ['date'];
  6513. $invoice->ipSource = 1;
  6514. $invoice->printStatus = 1;
  6515. $invoice->status = 2;
  6516. $invoice->postStatus = 1;
  6517. $invoice->untreadStatus = 0;
  6518. $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  6519. $iid = $invoice->insert ();
  6520. // 汇总
  6521. $invoiceStatistics = new invoiceStatistics ();
  6522. //
  6523. $item = array (
  6524. 'date' => $value ['date'],
  6525. 'priceClass' => 1,
  6526. 'cid' => $sDetail ['cid'],
  6527. 'staff' => $sDetail ['sid'],
  6528. 'invoicePrice' => $value ['invoicePrice']
  6529. );
  6530. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  6531. $invoiceOperationLog = new invoiceOperationLog ();
  6532. $item = array (
  6533. 'date' => date ( "Y-m-d H:i:s" ),
  6534. 'operation' => date ( "Y-m-d" ) . " 导入",
  6535. 'status' => 1,
  6536. 'img' => $sDetail ['avatar'],
  6537. 'username' => $sDetail ['username'],
  6538. 'uid' => $sDetail ['sid'],
  6539. 'category' => $sDetail ['category'],
  6540. 'iid' => $iid
  6541. );
  6542. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  6543. }
  6544. return '/importInvoice?count=' . count ( $exlArray );
  6545. // return "/keyonline";
  6546. }
  6547. echo 'no file';
  6548. }
  6549. function importInvoiceReceivables() {
  6550. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  6551. $data ['emsg'] = "";
  6552. if ($emsg != "")
  6553. $data ['emsg'] = "请填写完整的数据";
  6554. $data ['time'] = time ();
  6555. $this->render ( "/admin/invoiceReceivablesImport", $data );
  6556. }
  6557. // 导入入账数据
  6558. function importInvoiceReceivablesDo() {
  6559. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  6560. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  6561. if ($path != "") {
  6562. Doo::loadModel ( 'invoiceReceivables' );
  6563. Doo::loadModel ( 'invoice' );
  6564. Doo::loadModel ( 'staff' );
  6565. $staff = new staff ();
  6566. Doo::loadModel ( 'invoiceStatistics' );
  6567. // echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  6568. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path ), 'invoiceReceivables' );
  6569. // print_r ( $exlArray );
  6570. // die ();
  6571. // echo json_encode($exlArray);die;
  6572. foreach ( $exlArray as $key => $value ) {
  6573. // 收款
  6574. $invoiceReceivables = new invoiceReceivables ();
  6575. $invoice = new invoice ();
  6576. $invoiceReceivables->bindStatus = 1;
  6577. $invoiceReceivables->receivablesPrice = $value ['receivablesPrice'];
  6578. $invoiceReceivables->receivablesMessage = $value ['receivablesMessage'];
  6579. $invoiceReceivables->receivablesBank = $value ['receivablesBank'];
  6580. $invoiceReceivables->receivablesDate = $value ['receivablesDate'];
  6581. $sDetail = $staff->getStaffByName ( $value ['receivablesStaff'] );
  6582. $invoiceReceivables->receivablesCategory = $sDetail ['cid'] . ':' . $sDetail ['category'];
  6583. $invoiceReceivables->receivablesStaff = $sDetail ['sid'] . '-' . $sDetail ['username'];
  6584. $invoiceReceivables->receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  6585. $invoiceReceivables->sourcePrice = $value ['sourcePrice'];
  6586. $iDetail = $invoice->getInvoiceByInvoiceNo ( $value ['invoiceNo'] );
  6587. $invoiceReceivables->iid = $iDetail ['iid'];
  6588. $irid = $invoiceReceivables->insert ();
  6589. // 发票绑定收款
  6590. $detail = $iDetail;
  6591. $iridString = "";
  6592. if (empty ( $detail ['irid'] ))
  6593. $iridString = $irid;
  6594. else
  6595. $iridString = $detail ['irid'] . ',' . $irid;
  6596. $item = array (
  6597. 'irid' => $iridString,
  6598. 'iid' => $detail ['iid']
  6599. );
  6600. $invoice->setInvoiceByCondition ( $item );
  6601. // 汇总
  6602. $invoiceStatistics = new invoiceStatistics ();
  6603. // 扣除入账统计金额
  6604. $item = array (
  6605. 'date' => $value ['receivablesDate'],
  6606. 'priceClass' => 3,
  6607. 'cid' => $sDetail ['cid'],
  6608. 'staff' => $sDetail ['sid'],
  6609. // 'irid' => $irid,
  6610. 'accountPrice' => $value ['receivablesPrice']
  6611. );
  6612. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  6613. }
  6614. return '/importInvoiceReceivables?count=' . count ( $exlArray );
  6615. echo 'data count ' . count ( $exlArray );
  6616. die ();
  6617. // return "/keyonline";
  6618. }
  6619. echo 'no file';
  6620. }
  6621. function formatExcelToArrayTrain($file_url = "") {
  6622. if (! file_exists ( $file_url )) {
  6623. return array ();
  6624. }
  6625. // Doo::loadClass ( 'PHPExcel' );
  6626. Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  6627. $PHPExcel = new PHPExcel ();
  6628. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  6629. if (! $PHPReader->canRead ( $file_url )) {
  6630. $PHPReader = new PHPExcel_Reader_Excel5 ();
  6631. if (! $PHPReader->canRead ( $file_url )) {
  6632. echo 'no Excel';
  6633. return;
  6634. }
  6635. }
  6636. $PHPExcel = $PHPReader->load ( $file_url );
  6637. /* * 读取excel文件中的第一个工作表 */
  6638. $currentSheet = $PHPExcel->getSheet ( 0 );
  6639. /* * 取得最大的列号 */
  6640. $allColumn = $currentSheet->getHighestColumn ();
  6641. /* * 取得一共有多少行 */
  6642. $allRow = $currentSheet->getHighestRow ();
  6643. $excel_array = array ();
  6644. // die($file_url);
  6645. $conk = 2;
  6646. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  6647. $excel_column = array ();
  6648. // 后期改进
  6649. if ($allColumn == 'AM')
  6650. $allColumn = 'Z';
  6651. /* * 从第A列开始输出 */
  6652. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  6653. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  6654. if ($val instanceof PHPExcel_RichText)
  6655. $val = $val->__toString ();
  6656. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  6657. // $val = "'" . addslashes ( $val ) . "'";
  6658. if ($currentColumn == 'A') {
  6659. $excel_column ['invoiceTitle'] = $val;
  6660. } elseif ($currentColumn == 'B')
  6661. $excel_column ['invoiceType'] = $val;
  6662. elseif ($currentColumn == 'C') {
  6663. $excel_column ['TIN'] = $val;
  6664. } elseif ($currentColumn == 'D') {
  6665. $excel_column ['address'] = $val;
  6666. } elseif ($currentColumn == 'E') {
  6667. $excel_column ['phone'] = $val;
  6668. } elseif ($currentColumn == 'F') {
  6669. $excel_column ['bank'] = $val;
  6670. } elseif ($currentColumn == 'G') {
  6671. $excel_column ['bankAccount'] = $val;
  6672. } elseif ($currentColumn == 'H') {
  6673. $excel_column ['invoiceElement'] = $val;
  6674. } elseif ($currentColumn == 'I') {
  6675. $excel_column ['invoiceQuantity'] = $val;
  6676. } elseif ($currentColumn == 'J') {
  6677. $excel_column ['invoiceUnitPrice'] = $val;
  6678. } elseif ($currentColumn == 'K') {
  6679. $excel_column ['remark'] = $val;
  6680. } elseif ($currentColumn == 'L') {
  6681. $excel_column ['recipientsAddress'] = $val;
  6682. } elseif ($currentColumn == 'M') {
  6683. $excel_column ['recipients'] = $val;
  6684. } elseif ($currentColumn == 'N') {
  6685. $excel_column ['recipientsPhone'] = $val;
  6686. }
  6687. }
  6688. if (! empty ( $excel_column ['invoiceTitle'] ) && ! empty ( $excel_column ['invoiceQuantity'] ) && ! empty ( $excel_column ['invoiceUnitPrice'] ))
  6689. array_push ( $excel_array, $excel_column );
  6690. }
  6691. return $excel_array;
  6692. }
  6693. /**
  6694. * 格式化excel文件为数组
  6695. * @param unknown_type $file_url
  6696. * @param unknown_type $mcid
  6697. */
  6698. function _format_excel_to_array($file_url = "", $sType = "") {
  6699. if (! file_exists ( $file_url )) {
  6700. return array ();
  6701. }
  6702. Doo::loadClass ( 'PHPExcel' );
  6703. // Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  6704. $PHPExcel = new PHPExcel ();
  6705. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  6706. if (! $PHPReader->canRead ( $file_url )) {
  6707. $PHPReader = new PHPExcel_Reader_Excel5 ();
  6708. if (! $PHPReader->canRead ( $file_url )) {
  6709. echo 'no Excel';
  6710. return;
  6711. }
  6712. }
  6713. $PHPExcel = $PHPReader->load ( $file_url );
  6714. /* * 读取excel文件中的第一个工作表 */
  6715. $currentSheet = $PHPExcel->getSheet ( 0 );
  6716. /* * 取得最大的列号 */
  6717. $allColumn = $currentSheet->getHighestColumn ();
  6718. /* * 取得一共有多少行 */
  6719. $allRow = $currentSheet->getHighestRow ();
  6720. $excel_array = array ();
  6721. // die($file_url);
  6722. $conk = 2;
  6723. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  6724. $excel_column = array ();
  6725. // 后期改进
  6726. if ($allColumn == 'AM')
  6727. $allColumn = 'Z';
  6728. /* * 从第A列开始输出 */
  6729. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  6730. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  6731. if ($val instanceof PHPExcel_RichText)
  6732. $val = $val->__toString ();
  6733. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  6734. // $val = "'" . addslashes ( $val ) . "'";
  6735. if ($sType == 'invoiceReceivables') {
  6736. if ($currentColumn == 'A')
  6737. $excel_column ['invoiceNo'] = $val;
  6738. elseif ($currentColumn == 'B')
  6739. $excel_column ['receivablesPrice'] = $val;
  6740. elseif ($currentColumn == 'C') {
  6741. $excel_column ['receivablesMessage'] = $val;
  6742. } elseif ($currentColumn == 'D') {
  6743. $excel_column ['receivablesBank'] = $val;
  6744. } elseif ($currentColumn == 'E') {
  6745. $excel_column ['receivablesDate'] = $this->excelTime ( $val );
  6746. } elseif ($currentColumn == 'F') {
  6747. $excel_column ['receivablesStaff'] = $val;
  6748. } elseif ($currentColumn == 'G') {
  6749. $excel_column ['sourcePrice'] = $val;
  6750. }
  6751. } elseif ($sType == "invoiceTrain") {
  6752. if ($currentColumn == 'A') {
  6753. $excel_column ['invoiceTitle'] = $val;
  6754. } elseif ($currentColumn == 'B')
  6755. $excel_column ['invoiceType'] = $val;
  6756. elseif ($currentColumn == 'C') {
  6757. $excel_column ['TIN'] = $val;
  6758. } elseif ($currentColumn == 'D') {
  6759. $excel_column ['address'] = $val;
  6760. } elseif ($currentColumn == 'E') {
  6761. $excel_column ['phone'] = $val;
  6762. } elseif ($currentColumn == 'F') {
  6763. $excel_column ['bank'] = $val;
  6764. } elseif ($currentColumn == 'G') {
  6765. $excel_column ['bankAccount'] = $val;
  6766. } elseif ($currentColumn == 'H') {
  6767. $excel_column ['invoiceElement'] = $val;
  6768. } elseif ($currentColumn == 'I') {
  6769. $excel_column ['invoiceQuantity'] = $val;
  6770. } elseif ($currentColumn == 'J') {
  6771. $excel_column ['invoiceUnitPrice'] = $val;
  6772. } elseif ($currentColumn == 'K') {
  6773. $excel_column ['remark'] = $val;
  6774. } elseif ($currentColumn == 'L') {
  6775. $excel_column ['recipientsAddress'] = $val;
  6776. } elseif ($currentColumn == 'M') {
  6777. $excel_column ['recipients'] = $val;
  6778. } elseif ($currentColumn == 'N') {
  6779. $excel_column ['recipientsPhone'] = $val;
  6780. }
  6781. } else {
  6782. if ($currentColumn == 'A')
  6783. $excel_column ['invoiceNo'] = $val;
  6784. elseif ($currentColumn == 'B')
  6785. $excel_column ['invoiceType'] = $val;
  6786. elseif ($currentColumn == 'C') {
  6787. $excel_column ['invoicePrice'] = $val;
  6788. } elseif ($currentColumn == 'D') {
  6789. $excel_column ['invoiceTitle'] = $val;
  6790. } elseif ($currentColumn == 'E') {
  6791. $excel_column ['userName'] = $val;
  6792. } elseif ($currentColumn == 'F') {
  6793. $excel_column ['categoryName'] = $val;
  6794. } elseif ($currentColumn == 'G') {
  6795. $excel_column ['invoiceElement'] = $val;
  6796. } elseif ($currentColumn == 'H') {
  6797. $excel_column ['remark'] = $val;
  6798. } elseif ($currentColumn == 'I') {
  6799. $excel_column ['date'] = $this->excelTime ( $val );
  6800. }
  6801. }
  6802. }
  6803. array_push ( $excel_array, $excel_column );
  6804. }
  6805. return $excel_array;
  6806. }
  6807. function excelTime($date, $time = false) {
  6808. if (function_exists ( 'GregorianToJD' )) {
  6809. if (is_numeric ( $date )) {
  6810. $jd = GregorianToJD ( 1, 1, 1970 );
  6811. $gregorian = JDToGregorian ( $jd + intval ( $date ) - 25569 );
  6812. $date = explode ( '/', $gregorian );
  6813. $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" : '');
  6814. return $date_str;
  6815. }
  6816. } else {
  6817. $date = $date > 25568 ? $date + 1 : 25569;
  6818. /* There was a bug if Converting date before 1-1-1970 (tstamp 0) */
  6819. $ofs = (70 * 365 + 17 + 2) * 86400;
  6820. $date = date ( "Y-m-d", ($date * 86400) - $ofs ) . ($time ? " 00:00:00" : '');
  6821. }
  6822. return $date;
  6823. }
  6824. /**
  6825. * 旧输入导入
  6826. */
  6827. function _GetFileEXT($filename) {
  6828. $pics = explode ( '.', $filename );
  6829. $num = count ( $pics );
  6830. return $pics [$num - 1];
  6831. }
  6832. function showCache($path = "", $sid = 0) {
  6833. // if (file_exists ( $path )) {
  6834. // $htm = file_get_contents ( $path );
  6835. // } else {
  6836. Doo::loadModel ( 'invoiceStatistics' );
  6837. $invoiceStatistics = new invoiceStatistics ();
  6838. $isBriefly = $invoiceStatistics->getBrieflyStatistics ( $sid );
  6839. $htm = '<tr><th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计开票</th>
  6840. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['invoicePrice'] . '</td>
  6841. <th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计入账</th>
  6842. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['accountPrice'] . '</td></tr>';
  6843. /*
  6844. * '<tr><th class="taC">今年累计开票</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['invoicePrice'] . '</td> <th class="taC">今年累计入账</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['accountPrice'] . '</td></tr>';
  6845. */
  6846. file_put_contents ( $path, $htm );
  6847. // }
  6848. return $htm;
  6849. }
  6850. /**
  6851. * 生成token
  6852. * @return string
  6853. */
  6854. function set_token() {
  6855. $str = md5 ( uniqid ( md5 ( microtime ( true ) ), true ) ); // 生成一个不会重复的字符串
  6856. $str = sha1 ( $str ); // 加密
  6857. return $str;
  6858. }
  6859. /**
  6860. * 获取get或者POST值
  6861. *
  6862. * @param string $name 属性名称
  6863. * @return fixed 值
  6864. */
  6865. function get_args($name) {
  6866. if (isset ( $_GET [$name] )) {
  6867. if (is_array ( $_GET [$name] ))
  6868. return $_GET [$name];
  6869. else
  6870. return addslashes ( $_GET [$name] );
  6871. } elseif (isset ( $_POST [$name] )) {
  6872. if (is_array ( $_POST [$name] ))
  6873. return $_POST [$name];
  6874. else
  6875. return addslashes ( $_POST [$name] );
  6876. } else
  6877. return false;
  6878. }
  6879. function SafeFilter(&$arr) {
  6880. $ra = Array (
  6881. '/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/',
  6882. '/script/',
  6883. '/javascript/',
  6884. '/vbscript/',
  6885. '/expression/',
  6886. '/applet/',
  6887. '/meta/',
  6888. '/xml/',
  6889. '/blink/',
  6890. '/link/',
  6891. '/style/',
  6892. '/embed/',
  6893. '/object/',
  6894. '/frame/',
  6895. '/layer/',
  6896. '/title/',
  6897. '/bgsound/',
  6898. '/base/',
  6899. '/onload/',
  6900. '/onunload/',
  6901. '/onchange/',
  6902. '/onsubmit/',
  6903. '/onreset/',
  6904. '/onselect/',
  6905. '/onblur/',
  6906. '/onfocus/',
  6907. '/onabort/',
  6908. '/onkeydown/',
  6909. '/onkeypress/',
  6910. '/onkeyup/',
  6911. '/onclick/',
  6912. '/ondblclick/',
  6913. '/onmousedown/',
  6914. '/onmousemove/',
  6915. '/onmouseout/',
  6916. '/onmouseover/',
  6917. '/onmouseup/',
  6918. '/onunload/'
  6919. );
  6920. if (is_array ( $arr )) {
  6921. foreach ( $arr as $key => $value ) {
  6922. if (! is_array ( $value )) {
  6923. if (! get_magic_quotes_gpc ()) // 不对magic_quotes_gpc转义过的字符使用addslashes(),避免双重转义。
  6924. {
  6925. $value = addslashes ( $value ); // 给单引号(')、双引号(")、反斜线(\)与 NUL(NULL 字符)加上反斜线转义
  6926. }
  6927. $value = preg_replace ( $ra, '', $value ); // 删除非打印字符,粗暴式过滤xss可疑字符串
  6928. $arr [$key] = htmlentities ( strip_tags ( $value ) ); // 去除 HTML 和 PHP 标记并转换为 HTML 实体
  6929. } else {
  6930. SafeFilter ( $arr [$key] );
  6931. }
  6932. }
  6933. }
  6934. }
  6935. /**
  6936. * Escape String
  6937. *
  6938. * @access public
  6939. * @param string
  6940. * @param bool whether or not the string will be used in a LIKE condition
  6941. * @return string
  6942. */
  6943. function escape_str($str, $like = FALSE) {
  6944. if (is_array ( $str )) {
  6945. foreach ( $str as $key => $val ) {
  6946. $str [$key] = $this->escape_str ( $val, $like );
  6947. }
  6948. return $str;
  6949. }
  6950. var_dump ( Doo::db ()->getDbObject () );
  6951. die ();
  6952. if (function_exists ( 'mysql_real_escape_string' ) and is_resource ( Doo::db ()->getDbObject () )) { // Doo::db ()->getDbObject()
  6953. $str = mysql_real_escape_string ( $str, Doo::db ()->getDbObject () );
  6954. } elseif (function_exists ( 'mysql_escape_string' )) {
  6955. $str = mysql_escape_string ( $str );
  6956. } else {
  6957. $str = addslashes ( $str );
  6958. }
  6959. // escape LIKE condition wildcards
  6960. if ($like === TRUE) {
  6961. $str = str_replace ( array (
  6962. '%',
  6963. '_'
  6964. ), array (
  6965. '\\%',
  6966. '\\_'
  6967. ), $str );
  6968. }
  6969. return $str;
  6970. }
  6971. /**
  6972. * 获得分页数据
  6973. * @param unknown_type $table
  6974. * @param unknown_type $condition
  6975. * @param unknown_type $on_page
  6976. * @param unknown_type $page_size
  6977. */
  6978. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  6979. $page_c = "";
  6980. $page ['previous'] = $this->get_previous ( $on_page );
  6981. $page ['on_page'] = $on_page;
  6982. $total_count = $this->get_table_count ( $table, $condition );
  6983. $total = intval ( $total_count / $page_size );
  6984. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  6985. $page ['total_data'] = $total_count;
  6986. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  6987. $i = 1;
  6988. $page_max = 1;
  6989. $page_width = 3;
  6990. if ($on_page >= $page_width) {
  6991. $page_max = intval ( $on_page / $page_width ) + 1;
  6992. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  6993. }
  6994. for(; $i <= $page ['total_page']; $i ++) {
  6995. if ($i == $on_page)
  6996. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  6997. else
  6998. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  6999. if ($i == ($page_width * $page_max))
  7000. break;
  7001. }
  7002. $page ['page'] = $page_c;
  7003. $page ['lower'] = (-- $on_page) * $page_size;
  7004. return $page;
  7005. }
  7006. /**
  7007. * 获取上一页
  7008. * @param unknown_type $on_page
  7009. */
  7010. function get_previous($on_page = 1) {
  7011. return $on_page != 0 ? $on_page - 1 : $on_page;
  7012. }
  7013. /**
  7014. * 获取总页数
  7015. * @param unknown_type $table
  7016. * @param unknown_type $condition
  7017. */
  7018. public function get_table_count($table = "", $condition = "") {
  7019. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  7020. $sql = "select count(*) as count from " . $table . " where " . $condition;
  7021. // echo $sql;die;
  7022. $query = Doo::db ()->query ( $sql );
  7023. $result = $query->fetch ();
  7024. return $result ['count'];
  7025. }
  7026. /**
  7027. * 获得分页数据
  7028. * @param unknown_type $table
  7029. * @param unknown_type $condition
  7030. * @param unknown_type $on_page
  7031. * @param unknown_type $page_size
  7032. */
  7033. function getPageBySql($sql = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  7034. $page_c = "";
  7035. $page ['previous'] = $this->get_previous ( $on_page );
  7036. $page ['on_page'] = $on_page;
  7037. $total_count = $this->getTableCountBySql ( $sql );
  7038. $total = intval ( $total_count / $page_size );
  7039. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  7040. $page ['total_data'] = $total_count;
  7041. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  7042. $i = 1;
  7043. $page_max = 1;
  7044. $page_width = 3;
  7045. if ($on_page >= $page_width) {
  7046. $page_max = intval ( $on_page / $page_width ) + 1;
  7047. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  7048. }
  7049. for(; $i <= $page ['total_page']; $i ++) {
  7050. if ($i == $on_page)
  7051. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  7052. else
  7053. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  7054. if ($i == ($page_width * $page_max))
  7055. break;
  7056. }
  7057. $page ['page'] = $page_c;
  7058. $page ['lower'] = (-- $on_page) * $page_size;
  7059. return $page;
  7060. }
  7061. /**
  7062. * 获得总页数 sql
  7063. * @param string $type
  7064. * @return boolean[]
  7065. */
  7066. public function getTableCountBySql($sql = "") {
  7067. $query = Doo::db ()->query ( $sql );
  7068. $result = $query->fetchAll ();
  7069. return count ( $result );
  7070. }
  7071. function isInvoiceNew($type = "GLOBAL") {
  7072. Doo::loadModel ( 'invoice' );
  7073. $invoice = new invoice ();
  7074. Doo::loadModel ( 'invoiceReceivables' );
  7075. $invoiceReceivables = new invoiceReceivables ();
  7076. Doo::loadModel ( 'staff' );
  7077. $staff = new staff ();
  7078. $st = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  7079. // 我的发票待处理
  7080. $pendingInvoice = $invoice->getOne ( array ( // or (status=2 and printStatus=1 and untreadStatus=0 ) or (status=2 and printStatus=1 and untreadStatus=2 )
  7081. 'where' => "(status=3 or status=4) and isDelete=0 and sid=" . $st [0] ['sid'],
  7082. 'desc' => 'iid',
  7083. 'asArray' => TRUE
  7084. ) );
  7085. // 我的收款待入账
  7086. /*
  7087. * $myClaim = $invoiceReceivables->getOne ( array ( 'where' => " receivablesStaff like '" . $st [0] ['sid'] . "-%' and receivablesCategory like '" . $st [0] ['cid'] . ":%' and bindStatus=0", 'desc' => 'irid', 'asArray' => TRUE ) );
  7088. */
  7089. // 发票审批
  7090. $approval = $invoice->getOne ( array (
  7091. 'where' => 'status=1 and pendingApprovals=' . $st [0] ['sid'],
  7092. 'desc' => 'iid',
  7093. 'asArray' => true
  7094. ) );
  7095. // 发票邮寄
  7096. $post = $invoice->getOne ( array (
  7097. 'where' => "postStatus=0 and printStatus=1 and isDelete=0 and doPost=1 and status=2",
  7098. 'asArray' => TRUE
  7099. ) );
  7100. // 发票打印
  7101. $print = $invoice->getOne ( array (
  7102. 'where' => "status=2 and printStatus=0 and untreadStatus=0 and moldManage like '%[\"" . $st [0] ['sid'] . "\",%'",
  7103. 'desc' => 'iid',
  7104. 'asArray' => TRUE
  7105. ) );
  7106. // 发票退票 printStatus=1 and
  7107. $untread = $invoice->getOne ( array (
  7108. 'where' => " untreadStatus=1 and status=2 ",
  7109. 'asArray' => TRUE
  7110. ) );
  7111. $new = array (
  7112. 'GLOBAL' => FALSE,
  7113. 'pendingInvoice' => FALSE,
  7114. // 'myClaim' => FALSE,
  7115. 'approval' => FALSE,
  7116. 'post' => FALSE,
  7117. 'print' => FALSE,
  7118. 'untread' => FALSE
  7119. );
  7120. // || ! empty ( $myClaim )
  7121. if (! empty ( $pendingInvoice ) || ! empty ( $approval ) || ! empty ( $post ) || ! empty ( $print ) || ! empty ( $untread ))
  7122. $new ['GLOBAL'] = TRUE;
  7123. if (! empty ( $pendingInvoice ))
  7124. $new ['pendingInvoice'] = TRUE;
  7125. // if (! empty ( $myClaim ))
  7126. // $new ['myClaim'] = TRUE;
  7127. if (! empty ( $approval ))
  7128. $new ['approval'] = TRUE;
  7129. if (! empty ( $post ))
  7130. $new ['post'] = TRUE;
  7131. if (! empty ( $print ))
  7132. $new ['print'] = TRUE;
  7133. if (! empty ( $untread ))
  7134. $new ['untread'] = TRUE;
  7135. return $new;
  7136. }
  7137. function setWXMsg($rid, $typeMsg = '') {
  7138. Doo::loadModel ( 'invoice' );
  7139. $invoice = new invoice ();
  7140. $invoiceDetail = $invoice->getOne ( array (
  7141. 'where' => 'iid=' . $rid,
  7142. 'asArray' => true
  7143. ) );
  7144. if (! empty ( $invoiceDetail )) {
  7145. Doo::loadModel ( 'staff' );
  7146. $staff = new staff ();
  7147. $staffmsg = $staff->getOne ( array (
  7148. 'where' => "sid='" . $invoiceDetail ['sid'] . "'",
  7149. 'asArray' => TRUE
  7150. ) );
  7151. if (! empty ( $staffmsg ['wxid'] )) {
  7152. require_once (SITE_PATH . '/protected/class/client.php');
  7153. $client = new client ( 'http://m.cld.smartcost.com.cn/' );
  7154. $user = $staffmsg ['wxid'];
  7155. $expCom = explode ( ":", $invoiceDetail ['expressCompany'] );
  7156. if (empty ( $expCom ))
  7157. $expCom [0] = '';
  7158. $msg = "";
  7159. if (empty ( $typeMsg ))
  7160. $msg = '太好了,您的发票' . $invoiceDetail ['invoiceSerial'] . ' 已邮寄 ' . $expCom [0] . ' ,快递号: <a href="https://m.kuaidi100.com/result.jsp?nu=' . $invoiceDetail ['expressNumber'] . '" >' . $invoiceDetail ['expressNumber'] . '</a>';
  7161. elseif ($typeMsg == "PRINT")
  7162. $msg = '太好了,您的发票已打印完成。';
  7163. $result = $client->SendMsg ( $user, $msg, 'text' );
  7164. }
  7165. }
  7166. }
  7167. /**
  7168. * 获取微信部门
  7169. * @param string $category
  7170. * @return number|mixed
  7171. */
  7172. function getToparty($category = '') {
  7173. $token = $this->getAccessToken (); //
  7174. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token={$token}&id=5" ), true );
  7175. $toparty = 0;
  7176. foreach ( $result ['department'] as $key => $value ) {
  7177. if ($value ['name'] == $category)
  7178. $toparty = $value ['id'];
  7179. }
  7180. return $toparty;
  7181. }
  7182. /**
  7183. * 获得某部门下的用户
  7184. * @param string $toparty
  7185. */
  7186. function getUserByToparty($toparty = '') {
  7187. $token = $this->getAccessToken (); //
  7188. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token={$token}&department_id={$toparty}" ), true );
  7189. $userList = array ();
  7190. foreach ( $result ['userlist'] as $key => $value ) {
  7191. array_push ( $userList, "'" . $value ['userid'] . "'" );
  7192. }
  7193. return $userList;
  7194. }
  7195. function msgSendToparty($msg, $title, $url, $toparty, $text = '') {
  7196. $token = $this->getAccessToken ();
  7197. if ($text == 'text') {
  7198. $data = '{
  7199. "touser": "' . $toparty . '",
  7200. "toparty": "",
  7201. "totag": "",
  7202. "msgtype": "text",
  7203. "agentid": 1000002,
  7204. "text": {
  7205. "content": "' . $msg . '"
  7206. },
  7207. "safe":0
  7208. }';
  7209. }
  7210. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  7211. if ($result->errmsg != 'ok') {
  7212. return 0;
  7213. } else {
  7214. return 1;
  7215. }
  7216. }
  7217. /**
  7218. * 获得可以发送微信用户列表
  7219. * @param string $category
  7220. * @return string
  7221. */
  7222. function getWxidByCategory($category = "") {
  7223. if (empty ( $category ))
  7224. return "";
  7225. Doo::loadModel ( 'staff' );
  7226. $staff = new staff ();
  7227. $toparty = $this->getToparty ( $category );
  7228. $wxList = array ();
  7229. $wxString = "";
  7230. if (! empty ( $toparty )) {
  7231. $userList = $this->getUserByToparty ( $toparty );
  7232. $userCon = implode ( ',', $userList );
  7233. // echo $userCon;
  7234. $sidList = $staff->getStaffByWxid ( $userCon );
  7235. foreach ( $sidList as $key => $value ) {
  7236. $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  7237. if ($falg) {
  7238. array_push ( $wxList, $value ['wxid'] );
  7239. }
  7240. }
  7241. $wxString = implode ( '|', $wxList );
  7242. }
  7243. return $wxString;
  7244. }
  7245. /**
  7246. * 读取发送信息规则判断是否需要发送
  7247. * @param number $sid
  7248. * @param string $sendType
  7249. * @return boolean
  7250. */
  7251. function isSendNotification($sid = 0, $sendType = '') {
  7252. Doo::loadModel ( "notificationConf" );
  7253. $notificationConf = new notificationConf ();
  7254. $detail = $notificationConf->getNotificationConfBySid ( $sid );
  7255. $conf = array ();
  7256. $sendFlag = true;
  7257. if (! empty ( $detail )) {
  7258. $conf = json_decode ( $detail ['conf'], true );
  7259. if (! empty ( $sendType )) {
  7260. if (isset ( $conf [$sendType] )) {
  7261. if ($conf [$sendType] == "CLOSE")
  7262. $sendFlag = false;
  7263. elseif ($conf [$sendType] == "Weekend") {
  7264. $day = date ( "w" );
  7265. if (1 <= $day && 5 >= $day)
  7266. $sendFlag = false;
  7267. } elseif ($conf [$sendType] == "OneToFriday") {
  7268. $day = date ( "w" );
  7269. if (0 == $day || 6 == $day)
  7270. $sendFlag = false;
  7271. }
  7272. }
  7273. } else
  7274. $sendFlag = false;
  7275. }
  7276. return $sendFlag;
  7277. }
  7278. /**
  7279. * 根据规则发送信息
  7280. * @param unknown $msg
  7281. * @param unknown $title
  7282. * @param unknown $url
  7283. * @param unknown $user
  7284. * @param string $text
  7285. * @return number
  7286. */
  7287. private function msgSend($msg, $title, $url, $user, $sid = 0, $sendType = '') {
  7288. $token = $this->getAccessToken ();
  7289. $falg = $this->isSendNotification ( $sid, $sendType );
  7290. // if ($text == 'text') {
  7291. // $data = '{
  7292. // "touser": "' . $user . '",
  7293. // "toparty": "",
  7294. // "totag": "",
  7295. // "msgtype": "text",
  7296. // "agentid": 1000002,
  7297. // "text": {
  7298. // "content": "' . $msg . '"
  7299. // },
  7300. // "safe":0
  7301. // }';
  7302. // } else {
  7303. $data = '{
  7304. "touser": "' . $user . '",
  7305. "toparty": "",
  7306. "totag": "",
  7307. "msgtype": "news",
  7308. "agentid": 1000002,
  7309. "news": {
  7310. "articles":[
  7311. {
  7312. "title": "' . $title . '",
  7313. "description": "' . $msg . '",
  7314. "url": "' . $url . '",
  7315. "picurl": ""
  7316. }
  7317. ]
  7318. }
  7319. }';
  7320. // }
  7321. if ($falg) {
  7322. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  7323. if ($result->errmsg != 'ok') {
  7324. return 0;
  7325. } else {
  7326. return 1;
  7327. }
  7328. } else
  7329. return 0;
  7330. }
  7331. private function getAccessToken() {
  7332. // access_token 应该全局存储与更新,以下代码以写入到文件中做示例
  7333. // $file = './access_token.txt';
  7334. // $data = json_decode ( file_get_contents ( $file ) );
  7335. // if ($data->expire_time < time () or ! $data->expire_time) {
  7336. // 如果是企业号用以下URL获取access_token
  7337. $url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$this->appId&corpsecret=$this->appSecret";
  7338. // $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$this->appId&secret=$this->appSecret";
  7339. $res = json_decode ( $this->httpGet ( $url ) );
  7340. $access_token = $res->access_token;
  7341. // echo $access_token;
  7342. // if ($access_token) {
  7343. // $data->expire_time = time () + 7000;
  7344. // $data->access_token = $access_token;
  7345. // $fp = fopen ( $file, "w" );
  7346. // fwrite ( $fp, json_encode ( $data ) );
  7347. // fclose ( $fp );
  7348. // }
  7349. // } else {
  7350. // $access_token = $data->access_token;
  7351. // }
  7352. return $access_token;
  7353. }
  7354. private function httpGet($url) {
  7355. $curl = curl_init ();
  7356. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  7357. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  7358. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  7359. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  7360. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  7361. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  7362. curl_setopt ( $curl, CURLOPT_URL, $url );
  7363. $res = curl_exec ( $curl );
  7364. curl_close ( $curl );
  7365. return $res;
  7366. }
  7367. private function httpPost($url, $data) {
  7368. $curl = curl_init ();
  7369. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  7370. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  7371. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  7372. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  7373. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  7374. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  7375. curl_setopt ( $curl, CURLOPT_URL, $url );
  7376. curl_setopt ( $curl, CURLOPT_POST, 1 );
  7377. curl_setopt ( $curl, CURLOPT_POSTFIELDS, $data );
  7378. $res = curl_exec ( $curl );
  7379. curl_close ( $curl );
  7380. return $res;
  7381. }
  7382. }
  7383. ?>