InvoiceController.php 316 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636
  1. <?php
  2. /**
  3. * 开票功能控制器
  4. * @author CP
  5. * @version 1.0
  6. * @namespace invoice
  7. * @package invoiceController
  8. */
  9. class InvoiceController extends DooController {
  10. public $staff;
  11. public $NEW;
  12. public $data;
  13. private $INVOICEKEY = "APPROVAL";
  14. private $INVOICECOLLECTPATH = "protected/cache/invoiceCollect/";
  15. private $ACTION = '';
  16. private $appId = 'wx3ee46531947a1384';
  17. private $appSecret = 'awGWzy3J5q_96VXKBLA2BQ9RpiT0LiPXnkMF-xV6h5o'; // awGWzy3J5q_96VXKBLA2BXU6mVCGynPGD-sxUCsdNDE //'PeiQVH8tbQE7pM9pVO4AIPlX9FFNpwu7O6Iy6VFcAVtpjTA3Qn42dbNmktBFkUHo';
  18. public function beforeRun($resource, $action) {
  19. Doo::loadModel ( "invoiceManage" );
  20. $invoiceManage = new invoiceManage ();
  21. Doo::loadClass ( 'XDeode' );
  22. $XDeode = new XDeode ( 5 );
  23. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  24. header ( 'Content-Type:text/html;charset=utf-8' );
  25. $moldList = $invoiceManage->getInvoiceByStaff ( $sid );
  26. if (empty ( $moldList )) {
  27. $flag = false;
  28. $uGroups = 'ordinary';
  29. if (Doo::acl ()->isAllowed ( $uGroups, $resource, $action )) {
  30. $flag = true;
  31. }
  32. } else {
  33. $flag = false;
  34. array_push ( $moldList, array (
  35. 'mold' => 'ordinary'
  36. ) );
  37. // 删除审批人后-加入权限问题-暂时关闭
  38. $fileInvoice = file_get_contents ( "protected/config/invoice/invoice.ini" );
  39. $fiML = json_decode ( $fileInvoice, true );
  40. if (empty ( $fiML ))
  41. $fiML = array ();
  42. foreach ( $fiML as $key => $value ) {
  43. $sidList = explode ( ',', $value );
  44. foreach ( $sidList as $k => $v ) {
  45. if ($v == $sid) {
  46. array_push ( $moldList, array (
  47. 'mold' => $key
  48. ) );
  49. break;
  50. }
  51. }
  52. }
  53. foreach ( $moldList as $value ) {
  54. if (Doo::acl ()->isAllowed ( $value ['mold'], $resource, $action )) {
  55. $flag = true;
  56. break;
  57. }
  58. }
  59. }
  60. /*
  61. * Doo::acl()->isAllowed($uGroups['groups'], $resource, $action);
  62. */
  63. // 单独判断办事处汇总的访问权限 invoiceAggregateCategoryDetail,invoiceAggregateStaffDetail
  64. if ($action == 'invoiceAggregateCategoryDetail' || $action == 'invoiceAggregateStaffDetail') {
  65. Doo::loadModel ( "invoiceCategoryManage" );
  66. $invoiceCategoryManage = new invoiceCategoryManage ();
  67. $icm = $invoiceCategoryManage->getInvoiceCMByStaff ( $sid );
  68. if (empty ( $icm ))
  69. die ( 'illegal request-iacd' );
  70. }
  71. // 单独判断应收款访问权限
  72. if ($action == 'invoiceAggregateCompanyDetail') {
  73. Doo::loadModel ( "invoiceCompanyManage" );
  74. $invoiceCompanyManage = new invoiceCompanyManage ();
  75. $icm = $invoiceCompanyManage->getInvoiceCMByStaff ( $sid );
  76. if (empty ( $icm ))
  77. die ( 'illegal request' );
  78. }
  79. // 主权限获得与判断
  80. Doo::loadModel ( 'staff' );
  81. $staff = new staff ();
  82. $detail = $staff->getStaffBySid ( $_COOKIE ["staff"] );
  83. $accessModular = 'INVOICE';
  84. if (empty ( $detail ['cldAccessArray'] ))
  85. die ( 'illegal request' );
  86. else {
  87. if (in_array ( $accessModular, $detail ['cldAccessArray'] )) {
  88. if (Doo::acl ()->isAllowed ( $accessModular, $resource, $action )) {
  89. $flag = true;
  90. } else {
  91. $flag = false;
  92. }
  93. } else {
  94. die ( 'illegal request' );
  95. }
  96. }
  97. if (! $flag)
  98. die ( 'illegal request' );
  99. }
  100. function __construct() {
  101. if (isset ( $_COOKIE ["staff"] )) {
  102. if (! empty ( $_COOKIE ["staff"] )) {
  103. Doo::loadModel ( 'staff' );
  104. $staff = new staff ();
  105. $uriPartsOrig = explode ( '/', $_SERVER ['REQUEST_URI'] );
  106. $this->ACTION = $uriPartsOrig [1];
  107. $this->data ['new'] = $this->isInvoiceNew ();
  108. $this->staff = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  109. $this->data ['isStaffCompleteMsg'] = false;
  110. $detail = $staff->checkStaffInfoIsComplete ( $_COOKIE ["staff"] );
  111. if (! empty ( $detail ))
  112. $this->data ['isStaffCompleteMsg'] = true;
  113. return "/";
  114. }
  115. }
  116. Doo::loadCore ( 'uri/DooUriRouter' );
  117. $router = new DooUriRouter ();
  118. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  119. if ($routeRs ['1'] != "login") {
  120. header ( 'Content-Type:text/html;charset=utf-8' );
  121. @header ( "Location: /login" );
  122. }
  123. }
  124. function testSend() {
  125. // 测试根据规则发送信息 普通发送
  126. // $pendingApprovalsSid = 41;
  127. // Doo::loadModel ( 'staff' );
  128. // $staff = new staff ();
  129. // $username2 = $staff->getOne ( array ( 'select' => 'wxid', 'where' => 'sid=' . $pendingApprovalsSid, 'asArray' => TRUE ) );
  130. // // 发送微信审批通知
  131. // $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  132. // $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  133. // Doo::loadModel ( 'staff' );
  134. // $staff = new staff ();
  135. // $toparty = $this->getToparty ( '广东办' );
  136. // $wxList = array ();
  137. // if (! empty ( $toparty )) {
  138. // $userList = $this->getUserByToparty ( $toparty );
  139. // $userCon = implode ( ',', $userList );
  140. // // echo $userCon;
  141. // $sidList = $staff->getStaffByWxid ( $userCon );
  142. // foreach ( $sidList as $key => $value ) {
  143. // $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  144. // if ($falg) {
  145. // array_push ( $wxList, $value ['wxid'] );
  146. // }
  147. // }
  148. // $wxString = implode ( '|', $wxList );
  149. // print_r ( $wxList );
  150. // echo $wxString;
  151. // }
  152. // 测试发送
  153. /*
  154. * //$toparty = $this->getWxidByCategory( $receivablesCategory [1] ); $toparty = $this->getToparty ( $receivablesCategory [1] ); $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。'; if ($toparty != 0) $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  155. */
  156. // print_r ( $userList );
  157. // $msTouser='caipin|outaozhen';
  158. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  159. // $title2 = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  160. // $hfreult = $this->msgSend ( '', $title2, '', 'outaozhen' );
  161. // $toparty= $this->getToparty('广东办');
  162. // $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  163. // $toparty = 26;
  164. // $msg = '';
  165. // $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/1.html';
  166. // $hfreult = $this->msgSendToparty ( $msg, '', '', $toparty,'text' );
  167. }
  168. function invoice() {
  169. Doo::loadModel ( 'invoice' );
  170. $invoice = new invoice ();
  171. Doo::loadModel ( 'express' );
  172. $express = new express ();
  173. $expressList = $express->getExpressByAll ();
  174. $this->data ['expressList'] = $expressList;
  175. // Doo::loadModel ( 'invoiceReceivables' );
  176. // $invoiceReceivables = new invoiceReceivables ();
  177. // $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  178. Doo::loadClass ( 'XDeode' );
  179. $XDeode = new XDeode ( 5 );
  180. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  181. Doo::loadModel ( 'invoiceStatistics' );
  182. $invoiceStatistics = new invoiceStatistics ();
  183. $isMonth = $invoiceStatistics->getStatisticsByMonth ( $sid );
  184. // 缓存统计结果
  185. $year = date ( "Y" );
  186. $tmp_date = date ( "Ym" );
  187. $tmp_year = substr ( $tmp_date, 0, 4 );
  188. $tmp_mon = substr ( $tmp_date, 4, 2 );
  189. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  190. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  191. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . "_" . $sid . ".htm";
  192. if (is_file ( $path ))
  193. $htm = file_get_contents ( $path );
  194. else
  195. $htm = $this->showCache ( $path, $sid );
  196. $invoiceList = $invoice->getMyInvoice ( $sid );
  197. $sql = 'status=2 and printStatus=1 and irid!="" and sid=' . $sid;
  198. $list = $invoice->getInvoiceByUntreadStatusPage ( 4, $sql );
  199. // 我的待入账发票 and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  200. $sql = "status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid=" . $sid;
  201. $myInvoiceUnAccount = $invoice->getInvoiceByUntreadStatusPage ( 4, $sql );
  202. // 获得已退票功能
  203. $untreadStatusList = $invoice->getMyInvoiceByUntreadStatus ( 2, 0, 5, $sid );
  204. $this->data ['untreadStatusList'] = $untreadStatusList;
  205. // print_r($untreadStatusList);
  206. $this->data ['isMonth'] = $isMonth;
  207. $this->data ['htm'] = $htm;
  208. $this->data ['invoiceList'] = $invoiceList;
  209. $this->data ['receivablesList'] = $list;
  210. $this->data ['myInvoiceUnAccount'] = $myInvoiceUnAccount;
  211. $this->data ['memu'] = "invoice";
  212. $this->data ['staff'] = $this->staff;
  213. $this->data ['receiptMemu'] = 'invoice';
  214. $this->render ( "/admin/invoice", $this->data );
  215. }
  216. function invoiceExpress() {
  217. $expressCom = isset ( $this->params ['expressCom'] ) ? $this->params ['expressCom'] : "";
  218. $expressNumber = isset ( $this->params ['expressNumber'] ) ? $this->params ['expressNumber'] : "";
  219. $this->data ['expressCom'] = $expressCom;
  220. $this->data ['expressNumber'] = $expressNumber;
  221. $this->render ( "/admin/invoiceExpress", $this->data );
  222. }
  223. function invoiceAdd() {
  224. session_start ();
  225. /*Doo::loadModel ( 'invoice' );
  226. $invoice = new invoice ();
  227. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );*/
  228. Doo::loadModel ( 'L_category' );
  229. $lCategory = new L_category ();
  230. $category = $lCategory->find ( array (
  231. 'asArray' => true
  232. ) );
  233. $this->data ['category'] = $category;
  234. Doo::loadModel ( 'invoiceTraining' );
  235. $invoiceTraining = new invoiceTraining ();
  236. $itList = $invoiceTraining->getInvoiceTrainingByCid ( $this->staff [0] ['cid'] );
  237. Doo::loadModel ( 'receipt' );
  238. $receipt = new receipt ();
  239. foreach ( $itList as $key => $value ) { // 不展示已结算完结的培训班
  240. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $value ['itid'] );
  241. if (! empty ( $receiptDetail )) {
  242. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9) {
  243. unset ( $itList [$key] );
  244. }
  245. }
  246. }
  247. $this->data ['itList'] = $itList;
  248. $token = $this->set_token ();
  249. $tokenTime=time().rand(5, 15);
  250. $_SESSION ['token_' . $this->staff [0] ['sidKey'].'_'.$tokenTime] = $token;
  251. $this->data ['token'] = $token;
  252. $this->data['tokenTime']=$tokenTime;
  253. $this->data ['memu'] = "invoice";
  254. $this->data ['staff'] = $this->staff;
  255. $this->data ['receiptMemu'] = 'invoice';
  256. $this->render ( "/admin/invoiceAdd", $this->data );
  257. }
  258. /**
  259. * 自更新发票信息库
  260. * @param unknown $invoicePrintDetail
  261. */
  262. function autoUpdateInvoiceInfoBase($invoicePrintDetail) {
  263. // 发票信息库
  264. Doo::loadModel ( 'invoiceInfoBase' );
  265. $invoiceInfoBase = new invoiceInfoBase ();
  266. $updateDate = strtotime ( $invoicePrintDetail ['date'] );
  267. $TIN = $invoicePrintDetail ['TIN'];
  268. $invoiceTitle = $invoicePrintDetail ['invoiceTitle'];
  269. if (empty ( $invoiceTitle ))
  270. $invoiceTitle = $invoicePrintDetail ['invoiceCompany'];
  271. $IIBList = $invoiceInfoBase->getInvoiceInfoByTT ( $TIN, $invoiceTitle );
  272. // 确认有该条发票信息
  273. $invoiceInfoBase = new invoiceInfoBase ();
  274. if (! empty ( $IIBList )) {
  275. // 发票库里的信息数量
  276. $IIBListCount = count ( $IIBList );
  277. if ($IIBListCount == 1) { // 更新发票--提交是最新的时间
  278. $item = array (
  279. 'iibID' => $IIBList [0] ['iibID'],
  280. 'invoiceTitle' => $invoiceTitle,
  281. 'TIN' => $TIN
  282. );
  283. if (! empty ( $invoicePrintDetail ['address'] )) {
  284. $item += array (
  285. 'address' => $invoicePrintDetail ['address']
  286. );
  287. }
  288. if (! empty ( $invoicePrintDetail ['phone'] )) {
  289. $item += array (
  290. 'phone' => $invoicePrintDetail ['phone']
  291. );
  292. }
  293. if (! empty ( $invoicePrintDetail ['bank'] )) {
  294. $item += array (
  295. 'bank' => $invoicePrintDetail ['bank']
  296. );
  297. }
  298. if (! empty ( $invoicePrintDetail ['bankAccount'] )) {
  299. $item += array (
  300. 'bankAccount' => $invoicePrintDetail ['bankAccount']
  301. );
  302. }
  303. if ($updateDate >= strtotime ($IIBList [0] ['updateDate'])) {
  304. $item += array (
  305. 'updateDate' => $invoicePrintDetail ['date']
  306. );
  307. $invoiceInfoBase->setInvoiceInfoBaseByCondition ( $item );
  308. }
  309. } else { // 删除多张发票,重新添加发票
  310. $iibIDStr = '';
  311. $iibID = array ();
  312. foreach ( $IIBList as $key => $value ) {
  313. array_push ( $iibID, $value ['iibID'] );
  314. }
  315. $iibIDStr = implode ( ",", $iibID ); // 删除
  316. $invoiceInfoBase->delInvoiceInfoBaseByIibStr ( $iibIDStr );
  317. $item = array (
  318. 'invoiceTitle' => $invoiceTitle,
  319. 'TIN' => $TIN,
  320. 'address' => $invoicePrintDetail ['address'],
  321. 'phone' => $invoicePrintDetail ['phone'],
  322. 'bank' => $invoicePrintDetail ['bank'],
  323. 'bankAccount' => $invoicePrintDetail ['bankAccount'],
  324. 'updateDate' => $invoicePrintDetail ['date']
  325. );
  326. $invoiceInfoBase->addInvoiceInfoBase ( $item );
  327. }
  328. } else { // 没有新增发票信息
  329. $item = array (
  330. 'invoiceTitle' => $invoiceTitle,
  331. 'TIN' => $TIN,
  332. 'address' => $invoicePrintDetail ['address'],
  333. 'phone' => $invoicePrintDetail ['phone'],
  334. 'bank' => $invoicePrintDetail ['bank'],
  335. 'bankAccount' => $invoicePrintDetail ['bankAccount'],
  336. 'updateDate' => $invoicePrintDetail ['date']
  337. );
  338. $invoiceInfoBase->addInvoiceInfoBase ( $item );
  339. }
  340. }
  341. function invoiceAddFill() {
  342. session_start ();
  343. Doo::loadModel ( 'L_category' );
  344. $lCategory = new L_category ();
  345. $category = $lCategory->find ( array (
  346. 'asArray' => true
  347. ) );
  348. $this->data ['category'] = $category;
  349. Doo::loadModel ( 'invoiceTraining' );
  350. $invoiceTraining = new invoiceTraining ();
  351. $itList = $invoiceTraining->getInvoiceTrainingByCid ( $this->staff [0] ['cid'] );
  352. $this->data ['itList'] = $itList;
  353. Doo::loadModel ( 'invoice' );
  354. $invoice = new invoice ();
  355. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );
  356. $detail ['mailItemsArray'] = json_decode ( $detail ['mailItemsJson'], true );
  357. $token = $this->set_token ();
  358. $tokenTime=time().rand(5, 15);
  359. $_SESSION ['token_' . $this->staff [0] ['sidKey'].'_'.$tokenTime] = $token;
  360. $this->data ['token'] = $token;
  361. $this->data['tokenTime']=$tokenTime;
  362. $this->data ['invoiceDetail'] = $detail;
  363. $this->data ['memu'] = "invoice";
  364. $this->data ['staff'] = $this->staff;
  365. $this->data ['receiptMemu'] = 'invoice';
  366. $this->render ( "/admin/invoiceAddFill", $this->data );
  367. }
  368. /**
  369. * 提交一份开票申请,并记录下操作日志
  370. *
  371. * @since 1.0.0
  372. * @var integer cid 办事处ID
  373. * @var integer invoiceType 发票类型
  374. * @var integer doPost 是否邮寄
  375. * @var integer invoicePrice 开票金额
  376. * @var string invoiceElement 开票内容
  377. * @var string invoiceTitle 发票抬头
  378. * @var string invoiceCompany 单位名称
  379. * @var string TIN 纳税人识别码
  380. * @var string address 注册地址
  381. * @var string phone 注册电话
  382. * @var string bank 开户银行
  383. * @var string bankAccount 银行账户
  384. * @var string recipients 收件人
  385. * @var string recipientsPhone 收件人手机/电话
  386. * @var string recipientsAddress 收件地址
  387. * @var string mailItems 邮寄物品
  388. * @var string remark 备注
  389. * @return string 返回跳转开票主页路径
  390. */
  391. function invoiceAddDo() {
  392. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  393. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  394. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  395. // $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  396. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  397. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  398. $invoiceForm = $this->get_args ( 'invoiceForm' ) ? $this->get_args ( 'invoiceForm' ) : "";
  399. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  400. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  401. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  402. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  403. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  404. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  405. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  406. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  407. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  408. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  409. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  410. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  411. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  412. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  413. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  414. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  415. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  416. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  417. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  418. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  419. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  420. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  421. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  422. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  423. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  424. $trainId = $this->get_args ( 'trainId' ) ? $this->get_args ( 'trainId' ) : 0;
  425. $settlementType = $this->get_args ( 'settlementType' ) ? $this->get_args ( 'settlementType' ) : "";
  426. /*
  427. * $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;
  428. */
  429. $token = $this->get_args ( 'token' ) ? $this->get_args ( 'token' ) : "";
  430. $tokenTime = $this->get_args ( 'tokenTime' ) ? $this->get_args ( 'tokenTime' ) : "";
  431. if (empty ( $token )) {
  432. die ( 'illegal request-token' );
  433. } else {
  434. session_start ();
  435. $sessionKey='token_' . $this->staff [0] ['sidKey'].'_'.$tokenTime;
  436. header ( 'Content-Type:text/html;charset=utf-8' );
  437. if (!isset($_SESSION [$sessionKey])||empty($_SESSION [$sessionKey])) {
  438. die ( '请重新刷新发票申请页面' );
  439. }elseif($_SESSION [$sessionKey]=='repeat'){
  440. die ( '请勿重复申请发票' );
  441. } else {
  442. if ($_SESSION [$sessionKey] != $token){
  443. die ( '请勿重复申请发票' );
  444. }else{
  445. $_SESSION [$sessionKey] = 'repeat';
  446. }
  447. }
  448. }
  449. if ($invoiceType == 1) {
  450. $temporary = $invoiceQuantity * $invoiceUnitPrice;
  451. if ($temporary > 100001) {
  452. header ( 'Content-Type:text/html;charset=utf-8' );
  453. die ( '专用发票总金额暂时不能超过100000.00(一万)元。' );
  454. // die ( 'illegal request-Please priceError' );
  455. }
  456. }
  457. if (empty ( $this->staff [0] ))
  458. die ( 'illegal request-Please login' );
  459. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $settlementType )&&!empty($invoiceForm)) {
  460. Doo::loadModel ( 'invoice' );
  461. $invoice = new invoice ();
  462. Doo::loadModel ( 'L_category' );
  463. $lCategory = new L_category ();
  464. Doo::loadModel ( 'invoiceManage' );
  465. $invoiceManage = new invoiceManage ();
  466. Doo::loadModel ( 'invoiceOperationLog' );
  467. $invoiceOperationLog = new invoiceOperationLog ();
  468. Doo::loadClass ( 'XDeode' );
  469. $XDeode = new XDeode ( 5 );
  470. $trainId = $XDeode->decode ( $trainId );
  471. $categoryDetil = $lCategory->getOne ( array (
  472. 'SELECT' => 'title',
  473. 'where' => 'cid=' . $cid,
  474. 'asArray' => true
  475. ) );
  476. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  477. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  478. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  479. // print_r(current($invoiceManageDetail ['staffList']));
  480. // die;
  481. $moldManage = array ();
  482. foreach ( $invoiceManageList as $key => $value ) {
  483. if ($value ['mold'] == '发票打印')
  484. $moldManage [$value ['mold']] = $value ['staffList'];
  485. elseif ($value ['mold'] == '发票邮寄')
  486. $moldManage [$value ['mold']] = $value ['staffList'];
  487. elseif ($value ['mold'] == '发票退票')
  488. $moldManage [$value ['mold']] = $value ['staffList'];
  489. }
  490. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  491. $st = '';
  492. if ($settlementType == 'SOFTWARE') {
  493. $st = 0;
  494. $trainId = 0;
  495. } elseif ($settlementType == 'TRAINING') {
  496. $st = 1;
  497. if (empty ( $trainId ) && ! is_numeric ( $trainId )) {
  498. die ( 'illegal request-trainingIdError' );
  499. }
  500. } else {
  501. die ( 'illegal request-settlementError' );
  502. }
  503. if($invoiceForm=='electronic'){
  504. $invoiceSerial="#FE" . date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
  505. $invoiceForm=1;
  506. }elseif($invoiceForm=='paper'){
  507. $invoiceSerial="#F" . date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
  508. $invoiceForm=0;
  509. }else{
  510. die ( 'illegal request-invoiceForm' );
  511. }
  512. $item = array (
  513. 'cid' => $cid,
  514. 'categoryName' => $categoryDetil ['title'],
  515. 'invoiceElement' => $invoiceElement,
  516. 'invoiceForm'=>$invoiceForm,
  517. 'invoiceQuantity' => $invoiceQuantity,
  518. 'invoiceUnitPrice' => $invoiceUnitPrice,
  519. 'invoicePrice' => $invoicePrice,
  520. 'invoiceType' => $invoiceType,
  521. 'settlementType' => $st,
  522. 'doPost' => $doPost,
  523. 'status' => 1,
  524. 'invoiceSerial' => $invoiceSerial,
  525. 'date' => date ( "Y-m-d H:i:s" ),
  526. 'updateTime' => date ( "Y-m-d H:i:s" ),
  527. 'sid' => $this->staff [0] ['sid'],
  528. 'userName' => $this->staff [0] ['username'],
  529. 'invoiceManage' => $invoiceManageDetail ['staff'],
  530. 'pendingApprovals' => $pendingApprovalsSid,
  531. 'moldManage' => json_encode ( $moldManage ),
  532. 'remark' => $remark,
  533. 'trainId' => $trainId
  534. );
  535. if ($invoiceType == 0)
  536. $item += array (
  537. 'invoiceTitle' => $invoiceTitle,
  538. 'TIN' => $TINT,
  539. 'address' => $addressT,
  540. 'phone' => $phoneT,
  541. 'bank' => $bankT,
  542. 'bankAccount' => $bankAccountT
  543. );
  544. else {
  545. $item += array (
  546. 'invoiceCompany' => $invoiceCompany,
  547. 'TIN' => $TIN,
  548. 'address' => $address,
  549. 'phone' => $phone,
  550. 'bank' => $bank,
  551. 'bankAccount' => $bankAccount
  552. );
  553. }
  554. if ($doPost == 1) {
  555. $mailList = array (
  556. 'invoice' => 1,
  557. 'mailItems' => $mailItems
  558. );
  559. if (! empty ( $softLock ))
  560. $mailList += array (
  561. 'softLock' => $softLockNum
  562. );
  563. else
  564. $mailList += array (
  565. 'softLock' => 0
  566. );
  567. if (! empty ( $contract ))
  568. $mailList += array (
  569. 'contract' => $contractNum
  570. );
  571. else
  572. $mailList += array (
  573. 'contract' => 0
  574. );
  575. if (! empty ( $instructions ))
  576. $mailList += array (
  577. 'instructions' => $instructionsNum
  578. );
  579. else
  580. $mailList += array (
  581. 'instructions' => 0
  582. );
  583. if (! empty ( $remittance ))
  584. $mailList += array (
  585. 'remittance' => $remittance
  586. );
  587. else
  588. $mailList += array (
  589. 'remittance' => ''
  590. );
  591. $mailString = '发票x1张,备注:' . $mailItems;
  592. if (! empty ( $softLock ))
  593. $mailString .= ',软件锁x' . $softLockNum . '个';
  594. if (! empty ( $contract ))
  595. $mailString .= ',合同x' . $contractNum . '份';
  596. if (! empty ( $instructions ))
  597. $mailString .= ',说明书x' . $instructionsNum . '本';
  598. if (! empty ( $remittance ))
  599. $mailString .= ',汇款账号单(张)';
  600. $item += array (
  601. 'recipients' => $recipients,
  602. 'recipientsPhone' => $recipientsPhone,
  603. 'recipientsAddress' => $recipientsAddress,
  604. 'mailItems' => $mailString,
  605. 'mailItemsJson' => json_encode ( $mailList )
  606. );
  607. }
  608. $iid = $invoice->addInvoice ( $item );
  609. // 如果是培训班结算 创建培训班发票到培训班备份中
  610. if (! empty ( $st ) && $st == 1) {
  611. Doo::loadModel ( 'invoiceStore' );
  612. $invoiceStore = new invoiceStore ();
  613. Doo::loadModel ( 'invoiceTraining' );
  614. $invoiceTraining = new invoiceTraining ();
  615. $isid = $invoiceStore->setInvoiceToInvoiceStore ( $iid );
  616. $itemIS = array (
  617. 'isid' => $isid,
  618. 'ipSource' => 1,
  619. 'apStatus' => 1,
  620. 'iid' => $iid
  621. );
  622. $invoiceStore->setInvoiceStoreByCondition ( $itemIS );
  623. // 更新培训班总数量
  624. $detailIT = $invoiceTraining->getInvoiceTrainingByItid ( $trainId );
  625. $item = array (
  626. 'itid' => $trainId,
  627. 'invoiceTotal' => $detailIT ['invoiceTotal'] + 1,
  628. 'submitStatus' => 1
  629. );
  630. $itid = $invoiceTraining->setInvoiceTrainByCondition ( $item );
  631. }
  632. // 操作日志
  633. $item = array (
  634. 'date' => date ( "Y-m-d H:i:s" ),
  635. 'operation' => "创建",
  636. 'status' => 1,
  637. 'img' => $this->staff [0] ['avatar'],
  638. 'username' => $this->staff [0] ['username'],
  639. 'uid' => $this->staff [0] ['sid'],
  640. 'category' => $this->staff [0] ['category'],
  641. 'iid' => $iid
  642. );
  643. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  644. $item = array (
  645. 'date' => date ( "Y-m-d H:i:s" ),
  646. 'operation' => "提交审批",
  647. 'status' => 1,
  648. 'img' => $this->staff [0] ['avatar'],
  649. 'username' => $this->staff [0] ['username'],
  650. 'uid' => $this->staff [0] ['sid'],
  651. 'category' => $this->staff [0] ['category'],
  652. 'iid' => $iid
  653. );
  654. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  655. Doo::loadModel ( 'staff' );
  656. $staff = new staff ();
  657. $username2 = $staff->getOne ( array (
  658. 'select' => 'wxid',
  659. 'where' => 'sid=' . $pendingApprovalsSid,
  660. 'asArray' => TRUE
  661. ) );
  662. // 发送微信审批通知
  663. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  664. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  665. }
  666. return "/invoice";
  667. }
  668. function invoiceEdit() {
  669. Doo::loadClass ( 'XDeode' );
  670. $XDeode = new XDeode ( 5 );
  671. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  672. $iid = $XDeode->decode ( $iid );
  673. if (! is_numeric ( $iid ))
  674. die ( 'illegal request' );
  675. Doo::loadModel ( 'invoice' );
  676. $invoice = new invoice ();
  677. Doo::loadModel ( 'invoiceOperationLog' );
  678. $invoiceOperationLog = new invoiceOperationLog ();
  679. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  680. $operation = $invoiceOperationLog->getInvoiceOperationByDropped ( $iid );
  681. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  682. $this->data ['operation'] = $operation;
  683. $this->data ['invoiceDetail'] = $invoiceDetail;
  684. $this->data ['memu'] = "invoice";
  685. $this->data ['staff'] = $this->staff;
  686. $this->data ['receiptMemu'] = 'invoice';
  687. $this->render ( "/admin/invoiceEdit", $this->data );
  688. }
  689. /**
  690. * 重新编辑退回的发票
  691. * @return string
  692. */
  693. function invoiceEditDo() {
  694. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  695. Doo::loadModel ( 'invoice' );
  696. $invoice = new invoice ();
  697. $iid = $invoice->authcode ( $iidKey );
  698. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  699. die ( 'illegal request' );
  700. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  701. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  702. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  703. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  704. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  705. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  706. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  707. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  708. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  709. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  710. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  711. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  712. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  713. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  714. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  715. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  716. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  717. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  718. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  719. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  720. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  721. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  722. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  723. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  724. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  725. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  726. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  727. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  728. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  729. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  730. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  731. if ($invoiceType == 1) {
  732. $temporary = $invoiceQuantity * $invoiceUnitPrice;
  733. if ($temporary > 100001)
  734. die ( 'illegal request-Please priceError' );
  735. }
  736. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  737. Doo::loadModel ( 'invoiceManage' );
  738. $invoiceManage = new invoiceManage ();
  739. Doo::loadModel ( 'invoiceOperationLog' );
  740. $invoiceOperationLog = new invoiceOperationLog ();
  741. Doo::loadModel ( 'invoiceStore' );
  742. $invoiceStore = new invoiceStore ();
  743. $cid = explode ( ':', $cid );
  744. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  745. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  746. $moldManage = array ();
  747. foreach ( $invoiceManageList as $key => $value ) {
  748. if ($value ['mold'] == '发票打印')
  749. $moldManage [$value ['mold']] = $value ['staffList'];
  750. elseif ($value ['mold'] == '发票邮寄')
  751. $moldManage [$value ['mold']] = $value ['staffList'];
  752. elseif ($value ['mold'] == '发票打印')
  753. $moldManage [$value ['mold']] = $value ['staffList'];
  754. }
  755. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  756. $item = array (
  757. 'iid' => $iid,
  758. 'cid' => $cid [0],
  759. 'categoryName' => $cid [1],
  760. 'invoiceElement' => $invoiceElement,
  761. 'invoiceQuantity' => $invoiceQuantity,
  762. 'invoiceUnitPrice' => $invoiceUnitPrice,
  763. 'invoicePrice' => $invoicePrice,
  764. 'invoiceType' => $invoiceType,
  765. 'doPost' => $doPost,
  766. 'status' => 1,
  767. 'updateTime' => date ( "Y-m-d H:i:s" ),
  768. 'remark' => $remark
  769. );
  770. if ($invoiceType == 0)
  771. $item += array (
  772. 'invoiceTitle' => $invoiceTitle,
  773. 'TIN' => $TINT,
  774. 'address' => $addressT,
  775. 'phone' => $phoneT,
  776. 'bank' => $bankT,
  777. 'bankAccount' => $bankAccountT
  778. );
  779. else {
  780. $item += array (
  781. 'invoiceCompany' => $invoiceCompany,
  782. 'TIN' => $TIN,
  783. 'address' => $address,
  784. 'phone' => $phone,
  785. 'bank' => $bank,
  786. 'bankAccount' => $bankAccount
  787. );
  788. }
  789. if ($doPost == 1) {
  790. $mailList = array (
  791. 'invoice' => 1,
  792. 'mailItems' => $mailItems
  793. );
  794. if (! empty ( $softLock ))
  795. $mailList += array (
  796. 'softLock' => $softLockNum
  797. );
  798. else
  799. $mailList += array (
  800. 'softLock' => '0'
  801. );
  802. if (! empty ( $contract ))
  803. $mailList += array (
  804. 'contract' => $contractNum
  805. );
  806. else
  807. $mailList += array (
  808. 'contract' => '0'
  809. );
  810. if (! empty ( $instructions ))
  811. $mailList += array (
  812. 'instructions' => $instructionsNum
  813. );
  814. else
  815. $mailList += array (
  816. 'instructions' => '0'
  817. );
  818. if (! empty ( $remittance ))
  819. $mailList += array (
  820. 'remittance' => $remittance
  821. );
  822. else
  823. $mailList += array (
  824. 'remittance' => ''
  825. );
  826. $mailString = '发票x1,备注:' . $mailItems;
  827. if (! empty ( $softLock ))
  828. $mailString .= ',软件锁x' . $softLockNum;
  829. if (! empty ( $contract ))
  830. $mailString .= ',合同x' . $contractNum;
  831. if (! empty ( $instructions ))
  832. $mailString .= ',说明书x' . $instructionsNum;
  833. if (! empty ( $remittance ))
  834. $mailString .= ',汇款账号单';
  835. $item += array (
  836. 'recipients' => $recipients,
  837. 'recipientsPhone' => $recipientsPhone,
  838. 'recipientsAddress' => $recipientsAddress,
  839. 'mailItems' => $mailString,
  840. 'mailItemsJson' => json_encode ( $mailList )
  841. );
  842. }
  843. $invoice->setInvoiceByCondition ( $item );
  844. // 更新培训班仓库里的发票
  845. $detail = $invoice->getInvoiceByIid ( $iid );
  846. if (! empty ( $detail ['isid'] )) {
  847. $invoiceStore->isid = $detail ['isid'];
  848. $invoiceStore->invoiceQuantity = $invoiceQuantity;
  849. $invoiceStore->invoiceUnitPrice = $invoiceUnitPrice;
  850. $invoiceStore->invoicePrice = $invoicePrice;
  851. $invoiceStore->update ();
  852. }
  853. $item = array (
  854. 'date' => date ( "Y-m-d H:i:s" ),
  855. 'operation' => "重新提交审批",
  856. 'status' => 1,
  857. 'img' => $this->staff [0] ['avatar'],
  858. 'username' => $this->staff [0] ['username'],
  859. 'uid' => $this->staff [0] ['sid'],
  860. 'category' => $this->staff [0] ['category'],
  861. 'iid' => $iid
  862. );
  863. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  864. }
  865. return "/invoice";
  866. }
  867. /**
  868. * 培训班
  869. */
  870. function invoiceTraining() {
  871. Doo::loadModel ( 'L_category' );
  872. $lCategory = new L_category ();
  873. Doo::loadModel ( 'invoiceTraining' );
  874. $invoiceTraining = new invoiceTraining ();
  875. Doo::loadModel ( 'invoiceTrainManage' );
  876. $invoiceTrainManage = new invoiceTrainManage ();
  877. $imcStaff = $invoiceTrainManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  878. $cidList = array ();
  879. foreach ( $imcStaff as $key => $value ) {
  880. array_push ( $cidList, $value ['cid'] );
  881. }
  882. if (empty ( $cidList )) {
  883. $cidString = $this->staff [0] ['cid'];
  884. } else {
  885. $cidString = implode ( ',', $cidList );
  886. $cidString .= $cidString . ',' . $this->staff [0] ['cid'];
  887. }
  888. $itTodoList = $invoiceTraining->getInvoiceTrainingByTodo ( '', $cidString, $this->staff [0] ['sid'] );
  889. $itedList = $invoiceTraining->getInvoiceTrainingByStatus ( 2, '', $cidString, $this->staff [0] ['sid'] );
  890. $category = $lCategory->getCategory ();
  891. $itid = array ();
  892. foreach ( $itTodoList as $key => $value ) {
  893. array_push ( $itid, $value ['itid'] );
  894. // 如果入账100%更新为已完成
  895. if ($itTodoList [$key] ['arriveSchedule'] >= 100) {
  896. $invoiceTraining = new invoiceTraining ();
  897. $invoiceTraining->itid = $value ['itid'];
  898. $invoiceTraining->status = 2;
  899. $invoiceTraining->update ();
  900. }
  901. }
  902. foreach ( $itedList as $value ) {
  903. array_push ( $itid, $value ['itid'] );
  904. }
  905. $itid = implode ( ',', $itid );
  906. $this->data ['itStatist'] = $invoiceTraining->getInvoiceTrainStatistics ( $itid );
  907. // print_r($itTodoList);
  908. $this->data ['trainCount'] = count ( $itTodoList ) + count ( $itedList );
  909. $this->data ['itTodoList'] = $itTodoList;
  910. $this->data ['itedList'] = $itedList;
  911. $this->data ['category'] = $category;
  912. $this->data ['memu'] = "invoice";
  913. $this->data ['staff'] = $this->staff;
  914. $this->data ['receiptMemu'] = 'invoiceTraining';
  915. $this->render ( "/admin/invoiceTraining", $this->data );
  916. }
  917. /**
  918. * 创建培训班
  919. */
  920. function invoiceTrainingAdd() {
  921. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  922. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  923. $trainDate = $this->get_args ( 'trainDate' ) ? $this->get_args ( 'trainDate' ) : "";
  924. if (empty ( $this->staff [0] ))
  925. die ( 'illegal request' );
  926. if (! empty ( $cid ) && ! empty ( $trainName ) && ! empty ( $trainDate )) {
  927. Doo::loadModel ( 'invoiceTraining' );
  928. $invoiceTraining = new invoiceTraining ();
  929. Doo::loadModel ( 'invoice' );
  930. $invoice = new invoice ();
  931. Doo::loadModel ( 'L_category' );
  932. $lCategory = new L_category ();
  933. Doo::loadModel ( 'invoiceManage' );
  934. $invoiceManage = new invoiceManage ();
  935. Doo::loadModel ( 'invoiceOperationLog' );
  936. $invoiceOperationLog = new invoiceOperationLog ();
  937. $item = array (
  938. 'cid' => $cid,
  939. 'trainName' => $trainName,
  940. 'trainDate' => $trainDate,
  941. 'creator' => $this->staff [0] ['sid'],
  942. 'creatorDate' => date ( "Y-m-d H:i:s" )
  943. );
  944. $itid = $invoiceTraining->addInvoiceTraining ( $item );
  945. }
  946. return "/invoiceTraining";
  947. }
  948. /**
  949. * 删除培训班
  950. */
  951. function invoiceTrainingDelDo() {
  952. $itid = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  953. if (! empty ( $itid )) {
  954. Doo::loadModel ( 'invoiceTraining' );
  955. $invoiceTraining = new invoiceTraining ();
  956. $invoiceTraining->delInvoiceTrainingByItid ( $itid );
  957. }
  958. return "/invoiceTraining";
  959. }
  960. /**
  961. * 培训班详情
  962. */
  963. function invoiceTrainingDetail() {
  964. $trainStatus = $this->get_args ( 'trainStatus' ) ? $this->get_args ( 'trainStatus' ) : "ALL";
  965. $itid = isset ( $this->params ['trainingKey'] ) ? $this->params ['trainingKey'] : "";
  966. Doo::loadModel ( 'invoiceTraining' );
  967. $invoiceTraining = new invoiceTraining ();
  968. Doo::loadModel ( 'invoiceStore' );
  969. $invoiceStore = new invoiceStore ();
  970. if (empty ( $itid ))
  971. die ( 'illegal request' );
  972. $con = ' (b.untreadStatus is null or b.untreadStatus!=2) and ';
  973. if ($trainStatus == "SUBED")
  974. $con = ' (b.untreadStatus is null ) and ';
  975. elseif ($trainStatus == "APPROVAL")
  976. $con = ' ( b.status=1 and b.untreadStatus!=2 ) and ';
  977. elseif ($trainStatus == "TICKET")
  978. $con = ' (b.printStatus=1 and b.status=2 and b.untreadStatus!=2) and ';
  979. elseif ($trainStatus == "TICKETING") {
  980. $con = ' (b.status=2 and b.untreadStatus=1) and ';
  981. }
  982. $detail = $invoiceTraining->getInvoiceTrainingByItid ( $itid );
  983. $isList = $invoiceStore->getinvoiceStoreByItid ( $itid, $con );
  984. //print_r($isList);
  985. $trainlist = array ();
  986. foreach ( $isList as $key => $value ) {
  987. $irDetail = array ();
  988. if ($value ['apStatus'] == 1) {
  989. // array_push ( $irDetail, '' );
  990. array_push ( $irDetail, '<input disabled type="checkbox" style="display:none" >' );
  991. } else {
  992. array_push ( $irDetail, '<input type="checkbox" class="hide" id="' . $value ['storeKey'] . '" name="isBox" value="' . $value ['storeKey'] . '" > <a href="/invoiceStoreEdit/' . $value ['storeKey'] . '.html">编辑</a>
  993. <a href="#confirm" onclick="invoiceStoreApproval(\'' . $value ['storeKey'] . '\')" data-toggle="modal">提交审批</a>
  994. <a href="#del" node-iStore="del" data-key="' . $value ['storeKey'] . '" onclick="invoiceStoreDel(\'' . $value ['storeKey'] . '\')" data-toggle="modal" class="colRed">移除</a>' );
  995. }
  996. array_push ( $irDetail, $value ['invoiceSerial'] );
  997. if ($value ['invoiceType'] == 1)
  998. array_push ( $irDetail, $value ['invoiceCompany'] );
  999. else
  1000. array_push ( $irDetail, $value ['invoiceTitle'] );
  1001. array_push ( $irDetail, $value ['TIN'] );
  1002. array_push ( $irDetail, $value ['userName'] );
  1003. if (empty ( $value ['mailItems'] ) && $value ['apStatus'] != 1) {
  1004. array_push ( $irDetail, '<a href="#confirm-erro" onclick="invoiceStoreMail(\'' . $value ['storeKey'] . '\')" data-toggle="modal">设置邮寄物品</a>' );
  1005. } else
  1006. array_push ( $irDetail, $value ['mailItems'] );
  1007. array_push ( $irDetail, $value ['recipientsAddress'] . $value ['recipients'] . $value ['recipientsPhone'] );
  1008. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  1009. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  1010. array_push ( $irDetail, $value ['invoiceElement'] );
  1011. array_push ( $irDetail, $value ['invoiceQuantity'] );
  1012. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  1013. if ($value ['invoiceType'] == 1)
  1014. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  1015. else
  1016. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  1017. array_push ( $irDetail, $value ['remark'] );
  1018. if ($value ['status'] == 1)
  1019. array_push ( $irDetail, '审批中' );
  1020. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1)
  1021. array_push ( $irDetail, '已出票' );
  1022. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1 && $value ['printStatus'] != 'irid' && ($value ['untreadStatus'] == 3 || $value ['untreadStatus'] == 0))
  1023. array_push ( $irDetail, '已入账' );
  1024. else
  1025. array_push ( $irDetail, '' );
  1026. array_push ( $irDetail, $value ['invoiceNo'] );
  1027. array_push ( $irDetail, $value ['printTime'] );
  1028. $html = '';
  1029. foreach ( $value ['invoiceReceivables'] as $value ) {
  1030. $html .= '&nbsp;<a href="#billing" node-invoice="INFO" data-type="receivables" data-iskey="' . $value [2] . '" data-toggle="modal">' . $value [1] . '</a>';
  1031. }
  1032. array_push ( $irDetail, $html );
  1033. array_push ( $trainlist, $irDetail );
  1034. }
  1035. $trainlistJson = json_encode ( $trainlist );
  1036. if (empty ( $detail ))
  1037. die ( 'illegal request' );
  1038. // 培训班结算是否有和是否已经结算完成
  1039. Doo::loadModel ( 'receipt' );
  1040. $receipt = new receipt ();
  1041. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $itid );
  1042. $this->data ['receiptDetail'] = $receiptDetail;
  1043. $this->data ['trainStatus'] = $trainStatus;
  1044. $this->data ['itid'] = $itid;
  1045. $this->data ['trainlistJson'] = $trainlistJson;
  1046. $this->data ['iTrainDetail'] = $detail;
  1047. $this->data ['memu'] = "invoice";
  1048. $this->data ['staff'] = $this->staff;
  1049. $this->data ['receiptMemu'] = 'invoiceTraining';
  1050. $this->render ( "/admin/invoiceTrainingDetail", $this->data );
  1051. }
  1052. /**
  1053. * 上传培训班发票
  1054. * @return string
  1055. */
  1056. function invoiceTrainingUpload() {
  1057. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  1058. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  1059. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  1060. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  1061. header ( "HTTP/1.1 500 Internal Server Error" );
  1062. echo "POST exceeded maximum allowed size.";
  1063. exit ( 0 );
  1064. }
  1065. // Settings
  1066. $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)
  1067. $upload_name = "Filedata";
  1068. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  1069. $extension_whitelist = array (
  1070. "doc",
  1071. "txt",
  1072. "jpg",
  1073. "gif",
  1074. "png"
  1075. ); // Allowed file extensions
  1076. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  1077. // Other variables
  1078. $MAX_FILENAME_LENGTH = 260;
  1079. $file_name = "";
  1080. $file_extension = "";
  1081. $uploadErrors = array (
  1082. 0 => "文件上传成功",
  1083. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  1084. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  1085. 3 => "上传的文件仅为部分文件",
  1086. 4 => "没有文件上传",
  1087. 6 => "缺少临时文件夹"
  1088. );
  1089. $nk = time ();
  1090. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  1091. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  1092. echo "文件无法保存.";
  1093. exit ( 0 );
  1094. }
  1095. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  1096. echo json_encode ( array (
  1097. 'filename' => $file_name,
  1098. 'id' => $nk
  1099. ) );
  1100. exit ( 0 );
  1101. }
  1102. /**
  1103. * 导入发票临时仓库
  1104. */
  1105. function invoiceStoreImport() {
  1106. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  1107. $trainingKey = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  1108. $path = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  1109. if ($path != "" && ! empty ( $trainingKey )) {
  1110. Doo::loadModel ( 'invoiceStore' );
  1111. Doo::loadModel ( 'staff' );
  1112. $staff = new staff ();
  1113. Doo::loadModel ( 'invoiceTraining' );
  1114. $invoiceTraining = new invoiceTraining ();
  1115. Doo::loadClass ( 'XDeode' );
  1116. $XDeode = new XDeode ( 5 );
  1117. $itid = $XDeode->decode ( $trainingKey );
  1118. // 培训班结算是否有和是否已经结算完成
  1119. Doo::loadModel ( 'receipt' );
  1120. $receipt = new receipt ();
  1121. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $itid );
  1122. if (! empty ( $receiptDetail )) {
  1123. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9)
  1124. die ( 'illegal request--status' );
  1125. }
  1126. $exlArray = $this->formatExcelToArrayTrain ( DOO::conf ()->SITE_PATH . "upload/invoiceTraining/" . $path );
  1127. $userName = $this->staff [0] ['username'];
  1128. $sDetail = $staff->getStaffByName ( $userName );
  1129. // die('sdd');
  1130. // 可以优化
  1131. foreach ( $exlArray as $key => $value ) {
  1132. // 开票
  1133. $invoice = new invoiceStore ();
  1134. $invoice->trainId = $itid;
  1135. $invoice->invoiceType = 0;
  1136. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  1137. $invoice->invoiceType = 1;
  1138. $invoice->invoiceQuantity = $value ['invoiceQuantity'];
  1139. $invoice->invoiceUnitPrice = $value ['invoiceUnitPrice'];
  1140. $invoice->invoicePrice = $value ['invoiceQuantity'] * $value ['invoiceUnitPrice'];
  1141. $invoice->invoiceTitle = $value ['invoiceTitle'];
  1142. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  1143. $invoice->invoiceCompany = $value ['invoiceTitle'];
  1144. $invoice->userName = $userName;
  1145. $invoice->sid = $sDetail ['sid'];
  1146. $invoice->cid = $sDetail ['cid'];
  1147. $invoice->categoryName = $sDetail ['category'];
  1148. $invoice->invoiceElement = $value ['invoiceElement'];
  1149. $invoice->remark = $value ['remark'];
  1150. // $invoice->date = $value ['date'];
  1151. // $invoice->printTime = $value ['date'];
  1152. $invoice->ipSource = 1;
  1153. $invoice->printStatus = 0;
  1154. $invoice->status = 0;
  1155. $invoice->postStatus = 1;
  1156. $invoice->untreadStatus = 0;
  1157. // $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1158. $invoice->TIN = $value ['TIN'];
  1159. $invoice->address = $value ['address'];
  1160. $invoice->phone = $value ['phone'];
  1161. $invoice->bank = $value ['bank'];
  1162. $invoice->bankAccount = $value ['bankAccount'];
  1163. $invoice->recipientsAddress = $value ['recipientsAddress'];
  1164. $invoice->recipients = $value ['recipients'];
  1165. $invoice->recipientsPhone = $value ['recipientsPhone'];
  1166. $iid = $invoice->insert ();
  1167. }
  1168. // 加入发票总数量
  1169. $item = array (
  1170. 'itid' => $itid,
  1171. 'invoiceTotal' => count ( $exlArray )
  1172. );
  1173. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1174. return '/invoiceTrainingDetail/' . $trainingKey . ".html";
  1175. }
  1176. echo 'no file';
  1177. }
  1178. /**
  1179. * 编辑仓库里的发票
  1180. */
  1181. function invoiceStoreEdit() {
  1182. Doo::loadClass ( 'XDeode' );
  1183. $XDeode = new XDeode ( 5 );
  1184. $iid = isset ( $this->params ['storeKey'] ) ? $this->params ['storeKey'] : "";
  1185. $iid = $XDeode->decode ( $iid );
  1186. if (! is_numeric ( $iid ))
  1187. die ( 'illegal request' );
  1188. Doo::loadModel ( 'invoiceStore' );
  1189. $invoiceStore = new invoiceStore ();
  1190. $invoiceDetail = $invoiceStore->getInvoiceStoreByIsid ( $iid );
  1191. // print_r($invoiceDetail);
  1192. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  1193. $this->data ['invoiceDetail'] = $invoiceDetail;
  1194. $this->data ['memu'] = "invoice";
  1195. $this->data ['staff'] = $this->staff;
  1196. $this->data ['receiptMemu'] = 'invoiceTraining';
  1197. $this->render ( "/admin/invoiceStoreEdit", $this->data );
  1198. }
  1199. function invoiceStoreEditDo() {
  1200. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1201. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1202. Doo::loadModel ( 'invoiceStore' );
  1203. $invoice = new invoiceStore ();
  1204. Doo::loadClass ( 'XDeode' );
  1205. $XDeode = new XDeode ( 5 );
  1206. $iid = $XDeode->decode ( $storeKey );
  1207. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1208. die ( 'illegal request' );
  1209. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  1210. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  1211. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  1212. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  1213. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  1214. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  1215. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  1216. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  1217. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  1218. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  1219. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  1220. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  1221. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  1222. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  1223. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1224. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1225. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1226. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1227. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  1228. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  1229. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  1230. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  1231. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  1232. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  1233. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1234. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1235. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1236. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1237. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1238. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1239. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1240. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  1241. $cid = explode ( ':', $cid );
  1242. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  1243. $item = array (
  1244. 'isid' => $iid,
  1245. 'cid' => $cid [0],
  1246. 'categoryName' => $cid [1],
  1247. 'invoiceElement' => $invoiceElement,
  1248. 'invoiceQuantity' => $invoiceQuantity,
  1249. 'invoiceUnitPrice' => $invoiceUnitPrice,
  1250. 'invoicePrice' => $invoicePrice,
  1251. 'invoiceType' => $invoiceType,
  1252. 'doPost' => $doPost,
  1253. 'status' => 1,
  1254. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1255. 'remark' => $remark
  1256. );
  1257. if ($invoiceType == 0)
  1258. $item += array (
  1259. 'invoiceTitle' => $invoiceTitle,
  1260. 'TIN' => $TINT,
  1261. 'address' => $addressT,
  1262. 'phone' => $phoneT,
  1263. 'bank' => $bankT,
  1264. 'bankAccount' => $bankAccountT
  1265. );
  1266. else {
  1267. $item += array (
  1268. 'invoiceCompany' => $invoiceCompany,
  1269. 'TIN' => $TIN,
  1270. 'address' => $address,
  1271. 'phone' => $phone,
  1272. 'bank' => $bank,
  1273. 'bankAccount' => $bankAccount
  1274. );
  1275. }
  1276. if ($doPost == 1) {
  1277. $mailList = array (
  1278. 'invoice' => 1,
  1279. 'mailItems' => $mailItems
  1280. );
  1281. if (! empty ( $softLock ))
  1282. $mailList += array (
  1283. 'softLock' => $softLockNum
  1284. );
  1285. else
  1286. $mailList += array (
  1287. 'softLock' => '0'
  1288. );
  1289. if (! empty ( $contract ))
  1290. $mailList += array (
  1291. 'contract' => $contractNum
  1292. );
  1293. else
  1294. $mailList += array (
  1295. 'contract' => '0'
  1296. );
  1297. if (! empty ( $instructions ))
  1298. $mailList += array (
  1299. 'instructions' => $instructionsNum
  1300. );
  1301. else
  1302. $mailList += array (
  1303. 'instructions' => '0'
  1304. );
  1305. if (! empty ( $remittance ))
  1306. $mailList += array (
  1307. 'remittance' => $remittance
  1308. );
  1309. else
  1310. $mailList += array (
  1311. 'remittance' => ''
  1312. );
  1313. $mailString = '发票x1,备注:' . $mailItems;
  1314. if (! empty ( $softLock ))
  1315. $mailString .= ',软件锁x' . $softLockNum;
  1316. if (! empty ( $contract ))
  1317. $mailString .= ',合同x' . $contractNum;
  1318. if (! empty ( $instructions ))
  1319. $mailString .= ',说明书x' . $instructionsNum;
  1320. if (! empty ( $remittance ))
  1321. $mailString .= ',汇款账号单';
  1322. $item += array (
  1323. 'recipients' => $recipients,
  1324. 'recipientsPhone' => $recipientsPhone,
  1325. 'recipientsAddress' => $recipientsAddress,
  1326. 'mailItems' => $mailString,
  1327. 'mailItemsJson' => json_encode ( $mailList )
  1328. );
  1329. }
  1330. $invoice->setInvoiceStoreByCondition ( $item );
  1331. }
  1332. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1333. }
  1334. /**
  1335. *
  1336. * @return string
  1337. */
  1338. function invoiceStoreDelete() {
  1339. Doo::loadClass ( 'XDeode' );
  1340. $XDeode = new XDeode ( 5 );
  1341. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1342. $iStoreKey = $this->get_args ( 'iStoreKey' ) ? $this->get_args ( 'iStoreKey' ) : 0;
  1343. $isid = $XDeode->decode ( $iStoreKey );
  1344. $itid = $XDeode->decode ( $trainKey );
  1345. if (! is_numeric ( $isid ))
  1346. die ( 'illegal request' );
  1347. Doo::loadModel ( 'invoiceStore' );
  1348. $invoiceStore = new invoiceStore ();
  1349. $invoiceStore->delete ( array (
  1350. 'where' => 'isid=' . $isid,
  1351. 'limit' => 1
  1352. ) );
  1353. Doo::loadModel ( 'invoiceTraining' );
  1354. $invoiceTraining = new invoiceTraining ();
  1355. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1356. $item = array (
  1357. 'itid' => $itid,
  1358. 'invoiceTotal' => $itDetail ['invoiceTotal'] - 1
  1359. );
  1360. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1361. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1362. }
  1363. /**
  1364. * 批量删除库里发票
  1365. */
  1366. function invoiceStoreBatchDelete() {
  1367. Doo::loadClass ( 'XDeode' );
  1368. $XDeode = new XDeode ( 5 );
  1369. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1370. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1371. if (empty ( $trainKey ) || empty ( $storeKey ))
  1372. die ( 'illegal request-IdKey' );
  1373. $tid = $XDeode->decode ( $trainKey );
  1374. if (! is_numeric ( $tid ) && ! empty ( $storeKey ))
  1375. die ( 'illegal request' );
  1376. Doo::loadModel ( 'invoiceStore' );
  1377. $isidKeyList = explode ( ',', $storeKey );
  1378. $isidList = array ();
  1379. foreach ( $isidKeyList as $value ) {
  1380. $isid = $XDeode->decode ( $value );
  1381. if (! empty ( $isid ) && is_numeric ( $isid ))
  1382. array_push ( $isidList, $isid );
  1383. }
  1384. $isidString = implode ( ',', $isidList );
  1385. $invoiceStore = new invoiceStore ();
  1386. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,apStatus' );
  1387. $isidList = array ();
  1388. foreach ( $isList as $key => $value ) {
  1389. if ($value ['apStatus'] == 0)
  1390. array_push ( $isidList, $value ['isid'] );
  1391. }
  1392. $isidString = implode ( ',', $isidList );
  1393. // print_r($isList);
  1394. // echo $isidString;
  1395. $invoiceStore = new invoiceStore ();
  1396. $invoiceStore->delete ( array (
  1397. 'where' => "isid in ( " . $isidString . ")",
  1398. 'asArray' => TRUE
  1399. ) );
  1400. Doo::loadModel ( 'invoiceTraining' );
  1401. $invoiceTraining = new invoiceTraining ();
  1402. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1403. $item = array (
  1404. 'itid' => $tid,
  1405. 'invoiceTotal' => $itDetail ['invoiceTotal'] - count ( $isidList )
  1406. );
  1407. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1408. // echo $tid;
  1409. // echo $storeKey;
  1410. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1411. }
  1412. /**
  1413. * 仓库发票提交审批
  1414. * @return string
  1415. */
  1416. function invoiceStoreApproval() {
  1417. Doo::loadClass ( 'XDeode' );
  1418. $XDeode = new XDeode ( 5 );
  1419. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1420. $iStoreKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1421. $isid = $XDeode->decode ( $iStoreKey );
  1422. $trainId = $XDeode->decode ( $trainKey );
  1423. if (! is_numeric ( $isid ))
  1424. die ( 'illegal request' );
  1425. Doo::loadModel ( 'invoiceStore' );
  1426. Doo::loadModel ( 'invoice' );
  1427. $invoice = new invoice ();
  1428. // 加入限制必须填写入开票内容和邮寄物品
  1429. $invoiceStore = new invoiceStore ();
  1430. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid, 'isid,trainId ,invoiceElement,mailItemsJson' );
  1431. if (empty ( $isDetail ['invoiceElement'] ) || empty ( $isDetail ['mailItemsJson'] )) {
  1432. header ( 'Content-Type:text/html;charset=utf-8' );
  1433. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1434. }
  1435. // 拷贝插入一条发票数据
  1436. $invoiceStore = new invoiceStore ();
  1437. $iid = $invoiceStore->setInvoiceStoreToApproval ( $isid );
  1438. $invoiceStore = new invoiceStore ();
  1439. $item = array (
  1440. 'isid' => $isid,
  1441. 'iid' => $iid,
  1442. 'apStatus' => 1
  1443. );
  1444. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1445. Doo::loadModel ( 'invoiceManage' );
  1446. $invoiceManage = new invoiceManage ();
  1447. Doo::loadModel ( 'invoiceOperationLog' );
  1448. $invoiceOperationLog = new invoiceOperationLog ();
  1449. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1450. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1451. $moldManage = array ();
  1452. foreach ( $invoiceManageList as $key => $value ) {
  1453. if ($value ['mold'] == '发票打印')
  1454. $moldManage [$value ['mold']] = $value ['staffList'];
  1455. elseif ($value ['mold'] == '发票邮寄')
  1456. $moldManage [$value ['mold']] = $value ['staffList'];
  1457. elseif ($value ['mold'] == '发票退票')
  1458. $moldManage [$value ['mold']] = $value ['staffList'];
  1459. }
  1460. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1461. $item = array (
  1462. 'iid' => $iid,
  1463. 'isid' => $isid,
  1464. 'invoiceSerial' => "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  1465. 'date' => date ( "Y-m-d H:i:s" ),
  1466. 'status' => 1,
  1467. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1468. 'trainId' => $trainId,
  1469. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1470. 'moldManage' => json_encode ( $moldManage ),
  1471. 'settlementType' => 1,
  1472. 'pendingApprovals' => $pendingApprovalsSid
  1473. );
  1474. $invoice->setInvoiceByCondition ( $item );
  1475. Doo::loadModel ( 'invoiceTraining' );
  1476. $invoiceTraining = new invoiceTraining ();
  1477. $item = array (
  1478. 'itid' => $trainId,
  1479. 'submitStatus' => 1
  1480. );
  1481. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1482. $item = array (
  1483. 'date' => date ( "Y-m-d H:i:s" ),
  1484. 'operation' => "创建",
  1485. 'status' => 1,
  1486. 'img' => $this->staff [0] ['avatar'],
  1487. 'username' => $this->staff [0] ['username'],
  1488. 'uid' => $this->staff [0] ['sid'],
  1489. 'category' => $this->staff [0] ['category'],
  1490. 'iid' => $iid
  1491. );
  1492. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1493. $item = array (
  1494. 'date' => date ( "Y-m-d H:i:s" ),
  1495. 'operation' => "提交审批",
  1496. 'status' => 1,
  1497. 'img' => $this->staff [0] ['avatar'],
  1498. 'username' => $this->staff [0] ['username'],
  1499. 'uid' => $this->staff [0] ['sid'],
  1500. 'category' => $this->staff [0] ['category'],
  1501. 'iid' => $iid
  1502. );
  1503. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1504. Doo::loadModel ( 'staff' );
  1505. $staff = new staff ();
  1506. $username2 = $staff->getOne ( array (
  1507. 'select' => 'wxid',
  1508. 'where' => 'sid=' . $pendingApprovalsSid,
  1509. 'asArray' => TRUE
  1510. ) );
  1511. // 发送微信审批通知
  1512. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1513. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1514. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1515. }
  1516. /**
  1517. * 批量提交发票
  1518. * @return string
  1519. */
  1520. function invoiceStoreBatchApproval() {
  1521. Doo::loadClass ( 'XDeode' );
  1522. $XDeode = new XDeode ( 5 );
  1523. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1524. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1525. if (empty ( $trainKey ) || empty ( $storeKey ))
  1526. die ( 'illegal request-IdKey' );
  1527. $trainId = $XDeode->decode ( $trainKey );
  1528. $isidKeyList = explode ( ',', $storeKey );
  1529. $isidList = array ();
  1530. foreach ( $isidKeyList as $value ) {
  1531. $isid = $XDeode->decode ( $value );
  1532. if (! empty ( $isid ) && is_numeric ( $isid ))
  1533. array_push ( $isidList, $isid );
  1534. }
  1535. $isidString = implode ( ',', $isidList );
  1536. if (! is_numeric ( $trainId ))
  1537. die ( 'illegal request' );
  1538. Doo::loadModel ( 'invoiceStore' );
  1539. Doo::loadModel ( 'invoice' );
  1540. // 判断哪些已经加入审批过
  1541. // 加入限制必须填写入开票内容和邮寄物品
  1542. $invoiceStore = new invoiceStore ();
  1543. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,trainId ,invoiceElement,mailItemsJson' );
  1544. foreach ( $isList as $key => $value ) {
  1545. if (empty ( $value ['invoiceElement'] ) || empty ( $value ['mailItemsJson'] )) {
  1546. header ( 'Content-Type:text/html;charset=utf-8' );
  1547. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1548. }
  1549. }
  1550. // 拷贝插入一条发票数据
  1551. $invoiceStore = new invoiceStore ();
  1552. $invoiceStore->setInvoiceStoreBatchToApproval ( $isidString );
  1553. $invoiceStore = new invoiceStore ();
  1554. $item = array (
  1555. 'apStatus' => 1
  1556. );
  1557. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1558. // 获得正式发票ID
  1559. $invoice = new invoice ();
  1560. $iidList = $invoice->getInvoiceByIstoreid ( $isidString, 'iid,isid' );
  1561. $sqlList = array ();
  1562. $iidString = '';
  1563. $iida = array ();
  1564. foreach ( $iidList as $key => $value ) {
  1565. $sqlList [$value ['isid']] = $value ['iid'];
  1566. array_push ( $iida, $value ['iid'] );
  1567. }
  1568. $iidString = implode ( ',', $iida );
  1569. $ids = implode ( ',', array_keys ( $sqlList ) );
  1570. $sql = "UPDATE CLD_invoiceStore SET iid = CASE isid ";
  1571. foreach ( $sqlList as $id => $ordinal ) {
  1572. $sql .= sprintf ( "WHEN %d THEN %d ", $id, $ordinal );
  1573. }
  1574. $sql .= "END WHERE isid IN ($ids)";
  1575. $invoiceStore = new invoiceStore ();
  1576. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1577. Doo::loadModel ( 'invoiceManage' );
  1578. $invoiceManage = new invoiceManage ();
  1579. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1580. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1581. $moldManage = array ();
  1582. foreach ( $invoiceManageList as $key => $value ) {
  1583. if ($value ['mold'] == '发票打印')
  1584. $moldManage [$value ['mold']] = $value ['staffList'];
  1585. elseif ($value ['mold'] == '发票邮寄')
  1586. $moldManage [$value ['mold']] = $value ['staffList'];
  1587. elseif ($value ['mold'] == '发票退票')
  1588. $moldManage [$value ['mold']] = $value ['staffList'];
  1589. }
  1590. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1591. // 批量更新发票信息
  1592. $item = array (
  1593. 'date' => date ( "Y-m-d H:i:s" ),
  1594. 'status' => 1,
  1595. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1596. 'trainId' => $trainId,
  1597. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1598. 'moldManage' => json_encode ( $moldManage ),
  1599. 'settlementType' => 1,
  1600. 'pendingApprovals' => $pendingApprovalsSid
  1601. );
  1602. $invoice = new invoice ();
  1603. $invoice->BatchInvoiceByCondition ( $item, $iidString );
  1604. // 批量更新发票中仓库isid
  1605. $sql = "UPDATE CLD_invoiceStore SET isid = CASE iid ";
  1606. foreach ( $sqlList as $isid => $iid ) {
  1607. $sql .= sprintf ( "WHEN %d THEN %d ", $iid, $isid );
  1608. }
  1609. $sql .= "END WHERE iid IN ($iidString)";
  1610. $invoice = new invoice ();
  1611. $invoice->UpdateBatchInvoice ( $sql );
  1612. // 批量更新发票序列号
  1613. $sqlList = array ();
  1614. foreach ( $iida as $value ) {
  1615. $sqlList [$value] = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1616. }
  1617. $ids = implode ( ',', array_keys ( $sqlList ) );
  1618. $sql = "UPDATE CLD_invoice SET invoiceSerial = CASE iid ";
  1619. foreach ( $sqlList as $id => $ordinal ) {
  1620. $sql .= sprintf ( "WHEN %d THEN '%s' ", $id, $ordinal );
  1621. }
  1622. $sql .= "END WHERE iid IN ($ids)";
  1623. $invoiceStore = new invoiceStore ();
  1624. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1625. // 批量生产操作日志
  1626. Doo::loadModel ( 'invoiceOperationLog' );
  1627. $sqlList = array ();
  1628. foreach ( $iida as $key => $value ) {
  1629. $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 . '"),
  1630. ("' . 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 . '") ';
  1631. array_push ( $sqlList, $sql );
  1632. }
  1633. $iolSql = implode ( ',', $sqlList );
  1634. $sql = "INSERT INTO `CLD_invoiceOperationLog` (`date`, `operation`, `status`, `img`, `username`, `uid`, `category`, `iid`) VALUES " . $iolSql;
  1635. $invoiceOperationLog = new invoiceOperationLog ();
  1636. $invoiceOperationLog->setInvoiceOperationLogBySql ( $sql );
  1637. Doo::loadModel ( 'invoiceTraining' );
  1638. $invoiceTraining = new invoiceTraining ();
  1639. $item = array (
  1640. 'itid' => $trainId,
  1641. 'submitStatus' => 1
  1642. );
  1643. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1644. Doo::loadModel ( 'staff' );
  1645. $staff = new staff ();
  1646. $username2 = $staff->getOne ( array (
  1647. 'select' => 'wxid',
  1648. 'where' => 'sid=' . $pendingApprovalsSid,
  1649. 'asArray' => TRUE
  1650. ) );
  1651. // 发送微信审批通知
  1652. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1653. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1654. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1655. }
  1656. /**
  1657. */
  1658. function invoiceStoreMailItemSet() {
  1659. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1660. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1661. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1662. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1663. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1664. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1665. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1666. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1667. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1668. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1669. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1670. Doo::loadClass ( 'XDeode' );
  1671. $XDeode = new XDeode ( 5 );
  1672. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1673. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1674. $isid = $XDeode->decode ( $storeKey );
  1675. $trainId = $XDeode->decode ( $trainKey );
  1676. if (! is_numeric ( $isid ))
  1677. die ( 'illegal request' );
  1678. Doo::loadModel ( 'invoiceStore' );
  1679. $invoiceStore = new invoiceStore ();
  1680. $mailList = array (
  1681. 'invoice' => 1,
  1682. 'mailItems' => $mailItems
  1683. );
  1684. if (! empty ( $softLock ))
  1685. $mailList += array (
  1686. 'softLock' => $softLockNum
  1687. );
  1688. else
  1689. $mailList += array (
  1690. 'softLock' => 0
  1691. );
  1692. if (! empty ( $contract ))
  1693. $mailList += array (
  1694. 'contract' => $contractNum
  1695. );
  1696. else
  1697. $mailList += array (
  1698. 'contract' => 0
  1699. );
  1700. if (! empty ( $instructions ))
  1701. $mailList += array (
  1702. 'instructions' => $instructionsNum
  1703. );
  1704. else
  1705. $mailList += array (
  1706. 'instructions' => 0
  1707. );
  1708. if (! empty ( $remittance ))
  1709. $mailList += array (
  1710. 'remittance' => $remittance
  1711. );
  1712. else
  1713. $mailList += array (
  1714. 'remittance' => ''
  1715. );
  1716. $mailString = '发票x1,备注:' . $mailItems;
  1717. if (! empty ( $softLock ))
  1718. $mailString .= ',软件锁x' . $softLockNum;
  1719. if (! empty ( $contract ))
  1720. $mailString .= ',合同x' . $contractNum;
  1721. if (! empty ( $instructions ))
  1722. $mailString .= ',说明书x' . $instructionsNum;
  1723. if (! empty ( $remittance ))
  1724. $mailString .= ',汇款账号单';
  1725. $item = array (
  1726. 'isid' => $isid,
  1727. 'doPost' => 1,
  1728. 'mailItems' => $mailString,
  1729. 'mailItemsJson' => json_encode ( $mailList )
  1730. );
  1731. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1732. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1733. }
  1734. /**
  1735. * 批量设置邮寄物品
  1736. */
  1737. function invoiceStoreBatchMailItemSet() {
  1738. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1739. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1740. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1741. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1742. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1743. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1744. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1745. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1746. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1747. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1748. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1749. Doo::loadClass ( 'XDeode' );
  1750. $XDeode = new XDeode ( 5 );
  1751. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1752. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1753. if (empty ( $trainKey ) || empty ( $storeKey ))
  1754. die ( 'illegal request-IdKey' );
  1755. $isidKeyList = explode ( ',', $storeKey );
  1756. $isidList = array ();
  1757. foreach ( $isidKeyList as $value ) {
  1758. $isid = $XDeode->decode ( $value );
  1759. if (! empty ( $isid ) && is_numeric ( $isid ))
  1760. array_push ( $isidList, $isid );
  1761. }
  1762. $isidString = implode ( ',', $isidList );
  1763. $trainId = $XDeode->decode ( $trainKey );
  1764. if (! is_numeric ( $isid ))
  1765. die ( 'illegal request' );
  1766. Doo::loadModel ( 'invoiceStore' );
  1767. $invoiceStore = new invoiceStore ();
  1768. $mailList = array (
  1769. 'invoice' => 1,
  1770. 'mailItems' => $mailItems
  1771. );
  1772. if (! empty ( $softLock ))
  1773. $mailList += array (
  1774. 'softLock' => $softLockNum
  1775. );
  1776. else
  1777. $mailList += array (
  1778. 'softLock' => 0
  1779. );
  1780. if (! empty ( $contract ))
  1781. $mailList += array (
  1782. 'contract' => $contractNum
  1783. );
  1784. else
  1785. $mailList += array (
  1786. 'contract' => 0
  1787. );
  1788. if (! empty ( $instructions ))
  1789. $mailList += array (
  1790. 'instructions' => $instructionsNum
  1791. );
  1792. else
  1793. $mailList += array (
  1794. 'instructions' => 0
  1795. );
  1796. if (! empty ( $remittance ))
  1797. $mailList += array (
  1798. 'remittance' => $remittance
  1799. );
  1800. else
  1801. $mailList += array (
  1802. 'remittance' => ''
  1803. );
  1804. $mailString = '发票x1,备注:' . $mailItems;
  1805. if (! empty ( $softLock ))
  1806. $mailString .= ',软件锁x' . $softLockNum;
  1807. if (! empty ( $contract ))
  1808. $mailString .= ',合同x' . $contractNum;
  1809. if (! empty ( $instructions ))
  1810. $mailString .= ',说明书x' . $instructionsNum;
  1811. if (! empty ( $remittance ))
  1812. $mailString .= ',汇款账号单';
  1813. $item = array (
  1814. 'doPost' => 1,
  1815. 'mailItems' => $mailString,
  1816. 'mailItemsJson' => json_encode ( $mailList )
  1817. );
  1818. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1819. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1820. }
  1821. /**
  1822. * 废弃
  1823. */
  1824. function ajaxGetMailItemByIstore() {
  1825. Doo::loadClass ( 'XDeode' );
  1826. $XDeode = new XDeode ( 5 );
  1827. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1828. $isid = $XDeode->decode ( $storeKey );
  1829. if (! is_numeric ( $isid ))
  1830. die ( 'illegal request' );
  1831. Doo::loadModel ( 'invoiceStore' );
  1832. $invoiceStore = new invoiceStore ();
  1833. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid );
  1834. $isDetail ['mailItemsJson'] = json_decode ( $isDetail ['mailItemsJson'], true );
  1835. echo json_encode ( $isDetail ['mailItemsJson'] );
  1836. exit ();
  1837. }
  1838. /**
  1839. * 终止开票
  1840. */
  1841. function invoiceDroppedDo() {
  1842. $droppedIidKey = $this->get_args ( 'droppedIidKey' ) ? $this->get_args ( 'droppedIidKey' ) : '';
  1843. Doo::loadModel ( 'invoice' );
  1844. $invoice = new invoice ();
  1845. Doo::loadModel ( 'invoiceOperationLog' );
  1846. $invoiceOperationLog = new invoiceOperationLog ();
  1847. $iid = $invoice->authcode ( $droppedIidKey );
  1848. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1849. die ( 'illegal request' );
  1850. $item = array (
  1851. 'iid' => $iid,
  1852. 'status' => 4,
  1853. 'updateTime' => date ( "Y-m-d H:i:s" )
  1854. );
  1855. $invoice->setInvoiceByCondition ( $item );
  1856. $item = array (
  1857. 'date' => date ( "Y-m-d H:i:s" ),
  1858. 'operation' => '终止了开票',
  1859. 'status' => 4,
  1860. 'img' => $this->staff [0] ['avatar'],
  1861. 'username' => $this->staff [0] ['username'],
  1862. 'uid' => $this->staff [0] ['sid'],
  1863. 'category' => $this->staff [0] ['category'],
  1864. 'iid' => $iid
  1865. );
  1866. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1867. return "/invoice";
  1868. }
  1869. /**
  1870. * 更新退票的邮寄信息
  1871. */
  1872. function invoiceUntreadMailDo() {
  1873. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  1874. $untreadCompany = $this->get_args ( 'untreadCompany' ) ? $this->get_args ( 'untreadCompany' ) : "";
  1875. $untreadNumber = $this->get_args ( 'untreadNumber' ) ? $this->get_args ( 'untreadNumber' ) : "";
  1876. $untreadItems = $this->get_args ( 'untreadItems' ) ? $this->get_args ( 'untreadItems' ) : "";
  1877. Doo::loadModel ( 'invoice' );
  1878. $invoice = new invoice ();
  1879. $iid = $invoice->authcode ( $untreadIidKey );
  1880. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1881. die ( 'illegal request' );
  1882. $item = array (
  1883. 'iid' => $iid,
  1884. 'untreadCompany' => $untreadCompany,
  1885. 'untreadNumber' => $untreadNumber,
  1886. 'untreadItems' => $untreadItems
  1887. );
  1888. $invoice->setInvoiceByCondition ( $item );
  1889. return "/invoice";
  1890. }
  1891. /**
  1892. * 申请退票 --
  1893. */
  1894. function invoiceUntreadDo() {
  1895. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  1896. $untreadReason = $this->get_args ( 'untreadReason' ) ? $this->get_args ( 'untreadReason' ) : "";
  1897. $untreadPost = $this->get_args ( 'untreadPost' ) ? $this->get_args ( 'untreadPost' ) : "";
  1898. Doo::loadModel ( 'invoice' );
  1899. $invoice = new invoice ();
  1900. Doo::loadModel ( 'invoiceOperationLog' );
  1901. $invoiceOperationLog = new invoiceOperationLog ();
  1902. Doo::loadModel ( 'invoiceReceivables' );
  1903. $invoiceReceivables = new invoiceReceivables ();
  1904. $iid = $invoice->authcode ( $untreadIidKey );
  1905. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1906. die ( 'illegal request' );
  1907. /*
  1908. * 需求变革 有绑定收款也可以退票 $lt = $invoiceReceivables->getInvoiceReceivablesByIid ( $untreadIidKey ); if (! empty ( $lt )) { header ( 'Content-Type:text/html;charset=utf-8' ); die ( '该发票有收款绑定,请先移除!' ); }
  1909. */
  1910. $item = array (
  1911. 'iid' => $iid,
  1912. 'untreadStatus' => 1,
  1913. 'untreadReason' => $untreadReason,
  1914. 'untreadPost' => $untreadPost,
  1915. 'updateTime' => date ( "Y-m-d H:i:s" )
  1916. );
  1917. $invoice->setInvoiceByCondition ( $item );
  1918. $item = array (
  1919. 'date' => date ( "Y-m-d H:i:s" ),
  1920. 'operation' => '申请退票',
  1921. 'status' => 7,
  1922. 'img' => $this->staff [0] ['avatar'],
  1923. 'username' => $this->staff [0] ['username'],
  1924. 'uid' => $this->staff [0] ['sid'],
  1925. 'category' => $this->staff [0] ['category'],
  1926. 'iid' => $iid
  1927. );
  1928. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1929. return "/invoice";
  1930. }
  1931. /**
  1932. * 删除已终止的开票
  1933. */
  1934. function invoiceDelDo() {
  1935. Doo::loadModel ( 'invoice' );
  1936. $invoice = new invoice ();
  1937. Doo::loadModel ( 'invoiceOperationLog' );
  1938. $invoiceOperationLog = new invoiceOperationLog ();
  1939. Doo::loadClass ( 'XDeode' );
  1940. $XDeode = new XDeode ( 5 );
  1941. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  1942. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  1943. $iid = $XDeode->decode ( $iid );
  1944. Doo::loadModel ( 'invoiceStore' );
  1945. $invoiceStore = new invoiceStore ();
  1946. if (! is_numeric ( $iid ))
  1947. die ( 'illegal request' );
  1948. $invoiceDetail = $invoice->getMyInvoice ( $sid, $iid );
  1949. if (empty ( $invoiceDetail ))
  1950. die ( 'illegal request' );
  1951. $item = array (
  1952. 'iid' => $iid,
  1953. 'isDelete' => 1,
  1954. 'updateTime' => date ( "Y-m-d H:i:s" )
  1955. );
  1956. $invoice->setInvoiceByCondition ( $item );
  1957. $item = array (
  1958. 'date' => date ( "Y-m-d H:i:s" ),
  1959. 'operation' => '删除了已终止的发票',
  1960. 'status' => 4,
  1961. 'img' => $this->staff [0] ['avatar'],
  1962. 'username' => $this->staff [0] ['username'],
  1963. 'uid' => $this->staff [0] ['sid'],
  1964. 'category' => $this->staff [0] ['category'],
  1965. 'iid' => $iid
  1966. );
  1967. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1968. // 删除培训班发票仓库里的发票
  1969. $invoiceStore->delInvoiceStoreByIsid ( $invoiceDetail ['isid'] );
  1970. return "/invoice";
  1971. }
  1972. /**
  1973. */
  1974. function invoiceApproval() {
  1975. Doo::loadModel ( 'invoice' );
  1976. $invoice = new invoice ();
  1977. Doo::loadClass ( 'XDeode' );
  1978. $XDeode = new XDeode ( 5 );
  1979. Doo::loadModel ( 'staff' );
  1980. $staff = new staff ();
  1981. $invoiceList = $invoice->find ( array (
  1982. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  1983. 'desc' => 'iid',
  1984. 'limit' => 10,
  1985. 'asArray' => true
  1986. ) );
  1987. foreach ( $invoiceList as $key => $value ) {
  1988. $invoiceList [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1989. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1990. if (! empty ( $lastApprover )) {
  1991. $lastApproverKey = array_keys ( $lastApprover );
  1992. $lastApprover = end ( $lastApprover );
  1993. $staffDetail = $staff->getOne ( array (
  1994. 'where' => 'sid=' . end ( $lastApproverKey ),
  1995. 'asArray' => true
  1996. ) );
  1997. $lastApprover ['username'] = $staffDetail ['username'];
  1998. }
  1999. $invoiceList [$key] ['lastApprover'] = $lastApprover;
  2000. }
  2001. $ilist = $invoice->getInvoiceByProcessStatus ();
  2002. foreach ( $ilist as $key => $value ) {
  2003. $ilist [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2004. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2005. if (! empty ( $lastApprover )) {
  2006. $lastApproverKey = array_keys ( $lastApprover );
  2007. $lastApprover = end ( $lastApprover );
  2008. $staffDetail = $staff->getOne ( array (
  2009. 'where' => 'sid=' . end ( $lastApproverKey ),
  2010. 'asArray' => true
  2011. ) );
  2012. $lastApprover ['username'] = $staffDetail ['username'];
  2013. }
  2014. $ilist [$key] ['lastApprover'] = $lastApprover;
  2015. }
  2016. // print_r($ilist);
  2017. $this->data ['invoiceList'] = $invoiceList;
  2018. $this->data ['ilist'] = $ilist;
  2019. $this->data ['memu'] = "invoice";
  2020. $this->data ['staff'] = $this->staff;
  2021. $this->data ['receiptMemu'] = 'invoiceApproval';
  2022. $this->render ( "/admin/invoiceApproval", $this->data );
  2023. }
  2024. function invoiceDetail() {
  2025. Doo::loadClass ( 'XDeode' );
  2026. $XDeode = new XDeode ( 5 );
  2027. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  2028. $iid = $XDeode->decode ( $iid );
  2029. if (! is_numeric ( $iid ))
  2030. die ( 'illegal request' );
  2031. Doo::loadModel ( 'invoice' );
  2032. $invoice = new invoice ();
  2033. Doo::loadModel ( 'invoiceOperationLog' );
  2034. $invoiceOperationLog = new invoiceOperationLog ();
  2035. $invoiceDetail = $invoice->getOne ( array (
  2036. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'] . ' and iid=' . $iid,
  2037. 'asArray' => true
  2038. ) );
  2039. if (empty ( $invoiceDetail ))
  2040. die ( 'illegal request' );
  2041. if ($invoiceDetail ['settlementType'] == 1) {
  2042. Doo::loadModel ( 'invoiceTraining' );
  2043. $invoiceTraining = new invoiceTraining ();
  2044. $invoiceDetail ['invoiceTraining'] = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceDetail ['trainId'] );
  2045. }
  2046. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  2047. $this->data ['invoiceDetail'] = $invoiceDetail;
  2048. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  2049. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  2050. $this->data ['memu'] = "invoice";
  2051. $this->data ['staff'] = $this->staff;
  2052. $this->data ['receiptMemu'] = 'invoiceApproval';
  2053. $this->render ( "/admin/invoiceApprovalDetail", $this->data );
  2054. }
  2055. /**
  2056. * 对发票进行审批,其中操作有终止,退回,同意动作。操作成功并记录下操作日志
  2057. *
  2058. * @since 1.0.0
  2059. * @var integer iid 开票ID 已加密
  2060. * @var integer status 发票审批状态
  2061. * @var integer opintion 审批发票的意见
  2062. * @return string 如操作成功返回审批首页
  2063. */
  2064. function invoiceApprovalDo() {
  2065. Doo::loadModel ( 'invoice' );
  2066. $invoice = new invoice ();
  2067. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2068. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  2069. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  2070. $divApproval = $this->get_args ( 'divApproval' ) ? $this->get_args ( 'divApproval' ) : "";
  2071. $iid = $invoice->authcode ( $iid );
  2072. if (! is_numeric ( $iid ))
  2073. die ( 'illegal request' );
  2074. // && ! empty ( $opinion )
  2075. if (! empty ( $iid ) && ! empty ( $status )) {
  2076. if (! ($status == 2 || $status == 3 || $status == 4))
  2077. die ( 'illegal request' );
  2078. Doo::loadModel ( 'invoiceOperationLog' );
  2079. $invoiceOperationLog = new invoiceOperationLog ();
  2080. $invoiceDetail = $invoice->getOne ( array (
  2081. 'where' => 'status=1 and iid=' . $iid . ' and pendingApprovals=' . $this->staff [0] ['sid'],
  2082. 'asArray' => true
  2083. ) );
  2084. if (empty ( $invoiceDetail ))
  2085. die ( 'illegal request' );
  2086. $processApprovals = json_decode ( $invoiceDetail ['processApprovals'], true );
  2087. $invoiceManage = json_decode ( $invoiceDetail ['invoiceManage'], true );
  2088. if ($status == 3) {
  2089. $invoice->status = $status;
  2090. $item = array (
  2091. 'operation' => $opinion
  2092. );
  2093. } else {
  2094. if (empty ( $processApprovals )) {
  2095. $processApprovals = array (
  2096. $this->staff [0] ['sid'] => array (
  2097. 'date' => date ( "Y-m-d H:i:s" ),
  2098. 'opinion' => $opinion,
  2099. 'status' => $status
  2100. )
  2101. );
  2102. // var_dump(next($invoiceManage));
  2103. $nextInvoiceManage = next ( $invoiceManage );
  2104. // print_r($nextInvoiceManage);
  2105. if ($status != 4 && $nextInvoiceManage !== false)
  2106. $invoice->pendingApprovals = $nextInvoiceManage [0];
  2107. $invoice->processApprovals = json_encode ( $processApprovals );
  2108. // var_dump($invoice);
  2109. // print_r($invoiceManage);
  2110. } else {
  2111. $processApprovals [$this->staff [0] ['sid']] = array (
  2112. 'date' => date ( "Y-m-d H:i:s" ),
  2113. 'opinion' => $opinion,
  2114. 'status' => $status
  2115. );
  2116. $pendingApprovals = 0;
  2117. foreach ( $invoiceManage as $key => $value ) {
  2118. if ($value [0] == $this->staff [0] ['sid']) {
  2119. if (isset ( $invoiceManage [$key + 1] ))
  2120. $pendingApprovals = $invoiceManage [$key + 1] [0];
  2121. break;
  2122. }
  2123. }
  2124. if ($status != 4 && ! empty ( $pendingApprovals ))
  2125. $invoice->pendingApprovals = $pendingApprovals;
  2126. $invoice->processApprovals = json_encode ( $processApprovals );
  2127. }
  2128. $item = array (
  2129. 'operation' => $opinion
  2130. );
  2131. if (count ( $processApprovals ) == count ( $invoiceManage ) && $status != 4) {
  2132. $invoice->status = $status;
  2133. $invoice->pendingApprovals = 0;
  2134. $invoice->approvalTime = date ( "Y-m-d H:i:s" );
  2135. } elseif ($status == 4) {
  2136. $invoice->status = $status;
  2137. $item = array (
  2138. 'operation' => $opinion
  2139. );
  2140. }
  2141. }
  2142. $invoice->updateTime = date ( "Y-m-d H:i:s" );
  2143. $invoice->update ( array (
  2144. 'where' => 'iid=' . $iid
  2145. ) );
  2146. $item += array (
  2147. 'date' => date ( "Y-m-d H:i:s" ),
  2148. 'img' => $this->staff [0] ['avatar'],
  2149. 'username' => $this->staff [0] ['username'],
  2150. 'uid' => $this->staff [0] ['sid'],
  2151. 'category' => $this->staff [0] ['category'],
  2152. 'status' => $status,
  2153. 'iid' => $iid
  2154. );
  2155. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2156. if (empty ( $divApproval ))
  2157. return '/invoiceApproval';
  2158. else
  2159. return '/invoiceApprovalAchieve/PEND';
  2160. }
  2161. die ( 'illegal request' );
  2162. }
  2163. /**
  2164. * 展示需要打印的发票数据
  2165. *
  2166. * @since 1.0.0
  2167. */
  2168. function invoicePrint() {
  2169. Doo::loadModel ( 'invoice' );
  2170. $invoice = new invoice ();
  2171. Doo::loadClass ( 'XDeode' );
  2172. $XDeode = new XDeode ( 5 );
  2173. Doo::loadModel ( 'staff' );
  2174. $staff = new staff ();
  2175. $toPrint = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0 );
  2176. $printed = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 1 );
  2177. foreach ( $toPrint as $key => $value ) {
  2178. $toPrint [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2179. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2180. if (! empty ( $lastApprover )) {
  2181. $lastApproverKey = array_keys ( $lastApprover );
  2182. $lastApprover = end ( $lastApprover );
  2183. $staffDetail = $staff->getOne ( array (
  2184. 'where' => 'sid=' . end ( $lastApproverKey ),
  2185. 'asArray' => true
  2186. ) );
  2187. $lastApprover ['username'] = $staffDetail ['username'];
  2188. }
  2189. $toPrint [$key] ['lastApprover'] = $lastApprover;
  2190. }
  2191. foreach ( $printed as $key => $value ) {
  2192. $printed [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2193. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2194. if (! empty ( $lastApprover )) {
  2195. $lastApproverKey = array_keys ( $lastApprover );
  2196. $lastApprover = end ( $lastApprover );
  2197. $staffDetail = $staff->getOne ( array (
  2198. 'where' => 'sid=' . end ( $lastApproverKey ),
  2199. 'asArray' => true
  2200. ) );
  2201. $lastApprover ['username'] = $staffDetail ['username'];
  2202. }
  2203. $printed [$key] ['lastApprover'] = $lastApprover;
  2204. }
  2205. $this->data ['printed'] = $printed;
  2206. $this->data ['toPrint'] = $toPrint;
  2207. $this->data ['memu'] = "invoice";
  2208. $this->data ['staff'] = $this->staff;
  2209. $this->data ['receiptMemu'] = 'invoicePrint';
  2210. $this->render ( "/admin/invoicePrint", $this->data );
  2211. }
  2212. /**
  2213. * 展示发票打印的详情页面
  2214. *
  2215. * @since 1.0.0
  2216. */
  2217. function invoicePrintDetail() {
  2218. Doo::loadClass ( 'XDeode' );
  2219. $XDeode = new XDeode ( 5 );
  2220. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  2221. $iid = $XDeode->decode ( $iid );
  2222. if (! is_numeric ( $iid ))
  2223. die ( 'illegal request' );
  2224. Doo::loadModel ( 'invoice' );
  2225. $invoice = new invoice ();
  2226. Doo::loadModel ( 'invoiceOperationLog' );
  2227. $invoiceOperationLog = new invoiceOperationLog ();
  2228. Doo::loadModel ( 'invoicePaper' );
  2229. $invoicePaper = new invoicePaper ();
  2230. $invoiceDetail = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0, $iid );
  2231. if (empty ( $invoiceDetail ))
  2232. die ( 'illegal request' );
  2233. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $invoiceDetail ['invoiceType'],$invoiceDetail['invoiceForm'] );
  2234. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  2235. if ($invoiceDetail ['settlementType'] == 1) {
  2236. Doo::loadModel ( 'invoiceTraining' );
  2237. $invoiceTraining = new invoiceTraining ();
  2238. $invoiceDetail ['invoiceTraining'] = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceDetail ['trainId'] );
  2239. }
  2240. $this->data ['invoicePaperList'] = $invoicePaperList;
  2241. $this->data ['invoiceDetail'] = $invoiceDetail;
  2242. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  2243. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  2244. $this->data ['memu'] = "invoice";
  2245. $this->data ['staff'] = $this->staff;
  2246. $this->data ['receiptMemu'] = 'invoicePrint';
  2247. $this->render ( "/admin/invoicePrintDetail", $this->data );
  2248. }
  2249. /**
  2250. * 所有待打印 发票
  2251. */
  2252. function invoicePrintStayAchieve() {
  2253. Doo::loadModel ( 'invoice' );
  2254. $invoice = new invoice ();
  2255. Doo::loadClass ( 'XDeode' );
  2256. $XDeode = new XDeode ( 5 );
  2257. Doo::loadModel ( 'staff' );
  2258. $staff = new staff ();
  2259. $MebSea = $this->get_args ( 'MebSea' ) ? urldecode ( $this->get_args ( 'MebSea' ) ) : "";
  2260. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  2261. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  2262. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  2263. Doo::loadModel ( 'invoiceTraining' );
  2264. $invoiceTraining = new invoiceTraining ();
  2265. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  2266. $page_size = 12;
  2267. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2268. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : "ALL";
  2269. // $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : "ALL";
  2270. $get = "/" . $status;
  2271. $con = ' and status=2 ';
  2272. if ($status == 'TOPRINT')
  2273. $con = ' and status=2 and printStatus=0 ';
  2274. elseif ($status == 'PRINTED')
  2275. $con = ' and status=2 and printStatus=1';
  2276. if ($invoiceType == 'ORDINARY')
  2277. $con .= ' and invoiceType=0 ';
  2278. elseif ($invoiceType == 'SPECIAL')
  2279. $con .= ' and invoiceType=1 ';
  2280. if ($invoiceTrain == 'ORDINARY')
  2281. $con .= ' and trainId=0 ';
  2282. elseif ($invoiceTrain == 'TRAIN')
  2283. $con .= ' and trainId!=0 ';
  2284. if ($invoiceTrainName != 'ALL') {
  2285. $trainId = $XDeode->decode ( $invoiceTrainName );
  2286. if (is_numeric ( $trainId ))
  2287. $con .= ' and trainId =' . $trainId;
  2288. }
  2289. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2290. $dateArr = explode ( ':', $date );
  2291. $D1 = '';
  2292. $D2 = '';
  2293. if (! empty ( $date )) {
  2294. $D1 = $dateArr [0];
  2295. $D2 = $dateArr [1];
  2296. }
  2297. if (! empty ( $D1 ) && ! empty ( $D2 ) && ! empty ( $date ))
  2298. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2299. if (! empty ( $MebSea )) {
  2300. $con .= ' and ( invoiceNo like "%' . $MebSea . '%" or invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  2301. }
  2302. $pageinfo ['page'] = array (
  2303. 'previous' => ''
  2304. );
  2305. $get .= "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&invoiceType=" . urlencode ( $invoiceType ) . "&invoiceTrain=" . urlencode ( $invoiceTrain ) . "";
  2306. $sql = " (untreadStatus=0 or untreadStatus=3) and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  2307. $action = "invoicePrintStayAchieve";
  2308. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2309. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2310. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  2311. $this->data ['trainList'] = $trainList;
  2312. $this->data ['invoiceType'] = $invoiceType;
  2313. $this->data ['invoiceTrain'] = $invoiceTrain;
  2314. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  2315. $this->data ['MebSeaEn'] = $MebSea;
  2316. $this->data ['MebSea'] = urlencode ( $MebSea );
  2317. $this->data ['get'] = $get;
  2318. $this->data ['page'] = $pageinfo;
  2319. $this->data ['date'] = $date;
  2320. $this->data ['status'] = $status;
  2321. $this->data ['invoiceType'] = $invoiceType;
  2322. $this->data ['memu'] = "invoice";
  2323. $this->data ['staff'] = $this->staff;
  2324. foreach ( $list as $key => $value ) {
  2325. $list [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2326. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2327. if (! empty ( $lastApprover )) {
  2328. $lastApproverKey = array_keys ( $lastApprover );
  2329. $lastApprover = end ( $lastApprover );
  2330. $staffDetail = $staff->getOne ( array (
  2331. 'where' => 'sid=' . end ( $lastApproverKey ),
  2332. 'asArray' => true
  2333. ) );
  2334. $lastApprover ['username'] = $staffDetail ['username'];
  2335. }
  2336. $list [$key] ['lastApprover'] = $lastApprover;
  2337. }
  2338. $this->data ['receiptMemu'] = 'invoicePrint';
  2339. $this->data ['list'] = $list;
  2340. $this->render ( "/admin/invoicePrintStayAchieve", $this->data );
  2341. }
  2342. /**
  2343. * 填写票号并完成打印
  2344. * @since 1.0.0
  2345. */
  2346. function invoicePrintDo() {
  2347. Doo::loadModel ( 'invoice' );
  2348. $invoice = new invoice ();
  2349. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2350. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  2351. $invoicePrintType = $this->get_args ( 'invoicePrintType' ) ? $this->get_args ( 'invoicePrintType' ) : "";
  2352. $iid = $invoice->authcode ( $iid );
  2353. if (! is_numeric ( $iid ))
  2354. die ( 'illegal request' );
  2355. if (! empty ( $iid ) && ! empty ( $invoiceNo )) {
  2356. Doo::loadModel ( 'invoiceOperationLog' );
  2357. $invoiceOperationLog = new invoiceOperationLog ();
  2358. Doo::loadModel ( 'invoiceStatistics' );
  2359. $invoiceStatistics = new invoiceStatistics ();
  2360. $XDeode = new XDeode ( 5 );
  2361. Doo::loadModel ( 'invoicePaper' );
  2362. $invoicePaper = new invoicePaper ();
  2363. $invoicePrintDetail = $invoice->getInvoiceByPrint ( $iid );
  2364. if (empty ( $invoicePrintDetail ))
  2365. die ( 'illegal request' );
  2366. //
  2367. $ipid = $XDeode->decode ( $invoiceNo );
  2368. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  2369. if (empty ( $paperDetail ))
  2370. die ( 'illegal request' );
  2371. $invoicePaper = new invoicePaper ();
  2372. $item = array (
  2373. 'iid' => $iid,
  2374. 'ipid' => $ipid
  2375. );
  2376. $invoicePaper->setInvoicePaperByCondition ( $item );
  2377. $item = array (
  2378. 'iid' => $iid,
  2379. 'printStatus' => 1,
  2380. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2381. 'printer' => $this->staff [0] ['username'],
  2382. 'printTime' => date ( "Y-m-d H:i:s" ),
  2383. 'invoiceNo' => $paperDetail ['invoiceNo']
  2384. );
  2385. $invoice->setInvoiceByCondition ( $item );
  2386. $item = array (
  2387. 'date' => date ( "Y-m-d H:i:s" ),
  2388. 'operation' => '打印发票号:' . $paperDetail ['invoiceNo'],
  2389. 'status' => 5,
  2390. 'img' => $this->staff [0] ['avatar'],
  2391. 'username' => $this->staff [0] ['username'],
  2392. 'uid' => $this->staff [0] ['sid'],
  2393. 'category' => $this->staff [0] ['category'],
  2394. 'iid' => $iid
  2395. );
  2396. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2397. // 去统计--负票不汇总
  2398. if ($invoicePrintDetail ['untreadStatus'] != 4) {
  2399. $item = array (
  2400. 'date' => date ( "Y-m-d H:i:s" ),
  2401. 'priceClass' => 1,
  2402. 'cid' => $invoicePrintDetail ['cid'],
  2403. 'staff' => $invoicePrintDetail ['sid'],
  2404. 'invoicePrice' => $invoicePrintDetail ['invoicePrice']
  2405. );
  2406. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2407. }
  2408. // 发送通知信息到微信-去除
  2409. // $this->setWXMsg($iid,'PRINT');
  2410. // 发票信息库
  2411. $this->autoUpdateInvoiceInfoBase ( $invoicePrintDetail );
  2412. // 申请人获取微信通知
  2413. Doo::loadModel ( 'staff' );
  2414. $staff = new staff ();
  2415. Doo::loadClass ( 'XDeode' );
  2416. $XDeode = new XDeode ( 5 );
  2417. $username2 = $staff->getOne ( array (
  2418. 'select' => 'wxid',
  2419. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2420. 'asArray' => TRUE
  2421. ) );
  2422. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '完成打印';
  2423. $msg = '';
  2424. $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/' . $XDeode->encode ( $invoicePrintDetail ['iid'] ) . '.html';
  2425. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2426. if (empty ( $invoicePrintType ))
  2427. return "/invoicePrint";
  2428. else
  2429. return "/invoicePrintStayAchieve";
  2430. }
  2431. }
  2432. /**
  2433. * 需要邮寄的发票
  2434. * @since 1.0.0
  2435. */
  2436. function invoicePost() {
  2437. Doo::loadModel ( 'invoice' );
  2438. $invoice = new invoice ();
  2439. Doo::loadModel ( 'express' );
  2440. $express = new express ();
  2441. $invoicePost = $invoice->getPostByInvoice ();
  2442. $invoicePosted = $invoice->getPostByInvoice ( 1 );
  2443. $expressList = $express->getExpressByAll ();
  2444. $invoicePostExpress = "";
  2445. if (isset ( $_COOKIE ["invoicePostExpress"] ))
  2446. $invoicePostExpress = $_COOKIE ["invoicePostExpress"];
  2447. $this->data ['invoicePostExpress'] = $invoicePostExpress;
  2448. $this->data ['expressList'] = $expressList;
  2449. $this->data ['invoicePost'] = $invoicePost;
  2450. $this->data ['invoicePosted'] = $invoicePosted;
  2451. $this->data ['memu'] = "invoice";
  2452. $this->data ['staff'] = $this->staff;
  2453. $this->data ['receiptMemu'] = 'invoicePost';
  2454. $this->render ( "/admin/invoicePost", $this->data );
  2455. }
  2456. /**
  2457. * 添加发票邮寄信息
  2458. */
  2459. function invoiceExpressAddDo() {
  2460. Doo::loadModel ( 'invoice' );
  2461. $invoice = new invoice ();
  2462. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2463. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2464. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2465. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2466. $iid = $iid = $invoice->authcode ( $iid );
  2467. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2468. die ( 'illegal request' );
  2469. $invoicePrintDetail = $invoice->getInvoiceByIid ( $iid );
  2470. setcookie ( 'invoicePostExpress', $expressNumber );
  2471. $item = array (
  2472. 'iid' => $iid,
  2473. 'postStatus' => 1,
  2474. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2475. 'postTime' => date ( "Y-m-d H:i:s" ),
  2476. 'expressCompany' => $expressCompany,
  2477. 'expressNumber' => $expressNumber,
  2478. 'actualItems' => $actualItems,
  2479. 'poster' => $this->staff [0] ['username']
  2480. );
  2481. $invoice->setInvoiceByCondition ( $item );
  2482. // 微信通知-去掉
  2483. // $this->setWXMsg ( $iid );
  2484. Doo::loadModel ( 'staff' );
  2485. $staff = new staff ();
  2486. Doo::loadClass ( 'XDeode' );
  2487. $XDeode = new XDeode ( 5 );
  2488. $username2 = $staff->getOne ( array (
  2489. 'select' => 'wxid',
  2490. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2491. 'asArray' => TRUE
  2492. ) );
  2493. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '已邮寄';
  2494. $expCom = explode ( ":", $invoicePrintDetail ['expressCompany'] );
  2495. if (empty ( $expCom ))
  2496. $expCom [0] = '';
  2497. $msg = $expCom [0] . ':' . $invoicePrintDetail ['expressNumber'] . '';
  2498. $url = 'https://m.kuaidi100.com/result.jsp?nu=' . $invoicePrintDetail ['expressNumber'];
  2499. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2500. return '/invoicePost';
  2501. }
  2502. function invoiceExpressUpdateDo() {
  2503. Doo::loadModel ( 'invoice' );
  2504. $invoice = new invoice ();
  2505. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  2506. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2507. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2508. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2509. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2510. $iid = $invoice->authcode ( $iid );
  2511. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2512. die ( 'illegal request' );
  2513. $item = array (
  2514. 'iid' => $iid,
  2515. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2516. 'expressCompany' => $expressCompany,
  2517. 'expressNumber' => $expressNumber,
  2518. 'actualItems' => $actualItems,
  2519. 'poster' => $this->staff [0] ['username']
  2520. );
  2521. $invoice->setInvoiceByCondition ( $item );
  2522. return $action;
  2523. }
  2524. /**
  2525. * 可退票管理
  2526. */
  2527. function invoiceUntreadIsAchieve() {
  2528. Doo::loadModel ( 'invoice' );
  2529. $invoice = new invoice ();
  2530. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2531. /*
  2532. * 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' => '' );
  2533. */
  2534. if (empty ( $MebSea )) {//
  2535. $con = ' and invoiceNo like "NULL" ';
  2536. } else {
  2537. $con = ' and (invoiceNo like "%' . $MebSea . '%" or invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  2538. }
  2539. // printStatus=1 and
  2540. $sql = " (untreadStatus=0 or untreadStatus=3) and status=2 and sid=" . $this->staff [0] ['sid'] . $con;
  2541. /*
  2542. * $action = "invoiceUntreadIsAchieve"; $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" ); $limit = $pageinfo ['lower'] . ',' . $page_size;
  2543. */
  2544. $limit = '0,20';
  2545. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2546. //print_r($list);
  2547. $this->data ['MebSeaEn'] = $MebSea;
  2548. /*
  2549. * $this->data ['get'] = $get; $this->data ['page'] = $pageinfo; $this->data ['date'] = $date;
  2550. */
  2551. $this->data ['list'] = $list;
  2552. $this->data ['memu'] = "invoice";
  2553. $this->data ['staff'] = $this->staff;
  2554. $this->data ['receiptMemu'] = 'invoice';
  2555. $this->render ( "/admin/invoiceUntreadIsAchieve", $this->data );
  2556. }
  2557. // 已经退票的发票
  2558. function invoiceUntreadED() {
  2559. Doo::loadModel ( 'invoice' );
  2560. $invoice = new invoice ();
  2561. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2562. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "";
  2563. Doo::loadClass ( 'XDeode' );
  2564. $XDeode = new XDeode ( 5 );
  2565. $page_size = 18;
  2566. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2567. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2568. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  2569. $dateArr = explode ( ':', $date );
  2570. $D1 = '';
  2571. $D2 = '';
  2572. if (! empty ( $date )) {
  2573. $D1 = $dateArr [0];
  2574. $D2 = $dateArr [1];
  2575. }
  2576. $con = '';
  2577. if (! empty ( $D1 ) && ! empty ( $D2 )) {
  2578. $con = ' and bindTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2579. }
  2580. // if ($date == 'MONTHO')
  2581. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  2582. // elseif ($date == 'MONTHT')
  2583. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  2584. // elseif ($date == 'MONTHY')
  2585. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  2586. if (! empty ( $MebSea )) {
  2587. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  2588. }
  2589. if ($invoiceType == 'ORDINARY') {
  2590. $con .= ' and invoiceType=0 ';
  2591. } elseif ($invoiceType == 'SPECIAL') {
  2592. $con .= ' and invoiceType=1 ';
  2593. }
  2594. $pageinfo ['page'] = array (
  2595. 'previous' => ''
  2596. );
  2597. // printStatus=1 and
  2598. $sql = " (untreadStatus=2 ) and status=2 and sid=" . $this->staff [0] ['sid'] . $con;
  2599. $action = "invoiceUntreadED";
  2600. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2601. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2602. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2603. // print_r($list);
  2604. $this->data ['MebSeaEn'] = $MebSea;
  2605. $this->data ['get'] = $get;
  2606. $this->data ['page'] = $pageinfo;
  2607. $this->data ['date'] = $date;
  2608. $this->data ['invoiceType'] = $invoiceType;
  2609. $this->data ['list'] = $list;
  2610. $this->data ['memu'] = "invoice";
  2611. $this->data ['staff'] = $this->staff;
  2612. $this->data ['receiptMemu'] = 'invoice';
  2613. $this->render ( "/admin/invoiceUntreadED", $this->data );
  2614. }
  2615. /**
  2616. * 退票处理页面
  2617. */
  2618. function invoiceUntread() {
  2619. Doo::loadModel ( 'invoice' );
  2620. $invoice = new invoice ();
  2621. $untreadInvoice = $invoice->getInvoiceByUntreadStatus ( 1, 0, 50 );
  2622. $establishedInvoice = $invoice->getInvoiceByUntreadStatus ( 2 );
  2623. foreach ( $establishedInvoice as $key => $value ) {
  2624. // months
  2625. $lossDate = strtotime ( "+1 month", strtotime ( $value ['OperationLog'] ['date'] ) );
  2626. $nowDate = strtotime ( 'now' );
  2627. $establishedInvoice [$key] ['lossShow'] = false;
  2628. if ($lossDate < $nowDate)
  2629. $establishedInvoice [$key] ['lossShow'] = true;
  2630. }
  2631. $this->data ['untreadInvoice'] = $untreadInvoice;
  2632. $this->data ['establishedInvoice'] = $establishedInvoice;
  2633. $this->data ['memu'] = "invoice";
  2634. $this->data ['staff'] = $this->staff;
  2635. $this->data ['receiptMemu'] = 'invoiceUntread';
  2636. $this->render ( "/admin/invoiceUntread", $this->data );
  2637. }
  2638. /**
  2639. * 确认收到退回的发票,开票状态为退回 //收款状态解绑,公司统计扣除入账额度
  2640. */
  2641. function invoiceUntreadEstablishedDo() {
  2642. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  2643. Doo::loadModel ( 'invoice' );
  2644. $invoice = new invoice ();
  2645. Doo::loadModel ( 'invoiceOperationLog' );
  2646. $invoiceOperationLog = new invoiceOperationLog ();
  2647. Doo::loadModel ( 'invoiceReceivables' );
  2648. Doo::loadModel ( 'invoiceStatistics' );
  2649. $iid = $invoice->authcode ( $untreadIidKey );
  2650. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2651. die ( 'illegal request' );
  2652. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  2653. if ($invoiceDetails ['untreadStatus'] != 1)
  2654. die ( 'illegal request untreadStatus error !=1' );
  2655. $item = array (
  2656. 'iid' => $iid,
  2657. // 'irid'=>'',
  2658. 'untreadStatus' => 2,
  2659. 'updateTime' => date ( "Y-m-d H:i:s" )
  2660. );
  2661. $invoice->setInvoiceByCondition ( $item );
  2662. $item = array (
  2663. 'date' => date ( "Y-m-d H:i:s" ),
  2664. 'operation' => '已确认退票',
  2665. 'status' => 6,
  2666. 'img' => $this->staff [0] ['avatar'],
  2667. 'username' => $this->staff [0] ['username'],
  2668. 'uid' => $this->staff [0] ['sid'],
  2669. 'category' => $this->staff [0] ['category'],
  2670. 'iid' => $iid
  2671. );
  2672. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2673. // 收款解绑以及入账扣除 收款扣除
  2674. if (! empty ( $invoiceDetails ['irid'] )) {
  2675. $iridList = explode ( ',', $invoiceDetails ['irid'] );
  2676. foreach ( $iridList as $value ) {
  2677. $invoiceReceivables = new invoiceReceivables ();
  2678. $irDetails = $invoiceReceivables->getOne ( array (
  2679. 'where' => " irid=" . $value . ' and bindStatus=1',
  2680. 'asArray' => TRUE
  2681. ) );
  2682. $item = array (
  2683. 'irid' => $value,
  2684. 'bindStatus' => 0,
  2685. 'untreadStatus' => 1,
  2686. 'untreadStaff' => $invoiceDetails ['userName'],
  2687. 'unbundlingTime' => date ( "Y-m-d H:i:s" ),
  2688. 'iid' => 0
  2689. );
  2690. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2691. if (! empty ( $irDetails )) {
  2692. // 扣除入账
  2693. $invoiceStatistics = new invoiceStatistics ();
  2694. $item = array (
  2695. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2696. 'priceClass' => 3,
  2697. 'cid' => $invoiceDetails ['cid'],
  2698. 'staff' => $invoiceDetails ['sid'],
  2699. 'accountPrice' => - $irDetails ['receivablesPrice']
  2700. );
  2701. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2702. // 扣除收款
  2703. $invoiceStatistics = new invoiceStatistics ();
  2704. $item = array (
  2705. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2706. 'priceClass' => 2,
  2707. 'cid' => $invoiceDetails ['cid'],
  2708. 'staff' => $invoiceDetails ['sid'],
  2709. 'irid' => $irDetails ['irid'],
  2710. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  2711. );
  2712. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2713. }
  2714. // 解绑时删除收入流水
  2715. Doo::loadModel ( 'wasteBook' );
  2716. $wasteBook = new wasteBook ();
  2717. $wasteBook->delete ( array (
  2718. 'where' => 'dataID=' . $value . ' and accountType=7',
  2719. 'limit' => 1
  2720. ) );
  2721. }
  2722. }
  2723. return "/invoiceUntread";
  2724. }
  2725. function invoiceUntreadRecallDo() {
  2726. $iidKey = isset ( $this->params ['iidKey'] ) ? $this->params ['iidKey'] : "";
  2727. Doo::loadModel ( 'invoice' );
  2728. $invoice = new invoice ();
  2729. Doo::loadClass ( 'XDeode' );
  2730. $XDeode = new XDeode ( 5 );
  2731. Doo::loadModel ( 'invoiceOperationLog' );
  2732. $invoiceOperationLog = new invoiceOperationLog ();
  2733. $iid = $XDeode->decode ( $iidKey );
  2734. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  2735. if (empty ( $invoiceDetail )) {
  2736. die ( 'illegal request-DATANULL' );
  2737. }
  2738. $item = array (
  2739. 'iid' => $iid,
  2740. 'untreadStatus' => 0
  2741. );
  2742. $invoice->setInvoiceByCondition ( $item );
  2743. $item = array (
  2744. 'date' => date ( "Y-m-d H:i:s" ),
  2745. 'operation' => '撤回申请退票',
  2746. 'status' => 13,
  2747. 'img' => $this->staff [0] ['avatar'],
  2748. 'username' => $this->staff [0] ['username'],
  2749. 'uid' => $this->staff [0] ['sid'],
  2750. 'category' => $this->staff [0] ['category'],
  2751. 'iid' => $iid
  2752. );
  2753. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2754. return "/invoiceUntread";
  2755. }
  2756. /**
  2757. * 建立负票,关联原来发票
  2758. */
  2759. function invoiceLossDo() {
  2760. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2761. if (! empty ( $iidKey )) {
  2762. Doo::loadClass ( 'XDeode' );
  2763. $XDeode = new XDeode ( 5 );
  2764. Doo::loadModel ( 'invoice' );
  2765. $invoice = new invoice ();
  2766. Doo::loadModel ( 'invoiceOperationLog' );
  2767. $invoiceOperationLog = new invoiceOperationLog ();
  2768. $iidKey = $XDeode->decode ( $iidKey );
  2769. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  2770. // 拷贝插入一条发票数据
  2771. $iid = $invoice->setInvoiceLoss ( $iidKey );
  2772. // 更新负票
  2773. $invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  2774. $invoice = new invoice ();
  2775. $item = array (
  2776. 'iid' => $iid,
  2777. 'sid' => $this->staff [0] ['sid'],
  2778. 'userName' => $this->staff [0] ['username'],
  2779. 'cid' => $this->staff [0] ['cid'],
  2780. 'categoryName' => $this->staff [0] ['category'],
  2781. 'invoiceQuantity' => - $invoiceDetail ['invoiceQuantity'],
  2782. 'invoicePrice' => - $invoiceDetail ['invoicePrice'],
  2783. 'invoiceSerial' => $invoiceSerial,
  2784. 'invoiceNo' => '',
  2785. 'printStatus' => 0,
  2786. 'untreadStatus' => 4,
  2787. // 关联发票号
  2788. 'lossIid' => $invoiceDetail ['iid']
  2789. );
  2790. $invoice->setInvoiceByCondition ( $item );
  2791. // 更新原发票
  2792. $invoice = new invoice ();
  2793. $item = array (
  2794. 'iid' => $invoiceDetail ['iid'],
  2795. 'lossIid' => $iid
  2796. );
  2797. $invoice->setInvoiceByCondition ( $item );
  2798. // 操作日志
  2799. $item = array (
  2800. 'date' => date ( "Y-m-d H:i:s" ),
  2801. 'operation' => "创建负票" . $invoiceSerial,
  2802. 'status' => 12,
  2803. 'img' => $this->staff [0] ['avatar'],
  2804. 'username' => $this->staff [0] ['username'],
  2805. 'uid' => $this->staff [0] ['sid'],
  2806. 'category' => $this->staff [0] ['category'],
  2807. 'iid' => $iid
  2808. );
  2809. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2810. // print_r($invoiceDetail);
  2811. // echo $iid;die;
  2812. }
  2813. return '/invoiceUntread';
  2814. }
  2815. /**
  2816. * 上传银行到账 收款文件
  2817. */
  2818. function invoiceReceivablesBankUpload() {
  2819. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  2820. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  2821. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  2822. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  2823. header ( "HTTP/1.1 500 Internal Server Error" );
  2824. echo "POST exceeded maximum allowed size.";
  2825. exit ( 0 );
  2826. }
  2827. // Settings
  2828. $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)
  2829. $upload_name = "Filedata";
  2830. $file_name = "";
  2831. $nk = time ();
  2832. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  2833. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  2834. echo "文件无法保存.";
  2835. exit ( 0 );
  2836. }
  2837. echo json_encode ( array (
  2838. 'filename' => $file_name,
  2839. 'id' => $nk
  2840. ) );
  2841. exit ( 0 );
  2842. }
  2843. /**
  2844. * 解析银行到账收款execl并导入库中
  2845. */
  2846. function invoiceReceivablesImport() {
  2847. $path = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  2848. if ($path != "") {
  2849. Doo::loadModel ( 'invoiceReceivables' );
  2850. $invoiceReceivables = new invoiceReceivables ();
  2851. Doo::loadClass ( 'invoice.func' );
  2852. Doo::loadModel ( 'invoiceROLog' );
  2853. $invoiceROLog = new invoiceROLog ();
  2854. Doo::loadModel ( 'invoiceStatistics' );
  2855. $invoiceStatistics = new invoiceStatistics ();
  2856. $exlArray = formatExcelToArrayBank ( DOO::conf ()->SITE_PATH . "upload/invoiceReceivablesBank/" . $path );
  2857. $bankBatchNumber = 'BBN_' . time ();
  2858. Doo::db ()->beginTransaction ();
  2859. // 批量存储收款--由于必须获得收款ID,
  2860. $sql = 'INSERT INTO CLD_invoiceReceivables (OriginalPrice,receivablesPrice, receivablesMessage,receivablesSerial,receivablesBank,receivablesDate,inputStaff,date,receivablesCategory,receivablesStaff,bankBatchNumber,recepitTitleMark)
  2861. VALUES ';
  2862. $date = date ( "Y-m-d" );
  2863. $receivablesList = array ();
  2864. foreach ( $exlArray as $key => $value ) {
  2865. $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"] . '")';
  2866. array_push ( $receivablesList, $receivablesSql );
  2867. }
  2868. $sql = $sql . implode ( ',', $receivablesList );
  2869. // echo $sql;
  2870. Doo::db ()->query ( $sql );
  2871. // 批量存储收款统计
  2872. // 获得刚刚导入数据的irid组-缺少办事处和人员
  2873. $iridList = $invoiceReceivables->getInvoiceReceivablesByBBN ( $bankBatchNumber );
  2874. // 没有irid 回滚所有操作
  2875. if (empty ( $iridList )) {
  2876. Doo::db ()->rollBack ();
  2877. header ( 'Content-Type:text/html;charset=utf-8' );
  2878. die ( '文档或数据不正确,请重新<a href="/invoiceReceivables">上传</a>.' );
  2879. }
  2880. $sql = 'INSERT INTO CLD_invoiceStatistics (date, priceClass,irid,receivablesPrice)
  2881. VALUES ';
  2882. $statisticsList = array ();
  2883. foreach ( $iridList as $value ) {
  2884. $statisticsSql = '("' . $date . '",2,' . $value ['irid'] . ',' . $value ["receivablesPrice"] . ')';
  2885. array_push ( $statisticsList, $statisticsSql );
  2886. }
  2887. $sql = $sql . implode ( ',', $statisticsList );
  2888. Doo::db ()->query ( $sql );
  2889. // 批量存储操作日志
  2890. $sql = 'INSERT INTO CLD_invoiceROLog (operation, date,status,img, username,uid,category,irid)
  2891. VALUES ';
  2892. $ROLogList = array ();
  2893. foreach ( $iridList as $value ) {
  2894. $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'] . '")';
  2895. array_push ( $ROLogList, $ROLogSql );
  2896. }
  2897. $sql = $sql . implode ( ',', $ROLogList );
  2898. Doo::db ()->query ( $sql );
  2899. // 批量写入流水
  2900. $sql = 'INSERT INTO CLD_wasteBook (dataID, expensesType,accountType,accountPriceShow, accountPrice,accountBank,category,cid,name,sid,inputDate)
  2901. VALUES ';
  2902. $wasteBookList = array ();
  2903. foreach ( $iridList as $value ) {
  2904. $accountBank = '';
  2905. if ($value ['receivablesBank'] == '纵横广发') {
  2906. $accountBank = 'CGBDeposit';
  2907. } elseif ($value ['receivablesBank'] == '纵横工行') {
  2908. $accountBank = 'ICBCDeposit';
  2909. } elseif ($value ['receivablesBank'] == '华润银行') {
  2910. $accountBank = 'HUADeposit';
  2911. } elseif ($value ['receivablesBank'] == '个人广发') {
  2912. $accountBank = 'PersonalDeposit';
  2913. }
  2914. $wasteBookSql = '("' . $value ['irid'] . ' ",1,7,"' . $value ['receivablesPrice'] . '","' . $value ['receivablesPrice'] . '","' . $accountBank . '",
  2915. "' . $this->staff [0] ['category'] . '","' . $this->staff [0] ['cid'] . '","' . $this->staff [0] ['username'] . '","' . $this->staff [0] ['sid'] . '","' . date ( "Y-m-d H:i:s" ) . '")';
  2916. array_push ( $wasteBookList, $wasteBookSql );
  2917. }
  2918. $sql = $sql . implode ( ',', $wasteBookList );
  2919. Doo::db ()->query ( $sql );
  2920. Doo::db ()->commit ();
  2921. return "/invoiceReceivables";
  2922. }
  2923. echo 'no file';
  2924. }
  2925. function invoiceReceivables() {
  2926. $invoiceTC = $this->get_args ( 'invoiceTC' ) ? $this->get_args ( 'invoiceTC' ) : '';
  2927. Doo::loadModel ( 'L_category' );
  2928. $lCategory = new L_category ();
  2929. Doo::loadModel ( 'staff' );
  2930. $staff = new staff ();
  2931. Doo::loadModel ( 'invoiceReceivables' );
  2932. $invoiceReceivables = new invoiceReceivables ();
  2933. Doo::loadModel ( 'invoice' );
  2934. $invoice = new invoice ();
  2935. Doo::loadClass ( 'XDeode' );
  2936. $XDeode = new XDeode ( 5 );
  2937. $category = $lCategory->getCategory ();
  2938. $staffList = $staff->getStaffByCid ( $this->staff [0] ['cid'] );
  2939. $sql = 'bindStatus=1 and iid!=0';
  2940. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByNew ( 4, $sql );
  2941. // 获取未入账发票
  2942. $invoiceUnAccount = $invoice->getInvoiceByUnAccount ( $invoiceTC );
  2943. $invoiceExistAccount = $invoice->getInvoiceByUnAccount ( '', true );
  2944. foreach ( $invoiceUnAccount as $key => $value ) {
  2945. $invoiceUnAccount [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2946. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2947. if (! empty ( $lastApprover )) {
  2948. $lastApproverKey = array_keys ( $lastApprover );
  2949. $lastApprover = end ( $lastApprover );
  2950. $staffDetail = $staff->getOne ( array (
  2951. 'where' => 'sid=' . end ( $lastApproverKey ),
  2952. 'asArray' => true
  2953. ) );
  2954. $lastApprover ['username'] = $staffDetail ['username'];
  2955. }
  2956. $invoiceUnAccount [$key] ['lastApprover'] = $lastApprover;
  2957. }
  2958. foreach ( $invoiceExistAccount as $key => $value ) {
  2959. // $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  2960. // if (empty ( $irList ))
  2961. // $irList [0] ['sumPrice'] = 0;
  2962. //$balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  2963. $invoiceExistAccount [$key] ['existAccount'] = $value ['invoicePrice']-$value ['invoiceBalance'];
  2964. //$invoiceExistAccount [$key] ['balance'] = $balance;
  2965. }
  2966. $receivablesInput = $invoiceReceivables->getInvoiceReceivablesByInput ();
  2967. $halfList = $invoiceReceivables->getInvoiceReceivablesByHalf ();
  2968. $this->data ['halfList'] = $halfList;
  2969. $this->data ['halfCount'] = count ( $halfList );
  2970. // print_r($receivablesList);
  2971. $this->data ['receivablesDate'] = date ( "Y-m-d" );
  2972. $this->data ['ieaCount'] = count ( $invoiceExistAccount );
  2973. $this->data ['invoiceExistAccount'] = $invoiceExistAccount;
  2974. $this->data ['receivablesInput'] = $receivablesInput;
  2975. $this->data ['year'] = date ( 'Y' );
  2976. $this->data ['invoiceUnAccount'] = $invoiceUnAccount;
  2977. $this->data ['receivablesList'] = $receivablesList;
  2978. $this->data ['staffList'] = $staffList;
  2979. $this->data ['category'] = $category;
  2980. $this->data ['memu'] = "invoice";
  2981. $this->data ['staff'] = $this->staff;
  2982. $this->data ['receiptMemu'] = 'invoiceReceivables';
  2983. $this->render ( "/admin/invoiceReceivables", $this->data );
  2984. }
  2985. /**
  2986. * 设置收款认领地区
  2987. */
  2988. function setInvoiceReceivablesClaim() {
  2989. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  2990. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  2991. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  2992. if (! empty ( $iridKey ) && ! empty ( $receivablesCategory )) {
  2993. Doo::loadModel ( 'invoiceReceivables' );
  2994. $invoiceReceivables = new invoiceReceivables ();
  2995. Doo::loadClass ( 'XDeode' );
  2996. $XDeode = new XDeode ( 5 );
  2997. Doo::loadModel ( 'invoiceROLog' );
  2998. $invoiceROLog = new invoiceROLog ();
  2999. $irid = $XDeode->decode ( $iridKey );
  3000. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  3001. if (empty ( $irDetail ))
  3002. die ( 'illegal request' );
  3003. $item = array (
  3004. 'irid' => $irid,
  3005. 'receivablesCategory' => $receivablesCategory
  3006. );
  3007. if ($receivablesCategory != 'PUBLIC') {
  3008. $item += array (
  3009. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3010. 'inputType' => 1
  3011. );
  3012. }
  3013. $invoiceReceivables = new invoiceReceivables ();
  3014. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3015. // 收款操作日志
  3016. $item = array (
  3017. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 ",
  3018. 'date' => date ( "Y-m-d" ),
  3019. 'status' => 1,
  3020. 'img' => $this->staff [0] ['avatar'],
  3021. 'username' => $this->staff [0] ['username'],
  3022. 'uid' => $this->staff [0] ['sid'],
  3023. 'category' => $this->staff [0] ['category'],
  3024. 'irid' => $irid
  3025. );
  3026. $invoiceROLog->setInvoiceROLog ( $item );
  3027. if (empty ( $action ))
  3028. return '/invoiceReceivables';
  3029. else
  3030. return "/invoiceReceivablesAS";
  3031. }
  3032. die ( 'illegal request' );
  3033. }
  3034. /**
  3035. * 新添加收款直接入账发票
  3036. */
  3037. function invoiceCompareClaimPrice() {
  3038. // 收款录入
  3039. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  3040. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3041. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3042. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3043. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3044. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $iidKey )) {
  3045. Doo::loadModel ( 'invoiceReceivables' );
  3046. $invoiceReceivables = new invoiceReceivables ();
  3047. Doo::loadModel ( 'invoiceROLog' );
  3048. $invoiceROLog = new invoiceROLog ();
  3049. Doo::loadModel ( 'invoiceStatistics' );
  3050. Doo::loadModel ( 'invoice' );
  3051. $invoice = new invoice ();
  3052. Doo::loadClass ( 'XDeode' );
  3053. $XDeode = new XDeode ( 5 );
  3054. Doo::loadModel ( 'invoiceOperationLog' );
  3055. $invoiceOperationLog = new invoiceOperationLog ();
  3056. $iidKey = $XDeode->decode ( $iidKey );
  3057. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  3058. if (! ($invoiceDetail ['status'] == 2 && $invoiceDetail ['printStatus'] == 1 && $invoiceDetail ['untreadStatus'] == 0))
  3059. die ( 'illegal request' );
  3060. $receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  3061. // 收款录入 并绑定发票
  3062. Doo::db ()->beginTransaction ();
  3063. //获得发票入账余额
  3064. //$bindInvicePrice=$invoiceReceivables->getSumOfReceivablesPrice ( $invoiceDetail['irid'] );
  3065. //$bindPrice=$invoiceDetail ['invoiceBalance']-$bindInvicePrice;
  3066. $bindStatus = 0;
  3067. $invoiceBalance=$invoiceDetail ['invoicePrice'];
  3068. if($invoiceDetail ['invoiceBalance']!=0){
  3069. $invoiceBalance=$invoiceDetail ['invoiceBalance'];
  3070. }
  3071. if ($receivablesPrice <= $invoiceBalance){
  3072. $bindStatus = 1;
  3073. //$bindPrice=$receivablesPrice;
  3074. }
  3075. $titleMark = $invoiceDetail ['invoiceTitle'];
  3076. if (! empty ( $invoiceDetail ['invoiceCompany'] ))
  3077. $titleMark = $invoiceDetail ['invoiceCompany'];
  3078. $item = array (
  3079. 'recepitTitleMark' => $titleMark,
  3080. 'bindStatus' => $bindStatus,
  3081. 'iid' => $invoiceDetail ['iid'],
  3082. 'bindPrice' => $receivablesPrice,
  3083. 'bindDate' => date ( "Y-m-d H:i:s" ),
  3084. 'receivablesPrice' => $receivablesPrice,
  3085. 'OriginalPrice' => $receivablesPrice,
  3086. 'receivablesMessage' => $receivablesMessage,
  3087. 'receivablesSerial' => $receivablesSerial,
  3088. 'receivablesBank' => $receivablesBank,
  3089. 'receivablesDate' => $receivablesDate,
  3090. 'inputStaff' => $this->staff [0] ['username'],
  3091. 'accountClerk' => $this->staff [0] ['username'],
  3092. 'date' => date ( "Y-m-d" ),
  3093. 'receivablesCategory' => $invoiceDetail ['cid'] . ':' . $invoiceDetail ['categoryName'],
  3094. 'receivablesStaff' => $invoiceDetail ['sid'] . '-' . $invoiceDetail ['userName'],
  3095. 'confirmTime' => date ( "Y-m-d H:i:s" )
  3096. );
  3097. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  3098. $item = array ();
  3099. // 收款操作日志
  3100. $item = array (
  3101. 'operation' => $this->staff [0] ['username'] . " 转入 " . $invoiceDetail ['userName']
  3102. );
  3103. $item += array (
  3104. 'date' => date ( "Y-m-d" ),
  3105. 'status' => 1,
  3106. 'img' => $this->staff [0] ['avatar'],
  3107. 'username' => $this->staff [0] ['username'],
  3108. 'uid' => $this->staff [0] ['sid'],
  3109. 'category' => $this->staff [0] ['category'],
  3110. 'irid' => $irid
  3111. );
  3112. $invoiceROLog->setInvoiceROLog ( $item );
  3113. // 收款统计
  3114. $invoiceStatistics = new invoiceStatistics ();
  3115. $item = array (
  3116. 'date' => $receivablesDate,
  3117. 'priceClass' => 2,
  3118. 'irid' => $irid,
  3119. 'cid' => $invoiceDetail ['cid'],
  3120. 'staff' => $invoiceDetail ['sid'],
  3121. 'receivablesPrice' => $receivablesPrice
  3122. );
  3123. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3124. // 收款 入 发票
  3125. $detail = $invoiceDetail;
  3126. $iridString = "";
  3127. if (empty ( $detail ['irid'] ))
  3128. $iridString = $irid;
  3129. else
  3130. $iridString = $detail ['irid'] . ',' . $irid;
  3131. $item = array (
  3132. 'irid' => $iridString,
  3133. 'bindTime' => date ( "Y-m-d H:i:s" ),
  3134. 'updateTime' => date ( "Y-m-d H:i:s" ),
  3135. 'iid' => $detail ['iid']
  3136. );
  3137. // $invoiceReceivables = new invoiceReceivables ();
  3138. // $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  3139. // $sumBind = $bindInvicePrice;
  3140. // $sumBalance=$invoiceReceivables->balanceOfReceivablesPrice($irid);
  3141. // $sum=$sumBind+$sumBalance;
  3142. // ;
  3143. if ($receivablesPrice>=$invoiceBalance){
  3144. $item += array (
  3145. 'invoiceBalance'=>0,
  3146. 'untreadStatus' => 3
  3147. );
  3148. }else{
  3149. $item += array (
  3150. 'invoiceBalance'=>$invoiceBalance-$receivablesPrice
  3151. );
  3152. }
  3153. $invoice->setInvoiceByCondition ( $item );
  3154. // 操作日志
  3155. $item = array (
  3156. 'date' => date ( "Y-m-d H:i:s" ),
  3157. 'operation' => "收款入账" . $receivablesSerial . "到发票" . $detail ['invoiceSerial'],
  3158. 'status' => 8,
  3159. 'img' => $this->staff [0] ['avatar'],
  3160. 'username' => $this->staff [0] ['username'],
  3161. 'uid' => $this->staff [0] ['sid'],
  3162. 'category' => $this->staff [0] ['category'],
  3163. 'iid' => $detail ['iid']
  3164. );
  3165. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3166. // 入账汇总
  3167. $invoiceStatistics = new invoiceStatistics ();
  3168. // $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $iridString );
  3169. // $accountPrice = 0;
  3170. // foreach ( $list as $key => $value ) {
  3171. // $accountPrice += $value ['receivablesPrice'];
  3172. // }
  3173. $item = array (
  3174. 'date' => $receivablesDate,
  3175. 'priceClass' => 3,
  3176. 'cid' => $invoiceDetail ['cid'],
  3177. 'staff' => $invoiceDetail ['sid'],
  3178. 'accountPrice' => $receivablesPrice
  3179. );
  3180. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3181. // 公司流水记录
  3182. Doo::loadModel ( 'wasteBook' );
  3183. $wasteBook = new wasteBook ();
  3184. $abDetail = $wasteBook->getAccountBookByAid ( 2, 7, $irid );
  3185. $accountBank = '';
  3186. if ($receivablesBank == '纵横广发') {
  3187. $accountBank = 'CGBDeposit';
  3188. } elseif ($receivablesBank == '纵横工行') {
  3189. $accountBank = 'ICBCDeposit';
  3190. } elseif ($receivablesBank == '华润银行') {
  3191. $accountBank = 'HUADeposit';
  3192. } elseif ($receivablesBank == '个人广发') {
  3193. $accountBank = 'PersonalDeposit';
  3194. }
  3195. if (empty ( $abDetail )) {
  3196. $item = array (
  3197. 'dataID' => $irid,
  3198. 'expensesType' => 1,
  3199. 'accountType' => 7,
  3200. 'accountPrice' => $receivablesPrice,
  3201. 'accountPriceShow' => $receivablesPrice,
  3202. 'accountBank' => $accountBank,
  3203. 'category' => $this->staff [0] ['category'],
  3204. 'cid' => $this->staff [0] ['cid'],
  3205. 'name' => $this->staff [0] ['username'],
  3206. 'sid' => $this->staff [0] ['sid'],
  3207. 'inputDate' => date ( "Y-m-d H:i:s" )
  3208. );
  3209. $wasteBook->setAccountBookStatistics ( $item );
  3210. }
  3211. Doo::db ()->commit ();
  3212. }
  3213. return '/invoiceReceivables';
  3214. }
  3215. /**
  3216. * 录入收款数据
  3217. * @return string
  3218. */
  3219. function invoiceReceivablesDo() {
  3220. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3221. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3222. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3223. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3224. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3225. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  3226. Doo::loadModel ( 'invoiceReceivables' );
  3227. $invoiceReceivables = new invoiceReceivables ();
  3228. Doo::loadModel ( 'invoiceROLog' );
  3229. $invoiceROLog = new invoiceROLog ();
  3230. Doo::loadModel ( 'invoiceStatistics' );
  3231. $invoiceStatistics = new invoiceStatistics ();
  3232. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $receivablesCategory ) && ! empty ( $receivablesStaff )) {
  3233. $item = array (
  3234. 'receivablesPrice' => $receivablesPrice,
  3235. 'OriginalPrice' => $receivablesPrice,
  3236. 'receivablesMessage' => $receivablesMessage,
  3237. 'receivablesSerial' => "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  3238. 'receivablesBank' => $receivablesBank,
  3239. 'receivablesDate' => $receivablesDate,
  3240. 'inputStaff' => $this->staff [0] ['username'],
  3241. 'date' => date ( "Y-m-d" ),
  3242. 'receivablesCategory' => $receivablesCategory,
  3243. 'receivablesStaff' => $receivablesStaff
  3244. );
  3245. if ($receivablesCategory != 'PUBLIC') {
  3246. $item += array (
  3247. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3248. 'inputType' => 1
  3249. );
  3250. }
  3251. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  3252. $item = array ();
  3253. // 收款操作日志
  3254. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3255. $item = array (
  3256. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  3257. );
  3258. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3259. $item = array (
  3260. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  3261. );
  3262. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3263. $receivablesStaff = explode ( '-', $receivablesStaff );
  3264. $item = array (
  3265. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  3266. );
  3267. }
  3268. $item += array (
  3269. 'date' => date ( "Y-m-d" ),
  3270. 'status' => 1,
  3271. 'img' => $this->staff [0] ['avatar'],
  3272. 'username' => $this->staff [0] ['username'],
  3273. 'uid' => $this->staff [0] ['sid'],
  3274. 'category' => $this->staff [0] ['category'],
  3275. 'irid' => $irid
  3276. );
  3277. $invoiceROLog->setInvoiceROLog ( $item );
  3278. $item = array (
  3279. 'date' => $receivablesDate,
  3280. 'priceClass' => 2,
  3281. 'irid' => $irid,
  3282. 'receivablesPrice' => $receivablesPrice
  3283. );
  3284. if ($receivablesCategory != 'PUBLIC') {
  3285. $receivablesCategory = explode ( ":", $receivablesCategory );
  3286. $item += array (
  3287. 'cid' => $receivablesCategory [0]
  3288. );
  3289. }
  3290. if ($receivablesStaff2 != 'PUBLIC') {
  3291. $receivablesStaff = explode ( "-", $receivablesStaff2 );
  3292. $item += array (
  3293. 'staff' => $receivablesStaff [0]
  3294. );
  3295. }
  3296. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3297. $toparty = $this->getWxidByCategory ( $receivablesCategory [1] );
  3298. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  3299. $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  3300. if ($toparty != 0)
  3301. $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  3302. // 公司流水记录
  3303. Doo::loadModel ( 'wasteBook' );
  3304. $wasteBook = new wasteBook ();
  3305. $abDetail = $wasteBook->getAccountBookByAid ( 1, 7, $irid );
  3306. $accountBank = '';
  3307. if ($receivablesBank == '纵横广发') {
  3308. $accountBank = 'CGBDeposit';
  3309. } elseif ($receivablesBank == '纵横工行') {
  3310. $accountBank = 'ICBCDeposit';
  3311. } elseif ($receivablesBank == '华润银行') {
  3312. $accountBank = 'HUADeposit';
  3313. } elseif ($receivablesBank == '个人广发') {
  3314. $accountBank = 'PersonalDeposit';
  3315. }
  3316. $item = array (
  3317. 'dataID' => $irid,
  3318. 'expensesType' => 1,
  3319. 'accountType' => 7,
  3320. 'accountPriceShow' => $receivablesPrice,
  3321. 'accountPrice' => $receivablesPrice,
  3322. 'accountBank' => $accountBank,
  3323. 'category' => $this->staff [0] ['category'],
  3324. 'cid' => $this->staff [0] ['cid'],
  3325. 'name' => $this->staff [0] ['username'],
  3326. 'sid' => $this->staff [0] ['sid'],
  3327. 'inputDate' => date ( "Y-m-d H:i:s" )
  3328. );
  3329. $wasteBook->setAccountBookStatistics ( $item );
  3330. }
  3331. return "/invoiceReceivables";
  3332. }
  3333. /**
  3334. * 收款认领页面-包括公共认领 办事处认领 最近已认领数据
  3335. */
  3336. function invoiceReceivablesClaim() {
  3337. Doo::loadModel ( 'invoiceReceivables' );
  3338. $invoiceReceivables = new invoiceReceivables ();
  3339. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  3340. $this->data ['receivablesList'] = $receivablesList;
  3341. $this->data ['memu'] = "invoice";
  3342. $this->data ['staff'] = $this->staff;
  3343. $this->data ['receiptMemu'] = 'invoiceReceivablesClaim';
  3344. $this->render ( "/admin/invoiceReceivablesClaim", $this->data );
  3345. }
  3346. function invoiceReceivablesTitleMarkSet() {
  3347. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  3348. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  3349. if (empty ( $iridKey ) || empty ( $recepitTitleMark ))
  3350. die ( 'illegal request' );
  3351. Doo::loadModel ( 'invoiceReceivables' );
  3352. $invoiceReceivables = new invoiceReceivables ();
  3353. Doo::loadClass ( 'XDeode' );
  3354. $XDeode = new XDeode ( 5 );
  3355. $irid = $XDeode->decode ( $iridKey );
  3356. if (! is_numeric ( $irid ))
  3357. die ( 'illegal request' );
  3358. $invoiceReceivables->recepitTitleMark = $recepitTitleMark;
  3359. $invoiceReceivables->update ( array (
  3360. 'where' => 'irid = ' . $irid
  3361. ) );
  3362. return '/invoiceReceivablesClaim';
  3363. }
  3364. /**
  3365. * 更新收款相关数据
  3366. */
  3367. function invoiceReceivablesUpdateClaim() {
  3368. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3369. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3370. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3371. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3372. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3373. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  3374. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  3375. if (empty ( $claimKey ))
  3376. die ( 'illegal request' );
  3377. Doo::loadModel ( 'invoiceReceivables' );
  3378. $invoiceReceivables = new invoiceReceivables ();
  3379. Doo::loadModel ( 'invoiceROLog' );
  3380. $invoiceROLog = new invoiceROLog ();
  3381. $con = ' and iid=0 and bindStatus=0'; // and receivablesCategory!="PUBLIC" and receivablesStaff!="PUBLIC"
  3382. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  3383. if (empty ( $detail ))
  3384. die ( 'illegal request' );
  3385. $invoiceReceivables = new invoiceReceivables ();
  3386. $item = array (
  3387. 'irid' => $detail ['irid']
  3388. );
  3389. if ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3390. $item += array (
  3391. 'confirmTime' => date ( "Y-m-d H:i:s" )
  3392. );
  3393. }
  3394. if (! empty ( $receivablesCategory ))
  3395. $item += array (
  3396. 'receivablesCategory' => $receivablesCategory
  3397. );
  3398. if (! empty ( $receivablesStaff ))
  3399. $item += array (
  3400. 'receivablesStaff' => $receivablesStaff
  3401. );
  3402. if (! empty ( $receivablesPrice ))
  3403. $item += array (
  3404. 'receivablesPrice' => $receivablesPrice
  3405. );
  3406. if (! empty ( $receivablesMessage ))
  3407. $item += array (
  3408. 'receivablesMessage' => $receivablesMessage
  3409. );
  3410. if (! empty ( $receivablesBank ))
  3411. $item += array (
  3412. 'receivablesBank' => $receivablesBank
  3413. );
  3414. if (! empty ( $receivablesDate ))
  3415. $item += array (
  3416. 'receivablesDate' => $receivablesDate
  3417. );
  3418. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3419. // 收款操作日志
  3420. $item = array ();
  3421. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3422. $item = array (
  3423. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  3424. );
  3425. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3426. $item = array (
  3427. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  3428. );
  3429. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3430. $receivablesStaff = explode ( '-', $receivablesStaff );
  3431. $item = array (
  3432. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  3433. );
  3434. }
  3435. $item += array (
  3436. 'date' => date ( "Y-m-d" ),
  3437. 'status' => 1,
  3438. 'img' => $this->staff [0] ['avatar'],
  3439. 'username' => $this->staff [0] ['username'],
  3440. 'uid' => $this->staff [0] ['sid'],
  3441. 'category' => $this->staff [0] ['category'],
  3442. 'irid' => $detail ['irid']
  3443. );
  3444. $invoiceROLog->setInvoiceROLog ( $item );
  3445. return '/invoiceReceivablesAS';
  3446. }
  3447. function invoiceReceivablesDelete() {
  3448. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  3449. $skll = $this->get_args ( 'skll' ) ? $this->get_args ( 'skll' ) : "";
  3450. if ($skll != '删除到款')
  3451. die ( 'illegal request' );
  3452. if (empty ( $claimKey ))
  3453. die ( 'illegal request' );
  3454. Doo::loadModel ( 'invoiceReceivables' );
  3455. $invoiceReceivables = new invoiceReceivables ();
  3456. $con = ' and bindStatus=0 ';
  3457. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  3458. if (empty ( $detail ))
  3459. die ( 'illegal request' );
  3460. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  3461. // 扣除收款汇总信息 汇总
  3462. Doo::loadModel ( 'invoiceStatistics' );
  3463. $invoiceStatistics = new invoiceStatistics ();
  3464. $item = array (
  3465. 'date' => $detail ['receivablesDate'],
  3466. 'priceClass' => 2,
  3467. 'irid' => $detail ['irid'],
  3468. 'receivablesPrice' => - $detail ['receivablesPrice']
  3469. );
  3470. if ($detail ['receivablesCategory'] != 'PUBLIC') {
  3471. $receivablesCategory = explode ( ":", $detail ['receivablesCategory'] );
  3472. $item += array (
  3473. 'cid' => $receivablesCategory [0]
  3474. );
  3475. }
  3476. if ($detail ['receivablesStaff'] != 'PUBLIC') {
  3477. $receivablesStaff = explode ( "-", $detail ['receivablesStaff'] );
  3478. $item += array (
  3479. 'staff' => $receivablesStaff [0]
  3480. );
  3481. }
  3482. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3483. // 公司流水-删除时删除流水
  3484. Doo::loadModel ( 'wasteBook' );
  3485. $wasteBook = new wasteBook ();
  3486. $wasteBook->delete ( array (
  3487. 'where' => 'dataID=' . $detail ['irid'] . ' and accountType=7',
  3488. 'limit' => 1
  3489. ) );
  3490. return '/invoiceReceivablesAS';
  3491. }
  3492. /**
  3493. * 管理员录入的收款 ,确认认领到谁的名下.统计收款金额
  3494. */
  3495. function invoiceReceivablesAscription() {
  3496. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  3497. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  3498. Doo::loadModel ( 'invoiceReceivables' );
  3499. $invoiceReceivables = new invoiceReceivables ();
  3500. Doo::loadModel ( 'invoiceROLog' );
  3501. $invoiceROLog = new invoiceROLog ();
  3502. Doo::loadModel ( 'invoiceStatistics' );
  3503. $invoiceStatistics = new invoiceStatistics ();
  3504. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  3505. if (! empty ( $detail ) && $detail ['receivablesStaff'] == 'PUBLIC' && ! empty ( $recepitTitleMark )) {
  3506. $item = array (
  3507. 'irid' => $detail ['irid'],
  3508. 'receivablesCategory' => $this->staff [0] ['cid'] . ":" . $this->staff [0] ['category'],
  3509. 'receivablesStaff' => $this->staff [0] ['sid'] . "-" . $this->staff [0] ['username'],
  3510. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3511. 'recepitTitleMark' => $recepitTitleMark,
  3512. 'source' => 1
  3513. );
  3514. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3515. $item = array (
  3516. 'date' => date ( "Y-m-d" ),
  3517. 'operation' => $this->staff [0] ['username'] . " 认领 ",
  3518. 'status' => 2,
  3519. 'img' => $this->staff [0] ['avatar'],
  3520. 'username' => $this->staff [0] ['username'],
  3521. 'uid' => $this->staff [0] ['sid'],
  3522. 'category' => $this->staff [0] ['category'],
  3523. 'irid' => $irid
  3524. );
  3525. $invoiceROLog->setInvoiceROLog ( $item );
  3526. $item = array (
  3527. 'cid' => $this->staff [0] ['cid'],
  3528. 'staff' => $this->staff [0] ['sid']
  3529. );
  3530. $invoiceStatistics->updateInvoiceStatisticsByIrid ( $item, $detail ['irid'], 2 );
  3531. }
  3532. return "/invoiceReceivablesClaim";
  3533. }
  3534. /**
  3535. */
  3536. function invoiceMyReceivables() {
  3537. Doo::loadModel ( 'invoiceReceivables' );
  3538. $invoiceReceivables = new invoiceReceivables ();
  3539. Doo::loadModel ( 'invoiceStatistics' );
  3540. $invoiceStatistics = new invoiceStatistics ();
  3541. $isMonth = $invoiceStatistics->getStatisticsByMonth ( $this->staff [0] ['sid'] );
  3542. $year = date ( "Y" );
  3543. $tmp_date = date ( "Ym" );
  3544. $tmp_year = substr ( $tmp_date, 0, 4 );
  3545. $tmp_mon = substr ( $tmp_date, 4, 2 );
  3546. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  3547. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  3548. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . ".htm";
  3549. $htm = $this->showCache ( $path );
  3550. $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  3551. $this->data ['isMonth'] = $isMonth;
  3552. $this->data ['htm'] = $htm;
  3553. $this->data ['list'] = $list;
  3554. $this->data ['memu'] = "invoice";
  3555. $this->data ['staff'] = $this->staff;
  3556. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  3557. $this->render ( "/admin/invoiceMyReceivables", $this->data );
  3558. }
  3559. /**
  3560. * 纸票管理
  3561. */
  3562. function invoicePaper() {
  3563. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3564. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3565. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3566. $this->data ['dateString'] = $date;
  3567. $this->data ['status'] = $status;
  3568. $this->data ['invoiceType'] = $invoiceType;
  3569. $this->data ['memu'] = "invoice";
  3570. $this->data ['staff'] = $this->staff;
  3571. $this->data ['receiptMemu'] = 'invoicePaper';
  3572. $this->render ( "/admin/invoicePaper", $this->data );
  3573. }
  3574. /**
  3575. * 电子发票管理
  3576. */
  3577. function invoiceElectronic() {
  3578. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3579. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3580. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3581. $this->data ['dateString'] = $date;
  3582. $this->data ['status'] = $status;
  3583. $this->data ['invoiceType'] = $invoiceType;
  3584. $this->data ['memu'] = "invoice";
  3585. $this->data ['staff'] = $this->staff;
  3586. $this->data ['receiptMemu'] = 'invoicePaper';
  3587. $this->render ( "/invoice/invoiceElectronic", $this->data );
  3588. }
  3589. /**
  3590. * 获得纸票分页数据
  3591. */
  3592. function ajaxGetinvoicePaperAchieve() {
  3593. Doo::loadModel ( 'invoicePaper' );
  3594. $invoicePaper = new invoicePaper ();
  3595. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3596. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3597. $invoiceForm = $this->get_args ( 'invoiceForm' )&&is_numeric($this->get_args ( 'invoiceForm' )) ? $this->get_args ( 'invoiceForm' ) : "0";
  3598. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ORDINARY";
  3599. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3600. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  3601. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  3602. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  3603. $MebSea = $this->get_args ( 'search' );
  3604. $MebSea = $MebSea ['value'];
  3605. $page_size = $length;
  3606. $con = '';
  3607. if ($status == 'ALL')
  3608. $con = ' where 1 ';
  3609. elseif ($status == 'PRINTED')
  3610. $con = ' where a.iid!=0 '; // $con = ' where b.isDelete=0 and a.iid!=0 and b.status=2 and b.untreadStatus=0 ';
  3611. elseif ($status == 'UNPRINT')
  3612. $con = ' where a.iid=0 '; // $con = ' where b.isDelete=0 and a.iid=0 and b.status=2 and b.untreadStatus=0 ';
  3613. elseif ($status == 'TICKET')
  3614. $con = ' where b.isDelete=0 and b.untreadStatus=2';
  3615. if ($invoiceType == 'ORDINARY')
  3616. $con .= ' and a.invoiceType=0 ';
  3617. elseif ($invoiceType == 'SPECIAL')
  3618. $con .= ' and a.invoiceType=1 ';
  3619. if($invoiceForm==0){
  3620. $con .= ' and a.invoiceForm=0 ';
  3621. }else{
  3622. $con .= ' and a.invoiceForm=1 ';
  3623. }
  3624. $dateArr = explode ( ':', $date );
  3625. $D1 = $dateString = '';
  3626. $D2 = '';
  3627. if (! empty ( $date )) {
  3628. $D1 = $dateArr [0];
  3629. if (isset ( $dateArr [1] ))
  3630. $D2 = $dateArr [1];
  3631. else
  3632. $D2 = '';
  3633. $dateString = $D1 . " : " . $D2;
  3634. }
  3635. if (! empty ( $D1 ) && ! empty ( $D2 ))
  3636. $con .= ' and b.printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  3637. elseif (! empty ( $D1 ) && empty ( $D2 ))
  3638. $con .= ' and b.printTime like "%' . $D1 . '%" ';
  3639. if (! empty ( $MebSea ))
  3640. $con .= ' and ( b.invoiceTitle like "%' . $MebSea . '%" or b.invoiceCompany like "%' . $MebSea . '%" or a.invoiceNo like "%' . $MebSea . '%" )';
  3641. $invoiceTotal = $invoicePaper->getInvoicePaperCount ($invoiceForm);
  3642. $sql = ' ' . $con;
  3643. $limit = $page . ',' . $page_size;
  3644. $list = $invoicePaper->getInvoicePaper ( $limit, $sql, 'desc' );
  3645. $paperList = array ();
  3646. foreach ( $list as $key => $value ) {
  3647. $irDetail = array ();
  3648. if ($value ['iid'] == 0)
  3649. array_push ( $irDetail, '<a href="javascript:if(window.confirm(\'确认删除?\'))window.location=\'/invoicePaperDel/' . $value ['ipidKey'] . '\'" >删除</a>' );
  3650. else
  3651. array_push ( $irDetail, '' );
  3652. array_push ( $irDetail, $value ['invoiceCode'] );
  3653. array_push ( $irDetail, $value ['invoiceNo'] );
  3654. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKey'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  3655. if ($value ['invoiceType'] == 1)
  3656. array_push ( $irDetail, $value ['invoiceCompany'] );
  3657. else
  3658. array_push ( $irDetail, $value ['invoiceTitle'] );
  3659. if ($value ['invoiceType'] == 1)
  3660. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  3661. else
  3662. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  3663. array_push ( $irDetail, $value ['invoiceElement'] );
  3664. array_push ( $irDetail, $value ['categoryName'] . '-' . $value ['userName'] );
  3665. array_push ( $irDetail, $value ['printTime'] );
  3666. array_push ( $paperList, $irDetail );
  3667. }
  3668. // $approvalListJson = json_encode ( $approvalList );
  3669. $recordsFiltered = $invoiceTotal;
  3670. echo json_encode ( array (
  3671. "draw" => intval ( $draw ),
  3672. "recordsTotal" => intval ( $invoiceTotal ),
  3673. "recordsFiltered" => intval ( $recordsFiltered ),
  3674. "data" => $paperList
  3675. ), JSON_UNESCAPED_UNICODE );
  3676. }
  3677. function invoicePaperDel() {
  3678. $ipidKey = isset ( $this->params ['ipidKey'] ) ? $this->params ['ipidKey'] : "";
  3679. $XDeode = new XDeode ( 5 );
  3680. $ipid = $XDeode->decode ( $ipidKey );
  3681. if (empty ( $ipid ))
  3682. die ( 'illegal request' );
  3683. Doo::loadModel ( 'invoicePaper' );
  3684. $invoicePaper = new invoicePaper ();
  3685. $invoicePaper->delete ( array (
  3686. 'where' => 'ipid=' . $ipid . ' and iid=0',
  3687. 'limit' => 1
  3688. ) );
  3689. return '/invoicePaper';
  3690. }
  3691. /**
  3692. * 添加纸质发票号
  3693. */
  3694. function invoicePaperAdd() {
  3695. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : '0';
  3696. $invoiceCode = $this->get_args ( 'invoiceCode' ) ? $this->get_args ( 'invoiceCode' ) : "";
  3697. $invoiceNoStart = $this->get_args ( 'invoiceNoStart' ) && is_numeric ( $this->get_args ( 'invoiceNoStart' ) ) ? $this->get_args ( 'invoiceNoStart' ) : 0;
  3698. $invoiceNoTotal = $this->get_args ( 'invoiceNoTotal' ) && is_numeric ( $this->get_args ( 'invoiceNoTotal' ) ) ? $this->get_args ( 'invoiceNoTotal' ) : 0;
  3699. $invoiceForm = $this->get_args ( 'invoiceForm' ) && is_numeric ( $this->get_args ( 'invoiceForm' ) ) ? $this->get_args ( 'invoiceForm' ) : 0;
  3700. if ($invoiceType != '' && ! empty ( $invoiceCode ) && ! empty ( $invoiceNoStart ) && ! empty ( $invoiceNoTotal )) {
  3701. $sum = $invoiceNoStart + $invoiceNoTotal;
  3702. if (empty ( $sum ))
  3703. die ( 'illegal request' );
  3704. // echo $invoiceNoStart;
  3705. // echo $sum;
  3706. // echo strlen((int)$invoiceNoStart);
  3707. $sumLenght = strlen ( $invoiceNoStart ) - strlen ( ( int ) $invoiceNoStart );
  3708. Doo::db ()->beginTransaction ();
  3709. // 批量存储纸质发票
  3710. $date = date ( "Y-m-d H:i:s" );
  3711. $sql = 'INSERT INTO CLD_invoicePaper (invoiceType, invoiceCode,invoiceNo,date,invoiceForm)
  3712. VALUES ';
  3713. $paperList = array ();
  3714. for($invoiceNoStart; $invoiceNoStart <= $sum - 1; $invoiceNoStart ++) {
  3715. // 数字前面自加0
  3716. $INLENGHT = strlen ( ( int ) $invoiceNoStart ) + $sumLenght;
  3717. $var = sprintf ( "%0" . $INLENGHT . "d", $invoiceNoStart );
  3718. $paperSql = '(' . $invoiceType . ',"' . $invoiceCode . '","' . $var . '","' . $date . '","'.$invoiceForm.'")';
  3719. array_push ( $paperList, $paperSql );
  3720. }
  3721. if (empty ( $paperList ))
  3722. die ( 'illegal request' );
  3723. $sql = $sql . implode ( ',', $paperList );
  3724. Doo::db ()->query ( $sql );
  3725. Doo::db ()->commit ();
  3726. if($invoiceForm==1){
  3727. return 'invoiceElectronic';
  3728. }else{
  3729. return 'invoicePaper';
  3730. }
  3731. }
  3732. die ( 'illegal request' );
  3733. }
  3734. /**
  3735. * 收款绑定发票 ,//一个收款只能绑定一个发票
  3736. */
  3737. function invoiceBindReceivables() {
  3738. $claimKey = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  3739. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  3740. Doo::loadModel ( 'invoice' );
  3741. $invoice = new invoice ();
  3742. Doo::loadModel ( 'invoiceReceivables' );
  3743. $invoiceReceivables = new invoiceReceivables ();
  3744. Doo::loadModel ( 'invoiceOperationLog' );
  3745. $invoiceOperationLog = new invoiceOperationLog ();
  3746. if (empty ( $invoiceKey ) || empty ( $claimKey ))
  3747. die ( 'illegal request' );
  3748. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  3749. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey );
  3750. if (empty ( $detail ) && empty ( $detailM ))
  3751. die ( 'illegal request' );
  3752. if ($detail ['untreadStatus'] == 3)
  3753. die ( 'illegal request' );
  3754. // 修改 绑定状态改为 金额
  3755. $invoiceReceivables = new invoiceReceivables ();
  3756. //有BUG-需修改
  3757. $invoicePrice = $detail ['invoicePrice'] + $detailM ['bindPrice'];
  3758. if ($detailM ['receivablesPrice'] > $invoicePrice) {
  3759. $item = array (
  3760. 'bindPrice' => $invoicePrice
  3761. );
  3762. } elseif ($detailM ['receivablesPrice'] <= $invoicePrice) {//发票金额大于收款金额,绑定金额为收款金额
  3763. $item = array (
  3764. 'bindPrice' => $detailM ['receivablesPrice'],
  3765. 'bindStatus' => 1,
  3766. 'bindDate' => date ( "Y-m-d H:i:s" )
  3767. );
  3768. } else {
  3769. die ( 'illegal request' );
  3770. }
  3771. if ($detailM ['iid'] == 0) {
  3772. $item += array (
  3773. 'iid' => $detail ['iid']
  3774. );
  3775. } else {
  3776. $iidExtend = explode ( ',', $detailM ['iidExtend'] );
  3777. array_push ( $iidExtend, $detail ['iid'] );
  3778. $item += array (
  3779. 'iidExtend' => implode ( ',', $iidExtend )
  3780. );
  3781. }
  3782. $titleMark = $detail ['invoiceTitle'];
  3783. if (! empty ( $detail ['invoiceCompany'] ))
  3784. $titleMark = $detail ['invoiceCompany'];
  3785. $item += array (
  3786. 'irid' => $detailM ['irid'],
  3787. 'recepitTitleMark' => $titleMark,
  3788. 'accountClerk' => $this->staff [0] ['username']
  3789. );
  3790. // 如何没有人收款 则自动绑定收款
  3791. if ($detailM ['receivablesCategory'] == 'PUBLIC' || $detailM ['receivablesStaff'] == 'PUBLIC') {
  3792. $item += array (
  3793. 'receivablesCategory' => $detail ['cid'] . ':' . $detail ['categoryName'],
  3794. 'receivablesStaff' => $detail ['sid'] . '-' . $detail ['userName']
  3795. );
  3796. }
  3797. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3798. $iridString = "";
  3799. if (empty ( $detail ['irid'] ))
  3800. $iridString = $detailM ['irid'];
  3801. else
  3802. $iridString = $detail ['irid'] . ',' . $detailM ['irid'];
  3803. // $invoiceReceivables = new invoiceReceivables ();
  3804. // $sumBind = $invoiceReceivables->getSumOfReceivablesPrice ( $detail ['irid'] );
  3805. // //这个收款余额
  3806. // $sumBalance=$invoiceReceivables->balanceOfReceivablesPrice($detailM ['irid']);
  3807. // $sum=$sumBind+$sumBalance;
  3808. //这个收款余额
  3809. $sumBalance=$detailM ['receivablesPrice']-$detailM ['bindPrice'];
  3810. // echo $detailM ['irid'].'/'.$sumBalance.'/'.$detail ['invoicePrice'];
  3811. // die;
  3812. $item = array (
  3813. 'iid' => $detail ['iid'],
  3814. 'irid' => $iridString
  3815. );
  3816. if ($detail ['invoicePrice'] <= $sumBalance){
  3817. $item += array (
  3818. 'invoiceBalance'=>0,
  3819. 'untreadStatus' => 3,
  3820. 'bindTime' => date ( "Y-m-d H:i:s" )
  3821. );
  3822. }else{
  3823. $item += array (
  3824. 'invoiceBalance'=>$detail ['invoicePrice']-$sumBalance,
  3825. );
  3826. }
  3827. // print_r($item);
  3828. // echo $sum;die;
  3829. $invoice->setInvoiceByCondition ( $item );
  3830. // 操作日志
  3831. $item = array (
  3832. 'date' => date ( "Y-m-d H:i:s" ),
  3833. 'operation' => "收款" . $detailM ['receivablesSerial'] . "入账到发票" . $detail ['invoiceSerial'],
  3834. 'status' => 8,
  3835. 'img' => $this->staff [0] ['avatar'],
  3836. 'username' => $this->staff [0] ['username'],
  3837. 'uid' => $this->staff [0] ['sid'],
  3838. 'category' => $this->staff [0] ['category'],
  3839. 'iid' => $detail ['iid']
  3840. );
  3841. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3842. Doo::loadModel ( 'invoiceStatistics' );
  3843. $invoiceStatistics = new invoiceStatistics ();
  3844. $item = array (
  3845. 'date' => $detailM ['receivablesDate'],
  3846. 'priceClass' => 3,
  3847. 'cid' => $detail ['cid'],
  3848. 'staff' => $detail ['sid'],
  3849. 'accountPrice' => $detailM ['receivablesPrice']
  3850. );
  3851. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3852. // 公司流水记录
  3853. // Doo::loadModel ( 'wasteBook' );
  3854. // $wasteBook = new wasteBook ();
  3855. // $abDetail = $wasteBook->getAccountBookByAid (1,8,$detail ['iid'] );
  3856. // $accountBank='';
  3857. // if ($detailM ['receivablesBank']=='纵横广发'){
  3858. // $accountBank='CGBDeposit';
  3859. // }elseif($detailM ['receivablesBank']=='纵横工行'){
  3860. // $accountBank='ICBCDeposit';
  3861. // }elseif($detailM ['receivablesBank']=='华润银行'){
  3862. // $accountBank='HUADeposit';
  3863. // }elseif($detailM ['receivablesBank']=='个人广发'){
  3864. // $accountBank='PersonalDeposit';
  3865. // }
  3866. // if (empty($abDetail)){
  3867. // $item = array (
  3868. // 'dataID' => $detail ['iid'],
  3869. // 'expensesType' => 1,
  3870. // 'accountType' => 8,
  3871. // 'accountPriceShow'=>$detail ['invoicePrice'],
  3872. // 'accountPrice'=>$detail ['invoicePrice'],
  3873. // 'accountBank'=>$accountBank,
  3874. // 'category'=>$this->staff[0]['category'],
  3875. // 'cid'=>$this->staff[0]['cid'],
  3876. // 'name'=>$this->staff[0]['username'],
  3877. // 'sid'=>$this->staff[0]['sid'],
  3878. // 'inputDate'=>date ( "Y-m-d H:i:s" )
  3879. // );
  3880. // $wasteBook->setAccountBookStatistics($item);
  3881. // }
  3882. return "/invoiceReceivables";
  3883. }
  3884. /**
  3885. * 核销 动作,确认入账统计 发票收款完成--需求更变 废弃 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"; }
  3886. */
  3887. function invoiceAggregate() {
  3888. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3889. Doo::loadModel ( 'invoiceStatistics' );
  3890. $invoiceStatistics = new invoiceStatistics ();
  3891. Doo::loadModel ( 'L_category' );
  3892. $Lcategory = new L_category ();
  3893. $isList = $invoiceStatistics->getInvoiceStatisticsByYear ( $year );
  3894. $LcategoryList = $Lcategory->getCategory ();
  3895. // print_r($isList);
  3896. $html = ""; // $invoicePriceCategory=0;$receivablesPriceCategory=0;$accountPriceCategory=0;
  3897. foreach ( $LcategoryList as $key => $value ) {
  3898. $html .= '<tr><th><a href="/invoiceAggregateCategory/' . $value ['cidKey'] . '">' . $value ['title'] . '</a></th>';
  3899. $month = 1;
  3900. $invoicePriceYear = 0;
  3901. $receivablesPriceYear = 0;
  3902. $accountPriceYear = 0;
  3903. for(; $month <= 12; $month ++) {
  3904. $flag = true;
  3905. foreach ( $isList ['statisticsMonthCid'] as $k => $v ) {
  3906. if ($value ['cid'] == $v ['cid'] && $month == $v ['month']) {
  3907. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  3908. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  3909. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  3910. ';
  3911. $invoicePriceYear += $v ['invoicePrice'];
  3912. $receivablesPriceYear += $v ['receivablesPrice'];
  3913. $accountPriceYear += $v ['accountPrice'];
  3914. $flag = false;
  3915. break;
  3916. }
  3917. }
  3918. if ($flag)
  3919. $html .= '<td class="taR"></td>
  3920. <td class="taR"></td>
  3921. <td class="taR"><b></b></td>
  3922. ';
  3923. }
  3924. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  3925. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  3926. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  3927. ';
  3928. $html .= '</tr>';
  3929. }
  3930. $html .= '<tr><th><b class="colGreen">月合计</b></th>';
  3931. $invoicePriceYear = 0;
  3932. $receivablesPriceYear = 0;
  3933. $accountPriceYear = 0;
  3934. for($month = 1; $month <= 12; $month ++) {
  3935. $flag = true;
  3936. foreach ( $isList ['statisticsMonth'] as $k => $v ) {
  3937. if ($month == $v ['month']) {
  3938. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  3939. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  3940. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  3941. ';
  3942. $invoicePriceYear += $v ['invoicePrice'];
  3943. $receivablesPriceYear += $v ['receivablesPrice'];
  3944. $accountPriceYear += $v ['accountPrice'];
  3945. $flag = false;
  3946. break;
  3947. }
  3948. }
  3949. if ($flag) {
  3950. $html .= '<td class="taR"></td>
  3951. <td class="taR"></td>
  3952. <td class="taR"><b></b></td>
  3953. ';
  3954. }
  3955. }
  3956. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  3957. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  3958. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  3959. ';
  3960. $html .= '</tr>';
  3961. // print_r($isList);
  3962. $this->data ['html'] = $html;
  3963. $this->data ['LcategoryList'] = $LcategoryList;
  3964. $this->data ['isList'] = $isList;
  3965. $this->data ['year'] = $year;
  3966. $this->data ['memu'] = "invoice";
  3967. $this->data ['staff'] = $this->staff;
  3968. $this->data ['receiptMemu'] = 'invoiceAggregate';
  3969. $this->render ( "/admin/invoiceAggregate", $this->data );
  3970. }
  3971. function invoiceAggregateStaff() {
  3972. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3973. Doo::loadModel ( 'invoiceStatistics' );
  3974. $invoiceStatistics = new invoiceStatistics ();
  3975. Doo::loadModel ( 'L_category' );
  3976. $Lcategory = new L_category ();
  3977. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year );
  3978. $staffList = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year );
  3979. $cStaff = $Lcategory->getCategoryStaff ();
  3980. $html = '';
  3981. foreach ( $cStaff as $key => $value ) {
  3982. $categoryFir = true;
  3983. foreach ( $value ['staff'] as $k => $v ) {
  3984. if ($categoryFir) {
  3985. $width = count ( $value ['staff'] ) + 1;
  3986. $html .= '<tr><th rowspan="' . $width . '">' . $value ['title'] . ' </th>';
  3987. $categoryFir = false;
  3988. } else
  3989. $html .= '<tr>';
  3990. $html .= '<th>' . $v ['username'] . '</th>';
  3991. $invoicePriceStaffYear = 0;
  3992. $receivablesPriceStaffYear = 0;
  3993. $accountPriceStaffYear = 0;
  3994. for($month = 1; $month <= 12; $month ++) {
  3995. $flag = true;
  3996. foreach ( $staffList ['statisticsMonthStaff'] as $sl => $slv ) {
  3997. if ($v ['sid'] == $slv ['staff'] && $month == $slv ['month']) {
  3998. $html .= '<td class="taR">¥' . $slv ['invoicePrice'] . '</td>
  3999. <td class="taR">¥' . $slv ['receivablesPrice'] . '</td>
  4000. <td class="taR"><b>¥' . $slv ['accountPrice'] . '</b></td>
  4001. ';
  4002. $invoicePriceStaffYear += $slv ['invoicePrice'];
  4003. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  4004. $accountPriceStaffYear += $slv ['accountPrice'];
  4005. $flag = false;
  4006. break;
  4007. }
  4008. }
  4009. if ($flag)
  4010. $html .= '<td class="taR"></td>
  4011. <td class="taR"></td>
  4012. <td class="taR"><b></b></td>
  4013. ';
  4014. }
  4015. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  4016. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  4017. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  4018. ';
  4019. }
  4020. $html .= '</tr>';
  4021. // 小计
  4022. if (! empty ( $value ['staff'] )) {
  4023. $html .= '<tr><th class="taR">小计</th>';
  4024. $invoicePriceStaffYear = 0;
  4025. $receivablesPriceStaffYear = 0;
  4026. $accountPriceStaffYear = 0;
  4027. for($month = 1; $month <= 12; $month ++) {
  4028. $flag = true;
  4029. foreach ( $staffList ['statisticsMonthCid'] as $smc => $smcv ) {
  4030. if ($value ['cid'] == $smcv ['cid'] && $month == $slv ['month']) {
  4031. $html .= '<td class="taR">¥' . $smcv ['invoicePrice'] . '</td>
  4032. <td class="taR">¥' . $smcv ['receivablesPrice'] . '</td>
  4033. <td class="taR"><b>¥' . $smcv ['accountPrice'] . '</b></td>
  4034. ';
  4035. $invoicePriceStaffYear += $slv ['invoicePrice'];
  4036. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  4037. $accountPriceStaffYear += $slv ['accountPrice'];
  4038. $flag = false;
  4039. break;
  4040. }
  4041. }
  4042. if ($flag)
  4043. $html .= '<td class="taR"></td>
  4044. <td class="taR"></td>
  4045. <td class="taR"><b></b></td>
  4046. ';
  4047. }
  4048. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  4049. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  4050. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  4051. ';
  4052. $html .= '</tr>';
  4053. }
  4054. }
  4055. $html .= '<tr class="warning"><th colspan="2"><b class="colGreen" >月合计</b></th>';
  4056. $invoicePriceYear = 0;
  4057. $receivablesPriceYear = 0;
  4058. $accountPriceYear = 0;
  4059. for($month = 1; $month <= 12; $month ++) {
  4060. $flag = true;
  4061. foreach ( $staffList ['statisticsMonth'] as $k => $v ) {
  4062. if ($month == $v ['month']) {
  4063. $html .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>
  4064. <td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>
  4065. <td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>
  4066. ';
  4067. $invoicePriceYear += $v ['invoicePrice'];
  4068. $receivablesPriceYear += $v ['receivablesPrice'];
  4069. $accountPriceYear += $v ['accountPrice'];
  4070. $flag = false;
  4071. break;
  4072. }
  4073. }
  4074. if ($flag)
  4075. $html .= '<td class="taR"></td>
  4076. <td class="taR"></td>
  4077. <td class="taR"><b></b></td>
  4078. ';
  4079. }
  4080. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  4081. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  4082. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  4083. ';
  4084. $html .= '</tr>';
  4085. $this->data ['html'] = $html;
  4086. $this->data ['isList'] = $toteList;
  4087. $this->data ['year'] = $year;
  4088. $this->data ['memu'] = "invoice";
  4089. $this->data ['staff'] = $this->staff;
  4090. $this->data ['receiptMemu'] = 'invoiceAggregate';
  4091. $this->render ( "/admin/invoiceAggregateStaff", $this->data );
  4092. }
  4093. function invoiceAggregateCategory() {
  4094. Doo::loadClass ( 'XDeode' );
  4095. $XDeode = new XDeode ( 5 );
  4096. $cid = $cidKey = isset ( $this->params ['cid'] ) ? $this->params ['cid'] : "";
  4097. $cid = $XDeode->decode ( $cid );
  4098. if (! is_numeric ( $cid ))
  4099. die ( 'illegal request' );
  4100. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  4101. Doo::loadModel ( 'invoiceStatistics' );
  4102. $invoiceStatistics = new invoiceStatistics ();
  4103. Doo::loadModel ( 'staff' );
  4104. $staff = new staff ();
  4105. $list = $staff->getStaffByCid ( $cid );
  4106. $isCategory = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year, $cid );
  4107. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year, $cid );
  4108. if (empty ( $list ))
  4109. die ( '该办事处没有成员' );
  4110. $htmlA = $htmlB = $htmlC = $html = '';
  4111. foreach ( $list as $key => $value ) {
  4112. $htmlA = '<tr><th rowspan="3">' . $value ['username'] . '</th><th class="taC">开票</th>';
  4113. $htmlB = '<tr><th class="taC">收款</th>';
  4114. $htmlC = '<tr><th class="taC">入账</th>';
  4115. $invoicePriceStaffYear = 0;
  4116. $receivablesPriceStaffYear = 0;
  4117. $accountPriceStaffYear = 0;
  4118. for($month = 1; $month <= 12; $month ++) {
  4119. $flag = true;
  4120. foreach ( $isCategory ['statisticsMonthStaff'] as $k => $v ) {
  4121. if ($value ['sid'] == $v ['staff'] && $month == $v ['month']) {
  4122. $htmlA .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>';
  4123. $htmlB .= '<td class="taR">¥' . $v ['receivablesPrice'] . '</td>';
  4124. $htmlC .= '<td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>';
  4125. $invoicePriceStaffYear += $v ['invoicePrice'];
  4126. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  4127. $accountPriceStaffYear += $v ['accountPrice'];
  4128. $flag = false;
  4129. break;
  4130. }
  4131. }
  4132. if ($flag) {
  4133. $htmlA .= '<td class="taR">-</td>';
  4134. $htmlB .= '<td class="taR">-</td>';
  4135. $htmlC .= '<td class="taR"><b>-</b></td>';
  4136. }
  4137. }
  4138. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  4139. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  4140. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  4141. $htmlA .= '</tr>';
  4142. $htmlB .= '</tr>';
  4143. $htmlC .= '</tr>';
  4144. $html .= $htmlA . $htmlB . $htmlC;
  4145. }
  4146. $htmlA = $htmlB = $htmlC = "";
  4147. $htmlA = '<tr><th rowspan="3">月合计</th><th class="taC">开票</th>';
  4148. $htmlB = '<tr><th class="taC">收款</th>';
  4149. $htmlC = '<tr><th class="taC">入账</th>';
  4150. $invoicePriceStaffYear = 0;
  4151. $receivablesPriceStaffYear = 0;
  4152. $accountPriceStaffYear = 0;
  4153. for($month = 1; $month <= 12; $month ++) {
  4154. $flag = true;
  4155. foreach ( $isCategory ['statisticsMonth'] as $k => $v ) {
  4156. if ($month == $v ['month']) {
  4157. $htmlA .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>';
  4158. $htmlB .= '<td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>';
  4159. $htmlC .= '<td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>';
  4160. $invoicePriceStaffYear += $v ['invoicePrice'];
  4161. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  4162. $accountPriceStaffYear += $v ['accountPrice'];
  4163. $flag = false;
  4164. break;
  4165. }
  4166. }
  4167. if ($flag) {
  4168. $htmlA .= '<td class="taR">-</td>';
  4169. $htmlB .= '<td class="taR">-</td>';
  4170. $htmlC .= '<td class="taR"><b>-</b></td>';
  4171. }
  4172. }
  4173. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  4174. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  4175. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  4176. $htmlA .= '</tr>';
  4177. $htmlB .= '</tr>';
  4178. $htmlC .= '</tr>';
  4179. $html .= $htmlA . $htmlB . $htmlC;
  4180. $this->data ['html'] = $html;
  4181. $this->data ['cidKey'] = $cidKey;
  4182. $this->data ['slist'] = $list;
  4183. $this->data ['isList'] = $toteList;
  4184. $this->data ['year'] = $year;
  4185. $this->data ['memu'] = "invoice";
  4186. $this->data ['staff'] = $this->staff;
  4187. $this->data ['receiptMemu'] = 'invoiceAggregate';
  4188. $this->render ( "/admin/invoiceAggregateCategory", $this->data );
  4189. }
  4190. /**
  4191. * 办事处汇总信息
  4192. */
  4193. function invoiceAggregateCategoryDetail() {
  4194. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  4195. Doo::loadClass ( 'XDeode' );
  4196. $XDeode = new XDeode ( 5 );
  4197. Doo::loadModel ( 'invoiceStatistics' );
  4198. $invoiceStatistics = new invoiceStatistics ();
  4199. Doo::loadModel ( 'L_category' );
  4200. $category = new L_category ();
  4201. Doo::loadModel ( 'invoice' );
  4202. $invoice = new invoice ();
  4203. Doo::loadModel ( 'staff' );
  4204. $staff = new staff ();
  4205. Doo::loadModel ( "invoiceCategoryManage" );
  4206. $invoiceCategoryManage = new invoiceCategoryManage ();
  4207. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4208. $cidList = array ();
  4209. foreach ( $imcStaff as $key => $value ) {
  4210. array_push ( $cidList, $value ['cid'] );
  4211. if (empty ( $cidKey ))
  4212. $cidKey = $XDeode->encode ( $value ['cid'] );
  4213. }
  4214. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  4215. $cid = $XDeode->decode ( $cidKey );
  4216. $month = date ( "m", strtotime ( "-1 month" ) );
  4217. $YearMonth = date ( "Y-m", strtotime ( "-1 month" ) );
  4218. $redis = new Redis ();
  4219. $redis->connect ( '127.0.0.1', '6379' );
  4220. $redisKey = ''; // date('Y-m-d').'_iacd_'.$cid;
  4221. $redisValue = ''; // $redis->lrange($redisKey, 0, -1);
  4222. if (empty ( $redisValue )) {
  4223. $isMC = $invoiceStatistics->getInvoiceStatistiscsMothByCategory ( $cid );
  4224. $schedule = $invoice->getInvoiceScheduleByCid ( $cid );
  4225. // 获得办事处人员下的汇总
  4226. $slist = $staff->getStaffByCid ( $cid );
  4227. $ismsbMonth = $invoiceStatistics->getISMSByCategoryByMonth ( $cid, $YearMonth ); // 上一个月的汇总
  4228. $ismsb = $invoiceStatistics->getISMSByCategory ( $cid ); // 当月汇总
  4229. $ISAS = $invoiceStatistics->getISASByCategory ( $cid ); // 全部汇总
  4230. $scheduleStaff = $invoice->getInvoiceScheduleByCidGroupSid ( $cid ); // 完成度
  4231. foreach ( $slist as $key => $value ) {
  4232. $slist [$key] ['invoicePrice'] = 0;
  4233. $slist [$key] ['receivablesPrice'] = 0;
  4234. $slist [$key] ['accountPrice'] = 0;
  4235. $slist [$key] ['invoiceAllPrice'] = 0;
  4236. $slist [$key] ['receivablesAllPrice'] = 0;
  4237. $slist [$key] ['accountAllPrice'] = 0;
  4238. $slist [$key] ['schedule'] = 0;
  4239. $slist [$key] ['invoiceMonthPrice'] = 0;
  4240. $slist [$key] ['receivablesMonthPrice'] = 0;
  4241. $slist [$key] ['accountMonthPrice'] = 0;
  4242. foreach ( $ismsbMonth as $y => $l ) {
  4243. if ($value ['sid'] == $l ['staff']) {
  4244. $slist [$key] ['invoiceMonthPrice'] = $l ['invoicePrice'];
  4245. $slist [$key] ['receivablesMonthPrice'] = $l ['receivablesPrice'];
  4246. $slist [$key] ['accountMonthPrice'] = $l ['accountPrice'];
  4247. }
  4248. }
  4249. foreach ( $ismsb as $k => $v ) {
  4250. if ($value ['sid'] == $v ['staff']) {
  4251. $slist [$key] ['invoicePrice'] = $v ['invoicePrice'];
  4252. $slist [$key] ['receivablesPrice'] = $v ['receivablesPrice'];
  4253. $slist [$key] ['accountPrice'] = $v ['accountPrice'];
  4254. }
  4255. }
  4256. foreach ( $ISAS as $e => $a ) {
  4257. if ($value ['sid'] == $a ['staff']) {
  4258. $slist [$key] ['invoiceAllPrice'] = $a ['invoicePrice'];
  4259. $slist [$key] ['receivablesAllPrice'] = $a ['receivablesPrice'];
  4260. $slist [$key] ['accountAllPrice'] = $a ['accountPrice'];
  4261. }
  4262. }
  4263. if (isset ( $scheduleStaff [$value ['sid']] ))
  4264. $slist [$key] ['schedule'] = $scheduleStaff [$value ['sid']];
  4265. }
  4266. $this->data ['cidKey'] = $cidKey;
  4267. $schedule = ( int ) ($schedule * 100);
  4268. $this->data ['slist'] = $slist;
  4269. $this->data ['isMC'] = $isMC;
  4270. $this->data ['schedule'] = $schedule;
  4271. $slist = json_encode ( $slist );
  4272. $isMC = json_encode ( $isMC );
  4273. $schedule = json_encode ( $schedule );
  4274. $redis->lpush ( $redisKey, $slist );
  4275. $redis->lpush ( $redisKey, $isMC );
  4276. $redis->lpush ( $redisKey, $schedule );
  4277. } else {
  4278. $this->data ['cidKey'] = $cidKey;
  4279. $this->data ['slist'] = json_decode ( $redisValue [2], true );
  4280. $this->data ['isMC'] = json_decode ( $redisValue [1], true );
  4281. $this->data ['schedule'] = json_decode ( $redisValue [0], true );
  4282. }
  4283. $this->data ['month'] = $month;
  4284. $this->data ['categoryList'] = $categoryList;
  4285. $this->data ['memu'] = "invoice";
  4286. $this->data ['staff'] = $this->staff;
  4287. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4288. $this->render ( "/admin/invoiceAggregateCategoryDetail", $this->data );
  4289. }
  4290. /**
  4291. * 办事处人员汇总详情
  4292. */
  4293. function invoiceAggregateStaffDetail() {
  4294. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  4295. // $sidKey = isset ( $this->params ['sidKey'] ) ? $this->params ['sidKey'] : '';
  4296. Doo::loadClass ( 'XDeode' );
  4297. $XDeode = new XDeode ( 5 );
  4298. Doo::loadModel ( 'invoice' );
  4299. $invoice = new invoice ();
  4300. Doo::loadModel ( 'staff' );
  4301. $staff = new staff ();
  4302. Doo::loadModel ( "invoiceCategoryManage" );
  4303. $invoiceCategoryManage = new invoiceCategoryManage ();
  4304. $sid = $XDeode->decode ( $sidKey );
  4305. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4306. $cidList = array ();
  4307. foreach ( $imcStaff as $key => $value ) {
  4308. array_push ( $cidList, $value ['cid'] );
  4309. if (empty ( $cidKey ))
  4310. $cidKey = $XDeode->encode ( $value ['cid'] );
  4311. }
  4312. $cidString = implode ( ',', $cidList );
  4313. $staffList = $staff->getStaffInCid ( $cidString );
  4314. $staffDetail = $staff->getStaffBySid ( $sid );
  4315. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4316. $page_size = 18;
  4317. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4318. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4319. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  4320. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  4321. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  4322. $dateArr = explode ( ':', $date );
  4323. $D1 = '';
  4324. $D2 = '';
  4325. if (! empty ( $date )) {
  4326. $D1 = $dateArr [0] . " 00:00:00 ";
  4327. if (isset ( $dateArr [1] ))
  4328. $D2 = $dateArr [1] . " 23:59:59 ";
  4329. else
  4330. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4331. // $D2 = $dateArr [1];
  4332. }
  4333. $con = ' status=2 ';
  4334. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4335. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4336. if ($status == 'UNRECORD')
  4337. $con .= ' and printStatus=1 and untreadStatus=0';
  4338. elseif ($status == 'RECORD')
  4339. $con .= ' and printStatus=1 and untreadStatus=3';
  4340. elseif ($status == 'BOUNCED')
  4341. $con .= ' and untreadStatus=2';
  4342. elseif ($status == 'PARTRECORD')
  4343. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  4344. elseif ($status == 'All') {
  4345. $con .= ' and ( untreadStatus=2 or untreadStatus=0 or untreadStatus=3 )';
  4346. }
  4347. $con .= ' and sid=' . $sid;
  4348. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  4349. if (! empty ( $MebSea )) {
  4350. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  4351. }
  4352. $pageinfo ['page'] = array (
  4353. 'previous' => ''
  4354. );
  4355. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateStaffDetail", $get, "" );
  4356. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4357. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  4358. $this->data ['staffDetail'] = $staffDetail;
  4359. $this->data ['staffList'] = $staffList;
  4360. $this->data ['MebSeaEn'] = $MebSea;
  4361. $this->data ['MebSea'] = urlencode ( $MebSea );
  4362. $this->data ['date'] = $date;
  4363. $this->data ['page'] = $pageinfo;
  4364. $this->data ['get'] = $get;
  4365. $this->data ['list'] = $list;
  4366. $this->data ['status'] = $status;
  4367. $this->data ['sidKey'] = $sidKey;
  4368. $this->data ['memu'] = "invoice";
  4369. $this->data ['staff'] = $this->staff;
  4370. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4371. $this->render ( "/admin/invoiceAggregateStaffDetail", $this->data );
  4372. }
  4373. /**
  4374. * 办事处人员汇总收款情
  4375. */
  4376. function invoiceAggregateStaffReceivablesDetail() {
  4377. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  4378. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  4379. Doo::loadModel ( 'invoiceReceivables' );
  4380. $invoiceReceivables = new invoiceReceivables ();
  4381. Doo::loadModel ( 'staff' );
  4382. $staff = new staff ();
  4383. Doo::loadModel ( "invoiceCategoryManage" );
  4384. $invoiceCategoryManage = new invoiceCategoryManage ();
  4385. Doo::loadClass ( 'XDeode' );
  4386. $XDeode = new XDeode ( 5 );
  4387. $sid = $XDeode->decode ( $sidKey );
  4388. $staffDetail = $staff->getStaffBySid ( $sid );
  4389. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4390. $cidList = array ();
  4391. foreach ( $imcStaff as $key => $value ) {
  4392. array_push ( $cidList, $value ['cid'] );
  4393. if (empty ( $cidKey ))
  4394. $cidKey = $XDeode->encode ( $value ['cid'] );
  4395. }
  4396. $cidString = implode ( ',', $cidList );
  4397. $staffList = $staff->getStaffInCid ( $cidString );
  4398. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4399. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  4400. $page_size = 10;
  4401. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4402. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4403. if ($timeType == "BINDOTP") {
  4404. $status = 'Credited';
  4405. }
  4406. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  4407. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  4408. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  4409. $dateArr = explode ( ':', $date );
  4410. $D1 = '';
  4411. $D2 = '';
  4412. if (! empty ( $date )) {
  4413. $D1 = $dateArr [0] . " 00:00:00 ";
  4414. if (isset ( $dateArr [1] ))
  4415. $D2 = $dateArr [1] . " 23:59:59 ";
  4416. else
  4417. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4418. }
  4419. $con = ' a.receivablesStaff like "%' . $staffDetail ['username'] . '%" ';
  4420. $descField = 'a.bindDate';
  4421. if ($timeType == 'CREATE')
  4422. $descField = 'a.date';
  4423. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4424. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4425. elseif (! empty ( $D1 ) && empty ( $D2 ))
  4426. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  4427. if ($status == 'Unclaimed')
  4428. $con .= ' and a.bindStatus=0';
  4429. elseif ($status == 'Credited')
  4430. $con .= ' and a.bindStatus=1';
  4431. elseif ($status == 'Claim')
  4432. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  4433. elseif ($status == 'BBN')
  4434. $con .= ' and a.bindPrice>a.receivablesPrice';
  4435. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  4436. if (! empty ( $MebSea )) {
  4437. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" )';
  4438. }
  4439. $pageinfo ['page'] = array (
  4440. 'previous' => ''
  4441. );
  4442. // $sql = 'select group_concat(b.invoiceSerial) as invoiceSerial ,group_concat(b.iid) as invoiceId
  4443. // from CLD_invoiceReceivables as a left join CLD_invoice as b on
  4444. // find_in_set(b.iid,a.iidExtend) or a.iid=b.iid
  4445. // where ' . $con . ' group by a.irid ';
  4446. $pageinfo =$this->get_page ( "CLD_invoiceReceivables as a", $con, $page, $page_size, "invoiceAggregateStaffReceivablesDetail", $get, "" );
  4447. //$pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceAggregateStaffReceivablesDetail", $get, "" );
  4448. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4449. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', $descField);
  4450. foreach ( $list as $key => $value ) {
  4451. $list [$key] ['category'] = '';
  4452. if ($value ['receivablesCategory'] != 'PUBLIC') {
  4453. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  4454. $list [$key] ['category'] = $receivablesCategory [1];
  4455. }
  4456. }
  4457. // print_r($list);
  4458. $this->data ['staffDetail'] = $staffDetail;
  4459. $this->data ['sidKey'] = $sidKey;
  4460. $this->data ['staffList'] = $staffList;
  4461. $this->data ['timeType'] = $timeType;
  4462. $this->data ['MebSeaEn'] = $MebSea;
  4463. $this->data ['MebSea'] = urlencode ( $MebSea );
  4464. $this->data ['date'] = $date;
  4465. $this->data ['page'] = $pageinfo;
  4466. $this->data ['get'] = $get;
  4467. $this->data ['list'] = $list;
  4468. $this->data ['status'] = $status;
  4469. $this->data ['memu'] = "invoice";
  4470. $this->data ['staff'] = $this->staff;
  4471. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4472. $this->render ( "/admin/invoiceAggregateStaffReceivablesDetail", $this->data );
  4473. }
  4474. function invoiceAchieve() {
  4475. Doo::loadModel ( 'invoice' );
  4476. $invoice = new invoice ();
  4477. Doo::loadClass ( 'XDeode' );
  4478. $XDeode = new XDeode ( 5 );
  4479. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4480. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4481. $page_size = 18;
  4482. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4483. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4484. $get = "/" . $date;
  4485. $con = '';
  4486. if ($date == 'MONTHO')
  4487. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4488. elseif ($date == 'MONTHT')
  4489. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4490. elseif ($date == 'MONTHY')
  4491. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4492. if (! empty ( $MebSea )) {
  4493. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4494. $get .= "/" . $MebSea;
  4495. }
  4496. $pageinfo ['page'] = array (
  4497. 'previous' => ''
  4498. );
  4499. $sql = 'status=2 and printStatus=1 and irid!="" and ( untreadStatus=3 or untreadStatus=0 ) and sid=' . $sid . $con;
  4500. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceAchieve", $get, "" );
  4501. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4502. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  4503. // print_r($pageinfo);
  4504. $this->data ['MebSeaEn'] = $MebSea;
  4505. $this->data ['MebSea'] = urlencode ( $MebSea );
  4506. $this->data ['get'] = $get;
  4507. $this->data ['page'] = $pageinfo;
  4508. $this->data ['list'] = $list;
  4509. $this->data ['date'] = $date;
  4510. $this->data ['memu'] = "invoice";
  4511. $this->data ['staff'] = $this->staff;
  4512. $this->data ['receiptMemu'] = 'invoice';
  4513. $this->render ( "/admin/invoiceAchieve", $this->data );
  4514. }
  4515. /**
  4516. */
  4517. function invoiceMyUnAccountAchieve() {
  4518. Doo::loadModel ( 'invoice' );
  4519. $invoice = new invoice ();
  4520. Doo::loadClass ( 'XDeode' );
  4521. $XDeode = new XDeode ( 5 );
  4522. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4523. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4524. $page_size = 18;
  4525. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4526. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4527. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4528. $dateArr = explode ( ':', $date );
  4529. $D1 = '';
  4530. $D2 = '';
  4531. if (! empty ( $date )) {
  4532. $D1 = $dateArr [0];
  4533. $D2 = $dateArr [1];
  4534. }
  4535. $con = '';
  4536. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4537. $con = ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4538. if (! empty ( $MebSea )) {
  4539. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4540. }
  4541. $pageinfo ['page'] = array (
  4542. 'previous' => ''
  4543. );
  4544. // and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  4545. $sql = " status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid= " . $sid . $con;
  4546. $action = "invoiceMyUnAccountAchieve";
  4547. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  4548. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4549. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 'desc', 'printTime' );
  4550. Doo::loadModel ( 'express' );
  4551. $express = new express ();
  4552. $expressList = $express->getExpressByAll ();
  4553. $this->data ['expressList'] = $expressList;
  4554. // print_r($list);
  4555. $this->data ['MebSeaEn'] = $MebSea;
  4556. $this->data ['get'] = $get;
  4557. $this->data ['page'] = $pageinfo;
  4558. $this->data ['date'] = $date;
  4559. $this->data ['list'] = $list;
  4560. $this->data ['memu'] = "invoice";
  4561. $this->data ['staff'] = $this->staff;
  4562. $this->data ['receiptMemu'] = 'invoice';
  4563. $this->render ( "/admin/invoiceMyUnAccountAchieve", $this->data );
  4564. }
  4565. function invoiceReceivablesAchieve() {
  4566. Doo::loadModel ( 'invoiceReceivables' );
  4567. $invoiceReceivables = new invoiceReceivables ();
  4568. Doo::loadClass ( 'XDeode' );
  4569. $XDeode = new XDeode ( 5 );
  4570. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4571. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  4572. $page_size = 12;
  4573. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4574. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4575. $get = "/" . $date;
  4576. $con = '';
  4577. if ($date == 'MONTHO')
  4578. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4579. elseif ($date == 'MONTHT')
  4580. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4581. elseif ($date == 'MONTHY')
  4582. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4583. if (! empty ( $MebSea )) {
  4584. $con .= ' and ( receivablesMessage like "%' . $MebSea . '%" or receivablesPrice like "%' . $MebSea . '%" )';
  4585. $get .= "/" . $MebSea;
  4586. }
  4587. $pageinfo ['page'] = array (
  4588. 'previous' => ''
  4589. );
  4590. $sql = " bindStatus=1 and receivablesStaff like '" . $sid . "-%' " . $con;
  4591. $pageinfo = $this->get_page ( "CLD_invoiceReceivables", $sql, $page, $page_size, "invoiceReceivablesAchieve", $get, "" );
  4592. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4593. $list = $invoiceReceivables->getReceivablesByUntreadStatusPage ( $limit, $sql );
  4594. // print_r($pageinfo);
  4595. $this->data ['MebSeaEn'] = $MebSea;
  4596. $this->data ['MebSea'] = urlencode ( $MebSea );
  4597. $this->data ['get'] = $get;
  4598. $this->data ['page'] = $pageinfo;
  4599. $this->data ['list'] = $list;
  4600. $this->data ['date'] = $date;
  4601. $this->data ['memu'] = "invoice";
  4602. $this->data ['staff'] = $this->staff;
  4603. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  4604. $this->render ( "/admin/invoiceReceivablesAchieve", $this->data );
  4605. }
  4606. /**
  4607. * 收款解绑
  4608. */
  4609. function invoiceUnBundLing() {
  4610. $unBundKey = $this->get_args ( 'unBundKey' ) ? $this->get_args ( 'unBundKey' ) : '';
  4611. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  4612. Doo::loadModel ( 'invoice' );
  4613. $invoice = new invoice ();
  4614. Doo::loadModel ( 'invoiceReceivables' );
  4615. $invoiceReceivables = new invoiceReceivables ();
  4616. Doo::loadModel ( 'invoiceOperationLog' );
  4617. $invoiceOperationLog = new invoiceOperationLog ();
  4618. Doo::loadModel ( 'invoiceROLog' );
  4619. $invoiceROLog = new invoiceROLog ();
  4620. Doo::loadModel ( 'invoiceStatistics' );
  4621. Doo::loadClass ( 'XDeode' );
  4622. $XDeode = new XDeode ( 5 );
  4623. if (empty ( $iidKey ) || empty ( $unBundKey ))
  4624. die ( 'illegal request' );
  4625. $iid = $XDeode->decode ( $iidKey );
  4626. $irid = $invoice->authcode ( $unBundKey );
  4627. if ((! empty ( $irid ) && ! is_numeric ( $irid )) || (! empty ( $iid ) && ! is_numeric ( $iid )))
  4628. die ( 'illegal request' );
  4629. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4630. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  4631. if (empty ( $irDetails ) || empty ( $invoiceDetails ) || (empty ( $irDetails ['iid'] ) && empty ( $irDetails ['iidExtend'] )) || $invoiceDetails ['untreadStatus'] == 2)
  4632. die ( 'illegal request' );
  4633. // 收款
  4634. $item = array (
  4635. 'irid' => $irDetails ['irid'],
  4636. 'bindPrice' => $irDetails ['bindPrice'] - $invoiceDetails ['invoicePrice'],
  4637. 'bindStatus' => 0
  4638. );
  4639. if ($irDetails ['iid'] == $iid)
  4640. $item += array (
  4641. 'iid' => 0
  4642. );
  4643. else {
  4644. $iidExtend = explode ( ',', $irDetails ['iidExtend'] );
  4645. foreach ( $iidExtend as $key => $value ) {
  4646. if ($value == $iid)
  4647. unset ( $iidExtend [$key] );
  4648. }
  4649. $iidExtend = implode ( ',', $iidExtend );
  4650. $item += array (
  4651. 'iidExtend' => $iidExtend
  4652. );
  4653. }
  4654. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4655. // 收款操作日志
  4656. $item = array (
  4657. 'operation' => $this->staff [0] ['username'] . " 解绑 " . $irDetails ['receivablesSerial'],
  4658. 'date' => date ( "Y-m-d" ),
  4659. 'status' => 3,
  4660. 'img' => $this->staff [0] ['avatar'],
  4661. 'username' => $this->staff [0] ['username'],
  4662. 'uid' => $this->staff [0] ['sid'],
  4663. 'category' => $this->staff [0] ['category'],
  4664. 'irid' => $irid
  4665. );
  4666. $invoiceROLog->setInvoiceROLog ( $item );
  4667. // 扣除入账统计金额
  4668. $invoiceStatistics = new invoiceStatistics ();
  4669. $item = array (
  4670. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  4671. 'priceClass' => 3,
  4672. 'cid' => $invoiceDetails ['cid'],
  4673. 'staff' => $invoiceDetails ['sid'],
  4674. 'accountPrice' => - $irDetails ['receivablesPrice']
  4675. );
  4676. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4677. // 扣除收款统计金额
  4678. $invoiceStatistics = new invoiceStatistics ();
  4679. $item = array (
  4680. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  4681. 'priceClass' => 2,
  4682. 'cid' => $invoiceDetails ['cid'],
  4683. 'staff' => $invoiceDetails ['sid'],
  4684. 'irid' => $irDetails ['irid'],
  4685. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  4686. );
  4687. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4688. // 发票解绑去收款ID
  4689. $iridString = $invoiceDetails ['irid'];
  4690. if (! empty ( $invoiceDetails ['irid'] )) {
  4691. $list = explode ( ',', $invoiceDetails ['irid'] );
  4692. foreach ( $list as $key => $value ) {
  4693. if ($value == $irDetails ['irid']) {
  4694. unset ( $list [$key] );
  4695. break;
  4696. }
  4697. }
  4698. $iridString = implode ( ",", $list );
  4699. }
  4700. $item = array (
  4701. 'iid' => $invoiceDetails ['iid'],
  4702. 'irid' => $iridString,
  4703. 'updateTime' => date ( "Y-m-d H:i:s" )
  4704. );
  4705. if ($invoiceDetails ['untreadStatus'] == 3)
  4706. $item += array (
  4707. 'untreadStatus' => 0
  4708. );
  4709. $invoice->setInvoiceByCondition ( $item );
  4710. $item = array (
  4711. 'date' => date ( "Y-m-d H:i:s" ),
  4712. 'operation' => '解绑 收款 ' . $irDetails ['receivablesSerial'],
  4713. 'status' => 11,
  4714. 'img' => $this->staff [0] ['avatar'],
  4715. 'username' => $this->staff [0] ['username'],
  4716. 'uid' => $this->staff [0] ['sid'],
  4717. 'category' => $this->staff [0] ['category'],
  4718. 'iid' => $invoiceDetails ['iid']
  4719. );
  4720. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  4721. // 公司流水-解绑时删除流水
  4722. Doo::loadModel ( 'wasteBook' );
  4723. $wasteBook = new wasteBook ();
  4724. // $wasteBook->delete ( array (
  4725. // 'where' => 'dataID=' . $irDetails ['irid'] . ' and accountType=7',
  4726. // 'limit' => 1
  4727. // ) );
  4728. // 银行
  4729. /*
  4730. * $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); }
  4731. */
  4732. return "/invoiceReceivablesAS";
  4733. }
  4734. /**
  4735. * 或者该收款下的所以发票
  4736. */
  4737. function ajaxGetInvoiceReceivablesByInvoice() {
  4738. $irid = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : '';
  4739. Doo::loadModel ( 'invoice' );
  4740. $invoice = new invoice ();
  4741. Doo::loadModel ( 'invoiceReceivables' );
  4742. $invoiceReceivables = new invoiceReceivables ();
  4743. $irid = $invoice->authcode ( $irid );
  4744. if (! empty ( $irid ) && ! is_numeric ( $irid ))
  4745. die ( 'illegal request' );
  4746. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4747. $iidString = $irDetails ['iid'];
  4748. $iidExtend = array_filter ( explode ( ',', $irDetails ['iidExtend'] ) );
  4749. if (! empty ( $irDetails ['iidExtend'] ))
  4750. $iidString .= ',' . implode ( ',', $iidExtend );
  4751. $invoiceList = $invoice->getInvoiceInIid ( $iidString, 'iid,invoiceSerial,invoicePrice,invoiceTitle,invoiceCompany,invoiceElement' );
  4752. $html = "";
  4753. foreach ( $invoiceList as $key => $value ) {
  4754. $title = $value ['invoiceTitle'];
  4755. if (! empty ( $value ['invoiceCompany'] ))
  4756. $title = $value ['invoiceCompany'];
  4757. $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>';
  4758. }
  4759. echo json_encode ( array (
  4760. 'status' => 1,
  4761. 'html' => $html
  4762. ) );
  4763. }
  4764. /**
  4765. * 发票管理
  4766. */
  4767. function invoiceAS() {
  4768. Doo::loadModel ( 'invoice' );
  4769. $invoice = new invoice ();
  4770. Doo::loadModel ( 'invoiceReceivables' );
  4771. $invoiceReceivables = new invoiceReceivables ();
  4772. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4773. $page_size = 18;
  4774. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4775. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4776. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4777. $dateArr = explode ( ':', $date );
  4778. $D1 = '';
  4779. $D2 = '';
  4780. if (! empty ( $date )) {
  4781. $D1 = $dateArr [0] . " 00:00:00 ";
  4782. if (isset ( $dateArr [1] ))
  4783. $D2 = $dateArr [1] . " 23:59:59 ";
  4784. else
  4785. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4786. // $D2 = $dateArr [1];
  4787. }
  4788. $con = ' status=2 ';
  4789. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4790. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4791. if ($status == 'UNRECORD')
  4792. $con .= ' and printStatus=1 and untreadStatus=0';
  4793. elseif ($status == 'RECORD')
  4794. $con .= ' and printStatus=1 and untreadStatus=3';
  4795. elseif ($status == 'BOUNCED')
  4796. $con .= ' and untreadStatus=2';
  4797. elseif ($status == 'PARTRECORD')
  4798. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  4799. elseif ($status == 'All') {
  4800. $con .= ' and ( untreadStatus=2 or untreadStatus=1 or untreadStatus=0 or untreadStatus=3 )';
  4801. }
  4802. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4803. if (! empty ( $MebSea )) {
  4804. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  4805. }
  4806. $pageinfo ['page'] = array (
  4807. 'previous' => ''
  4808. );
  4809. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAS", $get, "" );
  4810. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4811. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  4812. $this->data ['MebSeaEn'] = $MebSea;
  4813. $this->data ['MebSea'] = urlencode ( $MebSea );
  4814. $this->data ['date'] = $date;
  4815. $this->data ['page'] = $pageinfo;
  4816. $this->data ['get'] = $get;
  4817. $this->data ['list'] = $list;
  4818. $this->data ['status'] = $status;
  4819. $this->data ['memu'] = "invoice";
  4820. $this->data ['staff'] = $this->staff;
  4821. $this->data ['receiptMemu'] = 'invoiceReceivables';
  4822. $this->render ( "/admin/invoiceAS", $this->data );
  4823. }
  4824. /**
  4825. * 收款管理
  4826. */
  4827. function invoiceReceivablesAS() {
  4828. Doo::loadModel ( 'invoiceReceivables' );
  4829. $invoiceReceivables = new invoiceReceivables ();
  4830. Doo::loadModel ( 'L_category' );
  4831. $lCategory = new L_category ();
  4832. $category = $lCategory->getCategory ();
  4833. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4834. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  4835. $page_size = 10;
  4836. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4837. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4838. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4839. $dateArr = explode ( ':', $date );
  4840. $D1 = '';
  4841. $D2 = '';
  4842. if (! empty ( $date )) {
  4843. $D1 = $dateArr [0]; // ." 00:00:00 ";
  4844. if (isset ( $dateArr [1] ))
  4845. $D2 = $dateArr [1]; // ." 23:59:59 ";
  4846. else
  4847. $D2 = $dateArr [0]; // ." 23:59:59 ";//date ( "Y-m-d" );
  4848. }
  4849. $descField = 'a.receivablesDate';
  4850. if ($timeType == 'CREATE')
  4851. $descField = 'a.date';
  4852. $con = ' 1 ';
  4853. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4854. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4855. elseif (! empty ( $D1 ) && empty ( $D2 ))
  4856. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  4857. if ($status == 'Unclaimed')
  4858. $con .= ' and a.bindStatus=0';
  4859. elseif ($status == 'Credited')
  4860. $con .= ' and a.bindStatus=1';
  4861. elseif ($status == 'Claim')
  4862. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  4863. elseif ($status == 'BBN')
  4864. $con .= ' and a.bankBatchNumber!=""';
  4865. elseif ($status == 'REFUND')
  4866. $con .= ' and ( (a.bindStatus=0 and a.refundLog!="" ) or a.bindStatus=2)';
  4867. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4868. if (! empty ( $MebSea )) {
  4869. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" or a.receivablesSerial like "%' . $MebSea . '%" )';
  4870. }
  4871. $pageinfo ['page'] = array (
  4872. 'previous' => ''
  4873. );
  4874. // if(!empty($con)){
  4875. // $con=' where 1 '.$con;
  4876. // }
  4877. // $sql = 'select a.iid from CLD_invoiceReceivables as a
  4878. // ' . $con ;
  4879. $pageinfo =$this->get_page ( "CLD_invoiceReceivables as a", $con, $page, $page_size, "invoiceReceivablesAS", $get, "" );
  4880. //echo $sql;
  4881. //$pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceReceivablesAS", $get, "" );
  4882. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4883. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', $descField );
  4884. foreach ( $list as $key => $value ) {
  4885. $list [$key] ['category'] = '';
  4886. if ($value ['receivablesCategory'] != 'PUBLIC') {
  4887. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  4888. $list [$key] ['category'] = $receivablesCategory [1];
  4889. }
  4890. }
  4891. // print_r($list);
  4892. $this->data ['category'] = $category;
  4893. $this->data ['timeType'] = $timeType;
  4894. $this->data ['MebSeaEn'] = $MebSea;
  4895. $this->data ['MebSea'] = urlencode ( $MebSea );
  4896. $this->data ['date'] = $date;
  4897. $this->data ['page'] = $pageinfo;
  4898. $this->data ['get'] = $get;
  4899. $this->data ['list'] = $list;
  4900. $this->data ['status'] = $status;
  4901. $this->data ['memu'] = "invoice";
  4902. $this->data ['staff'] = $this->staff;
  4903. $this->data ['receiptMemu'] = 'invoiceReceivables';
  4904. $this->render ( "/admin/invoiceReceivablesAS", $this->data );
  4905. }
  4906. /**
  4907. * 删除一条收款
  4908. */
  4909. function delInvoiceReceivables() {
  4910. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  4911. if (empty ( $iridKey ))
  4912. die ( 'illegal request' );
  4913. Doo::loadClass ( 'XDeode' );
  4914. $XDeode = new XDeode ( 5 );
  4915. $irid = $XDeode->decode ( $iridKey );
  4916. Doo::loadModel ( 'invoiceReceivables' );
  4917. $invoiceReceivables = new invoiceReceivables ();
  4918. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4919. if (empty ( $detail ))
  4920. die ( 'illegal request' );
  4921. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  4922. // 扣除收款汇总信息 汇总
  4923. Doo::loadModel ( 'invoiceStatistics' );
  4924. $invoiceStatistics = new invoiceStatistics ();
  4925. $item = array (
  4926. 'date' => $detail ['receivablesDate'],
  4927. 'priceClass' => 2,
  4928. 'irid' => $detail ['irid'],
  4929. 'receivablesPrice' => - $detail ['receivablesPrice']
  4930. );
  4931. if ($detail ['receivablesCategory'] != 'PUBLIC') {
  4932. $receivablesCategory = explode ( ":", $detail ['receivablesCategory'] );
  4933. $item += array (
  4934. 'cid' => $receivablesCategory [0]
  4935. );
  4936. }
  4937. if ($detail ['receivablesStaff'] != 'PUBLIC') {
  4938. $receivablesStaff = explode ( "-", $detail ['receivablesStaff'] );
  4939. $item += array (
  4940. 'staff' => $receivablesStaff [0]
  4941. );
  4942. }
  4943. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4944. return '/invoiceReceivablesAS';
  4945. }
  4946. /**
  4947. * 添加退款信息
  4948. */
  4949. function setInvoiceReceivablesRefund() {
  4950. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  4951. $refundType = $this->get_args ( 'refundType' ) && is_numeric ( $this->get_args ( 'refundType' ) ) ? $this->get_args ( 'refundType' ) : '0';
  4952. $refundCompany = $this->get_args ( 'refundCompany' ) ? $this->get_args ( 'refundCompany' ) : "";
  4953. $refundNumber = $this->get_args ( 'refundNumber' ) ? $this->get_args ( 'refundNumber' ) : "";
  4954. $refundPrice = $this->get_args ( 'refundPrice' ) ? $this->get_args ( 'refundPrice' ) : "";
  4955. $refundRemarks = $this->get_args ( 'refundRemarks' ) ? $this->get_args ( 'refundRemarks' ) : "";
  4956. if ($refundPrice < 0)
  4957. die ( 'illegal request' );
  4958. if (! empty ( $iridKey ) && ! empty ( $refundCompany ) && ! empty ( $refundNumber ) && ! empty ( $refundPrice )) {
  4959. Doo::loadModel ( 'invoiceReceivables' );
  4960. $invoiceReceivables = new invoiceReceivables ();
  4961. Doo::loadModel ( 'invoiceRefund' );
  4962. $invoiceRefund = new invoiceRefund ();
  4963. $irid = $invoiceReceivables->authcode ( $iridKey );
  4964. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4965. if ($irDetail ['receivablesPrice'] < $refundPrice)
  4966. die ( 'illegal request' );
  4967. $invoiceReceivables = new invoiceReceivables ();
  4968. $refundLog = $this->staff [0] ['username'] . ' 退款 <b class="colRed">¥' . $refundPrice . '</b>
  4969. <br/><a href="#refunded" onclick="getRefundByDetail(\'' . $iridKey . '\')" data-toggle="modal">退款信息</a> <br/>' . date ( "Y-m-d H:i:s" ) . '
  4970. ';
  4971. $item = array (
  4972. 'irid' => $irid,
  4973. 'refundCompany' => $refundCompany,
  4974. 'refundNumber' => $refundNumber,
  4975. 'refundPrice' => $refundPrice,
  4976. 'refundRemarks' => $refundRemarks,
  4977. 'refundLog' => $refundLog
  4978. );
  4979. if ($refundType == 1) {
  4980. $item += array (
  4981. 'refundType' => $refundType,
  4982. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice,
  4983. 'bindStatus' => 2
  4984. );
  4985. } elseif ($refundType == 0 && $irDetail ['receivablesPrice'] <= $refundPrice) {
  4986. $item += array (
  4987. 'refundType' => 1,
  4988. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice,
  4989. 'bindStatus' => 2
  4990. );
  4991. } else {
  4992. $item += array (
  4993. 'refundType' => $refundType,
  4994. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice
  4995. );
  4996. }
  4997. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4998. // 添加退款记录
  4999. $item = array (
  5000. 'irid' => $irid,
  5001. 'refundType' => $refundType,
  5002. 'refundCompany' => $refundCompany,
  5003. 'refundNumber' => $refundNumber,
  5004. 'refundPrice' => $refundPrice,
  5005. 'refundLog' => $refundLog,
  5006. 'refundRemarks' => $refundRemarks,
  5007. 'date' => date ( "Y-m-d H:i:s" )
  5008. );
  5009. $invoiceRefund->addInvoiceRefund ( $item );
  5010. // 扣除收款汇总信息 汇总
  5011. Doo::loadModel ( 'invoiceStatistics' );
  5012. $invoiceStatistics = new invoiceStatistics ();
  5013. $item = array (
  5014. 'date' => $irDetail ['receivablesDate'],
  5015. 'priceClass' => 2,
  5016. 'irid' => $irDetail ['irid'],
  5017. 'receivablesPrice' => - $refundPrice
  5018. );
  5019. if ($irDetail ['receivablesCategory'] != 'PUBLIC') {
  5020. $receivablesCategory = explode ( ":", $irDetail ['receivablesCategory'] );
  5021. $item += array (
  5022. 'cid' => $receivablesCategory [0]
  5023. );
  5024. }
  5025. if ($irDetail ['receivablesStaff'] != 'PUBLIC') {
  5026. $receivablesStaff = explode ( "-", $irDetail ['receivablesStaff'] );
  5027. $item += array (
  5028. 'staff' => $receivablesStaff [0]
  5029. );
  5030. }
  5031. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  5032. // 公司日常支出流水
  5033. Doo::loadModel ( 'wasteBook' );
  5034. $wasteBook = new wasteBook ();
  5035. $accountBank = '';
  5036. if ($irDetail ['receivablesBank'] == '纵横广发') {
  5037. $accountBank = 'CGBDeposit';
  5038. } elseif ($irDetail ['receivablesBank'] == '纵横工行') {
  5039. $accountBank = 'ICBCDeposit';
  5040. } elseif ($irDetail ['receivablesBank'] == '华润银行') {
  5041. $accountBank = 'HUADeposit';
  5042. } elseif ($irDetail ['receivablesBank'] == '个人广发') {
  5043. $accountBank = 'PersonalDeposit';
  5044. }
  5045. $itemWaste = array (
  5046. 'accountPrice' => - $refundPrice,
  5047. 'expensesType' => 2,
  5048. 'accountType' => 11,
  5049. 'accountPriceShow' => $refundPrice,
  5050. 'dataID' => $irid,
  5051. 'accountBank' => $accountBank,
  5052. 'category' => $this->staff [0] ['category'],
  5053. 'cid' => $this->staff [0] ['cid'],
  5054. 'name' => $this->staff [0] ['username'],
  5055. 'sid' => $this->staff [0] ['sid'],
  5056. 'inputDate' => date ( "Y-m-d H:i:s" )
  5057. );
  5058. $wasteBook->setAccountBookStatistics ( $itemWaste );
  5059. return '/invoiceReceivablesAS';
  5060. }
  5061. die ( 'illegal request' );
  5062. }
  5063. function ajaxCheckInvoiceReceivablesRefund() {
  5064. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5065. $refundPrice = $this->get_args ( 'refundPrice' ) ? $this->get_args ( 'refundPrice' ) : "";
  5066. if ($refundPrice < 0) {
  5067. echo json_encode ( array (
  5068. 'error' => '金额不能为负'
  5069. ) );
  5070. die ();
  5071. }
  5072. if (! empty ( $refundPrice ) && ! empty ( $iridKey )) {
  5073. Doo::loadModel ( 'invoiceReceivables' );
  5074. $invoiceReceivables = new invoiceReceivables ();
  5075. $irid = $invoiceReceivables->authcode ( $iridKey );
  5076. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5077. if ($irDetail ['receivablesPrice'] < $refundPrice) {
  5078. echo json_encode ( array (
  5079. 'error' => '退款金额不能超过收款金额'
  5080. ) );
  5081. die ();
  5082. }
  5083. echo json_encode ( array (
  5084. 'ok' => '可以使用!'
  5085. ) );
  5086. die ();
  5087. }
  5088. }
  5089. /**
  5090. * 获得收款退款信息
  5091. */
  5092. function getRefundByDetail() {
  5093. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5094. Doo::loadModel ( 'invoiceReceivables' );
  5095. $invoiceReceivables = new invoiceReceivables ();
  5096. if (! empty ( $iridKey )) {
  5097. $irid = $invoiceReceivables->authcode ( $iridKey );
  5098. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5099. echo json_encode ( array (
  5100. 'status' => 1,
  5101. 'irDetail' => $irDetail
  5102. ) );
  5103. die ();
  5104. }
  5105. echo json_encode ( array (
  5106. 'status' => 2
  5107. ) );
  5108. }
  5109. /**
  5110. * 根据收款序列号获得收款退款信息
  5111. */
  5112. function ajaxGetInvoiceReceivablesBySerial() {
  5113. $receivablesSerial = $this->get_args ( 'receivablesSerial' ) ? $this->get_args ( 'receivablesSerial' ) : '';
  5114. if (! empty ( $receivablesSerial )) {
  5115. Doo::loadModel ( 'invoiceReceivables' );
  5116. $invoiceReceivables = new invoiceReceivables ();
  5117. // , ' and refundLog=""'
  5118. $irDetail = $invoiceReceivables->getInvoiceReceivablesBySerial ( $receivablesSerial );
  5119. $html = '';
  5120. if (! empty ( $irDetail ))
  5121. $html = '<td><b>¥' . $irDetail ['receivablesPrice'] . '</b></td>
  5122. <td>' . $irDetail ['receivablesMessage'] . '</td>
  5123. <td>' . $irDetail ['receivablesBank'] . '<br>' . $irDetail ['receivablesDate'] . '</td>
  5124. <td>' . $irDetail ['title'] . '-' . $irDetail ['username'] . '<br>' . $irDetail ['confirmTime'] . '</td>
  5125. <td>' . $irDetail ['recepitTitleMark'] . '
  5126. <input type="hidden" name="iridKey" id="iridKey" value="' . $irDetail ['iridKey'] . '">
  5127. </td>';
  5128. echo json_encode ( array (
  5129. 'status' => 1,
  5130. 'html' => $html,
  5131. 'irDetail' => $irDetail
  5132. ) );
  5133. die ();
  5134. }
  5135. echo json_encode ( array (
  5136. 'status' => 2
  5137. ) );
  5138. }
  5139. /**
  5140. * 绑定新收款
  5141. */
  5142. function relationNewInvoiceReceivables() {
  5143. $iridKeyOld = $this->get_args ( 'iridKeyOld' ) ? $this->get_args ( 'iridKeyOld' ) : '';
  5144. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5145. if (! empty ( $iridKeyOld ) && ! empty ( $iridKey )) {
  5146. Doo::loadModel ( 'invoiceReceivables' );
  5147. $invoiceReceivables = new invoiceReceivables ();
  5148. Doo::loadClass ( 'XDeode' );
  5149. $XDeode = new XDeode ( 5 );
  5150. $irid = $XDeode->decode ( $iridKey );
  5151. $iridOld = $invoiceReceivables->authcode ( $iridKeyOld );
  5152. echo $irid . 'bbb' . $iridOld;
  5153. $oldIrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $iridOld );
  5154. $IrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5155. if (empty ( $oldIrDetail ) || empty ( $IrDetail ))
  5156. die ( 'illegal request' );
  5157. $relationLog = $this->staff [0] ['username'] . ' 关联新款 <a href="#billing" onclick="invoiceReceivblesDivShow(\'' . $iridKey . '\',\'receivables\')" data-toggle="modal">' . $IrDetail ['receivablesSerial'] . '</a>
  5158. <br/>' . date ( "Y-m-d H:i:s" ) . '
  5159. ';
  5160. $invoiceReceivables = new invoiceReceivables ();
  5161. $item = array (
  5162. 'irid' => $iridOld,
  5163. 'relationIrid' => $irid,
  5164. 'relationLog' => $relationLog
  5165. );
  5166. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  5167. return '/invoiceReceivablesAS';
  5168. }
  5169. die ( 'illegal request' );
  5170. }
  5171. // function invoiceApprovalAchieve() {
  5172. // Doo::loadModel ( 'invoice' );
  5173. // $invoice = new invoice ();
  5174. // $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  5175. // $page_size = 12;
  5176. // $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5177. // $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  5178. // $get = "/" . $date;
  5179. // $con = '';
  5180. // if ($date == 'MONTHO')
  5181. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  5182. // elseif ($date == 'MONTHT')
  5183. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  5184. // elseif ($date == 'MONTHY')
  5185. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  5186. // if (! empty ( $MebSea )) {
  5187. // $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  5188. // $get .= "/" . $MebSea;
  5189. // }
  5190. // $pageinfo ['page'] = array (
  5191. // 'previous' => ''
  5192. // );
  5193. // $sql = '(status=1 or status=2 or status=3 or status=4) and processApprovals!=""' . $con; // echo $sql;
  5194. // $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", $get, "" );
  5195. // $limit = $pageinfo ['lower'] . ',' . $page_size;
  5196. // $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  5197. // // print_r($list);
  5198. // $this->data ['MebSeaEn'] = $MebSea;
  5199. // $this->data ['MebSea'] = urlencode ( $MebSea );
  5200. // $this->data ['get'] = $get;
  5201. // $this->data ['page'] = $pageinfo;
  5202. // $this->data ['list'] = $list;
  5203. // $this->data ['date'] = $date;
  5204. // $this->data ['memu'] = "invoice";
  5205. // $this->data ['staff'] = $this->staff;
  5206. // $this->data ['receiptMemu'] = 'invoiceApproval';
  5207. // $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  5208. // }
  5209. /**
  5210. * 获得审批发票的信息以及审批页面
  5211. */
  5212. function ajaxGetInvoiceApprovalDetail() {
  5213. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5214. if (empty ( $serial )) {
  5215. echo json_encode ( array (
  5216. 'status' => 2,
  5217. 'msg' => 'illegal request'
  5218. ) );
  5219. die ();
  5220. }
  5221. Doo::loadModel ( 'invoice' );
  5222. $invoice = new invoice ();
  5223. Doo::loadModel ( 'invoiceOperationLog' );
  5224. $invoiceOperationLog = new invoiceOperationLog ();
  5225. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5226. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5227. if (empty ( $detail ))
  5228. $html = '';
  5229. else {
  5230. $html = '
  5231. <form action="/invoiceApprovalDo" method="post" name="invoiceApproval" class="nice-validator n-yellow" novalidate="novalidate">
  5232. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  5233. <input type="hidden" name="status" value="">
  5234. <input type="hidden" name="divApproval" value="divApproval">
  5235. <div class="modal-dialog modal-lg">
  5236. <div class="modal-content"><div class="modal-header"><h3>发票审批详情</h3></div>
  5237. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  5238. <tr>
  5239. <th class="taC" width="150">发票审批</th><td><textarea name="opinion" style="width:98%" placeholder="在这写下您的审批意见,选填。"></textarea></td>
  5240. </tr>
  5241. <tr>
  5242. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5243. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5244. </tr>
  5245. <tr>
  5246. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5247. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5248. </tr>
  5249. <tr>
  5250. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5251. </td>
  5252. </tr>
  5253. <tr>
  5254. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5255. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5256. </tr>
  5257. <tr>
  5258. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5259. </tr></tbody></table>';
  5260. if ($detail ['invoiceType'] == 0)
  5261. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5262. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5263. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5264. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5265. </tr>';
  5266. else
  5267. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5268. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5269. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5270. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5271. ';
  5272. $html .= '<tr>
  5273. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5274. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5275. </tr>
  5276. <tr>
  5277. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5278. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5279. </tr></tbody></table>';
  5280. if ($detail ['doPost'] == 1) {
  5281. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5282. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5283. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5284. </tr><tr>
  5285. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5286. </tr><tr>
  5287. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5288. </tr>
  5289. ';
  5290. if ($detail ['expressCom'] == 'SF')
  5291. $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>';
  5292. else
  5293. $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>';
  5294. $html .= '</tbody></table>';
  5295. }
  5296. if (! empty ( $invoiceOperationLogList )) {
  5297. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  5298. foreach ( $invoiceOperationLogList as $key => $value ) {
  5299. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5300. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5301. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5302. if ($value ['status'] == 2) {
  5303. $html .= '<span class="colGreen">同意</span>';
  5304. } elseif ($value ['status'] == 3) {
  5305. $html .= '<span class="colOrange">退回</span>';
  5306. } elseif ($value ['status'] == 5) {
  5307. $html .= '<span class="colGreen">打印</span>';
  5308. } elseif ($value ['status'] == 4) {
  5309. $html .= '<span class="colRed">终止</span>';
  5310. }
  5311. $html .= $value ['operation'] . '</p></blockquote>';
  5312. }
  5313. }
  5314. $html .= '</td></tr></tbody></table>';
  5315. }
  5316. $html .= '</div><div class="modal-footer">
  5317. <a href="javascript:void(0)" node-approval="approval" diss-data="2" class="button btn-done" data-placement="top" data-toggle="ctooltip" >同意</a>
  5318. <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>
  5319. <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>
  5320. <a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>
  5321. </form>
  5322. <script type="text/javascript">
  5323. $("a[node-approval^=\'approval\']").click(function() {
  5324. $("input[name=\'status\']").val($(this).attr("diss-data"));
  5325. $("form[name=\'invoiceApproval\']").submit();
  5326. });
  5327. </script>
  5328. ';
  5329. }
  5330. echo json_encode ( array (
  5331. 'status' => 1,
  5332. 'html' => $html
  5333. ) );
  5334. die ();
  5335. }
  5336. /**
  5337. * 获得审批发票分页数据
  5338. */
  5339. function ajaxGetinvoiceApprovalAchieve() {
  5340. Doo::loadModel ( 'invoice' );
  5341. $invoice = new invoice ();
  5342. Doo::loadModel ( 'staff' );
  5343. $staff = new staff ();
  5344. Doo::loadClass ( 'XDeode' );
  5345. $XDeode = new XDeode ( 5 );
  5346. Doo::loadModel ( 'invoiceTraining' );
  5347. $invoiceTraining = new invoiceTraining ();
  5348. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  5349. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5350. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5351. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5352. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5353. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  5354. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  5355. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  5356. $MebSea = $this->get_args ( 'search' );
  5357. $MebSea = $MebSea ['value'];
  5358. $page_size = $length;
  5359. $con = '';
  5360. if ($status == 'ALL')
  5361. $con = ' (status=1 or status=2 or status=3 or status=4) and isDelete=0 ';
  5362. elseif ($status == 'PEND')
  5363. $con = ' isDelete=0 and status=1';
  5364. elseif ($status == 'APPROVED')
  5365. $con = ' isDelete=0 and status=2';
  5366. if ($invoiceType == 'ORDINARY')
  5367. $con .= ' and invoiceType=0 ';
  5368. elseif ($invoiceType == 'SPECIAL')
  5369. $con .= ' and invoiceType=1 ';
  5370. if ($invoiceTrain == 'ORDINARY')
  5371. $con .= ' and trainId=0 ';
  5372. elseif ($invoiceTrain == 'TRAIN')
  5373. $con .= ' and trainId!=0 ';
  5374. if ($invoiceTrainName != 'ALL') {
  5375. $trainId = $XDeode->decode ( $invoiceTrainName );
  5376. if (is_numeric ( $trainId ))
  5377. $con .= ' and trainId =' . $trainId;
  5378. }
  5379. $dateArr = explode ( ':', $date );
  5380. $D1 = $dateString = '';
  5381. $D2 = '';
  5382. if (! empty ( $date )) {
  5383. $D1 = $dateArr [0];
  5384. if (isset ( $dateArr [1] ))
  5385. $D2 = $dateArr [1];
  5386. else
  5387. $D2 = '';
  5388. $dateString = $D1 . " : " . $D2;
  5389. }
  5390. if (! empty ( $D1 ) && ! empty ( $D2 ))
  5391. $con .= ' and approvalTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  5392. elseif (! empty ( $D1 ) && empty ( $D2 ))
  5393. $con .= ' and approvalTime like "%' . $D1 . '%" ';
  5394. if (! empty ( $MebSea ))
  5395. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceSerial like "%' . $MebSea . '%" )';
  5396. // /
  5397. $pageinfo ['page'] = array (
  5398. 'previous' => ''
  5399. );
  5400. $sql = ' ' . $con;
  5401. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", '', "" );
  5402. $limit = $page . ',' . $page_size;
  5403. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  5404. $approvalList = array ();
  5405. $html = '<script type="text/javascript">
  5406. </script>';
  5407. // 结算结束不能修改方式
  5408. Doo::loadModel ( 'receipt' );
  5409. $receipt = new receipt ();
  5410. foreach ( $list as $key => $value ) {
  5411. $irDetail = array ();
  5412. // 结算方式
  5413. $receiptDetail = array ();
  5414. if ($value ['trainId'] != 0) {
  5415. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $value ['trainId'] );
  5416. }
  5417. if (! empty ( $receiptDetail )) {
  5418. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9) {
  5419. array_push ( $irDetail, '' );
  5420. } else {
  5421. if ($value ['status'] == 1 && $value ['pendingApprovals'] == $this->staff [0] ['sid']) {
  5422. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoiceApproval(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">审批发票</a>' );
  5423. } elseif ($value ['status'] == 2) {
  5424. array_push ( $irDetail, '<a href="#editPay" class="fnSettlementType" data-iidKey="' . $value ['iidKeyK'] . '" data-toggle="modal">结算方式</a>' );
  5425. } else
  5426. array_push ( $irDetail, '' );
  5427. }
  5428. } else {
  5429. if ($value ['status'] == 2) {
  5430. array_push ( $irDetail, '<a href="#editPay" class="fnSettlementType" data-iidKey="' . $value ['iidKeyK'] . '" data-toggle="modal">结算方式</a>' );
  5431. } else
  5432. array_push ( $irDetail, '' );
  5433. }
  5434. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  5435. if ($value ['invoiceType'] == 1)
  5436. array_push ( $irDetail, $value ['invoiceCompany'] );
  5437. else
  5438. array_push ( $irDetail, $value ['invoiceTitle'] );
  5439. array_push ( $irDetail, $value ['TIN'] );
  5440. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  5441. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  5442. array_push ( $irDetail, $value ['remark'] );
  5443. array_push ( $irDetail, $value ['invoiceElement'] );
  5444. array_push ( $irDetail, $value ['invoiceQuantity'] );
  5445. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  5446. if ($value ['invoiceType'] == 1) {
  5447. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  5448. } else {
  5449. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  5450. }
  5451. if ($value ['settlementType'] == 0) {
  5452. array_push ( $irDetail, '软件销售' );
  5453. } else {
  5454. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $value ['trainId'] );
  5455. array_push ( $irDetail, $itDetail ['trainName'] );
  5456. }
  5457. array_push ( $irDetail, $value ['recipients'] . $value ['recipientsPhone'] );
  5458. array_push ( $irDetail, $value ['recipientsAddress'] );
  5459. array_push ( $irDetail, $value ['mailItems'] );
  5460. array_push ( $irDetail, $value ['userName'] . '&nbsp;' . $value ['date'] );
  5461. $fchtml = $value ['OL'] ['operation'];
  5462. if (count ( $list ) == $page_size)
  5463. $fchtml = $value ['OL'] ['operation'] . $html;
  5464. // 最后的审批意见
  5465. array_push ( $irDetail, $fchtml );
  5466. if ($value ['status'] == 2)
  5467. array_push ( $irDetail, '<span class="colGreen">同意</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5468. elseif ($value ['status'] == 3)
  5469. array_push ( $irDetail, '<span class="colOrange">退回</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5470. elseif ($value ['status'] == 4)
  5471. array_push ( $irDetail, '<span class="colRed">终止</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5472. else
  5473. array_push ( $irDetail, '' );
  5474. array_push ( $approvalList, $irDetail );
  5475. }
  5476. // $approvalListJson = json_encode ( $approvalList );
  5477. $recordsFiltered = $pageinfo ['total_data'];
  5478. echo json_encode ( array (
  5479. "draw" => intval ( $draw ),
  5480. "recordsTotal" => intval ( $pageinfo ['total_data'] ),
  5481. "recordsFiltered" => intval ( $recordsFiltered ),
  5482. "data" => $approvalList
  5483. ), JSON_UNESCAPED_UNICODE );
  5484. }
  5485. /**
  5486. * 审批发票查看更多--重构
  5487. */
  5488. function invoiceApprovalAchieve() {
  5489. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'ALL';
  5490. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5491. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5492. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5493. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5494. Doo::loadModel ( 'invoiceTraining' );
  5495. $invoiceTraining = new invoiceTraining ();
  5496. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  5497. $this->data ['trainList'] = $trainList;
  5498. $this->data ['dateString'] = $date;
  5499. $this->data ['status'] = $status;
  5500. $this->data ['invoiceType'] = $invoiceType;
  5501. $this->data ['invoiceTrain'] = $invoiceTrain;
  5502. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  5503. $this->data ['memu'] = "invoice";
  5504. $this->data ['staff'] = $this->staff;
  5505. $this->data ['receiptMemu'] = 'invoiceApproval';
  5506. $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  5507. }
  5508. function invoiceTAchieve() {
  5509. Doo::loadModel ( 'invoice' );
  5510. $invoice = new invoice ();
  5511. Doo::loadClass ( 'XDeode' );
  5512. $XDeode = new XDeode ( 5 );
  5513. Doo::loadModel ( 'staff' );
  5514. $staff = new staff ();
  5515. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  5516. $page_size = 12;
  5517. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5518. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  5519. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5520. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5521. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5522. Doo::loadModel ( 'invoiceTraining' );
  5523. $invoiceTraining = new invoiceTraining ();
  5524. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  5525. $get = "/" . $date;
  5526. $con = '';
  5527. if ($date == 'MONTHO')
  5528. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  5529. elseif ($date == 'MONTHT')
  5530. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  5531. elseif ($date == 'MONTHY')
  5532. $con = ' and YEAR(updateTime) = YEAR(NOW())'; // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  5533. if ($invoiceType == 'ORDINARY')
  5534. $con .= ' and invoiceType=0 ';
  5535. elseif ($invoiceType == 'SPECIAL')
  5536. $con .= ' and invoiceType=1 ';
  5537. if ($invoiceTrain == 'ORDINARY')
  5538. $con .= ' and trainId=0 ';
  5539. elseif ($invoiceTrain == 'TRAIN')
  5540. $con .= ' and trainId!=0 ';
  5541. if ($invoiceTrainName != 'ALL') {
  5542. $trainId = $XDeode->decode ( $invoiceTrainName );
  5543. if (is_numeric ( $trainId ))
  5544. $con .= ' and trainId =' . $trainId;
  5545. }
  5546. if (! empty ( $MebSea )) {
  5547. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  5548. $get .= "/" . $MebSea;
  5549. }
  5550. $pageinfo ['page'] = array (
  5551. 'previous' => ''
  5552. );
  5553. $sql = "";
  5554. $action = "";
  5555. if ($this->ACTION == 'invoicePrintAchieve') {
  5556. $sql = "status=2 and printStatus=1 and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  5557. $action = "invoicePrintAchieve";
  5558. } elseif ($this->ACTION == 'invoicePostAchieve') {
  5559. // and untreadStatus=0
  5560. $sql = "postStatus=1 and doPost=1 and status=2 and isDelete=0" . $con;
  5561. $action = "invoicePostAchieve";
  5562. } elseif ($this->ACTION == 'invoiceUntreadAchieve') { // printStatus=1 and
  5563. $sql = " untreadStatus=2 and status=2 " . $con;
  5564. $action = "invoiceUntreadAchieve";
  5565. }
  5566. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  5567. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5568. $this->data ['MebSeaEn'] = $MebSea;
  5569. $this->data ['MebSea'] = urlencode ( $MebSea );
  5570. $this->data ['get'] = $get;
  5571. $this->data ['page'] = $pageinfo;
  5572. $this->data ['trainList'] = $trainList;
  5573. $this->data ['invoiceType'] = $invoiceType;
  5574. $this->data ['invoiceTrain'] = $invoiceTrain;
  5575. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  5576. $this->data ['date'] = $date;
  5577. $this->data ['memu'] = "invoice";
  5578. $this->data ['staff'] = $this->staff;
  5579. if ($this->ACTION == 'invoicePrintAchieve') {
  5580. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  5581. $this->data ['receiptMemu'] = 'invoicePrint';
  5582. $this->data ['list'] = $list;
  5583. $this->render ( "/admin/invoicePrintAchieve", $this->data );
  5584. } elseif ($this->ACTION == 'invoicePostAchieve') {
  5585. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  5586. Doo::loadModel ( 'express' );
  5587. $express = new express ();
  5588. $expressList = $express->getExpressByAll ();
  5589. $this->data ['expressList'] = $expressList;
  5590. $this->data ['receiptMemu'] = 'invoicePost';
  5591. $this->data ['list'] = $list;
  5592. $this->render ( "/admin/invoicePostAchieve", $this->data );
  5593. } elseif ($this->ACTION == 'invoiceUntreadAchieve') {
  5594. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  5595. $this->data ['receiptMemu'] = 'invoiceUntread';
  5596. $this->data ['list'] = $list;
  5597. $this->render ( "/admin/invoiceUntreadAchieve", $this->data );
  5598. }
  5599. }
  5600. /**
  5601. * 公司应收款
  5602. */
  5603. function invoiceAggregateCompanyDetail() {
  5604. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  5605. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  5606. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : 'ALL';
  5607. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  5608. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  5609. $titleORno = $this->get_args ( 'titleORno' ) ? $this->get_args ( 'titleORno' ) : "";
  5610. Doo::loadClass ( 'XDeode' );
  5611. $XDeode = new XDeode ( 5 );
  5612. Doo::loadModel ( 'invoice' );
  5613. $invoice = new invoice ();
  5614. Doo::loadModel ( 'staff' );
  5615. $staff = new staff ();
  5616. Doo::loadModel ( "invoiceCompanyManage" );
  5617. $invoiceCompanyManage = new invoiceCompanyManage ();
  5618. Doo::loadModel ( 'L_category' );
  5619. $category = new L_category ();
  5620. $sid = '';
  5621. if (! empty ( $sidKey )) {
  5622. $sid = $XDeode->decode ( $sidKey );
  5623. }
  5624. $staffDetail = $staff->getStaffBySid ( $sid );
  5625. $cid = '';
  5626. if (! empty ( $cidKey )) {
  5627. $cid = $XDeode->decode ( $cidKey );
  5628. }
  5629. $imcStaff = $invoiceCompanyManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  5630. $cidList = array ();
  5631. foreach ( $imcStaff as $key => $value ) {
  5632. array_push ( $cidList, $value ['cid'] );
  5633. }
  5634. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  5635. $cidString = implode ( ',', $cidList );
  5636. if (empty ( $cid ))
  5637. $staffList = $staff->getStaffInCid ( $cidString );
  5638. else
  5639. $staffList = $staff->getStaffByCidAll ( $cid ); //
  5640. //$MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  5641. $page_size = 25;
  5642. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5643. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  5644. $con = ' status=2 and untreadStatus!=2 ';
  5645. $statisticsCon = '';
  5646. if (! empty ( $year ) && is_numeric ( $year ))
  5647. $con .= ' and Year(printTime)=' . $year . '';
  5648. if (! empty ( $month ) && is_numeric ( $month ))
  5649. $con .= ' and Month(printTime)="' . $month . '" ';
  5650. if ($status == 'UNRECORD')
  5651. $con .= ' and printStatus=1 and untreadStatus=0';
  5652. elseif ($status == 'RECORD')
  5653. $con .= ' and printStatus=1 and untreadStatus=3';
  5654. elseif ($status == 'BOUNCED')
  5655. $con .= ' and untreadStatus=2';
  5656. elseif ($status == 'PARTRECORD')
  5657. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  5658. elseif ($status == 'All') {
  5659. $con .= ' and printStatus=1 and ( untreadStatus=0 or untreadStatus=3 )';
  5660. }
  5661. if (! empty ( $sid ) && is_numeric ( $sid ))
  5662. $con .= ' and sid=' . $sid;
  5663. if (! empty ( $cid ) && is_numeric ( $cid ))
  5664. $con .= ' and cid=' . $cid;
  5665. else
  5666. $con .= ' and cid in (' . $cidString . ')';
  5667. // 开票内容筛选
  5668. if (! empty ( $invoiceElement ) && $invoiceElement != 'ALL') {
  5669. $con .= ' and invoiceElement="' . $invoiceElement . '"';
  5670. }
  5671. $get = "/" . $status . "?cidKey=" . $cidKey . "&sidKey=" . $sidKey . "&year=" . $year . "&month=" . $month
  5672. . "&invoiceElement=" . $invoiceElement."&titleORno=".urlencode ( $titleORno );
  5673. if (! empty ( $titleORno )) {
  5674. $con .= ' and ( invoiceTitle like "%' . $titleORno . '%" or invoiceCompany like "%' . $titleORno . '%" or invoiceNo like "%'.$titleORno.'%" )';
  5675. }
  5676. $pageinfo ['page'] = array (
  5677. 'previous' => ''
  5678. );
  5679. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateCompanyDetail", $get, "" );
  5680. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5681. // 应收款合计
  5682. $ics = $invoice->getInvoiceCompanyStatistics ( $con );
  5683. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  5684. $monthHtml = "";
  5685. if ($year != "ALL") {
  5686. for($i = 1; $i <= 12; $i ++) {
  5687. if ($i == $month)
  5688. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  5689. else
  5690. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  5691. }
  5692. }
  5693. $this->data ['monthHtml'] = $monthHtml;
  5694. $this->data ['year'] = $year;
  5695. $this->data ['month'] = $month;
  5696. $this->data ['ics'] = $ics;
  5697. $this->data ['cidKey'] = $cidKey;
  5698. $this->data ['sid'] = $sid;
  5699. $this->data ['staffDetail'] = $staffDetail;
  5700. $this->data ['staffList'] = $staffList;
  5701. $this->data ['titleORnoEn'] = $titleORno;
  5702. $this->data ['titleORno'] = urlencode ( $titleORno );
  5703. $this->data ['invoiceDetail'] = array (
  5704. 'invoiceElement' => $invoiceElement
  5705. );
  5706. $this->data ['page'] = $pageinfo;
  5707. $this->data ['get'] = $get;
  5708. $this->data ['list'] = $list;
  5709. $this->data ['status'] = $status;
  5710. $this->data ['categoryList'] = $categoryList;
  5711. $this->data ['memu'] = "invoice";
  5712. $this->data ['staff'] = $this->staff;
  5713. $this->data ['receiptMemu'] = 'invoiceAggregateCompanyDetail';
  5714. $this->render ( "/admin/invoiceAggregateCompanyDetail", $this->data );
  5715. }
  5716. /**
  5717. * 获取一条收款信息
  5718. */
  5719. function ajaxGetInvoiceReceivables() {
  5720. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  5721. Doo::loadModel ( 'invoiceReceivables' );
  5722. $invoiceReceivables = new invoiceReceivables ();
  5723. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5724. echo json_encode ( array (
  5725. 'status' => 1,
  5726. 'detail' => $detail
  5727. ) );
  5728. }
  5729. /**
  5730. * 异步获取办事处用户
  5731. */
  5732. function ajaxGetStaffByCategory() {
  5733. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "";
  5734. Doo::loadModel ( 'staff' );
  5735. $staff = new staff ();
  5736. if ($cid == "PUBLIC") {
  5737. echo json_encode ( array (
  5738. 'status' => 1,
  5739. 'html' => '<option value="PUBLIC">办事处待认领款项</option>'
  5740. ) );
  5741. die ();
  5742. }
  5743. if (! is_numeric ( $cid )) {
  5744. echo json_encode ( array (
  5745. 'status' => 0,
  5746. 'msg' => 'illegal request'
  5747. ) );
  5748. die ();
  5749. }
  5750. $staffList = $staff->getStaffByCid ( $cid );
  5751. $html = '<option value="PUBLIC">办事处待认领款项</option>';
  5752. foreach ( $staffList as $key => $value ) {
  5753. $html .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  5754. }
  5755. echo json_encode ( array (
  5756. 'status' => 1,
  5757. 'html' => $html
  5758. ) );
  5759. }
  5760. /**
  5761. * 异步获取一条发票的邮寄信息
  5762. */
  5763. function ajaxGetInvoicePostDetail() {
  5764. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  5765. Doo::loadModel ( 'invoice' );
  5766. $invoice = new invoice ();
  5767. $iid = $invoice->authcode ( $iid );
  5768. Doo::loadModel ( 'express' );
  5769. $express = new express ();
  5770. $expressList = $express->getExpressByAll ();
  5771. if (! is_numeric ( $iid )) {
  5772. echo json_encode ( array (
  5773. 'status' => 0,
  5774. 'msg' => 'illegal request'
  5775. ) );
  5776. die ();
  5777. }
  5778. $select = "iid,recipients,recipientsPhone,recipientsAddress,mailItems,expressCompany,expressNumber,actualItems";
  5779. $invoiceDetail = $invoice->getInvoiceByIid ( $iid, $select );
  5780. $html = "";
  5781. foreach ( $expressList as $key => $value ) {
  5782. if ($value ['company'] == $invoiceDetail ['expressCompany'])
  5783. $html .= '<option selected value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  5784. else
  5785. $html .= '<option value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  5786. }
  5787. $invoiceDetail ['eaHtml'] = $html;
  5788. echo json_encode ( array (
  5789. 'status' => 1,
  5790. 'invoiceDetail' => $invoiceDetail
  5791. ) );
  5792. }
  5793. /**
  5794. *
  5795. * @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 ) ); }
  5796. */
  5797. /**
  5798. *
  5799. * @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 ) ); }
  5800. */
  5801. /**
  5802. * 我的收款中 选择哪个发票入账,进行金额判断
  5803. */
  5804. function ajaxCompareInvoicePrice() {
  5805. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  5806. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  5807. Doo::loadModel ( 'invoice' );
  5808. $invoice = new invoice ();
  5809. Doo::loadModel ( 'invoiceReceivables' );
  5810. $invoiceReceivables = new invoiceReceivables ();
  5811. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  5812. $keyList = explode ( ';', $claimKey );
  5813. $receivablesPrice = 0;
  5814. foreach ( $keyList as $key => $value ) {
  5815. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $value );
  5816. $receivablesPrice += $detailM ['receivablesPrice'];
  5817. }
  5818. if ($receivablesPrice > $detail ['invoicePrice']) {
  5819. $price = $receivablesPrice - $detail ['invoicePrice'];
  5820. echo json_encode ( array (
  5821. 'status' => 1,
  5822. 'price' => $price
  5823. ) );
  5824. } else
  5825. echo json_encode ( array (
  5826. 'status' => 2
  5827. ) );
  5828. }
  5829. /**
  5830. * 获得打印发票
  5831. */
  5832. function ajaxGetInvoiceInfoByPrint() {
  5833. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5834. if (empty ( $serial )) {
  5835. echo json_encode ( array (
  5836. 'status' => 2,
  5837. 'msg' => 'illegal request'
  5838. ) );
  5839. die ();
  5840. }
  5841. Doo::loadModel ( 'invoice' );
  5842. $invoice = new invoice ();
  5843. Doo::loadModel ( 'invoiceOperationLog' );
  5844. $invoiceOperationLog = new invoiceOperationLog ();
  5845. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5846. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5847. Doo::loadModel ( 'invoicePaper' );
  5848. $invoicePaper = new invoicePaper ();
  5849. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $detail ['invoiceType'] );
  5850. if (empty ( $detail ))
  5851. $html = '';
  5852. else {
  5853. $html = '
  5854. <form action="/invoicePrintDo" method="post" name="invoicePrint" class="nice-validator n-yellow" onSubmit="return checkPrintForm()" novalidate="novalidate">
  5855. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  5856. <input type="hidden" name="invoicePrintType" value="invoicePrintType">
  5857. <div class="modal-dialog modal-lg">
  5858. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  5859. <div class="modal-body saeaList">
  5860. <table class="table table-bordered table-condensed"><tbody>
  5861. <tr>
  5862. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5863. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5864. </tr>
  5865. <tr>
  5866. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5867. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5868. </tr>
  5869. <tr>
  5870. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5871. </td>
  5872. </tr>
  5873. <tr>
  5874. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5875. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5876. </tr>
  5877. <tr>
  5878. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5879. </tr></tbody></table>';
  5880. if ($detail ['invoiceType'] == 0)
  5881. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5882. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5883. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5884. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5885. </tr>';
  5886. else
  5887. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5888. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5889. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5890. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5891. ';
  5892. $html .= '<tr>
  5893. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5894. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5895. </tr>
  5896. <tr>
  5897. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5898. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5899. </tr></tbody></table>';
  5900. if ($detail ['doPost'] == 1)
  5901. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5902. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5903. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5904. </tr><tr>
  5905. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5906. </tr><tr>
  5907. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5908. </tr></tbody></table>';
  5909. if (! empty ( $invoiceOperationLogList )) {
  5910. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th><th class="taC">发票打印</th></tr><tr><td>';
  5911. foreach ( $invoiceOperationLogList as $key => $value ) {
  5912. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5913. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5914. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5915. if ($value ['status'] == 2) {
  5916. $html .= '<span class="colGreen">同意</span>';
  5917. } elseif ($value ['status'] == 3) {
  5918. $html .= '<span class="colOrange">退回</span>';
  5919. } elseif ($value ['status'] == 5) {
  5920. $html .= '<span class="colGreen">打印</span>';
  5921. } elseif ($value ['status'] == 4) {
  5922. $html .= '<span class="colRed">终止</span>';
  5923. }
  5924. $html .= $value ['operation'] . '</p></blockquote>';
  5925. }
  5926. }
  5927. $html .= '</td>
  5928. <td><span class="colRed">*</span>
  5929. <select name="invoiceNo" id="invoiceNo" style="width:97%">';
  5930. foreach ( $invoicePaperList as $key => $value ) {
  5931. $html .= '<option value="' . $value ['ipidKey'] . '">No.' . $value ['invoiceNo'] . '</option>';
  5932. }
  5933. $html .= '</select>
  5934. <span class="red" id="p-msg"></span>
  5935. </td>
  5936. </tr></tbody></table>';
  5937. }
  5938. $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>
  5939. </div></div></form>
  5940. <link rel=stylesheet href="' . WEB_SITE_GLOBAL . 'css/jquery.validator.css">
  5941. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/jquery.validator.min.js"></script>
  5942. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/zh-CN.js"></script>
  5943. <script src="' . WEB_SITE_GLOBAL . 'js/invoice.validator.js"></script>
  5944. ';
  5945. }
  5946. echo json_encode ( array (
  5947. 'status' => 1,
  5948. 'html' => $html
  5949. ) );
  5950. die ();
  5951. }
  5952. /**
  5953. * @ 获得与我有关收款数据 --需求变更 废弃 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 ) ); }
  5954. */
  5955. function ajaxGetInvoiceInfoByType() {
  5956. $type = $this->get_args ( 'type' ) ? $this->get_args ( 'type' ) : "";
  5957. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5958. $loss = $this->get_args ( 'loss' ) ? $this->get_args ( 'loss' ) : false;
  5959. if (empty ( $serial )) {
  5960. echo json_encode ( array (
  5961. 'status' => 2,
  5962. 'msg' => 'illegal request'
  5963. ) );
  5964. die ();
  5965. }
  5966. if ($type == 'INVOICE') {
  5967. Doo::loadModel ( 'invoice' );
  5968. $invoice = new invoice ();
  5969. Doo::loadModel ( 'invoiceOperationLog' );
  5970. $invoiceOperationLog = new invoiceOperationLog ();
  5971. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5972. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5973. if (empty ( $detail ))
  5974. $html = '';
  5975. else {
  5976. $html = '
  5977. <div class="modal-dialog modal-lg">
  5978. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  5979. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  5980. <tr>
  5981. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5982. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5983. </tr>
  5984. <tr>
  5985. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5986. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5987. </tr>
  5988. <tr>
  5989. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5990. </td>
  5991. </tr>
  5992. <tr>
  5993. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5994. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5995. </tr>
  5996. <tr>
  5997. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5998. </tr>';
  5999. if ($detail ['settlementType'] == 1)
  6000. $html .= '<tr>
  6001. <th class="taC" width="150">结算方式</th><td colspan="3">培训班(<a href="/invoiceTrainingDetail/' . $detail ['invoiceTraining'] ['trainingKey'] . '.html" target="_blank">' . $detail ['invoiceTraining'] ['trainName'] . '</a>)</td>
  6002. </tr>';
  6003. else
  6004. $html .= '<tr>
  6005. <th class="taC" width="150">结算方式</th><td colspan="3">软件销售</td>
  6006. </tr>';
  6007. $html .= ' </tbody></table>';
  6008. if ($detail ['invoiceType'] == 0){
  6009. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6010. <tr><th colspan="4" class="taC">增值税普通发票';
  6011. if($detail ['invoiceForm']==1){
  6012. $html .= '( <span class="colRed">电子发票</span> )';
  6013. }
  6014. $html .= '</th></tr><tr>
  6015. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  6016. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  6017. </tr>';
  6018. }else{
  6019. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6020. <tr><th colspan="4" class="taC">增值税专用发票';
  6021. if($detail ['invoiceForm']==1){
  6022. $html .= '( <span class="colRed">电子发票</span> )';
  6023. }
  6024. $html .= '</th></tr><tr>
  6025. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  6026. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  6027. ';
  6028. }
  6029. $html .= '<tr>
  6030. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  6031. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  6032. </tr>
  6033. <tr>
  6034. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  6035. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  6036. </tr></tbody></table>';
  6037. if ($detail ['doPost'] == 1) {
  6038. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  6039. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  6040. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  6041. </tr><tr>
  6042. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  6043. </tr><tr>
  6044. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  6045. </tr>
  6046. ';
  6047. if ($detail ['expressCom'] == 'SF')
  6048. $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>';
  6049. else
  6050. $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>';
  6051. $html .= '</tbody></table>';
  6052. }
  6053. if (! empty ( $invoiceOperationLogList )) {
  6054. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  6055. foreach ( $invoiceOperationLogList as $key => $value ) {
  6056. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  6057. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  6058. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  6059. if ($value ['status'] == 2) {
  6060. $html .= '<span class="colGreen">同意</span>';
  6061. } elseif ($value ['status'] == 3) {
  6062. $html .= '<span class="colOrange">退回</span>';
  6063. } elseif ($value ['status'] == 5) {
  6064. $html .= '<span class="colGreen">打印</span>';
  6065. } elseif ($value ['status'] == 4) {
  6066. $html .= '<span class="colRed">终止</span>';
  6067. }
  6068. $html .= $value ['operation'] . '</p></blockquote>';
  6069. }
  6070. }
  6071. $html .= '</td></tr></tbody></table>';
  6072. }
  6073. $html .= '</div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  6074. }
  6075. echo json_encode ( array (
  6076. 'status' => 1,
  6077. 'html' => $html
  6078. ) );
  6079. die ();
  6080. } elseif ($type == 'RECEIVABLES') {
  6081. Doo::loadModel ( 'invoiceReceivables' );
  6082. $invoiceReceivables = new invoiceReceivables ();
  6083. Doo::loadModel ( 'invoiceRefund' );
  6084. $invoiceRefund = new invoiceRefund ();
  6085. $detail = $invoiceReceivables->getInvoiceReceivablesByIrsid ( $serial );
  6086. $ireList = $invoiceRefund->getInvoiceRefundIrid ( $detail ['irid'] );
  6087. if (empty ( $detail ))
  6088. $html = '';
  6089. else {
  6090. $html = '<div class="modal-dialog modal-lg"><div class="modal-content"><div class="modal-header"><h3>收款单详情</h3></div><div class="modal-body saeaList">
  6091. <table class="table table-bordered table-condensed">
  6092. <tbody><tr>
  6093. <th class="taC">收款流水号</th><td>' . $detail ['receivablesSerial'] . '</td>
  6094. <th class="taC">录入收款</th><td>' . $detail ['inputStaff'] . ' ' . $detail ['date'] . '</td>
  6095. </tr><tr>
  6096. <th class="taC">收款金额</th><td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  6097. <th class="taC">收款信息</th><td>' . $detail ['receivablesMessage'] . '</td>
  6098. </tr>
  6099. <tr>
  6100. <th class="taC">收款银行</th><td>' . $detail ['receivablesBank'] . '</td>
  6101. <th class="taC">银行到账</th><td>' . $detail ['receivablesDate'] . '</td>
  6102. </tr>
  6103. <tr>
  6104. <th class="taC">认领收款</th><td colspan="3">' . $detail ['inputStaff'] . ' 转入 ' . $detail ['username'] . ' ' . $detail ['confirmTime'] . '</td>
  6105. </tr>
  6106. </tbody></table>';
  6107. if (! empty ( $ireList )) {
  6108. $html .= '
  6109. <table class="table table-bordered table-condensed"><tbody><tr><th class="taC" colspan="5">退款记录</th></tr>
  6110. <tr>
  6111. <th class="taC">退款单位名称</th>
  6112. <th class="taC">退款的账号</th>
  6113. <th class="taC">退款金额</th>
  6114. <th class="taC">退款</th>
  6115. <th class="taC">备注</th>
  6116. </tr>
  6117. ';
  6118. foreach ( $ireList as $key => $value ) {
  6119. $refundLogList = explode ( "<br/>", $value ['refundLog'] );
  6120. $html .= '<tr>
  6121. <td>' . $value ['refundCompany'] . '</td>
  6122. <td>' . $value ['refundNumber'] . '</td>
  6123. <td><b class="colRed">¥' . $value ['refundPrice'] . '</b></td>
  6124. <td>' . $refundLogList [0] . $refundLogList [2] . '</td>
  6125. <td>' . $value ['refundRemarks'] . '</td>
  6126. </tr>
  6127. ';
  6128. }
  6129. }
  6130. $html .= '</tbody></table></div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  6131. }
  6132. echo json_encode ( array (
  6133. 'status' => 1,
  6134. 'html' => $html
  6135. ) );
  6136. die ();
  6137. } elseif ($type == 'IRTC') {
  6138. Doo::loadModel ( 'invoice' );
  6139. $invoice = new invoice ();
  6140. Doo::loadModel ( 'invoiceOperationLog' );
  6141. $invoiceOperationLog = new invoiceOperationLog ();
  6142. // Doo::loadModel ( 'invoiceReceivables' );
  6143. // $invoiceReceivables = new invoiceReceivables ();
  6144. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  6145. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  6146. if (empty ( $detail ))
  6147. $html = '';
  6148. else {
  6149. $receivablesPriceedHtml = '';
  6150. $receivablesPrice = $detail ['invoicePrice'];
  6151. if (! empty ( $detail ['irid'] )) {
  6152. // $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $detail ['irid'] );
  6153. // if (empty ( $irList ))
  6154. // $irList [0] ['sumPrice'] = 0;
  6155. // $balance = $detail ['invoicePrice'] - $irList [0] ['sumPrice'];
  6156. $enteredPrice=$detail ['invoicePrice']-$detail ['invoiceBalance'];
  6157. $receivablesPriceedHtml = '<table class="table table-bordered table-condensed"><tbody><tr>
  6158. <th class="taC">已入账金额</th><td><b class="colGreen" style="font-size:18px">¥' . $enteredPrice . '</b></td>
  6159. <th class="taC">剩余入账金额</th><td><b class="colRed" style="font-size:18px">¥' . $detail ['invoiceBalance'] . '</b></td>
  6160. </tr></tbody></table>';
  6161. $receivablesPrice = $detail ['invoiceBalance'];
  6162. }
  6163. if ($loss)
  6164. $detail ['invoicePrice'] = - $detail ['invoicePrice'];
  6165. $html = $receivablesPriceedHtml . '
  6166. <table class="table table-bordered table-condensed"><tbody>
  6167. <tr>
  6168. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  6169. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  6170. </tr>
  6171. <tr>
  6172. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  6173. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  6174. </tr>
  6175. <tr>
  6176. <th class="taC" width="150">发票备注</th><td colspan="3">' . $detail ['remark'] . '</td>
  6177. </tr>
  6178. <tr>
  6179. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  6180. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  6181. </tr>
  6182. <tr>
  6183. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  6184. </tr></tbody></table>';
  6185. if ($detail ['invoiceType'] == 0) {
  6186. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6187. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  6188. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  6189. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  6190. </tr>';
  6191. $receivablesMessage = $detail ['invoiceTitle'];
  6192. } else {
  6193. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6194. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  6195. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  6196. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  6197. ';
  6198. $receivablesMessage = $detail ['invoiceCompany'];
  6199. }
  6200. $html .= '<tr>
  6201. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  6202. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  6203. </tr>
  6204. <tr>
  6205. <th class="taC">开户银行</th><td>' . $detail ['bankAccount'] . '</td>
  6206. <th class="taC">银行账号</th><td>' . $detail ['bank'] . '</td>
  6207. </tr></tbody></table>';
  6208. if ($detail ['doPost'] == 1)
  6209. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  6210. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  6211. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  6212. </tr><tr>
  6213. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  6214. </tr><tr>
  6215. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  6216. </tr></tbody></table>';
  6217. if (! empty ( $invoiceOperationLogList )) {
  6218. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  6219. foreach ( $invoiceOperationLogList as $key => $value ) {
  6220. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  6221. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  6222. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  6223. if ($value ['status'] == 2) {
  6224. $html .= '<span class="colGreen">同意</span>';
  6225. } elseif ($value ['status'] == 3) {
  6226. $html .= '<span class="colOrange">退回</span>';
  6227. } elseif ($value ['status'] == 5) {
  6228. $html .= '<span class="colGreen">打印</span>';
  6229. }
  6230. $html .= $value ['operation'] . '</p></blockquote>';
  6231. }
  6232. }
  6233. $html .= '</td></tr></tbody></table>';
  6234. }
  6235. }
  6236. echo json_encode ( array (
  6237. 'status' => 1,
  6238. 'html' => $html,
  6239. 'receivablesPrice' => $receivablesPrice,
  6240. 'receivablesMessage' => $receivablesMessage,
  6241. 'receivablesDate' => date ( "Y-m-d" ),
  6242. 'iidKey' => $serial
  6243. ) );
  6244. die ();
  6245. }
  6246. }
  6247. function ajaxGetInvoiceReceivablesByStaff() {
  6248. $postData = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : "";
  6249. if (empty ( $postData )) {
  6250. echo json_encode ( array (
  6251. 'status' => 2,
  6252. 'msg' => 'illegal request'
  6253. ) );
  6254. die ();
  6255. }
  6256. Doo::loadModel ( 'invoiceReceivables' );
  6257. $invoiceReceivables = new invoiceReceivables ();
  6258. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $postData );
  6259. if (empty ( $detail )) {
  6260. echo json_encode ( array (
  6261. 'status' => 2,
  6262. 'msg' => 'illegal request'
  6263. ) );
  6264. die ();
  6265. }
  6266. Doo::loadModel ( 'L_category' );
  6267. $lCategory = new L_category ();
  6268. Doo::loadModel ( 'staff' );
  6269. $staff = new staff ();
  6270. $staffList = $staff->getStaffByCid ( $detail ['cid'] );
  6271. $category = $lCategory->getCategory ();
  6272. $categoryHtml = '<option post-data="PUBLIC" value="PUBLIC" >公共待认领款项</option>';
  6273. $staffHtml = '<option value="PUBLIC">办事处待认领款项</option>';
  6274. foreach ( $category as $key => $value ) {
  6275. $categoryHtml .= '<option post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  6276. if ($value ['cid'] == $detail ['cid'])
  6277. $categoryHtml .= '<option selected post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  6278. }
  6279. foreach ( $staffList as $key => $value ) {
  6280. $staffHtml .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  6281. if ($value ['sid'] == $detail ['sid'])
  6282. $staffHtml .= '<option selected value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  6283. }
  6284. $rbankHtml = '<option value="广发银行珠海分行柠溪支行">广发银行珠海分行柠溪支行</option>';
  6285. echo json_encode ( array (
  6286. 'status' => 1,
  6287. 'categoryHtml' => $categoryHtml,
  6288. 'staffHtml' => $staffHtml,
  6289. 'rbankHtml' => $rbankHtml,
  6290. 'detail' => $detail
  6291. ) );
  6292. }
  6293. function ajaxGetInvoiceReceivablesByIrid() {
  6294. $irid = $this->get_args ( 'irid' ) ? $this->get_args ( 'irid' ) : "";
  6295. if (empty ( $irid )) {
  6296. echo json_encode ( array (
  6297. 'status' => 2,
  6298. 'msg' => 'illegal request'
  6299. ) );
  6300. die ();
  6301. }
  6302. Doo::loadModel ( 'invoiceReceivables' );
  6303. $invoiceReceivables = new invoiceReceivables ();
  6304. Doo::loadModel ( 'invoice' );
  6305. $invoice = new invoice ();
  6306. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid ); // 入账完成 待定 and postStatus=1
  6307. $flag = true;
  6308. $invoiceDetail = $invoice->getInvoiceByTitle ( $detail ['recepitTitleMark'], 'EXACTLY', " and status=2 and printStatus=1 and untreadStatus=0 ", $flag ); //
  6309. $bakDetail = array ();
  6310. if ($flag === false) {
  6311. array_push ( $bakDetail, $invoiceDetail );
  6312. $invoiceDetail = $bakDetail;
  6313. }
  6314. $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>
  6315. <tr>
  6316. <td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  6317. <td>' . $detail ['receivablesMessage'] . '</td>
  6318. <td>' . $detail ['receivablesBank'] . '<br>' . $detail ['receivablesDate'] . '</td>
  6319. <td>' . $detail ['title'] . '-' . $detail ['username'] . '<br>' . $detail ['confirmTime'] . '</td>
  6320. <td>' . $detail ['recepitTitleMark'] . '</td>
  6321. </tr></tbody></table>';
  6322. $isInvoice = false;
  6323. $invoiceHtml = '';
  6324. if (empty ( $invoiceDetail )) {
  6325. $isInvoice = true;
  6326. } else {
  6327. $invoiceHtml = '<table class="table table-bordered table-condensed">
  6328. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody>';
  6329. foreach ( $invoiceDetail as $key => $value ) {
  6330. $invoiceHtml .= '<tr>';
  6331. if (! empty ( $value ['invoiceType'] )) {
  6332. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  6333. } else {
  6334. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  6335. }
  6336. if (! empty ( $value ['invoiceType'] )) {
  6337. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  6338. } else {
  6339. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  6340. }
  6341. $invoiceHtml .= '
  6342. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  6343. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  6344. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir" data-ikey="' . $value ['iidKey'] . '" href="javascript:void(0)">入账</a></td>
  6345. </tr>
  6346. ';
  6347. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  6348. if (empty ( $irList ))
  6349. $irList [0] ['sumPrice'] = 0;
  6350. $balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  6351. $priceString = '';
  6352. if ($balance < $detail ['receivablesPrice']) {
  6353. $priceString = '收款金额超过开票金额,';
  6354. }
  6355. if ($balance > $detail ['receivablesPrice']) {
  6356. $priceString = '收款金额低于开票金额,';
  6357. }
  6358. }
  6359. $invoiceHtml .= '
  6360. <script>
  6361. $(\'a[bind-receivables^="ir"]\').click(function() {
  6362. var data = $(this).attr("data-ikey");
  6363. $("input[name=\'invoiceKey\']").val(data);
  6364. var invoiceKey=data;
  6365. if(invoiceKey==""){
  6366. alert("入账错误,请重新刷新页面");
  6367. return false;
  6368. }
  6369. if(window.confirm("' . $priceString . '确定入账吗?")){
  6370. $("#IBR").submit();
  6371. }else{
  6372. return false;
  6373. }
  6374. });
  6375. </script>
  6376. ';
  6377. $invoiceHtml .= '</tbody></table>';
  6378. }
  6379. echo json_encode ( array (
  6380. 'status' => 1,
  6381. 'irkey' => $detail ['iridEn'],
  6382. 'receivablesHtml' => $receivablesHtml,
  6383. 'isInvoice' => $isInvoice,
  6384. 'invoiceHtml' => $invoiceHtml
  6385. ) );
  6386. }
  6387. function ajaxGetInvoiceReceivablesByTitle() {
  6388. $title = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  6389. if (empty ( $title )) {
  6390. echo json_encode ( array (
  6391. 'status' => 2,
  6392. 'msg' => 'illegal request'
  6393. ) );
  6394. die ();
  6395. }
  6396. Doo::loadModel ( 'invoice' );
  6397. $invoice = new invoice ();
  6398. $invoiceDetail = $invoice->getInvoiceByTitle ( $title, 'FUZZY', " and status=2 and printStatus=1 and untreadStatus=0 and (irid='' or irid is null) ", true );
  6399. $invoiceHtml = '';
  6400. if (! empty ( $invoiceDetail )) {
  6401. $invoiceHtml = '<table class="table table-bordered table-condensed">
  6402. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody><tr>';
  6403. foreach ( $invoiceDetail as $key => $value ) {
  6404. if (! empty ( $value ['invoiceType'] )) {
  6405. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  6406. } else {
  6407. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  6408. }
  6409. if (! empty ( $value ['invoiceType'] )) {
  6410. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  6411. } else {
  6412. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  6413. }
  6414. $invoiceHtml .= '
  6415. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  6416. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  6417. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir' . $value ['iidKeyXD'] . '" data-ikey="' . $value ['iidKey'] . '" href="#">入账</a></td>
  6418. </tr>
  6419. ';
  6420. }
  6421. $invoiceHtml .= '</tbody></table>
  6422. <script>
  6423. $(\'a[bind-receivables^="ir"]\').click(function() {
  6424. var data = $(this).attr("data-ikey");
  6425. $("input[name=\'invoiceKey\']").val(data);
  6426. var invoiceKey=$("input[name=\'invoiceKey\']").val();
  6427. if(invoiceKey==""){
  6428. alert("入账错误,请重新刷新页面");
  6429. return false;
  6430. }
  6431. if(window.confirm("确定入账吗?")){
  6432. $("#IBR").submit();
  6433. }else{
  6434. return false;
  6435. }
  6436. });
  6437. </script>
  6438. ';
  6439. }
  6440. echo json_encode ( array (
  6441. 'status' => 1,
  6442. 'invoiceHtml' => $invoiceHtml
  6443. ) );
  6444. }
  6445. function ajaxInvoicePushNotice() {
  6446. Doo::loadModel ( 'invoice' );
  6447. $invoice = new invoice ();
  6448. $approval = $invoice->getOne ( array (
  6449. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  6450. 'desc' => 'iid',
  6451. 'asArray' => true
  6452. ) );
  6453. $isNotice = false;
  6454. if (! empty ( $approval ))
  6455. $isNotice = true;
  6456. $response = array (
  6457. 'error' => 0,
  6458. 'isNotice' => $isNotice
  6459. );
  6460. echo json_encode ( $response );
  6461. exit ();
  6462. }
  6463. public function ajaxCheckInvoiceNoUniqueness() {
  6464. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  6465. Doo::loadModel ( 'invoice' );
  6466. $invoice = new invoice ();
  6467. if (! empty ( $invoiceNo )) {
  6468. Doo::loadModel ( 'invoicePaper' );
  6469. $invoicePaper = new invoicePaper ();
  6470. Doo::loadClass ( 'XDeode' );
  6471. $XDeode = new XDeode ( 5 );
  6472. $ipid = $XDeode->decode ( $invoiceNo );
  6473. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  6474. $info = $invoice->getOne ( array (
  6475. 'where' => "invoiceNo = '" . $paperDetail ['invoiceNo'] . "'",
  6476. 'asArray' => TRUE
  6477. ) );
  6478. if (! empty ( $info )) {
  6479. echo json_encode ( array (
  6480. 'error' => '发票号已存在'
  6481. ) );
  6482. die ();
  6483. } else
  6484. echo json_encode ( array (
  6485. 'ok' => '可以使用!'
  6486. ) );
  6487. die ();
  6488. }
  6489. }
  6490. function ajaxCheckInvoicePrice() {
  6491. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) && is_numeric ( $this->get_args ( 'receivablesPrice' ) ) ? $this->get_args ( 'receivablesPrice' ) : "";
  6492. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  6493. Doo::loadModel ( 'invoice' );
  6494. $invoice = new invoice ();
  6495. Doo::loadModel ( 'invoiceReceivables' );
  6496. $invoiceReceivables = new invoiceReceivables ();
  6497. Doo::loadClass ( 'XDeode' );
  6498. $XDeode = new XDeode ( 5 );
  6499. if (! empty ( $receivablesPrice ) && ! empty ( $iidKey )) {
  6500. $iidKey = $XDeode->decode ( $iidKey );
  6501. $info = $invoice->getInvoiceByIid ( $iidKey );
  6502. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $info ['irid'] );
  6503. if (empty ( $irList ))
  6504. $irList [0] ['sumPrice'] = 0;
  6505. $balance = $info ['invoicePrice'] - $irList [0] ['sumPrice'];
  6506. if ($balance < $receivablesPrice) {
  6507. echo json_encode ( array (
  6508. 'error' => '收款金额超过开票金额。'
  6509. ) );
  6510. die ();
  6511. }
  6512. if ($balance > $receivablesPrice) {
  6513. echo json_encode ( array (
  6514. 'error' => '收款金额低于开票金额。'
  6515. ) );
  6516. die ();
  6517. }
  6518. }
  6519. }
  6520. function ajaxGetInvoiceByNew() {
  6521. Doo::loadModel ( 'invoice' );
  6522. $invoice = new invoice ();
  6523. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );
  6524. echo json_encode ( array (
  6525. 'status' => 1,
  6526. 'detail' => $detail
  6527. ) );
  6528. }
  6529. /**
  6530. * 旧输入导入
  6531. */
  6532. function importInvoice() {
  6533. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  6534. $data ['emsg'] = "";
  6535. if ($emsg != "")
  6536. $data ['emsg'] = "请填写完整的数据";
  6537. $data ['time'] = time ();
  6538. $this->render ( "/admin/invoiceImport", $data );
  6539. }
  6540. function uploadInvoice() {
  6541. // move_uploaded_file($_FILES['Filedata']['tmp_name'], "/upload/".$_FILES['Filedata']['name']);
  6542. if (isset ( $_FILES ['Filedata'] ['name'] )) {
  6543. $file = $_FILES ['Filedata'] ['tmp_name'];
  6544. $error = false;
  6545. if (! is_uploaded_file ( $file )) {
  6546. $error = '400 Bad Request';
  6547. }
  6548. if ($error) {
  6549. header ( 'HTTP/1.0 ' . $error );
  6550. die ( 'Error ' . $error );
  6551. } else {
  6552. include (DOO::conf ()->SITE_PATH . 'protected/plugin/io.han.php');
  6553. $this->IoHandler = new IoHandler ();
  6554. $pics = explode ( '.', $_FILES ['Filedata'] ['name'] );
  6555. // $filedir=$_POST['time'];
  6556. // 调用定义物理路径
  6557. $t = DOO::conf ()->SITE_PATH . "upload/invoice/";
  6558. $this->IoHandler->MakeDir ( $t );
  6559. $filename = $this->_GetFileEXT ( $_FILES ['Filedata'] ['name'] );
  6560. if ($filename != 'xlsx')
  6561. return "";
  6562. // $upload_dir = $t."/".time().rand(10,100).".".$filename;
  6563. $upload_file = iconv ( "UTF-8", "GB2312", $_FILES ["Filedata"] ["name"] );
  6564. $upload_dir = $t . "/" . $upload_file;
  6565. $k = move_uploaded_file ( $file, $upload_dir );
  6566. if ($k) {
  6567. $m = round ( $_FILES ['Filedata'] ['size'] / 1024 / 1024, 2 );
  6568. echo $pics [0] . "." . $filename . "#" . $m . "#" . $_FILES ['Filedata'] ['size'];
  6569. }
  6570. }
  6571. }
  6572. }
  6573. function importInvoiceDo() {
  6574. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  6575. if ($path != "") {
  6576. Doo::loadModel ( 'invoice' );
  6577. Doo::loadModel ( 'staff' );
  6578. $staff = new staff ();
  6579. Doo::loadModel ( 'invoiceStatistics' );
  6580. Doo::loadModel ( 'invoiceOperationLog' );
  6581. echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  6582. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . $path );
  6583. // print_r ( $exlArray );
  6584. // die ();
  6585. // echo json_encode($exlArray);die;
  6586. foreach ( $exlArray as $key => $value ) {
  6587. // 开票
  6588. $invoice = new invoice ();
  6589. $invoice->invoiceNo = $value ['invoiceNo'];
  6590. $invoice->invoiceType = 0;
  6591. if ($value ['invoiceType'] == '专')
  6592. $invoice->invoiceType = 1;
  6593. $invoice->invoicePrice = $value ['invoicePrice'];
  6594. $invoice->invoiceQuantity = 1;
  6595. $invoice->invoiceUnitPrice = $value ['invoicePrice'];
  6596. $invoice->invoiceTitle = $value ['invoiceTitle'];
  6597. if ($value ['invoiceType'] == '专')
  6598. $invoice->invoiceCompany = $value ['invoiceTitle'];
  6599. $invoice->userName = $value ['userName'];
  6600. $sDetail = $staff->getStaffByName ( $value ['userName'] );
  6601. $invoice->sid = $sDetail ['sid'];
  6602. $invoice->cid = $sDetail ['cid'];
  6603. $invoice->categoryName = $sDetail ['category'];
  6604. $invoice->invoiceElement = $value ['invoiceElement'];
  6605. $invoice->remark = $value ['remark'];
  6606. $invoice->date = $value ['date'];
  6607. $invoice->printTime = $value ['date'];
  6608. $invoice->ipSource = 1;
  6609. $invoice->printStatus = 1;
  6610. $invoice->status = 2;
  6611. $invoice->postStatus = 1;
  6612. $invoice->untreadStatus = 0;
  6613. $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  6614. $iid = $invoice->insert ();
  6615. // 汇总
  6616. $invoiceStatistics = new invoiceStatistics ();
  6617. //
  6618. $item = array (
  6619. 'date' => $value ['date'],
  6620. 'priceClass' => 1,
  6621. 'cid' => $sDetail ['cid'],
  6622. 'staff' => $sDetail ['sid'],
  6623. 'invoicePrice' => $value ['invoicePrice']
  6624. );
  6625. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  6626. $invoiceOperationLog = new invoiceOperationLog ();
  6627. $item = array (
  6628. 'date' => date ( "Y-m-d H:i:s" ),
  6629. 'operation' => date ( "Y-m-d" ) . " 导入",
  6630. 'status' => 1,
  6631. 'img' => $sDetail ['avatar'],
  6632. 'username' => $sDetail ['username'],
  6633. 'uid' => $sDetail ['sid'],
  6634. 'category' => $sDetail ['category'],
  6635. 'iid' => $iid
  6636. );
  6637. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  6638. }
  6639. return '/importInvoice?count=' . count ( $exlArray );
  6640. // return "/keyonline";
  6641. }
  6642. echo 'no file';
  6643. }
  6644. function importInvoiceReceivables() {
  6645. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  6646. $data ['emsg'] = "";
  6647. if ($emsg != "")
  6648. $data ['emsg'] = "请填写完整的数据";
  6649. $data ['time'] = time ();
  6650. $this->render ( "/admin/invoiceReceivablesImport", $data );
  6651. }
  6652. // 导入入账数据
  6653. function importInvoiceReceivablesDo() {
  6654. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  6655. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  6656. if ($path != "") {
  6657. Doo::loadModel ( 'invoiceReceivables' );
  6658. Doo::loadModel ( 'invoice' );
  6659. Doo::loadModel ( 'staff' );
  6660. $staff = new staff ();
  6661. Doo::loadModel ( 'invoiceStatistics' );
  6662. // echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  6663. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path ), 'invoiceReceivables' );
  6664. // print_r ( $exlArray );
  6665. // die ();
  6666. // echo json_encode($exlArray);die;
  6667. foreach ( $exlArray as $key => $value ) {
  6668. // 收款
  6669. $invoiceReceivables = new invoiceReceivables ();
  6670. $invoice = new invoice ();
  6671. $invoiceReceivables->bindStatus = 1;
  6672. $invoiceReceivables->receivablesPrice = $value ['receivablesPrice'];
  6673. $invoiceReceivables->receivablesMessage = $value ['receivablesMessage'];
  6674. $invoiceReceivables->receivablesBank = $value ['receivablesBank'];
  6675. $invoiceReceivables->receivablesDate = $value ['receivablesDate'];
  6676. $sDetail = $staff->getStaffByName ( $value ['receivablesStaff'] );
  6677. $invoiceReceivables->receivablesCategory = $sDetail ['cid'] . ':' . $sDetail ['category'];
  6678. $invoiceReceivables->receivablesStaff = $sDetail ['sid'] . '-' . $sDetail ['username'];
  6679. $invoiceReceivables->receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  6680. $invoiceReceivables->sourcePrice = $value ['sourcePrice'];
  6681. $iDetail = $invoice->getInvoiceByInvoiceNo ( $value ['invoiceNo'] );
  6682. $invoiceReceivables->iid = $iDetail ['iid'];
  6683. $irid = $invoiceReceivables->insert ();
  6684. // 发票绑定收款
  6685. $detail = $iDetail;
  6686. $iridString = "";
  6687. if (empty ( $detail ['irid'] ))
  6688. $iridString = $irid;
  6689. else
  6690. $iridString = $detail ['irid'] . ',' . $irid;
  6691. $item = array (
  6692. 'irid' => $iridString,
  6693. 'iid' => $detail ['iid']
  6694. );
  6695. $invoice->setInvoiceByCondition ( $item );
  6696. // 汇总
  6697. $invoiceStatistics = new invoiceStatistics ();
  6698. // 扣除入账统计金额
  6699. $item = array (
  6700. 'date' => $value ['receivablesDate'],
  6701. 'priceClass' => 3,
  6702. 'cid' => $sDetail ['cid'],
  6703. 'staff' => $sDetail ['sid'],
  6704. // 'irid' => $irid,
  6705. 'accountPrice' => $value ['receivablesPrice']
  6706. );
  6707. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  6708. }
  6709. return '/importInvoiceReceivables?count=' . count ( $exlArray );
  6710. echo 'data count ' . count ( $exlArray );
  6711. die ();
  6712. // return "/keyonline";
  6713. }
  6714. echo 'no file';
  6715. }
  6716. function formatExcelToArrayTrain($file_url = "") {
  6717. if (! file_exists ( $file_url )) {
  6718. return array ();
  6719. }
  6720. // Doo::loadClass ( 'PHPExcel' );
  6721. Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  6722. $PHPExcel = new PHPExcel ();
  6723. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  6724. if (! $PHPReader->canRead ( $file_url )) {
  6725. $PHPReader = new PHPExcel_Reader_Excel5 ();
  6726. if (! $PHPReader->canRead ( $file_url )) {
  6727. echo 'no Excel';
  6728. return;
  6729. }
  6730. }
  6731. $PHPExcel = $PHPReader->load ( $file_url );
  6732. /* * 读取excel文件中的第一个工作表 */
  6733. $currentSheet = $PHPExcel->getSheet ( 0 );
  6734. /* * 取得最大的列号 */
  6735. $allColumn = $currentSheet->getHighestColumn ();
  6736. /* * 取得一共有多少行 */
  6737. $allRow = $currentSheet->getHighestRow ();
  6738. $excel_array = array ();
  6739. // die($file_url);
  6740. $conk = 2;
  6741. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  6742. $excel_column = array ();
  6743. // 后期改进
  6744. if ($allColumn == 'AM')
  6745. $allColumn = 'Z';
  6746. /* * 从第A列开始输出 */
  6747. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  6748. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  6749. if ($val instanceof PHPExcel_RichText)
  6750. $val = $val->__toString ();
  6751. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  6752. // $val = "'" . addslashes ( $val ) . "'";
  6753. if ($currentColumn == 'A') {
  6754. $excel_column ['invoiceTitle'] = $val;
  6755. } elseif ($currentColumn == 'B')
  6756. $excel_column ['invoiceType'] = $val;
  6757. elseif ($currentColumn == 'C') {
  6758. $excel_column ['TIN'] = $val;
  6759. } elseif ($currentColumn == 'D') {
  6760. $excel_column ['address'] = $val;
  6761. } elseif ($currentColumn == 'E') {
  6762. $excel_column ['phone'] = $val;
  6763. } elseif ($currentColumn == 'F') {
  6764. $excel_column ['bank'] = $val;
  6765. } elseif ($currentColumn == 'G') {
  6766. $excel_column ['bankAccount'] = $val;
  6767. } elseif ($currentColumn == 'H') {
  6768. $excel_column ['invoiceElement'] = $val;
  6769. } elseif ($currentColumn == 'I') {
  6770. $excel_column ['invoiceQuantity'] = $val;
  6771. } elseif ($currentColumn == 'J') {
  6772. $excel_column ['invoiceUnitPrice'] = $val;
  6773. } elseif ($currentColumn == 'K') {
  6774. $excel_column ['remark'] = $val;
  6775. } elseif ($currentColumn == 'L') {
  6776. $excel_column ['recipientsAddress'] = $val;
  6777. } elseif ($currentColumn == 'M') {
  6778. $excel_column ['recipients'] = $val;
  6779. } elseif ($currentColumn == 'N') {
  6780. $excel_column ['recipientsPhone'] = $val;
  6781. }
  6782. }
  6783. if (! empty ( $excel_column ['invoiceTitle'] ) && ! empty ( $excel_column ['invoiceQuantity'] ) && ! empty ( $excel_column ['invoiceUnitPrice'] ))
  6784. array_push ( $excel_array, $excel_column );
  6785. }
  6786. return $excel_array;
  6787. }
  6788. /**
  6789. * 格式化excel文件为数组
  6790. * @param unknown_type $file_url
  6791. * @param unknown_type $mcid
  6792. */
  6793. function _format_excel_to_array($file_url = "", $sType = "") {
  6794. if (! file_exists ( $file_url )) {
  6795. return array ();
  6796. }
  6797. Doo::loadClass ( 'PHPExcel' );
  6798. // Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  6799. $PHPExcel = new PHPExcel ();
  6800. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  6801. if (! $PHPReader->canRead ( $file_url )) {
  6802. $PHPReader = new PHPExcel_Reader_Excel5 ();
  6803. if (! $PHPReader->canRead ( $file_url )) {
  6804. echo 'no Excel';
  6805. return;
  6806. }
  6807. }
  6808. $PHPExcel = $PHPReader->load ( $file_url );
  6809. /* * 读取excel文件中的第一个工作表 */
  6810. $currentSheet = $PHPExcel->getSheet ( 0 );
  6811. /* * 取得最大的列号 */
  6812. $allColumn = $currentSheet->getHighestColumn ();
  6813. /* * 取得一共有多少行 */
  6814. $allRow = $currentSheet->getHighestRow ();
  6815. $excel_array = array ();
  6816. // die($file_url);
  6817. $conk = 2;
  6818. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  6819. $excel_column = array ();
  6820. // 后期改进
  6821. if ($allColumn == 'AM')
  6822. $allColumn = 'Z';
  6823. /* * 从第A列开始输出 */
  6824. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  6825. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  6826. if ($val instanceof PHPExcel_RichText)
  6827. $val = $val->__toString ();
  6828. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  6829. // $val = "'" . addslashes ( $val ) . "'";
  6830. if ($sType == 'invoiceReceivables') {
  6831. if ($currentColumn == 'A')
  6832. $excel_column ['invoiceNo'] = $val;
  6833. elseif ($currentColumn == 'B')
  6834. $excel_column ['receivablesPrice'] = $val;
  6835. elseif ($currentColumn == 'C') {
  6836. $excel_column ['receivablesMessage'] = $val;
  6837. } elseif ($currentColumn == 'D') {
  6838. $excel_column ['receivablesBank'] = $val;
  6839. } elseif ($currentColumn == 'E') {
  6840. $excel_column ['receivablesDate'] = $this->excelTime ( $val );
  6841. } elseif ($currentColumn == 'F') {
  6842. $excel_column ['receivablesStaff'] = $val;
  6843. } elseif ($currentColumn == 'G') {
  6844. $excel_column ['sourcePrice'] = $val;
  6845. }
  6846. } elseif ($sType == "invoiceTrain") {
  6847. if ($currentColumn == 'A') {
  6848. $excel_column ['invoiceTitle'] = $val;
  6849. } elseif ($currentColumn == 'B')
  6850. $excel_column ['invoiceType'] = $val;
  6851. elseif ($currentColumn == 'C') {
  6852. $excel_column ['TIN'] = $val;
  6853. } elseif ($currentColumn == 'D') {
  6854. $excel_column ['address'] = $val;
  6855. } elseif ($currentColumn == 'E') {
  6856. $excel_column ['phone'] = $val;
  6857. } elseif ($currentColumn == 'F') {
  6858. $excel_column ['bank'] = $val;
  6859. } elseif ($currentColumn == 'G') {
  6860. $excel_column ['bankAccount'] = $val;
  6861. } elseif ($currentColumn == 'H') {
  6862. $excel_column ['invoiceElement'] = $val;
  6863. } elseif ($currentColumn == 'I') {
  6864. $excel_column ['invoiceQuantity'] = $val;
  6865. } elseif ($currentColumn == 'J') {
  6866. $excel_column ['invoiceUnitPrice'] = $val;
  6867. } elseif ($currentColumn == 'K') {
  6868. $excel_column ['remark'] = $val;
  6869. } elseif ($currentColumn == 'L') {
  6870. $excel_column ['recipientsAddress'] = $val;
  6871. } elseif ($currentColumn == 'M') {
  6872. $excel_column ['recipients'] = $val;
  6873. } elseif ($currentColumn == 'N') {
  6874. $excel_column ['recipientsPhone'] = $val;
  6875. }
  6876. } else {
  6877. if ($currentColumn == 'A')
  6878. $excel_column ['invoiceNo'] = $val;
  6879. elseif ($currentColumn == 'B')
  6880. $excel_column ['invoiceType'] = $val;
  6881. elseif ($currentColumn == 'C') {
  6882. $excel_column ['invoicePrice'] = $val;
  6883. } elseif ($currentColumn == 'D') {
  6884. $excel_column ['invoiceTitle'] = $val;
  6885. } elseif ($currentColumn == 'E') {
  6886. $excel_column ['userName'] = $val;
  6887. } elseif ($currentColumn == 'F') {
  6888. $excel_column ['categoryName'] = $val;
  6889. } elseif ($currentColumn == 'G') {
  6890. $excel_column ['invoiceElement'] = $val;
  6891. } elseif ($currentColumn == 'H') {
  6892. $excel_column ['remark'] = $val;
  6893. } elseif ($currentColumn == 'I') {
  6894. $excel_column ['date'] = $this->excelTime ( $val );
  6895. }
  6896. }
  6897. }
  6898. array_push ( $excel_array, $excel_column );
  6899. }
  6900. return $excel_array;
  6901. }
  6902. function excelTime($date, $time = false) {
  6903. if (function_exists ( 'GregorianToJD' )) {
  6904. if (is_numeric ( $date )) {
  6905. $jd = GregorianToJD ( 1, 1, 1970 );
  6906. $gregorian = JDToGregorian ( $jd + intval ( $date ) - 25569 );
  6907. $date = explode ( '/', $gregorian );
  6908. $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" : '');
  6909. return $date_str;
  6910. }
  6911. } else {
  6912. $date = $date > 25568 ? $date + 1 : 25569;
  6913. /* There was a bug if Converting date before 1-1-1970 (tstamp 0) */
  6914. $ofs = (70 * 365 + 17 + 2) * 86400;
  6915. $date = date ( "Y-m-d", ($date * 86400) - $ofs ) . ($time ? " 00:00:00" : '');
  6916. }
  6917. return $date;
  6918. }
  6919. /**
  6920. * 旧输入导入
  6921. */
  6922. function _GetFileEXT($filename) {
  6923. $pics = explode ( '.', $filename );
  6924. $num = count ( $pics );
  6925. return $pics [$num - 1];
  6926. }
  6927. function showCache($path = "", $sid = 0) {
  6928. // if (file_exists ( $path )) {
  6929. // $htm = file_get_contents ( $path );
  6930. // } else {
  6931. Doo::loadModel ( 'invoiceStatistics' );
  6932. $invoiceStatistics = new invoiceStatistics ();
  6933. $isBriefly = $invoiceStatistics->getBrieflyStatistics ( $sid );
  6934. $htm = '<tr><th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计开票</th>
  6935. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['invoicePrice'] . '</td>
  6936. <th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计入账</th>
  6937. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['accountPrice'] . '</td></tr>';
  6938. /*
  6939. * '<tr><th class="taC">今年累计开票</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['invoicePrice'] . '</td> <th class="taC">今年累计入账</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['accountPrice'] . '</td></tr>';
  6940. */
  6941. file_put_contents ( $path, $htm );
  6942. // }
  6943. return $htm;
  6944. }
  6945. /**
  6946. * 生成token
  6947. * @return string
  6948. */
  6949. function set_token() {
  6950. $str = md5 ( uniqid ( md5 ( microtime ( true ) ), true ) ); // 生成一个不会重复的字符串
  6951. $str = sha1 ( $str ); // 加密
  6952. return $str;
  6953. }
  6954. /**
  6955. * 获取get或者POST值
  6956. *
  6957. * @param string $name 属性名称
  6958. * @return fixed 值
  6959. */
  6960. function get_args($name) {
  6961. if (isset ( $_GET [$name] )) {
  6962. if (is_array ( $_GET [$name] ))
  6963. return $_GET [$name];
  6964. else
  6965. return addslashes ( $_GET [$name] );
  6966. } elseif (isset ( $_POST [$name] )) {
  6967. if (is_array ( $_POST [$name] ))
  6968. return $_POST [$name];
  6969. else
  6970. return addslashes ( $_POST [$name] );
  6971. } else
  6972. return false;
  6973. }
  6974. function SafeFilter(&$arr) {
  6975. $ra = Array (
  6976. '/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/',
  6977. '/script/',
  6978. '/javascript/',
  6979. '/vbscript/',
  6980. '/expression/',
  6981. '/applet/',
  6982. '/meta/',
  6983. '/xml/',
  6984. '/blink/',
  6985. '/link/',
  6986. '/style/',
  6987. '/embed/',
  6988. '/object/',
  6989. '/frame/',
  6990. '/layer/',
  6991. '/title/',
  6992. '/bgsound/',
  6993. '/base/',
  6994. '/onload/',
  6995. '/onunload/',
  6996. '/onchange/',
  6997. '/onsubmit/',
  6998. '/onreset/',
  6999. '/onselect/',
  7000. '/onblur/',
  7001. '/onfocus/',
  7002. '/onabort/',
  7003. '/onkeydown/',
  7004. '/onkeypress/',
  7005. '/onkeyup/',
  7006. '/onclick/',
  7007. '/ondblclick/',
  7008. '/onmousedown/',
  7009. '/onmousemove/',
  7010. '/onmouseout/',
  7011. '/onmouseover/',
  7012. '/onmouseup/',
  7013. '/onunload/'
  7014. );
  7015. if (is_array ( $arr )) {
  7016. foreach ( $arr as $key => $value ) {
  7017. if (! is_array ( $value )) {
  7018. if (! get_magic_quotes_gpc ()) // 不对magic_quotes_gpc转义过的字符使用addslashes(),避免双重转义。
  7019. {
  7020. $value = addslashes ( $value ); // 给单引号(')、双引号(")、反斜线(\)与 NUL(NULL 字符)加上反斜线转义
  7021. }
  7022. $value = preg_replace ( $ra, '', $value ); // 删除非打印字符,粗暴式过滤xss可疑字符串
  7023. $arr [$key] = htmlentities ( strip_tags ( $value ) ); // 去除 HTML 和 PHP 标记并转换为 HTML 实体
  7024. } else {
  7025. SafeFilter ( $arr [$key] );
  7026. }
  7027. }
  7028. }
  7029. }
  7030. /**
  7031. * Escape String
  7032. *
  7033. * @access public
  7034. * @param string
  7035. * @param bool whether or not the string will be used in a LIKE condition
  7036. * @return string
  7037. */
  7038. function escape_str($str, $like = FALSE) {
  7039. if (is_array ( $str )) {
  7040. foreach ( $str as $key => $val ) {
  7041. $str [$key] = $this->escape_str ( $val, $like );
  7042. }
  7043. return $str;
  7044. }
  7045. var_dump ( Doo::db ()->getDbObject () );
  7046. die ();
  7047. if (function_exists ( 'mysql_real_escape_string' ) and is_resource ( Doo::db ()->getDbObject () )) { // Doo::db ()->getDbObject()
  7048. $str = mysql_real_escape_string ( $str, Doo::db ()->getDbObject () );
  7049. } elseif (function_exists ( 'mysql_escape_string' )) {
  7050. $str = mysql_escape_string ( $str );
  7051. } else {
  7052. $str = addslashes ( $str );
  7053. }
  7054. // escape LIKE condition wildcards
  7055. if ($like === TRUE) {
  7056. $str = str_replace ( array (
  7057. '%',
  7058. '_'
  7059. ), array (
  7060. '\\%',
  7061. '\\_'
  7062. ), $str );
  7063. }
  7064. return $str;
  7065. }
  7066. /**
  7067. * 获得分页数据
  7068. * @param unknown_type $table
  7069. * @param unknown_type $condition
  7070. * @param unknown_type $on_page
  7071. * @param unknown_type $page_size
  7072. */
  7073. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  7074. $page_c = "";
  7075. $page ['previous'] = $this->get_previous ( $on_page );
  7076. $page ['on_page'] = $on_page;
  7077. $total_count = $this->get_table_count ( $table, $condition );
  7078. $total = intval ( $total_count / $page_size );
  7079. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  7080. $page ['total_data'] = $total_count;
  7081. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  7082. $i = 1;
  7083. $page_max = 1;
  7084. $page_width = 3;
  7085. if ($on_page >= $page_width) {
  7086. $page_max = intval ( $on_page / $page_width ) + 1;
  7087. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  7088. }
  7089. for(; $i <= $page ['total_page']; $i ++) {
  7090. if ($i == $on_page)
  7091. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  7092. else
  7093. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  7094. if ($i == ($page_width * $page_max))
  7095. break;
  7096. }
  7097. $page ['page'] = $page_c;
  7098. $page ['lower'] = (-- $on_page) * $page_size;
  7099. return $page;
  7100. }
  7101. /**
  7102. * 获取上一页
  7103. * @param unknown_type $on_page
  7104. */
  7105. function get_previous($on_page = 1) {
  7106. return $on_page != 0 ? $on_page - 1 : $on_page;
  7107. }
  7108. /**
  7109. * 获取总页数
  7110. * @param unknown_type $table
  7111. * @param unknown_type $condition
  7112. */
  7113. public function get_table_count($table = "", $condition = "") {
  7114. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  7115. $sql = "select count(*) as count from " . $table . " where " . $condition;
  7116. // echo $sql;die;
  7117. $query = Doo::db ()->query ( $sql );
  7118. $result = $query->fetch ();
  7119. return $result ['count'];
  7120. }
  7121. function isInvoiceNew($type = "GLOBAL") {
  7122. Doo::loadModel ( 'invoice' );
  7123. $invoice = new invoice ();
  7124. Doo::loadModel ( 'invoiceReceivables' );
  7125. $invoiceReceivables = new invoiceReceivables ();
  7126. Doo::loadModel ( 'staff' );
  7127. $staff = new staff ();
  7128. $st = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  7129. // 我的发票待处理
  7130. $pendingInvoice = $invoice->getOne ( array ( // or (status=2 and printStatus=1 and untreadStatus=0 ) or (status=2 and printStatus=1 and untreadStatus=2 )
  7131. 'where' => "(status=3 or status=4) and isDelete=0 and sid=" . $st [0] ['sid'],
  7132. 'desc' => 'iid',
  7133. 'asArray' => TRUE
  7134. ) );
  7135. // 我的收款待入账
  7136. /*
  7137. * $myClaim = $invoiceReceivables->getOne ( array ( 'where' => " receivablesStaff like '" . $st [0] ['sid'] . "-%' and receivablesCategory like '" . $st [0] ['cid'] . ":%' and bindStatus=0", 'desc' => 'irid', 'asArray' => TRUE ) );
  7138. */
  7139. // 发票审批
  7140. $approval = $invoice->getOne ( array (
  7141. 'where' => 'status=1 and pendingApprovals=' . $st [0] ['sid'],
  7142. 'desc' => 'iid',
  7143. 'asArray' => true
  7144. ) );
  7145. // 发票邮寄
  7146. $post = $invoice->getOne ( array (
  7147. 'where' => "postStatus=0 and printStatus=1 and isDelete=0 and doPost=1 and status=2",
  7148. 'asArray' => TRUE
  7149. ) );
  7150. // 发票打印
  7151. $print = $invoice->getOne ( array (
  7152. 'where' => "status=2 and printStatus=0 and untreadStatus=0 and moldManage like '%[\"" . $st [0] ['sid'] . "\",%'",
  7153. 'desc' => 'iid',
  7154. 'asArray' => TRUE
  7155. ) );
  7156. // 发票退票 printStatus=1 and
  7157. $untread = $invoice->getOne ( array (
  7158. 'where' => " untreadStatus=1 and status=2 ",
  7159. 'asArray' => TRUE
  7160. ) );
  7161. $new = array (
  7162. 'GLOBAL' => FALSE,
  7163. 'pendingInvoice' => FALSE,
  7164. // 'myClaim' => FALSE,
  7165. 'approval' => FALSE,
  7166. 'post' => FALSE,
  7167. 'print' => FALSE,
  7168. 'untread' => FALSE
  7169. );
  7170. // || ! empty ( $myClaim )
  7171. if (! empty ( $pendingInvoice ) || ! empty ( $approval ) || ! empty ( $post ) || ! empty ( $print ) || ! empty ( $untread ))
  7172. $new ['GLOBAL'] = TRUE;
  7173. if (! empty ( $pendingInvoice ))
  7174. $new ['pendingInvoice'] = TRUE;
  7175. // if (! empty ( $myClaim ))
  7176. // $new ['myClaim'] = TRUE;
  7177. if (! empty ( $approval ))
  7178. $new ['approval'] = TRUE;
  7179. if (! empty ( $post ))
  7180. $new ['post'] = TRUE;
  7181. if (! empty ( $print ))
  7182. $new ['print'] = TRUE;
  7183. if (! empty ( $untread ))
  7184. $new ['untread'] = TRUE;
  7185. return $new;
  7186. }
  7187. function setWXMsg($rid, $typeMsg = '') {
  7188. Doo::loadModel ( 'invoice' );
  7189. $invoice = new invoice ();
  7190. $invoiceDetail = $invoice->getOne ( array (
  7191. 'where' => 'iid=' . $rid,
  7192. 'asArray' => true
  7193. ) );
  7194. if (! empty ( $invoiceDetail )) {
  7195. Doo::loadModel ( 'staff' );
  7196. $staff = new staff ();
  7197. $staffmsg = $staff->getOne ( array (
  7198. 'where' => "sid='" . $invoiceDetail ['sid'] . "'",
  7199. 'asArray' => TRUE
  7200. ) );
  7201. if (! empty ( $staffmsg ['wxid'] )) {
  7202. require_once (SITE_PATH . '/protected/class/client.php');
  7203. $client = new client ( 'http://m.cld.smartcost.com.cn/' );
  7204. $user = $staffmsg ['wxid'];
  7205. $expCom = explode ( ":", $invoiceDetail ['expressCompany'] );
  7206. if (empty ( $expCom ))
  7207. $expCom [0] = '';
  7208. $msg = "";
  7209. if (empty ( $typeMsg ))
  7210. $msg = '太好了,您的发票' . $invoiceDetail ['invoiceSerial'] . ' 已邮寄 ' . $expCom [0] . ' ,快递号: <a href="https://m.kuaidi100.com/result.jsp?nu=' . $invoiceDetail ['expressNumber'] . '" >' . $invoiceDetail ['expressNumber'] . '</a>';
  7211. elseif ($typeMsg == "PRINT")
  7212. $msg = '太好了,您的发票已打印完成。';
  7213. $result = $client->SendMsg ( $user, $msg, 'text' );
  7214. }
  7215. }
  7216. }
  7217. /**
  7218. * 获取微信部门
  7219. * @param string $category
  7220. * @return number|mixed
  7221. */
  7222. function getToparty($category = '') {
  7223. $token = $this->getAccessToken (); //
  7224. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token={$token}&id=5" ), true );
  7225. $toparty = 0;
  7226. foreach ( $result ['department'] as $key => $value ) {
  7227. if ($value ['name'] == $category)
  7228. $toparty = $value ['id'];
  7229. }
  7230. return $toparty;
  7231. }
  7232. /**
  7233. * 获得某部门下的用户
  7234. * @param string $toparty
  7235. */
  7236. function getUserByToparty($toparty = '') {
  7237. $token = $this->getAccessToken (); //
  7238. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token={$token}&department_id={$toparty}" ), true );
  7239. $userList = array ();
  7240. foreach ( $result ['userlist'] as $key => $value ) {
  7241. array_push ( $userList, "'" . $value ['userid'] . "'" );
  7242. }
  7243. return $userList;
  7244. }
  7245. function msgSendToparty($msg, $title, $url, $toparty, $text = '') {
  7246. $token = $this->getAccessToken ();
  7247. if ($text == 'text') {
  7248. $data = '{
  7249. "touser": "' . $toparty . '",
  7250. "toparty": "",
  7251. "totag": "",
  7252. "msgtype": "text",
  7253. "agentid": 1000002,
  7254. "text": {
  7255. "content": "' . $msg . '"
  7256. },
  7257. "safe":0
  7258. }';
  7259. }
  7260. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  7261. if ($result->errmsg != 'ok') {
  7262. return 0;
  7263. } else {
  7264. return 1;
  7265. }
  7266. }
  7267. /**
  7268. * 获得可以发送微信用户列表
  7269. * @param string $category
  7270. * @return string
  7271. */
  7272. function getWxidByCategory($category = "") {
  7273. if (empty ( $category ))
  7274. return "";
  7275. Doo::loadModel ( 'staff' );
  7276. $staff = new staff ();
  7277. $toparty = $this->getToparty ( $category );
  7278. $wxList = array ();
  7279. $wxString = "";
  7280. if (! empty ( $toparty )) {
  7281. $userList = $this->getUserByToparty ( $toparty );
  7282. $userCon = implode ( ',', $userList );
  7283. // echo $userCon;
  7284. $sidList = $staff->getStaffByWxid ( $userCon );
  7285. foreach ( $sidList as $key => $value ) {
  7286. $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  7287. if ($falg) {
  7288. array_push ( $wxList, $value ['wxid'] );
  7289. }
  7290. }
  7291. $wxString = implode ( '|', $wxList );
  7292. }
  7293. return $wxString;
  7294. }
  7295. /**
  7296. * 读取发送信息规则判断是否需要发送
  7297. * @param number $sid
  7298. * @param string $sendType
  7299. * @return boolean
  7300. */
  7301. function isSendNotification($sid = 0, $sendType = '') {
  7302. Doo::loadModel ( "notificationConf" );
  7303. $notificationConf = new notificationConf ();
  7304. $detail = $notificationConf->getNotificationConfBySid ( $sid );
  7305. $conf = array ();
  7306. $sendFlag = true;
  7307. if (! empty ( $detail )) {
  7308. $conf = json_decode ( $detail ['conf'], true );
  7309. if (! empty ( $sendType )) {
  7310. if (isset ( $conf [$sendType] )) {
  7311. if ($conf [$sendType] == "CLOSE")
  7312. $sendFlag = false;
  7313. elseif ($conf [$sendType] == "Weekend") {
  7314. $day = date ( "w" );
  7315. if (1 <= $day && 5 >= $day)
  7316. $sendFlag = false;
  7317. } elseif ($conf [$sendType] == "OneToFriday") {
  7318. $day = date ( "w" );
  7319. if (0 == $day || 6 == $day)
  7320. $sendFlag = false;
  7321. }
  7322. }
  7323. } else
  7324. $sendFlag = false;
  7325. }
  7326. return $sendFlag;
  7327. }
  7328. /**
  7329. * 根据规则发送信息
  7330. * @param unknown $msg
  7331. * @param unknown $title
  7332. * @param unknown $url
  7333. * @param unknown $user
  7334. * @param string $text
  7335. * @return number
  7336. */
  7337. private function msgSend($msg, $title, $url, $user, $sid = 0, $sendType = '') {
  7338. $token = $this->getAccessToken ();
  7339. $falg = $this->isSendNotification ( $sid, $sendType );
  7340. // if ($text == 'text') {
  7341. // $data = '{
  7342. // "touser": "' . $user . '",
  7343. // "toparty": "",
  7344. // "totag": "",
  7345. // "msgtype": "text",
  7346. // "agentid": 1000002,
  7347. // "text": {
  7348. // "content": "' . $msg . '"
  7349. // },
  7350. // "safe":0
  7351. // }';
  7352. // } else {
  7353. $data = '{
  7354. "touser": "' . $user . '",
  7355. "toparty": "",
  7356. "totag": "",
  7357. "msgtype": "news",
  7358. "agentid": 1000002,
  7359. "news": {
  7360. "articles":[
  7361. {
  7362. "title": "' . $title . '",
  7363. "description": "' . $msg . '",
  7364. "url": "' . $url . '",
  7365. "picurl": ""
  7366. }
  7367. ]
  7368. }
  7369. }';
  7370. // }
  7371. if ($falg) {
  7372. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  7373. if ($result->errmsg != 'ok') {
  7374. return 0;
  7375. } else {
  7376. return 1;
  7377. }
  7378. } else
  7379. return 0;
  7380. }
  7381. private function getAccessToken() {
  7382. // access_token 应该全局存储与更新,以下代码以写入到文件中做示例
  7383. // $file = './access_token.txt';
  7384. // $data = json_decode ( file_get_contents ( $file ) );
  7385. // if ($data->expire_time < time () or ! $data->expire_time) {
  7386. // 如果是企业号用以下URL获取access_token
  7387. $url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$this->appId&corpsecret=$this->appSecret";
  7388. // $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$this->appId&secret=$this->appSecret";
  7389. $res = json_decode ( $this->httpGet ( $url ) );
  7390. $access_token = $res->access_token;
  7391. // echo $access_token;
  7392. // if ($access_token) {
  7393. // $data->expire_time = time () + 7000;
  7394. // $data->access_token = $access_token;
  7395. // $fp = fopen ( $file, "w" );
  7396. // fwrite ( $fp, json_encode ( $data ) );
  7397. // fclose ( $fp );
  7398. // }
  7399. // } else {
  7400. // $access_token = $data->access_token;
  7401. // }
  7402. return $access_token;
  7403. }
  7404. private function httpGet($url) {
  7405. $curl = curl_init ();
  7406. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  7407. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  7408. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  7409. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  7410. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  7411. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  7412. curl_setopt ( $curl, CURLOPT_URL, $url );
  7413. $res = curl_exec ( $curl );
  7414. curl_close ( $curl );
  7415. return $res;
  7416. }
  7417. private function httpPost($url, $data) {
  7418. $curl = curl_init ();
  7419. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  7420. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  7421. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  7422. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  7423. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  7424. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  7425. curl_setopt ( $curl, CURLOPT_URL, $url );
  7426. curl_setopt ( $curl, CURLOPT_POST, 1 );
  7427. curl_setopt ( $curl, CURLOPT_POSTFIELDS, $data );
  7428. $res = curl_exec ( $curl );
  7429. curl_close ( $curl );
  7430. return $res;
  7431. }
  7432. }
  7433. ?>